# network_client.cpp File Reference

Client part of the network protocol. More...

`#include "../stdafx.h"`
`#include "../debug.h"`
`#include "network_internal.h"`
`#include "network_gui.h"`
`#include "../saveload/saveload.h"`
`#include "../command_func.h"`
`#include "../console_func.h"`
`#include "../fileio_func.h"`
`#include "../3rdparty/md5/md5.h"`
`#include "../strings_func.h"`
`#include "../window_func.h"`
`#include "../company_func.h"`
`#include "../company_base.h"`
`#include "../company_gui.h"`
`#include "../rev.h"`
`#include "network.h"`
`#include "network_base.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Defines
#define | MY_CLIENT NetworkClientSocket::Get(0)
## Typedefs
typedef NetworkRecvStatus | NetworkClientPacket (Packet *p)
## Functions
| assert_compile (NETWORK_SERVER_ID_LENGTH==16 *2+1)
| Make sure the server ID length is the same as a md5 hash.
static const char * | GenerateCompanyPasswordHash (const char *password)
| Generates a hashed password for the company name.
void | HashCurrentCompanyPassword (const char *password)
| Hash the current company password; used when the server 'company' sets his/her password.
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_COMPANY_INFO)
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_JOIN)
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_NEWGRFS_CHECKED)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_PASSWORD (NetworkPasswordType type, const char *password)
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_GETMAP)
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_MAP_OK)
| DEF_CLIENT_SEND_COMMAND (PACKET_CLIENT_ACK)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_COMMAND (const CommandPacket *cp)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_CHAT (NetworkAction action, DestType type, int dest, const char *msg, int64 data)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_ERROR (NetworkErrorCode errorno)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_SET_PASSWORD (const char *password)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_SET_NAME (const char *name)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_QUIT ()
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_RCON (const char *pass, const char *command)
DEF_CLIENT_SEND_COMMAND_PARAM() | PACKET_CLIENT_MOVE (CompanyID company, const char *pass)
bool | SafeSaveOrLoad (const char *filename, int mode, GameMode newgm, Subdirectory subdir)
| Load the specified savegame but on error do different things.
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_FULL)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_BANNED)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_COMPANY_INFO)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_CLIENT_INFO)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_ERROR)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_CHECK_NEWGRFS)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_NEED_PASSWORD)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_WELCOME)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_WAIT)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_MAP)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_FRAME)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_SYNC)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_COMMAND)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_CHAT)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_ERROR_QUIT)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_QUIT)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_JOIN)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_SHUTDOWN)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_NEWGAME)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_RCON)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_MOVE)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_CONFIG_UPDATE)
| DEF_CLIENT_RECEIVE_COMMAND (PACKET_SERVER_COMPANY_UPDATE)
| assert_compile (lengthof(_network_client_packet)==PACKET_END)
void | NetworkClient_Connected ()
NetworkRecvStatus | NetworkClient_ReadPackets (NetworkClientSocket *cs)
void | NetworkClientSendRcon (const char *password, const char *command)
void | NetworkClientRequestMove (CompanyID company_id, const char *pass)
| Notify the server of this client wanting to be moved to another company.
void | NetworkUpdateClientName ()
void | NetworkClientSendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data)
static void | NetworkClientSetPassword (const char *password)
bool | NetworkClientPreferTeamChat (const NetworkClientInfo *cio)
| Tell whether the client has team members where he/she can chat to.
const char * | NetworkChangeCompanyPassword (const char *password)
| Sets/resets company password.
bool | NetworkMaxCompaniesReached ()
| Check if max_companies has been reached on the server (local check only).
bool | NetworkMaxSpectatorsReached ()
| Check if max_spectatos has been reached on the server (local check only).
void | NetworkPrintClients ()
| Print all the clients to the console.
## Variables
static uint32 | last_ack_frame
static uint32 | _password_game_seed
| One bit of 'entropy' used to generate a salt for the company passwords.
static char | _password_server_id [NETWORK_SERVER_ID_LENGTH]
| The other bit of 'entropy' used to generate a salt for the company passwords.
static uint8 | _network_server_max_companies
| Maximum number of companies of the currently joined server.
static uint8 | _network_server_max_spectators
| Maximum number of spectators of the currently joined server.
CompanyID | _network_join_as
| Who would we like to join as.
const char * | _network_join_server_password = NULL
| Login password from -p argument.
const char * | _network_join_company_password = NULL
| Company password from -P argument.
StringID | _switch_mode_errorstr
static NetworkClientPacket *const | _network_client_packet []

## Detailed Description

Client part of the network protocol.

Definition in file network_client.cpp.

## Function Documentation

assert_compile | ( | NETWORK_SERVER_ID_LENGTH | = `=16 *2+1` | ) |

Make sure the server ID length is the same as a md5 hash.

static const char* GenerateCompanyPasswordHash | ( | const char * | password | ) | `[static]`

Generates a hashed password for the company name.

Parameters:

  | password | the password to 'encrypt'.

Returns:
  the hashed password.

Definition at line 68 of file network_client.cpp.

References _password_game_seed, _password_server_id, lengthof, NETWORK_SERVER_ID_LENGTH, and StrEmpty().

Referenced by HashCurrentCompanyPassword().

const char* NetworkChangeCompanyPassword | ( | const char * | password | ) |

Sets/resets company password.

Parameters:

  | password | new password, "" or "*" resets password

Returns:
  new password

Definition at line 1061 of file network_client.cpp.

References _network_server, and HashCurrentCompanyPassword().

Referenced by CmdCompanyCtrl().

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

Tell whether the client has team members where he/she can chat to.

Parameters:

  | cio | client to check members of.

Returns:
  true if there is at least one team member.

Definition at line 1043 of file network_client.cpp.

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

Referenced by MainWindow::OnKeyPress().

void NetworkClientRequestMove | ( | CompanyID | company_id,
|  | const char * | pass |
| ) |  |  |

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.
  | pass | the password, is only checked on the server end if a password is needed.

Returns:
  void

Definition at line 1003 of file network_client.cpp.

Referenced by CompanyWindow::OnClick(), and CompanyWindow::OnQueryTextFinished().

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 1078 of file network_client.cpp.

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

Referenced by PopupMainCompanyToolbMenu().

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 1087 of file network_client.cpp.

References _network_server, _network_server_max_spectators, _settings_client, NetworkSettings::max_spectators, and ClientSettings::network.

Referenced by PopupMainCompanyToolbMenu().

bool SafeSaveOrLoad | ( | const char * | filename,
|  | int | mode,
|  | GameMode | newgm,
|  | Subdirectory | subdir |
| ) |  |  |

Load the specified savegame but on error do different things.

If loading fails due to corrupt savegame, bad version, etc. go back to a previous correct state. In the menu for example load the intro game again.

Parameters:

  | filename | file to be loaded
  | mode | mode of loading, either SL_LOAD or SL_OLD_LOAD
  | newgm | switch to this mode of loading fails due to some unknown error
  | subdir | default directory to look for filename, set to 0 if not needed

Definition at line 916 of file openttd.cpp.

## Variable Documentation

CompanyID _network_join_as

Who would we like to join as.

Definition at line 53 of file network_client.cpp.

uint8 _network_server_max_companies`[static]`

Maximum number of companies of the currently joined server.

Definition at line 48 of file network_client.cpp.

Referenced by NetworkMaxCompaniesReached().

uint8 _network_server_max_spectators`[static]`

Maximum number of spectators of the currently joined server.

Definition at line 50 of file network_client.cpp.

Referenced by NetworkMaxSpectatorsReached().

uint32 _password_game_seed`[static]`

One bit of 'entropy' used to generate a salt for the company passwords.

Definition at line 43 of file network_client.cpp.

Referenced by GenerateCompanyPasswordHash(), and HashCurrentCompanyPassword().

char _password_server_id[NETWORK_SERVER_ID_LENGTH]`[static]`

The other bit of 'entropy' used to generate a salt for the company passwords.

Definition at line 45 of file network_client.cpp.

Referenced by GenerateCompanyPasswordHash(), and HashCurrentCompanyPassword().