OpenTTD Source
12.0-beta2
|
#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 "core/game_info.h"
#include "network.h"
#include "network_base.h"
#include "network_client.h"
#include "network_gamelist.h"
#include "../core/backup_type.hpp"
#include "../thread.h"
#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. | |
bool | SafeLoad (const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=nullptr) |
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 std::string &password, const std::string &command) |
Send a remote console command. More... | |
void | NetworkClientRequestMove (CompanyID company_id, const std::string &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... | |
bool | NetworkIsValidClientName (const std::string_view client_name) |
Check whether the given client name is deemed valid for use in network games. More... | |
bool | NetworkValidateClientName (std::string &client_name) |
Trim the given client name in place, i.e. More... | |
bool | NetworkValidateOurClientName () |
Convenience method for NetworkValidateClientName on _settings_client.network.client_name. More... | |
void | NetworkUpdateClientName (const std::string &client_name) |
Send the server our name as callback from the setting. More... | |
void | NetworkClientSendChat (NetworkAction action, DestType type, int dest, const std::string &msg, int64 data) |
Send a chat message. More... | |
void | NetworkClientSetCompanyPassword (const std::string &password) |
Set/Reset company password on the client side. More... | |
bool | NetworkClientPreferTeamChat (const NetworkClientInfo *cio) |
Tell whether the client has team members who they can chat to. More... | |
bool | NetworkMaxCompaniesReached () |
Check if max_companies has been reached on the server (local check only). More... | |
Variables | |
static uint32 | last_ack_frame |
Last frame we performed an ack. | |
static uint32 | _password_game_seed |
One bit of 'entropy' used to generate a salt for the company passwords. | |
static std::string | _password_server_id |
The other bit of 'entropy' used to generate a salt for the company passwords. | |
static uint8 | _network_server_max_companies |
Maximum number of companies of the currently joined server. | |
std::string | _network_server_name |
The current name of the server you are on. | |
NetworkJoinInfo | _network_join |
Information about the game to join to. | |
Client part of the network protocol.
Definition in file network_client.cpp.
bool NetworkClientPreferTeamChat | ( | const NetworkClientInfo * | cio | ) |
Tell whether the client has team members who they can chat to.
cio | client to check members of. |
Definition at line 1334 of file network_client.cpp.
References _settings_client, NetworkClientInfo::client_playas, ClientSettings::gui, 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<&_networkclientinfo_pool >::Iterate(), and GUISettings::prefer_teamchat.
void NetworkClientRequestMove | ( | CompanyID | company_id, |
const std::string & | pass | ||
) |
Notify the server of this client wanting to be moved to another company.
company_id | id of the company the client wishes to be moved to. |
pass | the password, is only checked on the server end if a password is needed. |
Definition at line 1208 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendMove().
Referenced by NetworkClientListWindow::OnClickCompanyJoin().
void NetworkClientSendChat | ( | NetworkAction | action, |
DestType | type, | ||
int | dest, | ||
const std::string & | msg, | ||
int64 | data | ||
) |
Send a chat message.
action | The action associated with the message. |
type | The destination type. |
dest | The destination index, be it a company index or client id. |
msg | The actual message. |
data | Arbitrary extra data. |
Definition at line 1315 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendChat().
void NetworkClientSendRcon | ( | const std::string & | password, |
const std::string & | command | ||
) |
Send a remote console command.
password | The password. |
command | The command to execute. |
Definition at line 1197 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendRCon().
void NetworkClientSetCompanyPassword | ( | const std::string & | password | ) |
Set/Reset company password on the client side.
password | Password to be set. |
Definition at line 1324 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendSetPassword().
Referenced by NetworkChangeCompanyPassword().
void NetworkClientsToSpectators | ( | CompanyID | cid | ) |
Move the clients of a company to the spectators.
cid | The company to move the clients of. |
Definition at line 1217 of file network_client.cpp.
References _current_company.
bool NetworkIsValidClientName | ( | const std::string_view | client_name | ) |
Check whether the given client name is deemed valid for use in network games.
An empty name (null or '') is not valid as that is essentially no name at all. A name starting with white space is not valid for tab completion purposes.
client_name | The client name to check for validity. |
Definition at line 1239 of file network_client.cpp.
Referenced by NetworkValidateClientName().
bool NetworkMaxCompaniesReached | ( | ) |
Check if max_companies has been reached on the server (local check only).
Definition at line 1350 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 NetworkClientListWindow::DrawWidget(), and NetworkClientListWindow::RebuildList().
void NetworkUpdateClientName | ( | const std::string & | client_name | ) |
Send the server our name as callback from the setting.
newname | The new client name. |
Definition at line 1286 of file network_client.cpp.
References _network_own_client_id, _network_server, NetworkClientInfo::client_name, NetworkClientInfo::GetByClientID(), NetworkMakeClientNameUnique(), and ClientNetworkGameSocketHandler::SendSetName().
bool NetworkValidateClientName | ( | std::string & | client_name | ) |
Trim the given client name in place, i.e.
remove leading and trailing spaces. After the trim check whether the client name is valid. A client name is valid whenever the name is not empty and does not start with spaces. This check is done via NetworkIsValidClientName
. When the client name is valid, this function returns true. When the client name is not valid a GUI error message is shown telling the user to set the client name and this function returns false.
This function is not suitable for ensuring a valid client name at the server as the error message will then be shown to the host instead of the client.
client_name | The client name to validate. It will be trimmed of leading and trailing spaces. |
Definition at line 1261 of file network_client.cpp.
References INVALID_STRING_ID, NetworkIsValidClientName(), ShowErrorMessage(), StrTrimInPlace(), and WL_ERROR.
Referenced by NetworkValidateOurClientName().
bool NetworkValidateOurClientName | ( | ) |
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
It trims the client name and checks whether it is empty. When it is empty an error message is shown to the GUI user. See NetworkValidateClientName(char*)
for details about the functionality.
Definition at line 1277 of file network_client.cpp.
References _settings_client, NetworkSettings::client_name, ClientSettings::network, and NetworkValidateClientName().
Referenced by NetworkClientConnectGame().
bool SafeLoad | ( | const std::string & | filename, |
SaveLoadOperation | fop, | ||
DetailedFileType | dft, | ||
GameMode | newgm, | ||
Subdirectory | subdir, | ||
struct LoadFilter * | lf = nullptr |
||
) |
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.
filename | file to be loaded |
fop | mode of loading, always SLO_LOAD |
newgm | switch to this mode of loading fails due to some unknown error |
subdir | default directory to look for filename, set to 0 if not needed |
lf | Load filter to use, if nullptr: use filename + subdir. |
Definition at line 933 of file openttd.cpp.