Base functions for networking support. More...
#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 "table/strings.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 | |
assert_compile (NetworkClientInfoPool::MAX_SIZE==NetworkClientSocketPool::MAX_SIZE) | |
assert_compile ((int) NETWORK_NUM_LANDSCAPES==(int) NUM_LANDSCAPE) | |
void | StateGameLoop () |
State controlling game loop. | |
NetworkClientInfo * | NetworkFindClientInfoFromClientID (ClientID client_id) |
Return the CI given it's client-identifier. | |
NetworkClientSocket * | NetworkFindClientStateFromClientID (ClientID client_id) |
Return the client state given it's client-identifier. | |
byte | NetworkSpectatorCount () |
bool | NetworkCompanyIsPassworded (CompanyID company_id) |
Check if the company we want to join requires a password. | |
void | NetworkTextMessage (NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str, int64 data) |
uint | NetworkCalculateLag (const NetworkClientSocket *cs) |
void | NetworkError (StringID error_string) |
StringID | GetNetworkErrorMsg (NetworkErrorCode err) |
Retrieve the string id of an internal error number. | |
void | NetworkHandlePauseChange (PauseMode prev_mode, PauseMode changed_mode) |
Handle the pause mode change so we send the right messages to the chat. | |
static void | CheckPauseHelper (bool pause, PauseMode pm) |
Helper function for the pause checkers. | |
static uint | NetworkCountActiveClients () |
Counts the number of active clients connected. | |
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. | |
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. | |
static void | InitializeNetworkPools (bool close_admins=true) |
Resets the pools used for network clients, and the admin pool if needed. | |
void | NetworkClose (bool close_admins) |
Close current connections. | |
static void | NetworkInitialize (bool close_admins=true) |
void | NetworkTCPQueryServer (NetworkAddress address) |
void | NetworkAddServer (const char *b) |
void | GetBindAddresses (NetworkAddressList *addresses, uint16 port) |
Get the addresses to bind to. | |
void | NetworkRebuildHostList () |
void | NetworkClientConnectGame (NetworkAddress address, CompanyID join_as, const char *join_server_password, const char *join_company_password) |
static void | NetworkInitGameInfo () |
bool | NetworkServerStart () |
void | NetworkReboot () |
void | NetworkDisconnect (bool blocking, bool close_admins) |
We want to disconnect from the host/clients. | |
static bool | NetworkReceive () |
Receives something from the network. | |
static void | NetworkSend () |
void | NetworkUDPGameLoop () |
void | NetworkGameLoop () |
static void | NetworkGenerateServerId () |
void | NetworkStartDebugLog (NetworkAddress address) |
void | NetworkStartUp () |
This tries to launch the network for a given OS. | |
void | NetworkShutDown () |
This shuts the network down. | |
bool | IsNetworkCompatibleVersion (const char *other) |
Checks whether the given version string is compatible with our version. | |
Variables | |
NetworkClientInfoPool | _networkclientinfo_pool ("NetworkClientInfo") |
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? | |
NetworkServerGameInfo | _network_game_info |
NetworkCompanyState * | _network_company_states = NULL |
ClientID | _network_own_client_id |
ClientID | _redirect_console_to_client |
bool | _network_need_advertise |
uint32 | _network_last_advertise_frame |
uint8 | _network_reconnect |
StringList | _network_bind_list |
StringList | _network_host_list |
StringList | _network_ban_list |
uint32 | _frame_counter_server |
uint32 | _frame_counter_max |
uint32 | _frame_counter |
uint32 | _last_sync_frame |
NetworkAddressList | _broadcast_list |
uint32 | _sync_seed_1 |
uint32 | _sync_frame |
bool | _network_first_time |
bool | _network_udp_server |
uint16 | _network_udp_broadcast |
uint8 | _network_advertise_retries |
CompanyMask | _network_company_passworded |
Bitmask of the password status of all companies. | |
NetworkUDPSocketHandler * | _udp_client_socket |
udp client socket | |
NetworkUDPSocketHandler * | _udp_server_socket |
udp server socket | |
NetworkUDPSocketHandler * | _udp_master_socket |
udp master socket | |
byte | _network_clients_connected = 0 |
Base functions for networking support.
Definition in file network.cpp.
static void CheckPauseHelper | ( | bool | pause, | |
PauseMode | pm | |||
) | [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 326 of file network.cpp.
References _pause_mode, CMD_PAUSE, DoCommandP(), and PM_UNPAUSED.
Referenced by CheckMinActiveClients(), and CheckPauseOnJoin().
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 557 of file network.cpp.
References SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), and SmallVector< T, S >::Length().
Referenced by TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::Listen().
StringID GetNetworkErrorMsg | ( | NetworkErrorCode | err | ) |
Retrieve the string id of an internal error number.
err | NetworkErrorCode |
Definition at line 244 of file network.cpp.
References lengthof.
static void InitializeNetworkPools | ( | bool | close_admins = true |
) | [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 441 of file network.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::CleanPool().
Referenced by NetworkClose().
bool IsNetworkCompatibleVersion | ( | const char * | other | ) |
Checks whether the given version string is compatible with our version.
other | the version string to compare to |
Definition at line 1022 of file network.cpp.
References NETWORK_REVISION_LENGTH.
void NetworkClose | ( | bool | close_admins | ) |
Close current connections.
close_admins | Whether the admin connections have to be closed as well. |
Definition at line 452 of file network.cpp.
References NetworkAdminSocketHandler::CloseConnection(), TCPListenHandler< ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED >::CloseListeners(), TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::CloseListeners(), InitializeNetworkPools(), TCPConnecter::KillAll(), ClientNetworkGameSocketHandler::my_client, NETWORK_RECV_STATUS_CONN_LOST, and NetworkFreeLocalCommandQueue().
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 158 of file network.cpp.
References HasBit().
Referenced by CompanyWindow::DrawWidget(), and CompanyWindow::OnClick().
static uint NetworkCountActiveClients | ( | ) | [static] |
Counts the number of active clients connected.
It has to be in STATUS_ACTIVE and not a spectator
Definition at line 338 of file network.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().
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 719 of file network.cpp.
References _settings_client, DeleteWindowById(), ClientSettings::network, NetworkClose(), NetworkUDPRemoveAdvertise(), NetworkTCPSocketHandler::SendPackets(), and NetworkSettings::server_advertise.
Referenced by NetworkShutDown(), NetworkJoinStatusWindow::OnClick(), TCPQueryConnecter::OnFailure(), NetworkJoinStatusWindow::OnQueryTextFinished(), and SafeLoad().
NetworkClientInfo* NetworkFindClientInfoFromClientID | ( | ClientID | client_id | ) |
Return the CI given it's client-identifier.
client_id | the ClientID to search for |
Definition at line 111 of file network.cpp.
References NetworkClientInfo::client_id.
Referenced by CmdCompanyCtrl(), NetworkChatWindow::DrawWidget(), NetworkServerChangeClientName(), NetworkServerDoMove(), MainWindow::OnKeyPress(), and NetworkChatWindow::UpdateWidgetSize().
NetworkClientSocket* NetworkFindClientStateFromClientID | ( | ClientID | client_id | ) |
Return the client state given it's client-identifier.
client_id | the ClientID to search for |
Definition at line 127 of file network.cpp.
Referenced by NetworkServerDoMove().
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 277 of file network.cpp.
References _pause_mode, CC_DEFAULT, DRAW_STRING_BUFFER, lastof, PM_PAUSED_ACTIVE_CLIENTS, PM_PAUSED_JOIN, PM_PAUSED_NORMAL, PM_UNPAUSED, and SetDParam().
Referenced by CmdPause().
static bool NetworkHasJoiningClient | ( | ) | [static] |
Checks whether there is a joining client.
Definition at line 369 of file network.cpp.
Referenced by CheckPauseOnJoin().
static bool NetworkReceive | ( | ) | [static] |
Receives something from the network.
Definition at line 751 of file network.cpp.
References ClientNetworkGameSocketHandler::Receive(), TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::Receive(), and TCPListenHandler< ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED >::Receive().
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 seperate 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 399 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 1235 of file openttd.cpp.
References _current_company, _date, _pause_mode, _settings_game, AnimateAnimatedTiles(), AUTOSAVE_DIR, CallWindowTickEvent(), CheckCaches(), ClearStorageChanges(), GameSettings::game_creation, AI::GameLoop(), GameCreationSettings::generation_seed, IncreaseDate(), IsGeneratingWorld(), IsLocalCompany(), lengthof, OWNER_NONE, PM_UNPAUSED, Backup< T >::Restore(), SaveOrLoad(), SL_SAVE, and UpdateLandscapingLimits().
Referenced by ClientNetworkGameSocketHandler::GameLoop().