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/>.
8 /** @file network_func.h Network functions used by other parts of OpenTTD. */
10 #ifndef NETWORK_FUNC_H
11 #define NETWORK_FUNC_H
14 * Uncomment the following define to enable command replaying.
15 * See docs/desync.md for details.
17 // #define DEBUG_DUMP_COMMANDS
18 // #define DEBUG_FAILED_DUMP_COMMANDS
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"
27 extern ClientID _network_own_client_id
;
28 extern ClientID _redirect_console_to_client
;
29 extern uint8_t _network_reconnect
;
30 extern StringList _network_bind_list
;
31 extern StringList _network_host_list
;
32 extern StringList _network_ban_list
;
34 uint8_t NetworkSpectatorCount();
35 bool NetworkIsValidClientName(const std::string_view client_name
);
36 bool NetworkValidateOurClientName();
37 bool NetworkValidateClientName(std::string
&client_name
);
38 bool NetworkValidateServerName(std::string
&server_name
);
39 void NetworkUpdateClientName(const std::string
&client_name
);
40 void NetworkUpdateServerGameType();
41 bool NetworkCompanyHasClients(CompanyID company
);
43 void NetworkDisconnect(bool close_admins
= true);
44 void NetworkGameLoop();
45 void NetworkBackgroundLoop();
46 std::string_view
ParseFullConnectionString(const std::string
&connection_string
, uint16_t &port
, CompanyID
*company_id
= nullptr);
47 void NetworkPopulateCompanyStats(NetworkCompanyStats
*stats
);
49 void NetworkUpdateClientInfo(ClientID client_id
);
50 void NetworkClientsToSpectators(CompanyID cid
);
51 bool NetworkClientConnectGame(const std::string
&connection_string
, CompanyID default_company
, const std::string
&join_server_password
= "");
52 void NetworkClientJoinGame();
53 void NetworkClientRequestMove(CompanyID company
);
54 void NetworkClientSendRcon(const std::string
&password
, const std::string
&command
);
55 void NetworkClientSendChat(NetworkAction action
, DestType type
, int dest
, const std::string
&msg
, int64_t data
= 0);
56 bool NetworkClientPreferTeamChat(const NetworkClientInfo
*cio
);
57 uint
NetworkMaxCompaniesAllowed();
58 bool NetworkMaxCompaniesReached();
59 void NetworkPrintClients();
60 std::string_view
NetworkGetPublicKeyOfClient(ClientID client_id
);
61 void NetworkHandlePauseChange(PauseMode prev_mode
, PauseMode changed_mode
);
63 void NetworkOnGameStart();
65 /*** Commands ran by the server ***/
66 void NetworkServerSendConfigUpdate();
67 void NetworkServerUpdateGameInfo();
68 void NetworkServerShowStatusToConsole();
69 bool NetworkServerStart();
70 void NetworkServerNewCompany(const Company
*company
, NetworkClientInfo
*ci
);
71 bool NetworkServerChangeClientName(ClientID client_id
, const std::string
&new_name
);
74 bool NetworkCanJoinCompany(CompanyID company_id
);
75 void NetworkServerDoMove(ClientID client_id
, CompanyID company_id
);
76 void NetworkServerSendRcon(ClientID client_id
, TextColour colour_code
, const std::string
&string
);
77 void NetworkServerSendChat(NetworkAction action
, DestType type
, int dest
, const std::string
&msg
, ClientID from_id
, int64_t data
= 0, bool from_admin
= false);
78 void NetworkServerSendExternalChat(const std::string
&source
, TextColour colour
, const std::string
&user
, const std::string
&msg
);
80 void NetworkServerKickClient(ClientID client_id
, const std::string
&reason
);
81 uint
NetworkServerKickOrBanIP(ClientID client_id
, bool ban
, const std::string
&reason
);
82 uint
NetworkServerKickOrBanIP(const std::string
&ip
, bool ban
, const std::string
&reason
);
84 void NetworkInitChatMessage();
85 void NetworkReInitChatBoxSize();
86 void CDECL
NetworkAddChatMessage(TextColour colour
, uint duration
, const std::string
&message
);
87 void NetworkUndrawChatMessage();
89 void NetworkAfterNewGRFScan();
91 #endif /* NETWORK_FUNC_H */