OpenTTD Source 20241224-master-gf74b0cf984
network_internal.h File Reference

Variables and function used internally. More...

Go to the source code of this file.

Data Structures

struct  CommandPacket
 Everything we need to know about a command to be able to execute it. More...
 

Typedefs

typedef class ServerNetworkGameSocketHandler NetworkClientSocket
 

Enumerations

enum  NetworkJoinStatus {
  NETWORK_JOIN_STATUS_CONNECTING , NETWORK_JOIN_STATUS_AUTHORIZING , NETWORK_JOIN_STATUS_WAITING , NETWORK_JOIN_STATUS_DOWNLOADING ,
  NETWORK_JOIN_STATUS_PROCESSING , NETWORK_JOIN_STATUS_REGISTERING , NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO , NETWORK_JOIN_STATUS_END
}
 Status of the clients during joining. More...
 

Functions

void NetworkQueryServer (const std::string &connection_string)
 Query a server to fetch the game-info.
 
void GetBindAddresses (NetworkAddressList *addresses, uint16_t port)
 Get the addresses to bind to.
 
struct NetworkGameListNetworkAddServer (const std::string &connection_string, bool manually=true, bool never_expire=false)
 Validates an address entered as a string and adds the server to the list.
 
void NetworkRebuildHostList ()
 
void UpdateNetworkGameWindow ()
 Update the network new window because a new server is found on the network.
 
void NetworkDistributeCommands ()
 Distribute the commands of ourself and the clients.
 
void NetworkExecuteLocalCommandQueue ()
 Execute all commands on the local command queue that ought to be executed this frame.
 
void NetworkFreeLocalCommandQueue ()
 Free the local command queues.
 
void NetworkSyncCommandQueue (NetworkClientSocket *cs)
 Sync our local command queue to the command queue of the given socket.
 
void NetworkReplaceCommandClientId (CommandPacket &cp, ClientID client_id)
 Insert a client ID into the command data in a command packet.
 
void ShowNetworkError (StringID error_string)
 
void NetworkTextMessage (NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str="", int64_t data=0, const std::string &data_str="")
 
uint NetworkCalculateLag (const NetworkClientSocket *cs)
 
StringID GetNetworkErrorMsg (NetworkErrorCode err)
 Retrieve the string id of an internal error number.
 
bool NetworkMakeClientNameUnique (std::string &new_name)
 Check whether a name is unique, and otherwise try to make it unique.
 
std::string_view ParseCompanyFromConnectionString (const std::string &connection_string, CompanyID *company_id)
 Parse the company part ("#company" postfix) of a connecting string.
 
NetworkAddress ParseConnectionString (const std::string &connection_string, uint16_t default_port)
 Convert a string containing either "hostname" or "hostname:ip" to a NetworkAddress.
 
std::string NormalizeConnectionString (const std::string &connection_string, uint16_t default_port)
 Normalize a connection string.
 
void ClientNetworkEmergencySave ()
 Create an emergency savegame when the network connection is lost.
 

Variables

uint32_t _frame_counter_server
 The frame_counter of the server, if in network-mode.
 
uint32_t _frame_counter_max
 To where we may go with our clients.
 
uint32_t _frame_counter
 The current frame.
 
uint32_t _last_sync_frame
 Used in the server to store the last time a sync packet was sent to clients.
 
NetworkAddressList _broadcast_list
 List of broadcast addresses.
 
uint32_t _sync_seed_1
 Seed to compare during sync checks.
 
uint32_t _sync_frame
 The frame to perform the sync check.
 
bool _network_first_time
 Whether we have finished joining or not.
 
NetworkJoinStatus _network_join_status
 The status of joining.
 
uint8_t _network_join_waiting
 The number of clients waiting in front of us.
 
uint32_t _network_join_bytes
 The number of bytes we already downloaded.
 
uint32_t _network_join_bytes_total
 The total number of bytes to download.
 
ConnectionType _network_server_connection_type
 What type of connection the Game Coordinator detected we are on.
 
std::string _network_server_invite_code
 Our invite code as indicated by the Game Coordinator.
 
std::string _network_server_name
 The current name of the server you are on.
 
uint8_t _network_reconnect
 Reconnect timeout.
 

Detailed Description

Variables and function used internally.

Definition in file network_internal.h.

Typedef Documentation

◆ NetworkClientSocket

typedef class ServerNetworkGameSocketHandler NetworkClientSocket

Definition at line 40 of file network_internal.h.

Enumeration Type Documentation

◆ NetworkJoinStatus

Status of the clients during joining.

Definition at line 43 of file network_internal.h.

Function Documentation

◆ ClientNetworkEmergencySave()

◆ GetBindAddresses()

void GetBindAddresses ( NetworkAddressList addresses,
uint16_t  port 
)

Get the addresses to bind to.

Parameters
addressesthe list to write to.
portthe port to bind to.

Definition at line 718 of file network.cpp.

References _network_bind_list.

Referenced by TCPListenHandler< Tsocket, Tfull_packet, Tban_packet >::Listen(), and NetworkUDPInitialize().

◆ GetNetworkErrorMsg()

StringID GetNetworkErrorMsg ( NetworkErrorCode  err)

Retrieve the string id of an internal error number.

Parameters
errNetworkErrorCode
Returns
the StringID

Definition at line 313 of file network.cpp.

References lengthof.

Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(), ServerNetworkAdminSocketHandler::SendError(), and ServerNetworkGameSocketHandler::SendError().

◆ NetworkAddServer()

struct NetworkGameList * NetworkAddServer ( const std::string &  connection_string,
bool  manually,
bool  never_expire 
)

Validates an address entered as a string and adds the server to the list.

If you use this function, the games will be marked as manually added.

Parameters
connection_stringThe IP:port of the server to add.
manuallyWhether the enter should be marked as manual added.
never_expireWhether the entry can expire (removed when no longer found in the public listing).
Returns
The entry on the game list.

Definition at line 692 of file network.cpp.

References ClearGRFConfigList(), NetworkServerGameInfo::grfconfig, NetworkGameList::info, NetworkGameList::manually, NetworkGameListAddItem(), NetworkQueryServer(), NetworkServerGameInfo::server_name, UpdateNetworkGameWindow(), and NetworkGameList::version.

Referenced by NetworkGameWindow::OnQueryTextFinished(), and ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE().

◆ NetworkCalculateLag()

uint NetworkCalculateLag ( const NetworkClientSocket *  cs)

Definition at line 287 of file network.cpp.

◆ NetworkDistributeCommands()

void NetworkDistributeCommands ( )

Distribute the commands of ourself and the clients.

Definition at line 346 of file network_command.cpp.

References _local_wait_queue, and DistributeQueue().

◆ NetworkExecuteLocalCommandQueue()

void NetworkExecuteLocalCommandQueue ( )

Execute all commands on the local command queue that ought to be executed this frame.

Definition at line 40 of file network_command.cpp.

◆ NetworkFreeLocalCommandQueue()

void NetworkFreeLocalCommandQueue ( )

Free the local command queues.

Definition at line 279 of file network_command.cpp.

References _local_execution_queue, and _local_wait_queue.

◆ NetworkMakeClientNameUnique()

bool NetworkMakeClientNameUnique ( std::string &  name)

◆ NetworkQueryServer()

void NetworkQueryServer ( const std::string &  connection_string)

Query a server to fetch the game-info.

Parameters
connection_stringthe address to query.

Definition at line 670 of file network.cpp.

References _network_available, Debug, NetworkGameListAddItem(), and NetworkGameList::refreshing.

Referenced by NetworkAddServer(), and NetworkGameWindow::OnClick().

◆ NetworkRebuildHostList()

void NetworkRebuildHostList ( )

Definition at line 733 of file network.cpp.

◆ NetworkReplaceCommandClientId()

void NetworkReplaceCommandClientId ( CommandPacket cp,
ClientID  client_id 
)

Insert a client ID into the command data in a command packet.

Parameters
cpCommand packet to modify.
client_idClient id to insert.

Definition at line 433 of file network_command.cpp.

References _cmd_dispatch, and CommandPacket::cmd.

Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND().

◆ NetworkSyncCommandQueue()

void NetworkSyncCommandQueue ( NetworkClientSocket *  cs)

Sync our local command queue to the command queue of the given socket.

This is needed for the case where we receive a command before saving the game for a joining client, but without the execution of those commands. Not syncing those commands means that the client will never get them and as such will be in a desynced state from the time it started with joining.

Parameters
csThe client to sync the queue to.

Definition at line 234 of file network_command.cpp.

References _local_execution_queue, and CommandPacket::callback.

Referenced by ServerNetworkGameSocketHandler::SendMap().

◆ NetworkTextMessage()

void NetworkTextMessage ( NetworkAction  action,
TextColour  colour,
bool  self_send,
const std::string &  name,
const std::string &  str = "",
int64_t  data = 0,
const std::string &  data_str = "" 
)

Definition at line 232 of file network.cpp.

◆ NormalizeConnectionString()

std::string NormalizeConnectionString ( const std::string &  connection_string,
uint16_t  default_port 
)

Normalize a connection string.

That is, ensure there is a port in the string.

Parameters
connection_stringThe connection string to normalize.
default_portThe port to use if none is given.
Returns
The normalized connection string.

Definition at line 541 of file network.cpp.

References ParseFullConnectionString().

Referenced by TCPConnecter::TCPConnecter().

◆ ParseCompanyFromConnectionString()

std::string_view ParseCompanyFromConnectionString ( const std::string &  connection_string,
CompanyID company_id 
)

Parse the company part ("#company" postfix) of a connecting string.

Parameters
connection_stringThe string with the connection data.
company_idThe company ID to set, if available.
Returns
A std::string_view into the connection string without the company part.

Definition at line 477 of file network.cpp.

References COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, and MAX_COMPANIES.

Referenced by ServerAddress::Parse(), and ParseFullConnectionString().

◆ ParseConnectionString()

NetworkAddress ParseConnectionString ( const std::string &  connection_string,
uint16_t  default_port 
)

Convert a string containing either "hostname" or "hostname:ip" to a NetworkAddress.

Parameters
connection_stringThe string to parse.
default_portThe default port to set port to if not in connection_string.
Returns
A valid NetworkAddress of the parsed information.

Definition at line 556 of file network.cpp.

References ParseFullConnectionString().

Referenced by TCPConnecter::Resolve().

◆ ShowNetworkError()

void ShowNetworkError ( StringID  error_string)

Definition at line 302 of file network.cpp.

◆ UpdateNetworkGameWindow()

Variable Documentation

◆ _broadcast_list

NetworkAddressList _broadcast_list
extern

List of broadcast addresses.

Definition at line 80 of file network.cpp.

Referenced by NetworkStartUp(), and NetworkUDPBroadCast().

◆ _frame_counter

◆ _frame_counter_max

◆ _frame_counter_server

uint32_t _frame_counter_server
extern

The frame_counter of the server, if in network-mode.

Definition at line 76 of file network.cpp.

Referenced by NetworkClient_Connected(), ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(), and ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN().

◆ _last_sync_frame

uint32_t _last_sync_frame
extern

Used in the server to store the last time a sync packet was sent to clients.

Definition at line 79 of file network.cpp.

Referenced by NetworkServer_Tick().

◆ _network_first_time

bool _network_first_time
extern

Whether we have finished joining or not.

Definition at line 86 of file network.cpp.

Referenced by ClientNetworkGameSocketHandler::GameLoop(), and ClientNetworkGameSocketHandler::Receive_SERVER_FRAME().

◆ _network_join_bytes

uint32_t _network_join_bytes
extern

◆ _network_join_bytes_total

uint32_t _network_join_bytes_total
extern

◆ _network_join_status

◆ _network_join_waiting

uint8_t _network_join_waiting
extern

The number of clients waiting in front of us.

Definition at line 2080 of file network_gui.cpp.

Referenced by NetworkJoinStatusWindow::DrawWidget(), and ClientNetworkGameSocketHandler::Receive_SERVER_WAIT().

◆ _network_reconnect

uint8_t _network_reconnect
extern

Reconnect timeout.

Definition at line 72 of file network.cpp.

Referenced by ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME().

◆ _network_server_connection_type

◆ _network_server_invite_code

std::string _network_server_invite_code
extern

Our invite code as indicated by the Game Coordinator.

Definition at line 32 of file network_coordinator.cpp.

Referenced by ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(), and NetworkClientListWindow::SetStringParameters().

◆ _network_server_name

std::string _network_server_name
extern

◆ _sync_frame

uint32_t _sync_frame
extern

◆ _sync_seed_1