Mercurial > hg > nnchat
comparison nnchat.c @ 198:21a37995c3fb
Make configuration username/password overridable on command line.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 18 Nov 2010 01:26:41 +0200 |
parents | e0ec2280a778 |
children | 4b93442bd411 |
comparison
equal
deleted
inserted
replaced
197:e0ec2280a778 | 198:21a37995c3fb |
---|---|
36 */ | 36 */ |
37 int optPort = 8003; | 37 int optPort = 8003; |
38 int optUserColor = 0x006080; | 38 int optUserColor = 0x006080; |
39 char *optServer = "chat.newbienudes.com", | 39 char *optServer = "chat.newbienudes.com", |
40 *optUserName = NULL, | 40 *optUserName = NULL, |
41 *optUserName2 = NULL, | 41 *optUserNameCmd = NULL, |
42 *optUserNameEnc = NULL, | |
42 *optPassword = NULL, | 43 *optPassword = NULL, |
44 *optPasswordCmd = NULL, | |
43 *optLogFilename = NULL, | 45 *optLogFilename = NULL, |
44 *setTarget = NULL, | 46 *setTarget = NULL, |
45 *optSite = "NN"; | 47 *optSite = "NN"; |
46 char optNickSep = ':'; | 48 char optNickSep = ':'; |
47 BOOL optDaemon = FALSE; | 49 BOOL optDaemon = FALSE; |
141 } | 143 } |
142 | 144 |
143 | 145 |
144 BOOL argHandleFile(char *currArg) | 146 BOOL argHandleFile(char *currArg) |
145 { | 147 { |
146 if (!optUserName) | 148 if (!optUserNameCmd) |
147 optUserName = currArg; | 149 optUserNameCmd = currArg; |
148 else if (!optPassword) | 150 else if (!optPasswordCmd) |
149 optPassword = currArg; | 151 optPasswordCmd = currArg; |
150 else { | 152 else { |
151 THERR("Username '%s' already specified on commandline!\n", optUserName); | 153 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); |
152 return FALSE; | 154 return FALSE; |
153 } | 155 } |
154 | 156 |
155 return TRUE; | 157 return TRUE; |
156 } | 158 } |
472 if (!strncmp(str, "FAILURE", 7)) { | 474 if (!strncmp(str, "FAILURE", 7)) { |
473 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); | 475 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); |
474 return -2; | 476 return -2; |
475 } else if (!strncmp(str, "SUCCESS", 7)) { | 477 } else if (!strncmp(str, "SUCCESS", 7)) { |
476 printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr); | 478 printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
477 nn_conn_send_msg(conn, optUserName2, "%%2FRequestUserList"); | 479 nn_conn_send_msg(conn, optUserNameEnc, "%%2FRequestUserList"); |
478 return 0; | 480 return 0; |
479 } else | 481 } else |
480 return 1; | 482 return 1; |
481 } | 483 } |
482 | 484 |
613 printMsg("Invalid color value '%s'\n", buf+7); | 615 printMsg("Invalid color value '%s'\n", buf+7); |
614 return 1; | 616 return 1; |
615 } | 617 } |
616 optUserColor = tmpInt; | 618 optUserColor = tmpInt; |
617 printMsg("Setting color to #%06x\n", optUserColor); | 619 printMsg("Setting color to #%06x\n", optUserColor); |
618 nn_conn_send_msg(conn, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 620 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
619 return 0; | 621 return 0; |
620 } else if (!strncasecmp(buf, "/ignore", 7)) { | 622 } else if (!strncasecmp(buf, "/ignore", 7)) { |
621 char *name = trimLeft(buf + 7); | 623 char *name = trimLeft(buf + 7); |
622 if (strlen(name) > 0) { | 624 if (strlen(name) > 0) { |
623 /* Add or remove someone to/from ignore */ | 625 /* Add or remove someone to/from ignore */ |
722 } | 724 } |
723 | 725 |
724 /* Send double-encoded */ | 726 /* Send double-encoded */ |
725 tmpStr = nn_dblencode_str(decodeUsername(buf)); | 727 tmpStr = nn_dblencode_str(decodeUsername(buf)); |
726 if (tmpStr == 0) return -2; | 728 if (tmpStr == 0) return -2; |
727 result = nn_conn_send_msg(conn, optUserName2, "%s", tmpStr); | 729 result = nn_conn_send_msg(conn, optUserNameEnc, "%s", tmpStr); |
728 th_free(tmpStr); | 730 th_free(tmpStr); |
729 | 731 |
730 return result ? 0 : -1; | 732 return result ? 0 : -1; |
731 } | 733 } |
732 | 734 |
971 | 973 |
972 /* Parse command line arguments */ | 974 /* Parse command line arguments */ |
973 argsOK = th_args_process(argc, argv, optList, optListN, | 975 argsOK = th_args_process(argc, argv, optList, optListN, |
974 argHandleOpt, argHandleFile, FALSE); | 976 argHandleOpt, argHandleFile, FALSE); |
975 | 977 |
978 if (optUserNameCmd != NULL) { | |
979 optUserName = optUserNameCmd; | |
980 optPassword = optPasswordCmd; | |
981 } | |
982 | |
976 /* Check if we have username and password */ | 983 /* Check if we have username and password */ |
977 if (optUserName == NULL || optPassword == NULL) { | 984 if (optUserName == NULL || optPassword == NULL) { |
978 printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); | 985 printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); |
979 optUserName = promptRequester("NN username: "); | 986 optUserName = promptRequester("NN username: "); |
980 optPassword = promptRequester("NN password: "); | 987 optPassword = promptRequester("NN password: "); |
1047 THERR("Main connection setup failed!\n"); | 1054 THERR("Main connection setup failed!\n"); |
1048 goto err_exit; | 1055 goto err_exit; |
1049 } | 1056 } |
1050 | 1057 |
1051 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); | 1058 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); |
1052 optUserName2 = nn_dblencode_str(optUserName); | 1059 optUserNameEnc = nn_dblencode_str(optUserName); |
1053 tmpStr = nn_dblencode_str(optSite); | 1060 tmpStr = nn_dblencode_str(optSite); |
1054 nn_conn_send_msg(conn, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); | 1061 nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
1055 th_free(tmpStr); | 1062 th_free(tmpStr); |
1056 | 1063 |
1057 /* Initialize NCurses */ | 1064 /* Initialize NCurses */ |
1058 if (!optDaemon) { | 1065 if (!optDaemon) { |
1059 if (LINES < 0 || LINES > 1000) LINES = 24; | 1066 if (LINES < 0 || LINES > 1000) LINES = 24; |
1337 } /* !optDaemon */ | 1344 } /* !optDaemon */ |
1338 | 1345 |
1339 if (++updateCount > 10) { | 1346 if (++updateCount > 10) { |
1340 time_t tmpTime = time(NULL); | 1347 time_t tmpTime = time(NULL); |
1341 if (tmpTime - prevTime > SET_KEEPALIVE) { | 1348 if (tmpTime - prevTime > SET_KEEPALIVE) { |
1342 nn_conn_send_msg(conn, optUserName2, "/listallusers"); | 1349 nn_conn_send_msg(conn, optUserNameEnc, "/listallusers"); |
1343 prevTime = tmpTime; | 1350 prevTime = tmpTime; |
1344 } | 1351 } |
1345 | 1352 |
1346 if (!colorSet) { | 1353 if (!colorSet) { |
1347 colorSet = TRUE; | 1354 colorSet = TRUE; |
1348 printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); | 1355 printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); |
1349 printMsg("%s\n", th_prog_author); | 1356 printMsg("%s\n", th_prog_author); |
1350 printMsg("%s\n", th_prog_license); | 1357 printMsg("%s\n", th_prog_license); |
1351 nn_conn_send_msg(conn, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 1358 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
1352 } | 1359 } |
1353 | 1360 |
1354 updateStatus(insertMode); | 1361 updateStatus(insertMode); |
1355 updateCount = 0; | 1362 updateCount = 0; |
1356 } | 1363 } |
1375 | 1382 |
1376 if (isError) { | 1383 if (isError) { |
1377 THMSG(1, "Error exit.\n"); | 1384 THMSG(1, "Error exit.\n"); |
1378 } | 1385 } |
1379 | 1386 |
1380 th_free(optUserName2); | 1387 th_free(optUserNameEnc); |
1381 | 1388 |
1382 nn_conn_close(conn); | 1389 nn_conn_close(conn); |
1383 | 1390 |
1384 if (networkInit) | 1391 if (networkInit) |
1385 nn_network_close(); | 1392 nn_network_close(); |