summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-04-22 16:02:21 +0000
committerrubidium <rubidium@openttd.org>2011-04-22 16:02:21 +0000
commitc61abe0019e8763c406f5694e1e6ca21dc663152 (patch)
tree1e4fc97bd220953b21f287ebe6d3c52c9844d851
parentcaf02450fb4937f08027903ff17ddc174004c2f2 (diff)
downloadopenttd-c61abe0019e8763c406f5694e1e6ca21dc663152.tar.xz
(svn r22366) -Codechange: make GetClientIP a function of the server's ClientSocket, after all the Socket is the bit that's associated with the network
-rw-r--r--src/network/network_func.h1
-rw-r--r--src/network/network_server.cpp24
-rw-r--r--src/network/network_server.h2
3 files changed, 16 insertions, 11 deletions
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 0d9e86f95..af530d068 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -68,7 +68,6 @@ bool NetworkServerStart();
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
-const char *GetClientIP(NetworkClientInfo *ci);
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 581596eb0..9a9e05fa8 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1016,18 +1016,18 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMMAND)
NetworkClientInfo *ci = this->GetInfo();
if (err != NULL) {
- IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, GetClientIP(ci));
+ IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, this->GetClientIP());
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
if ((GetCommandFlags(cp.cmd) & CMD_SERVER) && ci->client_id != CLIENT_ID_SERVER) {
- IConsolePrintF(CC_ERROR, "WARNING: server only command from: client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
+ IConsolePrintF(CC_ERROR, "WARNING: server only command from: client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
return this->SendError(NETWORK_ERROR_KICKED);
}
if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
- IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
+ IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
return this->SendError(NETWORK_ERROR_KICKED);
}
@@ -1038,7 +1038,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMMAND)
*/
if (!(cp.cmd == CMD_COMPANY_CTRL && cp.p1 == 0 && ci->client_playas == COMPANY_NEW_COMPANY) && ci->client_playas != cp.company) {
IConsolePrintF(CC_ERROR, "WARNING: client %d (IP: %s) tried to execute a command as company %d, kicking...",
- ci->client_playas + 1, GetClientIP(ci), cp.company + 1);
+ ci->client_playas + 1, this->GetClientIP(), cp.company + 1);
return this->SendError(NETWORK_ERROR_COMPANY_MISMATCH);
}
@@ -1306,7 +1306,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_CHAT)
NetworkServerSendChat(action, desttype, dest, msg, this->client_id, data);
break;
default:
- IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_id, GetClientIP(ci));
+ IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_id, this->GetClientIP());
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
return NETWORK_RECV_STATUS_OKAY;
@@ -1807,9 +1807,13 @@ void NetworkServerDailyLoop()
if ((_date % 7) == 3) NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);
}
-const char *GetClientIP(NetworkClientInfo *ci)
+/**
+ * Get the IP address/hostname of the connected client.
+ * @return The IP address.
+ */
+const char *ServerNetworkGameSocketHandler::GetClientIP()
{
- return ci->client_address.GetHostname();
+ return this->GetInfo()->client_address.GetHostname();
}
void NetworkServerShowStatusToConsole()
@@ -1838,7 +1842,7 @@ void NetworkServerShowStatusToConsole()
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s",
cs->client_id, ci->client_name, status, lag,
ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
- GetClientIP(ci));
+ cs->GetClientIP());
}
}
@@ -1921,7 +1925,7 @@ void NetworkServerKickClient(ClientID client_id)
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
{
- return NetworkServerKickOrBanIP(GetClientIP(NetworkClientInfo::GetByClientID(client_id)), ban);
+ return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban);
}
uint NetworkServerKickOrBanIP(const char *ip, bool ban)
@@ -1981,7 +1985,7 @@ void NetworkPrintClients()
ci->client_id,
ci->client_name,
ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
- _network_server ? GetClientIP(NetworkClientInfo::GetByClientID(ci->client_id)) : "");
+ _network_server ? NetworkClientSocket::GetByClientID(ci->client_id)->GetClientIP() : "");
}
}
diff --git a/src/network/network_server.h b/src/network/network_server.h
index aa8f6fc13..599ee3abf 100644
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -116,6 +116,8 @@ public:
return "server";
}
+ const char *GetClientIP();
+
static ServerNetworkGameSocketHandler *GetByClientID(ClientID client_id);
};