Mercurial > hg > nnchat
comparison nnchat.c @ 133:ffe8bbd429fa
Config file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 30 Oct 2010 20:37:09 +0300 |
parents | 10daf4660cae |
children | f367fc14021a |
comparison
equal
deleted
inserted
replaced
132:10daf4660cae | 133:ffe8bbd429fa |
---|---|
4 * (C) Copyright 2008-2010 Tecnic Software productions (TNSP) | 4 * (C) Copyright 2008-2010 Tecnic Software productions (TNSP) |
5 */ | 5 */ |
6 #include "libnnchat.h" | 6 #include "libnnchat.h" |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "th_args.h" | 8 #include "th_args.h" |
9 #include "th_config.h" | |
9 #include <string.h> | 10 #include <string.h> |
10 #include <errno.h> | 11 #include <errno.h> |
11 #ifdef __WIN32 | 12 #ifdef __WIN32 |
12 /* Undefine because both windows.h and curses.h #define it */ | 13 /* Undefine because both windows.h and curses.h #define it */ |
13 #undef MOUSE_MOVED | 14 #undef MOUSE_MOVED |
53 *statusWin = NULL, | 54 *statusWin = NULL, |
54 *editWin = NULL; | 55 *editWin = NULL; |
55 BOOL setPrvMode = FALSE; | 56 BOOL setPrvMode = FALSE; |
56 BOOL ignoreMode = FALSE; | 57 BOOL ignoreMode = FALSE; |
57 | 58 |
59 char *setConfigFile = "config"; | |
60 cfgitem_t *cfg = NULL; | |
61 | |
58 | 62 |
59 /* Arguments | 63 /* Arguments |
60 */ | 64 */ |
61 optarg_t optList[] = { | 65 optarg_t optList[] = { |
62 { 0, '?', "help", "Show this help", OPT_NONE }, | 66 { 0, '?', "help", "Show this help", OPT_NONE }, |
560 return 1; | 564 return 1; |
561 } | 565 } |
562 optUserColor = tmpInt; | 566 optUserColor = tmpInt; |
563 printMsg("Setting color to #%06x\n", optUserColor); | 567 printMsg("Setting color to #%06x\n", optUserColor); |
564 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); | 568 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
569 return 0; | |
570 } else if (!strncasecmp(buf, "/save", 5)) { | |
571 /* Save configuration */ | |
572 FILE *f = fopen(setConfigFile, "w"); | |
573 if (f == NULL) { | |
574 printMsg("Could not save configuration to file '%s'!\n", setConfigFile); | |
575 return 0; | |
576 } | |
577 printMsg("Configuration saved in file '%s', res=%d\n", | |
578 setConfigFile, | |
579 th_cfg_write(f, setConfigFile, cfg)); | |
580 | |
581 fclose(f); | |
565 return 0; | 582 return 0; |
566 } else if (!strncasecmp(buf, "/w ", 3)) { | 583 } else if (!strncasecmp(buf, "/w ", 3)) { |
567 /* Open given username's profile via firefox in a new tab */ | 584 /* Open given username's profile via firefox in a new tab */ |
568 char *name = trimLeft(buf + 3), | 585 char *name = trimLeft(buf + 3), |
569 *browser = getenv("BROWSER"); | 586 *browser = getenv("BROWSER"); |
764 /* Initialize */ | 781 /* Initialize */ |
765 th_init("NNChat", "Newbie Nudes chat client", "0.8.0", | 782 th_init("NNChat", "Newbie Nudes chat client", "0.8.0", |
766 "Written and designed by Anonymous Finnish Guy (C) 2008-2010", | 783 "Written and designed by Anonymous Finnish Guy (C) 2008-2010", |
767 "This software is freeware, use and distribute as you wish."); | 784 "This software is freeware, use and distribute as you wish."); |
768 th_verbosityLevel = 0; | 785 th_verbosityLevel = 0; |
786 | |
787 /* Read config */ | |
788 { | |
789 cfgitem_t *tmpcfg = NULL; | |
790 FILE *cfgfile; | |
791 | |
792 th_cfg_add_comment(&tmpcfg, "General settings"); | |
793 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); | |
794 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); | |
795 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); | |
796 th_cfg_add_section(&cfg, "general", tmpcfg); | |
797 | |
798 tmpcfg = NULL; | |
799 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); | |
800 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); | |
801 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)"); | |
802 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); | |
803 th_cfg_add_section(&cfg, "server", tmpcfg); | |
804 | |
805 th_cfg_add_comment(&cfg, "People to be ignored in ignore mode"); | |
806 th_cfg_add_string(&cfg, "ignores", ignoreList, NULL); | |
807 | |
808 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) | |
809 th_cfg_read(cfgfile, setConfigFile, cfg); | |
810 } | |
769 | 811 |
770 /* Parse arguments */ | 812 /* Parse arguments */ |
771 argsOK = th_args_process(argc, argv, optList, optListN, | 813 argsOK = th_args_process(argc, argv, optList, optListN, |
772 argHandleOpt, argHandleFile, FALSE); | 814 argHandleOpt, argHandleFile, FALSE); |
773 | 815 |
1200 | 1242 |
1201 if (optLogFile) { | 1243 if (optLogFile) { |
1202 THMSG(1, "Closing logfile.\n"); | 1244 THMSG(1, "Closing logfile.\n"); |
1203 fclose(optLogFile); | 1245 fclose(optLogFile); |
1204 } | 1246 } |
1205 | 1247 |
1206 | |
1207 return 0; | 1248 return 0; |
1208 } | 1249 } |