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.txt for details.
17 // #define DEBUG_DUMP_COMMANDS
18 // #define DEBUG_FAILED_DUMP_COMMANDS
20 #include "core/address.h"
21 #include "network_type.h"
22 #include "../console_type.h"
23 #include "../gfx_type.h"
24 #include "../openttd.h"
25 #include "../company_type.h"
27 extern NetworkServerGameInfo _network_game_info
;
28 extern NetworkCompanyState
*_network_company_states
;
30 extern ClientID _network_own_client_id
;
31 extern ClientID _redirect_console_to_client
;
32 extern bool _network_need_advertise
;
33 extern uint8 _network_reconnect
;
34 extern StringList _network_bind_list
;
35 extern StringList _network_host_list
;
36 extern StringList _network_ban_list
;
38 byte
NetworkSpectatorCount();
39 void NetworkUpdateClientName();
40 bool NetworkCompanyHasClients(CompanyID company
);
41 const char *NetworkChangeCompanyPassword(CompanyID company_id
, const char *password
);
43 void NetworkDisconnect(bool blocking
= false, bool close_admins
= true);
44 void NetworkGameLoop();
45 void NetworkBackgroundLoop();
46 void ParseConnectionString(const char **company
, const char **port
, char *connection_string
);
47 void NetworkStartDebugLog(NetworkAddress address
);
48 void NetworkPopulateCompanyStats(NetworkCompanyStats
*stats
);
50 void NetworkUpdateClientInfo(ClientID client_id
);
51 void NetworkClientsToSpectators(CompanyID cid
);
52 void NetworkClientConnectGame(NetworkAddress address
, CompanyID join_as
, const char *join_server_password
= nullptr, const char *join_company_password
= nullptr);
53 void NetworkClientRequestMove(CompanyID company
, const char *pass
= "");
54 void NetworkClientSendRcon(const char *password
, const char *command
);
55 void NetworkClientSendChat(NetworkAction action
, DestType type
, int dest
, const char *msg
, int64 data
= 0);
56 bool NetworkClientPreferTeamChat(const NetworkClientInfo
*cio
);
57 bool NetworkCompanyIsPassworded(CompanyID company_id
);
58 bool NetworkMaxCompaniesReached();
59 bool NetworkMaxSpectatorsReached();
60 void NetworkPrintClients();
61 void NetworkHandlePauseChange(PauseMode prev_mode
, PauseMode changed_mode
);
63 /*** Commands ran by the server ***/
64 void NetworkServerDailyLoop();
65 void NetworkServerMonthlyLoop();
66 void NetworkServerYearlyLoop();
67 void NetworkServerSendConfigUpdate();
68 void NetworkServerShowStatusToConsole();
69 bool NetworkServerStart();
70 void NetworkServerNewCompany(const Company
*company
, NetworkClientInfo
*ci
);
71 bool NetworkServerChangeClientName(ClientID client_id
, const char *new_name
);
74 void NetworkServerDoMove(ClientID client_id
, CompanyID company_id
);
75 void NetworkServerSendRcon(ClientID client_id
, TextColour colour_code
, const char *string
);
76 void NetworkServerSendChat(NetworkAction action
, DestType type
, int dest
, const char *msg
, ClientID from_id
, int64 data
= 0, bool from_admin
= false);
78 void NetworkServerKickClient(ClientID client_id
, const char *reason
);
79 uint
NetworkServerKickOrBanIP(ClientID client_id
, bool ban
, const char *reason
);
80 uint
NetworkServerKickOrBanIP(const char *ip
, bool ban
, const char *reason
);
82 void NetworkInitChatMessage();
83 void CDECL
NetworkAddChatMessage(TextColour colour
, uint duration
, const char *message
, ...) WARN_FORMAT(3, 4);
84 void NetworkUndrawChatMessage();
85 void NetworkChatMessageLoop();
87 void NetworkAfterNewGRFScan();
89 #endif /* NETWORK_FUNC_H */