# network_internal.h File Reference

Variables and function used internally. More...

`#include "network_func.h"`
`#include "core/tcp_game.h"`
`#include "../command_type.h"`

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

## Defines

#define | _ddc_fastforward (false)
| Helper variable to make the dedicated server go fast until the (first) join.
#define | DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
#define | DEF_CLIENT_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command()
#define | DEF_CLIENT_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
#define | DEF_SERVER_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(NetworkClientSocket *cs, Packet *p)
#define | DEF_SERVER_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command(NetworkClientSocket *cs)
#define | DEF_SERVER_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
#define | SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
#define | RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command

## Enumerations

enum | MapPacket { MAP_PACKET_START, MAP_PACKET_NORMAL, MAP_PACKET_END }
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 }

enum

NetworkLanguage {
NETLANG_ANY = 0, NETLANG_ENGLISH, NETLANG_GERMAN, NETLANG_FRENCH,
NETLANG_BRAZILIAN, NETLANG_BULGARIAN, NETLANG_CHINESE, NETLANG_CZECH,
NETLANG_DANISH, NETLANG_DUTCH, NETLANG_ESPERANTO, NETLANG_FINNISH,
NETLANG_HUNGARIAN, NETLANG_ICELANDIC, NETLANG_ITALIAN, NETLANG_JAPANESE,
NETLANG_KOREAN, NETLANG_LITHUANIAN, NETLANG_NORWEGIAN, NETLANG_POLISH,
NETLANG_PORTUGUESE, NETLANG_ROMANIAN, NETLANG_RUSSIAN, NETLANG_SLOVAK,
NETLANG_SLOVENIAN, NETLANG_SPANISH, NETLANG_SWEDISH, NETLANG_TURKISH,
NETLANG_UKRAINIAN, NETLANG_AFRIKAANS, NETLANG_CROATIAN, NETLANG_CATALAN,
NETLANG_ESTONIAN, NETLANG_GALICIAN, NETLANG_GREEK, NETLANG_LATVIAN,
NETLANG_COUNT
}

| Language ids for server_lang and client_lang. More...

## Functions

void | NetworkTCPQueryServer (NetworkAddress address)
void | GetBindAddresses (NetworkAddressList *addresses, uint16 port)
| Get the addresses to bind to.
void | NetworkAddServer (const char *b)
void | NetworkRebuildHostList ()
void | UpdateNetworkGameWindow (bool unselect)
| Update the network new window because a new server is found on the network.
bool | IsNetworkCompatibleVersion (const char *version)
| Checks whether the given version string is compatible with our version.
void | NetworkAddCommandQueue (CommandPacket cp, NetworkClientSocket *cs=NULL)
| Add a command to the local or client socket command queue, based on the socket.
void | NetworkExecuteLocalCommandQueue ()
| Execute all commands on the local command queue that ought to be executed this frame.
void | NetworkFreeLocalCommandQueue ()
| Free the local command queue.
void | NetworkSyncCommandQueue (NetworkClientSocket *cs)
| Sync our local command queue to the command queue of the given socket.
NetworkRecvStatus | NetworkCloseClient (NetworkClientSocket *cs, NetworkRecvStatus status)
void | NetworkTextMessage (NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str="", int64 data=0)
void | NetworkGetClientName (char *clientname, size_t size, const NetworkClientSocket *cs)
uint | NetworkCalculateLag (const NetworkClientSocket *cs)
byte | NetworkGetCurrentLanguageIndex ()
NetworkClientSocket * | NetworkFindClientStateFromClientID (ClientID client_id)
| Return the client state given it's client-identifier.
StringID | GetNetworkErrorMsg (NetworkErrorCode err)
| Retrieve the string id of an internal error number.
bool | NetworkFindName (char new_name[NETWORK_CLIENT_NAME_LENGTH])

## Variables

uint32 | _frame_counter_server
uint32 | _frame_counter_max
uint32 | _frame_counter
uint32 | _last_sync_frame
NetworkAddressList | _broadcast_list
uint32 | _sync_seed_1
uint32 | _sync_frame
bool | _network_first_time
NetworkJoinStatus | _network_join_status
uint8 | _network_join_waiting
uint32 | _network_join_bytes
uint32 | _network_join_bytes_total
uint8 | _network_reconnect
bool | _network_udp_server
uint16 | _network_udp_broadcast
uint8 | _network_advertise_retries
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.

## Define Documentation

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

Definition at line 50 of file network_internal.h.

## Enumeration Type Documentation

enum NetworkLanguage

Language ids for server_lang and client_lang.

Do NOT modify the order.

Definition at line 73 of file network_internal.h.

## Function Documentation

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

Get the addresses to bind to.

Parameters:

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

Definition at line 782 of file network.cpp.

References SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), and SmallVector< T, S >::Length().

StringID GetNetworkErrorMsg | ( | NetworkErrorCode | err | ) |

Retrieve the string id of an internal error number.

Parameters:

  | err | NetworkErrorCode

Returns:
  the StringID

Definition at line 334 of file network.cpp.

References lengthof.

bool IsNetworkCompatibleVersion | ( | const char * | other | ) |

Checks whether the given version string is compatible with our version.

Parameters:

  | other | the version string to compare to

Definition at line 1309 of file network.cpp.

References NETWORK_REVISION_LENGTH.

void NetworkAddCommandQueue | ( | CommandPacket | cp,
|  | NetworkClientSocket * | cs |
| ) |  |  |

Add a command to the local or client socket command queue, based on the socket.

Parameters:

  | cp | the command packet to add
  | cs | the socket to send to (NULL = locally)

Definition at line 61 of file network_command.cpp.

References NetworkClientSocket::command_queue, and CommandPacket::next.

Referenced by DEF_SERVER_RECEIVE_COMMAND(), NetworkSend_Command(), and NetworkSyncCommandQueue().

NetworkClientSocket* NetworkFindClientStateFromClientID | ( | ClientID | client_id | ) |

Return the client state given it's client-identifier.

Parameters:

  | client_id | the ClientID to search for

Returns:
  return a pointer to the corresponding NetworkClientSocket struct or NULL when not found

Definition at line 162 of file network.cpp.

References NetworkClientSocket::client_id.

Referenced by NetworkServerDoMove().

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 139 of file network_command.cpp.

References CommandContainer::callback, NetworkAddCommandQueue(), and CommandPacket::next.

void UpdateNetworkGameWindow | ( | bool | unselect | ) |

Update the network new window because a new server is found on the network.

Parameters:

  | unselect | unselect the currently selected item

Definition at line 70 of file network_gui.cpp.

References InvalidateWindowData().

Referenced by NetworkGameListAddItem(), NetworkGameListHandleDelayedInsert(), and NetworkGameListRemoveItem().