diff options
author | Ibrahem Hossam <hemagx2@gmail.com> | 2016-04-24 13:13:19 +0200 |
---|---|---|
committer | Ibrahem Hossam <hemagx2@gmail.com> | 2016-04-24 13:13:19 +0200 |
commit | 31e27a130676e3e416b583bb947f9dd87efdce81 (patch) | |
tree | f91422fa8b0ecd93ccb15720bc15a9b9b839cfd2 /src/map/channel.c | |
parent | 3ccc681a4bebd5b91b96c1c7059fdec91f2b5d16 (diff) | |
parent | 9fdb4567ab8af97004d7c6dcd35f27f788b0bb15 (diff) | |
download | hercules-31e27a130676e3e416b583bb947f9dd87efdce81.tar.gz hercules-31e27a130676e3e416b583bb947f9dd87efdce81.tar.bz2 hercules-31e27a130676e3e416b583bb947f9dd87efdce81.tar.xz hercules-31e27a130676e3e416b583bb947f9dd87efdce81.zip |
Merge pull request #1264 from HerculesWS/vs2015
Diffstat (limited to 'src/map/channel.c')
-rw-r--r-- | src/map/channel.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/map/channel.c b/src/map/channel.c index 3d1b3f975..e4e3d069d 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -640,52 +640,47 @@ void read_channels_config(void) const char *irc_server, *irc_channel, *irc_nick, *irc_nick_pw; int irc_use_ghost = 0; - if( libconfig->setting_lookup_string(settings, "irc_channel_network", &irc_server) ) { - if( !strstr(irc_server,":") ) { + if (!libconfig->setting_lookup_string(settings, "irc_channel_network", &irc_server)) { + channel->config->irc = false; + ShowWarning("channels.conf : irc channel enabled but irc_channel_network wasn't found, disabling irc channel...\n"); + } else { + char *server = aStrdup(irc_server); + char *port = strchr(server, ':'); + if (port == NULL) { channel->config->irc = false; - ShowWarning("channels.conf : network port wasn't found in 'irc_channel_network', disabling irc channel...\n"); + ShowWarning("channels.conf: network port wasn't found in 'irc_channel_network', disabling irc channel...\n"); + } else if ((size_t)(port-server) > sizeof channel->config->irc_server - 1) { + channel->config->irc = false; + ShowWarning("channels.conf: server name is too long in 'irc_channel_network', disabling irc channel...\n"); } else { - unsigned char d = 0, dlen = strlen(irc_server); - char server[40]; - if (dlen > 39) - dlen = 39; - memset(server, '\0', sizeof(server)); - - for(d = 0; d < dlen; d++) { - if(irc_server[d] == ':') { - memcpy(server, irc_server, d); - safestrncpy(channel->config->irc_server, server, 40); - memcpy(server, &irc_server[d+1], dlen - d - 1); - channel->config->irc_server_port = atoi(server); - break; - } - } + *port = '\0'; + port++; + safestrncpy(channel->config->irc_server, server, sizeof channel->config->irc_server); + channel->config->irc_server_port = atoi(port); } - } else { - channel->config->irc = false; - ShowWarning("channels.conf : irc channel enabled but irc_channel_network wasn't found, disabling irc channel...\n"); + aFree(server); } - if( libconfig->setting_lookup_string(settings, "irc_channel_channel", &irc_channel) ) + if (libconfig->setting_lookup_string(settings, "irc_channel_channel", &irc_channel)) { safestrncpy(channel->config->irc_channel, irc_channel, 50); - else { + } else { channel->config->irc = false; ShowWarning("channels.conf : irc channel enabled but irc_channel_channel wasn't found, disabling irc channel...\n"); } - if( libconfig->setting_lookup_string(settings, "irc_channel_nick", &irc_nick) ) { - if( strcmpi(irc_nick,"Hercules_chSysBot") == 0 ) { + if (libconfig->setting_lookup_string(settings, "irc_channel_nick", &irc_nick)) { + if (strcmpi(irc_nick,"Hercules_chSysBot") == 0) { sprintf(channel->config->irc_nick, "Hercules_chSysBot%d",rnd()%777); - } else + } else { safestrncpy(channel->config->irc_nick, irc_nick, 40); + } } else { channel->config->irc = false; ShowWarning("channels.conf : irc channel enabled but irc_channel_nick wasn't found, disabling irc channel...\n"); } - if( libconfig->setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw) ) { + if (libconfig->setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw)) { safestrncpy(channel->config->irc_nick_pw, irc_nick_pw, 30); config_setting_lookup_bool(settings, "irc_channel_use_ghost", &irc_use_ghost); channel->config->irc_use_ghost = irc_use_ghost; } - } libconfig->setting_lookup_bool(settings, "map_local_channel_autojoin", &local_autojoin); |