summaryrefslogtreecommitdiff
path: root/src/network/network.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-23 08:39:30 +0000
committerrubidium <rubidium@openttd.org>2008-12-23 08:39:30 +0000
commit9a965577636e5369dd99ac00c2d68cf41ad19697 (patch)
tree195e0e3d8e52be7e4c308d394d03d4468a967c67 /src/network/network.cpp
parentbdd92008cf1506823baba4d83d4d59b185b3decf (diff)
downloadopenttd-9a965577636e5369dd99ac00c2d68cf41ad19697.tar.xz
(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)
Diffstat (limited to 'src/network/network.cpp')
-rw-r--r--src/network/network.cpp21
1 files changed, 10 insertions, 11 deletions
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 #<no> 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
}
}