1 /* 2 * This file is part of OpenTTD. 3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 6 */ 7 8 /** @file network_func.h Network functions used by other parts of OpenTTD. */ 9 10 #ifndef NETWORK_FUNC_H 11 #define NETWORK_FUNC_H 12 13 /** 14 * Uncomment the following define to enable command replaying. 15 * See docs/desync.txt for details. 16 */ 17 // #define DEBUG_DUMP_COMMANDS 18 // #define DEBUG_FAILED_DUMP_COMMANDS 19 20 #include "network_type.h" 21 #include "../console_type.h" 22 #include "../gfx_type.h" 23 #include "../openttd.h" 24 #include "../company_type.h" 25 #include "../string_type.h" 26 27 extern NetworkCompanyState *_network_company_states; 28 29 extern ClientID _network_own_client_id; 30 extern ClientID _redirect_console_to_client; 31 extern uint8 _network_reconnect; 32 extern StringList _network_bind_list; 33 extern StringList _network_host_list; 34 extern StringList _network_ban_list; 35 36 byte NetworkSpectatorCount(); 37 bool NetworkIsValidClientName(const std::string_view client_name); 38 bool NetworkValidateOurClientName(); 39 bool NetworkValidateClientName(std::string &client_name); 40 bool NetworkValidateServerName(std::string &server_name); 41 void NetworkUpdateClientName(const std::string &client_name); 42 void NetworkUpdateServerGameType(); 43 bool NetworkCompanyHasClients(CompanyID company); 44 std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password); 45 void NetworkReboot(); 46 void NetworkDisconnect(bool blocking = false, bool close_admins = true); 47 void NetworkGameLoop(); 48 void NetworkBackgroundLoop(); 49 std::string_view ParseFullConnectionString(const std::string &connection_string, uint16 &port, CompanyID *company_id = nullptr); 50 void NetworkStartDebugLog(const std::string &connection_string); 51 void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); 52 53 void NetworkUpdateClientInfo(ClientID client_id); 54 void NetworkClientsToSpectators(CompanyID cid); 55 bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password = "", const std::string &join_company_password = ""); 56 void NetworkClientJoinGame(); 57 void NetworkClientRequestMove(CompanyID company, const std::string &pass = ""); 58 void NetworkClientSendRcon(const std::string &password, const std::string &command); 59 void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data = 0); 60 bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio); 61 bool NetworkCompanyIsPassworded(CompanyID company_id); 62 bool NetworkMaxCompaniesReached(); 63 void NetworkPrintClients(); 64 void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode); 65 66 /*** Commands ran by the server ***/ 67 void NetworkServerDailyLoop(); 68 void NetworkServerMonthlyLoop(); 69 void NetworkServerYearlyLoop(); 70 void NetworkServerSendConfigUpdate(); 71 void NetworkServerUpdateGameInfo(); 72 void NetworkServerShowStatusToConsole(); 73 bool NetworkServerStart(); 74 void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci); 75 bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name); 76 77 78 void NetworkServerDoMove(ClientID client_id, CompanyID company_id); 79 void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string); 80 void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false); 81 void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg); 82 83 void NetworkServerKickClient(ClientID client_id, const std::string &reason); 84 uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason); 85 uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason); 86 87 void NetworkInitChatMessage(); 88 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message); 89 void NetworkUndrawChatMessage(); 90 void NetworkChatMessageLoop(); 91 92 void NetworkAfterNewGRFScan(); 93 94 #endif /* NETWORK_FUNC_H */ 95