diff options
author | adf88 <adf88@openttd.org> | 2017-09-10 14:02:13 +0000 |
---|---|---|
committer | adf88 <adf88@openttd.org> | 2017-09-10 14:02:13 +0000 |
commit | f3fbf6beb8b767e2e45591a7daa605c413e2832b (patch) | |
tree | c1394a1f786a5833d9f435be9aa3ded4f2a30bed /src | |
parent | 016a68815d099ffb505806cbd2122bd33693e7f0 (diff) | |
download | openttd-f3fbf6beb8b767e2e45591a7daa605c413e2832b.tar.xz |
(svn r27913) -Fix: 'unban' console command was not handling IPv6 adresses properly
Diffstat (limited to 'src')
-rw-r--r-- | src/console_cmds.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 9cfc8e8f9..d9706f7bf 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -562,20 +562,25 @@ DEF_CONSOLE_CMD(ConUnBan) if (argc != 2) return false; - uint index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0; - index--; - uint i = 0; + /* Try by IP. */ + uint index; + for (index = 0; index < _network_ban_list.Length(); index++) { + if (strcmp(_network_ban_list[index], argv[1]) == 0) break; + } - for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) { - if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) { - free(_network_ban_list[i]); - _network_ban_list.Erase(iter); - IConsolePrint(CC_DEFAULT, "IP unbanned."); - return true; - } + /* Try by index. */ + if (index >= _network_ban_list.Length()) { + index = atoi(argv[1]) - 1U; // let it wrap + } + + if (index < _network_ban_list.Length()) { + free(_network_ban_list[index]); + _network_ban_list.Erase(_network_ban_list.Get(index)); + IConsolePrint(CC_DEFAULT, "IP unbanned."); + } else { + IConsolePrint(CC_DEFAULT, "IP not in ban-list."); } - IConsolePrint(CC_DEFAULT, "IP not in ban-list."); return true; } |