OpenTTD Source  1.11.2
network_func.h File Reference
#include "network_type.h"
#include "../console_type.h"
#include "../gfx_type.h"
#include "../openttd.h"
#include "../company_type.h"
#include "../string_type.h"

Go to the source code of this file.

Functions

byte NetworkSpectatorCount ()
 
void NetworkUpdateClientName ()
 Send the server our name.
 
bool NetworkCompanyHasClients (CompanyID company)
 Check whether a particular company has clients. More...
 
const char * NetworkChangeCompanyPassword (CompanyID company_id, const char *password)
 Change the company password of a given company. More...
 
void NetworkReboot ()
 
void NetworkDisconnect (bool blocking=false, bool close_admins=true)
 We want to disconnect from the host/clients. More...
 
void NetworkGameLoop ()
 
void NetworkBackgroundLoop ()
 We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer. More...
 
void ParseConnectionString (const char **company, const char **port, char *connection_string)
 Converts a string to ip/port/company Format: IP:port::company. More...
 
void NetworkStartDebugLog (const char *hostname, uint16 port)
 
void NetworkPopulateCompanyStats (NetworkCompanyStats *stats)
 Populate the company stats. More...
 
void NetworkUpdateClientInfo (ClientID client_id)
 Send updated client info of a particular client. More...
 
void NetworkClientsToSpectators (CompanyID cid)
 Move the clients of a company to the spectators. More...
 
void NetworkClientConnectGame (const char *hostname, uint16 port, CompanyID join_as, const char *join_server_password=nullptr, const char *join_company_password=nullptr)
 
void NetworkClientJoinGame ()
 Actually perform the joining to the server. More...
 
void NetworkClientRequestMove (CompanyID company, const char *pass="")
 Notify the server of this client wanting to be moved to another company. More...
 
void NetworkClientSendRcon (const char *password, const char *command)
 Send a remote console command. More...
 
void NetworkClientSendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data=0)
 Send a chat message. More...
 
bool NetworkClientPreferTeamChat (const NetworkClientInfo *cio)
 Tell whether the client has team members where he/she can chat to. More...
 
bool NetworkCompanyIsPassworded (CompanyID company_id)
 Check if the company we want to join requires a password. More...
 
bool NetworkMaxCompaniesReached ()
 Check if max_companies has been reached on the server (local check only). More...
 
bool NetworkMaxSpectatorsReached ()
 Check if max_spectatos has been reached on the server (local check only). More...
 
void NetworkPrintClients ()
 Print all the clients to the console.
 
void NetworkHandlePauseChange (PauseMode prev_mode, PauseMode changed_mode)
 Handle the pause mode change so we send the right messages to the chat. More...
 
void NetworkServerDailyLoop ()
 Daily "callback". More...
 
void NetworkServerMonthlyLoop ()
 Monthly "callback". More...
 
void NetworkServerYearlyLoop ()
 Yearly "callback". More...
 
void NetworkServerSendConfigUpdate ()
 Send Config Update.
 
void NetworkServerShowStatusToConsole ()
 Show the status message of all clients on the console.
 
bool NetworkServerStart ()
 
void NetworkServerNewCompany (const Company *company, NetworkClientInfo *ci)
 Perform all the server specific administration of a new company. More...
 
bool NetworkServerChangeClientName (ClientID client_id, const char *new_name)
 Change the client name of the given client. More...
 
void NetworkServerDoMove (ClientID client_id, CompanyID company_id)
 Handle the tid-bits of moving a client from one company to another. More...
 
void NetworkServerSendRcon (ClientID client_id, TextColour colour_code, const char *string)
 Send an rcon reply to the client. More...
 
void NetworkServerSendChat (NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
 Send an actual chat message. More...
 
void NetworkServerKickClient (ClientID client_id, const char *reason)
 Kick a single client. More...
 
uint NetworkServerKickOrBanIP (ClientID client_id, bool ban, const char *reason)
 Ban, or kick, everyone joined from the given client's IP. More...
 
uint NetworkServerKickOrBanIP (const char *ip, bool ban, const char *reason)
 Kick or ban someone based on an IP address. More...
 
void NetworkInitChatMessage ()
 Initialize all buffers of the chat visualisation.
 
void CDECL NetworkAddChatMessage (TextColour colour, uint duration, const char *message,...) WARN_FORMAT(3
 
void CDECL void NetworkUndrawChatMessage ()
 Hide the chatbox.
 
void NetworkChatMessageLoop ()
 Check if a message is expired.
 
void NetworkAfterNewGRFScan ()
 Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new NewGRFs.
 

Variables

NetworkCompanyState_network_company_states
 Uncomment the following define to enable command replaying. More...
 
ClientID _network_own_client_id
 Our client identifier.
 
ClientID _redirect_console_to_client
 If not invalid, redirect the console output to a client.
 
bool _network_need_advertise
 Whether we need to advertise.
 
uint8 _network_reconnect
 Reconnect timeout.
 
StringList _network_bind_list
 The addresses to bind on.
 
StringList _network_host_list
 The servers we know.
 
StringList _network_ban_list
 The banned clients.
 

Detailed Description

Network functions used by other parts of OpenTTD.

Definition in file network_func.h.

Function Documentation

◆ NetworkBackgroundLoop()

void NetworkBackgroundLoop ( )

We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.

For example stuff needed for finding servers or downloading content.

Definition at line 856 of file network.cpp.

References _network_content_client, TCPConnecter::CheckCallbacks(), NetworkHTTPSocketHandler::HTTPReceive(), NetworkBackgroundUDPLoop(), and ClientNetworkContentSocketHandler::SendReceive().

◆ NetworkChangeCompanyPassword()

const char* NetworkChangeCompanyPassword ( CompanyID  company_id,
const char *  password 
)

Change the company password of a given company.

Parameters
company_idID of the company the password should be changed for.
passwordThe unhashed password we like to set ('*' or '' resets the password)
Returns
The password.

Definition at line 154 of file network.cpp.

References _network_server, NetworkClientSetCompanyPassword(), and NetworkServerSetCompanyPassword().

◆ NetworkClientJoinGame()

void NetworkClientJoinGame ( )

Actually perform the joining to the server.

Use #NetworkClientConnectGame when you want to connect to a specific server/company. This function assumes _network_join is already fully set up.

Definition at line 694 of file network.cpp.

References NetworkDisconnect().

◆ NetworkClientPreferTeamChat()

bool NetworkClientPreferTeamChat ( const NetworkClientInfo cio)

◆ NetworkClientRequestMove()

void NetworkClientRequestMove ( CompanyID  company_id,
const char *  pass 
)

Notify the server of this client wanting to be moved to another company.

Parameters
company_idid of the company the client wishes to be moved to.
passthe password, is only checked on the server end if a password is needed.
Returns
void

Definition at line 1230 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendMove().

◆ NetworkClientSendChat()

void NetworkClientSendChat ( NetworkAction  action,
DestType  type,
int  dest,
const char *  msg,
int64  data 
)

Send a chat message.

Parameters
actionThe action associated with the message.
typeThe destination type.
destThe destination index, be it a company index or client id.
msgThe actual message.
dataArbitrary extra data.

Definition at line 1285 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendChat().

◆ NetworkClientSendRcon()

void NetworkClientSendRcon ( const char *  password,
const char *  command 
)

Send a remote console command.

Parameters
passwordThe password.
commandThe command to execute.

Definition at line 1219 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendRCon().

◆ NetworkClientsToSpectators()

void NetworkClientsToSpectators ( CompanyID  cid)

Move the clients of a company to the spectators.

Parameters
cidThe company to move the clients of.

Definition at line 1239 of file network_client.cpp.

References _current_company.

◆ NetworkCompanyHasClients()

bool NetworkCompanyHasClients ( CompanyID  company)

Check whether a particular company has clients.

Parameters
companyThe company to check.
Returns
True if at least one client is joined to the company.

Definition at line 2169 of file network_server.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::Iterate().

◆ NetworkCompanyIsPassworded()

bool NetworkCompanyIsPassworded ( CompanyID  company_id)

Check if the company we want to join requires a password.

Parameters
company_idid of the company we want to check the 'passworded' flag for.
Returns
true if the company requires a password.

Definition at line 208 of file network.cpp.

References _network_company_passworded, and HasBit().

Referenced by NetworkServerUpdateCompanyPassworded().

◆ NetworkDisconnect()

void NetworkDisconnect ( bool  blocking,
bool  close_admins 
)

◆ NetworkHandlePauseChange()

void NetworkHandlePauseChange ( PauseMode  prev_mode,
PauseMode  changed_mode 
)

Handle the pause mode change so we send the right messages to the chat.

Parameters
prev_modeThe previous pause mode.
changed_modeThe pause mode that got changed.

Definition at line 332 of file network.cpp.

References _networking, _pause_mode, PM_PAUSED_ACTIVE_CLIENTS, PM_PAUSED_GAME_SCRIPT, PM_PAUSED_JOIN, PM_PAUSED_LINK_GRAPH, PM_PAUSED_NORMAL, PM_UNPAUSED, and SetDParam().

◆ NetworkMaxCompaniesReached()

bool NetworkMaxCompaniesReached ( )

Check if max_companies has been reached on the server (local check only).

Returns
true if the max value has been reached or exceeded, false otherwise.

Definition at line 1320 of file network_client.cpp.

References _network_server, _network_server_max_companies, _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkSettings::max_companies, and ClientSettings::network.

Referenced by PopupMainCompanyToolbMenu().

◆ NetworkMaxSpectatorsReached()

bool NetworkMaxSpectatorsReached ( )

Check if max_spectatos has been reached on the server (local check only).

Returns
true if the max value has been reached or exceeded, false otherwise.

Definition at line 1329 of file network_client.cpp.

Referenced by PopupMainCompanyToolbMenu().

◆ NetworkPopulateCompanyStats()

◆ NetworkServerChangeClientName()

bool NetworkServerChangeClientName ( ClientID  client_id,
const char *  new_name 
)

Change the client name of the given client.

Parameters
client_idthe client to change the name of
new_namethe new name for the client
Returns
true iff the name was changed

Definition at line 1780 of file network_server.cpp.

References NetworkClientInfo::GetByClientID(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::Iterate().

◆ NetworkServerDailyLoop()

void NetworkServerDailyLoop ( )

Daily "callback".

Called whenever the date changes.

Definition at line 1983 of file network_server.cpp.

References _date, ADMIN_FREQUENCY_DAILY, ADMIN_FREQUENCY_WEEKLY, and NetworkAdminUpdate().

◆ NetworkServerDoMove()

void NetworkServerDoMove ( ClientID  client_id,
CompanyID  company_id 
)

Handle the tid-bits of moving a client from one company to another.

Parameters
client_idid of the client we want to move.
company_idid of the company we want to move the client to.
Returns
void

Definition at line 2064 of file network_server.cpp.

References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, NetworkClientInfo::GetByClientID(), NetworkUpdateClientInfo(), and SetLocalCompany().

◆ NetworkServerKickClient()

void NetworkServerKickClient ( ClientID  client_id,
const char *  reason 
)

Kick a single client.

Parameters
client_idThe client to kick.
reasonIn case of kicking a client, specifies the reason for kicking the client.

Definition at line 2108 of file network_server.cpp.

References CLIENT_ID_SERVER.

Referenced by NetworkServerKickOrBanIP().

◆ NetworkServerKickOrBanIP() [1/2]

uint NetworkServerKickOrBanIP ( ClientID  client_id,
bool  ban,
const char *  reason 
)

Ban, or kick, everyone joined from the given client's IP.

Parameters
client_idThe client to check for.
banWhether to ban or kick.
reasonIn case of kicking a client, specifies the reason for kicking the client.

Definition at line 2120 of file network_server.cpp.

◆ NetworkServerKickOrBanIP() [2/2]

uint NetworkServerKickOrBanIP ( const char *  ip,
bool  ban,
const char *  reason 
)

Kick or ban someone based on an IP address.

Parameters
ipThe IP address/range to ban/kick.
banWhether to ban or just kick.
reasonIn case of kicking a client, specifies the reason for kicking the client.

Definition at line 2131 of file network_server.cpp.

References _network_ban_list, _redirect_console_to_client, CLIENT_ID_SERVER, and NetworkServerKickClient().

◆ NetworkServerMonthlyLoop()

void NetworkServerMonthlyLoop ( )

Monthly "callback".

Called whenever the month changes.

Definition at line 1975 of file network_server.cpp.

References _cur_month, ADMIN_FREQUENCY_MONTHLY, ADMIN_FREQUENCY_QUARTERLY, NetworkAdminUpdate(), and NetworkAutoCleanCompanies().

◆ NetworkServerNewCompany()

void NetworkServerNewCompany ( const Company c,
NetworkClientInfo ci 
)

◆ NetworkServerSendChat()

void NetworkServerSendChat ( NetworkAction  action,
DestType  desttype,
int  dest,
const char *  msg,
ClientID  from_id,
int64  data,
bool  from_admin 
)

Send an actual chat message.

Parameters
actionThe action that's performed.
desttypeThe type of destination.
destThe actual destination index.
msgThe actual message.
from_idThe origin of the message.
dataArbitrary data.
from_adminWhether the origin is an admin or not.

Definition at line 1295 of file network_server.cpp.

References CLIENT_ID_SERVER, DESTTYPE_CLIENT, and NetworkClientInfo::GetByClientID().

Referenced by NetworkServerNewCompany().

◆ NetworkServerSendRcon()

void NetworkServerSendRcon ( ClientID  client_id,
TextColour  colour_code,
const char *  string 
)

Send an rcon reply to the client.

Parameters
client_idThe identifier of the client.
colour_codeThe colour of the text.
stringThe actual reply.

Definition at line 2098 of file network_server.cpp.

Referenced by IConsolePrint().

◆ NetworkServerYearlyLoop()

void NetworkServerYearlyLoop ( )

Yearly "callback".

Called whenever the year changes.

Definition at line 1968 of file network_server.cpp.

References ADMIN_FREQUENCY_ANUALLY, NetworkAdminUpdate(), and NetworkCheckRestartMap().

◆ NetworkUpdateClientInfo()

void NetworkUpdateClientInfo ( ClientID  client_id)

Send updated client info of a particular client.

Parameters
client_idThe client to send it for.

Definition at line 1623 of file network_server.cpp.

References _date, _date_fract, NetworkClientInfo::client_playas, DEBUG, NetworkClientInfo::GetByClientID(), NetworkAdminClientUpdate(), and ServerNetworkGameSocketHandler::STATUS_AUTHORIZED.

Referenced by NetworkServerDoMove(), and NetworkServerNewCompany().

◆ ParseConnectionString()

void ParseConnectionString ( const char **  company,
const char **  port,
char *  connection_string 
)

Converts a string to ip/port/company Format: IP:port::company.

connection_string will be re-terminated to separate out the hostname, and company and port will be set to the company and port strings given by the user, inside the memory area originally occupied by connection_string.

Definition at line 459 of file network.cpp.

Referenced by NetworkHTTPSocketHandler::Connect().

Variable Documentation

◆ _network_company_states

NetworkCompanyState* _network_company_states

Uncomment the following define to enable command replaying.

See docs/desync.txt for details.

Uncomment the following define to enable command replaying.

Definition at line 57 of file network.cpp.

Referenced by NetworkAutoCleanCompanies(), NetworkClose(), NetworkServerNewCompany(), and NetworkServerSetCompanyPassword().