# network_server.cpp File Reference

Server part of the network protocol. More...

`#include "../stdafx.h"`
`#include "../strings_func.h"`
`#include "../date_func.h"`
`#include "network_admin.h"`
`#include "network_server.h"`
`#include "network_udp.h"`
`#include "network_base.h"`
`#include "../console_func.h"`
`#include "../company_base.h"`
`#include "../command_func.h"`
`#include "../saveload/saveload.h"`
`#include "../saveload/saveload_filter.h"`
`#include "../station_base.h"`
`#include "../genworld.h"`
`#include "../company_func.h"`
`#include "../company_gui.h"`
`#include "../window_func.h"`
`#include "../roadveh.h"`
`#include "../order_backup.h"`
`#include "../core/pool_func.hpp"`
`#include "../core/random_func.hpp"`
`#include "../rev.h"`

Go to the source code of this file.

## Data Structures
struct | PacketWriter
| Writing a savegame directly to a number of packets. More...
## Functions
| assert_compile (MAX_CLIENT_SLOTS > MAX_CLIENTS)
| Make very sure the preconditions given in network_type.h are actually followed.
| assert_compile (NetworkClientSocketPool::MAX_SIZE==MAX_CLIENT_SLOTS)
static void | NetworkHandleCommandQueue (NetworkClientSocket *cs)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_COMPANY_INFO)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_NEWGRFS_CHECKED)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_JOIN)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_GAME_PASSWORD)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_COMPANY_PASSWORD)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_GETMAP)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_MAP_OK)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_COMMAND)
| The client has done a command and wants us to handle it.
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_ERROR)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_QUIT)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_ACK)
void | NetworkServerSendChat (NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_CHAT)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_SET_PASSWORD)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_SET_NAME)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_RCON)
| DEF_GAME_RECEIVE_COMMAND (Server, PACKET_CLIENT_MOVE)
void | NetworkPopulateCompanyStats (NetworkCompanyStats *stats)
| Populate the company stats.
void | NetworkUpdateClientInfo (ClientID client_id)
static void | NetworkCheckRestartMap ()
static void | NetworkAutoCleanCompanies ()
bool | NetworkFindName (char new_name[NETWORK_CLIENT_NAME_LENGTH])
bool | NetworkServerChangeClientName (ClientID client_id, const char *new_name)
| Change the client name of the given client.
void | NetworkServerSetCompanyPassword (CompanyID company_id, const char *password, bool already_hashed)
| Set/Reset a company password on the server end.
void | NetworkServer_Tick (bool send_frame)
void | NetworkServerYearlyLoop ()
| Yearly "callback".
void | NetworkServerMonthlyLoop ()
| Monthly "callback".
void | NetworkServerDailyLoop ()
| Daily "callback".
const char * | GetClientIP (NetworkClientInfo *ci)
void | NetworkServerShowStatusToConsole ()
void | NetworkServerSendConfigUpdate ()
| Send Config Update.
void | NetworkServerUpdateCompanyPassworded (CompanyID company_id, bool passworded)
void | NetworkServerDoMove (ClientID client_id, CompanyID company_id)
| Handle the tid-bits of moving a client from one company to another.
void | NetworkServerSendRcon (ClientID client_id, TextColour colour_code, const char *string)
static void | NetworkServerSendError (ClientID client_id, NetworkErrorCode error)
void | NetworkServerKickClient (ClientID client_id)
uint | NetworkServerKickOrBanIP (const char *ip, bool ban)
bool | NetworkCompanyHasClients (CompanyID company)
## Variables
static ClientID | _network_client_id = CLIENT_ID_FIRST
| The identifier counter for new clients (is never decreased).
NetworkClientSocketPool | _networkclientsocket_pool ("NetworkClientSocket")

## Detailed Description

Server part of the network protocol.

Definition in file network_server.cpp.

## Function Documentation

DEF_GAME_RECEIVE_COMMAND | ( | Server | ,
|  | PACKET_CLIENT_COMMAND |  |
| ) |  |  |

The client has done a command and wants us to handle it.

Parameters:

  | p | the packet in which the command was sent

Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs to match the company in the packet. If it doesn't, the client has done something pretty naughty (or a bug), and will be kicked

Definition at line 993 of file network_server.cpp.

References _settings_client, CC_ERROR, NetworkClientInfo::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, CommandContainer::cmd, CMD_CLIENT_ID, CMD_COMPANY_CTRL, CMD_SERVER, CMD_SPECTATOR, CommandPacket::company, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, DESTTYPE_CLIENT, GetCommandFlags(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), IConsolePrintF(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NetworkSettings::max_commands_in_queue, NetworkSettings::max_companies, ClientSettings::network, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_OKAY, CommandContainer::p1, and CommandContainer::p2.

void NetworkPopulateCompanyStats | ( | NetworkCompanyStats * | stats | ) |

Populate the company stats.

Parameters:

  | stats | the stats to update

Definition at line 1460 of file network_server.cpp.

References FACIL_AIRPORT, FACIL_BUS_STOP, FACIL_DOCK, FACIL_TRAIN, FACIL_TRUCK_STOP, BaseStation::facilities, FOR_ALL_VEHICLES, SpecializedVehicle< RoadVehicle, Type >::From(), RoadVehicle::IsBus(), Vehicle::IsPrimaryVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MAX_COMPANIES, NetworkCompanyStats::num_station, NetworkCompanyStats::num_vehicle, BaseStation::owner, Vehicle::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

bool NetworkServerChangeClientName | ( | ClientID | client_id,
|  | const char * | new_name |
| ) |  |  |

Change the client name of the given client.

Parameters:

  | client_id | the client to change the name of
  | new_name | the new name for the client

Returns:
  true iff the name was changed

Definition at line 1642 of file network_server.cpp.

References CC_DEFAULT, NetworkClientInfo::client_name, lastof, NetworkFindClientInfoFromClientID(), and strecpy().

void NetworkServerDailyLoop | ( |  | ) |

Daily "callback".

Called whenever the date changes.

Definition at line 1798 of file network_server.cpp.

References _date, ADMIN_FREQUENCY_DAILY, ADMIN_FREQUENCY_WEEKLY, and NetworkAdminUpdate().

Referenced by OnNewDay().

void NetworkServerDoMove | ( | ClientID | client_id,
|  | CompanyID | company_id |
| ) |  |  |

Handle the tid-bits of moving a client from one company to another.

Parameters:

  | client_id | id of the client we want to move.
  | company_id | id of the company we want to move the client to.

Returns:
  void

Definition at line 1872 of file network_server.cpp.

References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, DESTTYPE_BROADCAST, NetworkFindClientInfoFromClientID(), NetworkFindClientStateFromClientID(), and SetLocalCompany().

Referenced by CompanyWindow::OnClick().

void NetworkServerMonthlyLoop | ( |  | ) |

Monthly "callback".

Called whenever the month changes.

Definition at line 1790 of file network_server.cpp.

References _cur_month, ADMIN_FREQUENCY_MONTHLY, ADMIN_FREQUENCY_QUARTERLY, and NetworkAdminUpdate().

Referenced by OnNewMonth().

void NetworkServerSetCompanyPassword | ( | CompanyID | company_id,
|  | const char * | password,
|  | bool | already_hashed |
| ) |  |  |

Set/Reset a company password on the server end.

Parameters:

  | company_id | ID of the company the password should be changed for.
  | password | The new password.
  | already_hashed | Is the given password already hashed?

Definition at line 1667 of file network_server.cpp.

References _settings_client, _settings_game, GameSettings::game_creation, GenerateCompanyPasswordHash(), GameCreationSettings::generation_seed, Company::IsValidHumanID(), lastof, ClientSettings::network, NetworkSettings::network_id, strecpy(), and StrEmpty().

Referenced by NetworkChangeCompanyPassword().

void NetworkServerYearlyLoop | ( |  | ) |

Yearly "callback".

Called whenever the year changes.

Definition at line 1783 of file network_server.cpp.

References ADMIN_FREQUENCY_ANUALLY, and NetworkAdminUpdate().

Referenced by OnNewYear().