OpenTTD Source 20241224-master-gf74b0cf984
network_func.h
Go to the documentation of this file.
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
10#ifndef NETWORK_FUNC_H
11#define NETWORK_FUNC_H
12
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
29extern uint8_t _network_reconnect;
33
34uint8_t NetworkSpectatorCount();
35bool NetworkIsValidClientName(const std::string_view client_name);
37bool NetworkValidateClientName(std::string &client_name);
38bool NetworkValidateServerName(std::string &server_name);
39void NetworkUpdateClientName(const std::string &client_name);
42void NetworkReboot();
43void NetworkDisconnect(bool close_admins = true);
44void NetworkGameLoop();
46std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id = nullptr);
48
49void NetworkUpdateClientInfo(ClientID client_id);
51bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password = "");
54void NetworkClientSendRcon(const std::string &password, const std::string &command);
55void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data = 0);
60std::string_view NetworkGetPublicKeyOfClient(ClientID client_id);
61void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
62
64
65/*** Commands ran by the server ***/
69bool NetworkServerStart();
70void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
71bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name);
72
73
74bool NetworkCanJoinCompany(CompanyID company_id);
75void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
76void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string);
77void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data = 0, bool from_admin = false);
78void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
79
80void NetworkServerKickClient(ClientID client_id, const std::string &reason);
81uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason);
82uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason);
83
86void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message);
88
90
91#endif /* NETWORK_FUNC_H */
Owner
Enum for all companies/owners.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
void NetworkUpdateClientName(const std::string &client_name)
Send the server our name as callback from the setting.
StringList _network_host_list
The servers we know.
Definition network.cpp:74
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
void NetworkPrintClients()
Print all the clients to the console.
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
void NetworkClientJoinGame()
Actually perform the joining to the server.
Definition network.cpp:818
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password="")
Join a client to the server at with the given connection string.
Definition network.cpp:785
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string)
Send an rcon reply to the client.
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
Definition network.cpp:71
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
Add a text message to the 'chat window' to be shown.
void NetworkOnGameStart()
Perform tasks when the server is started.
Definition network.cpp:945
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
void NetworkClientRequestMove(CompanyID company)
Notify the server of this client wanting to be moved to another company.
uint8_t _network_reconnect
Reconnect timeout.
Definition network.cpp:72
void NetworkServerSendConfigUpdate()
Send Config Update.
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
StringList _network_ban_list
The banned clients.
Definition network.cpp:75
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id=nullptr)
Converts a string to ip/port/company Format: IP:port::company.
Definition network.cpp:521
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
std::string_view NetworkGetPublicKeyOfClient(ClientID client_id)
Get the public key of the client with the given id.
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Definition network.cpp:1080
StringList _network_bind_list
The addresses to bind on.
Definition network.cpp:73
uint NetworkMaxCompaniesAllowed()
Get the maximum number of companies that are allowed by the server.
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
void NetworkDisconnect(bool close_admins=true)
We want to disconnect from the host/clients.
Definition network.cpp:999
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
ClientID _network_own_client_id
Uncomment the following define to enable command replaying.
Definition network.cpp:70
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
void NetworkUndrawChatMessage()
Hide the chatbox.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data=0)
Send a chat message.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode)
Handle the pause mode change so we send the right messages to the chat.
Definition network.cpp:354
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
Send a chat message from external source.
void NetworkUpdateServerGameType()
The setting server_game_type was updated; possibly we need to take some action.
Definition network.cpp:1027
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Definition network.cpp:141
bool NetworkValidateClientName(std::string &client_name)
Trim the given client name in place, i.e.
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
bool NetworkValidateServerName(std::string &server_name)
Trim the given server name in place, i.e.
Definition network.cpp:858
Types used for networking.
DestType
Destination of our chat messages.
NetworkAction
Actions that can be used for NetworkTextMessage.
ClientID
'Unique' identifier to be given to clients
PauseMode
Modes of pausing we've got.
Definition openttd.h:68
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:60
Container for all information known about a client.
Simple calculated statistics of a company.