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

OpenTTD Source 14.0-beta3

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
network_internal.h File Reference
`#include "network_func.h"`
`#include "core/tcp_coordinator.h"`
`#include "core/tcp_game.h"`
`#include "../command_type.h"`
`#include "../command_func.h"`
`#include "../misc/endian_buffer.hpp"`

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

## Macros
#define | _ddc_fastforward (false)
| Helper variable to make the dedicated server go fast until the (first) join. 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.

## Functions
void | NetworkQueryServer (const std::string &connection_string)
| Query a server to fetch the game-info. More...
void | GetBindAddresses (NetworkAddressList *addresses, uint16_t port)
| Get the addresses to bind to. More...
struct NetworkGameList * | NetworkAddServer (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. More...
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. More...
void | NetworkReplaceCommandClientId (CommandPacket &cp, ClientID client_id)
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. More...
bool | NetworkMakeClientNameUnique (std::string &new_name)
| Check whether a name is unique, and otherwise try to make it unique. More...
std::string | GenerateCompanyPasswordHash (const std::string &password, const std::string &password_server_id, uint32_t password_game_seed)
| Hash the given password using server ID and game seed. More...
std::string_view | ParseCompanyFromConnectionString (const std::string &connection_string, CompanyID *company_id)
| Parse the company part ("#company" postfix) of a connecting string. More...
NetworkAddress | ParseConnectionString (const std::string &connection_string, uint16_t default_port)
| Convert a string containing either "hostname" or "hostname:ip" to a NetworkAddress. More...
std::string | NormalizeConnectionString (const std::string &connection_string, uint16_t default_port)
| Normalize a connection string. More...
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.
CompanyMask | _network_company_passworded
| Bitmask of the password status of all companies.

## Detailed Description

Variables and function used internally.

Definition in file network_internal.h.

## Macro Definition Documentation

## ◆ _ddc_fastforward

#define _ddc_fastforward (false)

Helper variable to make the dedicated server go fast until the (first) join.

Used to load the desync debug logs, i.e. for reproducing a desync. There's basically no need to ever enable this, unless you really know what you are doing, i.e. debugging a desync. See docs/desync.txt for details.

Definition at line 50 of file network_internal.h.

## Function Documentation

## ◆ GenerateCompanyPasswordHash()

std::string GenerateCompanyPasswordHash | ( | const std::string & | password,
|  | const std::string & | password_server_id,
|  | uint32_t | password_game_seed
| ) |  |

Hash the given password using server ID and game seed.

Parameters

  password | Password to hash.
  password_server_id | Server ID.
  password_game_seed | Game seed.

Returns
  The hashed password.

Definition at line 177 of file network.cpp.

References FormatArrayAsHex(), and NETWORK_SERVER_ID_LENGTH.

Referenced by NetworkServerSetCompanyPassword(), ClientNetworkGameSocketHandler::SendCompanyPassword(), ClientNetworkGameSocketHandler::SendMove(), and ClientNetworkGameSocketHandler::SendSetPassword().

## ◆ GetBindAddresses()

void GetBindAddresses | ( | NetworkAddressList * | addresses,
|  | uint16_t | port
| ) |  |

Get the addresses to bind to.

Parameters

  addresses | the list to write to.
  port | the port to bind to.

Definition at line 705 of file network.cpp.

Referenced by NetworkUDPInitialize().

## ◆ GetNetworkErrorMsg()

StringID GetNetworkErrorMsg | ( | NetworkErrorCode | err | ) |

Retrieve the string id of an internal error number.

Parameters

  err | NetworkErrorCode

Returns
  the StringID

Definition at line 298 of file network.cpp.

References lengthof.

Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), 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_string | The IP:port of the server to add.
  manually | Whether the enter should be marked as manual added.
  never_expire | Whether the entry can expire (removed when no longer found in the public listing).

Returns
  The entry on the game list.

Definition at line 679 of file network.cpp.

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

Referenced by ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE().

## ◆ NetworkMakeClientNameUnique()

bool NetworkMakeClientNameUnique | ( | std::string & | name | ) |

Check whether a name is unique, and otherwise try to make it unique.

Parameters

  new_name | The name to check/modify.

Returns
  True if an unique name was achieved.

Definition at line 1622 of file network_server.cpp.

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

Referenced by NetworkUpdateClientName().

## ◆ NetworkQueryServer()

void NetworkQueryServer | ( | const std::string & | connection_string | ) |

Query a server to fetch the game-info.

Parameters

  connection_string | the address to query.

Definition at line 657 of file network.cpp.

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

Referenced by NetworkAddServer().

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

  cs | The client to sync the queue to.

Definition at line 234 of file network_command.cpp.

References _local_execution_queue, and CommandPacket::callback.

## ◆ 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_string | The connection string to normalize.
  default_port | The port to use if none is given.

Returns
  The normalized connection string.

Definition at line 524 of file network.cpp.

## ◆ 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_string | The string with the connection data.
  company_id | The company ID to set, if available.

Returns
  A std::string_view into the connection string without the company part.

Definition at line 460 of file network.cpp.

References COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, and MAX_COMPANIES.

## ◆ 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_string | The string to parse.
  default_port | The default port to set port to if not in connection_string.

Returns
  A valid NetworkAddress of the parsed information.

Definition at line 539 of file network.cpp.

Referenced by TCPConnecter::Resolve().