diff options
author | Darkvater <Darkvater@openttd.org> | 2006-01-19 15:58:57 +0000 |
---|---|---|
committer | Darkvater <Darkvater@openttd.org> | 2006-01-19 15:58:57 +0000 |
commit | ad47f3a6a288499aacef5e8410f207dda7594058 (patch) | |
tree | 709cb38fd32c03459358ff86e3bdc3e81f0102b9 | |
parent | 6be0fdfb74bb49eac1b71c005bc66ca948629faa (diff) | |
download | openttd-ad47f3a6a288499aacef5e8410f207dda7594058.tar.xz |
(svn r3407) - Feature: Kick and ban now with IP numbers.
-rw-r--r-- | console_cmds.c | 29 | ||||
-rw-r--r-- | network.c | 15 | ||||
-rw-r--r-- | network_data.h | 1 |
3 files changed, 36 insertions, 9 deletions
diff --git a/console_cmds.c b/console_cmds.c index e8bd432e6..6f7e7cb90 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -365,26 +365,31 @@ DEF_CONSOLE_CMD(ConBan) uint32 index; if (argc == 0) { - IConsoleHelp("Ban a player from a network game. Usage: 'ban <client-id>'"); + IConsoleHelp("Ban a player from a network game. Usage: 'ban <ip | client-id>'"); IConsoleHelp("For client-id's, see the command 'clients'"); return true; } if (argc != 2) return false; - index = atoi(argv[1]); + if (strchr(argv[1], '.') == NULL) { + index = atoi(argv[1]); + ci = NetworkFindClientFromIndex(index); + } else { + ci = NetworkFindClientFromIP(argv[1]); + index = (ci == NULL) ? 0 : ci->client_index; + } if (index == NETWORK_SERVER_INDEX) { IConsolePrint(_icolour_def, "Silly boy, you can not ban yourself!"); return true; } + if (index == 0) { IConsoleError("Invalid Client-ID"); return true; } - ci = NetworkFindClientInfoFromIndex(index); - if (ci != NULL) { uint i; /* Add user to ban-list */ @@ -407,7 +412,7 @@ DEF_CONSOLE_CMD(ConUnBan) uint i, index; if (argc == 0) { - IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | id>'"); + IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | client-id>'"); IConsoleHelp("For a list of banned IP's, see the command 'banlist'"); return true; } @@ -528,25 +533,31 @@ DEF_CONSOLE_CMD(ConKick) uint32 index; if (argc == 0) { - IConsoleHelp("Kick a player from a network game. Usage: 'kick <client-id>'"); + IConsoleHelp("Kick a player from a network game. Usage: 'kick <ip | client-id>'"); IConsoleHelp("For client-id's, see the command 'clients'"); return true; } if (argc != 2) return false; - index = atoi(argv[1]); + if (strchr(argv[1], '.') == NULL) { + index = atoi(argv[1]); + ci = NetworkFindClientFromIndex(index); + } else { + ci = NetworkFindClientFromIP(argv[1]); + index = (ci == NULL) ? 0 : ci->client_index; + } + if (index == NETWORK_SERVER_INDEX) { IConsolePrint(_icolour_def, "Silly boy, you can not kick yourself!"); return true; } + if (index == 0) { IConsoleError("Invalid client-id"); return true; } - ci = NetworkFindClientInfoFromIndex(index); - if (ci != NULL) { SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED); } else @@ -65,6 +65,21 @@ NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index) return NULL; } +/** Return the CI for a given IP + * @param ip IP of the client we are looking for. This must be in string-format + * @return return a pointer to the corresponding NetworkClientInfo struct or NULL on failure */ +NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip) +{ + NetworkClientInfo *ci; + uint32 ip_number = inet_addr(ip); + + for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) { + if (ci->client_ip == ip_number) return ci; + } + + return NULL; +} + // Function that looks up the CS for a given client-index NetworkClientState *NetworkFindClientStateFromIndex(uint16 client_index) { diff --git a/network_data.h b/network_data.h index b4dea28b1..553680fc2 100644 --- a/network_data.h +++ b/network_data.h @@ -226,6 +226,7 @@ void NetworkGetClientName(char *clientname, size_t size, const NetworkClientStat uint NetworkCalculateLag(const NetworkClientState *cs); byte NetworkGetCurrentLanguageIndex(void); NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index); +NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip); NetworkClientState *NetworkFindClientStateFromIndex(uint16 client_index); unsigned long NetworkResolveHost(const char *hostname); |