diff options
author | rubidium <rubidium@openttd.org> | 2008-12-22 21:15:02 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-12-22 21:15:02 +0000 |
commit | 8e8174987230eb298b1b86a225f3c6a175b86751 (patch) | |
tree | 6a54ea9e5c67b1b74f443bacaae9ba48deb5a787 | |
parent | 648d7072a477bad26c3eaa3d620d3bc6e8d92ce6 (diff) | |
download | openttd-8e8174987230eb298b1b86a225f3c6a175b86751.tar.xz |
(svn r14715) -Codechange: move some network code from the main gui file into one of the the network files.
-rw-r--r-- | src/main_gui.cpp | 15 | ||||
-rw-r--r-- | src/network/network_client.cpp | 18 | ||||
-rw-r--r-- | src/network/network_func.h | 1 |
3 files changed, 20 insertions, 14 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp index ffa2b7feb..1befb36e7 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -317,22 +317,9 @@ struct MainWindow : Window case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all if (_networking) { const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_id); - bool teamchat = false; - if (cio == NULL) break; - /* Only companies actually playing can speak to team. Eg spectators cannot */ - if (_settings_client.gui.prefer_teamchat && IsValidCompanyID(cio->client_playas)) { - const NetworkClientInfo *ci; - FOR_ALL_ACTIVE_CLIENT_INFOS(ci) { - if (ci->client_playas == cio->client_playas && ci != cio) { - teamchat = true; - break; - } - } - } - - ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas); + ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas); } break; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index d1ff4e078..1ef35508b 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -956,4 +956,22 @@ void NetworkClientSetPassword(const char *password) SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(password); } +/** + * Tell whether the client has team members where he/she can chat to. + * @param cio client to check members of. + * @return true if there is at least one team member. + */ +bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio) +{ + /* Only companies actually playing can speak to team. Eg spectators cannot */ + if (!_settings_client.gui.prefer_teamchat || !IsValidCompanyID(cio->client_playas)) return false; + + const NetworkClientInfo *ci; + FOR_ALL_ACTIVE_CLIENT_INFOS(ci) { + if (ci->client_playas == cio->client_playas && ci != cio) return true; + } + + return false; +} + #endif /* ENABLE_NETWORK */ diff --git a/src/network/network_func.h b/src/network/network_func.h index c4c0cd6be..9d45035b7 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -41,6 +41,7 @@ bool NetworkClientConnectGame(const char *host, uint16 port); void NetworkClientSendRcon(const char *password, const char *command); void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg); void NetworkClientSetPassword(const char *password); +bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio); /*** Commands ran by the server ***/ void NetworkServerMonthlyLoop(); |