From b4734ee9a4d352785f1332f59c363186abe29695 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 23 Dec 2008 08:39:30 +0000 Subject: (svn r14719) -Codechange: replace DEREF_CLIENT with an instance function and replace looping socket structs with info structs when the loop is only interested in the info structs (i.e. not derefing the info from sockets when one can loop info directly and the socket isn't used) --- src/network/network.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/network/network.cpp') diff --git a/src/network/network.cpp b/src/network/network.cpp index 2983446fc..0b0bfb98e 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -163,9 +163,9 @@ NetworkTCPSocketHandler *NetworkFindClientStateFromClientID(ClientID client_id) // if the user did not send it yet, Client # is used. void NetworkGetClientName(char *client_name, size_t size, const NetworkTCPSocketHandler *cs) { - const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs); + const NetworkClientInfo *ci = cs->GetInfo(); - if (ci->client_name[0] == '\0') { + if (StrEmpty(ci->client_name)) { snprintf(client_name, size, "Client #%4d", cs->client_id); } else { ttd_strlcpy(client_name, ci->client_name, size); @@ -174,11 +174,11 @@ void NetworkGetClientName(char *client_name, size_t size, const NetworkTCPSocket byte NetworkSpectatorCount() { - NetworkTCPSocketHandler *cs; + const NetworkClientInfo *ci; byte count = 0; - FOR_ALL_CLIENTS(cs) { - if (DEREF_CLIENT_INFO(cs)->client_playas == COMPANY_SPECTATOR) count++; + FOR_ALL_CLIENT_INFOS(ci) { + if (ci->client_playas == COMPANY_SPECTATOR) count++; } return count; @@ -360,11 +360,10 @@ char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last) /* Count the number of active clients connected */ static uint NetworkCountActiveClients() { - NetworkTCPSocketHandler *cs; + const NetworkClientInfo *ci; uint count = 0; - FOR_ALL_CLIENTS(cs) { - const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs); + FOR_ALL_CLIENT_INFOS(ci) { if (IsValidCompanyID(ci->client_playas)) count++; } @@ -439,7 +438,7 @@ static NetworkTCPSocketHandler *NetworkAllocClient(SOCKET s) cs->last_frame_server = _frame_counter; if (_network_server) { - NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs); + NetworkClientInfo *ci = cs->GetInfo(); memset(ci, 0, sizeof(*ci)); cs->client_id = _network_client_id++; @@ -495,7 +494,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs) cs->Destroy(); // Close the gap in the client-list - ci = DEREF_CLIENT_INFO(cs); + ci = cs->GetInfo(); if (_network_server) { // We just lost one client :( @@ -617,7 +616,7 @@ static void NetworkAcceptClients() // the client stays inactive cs->status = STATUS_INACTIVE; - DEREF_CLIENT_INFO(cs)->client_ip = sin.sin_addr.s_addr; // Save the IP of the client + cs->GetInfo()->client_ip = sin.sin_addr.s_addr; // Save the IP of the client } } -- cgit v1.2.3-54-g00ecf