OpenTTD Source
1.11.2
|
#include "../stdafx.h"
#include "../strings_func.h"
#include "../command_func.h"
#include "../date_func.h"
#include "network_admin.h"
#include "network_client.h"
#include "network_server.h"
#include "network_content.h"
#include "network_udp.h"
#include "network_gamelist.h"
#include "network_base.h"
#include "core/udp.h"
#include "core/host.h"
#include "network_gui.h"
#include "../console_func.h"
#include "../3rdparty/md5/md5.h"
#include "../core/random_func.hpp"
#include "../window_func.h"
#include "../company_func.h"
#include "../company_base.h"
#include "../landscape_type.h"
#include "../rev.h"
#include "../core/pool_func.hpp"
#include "../gfx_func.h"
#include "../error.h"
#include "../safeguards.h"
Go to the source code of this file.
Data Structures | |
class | TCPQueryConnecter |
Non blocking connection create to query servers. More... | |
class | TCPClientConnecter |
Non blocking connection create to actually connect to servers. More... | |
Functions | |
void | StateGameLoop () |
State controlling game loop. More... | |
bool | HasClients () |
Return whether there is any client connected or trying to connect at all. More... | |
byte | NetworkSpectatorCount () |
const char * | NetworkChangeCompanyPassword (CompanyID company_id, const char *password) |
Change the company password of a given company. More... | |
const char * | GenerateCompanyPasswordHash (const char *password, const char *password_server_id, uint32 password_game_seed) |
Hash the given password using server ID and game seed. More... | |
bool | NetworkCompanyIsPassworded (CompanyID company_id) |
Check if the company we want to join requires a password. More... | |
void | NetworkTextMessage (NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str, int64 data) |
uint | NetworkCalculateLag (const NetworkClientSocket *cs) |
void | ShowNetworkError (StringID error_string) |
StringID | GetNetworkErrorMsg (NetworkErrorCode err) |
Retrieve the string id of an internal error number. More... | |
void | NetworkHandlePauseChange (PauseMode prev_mode, PauseMode changed_mode) |
Handle the pause mode change so we send the right messages to the chat. More... | |
static void | CheckPauseHelper (bool pause, PauseMode pm) |
Helper function for the pause checkers. More... | |
static uint | NetworkCountActiveClients () |
Counts the number of active clients connected. More... | |
static void | CheckMinActiveClients () |
Check if the minimum number of active clients has been reached and pause or unpause the game as appropriate. | |
static bool | NetworkHasJoiningClient () |
Checks whether there is a joining client. More... | |
static void | CheckPauseOnJoin () |
Check whether we should pause on join. | |
void | ParseConnectionString (const char **company, const char **port, char *connection_string) |
Converts a string to ip/port/company Format: IP:port::company. More... | |
static void | InitializeNetworkPools (bool close_admins=true) |
Resets the pools used for network clients, and the admin pool if needed. More... | |
void | NetworkClose (bool close_admins) |
Close current connections. More... | |
static void | NetworkInitialize (bool close_admins=true) |
void | NetworkTCPQueryServer (NetworkAddress address) |
Query a server to fetch his game-info. More... | |
void | NetworkAddServer (const char *b) |
void | GetBindAddresses (NetworkAddressList *addresses, uint16 port) |
Get the addresses to bind to. More... | |
void | NetworkRebuildHostList () |
void | NetworkClientConnectGame (const char *hostname, uint16 port, CompanyID join_as, const char *join_server_password, const char *join_company_password) |
void | NetworkClientJoinGame () |
Actually perform the joining to the server. More... | |
static void | NetworkInitGameInfo () |
bool | NetworkServerStart () |
void | NetworkReboot () |
void | NetworkDisconnect (bool blocking, bool close_admins) |
We want to disconnect from the host/clients. More... | |
static bool | NetworkReceive () |
Receives something from the network. More... | |
static void | NetworkSend () |
void | NetworkBackgroundLoop () |
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer. More... | |
void | NetworkGameLoop () |
static void | NetworkGenerateServerId () |
void | NetworkStartDebugLog (const char *hostname, uint16 port) |
void | NetworkStartUp () |
This tries to launch the network for a given OS. | |
void | NetworkShutDown () |
This shuts the network down. | |
Variables | |
NetworkClientInfoPool | _networkclientinfo_pool ("NetworkClientInfo") |
Make sure both pools have the same size. More... | |
bool | _networking |
are we in networking mode? | |
bool | _network_server |
network-server is active | |
bool | _network_available |
is network mode available? | |
bool | _network_dedicated |
are we a dedicated server? | |
bool | _is_network_server |
Does this client wants to be a network-server? | |
NetworkCompanyState * | _network_company_states = nullptr |
Statistics about some companies. More... | |
ClientID | _network_own_client_id |
Our client identifier. | |
ClientID | _redirect_console_to_client |
If not invalid, redirect the console output to a client. | |
bool | _network_need_advertise |
Whether we need to advertise. | |
uint8 | _network_reconnect |
Reconnect timeout. | |
StringList | _network_bind_list |
The addresses to bind on. | |
StringList | _network_host_list |
The servers we know. | |
StringList | _network_ban_list |
The banned clients. | |
uint32 | _frame_counter_server |
The frame_counter of the server, if in network-mode. | |
uint32 | _frame_counter_max |
To where we may go with our clients. | |
uint32 | _frame_counter |
The current frame. | |
uint32 | _last_sync_frame |
Used in the server to store the last time a sync packet was sent to clients. | |
NetworkAddressList | _broadcast_list |
List of broadcast addresses. | |
uint32 | _sync_seed_1 |
Seed to compare during sync checks. | |
uint32 | _sync_frame |
The frame to perform the sync check. | |
bool | _network_first_time |
Whether we have finished joining or not. | |
CompanyMask | _network_company_passworded |
Bitmask of the password status of all companies. | |
byte | _network_clients_connected = 0 |
The amount of clients connected. | |
Base functions for networking support.
Definition in file network.cpp.
|
static |
Helper function for the pause checkers.
If pause is true and the current pause mode isn't set the game will be paused, if it it false and the pause mode is set the game will be unpaused. In the other cases nothing happens to the pause state.
pause | whether we'd like to pause |
pm | the mode which we would like to pause with |
Definition at line 388 of file network.cpp.
References _pause_mode, CMD_PAUSE, DoCommandP(), and PM_UNPAUSED.
Referenced by CheckMinActiveClients(), and CheckPauseOnJoin().
const char* GenerateCompanyPasswordHash | ( | const char * | password, |
const char * | password_server_id, | ||
uint32 | password_game_seed | ||
) |
Hash the given password using server ID and game seed.
password | Password to hash. |
password_server_id | Server ID. |
password_game_seed | Game seed. |
Definition at line 174 of file network.cpp.
References lastof, NETWORK_SERVER_ID_LENGTH, seprintf(), and StrEmpty().
Referenced by NetworkServerSetCompanyPassword(), ClientNetworkGameSocketHandler::SendCompanyPassword(), ClientNetworkGameSocketHandler::SendMove(), and ClientNetworkGameSocketHandler::SendSetPassword().
void GetBindAddresses | ( | NetworkAddressList * | addresses, |
uint16 | port | ||
) |
Get the addresses to bind to.
addresses | the list to write to. |
port | the port to bind to. |
Definition at line 619 of file network.cpp.
References _network_bind_list.
Referenced by TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::Listen(), and NetworkUDPInitialize().
StringID GetNetworkErrorMsg | ( | NetworkErrorCode | err | ) |
Retrieve the string id of an internal error number.
err | NetworkErrorCode |
Definition at line 294 of file network.cpp.
References lengthof.
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), ServerNetworkAdminSocketHandler::SendError(), and ServerNetworkGameSocketHandler::SendError().
bool HasClients | ( | ) |
Return whether there is any client connected or trying to connect at all.
Definition at line 92 of file network.cpp.
|
static |
Resets the pools used for network clients, and the admin pool if needed.
close_admins | Whether the admin pool has to be cleared as well. |
Definition at line 506 of file network.cpp.
References PoolBase::Clean(), PT_NADMIN, PT_NCLIENT, and PT_NONE.
Referenced by NetworkClose().
void NetworkBackgroundLoop | ( | ) |
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
For example stuff needed for finding servers or downloading content.
Definition at line 856 of file network.cpp.
References _network_content_client, TCPConnecter::CheckCallbacks(), NetworkHTTPSocketHandler::HTTPReceive(), NetworkBackgroundUDPLoop(), and ClientNetworkContentSocketHandler::SendReceive().
const char* NetworkChangeCompanyPassword | ( | CompanyID | company_id, |
const char * | password | ||
) |
Change the company password of a given company.
company_id | ID of the company the password should be changed for. |
password | The unhashed password we like to set ('*' or '' resets the password) |
Definition at line 154 of file network.cpp.
References _network_server, NetworkClientSetCompanyPassword(), and NetworkServerSetCompanyPassword().
void NetworkClientJoinGame | ( | ) |
Actually perform the joining to the server.
Use #NetworkClientConnectGame when you want to connect to a specific server/company. This function assumes _network_join is already fully set up.
Definition at line 694 of file network.cpp.
References NetworkDisconnect().
void NetworkClose | ( | bool | close_admins | ) |
Close current connections.
close_admins | Whether the admin connections have to be closed as well. |
Definition at line 515 of file network.cpp.
References _network_company_states, _network_server, _networking, ClientNetworkGameSocketHandler::CloseConnection(), TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::CloseListeners(), TCPListenHandler< ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED >::CloseListeners(), free(), InitializeNetworkPools(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkadminsocket_pool >::Iterate(), TCPConnecter::KillAll(), ClientNetworkGameSocketHandler::my_client, NETWORK_RECV_STATUS_CONN_LOST, NetworkFreeLocalCommandQueue(), and ClientNetworkGameSocketHandler::SendQuit().
Referenced by NetworkDisconnect().
bool NetworkCompanyIsPassworded | ( | CompanyID | company_id | ) |
Check if the company we want to join requires a password.
company_id | id of the company we want to check the 'passworded' flag for. |
Definition at line 208 of file network.cpp.
References _network_company_passworded, and HasBit().
Referenced by NetworkServerUpdateCompanyPassworded().
|
static |
Counts the number of active clients connected.
It has to be in STATUS_ACTIVE and not a spectator
Definition at line 400 of file network.cpp.
Referenced by CheckMinActiveClients().
void NetworkDisconnect | ( | bool | blocking, |
bool | close_admins | ||
) |
We want to disconnect from the host/clients.
blocking | whether to wait till everything has been closed. |
close_admins | Whether the admin sockets need to be closed as well. |
Definition at line 800 of file network.cpp.
References _network_server, _settings_client, DeleteWindowById(), ServerNetworkAdminSocketHandler::IterateActive(), ClientSettings::network, NetworkClose(), NetworkUDPInitialize(), NetworkUDPRemoveAdvertise(), NetworkSettings::server_advertise, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
Referenced by NetworkClientJoinGame(), NetworkShutDown(), NetworkTCPQueryServer(), NetworkJoinStatusWindow::OnClick(), TCPQueryConnecter::OnFailure(), and NetworkJoinStatusWindow::OnQueryTextFinished().
Handle the pause mode change so we send the right messages to the chat.
prev_mode | The previous pause mode. |
changed_mode | The pause mode that got changed. |
Definition at line 332 of file network.cpp.
References _networking, _pause_mode, PM_PAUSED_ACTIVE_CLIENTS, PM_PAUSED_GAME_SCRIPT, PM_PAUSED_JOIN, PM_PAUSED_LINK_GRAPH, PM_PAUSED_NORMAL, PM_UNPAUSED, and SetDParam().
|
static |
Checks whether there is a joining client.
Definition at line 430 of file network.cpp.
Referenced by CheckPauseOnJoin().
|
static |
Receives something from the network.
Definition at line 830 of file network.cpp.
References _network_server, TCPListenHandler< ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED >::Receive(), TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::Receive(), and ClientNetworkGameSocketHandler::Receive().
void NetworkTCPQueryServer | ( | NetworkAddress | address | ) |
Query a server to fetch his game-info.
address | the address to query. |
Definition at line 581 of file network.cpp.
References _network_available, and NetworkDisconnect().
Referenced by ShowNetworkLobbyWindow().
void ParseConnectionString | ( | const char ** | company, |
const char ** | port, | ||
char * | connection_string | ||
) |
Converts a string to ip/port/company Format: IP:port::company.
connection_string will be re-terminated to separate out the hostname, and company and port will be set to the company and port strings given by the user, inside the memory area originally occupied by connection_string.
Definition at line 459 of file network.cpp.
Referenced by NetworkHTTPSocketHandler::Connect().
void StateGameLoop | ( | ) |
State controlling game loop.
The state must not be changed from anywhere but here. That check is enforced in DoCommand.
Definition at line 1350 of file openttd.cpp.
References _network_server, _networking, _pause_mode, Game::GameLoop(), HasModalProgress(), PerformanceMeasurer::Paused(), PFE_GAMELOOP, PFE_GL_AIRCRAFT, PFE_GL_ECONOMY, PFE_GL_LANDSCAPE, PFE_GL_ROADVEHS, PFE_GL_SHIPS, PFE_GL_TRAINS, PM_UNPAUSED, Layouter::ReduceLineCache(), PerformanceAccumulator::Reset(), StateGameLoop_LinkGraphPauseControl(), and UpdateLandscapingLimits().
Referenced by ClientNetworkGameSocketHandler::GameLoop().
NetworkCompanyState* _network_company_states = nullptr |
Statistics about some companies.
Uncomment the following define to enable command replaying.
Definition at line 57 of file network.cpp.
Referenced by NetworkAutoCleanCompanies(), NetworkClose(), NetworkServerNewCompany(), and NetworkServerSetCompanyPassword().
NetworkClientInfoPool _networkclientinfo_pool("NetworkClientInfo") |
Make sure both pools have the same size.
The pool with client information.