OpenTTD Source: src/network/network_func.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 "../core/convertible_through_base.hpp"
22#include "../console_type.h"
23#include "../gfx_type.h"
24#include "../openttd.h"
25#include "../company_type.h"
26#include "../string_type.h"
27
28extern ClientID _network_own_client_id;
29extern ClientID _redirect_console_to_client;
30extern uint8_t _network_reconnect;
31extern StringList _network_bind_list;
32extern StringList _network_host_list;
33extern StringList _network_ban_list;
34
35uint8_t NetworkSpectatorCount();
36bool NetworkIsValidClientName(std::string_view client_name);
37bool NetworkValidateOurClientName();
38bool NetworkValidateClientName(std::string &client_name);
39bool NetworkValidateServerName(std::string &server_name);
40void NetworkUpdateClientName(const std::string &client_name);
41void NetworkUpdateServerGameType();
42bool NetworkCompanyHasClients(CompanyID company);
43void NetworkReboot();
44void NetworkDisconnect(bool close_admins = true);
45void NetworkGameLoop();
46void NetworkBackgroundLoop();
47std::string_view ParseFullConnectionString(std::string_view connection_string, uint16_t &port, CompanyID *company_id = nullptr);
48using NetworkCompanyStatsArray = TypedIndexContainer<std::array<NetworkCompanyStats, MAX_COMPANIES>, CompanyID>;
49 NetworkCompanyStatsArray NetworkGetCompanyStats();
50
51void NetworkUpdateClientInfo(ClientID client_id);
52void NetworkClientsToSpectators(CompanyID cid);
53bool NetworkClientConnectGame(std::string_view connection_string, CompanyID default_company, const std::string &join_server_password = "");
54void NetworkClientJoinGame();
55void NetworkClientRequestMove(CompanyID company);
56void NetworkClientSendRcon(std::string_view password, std::string_view command);
57void NetworkClientSendChat(NetworkAction action, DestType type, int dest, std::string_view msg, int64_t data = 0);
58bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
59uint NetworkMaxCompaniesAllowed();
60bool NetworkMaxCompaniesReached();
61void NetworkPrintClients();
62std::string_view NetworkGetPublicKeyOfClient(ClientID client_id);
63void NetworkHandlePauseChange(PauseModes prev_mode, PauseMode changed_mode);
64
65void NetworkOnGameStart();
66
67/*** Commands ran by the server ***/
68void NetworkServerSendConfigUpdate();
69void NetworkServerUpdateGameInfo();
70void NetworkServerShowStatusToConsole();
71bool NetworkServerStart();
72void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
73bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name);
74
75
76bool NetworkCanJoinCompany(CompanyID company_id);
77void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
78void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, std::string_view string);
79void NetworkServerSendChat(NetworkAction action, DestType type, int dest, std::string_view msg, ClientID from_id, int64_t data = 0, bool from_admin = false);
80void NetworkServerSendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg);
81
82void NetworkServerKickClient(ClientID client_id, std::string_view reason);
83uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason);
84uint NetworkServerKickOrBanIP(std::string_view ip, bool ban, std::string_view reason);
85
86void NetworkInitChatMessage();
87void NetworkReInitChatBoxSize();
88void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message);
89void NetworkUndrawChatMessage();
90
91void NetworkAfterNewGRFScan();
92
93#endif /* NETWORK_FUNC_H */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
TypedIndexContainer
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
Definition convertible_through_base.hpp:38
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
NetworkHandlePauseChange
void NetworkHandlePauseChange(PauseModes prev_mode, PauseMode changed_mode)
Handle the pause mode change so we send the right messages to the chat.
Definition network.cpp:351
NetworkUpdateClientName
void NetworkUpdateClientName(const std::string &client_name)
Send the server our name as callback from the setting.
Definition network_client.cpp:1292
_network_host_list
StringList _network_host_list
The servers we know.
Definition network.cpp:75
NetworkServerChangeClientName
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
Definition network_server.cpp:1647
NetworkServerNewCompany
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
Definition network_server.cpp:2150
NetworkServerSendExternalChat
void NetworkServerSendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
Send a chat message from external source.
Definition network_server.cpp:1369
NetworkPrintClients
void NetworkPrintClients()
Print all the clients to the console.
Definition network_server.cpp:2115
NetworkServerUpdateGameInfo
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
Definition network_server.cpp:1965
NetworkClientJoinGame
void NetworkClientJoinGame()
Actually perform the joining to the server.
Definition network.cpp:818
NetworkGetCompanyStats
NetworkCompanyStatsArray NetworkGetCompanyStats()
Get the company stats.
Definition network_server.cpp:1491
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition network_server.cpp:1529
_redirect_console_to_client
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
Definition network.cpp:72
NetworkAddChatMessage
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
Add a text message to the 'chat window' to be shown.
Definition network_chat_gui.cpp:85
NetworkOnGameStart
void NetworkOnGameStart()
Perform tasks when the server is started.
Definition network.cpp:945
NetworkValidateOurClientName
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
Definition network_client.cpp:1283
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company)
Notify the server of this client wanting to be moved to another company.
Definition network_client.cpp:1214
_network_reconnect
uint8_t _network_reconnect
Reconnect timeout.
Definition network.cpp:73
NetworkServerSendConfigUpdate
void NetworkServerSendConfigUpdate()
Send Config Update.
Definition network_server.cpp:1957
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition network.cpp:76
NetworkReInitChatBoxSize
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
Definition network_chat_gui.cpp:101
NetworkServerDoMove
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
Definition network_server.cpp:1976
NetworkCompanyHasClients
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
Definition network_server.cpp:2090
NetworkServerKickClient
void NetworkServerKickClient(ClientID client_id, std::string_view reason)
Kick a single client.
Definition network_server.cpp:2029
NetworkAfterNewGRFScan
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
Definition network_gamelist.cpp:80
NetworkMaxCompaniesReached
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
Definition network_client.cpp:1356
ParseFullConnectionString
std::string_view ParseFullConnectionString(std::string_view connection_string, uint16_t &port, CompanyID *company_id=nullptr)
Converts a string to ip/port/company Format: IP:port::company.
Definition network.cpp:519
NetworkGetPublicKeyOfClient
std::string_view NetworkGetPublicKeyOfClient(ClientID client_id)
Get the public key of the client with the given id.
Definition network_server.cpp:2138
NetworkClientSendChat
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, std::string_view msg, int64_t data=0)
Send a chat message.
Definition network_client.cpp:1321
NetworkClientSendRcon
void NetworkClientSendRcon(std::string_view password, std::string_view command)
Send a remote console command.
Definition network_client.cpp:1205
NetworkBackgroundLoop
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Definition network.cpp:1080
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition network.cpp:74
NetworkMaxCompaniesAllowed
uint NetworkMaxCompaniesAllowed()
Get the maximum number of companies that are allowed by the server.
Definition network_client.cpp:1347
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition network_chat_gui.cpp:108
NetworkDisconnect
void NetworkDisconnect(bool close_admins=true)
We want to disconnect from the host/clients.
Definition network.cpp:999
NetworkClientsToSpectators
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
Definition network_client.cpp:1223
_network_own_client_id
ClientID _network_own_client_id
Uncomment the following define to enable command replaying.
Definition network.cpp:71
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Definition network_client.cpp:1331
NetworkUndrawChatMessage
void NetworkUndrawChatMessage()
Hide the chatbox.
Definition network_chat_gui.cpp:120
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, std::string_view msg, ClientID from_id, int64_t data=0, bool from_admin=false)
Send an actual chat message.
Definition network_server.cpp:1252
NetworkServerShowStatusToConsole
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
Definition network_server.cpp:1925
NetworkServerSendRcon
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, std::string_view string)
Send an rcon reply to the client.
Definition network_server.cpp:2019
NetworkServerKickOrBanIP
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, std::string_view reason)
Ban, or kick, everyone joined from the given client's IP.
Definition network_server.cpp:2041
NetworkClientConnectGame
bool NetworkClientConnectGame(std::string_view 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
NetworkUpdateServerGameType
void NetworkUpdateServerGameType()
The setting server_game_type was updated; possibly we need to take some action.
Definition network.cpp:1027
NetworkCanJoinCompany
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Definition network.cpp:142
NetworkValidateClientName
bool NetworkValidateClientName(std::string &client_name)
Trim the given client name in place, i.e.
Definition network_client.cpp:1267
NetworkIsValidClientName
bool NetworkIsValidClientName(std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Definition network_client.cpp:1245
NetworkValidateServerName
bool NetworkValidateServerName(std::string &server_name)
Trim the given server name in place, i.e.
Definition network.cpp:858
network_type.h
Types used for networking.
DestType
DestType
Destination of our chat messages.
Definition network_type.h:68
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition network_type.h:79
ClientID
ClientID
'Unique' identifier to be given to clients
Definition network_type.h:43
PauseMode
PauseMode
Modes of pausing we've got.
Definition openttd.h:68
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:60
Company
Definition company_base.h:127
NetworkClientInfo
Container for all information known about a client.
Definition network_base.h:24
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >