diff options
author | rubidium <rubidium@openttd.org> | 2011-04-22 15:54:16 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-04-22 15:54:16 +0000 |
commit | bc9a803ea956620574896f95932a9973d7601fdd (patch) | |
tree | ca9a419644a1eac8f839925a51a0a5641abd695a | |
parent | 393fb8e46b8ad9bb65dbea391ad225d0fcfffcac (diff) | |
download | openttd-bc9a803ea956620574896f95932a9973d7601fdd.tar.xz |
(svn r22362) -Codechange: NetworkFindClientInfoFromClientID -> NetworkClientInfo::GetByClientID
-rw-r--r-- | src/company_cmd.cpp | 2 | ||||
-rw-r--r-- | src/console_cmds.cpp | 10 | ||||
-rw-r--r-- | src/main_gui.cpp | 4 | ||||
-rw-r--r-- | src/network/network.cpp | 2 | ||||
-rw-r--r-- | src/network/network_admin.cpp | 2 | ||||
-rw-r--r-- | src/network/network_base.h | 2 | ||||
-rw-r--r-- | src/network/network_chat_gui.cpp | 4 | ||||
-rw-r--r-- | src/network/network_client.cpp | 18 | ||||
-rw-r--r-- | src/network/network_func.h | 1 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 6 | ||||
-rw-r--r-- | src/network/network_server.cpp | 26 |
11 files changed, 39 insertions, 38 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 56920a270..4944b66b1 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -812,7 +812,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 #ifdef ENABLE_NETWORK /* Has the network client a correct ClientIndex? */ if (!(flags & DC_EXEC)) return CommandCost(); - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci == NULL) return CommandCost(); /* Delete multiplayer progress bar */ diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index d39b0373b..9f8591dcb 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -500,7 +500,7 @@ static bool ConKickOrBan(const char *argv, bool ban) return true; } - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci == NULL) { IConsoleError("Invalid client"); return true; @@ -695,7 +695,7 @@ DEF_CONSOLE_CMD(ConClientNickChange) return true; } - if (NetworkFindClientInfoFromClientID(client_id) == NULL) { + if (NetworkClientInfo::GetByClientID(client_id) == NULL) { IConsoleError("Invalid client"); return true; } @@ -723,7 +723,7 @@ DEF_CONSOLE_CMD(ConJoinCompany) return true; } - if (NetworkFindClientInfoFromClientID(_network_own_client_id)->client_playas == company_id) { + if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) { IConsoleError("You are already there!"); return true; } @@ -762,7 +762,7 @@ DEF_CONSOLE_CMD(ConMoveClient) return true; } - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID((ClientID)atoi(argv[1])); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)atoi(argv[1])); CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2])); /* check the client exists */ @@ -824,7 +824,7 @@ DEF_CONSOLE_CMD(ConResetCompany) IConsoleError("Cannot remove company: a client is connected to that company."); return false; } - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); if (ci->client_playas == index) { IConsoleError("Cannot remove company: the server is connected to that company."); return true; diff --git a/src/main_gui.cpp b/src/main_gui.cpp index d87f1dbef..7c282c292 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -377,7 +377,7 @@ struct MainWindow : Window #ifdef ENABLE_NETWORK case GHK_CHAT: // smart chat; send to team if any, otherwise to all if (_networking) { - const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id); + const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id); if (cio == NULL) break; ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas); @@ -390,7 +390,7 @@ struct MainWindow : Window case GHK_CHAT_COMPANY: // send text to all team mates if (_networking) { - const NetworkClientInfo *cio = NetworkFindClientInfoFromClientID(_network_own_client_id); + const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id); if (cio == NULL) break; ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas); diff --git a/src/network/network.cpp b/src/network/network.cpp index 308a493b0..c857c0784 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -108,7 +108,7 @@ NetworkClientInfo::~NetworkClientInfo() * @param client_id the ClientID to search for * @return return a pointer to the corresponding NetworkClientInfo struct or NULL when not found */ -NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id) +/* static */ NetworkClientInfo *NetworkClientInfo::GetByClientID(ClientID client_id) { NetworkClientInfo *ci; diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index b6d5c3e6c..721773c5d 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -576,7 +576,7 @@ DEF_ADMIN_RECEIVE_COMMAND(Server, ADMIN_PACKET_ADMIN_POLL) this->SendClientInfo(ci); } } else { - ci = NetworkFindClientInfoFromClientID((ClientID)d1); + ci = NetworkClientInfo::GetByClientID((ClientID)d1); if (ci != NULL) this->SendClientInfo(ci); } break; diff --git a/src/network/network_base.h b/src/network/network_base.h index 86a444cb1..4540ca962 100644 --- a/src/network/network_base.h +++ b/src/network/network_base.h @@ -32,6 +32,8 @@ struct NetworkClientInfo : NetworkClientInfoPool::PoolItem<&_networkclientinfo_p NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {} ~NetworkClientInfo(); + + static NetworkClientInfo *GetByClientID(ClientID client_id); }; #define FOR_ALL_CLIENT_INFOS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientInfo, clientinfo_index, var, start) diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 0a0d51f39..6a39ffef0 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -468,7 +468,7 @@ struct NetworkChatWindow : public QueryStringBaseWindow { if (widget != NWCW_DESTINATION) return; if (this->dtype == DESTTYPE_CLIENT) { - SetDParamStr(0, NetworkFindClientInfoFromClientID((ClientID)this->dest)->client_name); + SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name); } Dimension d = GetStringBoundingBox(this->dest_string); d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; @@ -481,7 +481,7 @@ struct NetworkChatWindow : public QueryStringBaseWindow { if (widget != NWCW_DESTINATION) return; if (this->dtype == DESTTYPE_CLIENT) { - SetDParamStr(0, NetworkFindClientInfoFromClientID((ClientID)this->dest)->client_name); + SetDParamStr(0, NetworkClientInfo::GetByClientID((ClientID)this->dest)->client_name); } DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->dest_string, TC_BLACK, SA_RIGHT); } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 66eff8fdb..d86857a63 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -556,7 +556,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CLIENT_INFO) if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST; - ci = NetworkFindClientInfoFromClientID(client_id); + ci = NetworkClientInfo::GetByClientID(client_id); if (ci != NULL) { if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) { /* Client name changed, display the change */ @@ -909,7 +909,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHAT) p->Recv_string(msg, NETWORK_CHAT_LENGTH); int64 data = p->Recv_uint64(); - ci_to = NetworkFindClientInfoFromClientID(client_id); + ci_to = NetworkClientInfo::GetByClientID(client_id); if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY; /* Did we initiate the action locally? */ @@ -918,7 +918,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHAT) case NETWORK_ACTION_CHAT_CLIENT: /* For speaking to client we need the client-name */ snprintf(name, sizeof(name), "%s", ci_to->client_name); - ci = NetworkFindClientInfoFromClientID(_network_own_client_id); + ci = NetworkClientInfo::GetByClientID(_network_own_client_id); break; /* For speaking to company or giving money, we need the company-name */ @@ -930,7 +930,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHAT) SetDParam(0, ci_to->client_playas); GetString(name, str, lastof(name)); - ci = NetworkFindClientInfoFromClientID(_network_own_client_id); + ci = NetworkClientInfo::GetByClientID(_network_own_client_id); break; } @@ -954,7 +954,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_ERROR_QUIT) ClientID client_id = (ClientID)p->Recv_uint32(); - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci != NULL) { NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8())); delete ci; @@ -971,7 +971,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_QUIT) ClientID client_id = (ClientID)p->Recv_uint32(); - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci != NULL) { NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING); delete ci; @@ -991,7 +991,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_JOIN) ClientID client_id = (ClientID)p->Recv_uint32(); - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci != NULL) { NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name); } @@ -1056,7 +1056,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MOVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; } - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); /* Just make sure we do not try to use a client_index that does not exist */ if (ci == NULL) return NETWORK_RECV_STATUS_OKAY; @@ -1169,7 +1169,7 @@ void NetworkClientsToSpectators(CompanyID cid) void NetworkUpdateClientName() { - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(_network_own_client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id); if (ci == NULL) return; diff --git a/src/network/network_func.h b/src/network/network_func.h index f50406140..4649d09ad 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -68,7 +68,6 @@ bool NetworkServerStart(); void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded); bool NetworkServerChangeClientName(ClientID client_id, const char *new_name); -NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id); const char *GetClientIP(NetworkClientInfo *ci); void NetworkServerDoMove(ClientID client_id, CompanyID company_id); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 2f4af939b..fef064a69 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1772,7 +1772,7 @@ struct NetworkClientListPopupWindow : Window { this->desired_location.x = x; this->desired_location.y = y; - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (_network_own_client_id != ci->client_id) { this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient); @@ -1848,7 +1848,7 @@ struct NetworkClientListPopupWindow : Window { this->SetDirty(); } else { if (index < this->actions.Length() && _cursor.pos.y >= this->top) { - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(this->client_id); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(this->client_id); if (ci != NULL) this->actions[index].proc(ci); } @@ -1864,7 +1864,7 @@ static void PopupClientList(ClientID client_id, int x, int y) { DeleteWindowByClass(WC_CLIENT_LIST_POPUP); - if (NetworkFindClientInfoFromClientID(client_id) == NULL) return; + if (NetworkClientInfo::GetByClientID(client_id) == NULL) return; new NetworkClientListPopupWindow(&_client_list_popup_desc, x, y, client_id); } diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index eef194a98..142b83b5b 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -326,7 +326,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo() memset(clients, 0, sizeof(clients)); /* Add the local player (if not dedicated) */ - const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER); + const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); if (ci != NULL && Company::IsValidID(ci->client_playas)) { strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas])); } @@ -487,7 +487,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome() } } /* Also send the info of the server */ - return this->SendClientInfo(NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER)); + return this->SendClientInfo(NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER)); } NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait() @@ -1177,7 +1177,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co case DESTTYPE_CLIENT: /* Are we sending to the server? */ if ((ClientID)dest == CLIENT_ID_SERVER) { - ci = NetworkFindClientInfoFromClientID(from_id); + ci = NetworkClientInfo::GetByClientID(from_id); /* Display the text locally, and that is it */ if (ci != NULL) { NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data); @@ -1199,8 +1199,8 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co /* Display the message locally (so you know you have sent it) */ if (from_id != (ClientID)dest) { if (from_id == CLIENT_ID_SERVER) { - ci = NetworkFindClientInfoFromClientID(from_id); - ci_to = NetworkFindClientInfoFromClientID((ClientID)dest); + ci = NetworkClientInfo::GetByClientID(from_id); + ci_to = NetworkClientInfo::GetByClientID((ClientID)dest); if (ci != NULL && ci_to != NULL) { NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), true, ci_to->client_name, msg, data); } @@ -1233,8 +1233,8 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co NetworkAdminChat(action, desttype, from_id, msg, data, from_admin); } - ci = NetworkFindClientInfoFromClientID(from_id); - ci_own = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER); + ci = NetworkClientInfo::GetByClientID(from_id); + ci_own = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) { NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data); if (from_id == CLIENT_ID_SERVER) show_local = false; @@ -1272,7 +1272,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co NetworkAdminChat(action, desttype, from_id, msg, data, from_admin); - ci = NetworkFindClientInfoFromClientID(from_id); + ci = NetworkClientInfo::GetByClientID(from_id); if (ci != NULL) { NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data); } @@ -1502,7 +1502,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats) void NetworkUpdateClientInfo(ClientID client_id) { NetworkClientSocket *cs; - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); if (ci == NULL) return; @@ -1547,7 +1547,7 @@ static void NetworkAutoCleanCompanies() } if (!_network_dedicated) { - ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER); + ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true; } @@ -1622,7 +1622,7 @@ bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]) } } /* Check if it is the same as the server-name */ - ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER); + ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); if (ci != NULL) { if (strcmp(ci->client_name, new_name) == 0) found_name = false; // name already in use } @@ -1653,7 +1653,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name) if (strcmp(ci->client_name, new_name) == 0) return false; } - ci = NetworkFindClientInfoFromClientID(client_id); + ci = NetworkClientInfo::GetByClientID(client_id); if (ci == NULL) return false; NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name); @@ -1880,7 +1880,7 @@ void NetworkServerDoMove(ClientID client_id, CompanyID company_id) /* Only allow non-dedicated servers and normal clients to be moved */ if (client_id == CLIENT_ID_SERVER && _network_dedicated) return; - NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id); /* No need to waste network resources if the client is in the company already! */ if (ci->client_playas == company_id) return; |