diff options
author | rubidium <rubidium@openttd.org> | 2008-12-23 20:52:27 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-12-23 20:52:27 +0000 |
commit | afddfcb2b1a37358459158ce83a64535f13cd05e (patch) | |
tree | 5fc12b987e4ccf94d7c727fd7c3eccc1826b870a /src/network/network_client.cpp | |
parent | 94dd23aaf86cb1c22ce78d8555261d045de0ee60 (diff) | |
download | openttd-afddfcb2b1a37358459158ce83a64535f13cd05e.tar.xz |
(svn r14730) -Codechange: remove the need for networkclientsockets and networkclientinfo structs to be in a contiguous piece of memory and put them in a pool.
-Note: 255 should really be enough for now... making it any more means network protocol bumps.
Diffstat (limited to 'src/network/network_client.cpp')
-rw-r--r-- | src/network/network_client.cpp | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index f4d49539e..5abb151fd 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -420,23 +420,15 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO) } // We don't have this client_id yet, find an empty client_id, and put the data there - for (int i = 0; i < MAX_CLIENT_SLOTS; i++) { - ci = GetNetworkClientInfo(i); - if (!ci->IsValid()) break; - } - if (ci != GetNetworkClientInfo(MAX_CLIENT_SLOTS)) { - ci->client_id = client_id; - ci->client_playas = playas; - - strecpy(ci->client_name, name, lastof(ci->client_name)); + ci = new NetworkClientInfo(client_id); + ci->client_playas = playas; + if (client_id == _network_own_client_id) MY_CLIENT->SetInfo(ci); - InvalidateWindow(WC_CLIENT_LIST, 0); + strecpy(ci->client_name, name, lastof(ci->client_name)); - return NETWORK_RECV_STATUS_OKAY; - } + InvalidateWindow(WC_CLIENT_LIST, 0); - // Here the program should never ever come..... - return NETWORK_RECV_STATUS_MALFORMED_PACKET; + return NETWORK_RECV_STATUS_OKAY; } DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR) @@ -765,9 +757,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT) ci = NetworkFindClientInfoFromClientID(client_id); if (ci != NULL) { NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str); - - // The client is gone, give the NetworkClientInfo free - ci->client_id = INVALID_CLIENT_ID; + delete ci; } InvalidateWindow(WC_CLIENT_LIST, 0); @@ -786,9 +776,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT) ci = NetworkFindClientInfoFromClientID(client_id); if (ci != NULL) { NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str); - - // The client is gone, give the NetworkClientInfo free - ci->client_id = INVALID_CLIENT_ID; + delete ci; } else { DEBUG(net, 0, "Unknown client (%d) is leaving the game", client_id); } |