OpenTTD
network_client.cpp File Reference

Client part of the network protocol. More...

#include "../stdafx.h"
#include "network_gui.h"
#include "../saveload/saveload.h"
#include "../saveload/saveload_filter.h"
#include "../command_func.h"
#include "../console_func.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "../company_func.h"
#include "../company_base.h"
#include "../company_gui.h"
#include "../core/random_func.hpp"
#include "../date_func.h"
#include "../gfx_func.h"
#include "../error.h"
#include "../rev.h"
#include "network.h"
#include "network_base.h"
#include "network_client.h"
#include "../core/backup_type.hpp"
#include "table/strings.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  PacketReader
 Read some packets, and when do use that data as initial load filter. More...
 

Functions

void ClientNetworkEmergencySave ()
 Create an emergency savegame when the network connection is lost.
 
 assert_compile (NETWORK_SERVER_ID_LENGTH==16 *2+1)
 Make sure the server ID length is the same as a md5 hash. More...
 
bool SafeLoad (const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=NULL)
 Load the specified savegame but on error do different things. More...
 
void NetworkClient_Connected ()
 Is called after a client is connected to the server.
 
void NetworkClientSendRcon (const char *password, const char *command)
 Send a remote console command. More...
 
void NetworkClientRequestMove (CompanyID company_id, const char *pass)
 Notify the server of this client wanting to be moved to another company. More...
 
void NetworkClientsToSpectators (CompanyID cid)
 Move the clients of a company to the spectators. More...
 
void NetworkUpdateClientName ()
 Send the server our name.
 
void NetworkClientSendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data)
 Send a chat message. More...
 
void NetworkClientSetCompanyPassword (const char *password)
 Set/Reset company password on the client side. More...
 
bool NetworkClientPreferTeamChat (const NetworkClientInfo *cio)
 Tell whether the client has team members where he/she can chat to. More...
 
bool NetworkMaxCompaniesReached ()
 Check if max_companies has been reached on the server (local check only). More...
 
bool NetworkMaxSpectatorsReached ()
 Check if max_spectatos has been reached on the server (local check only). More...
 

Variables

static uint32 last_ack_frame
 Last frame we performed an ack. More...
 
static uint32 _password_game_seed
 One bit of 'entropy' used to generate a salt for the company passwords. More...
 
static char _password_server_id [NETWORK_SERVER_ID_LENGTH]
 The other bit of 'entropy' used to generate a salt for the company passwords. More...
 
static uint8 _network_server_max_companies
 Maximum number of companies of the currently joined server. More...
 
static uint8 _network_server_max_spectators
 Maximum number of spectators of the currently joined server. More...
 
CompanyID _network_join_as
 Who would we like to join as. More...
 
const char * _network_join_server_password = NULL
 Login password from -p argument.
 
const char * _network_join_company_password = NULL
 Company password from -P argument.
 

Detailed Description

Client part of the network protocol.

Definition in file network_client.cpp.

Function Documentation

◆ assert_compile()

assert_compile ( NETWORK_SERVER_ID_LENGTH  = =16 *2+1)

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

Referenced by ClientNetworkGameSocketHandler::Receive_SERVER_ERROR().

◆ NetworkClientPreferTeamChat()

bool NetworkClientPreferTeamChat ( const NetworkClientInfo cio)

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

Parameters
cioclient to check members of.
Returns
true if there is at least one team member.

Definition at line 1293 of file network_client.cpp.

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

◆ NetworkClientRequestMove()

void NetworkClientRequestMove ( CompanyID  company_id,
const char *  pass 
)

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

Parameters
company_idid of the company the client wishes to be moved to.
passthe password, is only checked on the server end if a password is needed.
Returns
void

Definition at line 1218 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendMove().

◆ NetworkClientSendChat()

void NetworkClientSendChat ( NetworkAction  action,
DestType  type,
int  dest,
const char *  msg,
int64  data 
)

Send a chat message.

Parameters
actionThe action associated with the message.
typeThe destination type.
destThe destination index, be it a company index or client id.
msgThe actual message.
dataArbitrary extra data.

Definition at line 1274 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendChat().

◆ NetworkClientSendRcon()

void NetworkClientSendRcon ( const char *  password,
const char *  command 
)

Send a remote console command.

Parameters
passwordThe password.
commandThe command to execute.

Definition at line 1207 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendRCon().

◆ NetworkClientSetCompanyPassword()

void NetworkClientSetCompanyPassword ( const char *  password)

Set/Reset company password on the client side.

Parameters
passwordPassword to be set.

Definition at line 1283 of file network_client.cpp.

References ClientNetworkGameSocketHandler::SendSetPassword().

Referenced by NetworkChangeCompanyPassword().

◆ NetworkClientsToSpectators()

void NetworkClientsToSpectators ( CompanyID  cid)

Move the clients of a company to the spectators.

Parameters
cidThe company to move the clients of.

Definition at line 1227 of file network_client.cpp.

References _current_company.

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

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

Referenced by PopupMainCompanyToolbMenu().

◆ NetworkMaxSpectatorsReached()

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

Referenced by PopupMainCompanyToolbMenu().

◆ SafeLoad()

bool SafeLoad ( const char *  filename,
SaveLoadOperation  fop,
DetailedFileType  dft,
GameMode  newgm,
Subdirectory  subdir,
struct LoadFilter lf = NULL 
)

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
filenamefile to be loaded
fopmode of loading, always SLO_LOAD
newgmswitch to this mode of loading fails due to some unknown error
subdirdefault directory to look for filename, set to 0 if not needed
lfLoad filter to use, if NULL: use filename + subdir.

Definition at line 1013 of file openttd.cpp.

Referenced by ClientNetworkGameSocketHandler::IsConnected().

Variable Documentation

◆ _network_join_as

CompanyID _network_join_as

Who would we like to join as.

Definition at line 314 of file network_client.cpp.

◆ _network_server_max_companies

uint8 _network_server_max_companies
static

Maximum number of companies of the currently joined server.

Definition at line 309 of file network_client.cpp.

Referenced by NetworkMaxCompaniesReached().

◆ _network_server_max_spectators

uint8 _network_server_max_spectators
static

Maximum number of spectators of the currently joined server.

Definition at line 311 of file network_client.cpp.

◆ _password_game_seed

uint32 _password_game_seed
static

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

Definition at line 304 of file network_client.cpp.

◆ _password_server_id

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

◆ last_ack_frame

uint32 last_ack_frame
static

Last frame we performed an ack.

Definition at line 301 of file network_client.cpp.