Mercurial > hg > nnchat
diff 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 |
line wrap: on
line diff
--- a/nnchat.c Sat Oct 30 17:03:29 2010 +0300 +++ b/nnchat.c Sat Oct 30 20:37:09 2010 +0300 @@ -6,6 +6,7 @@ #include "libnnchat.h" #include <stdlib.h> #include "th_args.h" +#include "th_config.h" #include <string.h> #include <errno.h> #ifdef __WIN32 @@ -55,6 +56,9 @@ BOOL setPrvMode = FALSE; BOOL ignoreMode = FALSE; +char *setConfigFile = "config"; +cfgitem_t *cfg = NULL; + /* Arguments */ @@ -563,6 +567,19 @@ printMsg("Setting color to #%06x\n", optUserColor); nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); return 0; + } else if (!strncasecmp(buf, "/save", 5)) { + /* Save configuration */ + FILE *f = fopen(setConfigFile, "w"); + if (f == NULL) { + printMsg("Could not save configuration to file '%s'!\n", setConfigFile); + return 0; + } + printMsg("Configuration saved in file '%s', res=%d\n", + setConfigFile, + th_cfg_write(f, setConfigFile, cfg)); + + fclose(f); + return 0; } else if (!strncasecmp(buf, "/w ", 3)) { /* Open given username's profile via firefox in a new tab */ char *name = trimLeft(buf + 3), @@ -766,6 +783,31 @@ "Written and designed by Anonymous Finnish Guy (C) 2008-2010", "This software is freeware, use and distribute as you wish."); th_verbosityLevel = 0; + + /* Read config */ + { + cfgitem_t *tmpcfg = NULL; + FILE *cfgfile; + + th_cfg_add_comment(&tmpcfg, "General settings"); + th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); + th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); + th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); + th_cfg_add_section(&cfg, "general", tmpcfg); + + tmpcfg = NULL; + th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); + th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); + th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)"); + th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); + th_cfg_add_section(&cfg, "server", tmpcfg); + + th_cfg_add_comment(&cfg, "People to be ignored in ignore mode"); + th_cfg_add_string(&cfg, "ignores", ignoreList, NULL); + + if ((cfgfile = fopen(setConfigFile, "r")) != NULL) + th_cfg_read(cfgfile, setConfigFile, cfg); + } /* Parse arguments */ argsOK = th_args_process(argc, argv, optList, optListN, @@ -1202,7 +1244,6 @@ THMSG(1, "Closing logfile.\n"); fclose(optLogFile); } - - + return 0; }