2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-10-14 21:27:08 +02:00
|
|
|
/** @file network_func.h Network functions used by other parts of OpenTTD. */
|
2008-05-30 20:20:26 +02:00
|
|
|
|
|
|
|
#ifndef NETWORK_FUNC_H
|
|
|
|
#define NETWORK_FUNC_H
|
|
|
|
|
2014-02-23 20:32:32 +01:00
|
|
|
/**
|
|
|
|
* Uncomment the following define to enable command replaying.
|
|
|
|
* See docs/desync.txt for details.
|
|
|
|
*/
|
|
|
|
// #define DEBUG_DUMP_COMMANDS
|
2014-09-07 16:21:16 +02:00
|
|
|
// #define DEBUG_FAILED_DUMP_COMMANDS
|
2014-02-23 20:32:32 +01:00
|
|
|
|
2008-05-30 20:20:26 +02:00
|
|
|
#include "network_type.h"
|
|
|
|
#include "../console_type.h"
|
2009-02-09 03:09:47 +01:00
|
|
|
#include "../gfx_type.h"
|
2009-11-12 21:33:30 +01:00
|
|
|
#include "../openttd.h"
|
2010-01-15 17:41:15 +01:00
|
|
|
#include "../company_type.h"
|
2021-04-26 15:18:10 +02:00
|
|
|
#include "../string_type.h"
|
2008-05-30 20:20:26 +02:00
|
|
|
|
2008-12-22 21:42:02 +01:00
|
|
|
extern NetworkCompanyState *_network_company_states;
|
2008-05-30 20:20:26 +02:00
|
|
|
|
2008-12-22 13:59:31 +01:00
|
|
|
extern ClientID _network_own_client_id;
|
|
|
|
extern ClientID _redirect_console_to_client;
|
2008-05-30 20:20:26 +02:00
|
|
|
extern bool _network_need_advertise;
|
|
|
|
extern uint8 _network_reconnect;
|
2009-04-10 14:56:55 +02:00
|
|
|
extern StringList _network_bind_list;
|
2009-04-03 14:49:58 +02:00
|
|
|
extern StringList _network_host_list;
|
|
|
|
extern StringList _network_ban_list;
|
2008-05-30 20:20:26 +02:00
|
|
|
|
|
|
|
byte NetworkSpectatorCount();
|
2021-04-27 22:02:40 +02:00
|
|
|
bool NetworkIsValidClientName(const std::string_view client_name);
|
2021-04-22 08:01:52 +02:00
|
|
|
bool NetworkValidateClientName();
|
2021-04-27 22:02:40 +02:00
|
|
|
bool NetworkValidateClientName(std::string &client_name);
|
2008-09-30 22:39:50 +02:00
|
|
|
void NetworkUpdateClientName();
|
|
|
|
bool NetworkCompanyHasClients(CompanyID company);
|
2011-08-13 10:32:55 +02:00
|
|
|
const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password);
|
2008-05-30 20:20:26 +02:00
|
|
|
void NetworkReboot();
|
2010-10-17 19:35:42 +02:00
|
|
|
void NetworkDisconnect(bool blocking = false, bool close_admins = true);
|
2008-05-30 20:20:26 +02:00
|
|
|
void NetworkGameLoop();
|
2012-01-04 23:08:43 +01:00
|
|
|
void NetworkBackgroundLoop();
|
2021-05-04 19:32:37 +02:00
|
|
|
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16 &port, CompanyID *company_id = nullptr);
|
2021-04-29 16:43:13 +02:00
|
|
|
void NetworkStartDebugLog(const std::string &connection_string);
|
2008-12-22 19:40:57 +01:00
|
|
|
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
|
2008-05-30 20:20:26 +02:00
|
|
|
|
2008-12-22 13:59:31 +01:00
|
|
|
void NetworkUpdateClientInfo(ClientID client_id);
|
2010-04-17 13:39:46 +02:00
|
|
|
void NetworkClientsToSpectators(CompanyID cid);
|
2021-05-01 13:54:30 +02:00
|
|
|
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
|
2021-05-01 14:41:25 +02:00
|
|
|
void NetworkClientJoinGame();
|
2009-01-23 23:18:06 +01:00
|
|
|
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
2008-05-30 20:20:26 +02:00
|
|
|
void NetworkClientSendRcon(const char *password, const char *command);
|
2008-12-29 11:37:53 +01:00
|
|
|
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
|
2008-12-22 22:15:02 +01:00
|
|
|
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
2009-01-23 23:18:06 +01:00
|
|
|
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
|
|
|
bool NetworkMaxCompaniesReached();
|
|
|
|
bool NetworkMaxSpectatorsReached();
|
2008-12-22 22:26:26 +01:00
|
|
|
void NetworkPrintClients();
|
2009-11-12 21:33:30 +01:00
|
|
|
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
|
2008-05-30 20:20:26 +02:00
|
|
|
|
|
|
|
/*** Commands ran by the server ***/
|
2010-10-17 19:36:23 +02:00
|
|
|
void NetworkServerDailyLoop();
|
2008-05-30 20:20:26 +02:00
|
|
|
void NetworkServerMonthlyLoop();
|
|
|
|
void NetworkServerYearlyLoop();
|
2009-01-23 23:18:06 +01:00
|
|
|
void NetworkServerSendConfigUpdate();
|
2021-05-05 19:21:12 +02:00
|
|
|
void NetworkServerUpdateGameInfo();
|
2008-05-30 20:20:26 +02:00
|
|
|
void NetworkServerShowStatusToConsole();
|
|
|
|
bool NetworkServerStart();
|
2014-05-11 14:52:21 +02:00
|
|
|
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
|
2009-01-22 00:07:11 +01:00
|
|
|
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
|
2008-05-30 20:20:26 +02:00
|
|
|
|
|
|
|
|
2009-01-23 23:18:06 +01:00
|
|
|
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
|
2011-01-03 13:01:41 +01:00
|
|
|
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
|
2010-10-17 19:40:18 +02:00
|
|
|
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0, bool from_admin = false);
|
2008-05-30 20:20:26 +02:00
|
|
|
|
2020-01-21 16:39:10 +01:00
|
|
|
void NetworkServerKickClient(ClientID client_id, const char *reason);
|
|
|
|
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason);
|
|
|
|
uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason);
|
2009-03-06 13:42:01 +01:00
|
|
|
|
2008-08-12 00:45:11 +02:00
|
|
|
void NetworkInitChatMessage();
|
2021-05-08 10:19:42 +02:00
|
|
|
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message);
|
2008-08-12 00:45:11 +02:00
|
|
|
void NetworkUndrawChatMessage();
|
2010-12-14 15:57:51 +01:00
|
|
|
void NetworkChatMessageLoop();
|
2008-08-12 00:45:11 +02:00
|
|
|
|
2009-09-17 23:14:16 +02:00
|
|
|
void NetworkAfterNewGRFScan();
|
|
|
|
|
2008-05-30 20:20:26 +02:00
|
|
|
#endif /* NETWORK_FUNC_H */
|