summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-04-22 15:59:32 +0000
committerrubidium <rubidium@openttd.org>2011-04-22 15:59:32 +0000
commitcaf02450fb4937f08027903ff17ddc174004c2f2 (patch)
tree2c1eb253c42ee7b57dbf8ef795b3427375ce3062
parent1c419d99bcb72eb198796f1695c003b3736abe8f (diff)
downloadopenttd-caf02450fb4937f08027903ff17ddc174004c2f2.tar.xz
(svn r22365) -Codechange: add overload of NetworkServerKickOrBanIP using the ClientID, which later resolves the IP address to ban. This to consolidate the knowledge about resolving IP addresses
-rw-r--r--src/console_cmds.cpp7
-rw-r--r--src/network/network_func.h1
-rw-r--r--src/network/network_gui.cpp2
-rw-r--r--src/network/network_server.cpp5
4 files changed, 11 insertions, 4 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 9f8591dcb..caee5190f 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -490,7 +490,7 @@ DEF_CONSOLE_CMD(ConClearBuffer)
static bool ConKickOrBan(const char *argv, bool ban)
{
- const char *ip = argv;
+ uint n;
if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID
ClientID client_id = (ClientID)atoi(argv);
@@ -513,10 +513,11 @@ static bool ConKickOrBan(const char *argv, bool ban)
}
/* When banning, kick+ban all clients with that IP */
- ip = GetClientIP(ci);
+ n = NetworkServerKickOrBanIP(client_id, ban);
+ } else {
+ n = NetworkServerKickOrBanIP(argv, ban);
}
- uint n = NetworkServerKickOrBanIP(ip, ban);
if (n == 0) {
IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
} else {
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 4649d09ad..0d9e86f95 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -75,6 +75,7 @@ void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const cha
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0, bool from_admin = false);
void NetworkServerKickClient(ClientID client_id);
+uint NetworkServerKickOrBanIP(ClientID client_id, bool ban);
uint NetworkServerKickOrBanIP(const char *ip, bool ban);
void NetworkInitChatMessage();
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index fef064a69..164f601bd 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1717,7 +1717,7 @@ static void ClientList_Kick(const NetworkClientInfo *ci)
static void ClientList_Ban(const NetworkClientInfo *ci)
{
- NetworkServerKickOrBanIP(GetClientIP(const_cast<NetworkClientInfo *>(ci)), true);
+ NetworkServerKickOrBanIP(ci->client_id, true);
}
static void ClientList_GiveMoney(const NetworkClientInfo *ci)
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 8851d1810..581596eb0 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1919,6 +1919,11 @@ void NetworkServerKickClient(ClientID client_id)
NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
}
+uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
+{
+ return NetworkServerKickOrBanIP(GetClientIP(NetworkClientInfo::GetByClientID(client_id)), ban);
+}
+
uint NetworkServerKickOrBanIP(const char *ip, bool ban)
{
/* Add address to ban-list */