diff options
author | rubidium <rubidium@openttd.org> | 2010-10-15 19:35:08 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-10-15 19:35:08 +0000 |
commit | bda26d03b509c3783596c0b3431ca0c8fd7c9990 (patch) | |
tree | 9e741d9b26b296c6b5e659da0778ca8a0aabea12 /src | |
parent | f555e6d72ed960a9311b8a38321ffb3d799ecc18 (diff) | |
download | openttd-bda26d03b509c3783596c0b3431ca0c8fd7c9990.tar.xz |
(svn r20934) -Codechange: move NetworkGetClientName to the server's socket
Diffstat (limited to 'src')
-rw-r--r-- | src/network/network.cpp | 13 | ||||
-rw-r--r-- | src/network/network_internal.h | 1 | ||||
-rw-r--r-- | src/network/network_server.cpp | 29 | ||||
-rw-r--r-- | src/network/network_server.h | 1 |
4 files changed, 24 insertions, 20 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index fd9771cba..ea6f4c37a 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -137,19 +137,6 @@ NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id) return NULL; } -/* NetworkGetClientName is a server-safe function to get the name of the client - * if the user did not send it yet, Client #<no> is used. */ -void NetworkGetClientName(char *client_name, size_t size, const NetworkClientSocket *cs) -{ - const NetworkClientInfo *ci = cs->GetInfo(); - - if (StrEmpty(ci->client_name)) { - snprintf(client_name, size, "Client #%4d", cs->client_id); - } else { - ttd_strlcpy(client_name, ci->client_name, size); - } -} - byte NetworkSpectatorCount() { const NetworkClientInfo *ci; diff --git a/src/network/network_internal.h b/src/network/network_internal.h index 03ac8757d..e32b5122b 100644 --- a/src/network/network_internal.h +++ b/src/network/network_internal.h @@ -168,7 +168,6 @@ void NetworkSyncCommandQueue(NetworkClientSocket *cs); /* from network.c */ void NetworkError(StringID error_string); void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0); -void NetworkGetClientName(char *clientname, size_t size, const NetworkClientSocket *cs); uint NetworkCalculateLag(const NetworkClientSocket *cs); NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id); StringID GetNetworkErrorMsg(NetworkErrorCode err); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index b5189da0e..fa251cc81 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -80,7 +80,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta char client_name[NETWORK_CLIENT_NAME_LENGTH]; NetworkClientSocket *new_cs; - NetworkGetClientName(client_name, sizeof(client_name), this); + this->GetClientName(client_name, sizeof(client_name)); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST); @@ -164,7 +164,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO) FOR_ALL_CLIENT_SOCKETS(csi) { char client_name[NETWORK_CLIENT_NAME_LENGTH]; - NetworkGetClientName(client_name, sizeof(client_name), csi); + ((ServerNetworkGameSocketHandler*)csi)->GetClientName(client_name, sizeof(client_name)); ci = csi->GetInfo(); if (ci != NULL && Company::IsValidID(ci->client_playas)) { @@ -229,7 +229,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw NetworkClientSocket *new_cs; char client_name[NETWORK_CLIENT_NAME_LENGTH]; - NetworkGetClientName(client_name, sizeof(client_name), cs); + ((ServerNetworkGameSocketHandler*)cs)->GetClientName(client_name, sizeof(client_name)); DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str); @@ -923,7 +923,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MAP_OK) char client_name[NETWORK_CLIENT_NAME_LENGTH]; NetworkClientSocket *new_cs; - NetworkGetClientName(client_name, sizeof(client_name), this); + this->GetClientName(client_name, sizeof(client_name)); NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, NULL, this->client_id); @@ -1039,7 +1039,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ERROR) return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST); } - NetworkGetClientName(client_name, sizeof(client_name), this); + this->GetClientName(client_name, sizeof(client_name)); StringID strid = GetNetworkErrorMsg(errorno); GetString(str, strid, lastof(str)); @@ -1069,7 +1069,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_QUIT) return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST); } - NetworkGetClientName(client_name, sizeof(client_name), this); + this->GetClientName(client_name, sizeof(client_name)); NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING); @@ -1810,4 +1810,21 @@ bool NetworkCompanyHasClients(CompanyID company) return false; } + +/** + * Get the name of the client, if the user did not send it yet, Client #<no> is used. + * @param client_name The variable to write the name to. + * @param size The amount of bytes we can write. + */ +void ServerNetworkGameSocketHandler::GetClientName(char *client_name, size_t size) const +{ + const NetworkClientInfo *ci = this->GetInfo(); + + if (StrEmpty(ci->client_name)) { + snprintf(client_name, size, "Client #%4d", this->client_id); + } else { + ttd_strlcpy(client_name, ci->client_name, size); + } +} + #endif /* ENABLE_NETWORK */ diff --git a/src/network/network_server.h b/src/network/network_server.h index 2e5e3fc49..2e878dc5f 100644 --- a/src/network/network_server.h +++ b/src/network/network_server.h @@ -40,6 +40,7 @@ public: ~ServerNetworkGameSocketHandler(); NetworkRecvStatus CloseConnection(NetworkRecvStatus status); + void GetClientName(char *client_name, size_t size) const; }; DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP); |