changeset 18279:574646cd34a7 draft

(svn r23115) -Fix [FS#4813]: allow accessing the server's client info as well in the admin network (dihedral)
author rubidium <rubidium@openttd.org>
date Fri, 04 Nov 2011 22:32:21 +0000
parents 11ed8abd8930
children 7910779b241a
files src/network/network_admin.cpp src/network/network_admin.h
diffstat 2 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -226,18 +226,18 @@
 
 /**
  * Send an initial set of data from some client's information.
- * @param cs The information about a client.
+ * @param cs The socket of the client.
+ * @param ci The information about the client.
  */
-NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs)
+NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
 {
 	/* Only send data when we're a proper client, not just someone trying to query the server. */
-	const NetworkClientInfo *ci = cs->GetInfo();
 	if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
 
 	Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO);
 
 	p->Send_uint32(ci->client_id);
-	p->Send_string(const_cast<NetworkAddress &>(cs->client_address).GetHostname());
+	p->Send_string(cs == NULL ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
 	p->Send_string(ci->client_name);
 	p->Send_uint8 (ci->client_lang);
 	p->Send_uint32(ci->join_date);
@@ -658,12 +658,17 @@
 			/* The admin is requesting client info. */
 			const NetworkClientSocket *cs;
 			if (d1 == UINT32_MAX) {
+				this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
 				FOR_ALL_CLIENT_SOCKETS(cs) {
-					this->SendClientInfo(cs);
+					this->SendClientInfo(cs, cs->GetInfo());
 				}
 			} else {
-				cs = NetworkClientSocket::GetByClientID((ClientID)d1);
-				if (cs != NULL) this->SendClientInfo(cs);
+				if (d1 == CLIENT_ID_SERVER) {
+					this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
+				} else {
+					cs = NetworkClientSocket::GetByClientID((ClientID)d1);
+					if (cs != NULL) this->SendClientInfo(cs, cs->GetInfo());
+				}
 			}
 			break;
 
@@ -745,7 +750,7 @@
 	ServerNetworkAdminSocketHandler *as;
 	FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
 		if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
-			as->SendClientInfo(cs);
+			as->SendClientInfo(cs, cs->GetInfo());
 			if (new_client) {
 				as->SendClientJoin(cs->client_id);
 			}
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -51,7 +51,7 @@
 
 	NetworkRecvStatus SendDate();
 	NetworkRecvStatus SendClientJoin(ClientID client_id);
-	NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs);
+	NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
 	NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
 	NetworkRecvStatus SendClientQuit(ClientID client_id);
 	NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);