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

OpenTTD Source 15.3

Typedefs | Functions | Variables
network_func.h File Reference

Network functions used by other parts of OpenTTD. More...

`#include "network_type.h"`
`#include "../core/convertible_through_base.hpp"`
`#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.

## Typedefs
using | NetworkCompanyStatsArray = TypedIndexContainer< std::array< NetworkCompanyStats, MAX_COMPANIES >, CompanyID >

## Functions
uint8_t | NetworkSpectatorCount ()
bool | NetworkIsValidClientName (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.
bool | NetworkValidateClientName (std::string &client_name)
| Trim the given client name in place, i.e.
bool | NetworkValidateServerName (std::string &server_name)
| Trim the given server name in place, i.e.
void | NetworkUpdateClientName (const std::string &client_name)
| Send the server our name as callback from the setting.
void | NetworkUpdateServerGameType ()
| The setting server_game_type was updated; possibly we need to take some action.
bool | NetworkCompanyHasClients (CompanyID company)
| Check whether a particular company has clients.
void | NetworkReboot ()
void | NetworkDisconnect (bool close_admins=true)
| We want to disconnect from the host/clients.
void | NetworkGameLoop ()
void | NetworkBackgroundLoop ()
| We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
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.
NetworkCompanyStatsArray | NetworkGetCompanyStats ()
| Get the company stats.
void | NetworkUpdateClientInfo (ClientID client_id)
| Send updated client info of a particular client.
void | NetworkClientsToSpectators (CompanyID cid)
| Move the clients of a company to the spectators.
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.
void | NetworkClientJoinGame ()
| Actually perform the joining to the server.
void | NetworkClientRequestMove (CompanyID company)
| Notify the server of this client wanting to be moved to another company.
void | NetworkClientSendRcon (std::string_view password, std::string_view command)
| Send a remote console command.
void | NetworkClientSendChat (NetworkAction action, DestType type, int dest, std::string_view msg, int64_t data=0)
| Send a chat message.
bool | NetworkClientPreferTeamChat (const NetworkClientInfo *cio)
| Tell whether the client has team members who they can chat to.
uint | NetworkMaxCompaniesAllowed ()
| Get the maximum number of companies that are allowed by the server.
bool | NetworkMaxCompaniesReached ()
| Check if max_companies has been reached on the server (local check only).
void | NetworkPrintClients ()
| Print all the clients to the console.
std::string_view | NetworkGetPublicKeyOfClient (ClientID client_id)
| Get the public key of the client with the given id.
void | NetworkHandlePauseChange (PauseModes prev_mode, PauseMode changed_mode)
| Handle the pause mode change so we send the right messages to the chat.
void | NetworkOnGameStart ()
| Perform tasks when the server is started.
void | NetworkServerSendConfigUpdate ()
| Send Config Update.
void | NetworkServerUpdateGameInfo ()
| Update the server's NetworkServerGameInfo due to changes in settings.
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.
bool | NetworkServerChangeClientName (ClientID client_id, const std::string &new_name)
| Change the client name of the given client.
bool | NetworkCanJoinCompany (CompanyID company_id)
| Returns whether the given company can be joined by this client.
void | NetworkServerDoMove (ClientID client_id, CompanyID company_id)
| Handle the tid-bits of moving a client from one company to another.
void | NetworkServerSendRcon (ClientID client_id, TextColour colour_code, std::string_view string)
| Send an rcon reply to the client.
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.
void | NetworkServerSendExternalChat (std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
| Send a chat message from external source.
void | NetworkServerKickClient (ClientID client_id, std::string_view reason)
| Kick a single client.
uint | NetworkServerKickOrBanIP (ClientID client_id, bool ban, std::string_view reason)
| Ban, or kick, everyone joined from the given client's IP.
uint | NetworkServerKickOrBanIP (std::string_view ip, bool ban, std::string_view reason)
| Kick or ban someone based on an IP address.
void | NetworkInitChatMessage ()
| Initialize all buffers of the chat visualisation.
void | NetworkReInitChatBoxSize ()
| Initialize all font-dependent chat box sizes.
void CDECL | NetworkAddChatMessage (TextColour colour, uint duration, const std::string &message)
| Add a text message to the 'chat window' to be shown.
void | NetworkUndrawChatMessage ()
| Hide the chatbox.
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
ClientID | _network_own_client_id
| Uncomment the following define to enable command replaying.
ClientID | _redirect_console_to_client
| If not invalid, redirect the console output to a client.
uint8_t | _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.

## Typedef Documentation

## ◆ NetworkCompanyStatsArray

using NetworkCompanyStatsArray = TypedIndexContainer<std::array<NetworkCompanyStats, MAX_COMPANIES>, CompanyID>

Definition at line 48 of file network_func.h.

## Function Documentation

## ◆ NetworkAddChatMessage()

void CDECL NetworkAddChatMessage | ( | TextColour | colour,
|  | uint | duration,
|  | const std::string & | message
| ) |  |

Add a text message to the 'chat window' to be shown.

Parameters

  colour | The colour this message is to be shown in
  duration | The duration of the chat message in seconds
  message | message itself

Definition at line 85 of file network_chat_gui.cpp.

References _chatmessage_dirty, _chatmessage_dirty_time, _chatmsg_list, ChatMessage::colour, MAX_CHAT_MESSAGES, ChatMessage::message, and ChatMessage::remove_time.

## ◆ NetworkAfterNewGRFScan()

void NetworkAfterNewGRFScan | ( |  | ) |

Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new NewGRFs.

Definition at line 80 of file network_gamelist.cpp.

References _network_game_list, Copy, FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), GCS_NOT_FOUND, GCS_UNKNOWN, GRFConfig::info, InvalidateWindowClassesData(), GRFConfig::name, and WC_NETWORK_WINDOW.

Referenced by DoScanNewGRFFiles().

## ◆ 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 1081 of file network.cpp.

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

Referenced by NetworkSurveyHandler::Transmit().

## ◆ NetworkCanJoinCompany()

bool NetworkCanJoinCompany | ( | CompanyID | company_id | ) |

Returns whether the given company can be joined by this client.

Parameters

  company_id | The id of the company.

Returns
  `true` when this company is allowed to join, otherwise `false`.

Definition at line 143 of file network.cpp.

References _network_own_client_id, NetworkClientInfo::CanJoinCompany(), and NetworkClientInfo::GetByClientID().

Referenced by CompanyWindow::OnPaint().

## ◆ 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.

The default for the passwords is `nullptr`. When the server needs a password and none is given, the user is asked to enter the password in the GUI. This function will return false whenever some information required to join is not correct such as the company number or the client's name, or when there is not networking avalabile at all. If the function returns false the connection with the existing server is not disconnected. It will return true when it starts the actual join process, i.e. when it actually shows the join status window.

Parameters

  connection_string | The IP address, port and company number to join as.
  default_company | The company number to join as when none is given.
  join_server_password | The password for the server.

Returns
  Whether the join has started.

Definition at line 786 of file network.cpp.

References _network_available, _network_join, _switch_mode, NetworkJoinInfo::company, ServerAddress::connection_string, NetworkJoinInfo::connection_string, Debug, NETWORK_DEFAULT_PORT, NetworkClientJoinGame(), NetworkValidateOurClientName(), ServerAddress::Parse(), NetworkJoinInfo::server_password, and SM_JOIN_GAME.

Referenced by NetworkGameWindow::OnClick(), and AfterNewGRFScan::OnNewGRFsScanned().

## ◆ 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 819 of file network.cpp.

References _network_join, _network_join_status, _settings_client, NetworkJoinInfo::connection_string, Debug, NetworkSettings::last_joined, ClientSettings::network, and NetworkDisconnect().

Referenced by NetworkClientConnectGame().

## ◆ NetworkClientPreferTeamChat()

bool NetworkClientPreferTeamChat | ( | const NetworkClientInfo * | cio | ) |

Tell whether the client has team members who they can chat to.

Parameters

  cio | client to check members of.

Returns
  true if there is at least one team member.

Definition at line 1331 of file network_client.cpp.

References _settings_client, NetworkClientInfo::client_playas, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkclientinfo_pool >::Iterate(), and GUISettings::prefer_teamchat.

Referenced by MainWindow::OnHotkey().

## ◆ NetworkClientRequestMove()

void NetworkClientRequestMove | ( | CompanyID | company_id | ) |

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

Parameters

  company_id | id of the company the client wishes to be moved to.

Definition at line 1214 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendMove().

Referenced by MenuClickCompany(), CompanyWindow::OnClick(), and NetworkClientListWindow::OnClickCompanyJoin().

## ◆ NetworkClientSendChat()

void NetworkClientSendChat | ( | NetworkAction | action,
|  | DestType | type,
|  | int | dest,
|  | std::string_view | msg,
|  | int64_t | data
| ) |  |

Send a chat message.

Parameters

  action | The action associated with the message.
  type | The destination type.
  dest | The destination index, be it a company index or client id.
  msg | The actual message.
  data | Arbitrary extra data.

Definition at line 1321 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendChat().

## ◆ NetworkClientSendRcon()

void NetworkClientSendRcon | ( | std::string_view | password,
|  | std::string_view | command
| ) |  |

Send a remote console command.

Parameters

  password | The password.
  command | The command to execute.

Definition at line 1205 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendRCon().

## ◆ NetworkClientsToSpectators()

void NetworkClientsToSpectators | ( | CompanyID | cid | ) |

Move the clients of a company to the spectators.

Parameters

  cid | The company to move the clients of.

Definition at line 1223 of file network_client.cpp.

References _current_company, _local_company, CC_DEFAULT, COMPANY_SPECTATOR, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkclientinfo_pool >::Iterate(), Backup< T >::Restore(), and SetLocalCompany().

Referenced by ChangeOwnershipOfCompanyItems().

## ◆ NetworkCompanyHasClients()

bool NetworkCompanyHasClients | ( | CompanyID | company | ) |

Check whether a particular company has clients.

Parameters

  company | The company to check.

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

Definition at line 2090 of file network_server.cpp.

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

Referenced by AdminCompanyResetCallback(), and NetworkClientListWindow::OnClickCompanyAdmin().

## ◆ NetworkDisconnect()

void NetworkDisconnect | ( | bool | close_admins | ) |

We want to disconnect from the host/clients.

Parameters

  close_admins | Whether the admin sockets need to be closed as well.

Definition at line 1000 of file network.cpp.

References _network_server, CloseWindowById(), ServerNetworkAdminSocketHandler::IterateActive(), NetworkClose(), NetworkUDPInitialize(), WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.

Referenced by NetworkClientJoinGame(), NetworkShutDown(), NetworkJoinStatusWindow::OnClick(), NetworkJoinStatusWindow::OnQueryTextFinished(), and SafeLoad().

## ◆ NetworkGameLoop()

void NetworkGameLoop | ( |  | ) |

Definition at line 1095 of file network.cpp.

## ◆ NetworkGetCompanyStats()

NetworkCompanyStatsArray NetworkGetCompanyStats | ( |  | ) |

Get the company stats.

Definition at line 1491 of file network_server.cpp.

References Airport, BusStop, Dock, SpecializedVehicle< T, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), NetworkCompanyStats::num_station, Train, TruckStop, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by ServerNetworkAdminSocketHandler::SendCompanyStats().

## ◆ NetworkGetPublicKeyOfClient()

std::string_view NetworkGetPublicKeyOfClient | ( | ClientID | client_id | ) |

Get the public key of the client with the given id.

Parameters

  client_id | The id of the client.

Returns
  View of the public key, which is empty when the client does not exist.

Definition at line 2138 of file network_server.cpp.

## ◆ NetworkHandlePauseChange()

void NetworkHandlePauseChange | ( | PauseModes | prev_mode,
|  | PauseMode | changed_mode
| ) |  |

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

Parameters

  prev_mode | The previous pause mode.
  changed_mode | The pause mode that got changed.

Definition at line 352 of file network.cpp.

References _networking, _pause_mode, ActiveClients, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CC_DEFAULT, GameScript, GetString(), GetStringWithArgs(), Join, LinkGraph, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), Normal, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdPause().

## ◆ NetworkInitChatMessage()

void NetworkInitChatMessage | ( |  | ) |

Initialize all buffers of the chat visualisation.

Definition at line 108 of file network_chat_gui.cpp.

References _chatmessage_visible, _chatmsg_box, _chatmsg_list, _settings_client, ClientSettings::gui, MAX_CHAT_MESSAGES, GUISettings::network_chat_box_height, GUISettings::network_chat_box_width_pct, NetworkReInitChatBoxSize(), and ScaleGUITrad().

## ◆ NetworkIsValidClientName()

bool NetworkIsValidClientName | ( | std::string_view | client_name | ) |

Check whether the given client name is deemed valid for use in network games.

An empty name (null or '') is not valid as that is essentially no name at all. A name starting with white space is not valid for tab completion purposes.

Parameters

  client_name | The client name to check for validity.

Returns
  True iff the name is valid.

Definition at line 1245 of file network_client.cpp.

Referenced by NetworkValidateClientName(), ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(), and ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO().

## ◆ NetworkMaxCompaniesAllowed()

uint NetworkMaxCompaniesAllowed | ( |  | ) |

Get the maximum number of companies that are allowed by the server.

Returns
  The number of companies allowed.

Definition at line 1347 of file network_client.cpp.

References _network_server, _network_server_max_companies, _settings_client, NetworkSettings::max_companies, and ClientSettings::network.

Referenced by NetworkClientListWindow::GetWidgetString(), and NetworkMaxCompaniesReached().

## ◆ 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 1356 of file network_client.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetNumItems(), and NetworkMaxCompaniesAllowed().

Referenced by NetworkClientListWindow::RebuildList().

## ◆ NetworkOnGameStart()

void NetworkOnGameStart | ( |  | ) |

Perform tasks when the server is started.

This consists of things like putting the server's client in a valid company and resetting the restart time.

Definition at line 946 of file network.cpp.

References _network_dedicated, _network_server, ChangeNetworkRestartTime(), CLIENT_ID_SERVER, NetworkClientInfo::client_playas, NetworkClientInfo::GetByClientID(), GetFirstPlayableCompanyID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, CompanyProperties::name, CompanyProperties::name_1, NetworkServerNewCompany(), NetworkServerUpdateGameInfo(), and ServerNetworkAdminSocketHandler::WelcomeAll().

Referenced by OnStartGame().

## ◆ NetworkPrintClients()

void NetworkPrintClients | ( |  | ) |

Print all the clients to the console.

Definition at line 2115 of file network_server.cpp.

References _network_server, CC_INFO, CLIENT_ID_SERVER, IConsolePrint(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkclientinfo_pool >::Iterate().

## ◆ NetworkReboot()

void NetworkReboot | ( |  | ) |

Definition at line 977 of file network.cpp.

## ◆ NetworkReInitChatBoxSize()

void NetworkReInitChatBoxSize | ( |  | ) |

Initialize all font-dependent chat box sizes.

Definition at line 101 of file network_chat_gui.cpp.

References _chatmsg_box, FS_NORMAL, GetCharacterHeight(), MAX_CHAT_MESSAGES, NETWORK_CHAT_LINE_SPACING, and ScaleGUITrad().

Referenced by NetworkInitChatMessage(), and ReInitAllWindows().

## ◆ NetworkServerChangeClientName()

bool NetworkServerChangeClientName | ( | ClientID | client_id,
|  | const std::string & | new_name
| ) |  |

Change the client name of the given client.

Parameters

  client_id | the client to change the name of
  new_name | the new name for the client

Returns
  true iff the name was changed

Definition at line 1647 of file network_server.cpp.

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

## ◆ NetworkServerDoMove()

void NetworkServerDoMove | ( | ClientID | client_id,
|  | CompanyID | company_id
| ) |  |

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

Parameters

  client_id | id of the client we want to move.
  company_id | id of the company we want to move the client to.

Returns
  void

Definition at line 1976 of file network_server.cpp.

References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, DESTTYPE_BROADCAST, NetworkClientInfo::GetByClientID(), GetString(), InvalidateWindowData(), NetworkServerSendChat(), NetworkUpdateClientInfo(), SetLocalCompany(), and WC_CLIENT_LIST.

Referenced by MenuClickCompany(), CompanyWindow::OnClick(), NetworkClientListWindow::OnClickCompanyJoin(), and ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE().

## ◆ NetworkServerKickClient()

void NetworkServerKickClient | ( | ClientID | client_id,
|  | std::string_view | reason
| ) |  |

Kick a single client.

Parameters

  client_id | The client to kick.
  reason | In case of kicking a client, specifies the reason for kicking the client.

Definition at line 2029 of file network_server.cpp.

References CLIENT_ID_SERVER.

Referenced by AdminClientKickCallback(), and NetworkServerKickOrBanIP().

## ◆ NetworkServerKickOrBanIP() [1/2]

uint NetworkServerKickOrBanIP | ( | ClientID | client_id,
|  | bool | ban,
|  | std::string_view | reason
| ) |  |

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

Parameters

  client_id | The client to check for.
  ban | Whether to ban or kick.
  reason | In case of kicking a client, specifies the reason for kicking the client.

Definition at line 2041 of file network_server.cpp.

References NetworkServerKickOrBanIP().

Referenced by AdminClientBanCallback(), and NetworkServerKickOrBanIP().

## ◆ NetworkServerKickOrBanIP() [2/2]

uint NetworkServerKickOrBanIP | ( | std::string_view | ip,
|  | bool | ban,
|  | std::string_view | reason
| ) |  |

Kick or ban someone based on an IP address.

Parameters

  ip | The IP address/range to ban/kick.
  ban | Whether to ban or just kick.
  reason | In case of kicking a client, specifies the reason for kicking the client.

Definition at line 2052 of file network_server.cpp.

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

## ◆ NetworkServerNewCompany()

void NetworkServerNewCompany | ( | const Company * | c,
|  | NetworkClientInfo * | ci
| ) |  |

Perform all the server specific administration of a new company.

Parameters

  c | The newly created company; can't be nullptr.
  ci | The client information of the client that made the company; can be nullptr.

Definition at line 2150 of file network_server.cpp.

References _network_server, CALCA_ADD, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, DESTTYPE_BROADCAST, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, NetworkServerSendChat(), NetworkUpdateClientInfo(), and NetworkClientInfo::public_key.

Referenced by CmdCompanyCtrl(), and NetworkOnGameStart().

## ◆ NetworkServerSendChat()

void NetworkServerSendChat | ( | NetworkAction | action,
|  | DestType | desttype,
|  | int | dest,
|  | std::string_view | msg,
|  | ClientID | from_id,
|  | int64_t | data,
|  | bool | from_admin
| ) |  |

Send an actual chat message.

Parameters

  action | The action that's performed.
  desttype | The type of destination.
  dest | The actual destination index.
  msg | The actual message.
  from_id | The origin of the message.
  data | Arbitrary data.
  from_admin | Whether the origin is an admin or not.

Definition at line 1252 of file network_server.cpp.

References _local_company, _settings_client, NetworkClientInfo::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, Debug, DESTTYPE_BROADCAST, DESTTYPE_CLIENT, DESTTYPE_TEAM, NetworkClientInfo::GetByClientID(), GetDrawStringCompanyColour(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), ClientSettings::network, NetworkAdminChat(), NetworkSettings::server_admin_chat, and ServerNetworkGameSocketHandler::STATUS_AUTHORIZED.

Referenced by NetworkServerDoMove(), NetworkServerNewCompany(), ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and SendChat().

## ◆ NetworkServerSendConfigUpdate()

void NetworkServerSendConfigUpdate | ( |  | ) |

Send Config Update.

Definition at line 1957 of file network_server.cpp.

Referenced by UpdateClientConfigValues().

## ◆ NetworkServerSendExternalChat()

void NetworkServerSendExternalChat | ( | std::string_view | source,
|  | TextColour | colour,
|  | std::string_view | user,
|  | std::string_view | msg
| ) |  |

Send a chat message from external source.

Parameters

  source | Name of the source this message came from.
  colour | TextColour to use for the message.
  user | Name of the user who sent the message.
  msg | The actual message.

Definition at line 1369 of file network_server.cpp.

References ServerNetworkGameSocketHandler::STATUS_AUTHORIZED.

Referenced by ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT().

## ◆ NetworkServerSendRcon()

void NetworkServerSendRcon | ( | ClientID | client_id,
|  | TextColour | colour_code,
|  | std::string_view | string
| ) |  |

Send an rcon reply to the client.

Parameters

  client_id | The identifier of the client.
  colour_code | The colour of the text.
  string | The actual reply.

Definition at line 2019 of file network_server.cpp.

Referenced by IConsolePrint().

## ◆ NetworkServerShowStatusToConsole()

void NetworkServerShowStatusToConsole | ( |  | ) |

Show the status message of all clients on the console.

Definition at line 1925 of file network_server.cpp.

References CC_INFO, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, IConsolePrint(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), and lengthof.

## ◆ NetworkServerStart()

bool NetworkServerStart | ( |  | ) |

Definition at line 891 of file network.cpp.

## ◆ NetworkServerUpdateGameInfo()

void NetworkServerUpdateGameInfo | ( |  | ) |

Update the server's NetworkServerGameInfo due to changes in settings.

Definition at line 1965 of file network_server.cpp.

References _network_server.

Referenced by NetworkOnGameStart(), and UpdateClientConfigValues().

## ◆ NetworkSpectatorCount()

uint8_t NetworkSpectatorCount | ( |  | ) |

Definition at line 216 of file network.cpp.

## ◆ NetworkUndrawChatMessage()

void NetworkUndrawChatMessage | ( |  | ) |

Hide the chatbox.

Definition at line 120 of file network_chat_gui.cpp.

References _chatmessage_backup, _chatmessage_dirty, _chatmessage_dirty_time, _chatmessage_visible, _chatmsg_box, Blitter::CopyFromBuffer(), CursorVars::draw_size, ReusableBuffer< T >::GetBuffer(), BlitterFactory::GetCurrentBlitter(), VideoDriver::GetInstance(), VideoDriver::MakeDirty(), Blitter::MoveTo(), CursorVars::visible, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by NetworkDrawChatMessage(), RedrawScreenRect(), and ReInitAllWindows().

## ◆ NetworkUpdateClientInfo()

void NetworkUpdateClientInfo | ( | ClientID | client_id | ) |

Send updated client info of a particular client.

Parameters

  client_id | The client to send it for.

Definition at line 1529 of file network_server.cpp.

References NetworkClientInfo::client_playas, TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, NetworkClientInfo::GetByClientID(), NetworkAdminClientUpdate(), and ServerNetworkGameSocketHandler::STATUS_AUTHORIZED.

Referenced by CmdCompanyCtrl(), NetworkServerChangeClientName(), NetworkServerDoMove(), NetworkServerNewCompany(), NetworkUpdateClientName(), and ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME().

## ◆ NetworkUpdateClientName()

void NetworkUpdateClientName | ( | const std::string & | client_name | ) |

Send the server our name as callback from the setting.

Parameters

  newname | The new client name.

Definition at line 1292 of file network_client.cpp.

References _network_own_client_id, _network_server, CC_DEFAULT, CLIENT_ID_SERVER, NetworkClientInfo::client_name, NetworkClientInfo::GetByClientID(), NetworkMakeClientNameUnique(), NetworkUpdateClientInfo(), and ClientNetworkGameSocketHandler::SendSetName().

## ◆ NetworkUpdateServerGameType()

void NetworkUpdateServerGameType | ( |  | ) |

The setting server_game_type was updated; possibly we need to take some action.

Definition at line 1028 of file network.cpp.

References _network_coordinator_client, _networking, _settings_client, ClientNetworkCoordinatorSocketHandler::CloseConnection(), ClientSettings::network, ClientNetworkCoordinatorSocketHandler::Register(), and NetworkSettings::server_game_type.

Referenced by NetworkClientListWindow::OnDropdownSelect().

## ◆ NetworkValidateClientName()

bool NetworkValidateClientName | ( | std::string & | client_name | ) |

Trim the given client name in place, i.e.

remove leading and trailing spaces. After the trim check whether the client name is valid. A client name is valid whenever the name is not empty and does not start with spaces. This check is done via `NetworkIsValidClientName`. When the client name is valid, this function returns true. When the client name is not valid a GUI error message is shown telling the user to set the client name and this function returns false.

This function is not suitable for ensuring a valid client name at the server as the error message will then be shown to the host instead of the client.

Parameters

  client_name | The client name to validate. It will be trimmed of leading and trailing spaces.

Returns
  True iff the client name is valid.

Definition at line 1267 of file network_client.cpp.

References GetEncodedString(), NetworkIsValidClientName(), ShowErrorMessage(), StrTrimInPlace(), and WL_ERROR.

Referenced by NetworkValidateOurClientName().

## ◆ NetworkValidateOurClientName()

bool NetworkValidateOurClientName | ( |  | ) |

Convenience method for NetworkValidateClientName on _settings_client.network.client_name.

It trims the client name and checks whether it is empty. When it is empty an error message is shown to the GUI user. See `NetworkValidateClientName(std::string&)` for details about the functionality.

Returns
  True iff the client name is valid.

Definition at line 1283 of file network_client.cpp.

References _settings_client, NetworkSettings::client_name, ClientSettings::network, and NetworkValidateClientName().

Referenced by NetworkClientConnectGame().

## ◆ NetworkValidateServerName()

bool NetworkValidateServerName | ( | std::string & | server_name | ) |

Trim the given server name in place, i.e.

remove leading and trailing spaces. After the trim check whether the server name is not empty. When the server name is empty a GUI error message is shown telling the user to set the servername and this function returns false.

Parameters

  server_name | The server name to validate. It will be trimmed of leading and trailing spaces.

Returns
  True iff the server name is valid.

Definition at line 859 of file network.cpp.

References GetEncodedString(), ShowErrorMessage(), StrTrimInPlace(), and WL_ERROR.

## ◆ ParseFullConnectionString()

std::string_view ParseFullConnectionString | ( | std::string_view | connection_string,
|  | uint16_t & | port,
|  | CompanyID * | company_id
| ) |  |

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

Returns the IP part as a string view into the passed string. This view is valid as long the passed connection string is valid. If there is no port present in the connection string, the port reference will not be touched. When there is no company ID present in the connection string or company_id is nullptr, then company ID will not be touched.

Parameters

  connection_string | The string with the connection data.
  port | The port reference to set.
  company_id | The company ID to set, if available.

Returns
  A std::string_view into the connection string with the (IP) address part.

Definition at line 520 of file network.cpp.

References ParseCompanyFromConnectionString().

Referenced by NormalizeConnectionString(), openttd_main(), ServerAddress::Parse(), and ParseConnectionString().

## Variable Documentation

## ◆ _network_ban_list

StringList _network_ban_list
| extern

The banned clients.

Definition at line 77 of file network.cpp.

Referenced by NetworkServerKickOrBanIP().

## ◆ _network_bind_list

StringList _network_bind_list
| extern

The addresses to bind on.

Definition at line 75 of file network.cpp.

Referenced by GetBindAddresses(), and AfterNewGRFScan::OnNewGRFsScanned().

## ◆ _network_host_list

StringList _network_host_list
| extern

The servers we know.

Definition at line 76 of file network.cpp.

## ◆ _network_own_client_id

ClientID _network_own_client_id
| extern

Uncomment the following define to enable command replaying.

See docs/desync.md for details.

Uncomment the following define to enable command replaying.

Definition at line 72 of file network.cpp.

Referenced by CmdCompanyCtrl(), CmdGoalQuestion(), CmdScrollViewport(), ClientButtonLine::Draw(), ClientButtonLine::GetTooltip(), NetworkClientListWindow::GetWidgetString(), NetworkAdminCmdLogging(), NetworkCanJoinCompany(), NetworkUpdateClientName(), NetworkClientListWindow::OnClick(), NetworkClientListWindow::OnClickCompanyNew(), TCPClientConnecter::OnConnect(), MainWindow::OnHotkey(), NetworkClientListWindow::RebuildList(), NetworkClientListWindow::RebuildListCompany(), ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(), ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(), ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(), ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME(), OrderBackup::Reset(), and NetworkClientListWindow::UpdateWidgetSize().

## ◆ _network_reconnect

uint8_t _network_reconnect
| extern

Reconnect timeout.

Definition at line 74 of file network.cpp.

## ◆ _redirect_console_to_client

ClientID _redirect_console_to_client
| extern

If not invalid, redirect the console output to a client.

Definition at line 73 of file network.cpp.

Referenced by IConsolePrint(), NetworkServerKickOrBanIP(), ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().