comparison nnchat.c @ 33:e49ea6febfeb

Cleanups. Added option to specify/fake "site" where logging in from.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Aug 2008 08:42:57 +0300
parents 67ec4073e38c
children f5d335771b16
comparison
equal deleted inserted replaced
32:67ec4073e38c 33:e49ea6febfeb
27 char *optServer = "www11.servemedata.com", 27 char *optServer = "www11.servemedata.com",
28 *optUserName = NULL, 28 *optUserName = NULL,
29 *optUserName2 = NULL, 29 *optUserName2 = NULL,
30 *optPassword = NULL, 30 *optPassword = NULL,
31 *optLogFilename = NULL, 31 *optLogFilename = NULL,
32 *setTarget = NULL; 32 *setTarget = NULL,
33 *optSite = "NN";
33 BOOL optDaemon = FALSE; 34 BOOL optDaemon = FALSE;
34 FILE *optLogFile = NULL; 35 FILE *optLogFile = NULL;
35 WINDOW *mainWin = NULL, 36 WINDOW *mainWin = NULL,
36 *statusWin = NULL, 37 *statusWin = NULL,
37 *editWin = NULL; 38 *editWin = NULL;
38 BOOL setPrvMode = FALSE; 39 BOOL setPrvMode = FALSE;
40
39 41
40 /* Arguments 42 /* Arguments
41 */ 43 */
42 optarg_t optList[] = { 44 optarg_t optList[] = {
43 { 0, '?', "help", "Show this help", OPT_NONE }, 45 { 0, '?', "help", "Show this help", OPT_NONE },
45 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, 47 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
46 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, 48 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
47 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, 49 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ },
48 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, 50 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
49 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, 51 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE },
52 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ },
50 }; 53 };
51 54
52 const int optListN = (sizeof(optList) / sizeof(optarg_t)); 55 const int optListN = (sizeof(optList) / sizeof(optarg_t));
53 56
54 57
107 THMSG(1, "Using color #%06x\n", optUserColor); 110 THMSG(1, "Using color #%06x\n", optUserColor);
108 break; 111 break;
109 112
110 case 5: 113 case 5:
111 optLogFilename = optArg; 114 optLogFilename = optArg;
115 break;
116
117 case 7:
118 optSite = optArg;
112 break; 119 break;
113 120
114 case 6: 121 case 6:
115 optDaemon = TRUE; 122 optDaemon = TRUE;
116 THMSG(1, "Running in pseudo-daemon mode.\n"); 123 THMSG(1, "Running in pseudo-daemon mode.\n");
1045 if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) { 1052 if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) {
1046 THERR("Main connection setup failed!\n"); 1053 THERR("Main connection setup failed!\n");
1047 goto err_exit; 1054 goto err_exit;
1048 } 1055 }
1049 1056
1050 THMSG(1, "Connected, logging in as '%s'.\n", optUserName); 1057 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite);
1051 optUserName2 = encodeStr1(optUserName); 1058 optUserName2 = encodeStr1(optUserName);
1052 1059 tmpStr = encodeStr1(optSite);
1053 sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20NN%%20%%2Dpassword%%20%s", optPassword); 1060 sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword);
1054 1061 th_free(tmpStr);
1055 /* Initialize curses */ 1062
1056 1063 /* Initialize NCurses */
1057 if (!optDaemon) { 1064 if (!optDaemon) {
1058 initscr(); 1065 initscr();
1059 raw(); 1066 raw();
1060 keypad(stdscr, TRUE); 1067 keypad(stdscr, TRUE);
1061 noecho(); 1068 noecho();
1241 editBuf->pos = editBuf->len; 1248 editBuf->pos = editBuf->len;
1242 update = TRUE; 1249 update = TRUE;
1243 break; 1250 break;
1244 1251
1245 case 0x111: /* F9 */ 1252 case 0x111: /* F9 */
1246 printMsg("Quitting per user request."); 1253 printMsg("Quitting per user request.\n");
1247 exitProg = TRUE; 1254 exitProg = TRUE;
1248 break; 1255 break;
1249 1256
1250 case 0x10a: /* F2 */ 1257 case 0x10a: /* F2 */
1251 clearBuf(editBuf); 1258 clearBuf(editBuf);