changeset 17602:9232c1bd93b2 draft

(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
author rubidium <rubidium@openttd.org>
date Fri, 22 Apr 2011 16:02:21 +0000 (2011-04-22)
parents 670b50f32c98
children dafbbdd3753c
files src/network/network_func.h src/network/network_server.cpp src/network/network_server.h
diffstat 3 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -68,7 +68,6 @@
 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);
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1016,18 +1016,18 @@
 	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 @@
 	 */
 	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 @@
 			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 @@
 	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 @@
 		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 @@
 
 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 @@
 				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() : "");
 	}
 }
 
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -116,6 +116,8 @@
 		return "server";
 	}
 
+	const char *GetClientIP();
+
 	static ServerNetworkGameSocketHandler *GetByClientID(ClientID client_id);
 };