Mercurial > hg > nnchat
comparison nnchat.c @ 140:2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Nov 2010 21:48:24 +0200 |
parents | c39399725f7b |
children | cce05daf6f01 |
comparison
equal
deleted
inserted
replaced
139:c39399725f7b | 140:2d2ef5bbcc11 |
---|---|
29 #define SET_MAX_HISTORY (16) | 29 #define SET_MAX_HISTORY (16) |
30 #define SET_DELAY (15) | 30 #define SET_DELAY (15) |
31 #define SET_DELAY_USEC (SET_DELAY * 250) | 31 #define SET_DELAY_USEC (SET_DELAY * 250) |
32 #define SET_KEEPALIVE (15*60) /* Ping/keepalive period in seconds */ | 32 #define SET_KEEPALIVE (15*60) /* Ping/keepalive period in seconds */ |
33 | 33 |
34 char *ignoreList[] = { | |
35 "purr_rr", | |
36 "moisha", | |
37 "leth", | |
38 "shaz:)", | |
39 "rayen", | |
40 "iam2qute4you_92", | |
41 NULL | |
42 }; | |
43 | |
44 nn_userhash_t *nnUsers = NULL; | |
45 | 34 |
46 /* Options | 35 /* Options |
47 */ | 36 */ |
48 int optPort = 8003; | 37 int optPort = 8003; |
49 int optUserColor = 0x006080; | 38 int optUserColor = 0x006080; |
61 *statusWin = NULL, | 50 *statusWin = NULL, |
62 *editWin = NULL; | 51 *editWin = NULL; |
63 BOOL setPrvMode = FALSE; | 52 BOOL setPrvMode = FALSE; |
64 BOOL ignoreMode = FALSE; | 53 BOOL ignoreMode = FALSE; |
65 | 54 |
55 | |
56 qlist_t *nnIgnoreList = NULL; | |
57 nn_userhash_t *nnUsers = NULL; | |
66 char *setConfigFile = NULL, | 58 char *setConfigFile = NULL, |
67 *setBrowser = NULL; | 59 *setBrowser = NULL; |
68 cfgitem_t *cfg = NULL; | 60 cfgitem_t *cfg = NULL; |
69 | 61 |
70 | 62 |
403 BOOL isMine = strcmp(p2, optUserName) == 0; | 395 BOOL isMine = strcmp(p2, optUserName) == 0; |
404 BOOL logOnly = FALSE; | 396 BOOL logOnly = FALSE; |
405 t = nn_strip_tags(s); | 397 t = nn_strip_tags(s); |
406 h = nn_decode_str2(t); | 398 h = nn_decode_str2(t); |
407 if (ignoreMode) { | 399 if (ignoreMode) { |
408 char **user = ignoreList; | 400 qlist_t *node = nnIgnoreList; |
409 while (*user != NULL) { | 401 while (node != NULL) { |
410 if (strcasecmp(p2, *user) == 0) { | 402 if (strcasecmp(p2, (char *) node->data) == 0) { |
411 logOnly = TRUE; | 403 logOnly = TRUE; |
412 break; | 404 break; |
413 } | 405 } |
414 user++; | 406 node = node->next; |
415 } | 407 } |
416 } | 408 } |
417 printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h); | 409 printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h); |
418 th_free(h); | 410 th_free(h); |
419 th_free(t); | 411 th_free(t); |
548 { | 540 { |
549 while (*buf != 0 && isspace(*buf)) buf++; | 541 while (*buf != 0 && isspace(*buf)) buf++; |
550 return buf; | 542 return buf; |
551 } | 543 } |
552 | 544 |
545 int compareUsername(const void *s1, const void *s2) | |
546 { | |
547 return strcasecmp((char *) s1, (char *) s2); | |
548 } | |
549 | |
553 int handleUserInput(const int sock, char *buf, size_t bufLen) | 550 int handleUserInput(const int sock, char *buf, size_t bufLen) |
554 { | 551 { |
555 char *tmpStr, tmpBuf[4096]; | 552 char *tmpStr, tmpBuf[4096]; |
556 BOOL result; | 553 BOOL result; |
557 | 554 |
572 return 1; | 569 return 1; |
573 } | 570 } |
574 optUserColor = tmpInt; | 571 optUserColor = tmpInt; |
575 printMsg("Setting color to #%06x\n", optUserColor); | 572 printMsg("Setting color to #%06x\n", optUserColor); |
576 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 573 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
574 return 0; | |
575 } else if (!strncasecmp(buf, "/ignore", 7)) { | |
576 char *name = trimLeft(buf + 7); | |
577 if (strlen(name) > 0) { | |
578 /* Add or remove someone to/from ignore */ | |
579 qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername); | |
580 if (user != NULL) { | |
581 printMsg("Removed user '%s' from ignore.\n", name); | |
582 th_llist_delete_node(&nnIgnoreList, user); | |
583 } else { | |
584 printMsg("Now ignoring '%s'.\n", name); | |
585 th_llist_append(&nnIgnoreList, th_strdup(name)); | |
586 } | |
587 } else { | |
588 /* Just list whomever is in ignore now */ | |
589 qlist_t *user = nnIgnoreList; | |
590 ssize_t nuser = th_llist_length(nnIgnoreList); | |
591 printMsg("Users ignored (%d): ", nuser); | |
592 while (user != NULL) { | |
593 if (user->data != NULL) { | |
594 printMsgC("'%s'", (char *) user->data); | |
595 if (--nuser > 0) | |
596 printMsgC(", "); | |
597 } | |
598 user = user->next; | |
599 } | |
600 printMsgC("\n"); | |
601 } | |
577 return 0; | 602 return 0; |
578 } else if (!strncasecmp(buf, "/save", 5)) { | 603 } else if (!strncasecmp(buf, "/save", 5)) { |
579 /* Save configuration */ | 604 /* Save configuration */ |
580 FILE *f = fopen(setConfigFile, "w"); | 605 FILE *f = fopen(setConfigFile, "w"); |
581 if (f == NULL) { | 606 if (f == NULL) { |