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

OpenTTD Source 12.2

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
27 extern NetworkCompanyState *_network_company_states;
28
29 extern ClientID _network_own_client_id;
30 extern ClientID _redirect_console_to_client;
31 extern uint8 _network_reconnect;
32 extern StringList _network_bind_list;
33 extern StringList _network_host_list;
34 extern StringList _network_ban_list;
35
36 byte NetworkSpectatorCount();
37 bool NetworkIsValidClientName(const std::string_view client_name);
38 bool NetworkValidateOurClientName();
39 bool NetworkValidateClientName(std::string &client_name);
40 bool NetworkValidateServerName(std::string &server_name);
41 void NetworkUpdateClientName(const std::string &client_name);
42 void NetworkUpdateServerGameType();
43 bool NetworkCompanyHasClients(CompanyID company);
44 std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password);
45 void NetworkReboot();
46 void NetworkDisconnect(bool blocking = false, bool close_admins = true);
47 void NetworkGameLoop();
48 void NetworkBackgroundLoop();
49 std::string_view ParseFullConnectionString(const std::string &connection_string, uint16 &port, CompanyID *company_id = nullptr);
50 void NetworkStartDebugLog(const std::string &connection_string);
51 void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
52
53 void NetworkUpdateClientInfo(ClientID client_id);
54 void NetworkClientsToSpectators(CompanyID cid);
55 bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password = "", const std::string &join_company_password = "");
56 void NetworkClientJoinGame();
57 void NetworkClientRequestMove(CompanyID company, const std::string &pass = "");
58 void NetworkClientSendRcon(const std::string &password, const std::string &command);
59 void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data = 0);
60 bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
61 bool NetworkCompanyIsPassworded(CompanyID company_id);
62 bool NetworkMaxCompaniesReached();
63 void NetworkPrintClients();
64 void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
65
66 /*** Commands ran by the server ***/
67 void NetworkServerDailyLoop();
68 void NetworkServerMonthlyLoop();
69 void NetworkServerYearlyLoop();
70 void NetworkServerSendConfigUpdate();
71 void NetworkServerUpdateGameInfo();
72 void NetworkServerShowStatusToConsole();
73 bool NetworkServerStart();
74 void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
75 bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name);
76
77
78 void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
79 void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string);
80 void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false);
81 void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
82
83 void NetworkServerKickClient(ClientID client_id, const std::string &reason);
84 uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason);
85 uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason);
86
87 void NetworkInitChatMessage();
88 void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message);
89 void NetworkUndrawChatMessage();
90 void NetworkChatMessageLoop();
91
92 void NetworkAfterNewGRFScan();
93
94 #endif /* NETWORK_FUNC_H */
NetworkCompanyStats
Simple calculated statistics of a company.
Definition: network_type.h:65
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:89
NetworkServerShowStatusToConsole
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
Definition: network_server.cpp:1841
NetworkCompanyIsPassworded
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:212
NetworkServerSendChat
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
Definition: network_server.cpp:1182
NetworkDisconnect
void NetworkDisconnect(bool blocking=false, bool close_admins=true)
We want to disconnect from the host/clients.
Definition: network.cpp:944
NetworkCompanyState
Some state information of a company, especially for servers.
Definition: network_type.h:72
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:99
NetworkCompanyHasClients
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
Definition: network_server.cpp:2019
NetworkPopulateCompanyStats
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
Definition: network_server.cpp:1434
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition: network_server.cpp:1470
NetworkClientSendRcon
void NetworkClientSendRcon(const std::string &password, const std::string &command)
Send a remote console command.
Definition: network_client.cpp:1176
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:1912
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
NetworkHandlePauseChange
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:339
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:66
NetworkServerDailyLoop
void NetworkServerDailyLoop()
Daily "callback".
Definition: network_server.cpp:1825
NetworkUpdateServerGameType
void NetworkUpdateServerGameType()
The setting server_game_type was updated; possibly we need to take some action.
Definition: network.cpp:972
NetworkIsValidClientName
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Definition: network_client.cpp:1218
NetworkChangeCompanyPassword
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
Definition: network.cpp:156
NetworkClientJoinGame
void NetworkClientJoinGame()
Actually perform the joining to the server.
Definition: network.cpp:794
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:47
NetworkServerYearlyLoop
void NetworkServerYearlyLoop()
Yearly "callback".
Definition: network_server.cpp:1810
NetworkPrintClients
void NetworkPrintClients()
Print all the clients to the console.
Definition: network_server.cpp:2044
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
NetworkServerChangeClientName
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
Definition: network_server.cpp:1624
NetworkClientPreferTeamChat
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
Definition: network_client.cpp:1313
NetworkServerKickOrBanIP
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
Definition: network_server.cpp:1970
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:90
PauseMode
PauseMode
Modes of pausing we've got.
Definition: openttd.h:60
ParseFullConnectionString
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16 &port, CompanyID *company_id=nullptr)
Converts a string to ip/port/company Format: IP:port::company.
Definition: network.cpp:506
NetworkMaxCompaniesReached
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
Definition: network_client.cpp:1329
_network_host_list
StringList _network_host_list
The servers we know.
Definition: network.cpp:67
NetworkBackgroundLoop
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Definition: network.cpp:1021
NetworkUpdateClientName
void NetworkUpdateClientName(const std::string &client_name)
Send the server our name as callback from the setting.
Definition: network_client.cpp:1265
NetworkServerSendConfigUpdate
void NetworkServerSendConfigUpdate()
Send Config Update.
Definition: network_server.cpp:1874
NetworkUndrawChatMessage
void NetworkUndrawChatMessage()
Hide the chatbox.
Definition: network_chat_gui.cpp:126
NetworkValidateClientName
bool NetworkValidateClientName(std::string &client_name)
Trim the given client name in place, i.e.
Definition: network_client.cpp:1240
NetworkClientConnectGame
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password="", const std::string &join_company_password="")
Join a client to the server at with the given connection string.
Definition: network.cpp:762
NetworkValidateOurClientName
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
Definition: network_client.cpp:1256
NetworkServerNewCompany
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
Definition: network_server.cpp:2067
NetworkServerSendExternalChat
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
Send a chat message from external source.
Definition: network_server.cpp:1300
NetworkServerSendRcon
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string)
Send an rcon reply to the client.
Definition: network_server.cpp:1948
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
NetworkClientsToSpectators
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
Definition: network_client.cpp:1196
NetworkClientRequestMove
void NetworkClientRequestMove(CompanyID company, const std::string &pass="")
Notify the server of this client wanting to be moved to another company.
Definition: network_client.cpp:1187
_network_ban_list
StringList _network_ban_list
The banned clients.
Definition: network.cpp:68
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:173
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:118
NetworkServerKickClient
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
Definition: network_server.cpp:1958
_redirect_console_to_client
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
Definition: network.cpp:64
NetworkClientSendChat
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data=0)
Send a chat message.
Definition: network_client.cpp:1294
NetworkServerMonthlyLoop
void NetworkServerMonthlyLoop()
Monthly "callback".
Definition: network_server.cpp:1817
Company
Definition: company_base.h:115
NetworkServerUpdateGameInfo
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
Definition: network_server.cpp:1882
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
NetworkValidateServerName
bool NetworkValidateServerName(std::string &server_name)
Trim the given server name in place, i.e.
Definition: network.cpp:830
network_type.h
_network_company_states
NetworkCompanyState * _network_company_states
Uncomment the following define to enable command replaying.
Definition: network.cpp:62
_network_reconnect
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:65
NetworkInitChatMessage
void NetworkInitChatMessage()
Initialize all buffers of the chat visualisation.
Definition: network_chat_gui.cpp:114