Mercurial > hg > nnchat
comparison nnchat.c @ 258:8a0f7446318e
General cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 May 2011 03:06:55 +0300 |
parents | 269135d58acd |
children | 4c1c18a388d9 6d48fc4fd421 |
comparison
equal
deleted
inserted
replaced
257:214f0b524f9d | 258:8a0f7446318e |
---|---|
62 FILE *optLogFile = NULL; | 62 FILE *optLogFile = NULL; |
63 WINDOW *mainWin = NULL, | 63 WINDOW *mainWin = NULL, |
64 *statusWin = NULL, | 64 *statusWin = NULL, |
65 *editWin = NULL; | 65 *editWin = NULL; |
66 BOOL setPrvMode = FALSE; | 66 BOOL setPrvMode = FALSE; |
67 BOOL setIgnoreMode = FALSE; | 67 BOOL setIgnoreMode = FALSE; |
68 BOOL optDebug = FALSE; | 68 BOOL optDebug = FALSE; |
69 BOOL optLogEnable = FALSE; | 69 BOOL optLogEnable = FALSE; |
70 | 70 |
71 qlist_t *nnIgnoreList = NULL; | 71 qlist_t *nnIgnoreList = NULL; |
72 nn_userhash_t *nnUsers = NULL; | 72 nn_userhash_t *nnUsers = NULL; |
90 }; | 90 }; |
91 | 91 |
92 const int optListN = (sizeof(optList) / sizeof(optList[0])); | 92 const int optListN = (sizeof(optList) / sizeof(optList[0])); |
93 | 93 |
94 | 94 |
95 void argShowHelp() | 95 void argShowHelp(void) |
96 { | 96 { |
97 th_args_help(stdout, optList, optListN, th_prog_name, | 97 th_args_help(stdout, optList, optListN, th_prog_name, |
98 "[options] <username> <password>"); | 98 "[options] <username> <password>"); |
99 } | 99 } |
100 | 100 |
191 for (; *c ; c++) | 191 for (; *c ; c++) |
192 if (*c == ' ') *c = 255; | 192 if (*c == ' ') *c = 255; |
193 return str; | 193 return str; |
194 } | 194 } |
195 | 195 |
196 | |
196 char *decodeUsername(char *str) | 197 char *decodeUsername(char *str) |
197 { | 198 { |
198 unsigned char *c = (unsigned char *) str; | 199 unsigned char *c = (unsigned char *) str; |
199 if (str == NULL) return NULL; | 200 if (str == NULL) return NULL; |
200 for (; *c ; c++) | 201 for (; *c ; c++) |
201 if (*c == 255) *c = ' '; | 202 if (*c == 255) *c = ' '; |
202 return str; | 203 return str; |
203 } | 204 } |
205 | |
204 | 206 |
205 void updateStatus(BOOL insertMode) | 207 void updateStatus(BOOL insertMode) |
206 { | 208 { |
207 char tmpStr[128]; | 209 char tmpStr[128]; |
208 | 210 |
475 | 477 |
476 /* Check if the username is on our ignore list and | 478 /* Check if the username is on our ignore list and |
477 * that it is not our OWN username! | 479 * that it is not our OWN username! |
478 */ | 480 */ |
479 isMine = strcmp(userName, optUserName) == 0; | 481 isMine = strcmp(userName, optUserName) == 0; |
480 if (setIgnoreMode && !isMine) | 482 isIgnored = setIgnoreMode && !isMine && checkIgnoreList(userName); |
481 isIgnored = checkIgnoreList(userName); | |
482 | 483 |
483 /* Is it a special control message? */ | 484 /* Is it a special control message? */ |
484 if (*s == '/') { | 485 if (*s == '/') { |
485 /* Ignore room join/leave messages */ | 486 /* Ignore room join/leave messages */ |
486 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) | 487 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) |
656 /* Trim right */ | 657 /* Trim right */ |
657 bufLen--; | 658 bufLen--; |
658 buf[bufLen--] = 0; | 659 buf[bufLen--] = 0; |
659 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) | 660 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) |
660 buf[bufLen--] = 0; | 661 buf[bufLen--] = 0; |
662 | |
663 /* Decode completed usernames */ | |
661 decodeUsername(buf); | 664 decodeUsername(buf); |
662 | 665 |
663 /* Check for special user commands */ | 666 /* Check for special user commands */ |
664 if (*buf == 0) { | 667 if (*buf == 0) { |
665 return 1; | 668 return 1; |
666 } else if (!strncasecmp(buf, "/color ", 7)) { | 669 } |
670 else if (!strncasecmp(buf, "/color ", 7)) { | |
667 /* Change color */ | 671 /* Change color */ |
668 int tmpInt; | 672 int tmpInt; |
669 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) { | 673 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) { |
670 printMsg("Invalid color value '%s'\n", buf+7); | 674 printMsg("Invalid color value '%s'\n", buf+7); |
671 return 1; | 675 return 1; |
672 } | 676 } |
673 optUserColor = tmpInt; | 677 optUserColor = tmpInt; |
674 printMsg("Setting color to #%06x\n", optUserColor); | 678 printMsg("Setting color to #%06x\n", optUserColor); |
675 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 679 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
676 return 0; | 680 return 0; |
677 } else if (!strncasecmp(buf, "/ignore", 7)) { | 681 } |
682 else if (!strncasecmp(buf, "/ignore", 7)) { | |
678 char *name = trimLeft(buf + 7); | 683 char *name = trimLeft(buf + 7); |
679 if (strlen(name) > 0) { | 684 if (strlen(name) > 0) { |
680 /* Add or remove someone to/from ignore */ | 685 /* Add or remove someone to/from ignore */ |
681 qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername); | 686 qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername); |
682 if (user != NULL) { | 687 if (user != NULL) { |
700 user = user->next; | 705 user = user->next; |
701 } | 706 } |
702 printMsgC("\n"); | 707 printMsgC("\n"); |
703 } | 708 } |
704 return 0; | 709 return 0; |
705 } else if (!strncasecmp(buf, "/save", 5)) { | 710 } |
711 else if (!strncasecmp(buf, "/save", 5)) { | |
706 /* Save configuration */ | 712 /* Save configuration */ |
707 FILE *cfgfile = fopen(setConfigFile, "w"); | 713 FILE *cfgfile = fopen(setConfigFile, "w"); |
708 if (cfgfile == NULL) { | 714 if (cfgfile == NULL) { |
709 printMsg("Could not create configuration to file '%s': %s\n", setConfigFile, | 715 printMsg("Could not create configuration to file '%s': %s\n", setConfigFile, |
710 strerror(errno)); | 716 strerror(errno)); |
714 setConfigFile, | 720 setConfigFile, |
715 th_cfg_write(cfgfile, setConfigFile, cfg)); | 721 th_cfg_write(cfgfile, setConfigFile, cfg)); |
716 | 722 |
717 fclose(cfgfile); | 723 fclose(cfgfile); |
718 return 0; | 724 return 0; |
719 } else if (!strncasecmp(buf, "/w ", 3)) { | 725 } |
726 else if (!strncasecmp(buf, "/w ", 3)) { | |
720 /* Open given username's profile via firefox in a new tab */ | 727 /* Open given username's profile via firefox in a new tab */ |
721 char *name = trimLeft(buf + 3); | 728 char *name = trimLeft(buf + 3); |
722 | 729 |
723 printMsg("Opening profile for: '%s'\n", name); | 730 printMsg("Opening profile for: '%s'\n", name); |
724 | 731 |
757 | 764 |
758 wait(&status); | 765 wait(&status); |
759 } | 766 } |
760 #endif | 767 #endif |
761 return 0; | 768 return 0; |
762 } else if (!strncasecmp(buf, "/to", 3)) { | 769 } |
770 else if (!strncasecmp(buf, "/to", 3)) { | |
763 char *name = trimLeft(buf + 3); | 771 char *name = trimLeft(buf + 3); |
764 /* Set private messaging target */ | 772 /* Set private messaging target */ |
765 th_free(setTarget); | 773 th_free(setTarget); |
766 if (strlen(name) > 0) { | 774 if (strlen(name) > 0) { |
767 setTarget = th_strdup(trimLeft(buf + 3)); | 775 setTarget = th_strdup(trimLeft(buf + 3)); |
769 } else { | 777 } else { |
770 setTarget = NULL; | 778 setTarget = NULL; |
771 printMsg("Cleared prv target.\n"); | 779 printMsg("Cleared prv target.\n"); |
772 } | 780 } |
773 return 0; | 781 return 0; |
774 } else if (!strncasecmp(buf, "/who", 4)) { | 782 } |
783 else if (!strncasecmp(buf, "/who", 4)) { | |
775 /* Alias /who to /listallusers */ | 784 /* Alias /who to /listallusers */ |
776 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers"); | 785 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers"); |
777 buf = tmpBuf; | 786 buf = tmpBuf; |
778 } else if (setPrvMode) { | 787 } |
788 else if (setPrvMode) { | |
779 /* Private chat mode, send as PRV */ | 789 /* Private chat mode, send as PRV */ |
780 if (setTarget != NULL) { | 790 if (setTarget != NULL) { |
781 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf); | 791 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf); |
782 buf = tmpBuf; | 792 buf = tmpBuf; |
783 } else { | 793 } else { |