Merge branch 'cpp-11' into jgrpp

This commit is contained in:
Jonathan G Rennison
2017-10-05 18:20:54 +01:00
39 changed files with 6320 additions and 298 deletions

View File

@@ -555,29 +555,36 @@ DEF_CONSOLE_CMD(ConBan)
DEF_CONSOLE_CMD(ConUnBan)
{
if (argc == 0) {
IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | client-id>'");
IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | banlist-index>'");
IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
return true;
}
if (argc != 2) return false;
uint index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0;
index--;
uint i = 0;
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 IP. */
uint index;
for (index = 0; index < _network_ban_list.Length(); index++) {
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
}
/* Try by index. */
if (index >= _network_ban_list.Length()) {
index = atoi(argv[1]) - 1U; // let it wrap
}
if (index < _network_ban_list.Length()) {
char msg[64];
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
IConsolePrint(CC_DEFAULT, msg);
free(_network_ban_list[index]);
_network_ban_list.Erase(_network_ban_list.Get(index));
} else {
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'");
}
IConsolePrint(CC_DEFAULT, "IP not in ban-list.");
return true;
}