|
OpenTTD Source
1.10.0-RC1
|
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 "../roadveh.h"#include "../order_backup.h"#include "../core/pool_func.hpp"#include "../core/random_func.hpp"#include "../rev.h"#include <mutex>#include <condition_variable>#include "../safeguards.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) | |
| Yes... More... | |
| static void | NetworkHandleCommandQueue (NetworkClientSocket *cs) |
| Handle the command-queue of a socket. More... | |
| void | NetworkServerSendChat (NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin) |
| Send an actual chat message. More... | |
| void | NetworkPopulateCompanyStats (NetworkCompanyStats *stats) |
| Populate the company stats. More... | |
| void | NetworkUpdateClientInfo (ClientID client_id) |
| Send updated client info of a particular client. More... | |
| static void | NetworkCheckRestartMap () |
| Check if we want to restart the map. | |
| static void | NetworkAutoCleanCompanies () |
| Check if the server has autoclean_companies activated Two things happen: 1) If a company is not protected, it is closed after 1 year (for example) 2) If a company is protected, protection is disabled after 3 years (for example) (and item 1. More... | |
| bool | NetworkFindName (char *new_name, const char *last) |
| Check whether a name is unique, and otherwise try to make it unique. More... | |
| bool | NetworkServerChangeClientName (ClientID client_id, const char *new_name) |
| Change the client name of the given client. More... | |
| void | NetworkServerSetCompanyPassword (CompanyID company_id, const char *password, bool already_hashed) |
| Set/Reset a company password on the server end. More... | |
| void | NetworkServer_Tick (bool send_frame) |
| This is called every tick if this is a _network_server. More... | |
| void | NetworkServerYearlyLoop () |
| Yearly "callback". More... | |
| void | NetworkServerMonthlyLoop () |
| Monthly "callback". More... | |
| void | NetworkServerDailyLoop () |
| Daily "callback". More... | |
| void | NetworkServerShowStatusToConsole () |
| Show the status message of all clients on the console. More... | |
| void | NetworkServerSendConfigUpdate () |
| Send Config Update. | |
| void | NetworkServerUpdateCompanyPassworded (CompanyID company_id, bool passworded) |
| Tell that a particular company is (not) passworded. More... | |
| void | NetworkServerDoMove (ClientID client_id, CompanyID company_id) |
| Handle the tid-bits of moving a client from one company to another. More... | |
| void | NetworkServerSendRcon (ClientID client_id, TextColour colour_code, const char *string) |
| Send an rcon reply to the client. More... | |
| void | NetworkServerKickClient (ClientID client_id, const char *reason) |
| Kick a single client. More... | |
| uint | NetworkServerKickOrBanIP (ClientID client_id, bool ban, const char *reason) |
| Ban, or kick, everyone joined from the given client's IP. More... | |
| uint | NetworkServerKickOrBanIP (const char *ip, bool ban, const char *reason) |
| Kick or ban someone based on an IP address. More... | |
| bool | NetworkCompanyHasClients (CompanyID company) |
| Check whether a particular company has clients. More... | |
| void | NetworkPrintClients () |
| Print all the clients to the console. | |
| void | NetworkServerNewCompany (const Company *c, NetworkClientInfo *ci) |
| Perform all the server specific administration of a new company. More... | |
Variables | |
| static ClientID | _network_client_id = CLIENT_ID_FIRST |
| The identifier counter for new clients (is never decreased) | |
| NetworkClientSocketPool | _networkclientsocket_pool ("NetworkClientSocket") |
| The pool with clients. More... | |
Server part of the network protocol.
Definition in file network_server.cpp.
| assert_compile | ( | NetworkClientSocketPool::MAX_SIZE | = =MAX_CLIENT_SLOTS | ) |
Yes...
|
static |
Check if the server has autoclean_companies activated Two things happen: 1) If a company is not protected, it is closed after 1 year (for example) 2) If a company is protected, protection is disabled after 3 years (for example) (and item 1.
happens a year later)
Definition at line 1621 of file network_server.cpp.
References _network_company_states, _network_dedicated, _settings_client, NetworkSettings::autoclean_companies, NetworkSettings::autoclean_novehicles, NetworkSettings::autoclean_protected, NetworkSettings::autoclean_unprotected, CC_DEFAULT, CCA_DELETE, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, CMD_COMPANY_CTRL, CRR_AUTOCLEAN, DoCommandP(), NetworkClientInfo::GetByClientID(), IConsolePrintF(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::Iterate(), MAX_COMPANIES, NetworkCompanyState::months_empty, ClientSettings::network, NetworkServerUpdateCompanyPassworded(), NetworkCompanyState::password, and StrEmpty().
Referenced by NetworkServerMonthlyLoop().
| bool NetworkCompanyHasClients | ( | CompanyID | company | ) |
Check whether a particular company has clients.
| company | The company to check. |
Definition at line 2111 of file network_server.cpp.
| bool NetworkFindName | ( | char * | new_name, |
| const char * | last | ||
| ) |
Check whether a name is unique, and otherwise try to make it unique.
| new_name | The name to check/modify. |
| last | The last writeable element of the buffer. |
Definition at line 1691 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(), lastof, MAX_CLIENTS, NETWORK_CLIENT_NAME_LENGTH, seprintf(), and strecpy().
Referenced by NetworkUpdateClientName().
|
static |
Handle the command-queue of a socket.
| cs | The socket to handle the queue for. |
Definition at line 1772 of file network_server.cpp.
References free().
Referenced by ServerNetworkGameSocketHandler::Send().
| void NetworkPopulateCompanyStats | ( | NetworkCompanyStats * | stats | ) |
Populate the company stats.
| stats | the stats to update |
Definition at line 1541 of file network_server.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), MAX_COMPANIES, and VEH_TRAIN.
Referenced by ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(), ServerNetworkGameSocketHandler::SendCompanyInfo(), and ServerNetworkAdminSocketHandler::SendCompanyStats().
| void NetworkServer_Tick | ( | bool | send_frame | ) |
This is called every tick if this is a _network_server.
| send_frame | Whether to send the frame to the clients. |
Definition at line 1785 of file network_server.cpp.
References _frame_counter, _last_sync_frame, _settings_client, NetworkSettings::bytes_per_frame, NetworkSettings::bytes_per_frame_burst, min(), ClientSettings::network, and NetworkSettings::sync_freq.
Referenced by ServerNetworkGameSocketHandler::GetName().
| bool NetworkServerChangeClientName | ( | ClientID | client_id, |
| const char * | new_name | ||
| ) |
Change the client name of the given client.
| client_id | the client to change the name of |
| new_name | the new name for the client |
Definition at line 1732 of file network_server.cpp.
References NetworkClientInfo::GetByClientID(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::Iterate().
| void NetworkServerDailyLoop | ( | ) |
Daily "callback".
Called whenever the date changes.
Definition at line 1925 of file network_server.cpp.
References _date, ADMIN_FREQUENCY_DAILY, ADMIN_FREQUENCY_WEEKLY, and NetworkAdminUpdate().
Handle the tid-bits of moving a client from one company to another.
| client_id | id of the client we want to move. |
| company_id | id of the company we want to move the client to. |
Definition at line 2006 of file network_server.cpp.
References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, NetworkClientInfo::GetByClientID(), NetworkUpdateClientInfo(), and SetLocalCompany().
| void NetworkServerKickClient | ( | ClientID | client_id, |
| const char * | reason | ||
| ) |
Kick a single client.
| client_id | The client to kick. |
| reason | In case of kicking a client, specifies the reason for kicking the client. |
Definition at line 2050 of file network_server.cpp.
References CLIENT_ID_SERVER.
Referenced by NetworkServerKickOrBanIP().
| uint NetworkServerKickOrBanIP | ( | ClientID | client_id, |
| bool | ban, | ||
| const char * | reason | ||
| ) |
Ban, or kick, everyone joined from the given client's IP.
| client_id | The client to check for. |
| ban | Whether to ban or kick. |
| reason | In case of kicking a client, specifies the reason for kicking the client. |
Definition at line 2062 of file network_server.cpp.
References ServerNetworkGameSocketHandler::GetClientIP().
| uint NetworkServerKickOrBanIP | ( | const char * | ip, |
| bool | ban, | ||
| const char * | reason | ||
| ) |
Kick or ban someone based on an IP address.
| ip | The IP address/range to ban/kick. |
| ban | Whether to ban or just kick. |
| reason | In case of kicking a client, specifies the reason for kicking the client. |
Definition at line 2073 of file network_server.cpp.
References _network_ban_list, _redirect_console_to_client, CLIENT_ID_SERVER, and NetworkServerKickClient().
| void NetworkServerMonthlyLoop | ( | ) |
Monthly "callback".
Called whenever the month changes.
Definition at line 1917 of file network_server.cpp.
References _cur_month, ADMIN_FREQUENCY_MONTHLY, ADMIN_FREQUENCY_QUARTERLY, NetworkAdminUpdate(), and NetworkAutoCleanCompanies().
| void NetworkServerNewCompany | ( | const Company * | c, |
| NetworkClientInfo * | ci | ||
| ) |
Perform all the server specific administration of a new company.
| c | The newly created company; can't be nullptr. |
| ci | The client information of the client that made the company; can be nullptr. |
Definition at line 2162 of file network_server.cpp.
| void NetworkServerSendChat | ( | NetworkAction | action, |
| DestType | desttype, | ||
| int | dest, | ||
| const char * | msg, | ||
| ClientID | from_id, | ||
| int64 | data, | ||
| bool | from_admin | ||
| ) |
Send an actual chat message.
| action | The action that's performed. |
| desttype | The type of destination. |
| dest | The actual destination index. |
| msg | The actual message. |
| from_id | The origin of the message. |
| data | Arbitrary data. |
| from_admin | Whether the origin is an admin or not. |
Definition at line 1246 of file network_server.cpp.
References CLIENT_ID_SERVER, DESTTYPE_CLIENT, and NetworkClientInfo::GetByClientID().
| void NetworkServerSendRcon | ( | ClientID | client_id, |
| TextColour | colour_code, | ||
| const char * | string | ||
| ) |
Send an rcon reply to the client.
| client_id | The identifier of the client. |
| colour_code | The colour of the text. |
| string | The actual reply. |
Definition at line 2040 of file network_server.cpp.
| void NetworkServerSetCompanyPassword | ( | CompanyID | company_id, |
| const char * | password, | ||
| bool | already_hashed | ||
| ) |
Set/Reset a company password on the server end.
| 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 1756 of file network_server.cpp.
References _network_company_states, _settings_client, _settings_game, GameSettings::game_creation, GenerateCompanyPasswordHash(), GameCreationSettings::generation_seed, Company::IsValidHumanID(), lastof, ClientSettings::network, NetworkSettings::network_id, NetworkServerUpdateCompanyPassworded(), strecpy(), and StrEmpty().
Referenced by ServerNetworkGameSocketHandler::GetName(), and NetworkChangeCompanyPassword().
| void NetworkServerShowStatusToConsole | ( | ) |
Show the status message of all clients on the console.
Definition at line 1941 of file network_server.cpp.
References assert_compile(), and lengthof.
| void NetworkServerUpdateCompanyPassworded | ( | CompanyID | company_id, |
| bool | passworded | ||
| ) |
Tell that a particular company is (not) passworded.
| company_id | The company that got/removed the password. |
| passworded | Whether the password was received or removed. |
Definition at line 1986 of file network_server.cpp.
References _network_company_passworded, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), NetworkAdminCompanyUpdate(), NetworkCompanyIsPassworded(), SB(), SetWindowClassesDirty(), and WC_COMPANY.
Referenced by ServerNetworkGameSocketHandler::GetName(), NetworkAutoCleanCompanies(), and NetworkServerSetCompanyPassword().
| void NetworkServerYearlyLoop | ( | ) |
Yearly "callback".
Called whenever the year changes.
Definition at line 1910 of file network_server.cpp.
References ADMIN_FREQUENCY_ANUALLY, NetworkAdminUpdate(), and NetworkCheckRestartMap().
| void NetworkUpdateClientInfo | ( | ClientID | client_id | ) |
Send updated client info of a particular client.
| client_id | The client to send it for. |
Definition at line 1577 of file network_server.cpp.
References _date, _date_fract, NetworkClientInfo::client_playas, DEBUG, NetworkClientInfo::GetByClientID(), and NetworkAdminClientUpdate().
Referenced by NetworkServerDoMove().
| NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket") |
The pool with clients.