diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-09-14 20:44:32 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-09-14 20:44:32 +0100 |
commit | 4dea4c16313ba3d1575cfa6722d75492c907f551 (patch) | |
tree | cade95813a471e3aa4597a5a35e907e2cd675181 /blabouncer.c | |
parent | e1f41810ac85a0d210062ed33f43938dc4b03be4 (diff) |
Specify multiple nicks using a configuration array instead of multiple individual settings.
Diffstat (limited to 'blabouncer.c')
-rw-r--r-- | blabouncer.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/blabouncer.c b/blabouncer.c index e6a56c1..772b969 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -137,8 +137,8 @@ int connecttoircserver(SSL_CTX **serverctx, SSL **server_ssl, int *serversockfd, // ircdstate.clientchangetime and ircdstate.clientsnonetime not set here as they are set at startup and only changed when clients connect/disconnect // ircdstate.clientcodes not set here, set on startup and whenever a client sets one - // Populate nick and username from our configuration file for now, real IRCd may change them later (TODO - Is this true of username?) - strcpy(ircdstate->ircnick, settings->ircnick); + // Populate nicks[0] and username from our configuration file for now, real IRCd may change them later (TODO - Is this true of username?) + strcpy(ircdstate->ircnick, settings->ircnicks[0]); strcpy(ircdstate->ircusername, settings->ircusername); // Send the server password if one was configured @@ -967,22 +967,27 @@ int main(int argc, char *argv[]) { exit(1); } - // What is the configured nick? - if (!getconfstr("nick", settings.conffile, settings.ircnick)) { - printf("main(): error getting 'nick' from configuration file.\n"); + // What are the configured nick(s)? + int ret = getconfarr("nicks", settings.conffile, settings.ircnicks); + if (!ret) { + printf("main(): error getting any 'nicks' from configuration file.\n"); + } else if (ret == -1) { + // Error reading an array line from the configuration file + // Remove any newlines from the middle of the string so error printing works nicely + for (size_t i = 0; i < strlen(settings.ircnicks[0]) - 1; i++) { + if (settings.ircnicks[0][i] == '\n') { + settings.ircnicks[0][i] = ' '; + } + } + printf("main(): error getting 'nicks' from configuration file: %s", settings.ircnicks[0]); exit(1); } - - // What is the configured nick2? - if (!getconfstr("nick2", settings.conffile, settings.ircnick2)) { - // Not configured, set to blank string - settings.ircnick2[0] = '\0'; - } - - // What is the configured nick3? - if (!getconfstr("nick3", settings.conffile, settings.ircnick3)) { - // Not configured, set to blank string - settings.ircnick3[0] = '\0'; + // Make sure nicks aren't too long (since getconfarr() has to use MAXDATASIZE for all string lengths) + for (int i = 0; i < MAXCONFARR; i++) { + if (settings.ircnicks[i][0] && strlen(settings.ircnicks[i]) > MAXNICKLENGTH) { + printf("main(): error: specified nick '%s' is too long, maximum length is %d.\n", settings.ircnicks[i], MAXNICKLENGTH); + exit(1); + } } // What is the configured username? @@ -1026,7 +1031,7 @@ int main(int argc, char *argv[]) { } // What are the connect commands, if any? - int ret = getconfarr("connectcommands", settings.conffile, settings.connectcommands); + ret = getconfarr("connectcommands", settings.conffile, settings.connectcommands); if (!ret) { for (int i = 0; i < MAXCONFARR; i++) { settings.connectcommands[i][0] = '\0'; |