diff options
author | smatz <smatz@openttd.org> | 2009-03-06 12:42:01 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-03-06 12:42:01 +0000 |
commit | f3ed8268b6ead737f9fe3c32f152743a47f9cd03 (patch) | |
tree | 090a0987af3a2a82a3ef659f1c00647717f306ed /src/network/network_server.cpp | |
parent | 3d05c31031e3c6759a246cabe761b0edd01dc6a7 (diff) | |
download | openttd-f3ed8268b6ead737f9fe3c32f152743a47f9cd03.tar.xz |
(svn r15628) -Fix [FS#2705]: kicking/banning a client from the Client list window crashed the server
Diffstat (limited to 'src/network/network_server.cpp')
-rw-r--r-- | src/network/network_server.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index b4786ea28..b286fdfd8 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1766,6 +1766,33 @@ void NetworkServerSendError(ClientID client_id, NetworkErrorCode error) SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromClientID(client_id), error); } +void NetworkServerKickClient(ClientID client_id) +{ + if (client_id == CLIENT_ID_SERVER) return; + NetworkServerSendError(client_id, NETWORK_ERROR_KICKED); +} + +void NetworkServerBanIP(const char *banip) +{ + const NetworkClientInfo *ci; + uint32 ip_number = inet_addr(banip); + + /* There can be multiple clients with the same IP, kick them all */ + FOR_ALL_CLIENT_INFOS(ci) { + if (ci->client_ip == ip_number) { + NetworkServerKickClient(ci->client_id); + } + } + + /* Add user to ban-list */ + for (uint index = 0; index < lengthof(_network_ban_list); index++) { + if (_network_ban_list[index] == NULL) { + _network_ban_list[index] = strdup(banip); + break; + } + } +} + bool NetworkCompanyHasClients(CompanyID company) { const NetworkClientInfo *ci; |