|
OpenTTD Source 20260421-master-gc2fbc6fdeb
|
Variables and function used internally. More...
#include "network_func.h"#include "core/tcp_coordinator.h"#include "core/tcp_game.h"#include "../command_type.h"#include "../command_func.h"#include "../misc/endian_buffer.hpp"#include "../strings_type.h"Go to the source code of this file.
Data Structures | |
| struct | CommandPacket |
| Everything we need to know about a command to be able to execute it. More... | |
Typedefs | |
| using | NetworkClientSocket = class ServerNetworkGameSocketHandler |
| Class for handling the server side of the game connection. | |
Enumerations | |
| enum class | NetworkJoinStatus : uint8_t { Connecting , Authorizing , Waiting , Downloading , Processing , Registering , End } |
| Status of the clients during joining. More... | |
Functions | |
| void | NetworkQueryServer (std::string_view connection_string) |
| Query a server to fetch the game-info. | |
| void | GetBindAddresses (NetworkAddressList *addresses, uint16_t port) |
| Get the addresses to bind to. | |
| struct NetworkGame * | NetworkAddServer (std::string_view connection_string, bool manually=true, bool never_expire=false) |
| Validates an address entered as a string and adds the server to the list. | |
| void | NetworkRebuildHostList () |
| Generates the list of manually added hosts from NetworkGame and dumps them into the array _network_host_list. | |
| void | UpdateNetworkGameWindow () |
| Update the network new window because a new server is found on the network. | |
| void | NetworkDistributeCommands () |
| Distribute the commands of ourself and the clients. | |
| void | NetworkExecuteLocalCommandQueue () |
| Execute all commands on the local command queue that ought to be executed this frame. | |
| void | NetworkFreeLocalCommandQueue () |
| Free the local command queues. | |
| void | NetworkSyncCommandQueue (NetworkClientSocket *cs) |
| Sync our local command queue to the command queue of the given socket. | |
| void | NetworkReplaceCommandClientId (CommandPacket &cp, ClientID client_id) |
| Insert a client ID into the command data in a command packet. | |
| void | ShowNetworkError (StringID error_string) |
| There was a non-recoverable error, drop back to the main menu with a nice error. | |
| void | NetworkTextMessage (NetworkAction action, TextColour colour, bool self_send, std::string_view name, std::string_view str={}, StringParameter &&data={}) |
| Writes a text-message to the console and the chat box. | |
| uint | NetworkCalculateLag (const NetworkClientSocket *cs) |
| Calculate the frame-lag of a client. | |
| StringID | GetNetworkErrorMsg (NetworkErrorCode err) |
| Retrieve a short translateable string of the error code. | |
| bool | NetworkMakeClientNameUnique (std::string &new_name) |
| Check whether a name is unique, and otherwise try to make it unique. | |
| std::string_view | ParseCompanyFromConnectionString (std::string_view connection_string, CompanyID *company_id) |
| Parse the company part ("#company" postfix) of a connecting string. | |
| NetworkAddress | ParseConnectionString (std::string_view connection_string, uint16_t default_port) |
| Convert a string containing either "hostname" or "hostname:ip" to a NetworkAddress. | |
| std::string | NormalizeConnectionString (std::string_view connection_string, uint16_t default_port) |
| Normalize a connection string. | |
| void | ClientNetworkEmergencySave () |
| Create an emergency savegame when the network connection is lost. | |
Variables | |
| uint32_t | _frame_counter_server |
| The frame_counter of the server, if in network-mode. | |
| uint32_t | _frame_counter_max |
| To where we may go with our clients. | |
| uint32_t | _frame_counter |
| The current frame. | |
| uint32_t | _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_t | _sync_seed_1 |
| Seed to compare during sync checks. | |
| uint32_t | _sync_frame |
| The frame to perform the sync check. | |
| bool | _network_first_time |
| Whether we have finished joining or not. | |
| NetworkJoinStatus | _network_join_status |
| The status of joining. | |
| uint8_t | _network_join_waiting |
| The number of clients waiting in front of us. | |
| uint32_t | _network_join_bytes |
| The number of bytes we already downloaded. | |
| uint32_t | _network_join_bytes_total |
| The total number of bytes to download. | |
| ConnectionType | _network_server_connection_type |
| What type of connection the Game Coordinator detected we are on. | |
| std::string | _network_server_invite_code |
| Our invite code as indicated by the Game Coordinator. | |
| std::string | _network_server_name |
| The current name of the server you are on. | |
| uint8_t | _network_reconnect |
| Reconnect timeout. | |
Variables and function used internally.
Definition in file network_internal.h.
| using NetworkClientSocket = class ServerNetworkGameSocketHandler |
Class for handling the server side of the game connection.
Definition at line 41 of file network_internal.h.
|
strong |
Status of the clients during joining.
Definition at line 44 of file network_internal.h.
| void ClientNetworkEmergencySave | ( | ) |
Create an emergency savegame when the network connection is lost.
Definition at line 91 of file network_client.cpp.
References DoAutoOrNetsave().
Referenced by ClientNetworkGameSocketHandler::ClientError(), NetworkGameSocketHandler::CloseConnection(), ClientNetworkGameSocketHandler::ReceiveServerError(), ClientNetworkGameSocketHandler::ReceiveServerNewGame(), and ClientNetworkGameSocketHandler::ReceiveServerShutdown().
| void GetBindAddresses | ( | NetworkAddressList * | addresses, |
| uint16_t | port ) |
Get the addresses to bind to.
| addresses | the list to write to. |
| port | the port to bind to. |
Definition at line 737 of file network.cpp.
References _network_bind_list.
Referenced by TCPListenHandler< Tsocket, EnumPacketType, Tfull_packet, Tban_packet >::Listen(), and NetworkUDPInitialize().
| StringID GetNetworkErrorMsg | ( | NetworkErrorCode | err | ) |
Retrieve a short translateable string of the error code.
An unknown error code will get STR_NETWORK_ERROR_CLIENT_GENERAL.
| err | The error code. |
StringID. Definition at line 328 of file network.cpp.
References Cheater, CompanyMismatch, ConnectionLost, Desync, General, IllegalPacket, InvalidClientName, Kicked, NameInUse, NewGRFMismatch, NoAuthenticationMethodAvailable, NotAuthorized, NotExpected, NotOnAllowList, SavegameFailed, ServerFull, TimeoutComputer, TimeoutJoin, TimeoutMap, TimeoutPassword, TooManyCommands, WrongPassword, and WrongRevision.
Referenced by ServerNetworkGameSocketHandler::ReceiveClientError(), ClientNetworkGameSocketHandler::ReceiveServerErrorQuit(), ServerNetworkAdminSocketHandler::SendError(), and ServerNetworkGameSocketHandler::SendError().
| struct NetworkGame * NetworkAddServer | ( | std::string_view | connection_string, |
| bool | manually, | ||
| bool | never_expire ) |
Validates an address entered as a string and adds the server to the list.
If you use this function, the games will be marked as manually added.
| connection_string | The IP:port of the server to add. |
| manually | Whether the enter should be marked as manual added. |
| never_expire | Whether the entry can expire (removed when no longer found in the public listing). |
Definition at line 711 of file network.cpp.
References ClearGRFConfigList(), NetworkServerGameInfo::grfconfig, NetworkGame::info, NetworkGame::manually, NetworkGameListAddItem(), NetworkQueryServer(), NetworkServerGameInfo::server_name, UpdateNetworkGameWindow(), and NetworkGame::version.
Referenced by NetworkGameWindow::NetworkGameWindow(), NetworkGameWindow::OnQueryTextFinished(), ClientNetworkUDPSocketHandler::ReceiveServerResponse(), and ShowNetworkGameWindow().
| uint NetworkCalculateLag | ( | const NetworkClientSocket * | cs | ) |
Calculate the frame-lag of a client.
| cs | The client's socket. |
Definition at line 299 of file network.cpp.
References _frame_counter, _settings_client, and Ticks::DAY_TICKS.
Referenced by NetworkServer_Tick(), and NetworkServerShowStatusToConsole().
| void NetworkDistributeCommands | ( | ) |
Distribute the commands of ourself and the clients.
Definition at line 357 of file network_command.cpp.
References _local_wait_queue, and DistributeQueue().
Referenced by NetworkGameLoop().
| void NetworkExecuteLocalCommandQueue | ( | ) |
Execute all commands on the local command queue that ought to be executed this frame.
Definition at line 40 of file network_command.cpp.
Referenced by NetworkGameLoop().
| void NetworkFreeLocalCommandQueue | ( | ) |
Free the local command queues.
Definition at line 290 of file network_command.cpp.
References _local_execution_queue, and _local_wait_queue.
Referenced by ClientNetworkGameSocketHandler::NetworkClose.
| bool NetworkMakeClientNameUnique | ( | std::string & | name | ) |
Check whether a name is unique, and otherwise try to make it unique.
| name | The name to check/modify. |
Definition at line 1669 of file network_server.cpp.
References CLIENT_ID_SERVER, NetworkClientInfo::client_name, NetworkClientInfo::GetByClientID(), MAX_CLIENTS, and NETWORK_CLIENT_NAME_LENGTH.
Referenced by NetworkUpdateClientName(), ServerNetworkGameSocketHandler::ReceiveClientIdentify(), and ServerNetworkGameSocketHandler::ReceiveClientSetName().
| void NetworkQueryServer | ( | std::string_view | connection_string | ) |
Query a server to fetch the game-info.
| connection_string | the address to query. |
Definition at line 689 of file network.cpp.
References _network_available, TCPConnecter::Create(), Debug, NetworkGameListAddItem(), and NetworkGame::refreshing.
Referenced by NetworkAddServer(), and NetworkGameWindow::OnClick().
| void NetworkRebuildHostList | ( | ) |
Generates the list of manually added hosts from NetworkGame and dumps them into the array _network_host_list.
This array is needed by the function that generates the config file.
Definition at line 753 of file network.cpp.
References _network_game_list, and _network_host_list.
Referenced by NetworkGameListRemoveItem(), and NetworkGameWindow::OnQueryTextFinished().
| void NetworkReplaceCommandClientId | ( | CommandPacket & | cp, |
| ClientID | client_id ) |
Insert a client ID into the command data in a command packet.
| cp | Command packet to modify. |
| client_id | Client id to insert. |
Definition at line 452 of file network_command.cpp.
References _cmd_dispatch, and CommandPacket::cmd.
| void NetworkSyncCommandQueue | ( | NetworkClientSocket * | cs | ) |
Sync our local command queue to the command queue of the given socket.
This is needed for the case where we receive a command before saving the game for a joining client, but without the execution of those commands. Not syncing those commands means that the client will never get them and as such will be in a desynced state from the time it started with joining.
| cs | The client to sync the queue to. |
Definition at line 245 of file network_command.cpp.
References _local_execution_queue, and CommandPacket::callback.
Referenced by ServerNetworkGameSocketHandler::SendMap().
| void NetworkTextMessage | ( | NetworkAction | action, |
| TextColour | colour, | ||
| bool | self_send, | ||
| std::string_view | name, | ||
| std::string_view | str, | ||
| StringParameter && | data ) |
Writes a text-message to the console and the chat box.
| action | The network action that lead to this message. |
| colour | The color for the message. |
| self_send | Whether the message came from ourselves, or the network. |
| name | The name of the client. |
| str | Arbitrary extra string, depending on the action. For example a complete message or company name. |
| data | Arbitrary extra data, depending on the action. For example a client's ID or an amount of money that was given. |
Definition at line 244 of file network.cpp.
References _current_text_dir, _network_server, _settings_client, CC_DEFAULT, CHAR_TD_LRM, CHAR_TD_RLM, ChatClient, ChatExternal, ChatTeam, ClientJoin, ClientKicked, ClientLeave, ClientNameChange, CompanyJoin, CompanyNew, CompanySpectator, TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, GetString(), GiveMoney, IConsolePrint(), NetworkAddChatMessage(), BaseStringBuilder::PutUtf8(), ServerMessage, and TD_LTR.
Referenced by ServerNetworkGameSocketHandler::CloseConnection(), CmdGiveMoney(), NetworkClientsToSpectators(), NetworkHandlePauseChange(), NetworkServerChangeClientName(), NetworkServerSendChat(), NetworkServerSendExternalChat(), NetworkUpdateClientName(), ServerNetworkGameSocketHandler::ReceiveClientError(), ServerNetworkGameSocketHandler::ReceiveClientMapOk(), ServerNetworkGameSocketHandler::ReceiveClientQuit(), ServerNetworkGameSocketHandler::ReceiveClientSetName(), ClientNetworkGameSocketHandler::ReceiveServerChat(), ClientNetworkGameSocketHandler::ReceiveServerClientInfo(), ClientNetworkGameSocketHandler::ReceiveServerClientJoined(), ClientNetworkGameSocketHandler::ReceiveServerErrorQuit(), ClientNetworkGameSocketHandler::ReceiveServerExternalChat(), ClientNetworkGameSocketHandler::ReceiveServerQuit(), and ServerNetworkGameSocketHandler::SendError().
| std::string NormalizeConnectionString | ( | std::string_view | connection_string, |
| uint16_t | default_port ) |
Normalize a connection string.
That is, ensure there is a port in the string.
| connection_string | The connection string to normalize. |
| default_port | The port to use if none is given. |
Definition at line 551 of file network.cpp.
References ParseFullConnectionString().
Referenced by TCPConnecter::TCPConnecter().
| std::string_view ParseCompanyFromConnectionString | ( | std::string_view | connection_string, |
| CompanyID * | company_id ) |
Parse the company part ("#company" postfix) of a connecting string.
| connection_string | The string with the connection data. |
| company_id | The company ID to set, if available. |
Definition at line 487 of file network.cpp.
References COMPANY_NEW_COMPANY, and COMPANY_SPECTATOR.
Referenced by ServerAddress::Parse(), and ParseFullConnectionString().
| NetworkAddress ParseConnectionString | ( | std::string_view | connection_string, |
| uint16_t | default_port ) |
Convert a string containing either "hostname" or "hostname:ip" to a NetworkAddress.
| connection_string | The string to parse. |
| default_port | The default port to set port to if not in connection_string. |
Definition at line 566 of file network.cpp.
References ParseFullConnectionString().
Referenced by TCPConnecter::Resolve().
| void ShowNetworkError | ( | StringID | error_string | ) |
There was a non-recoverable error, drop back to the main menu with a nice error.
| error_string | The error message to show. |
Definition at line 316 of file network.cpp.
References _switch_mode, GetEncodedString(), ShowErrorMessage(), SM_MENU, and WL_CRITICAL.
Referenced by ClientNetworkGameSocketHandler::GameLoop(), TCPListenHandler< Tsocket, EnumPacketType, Tfull_packet, Tban_packet >::Listen(), and TCPClientConnecter::OnFailure().
| void UpdateNetworkGameWindow | ( | ) |
Update the network new window because a new server is found on the network.
Definition at line 66 of file network_gui.cpp.
References InvalidateWindowData(), WC_NETWORK_WINDOW, and WN_NETWORK_WINDOW_GAME.
Referenced by QueryNetworkGameSocketHandler::CloseConnection(), NetworkAddServer(), NetworkGameListAddItem(), NetworkGameListRemoveExpired(), NetworkGameListRemoveItem(), TCPQueryConnecter::OnFailure(), ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorError(), ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorListing(), QueryNetworkGameSocketHandler::ReceiveServerBanned(), QueryNetworkGameSocketHandler::ReceiveServerError(), QueryNetworkGameSocketHandler::ReceiveServerFull(), and QueryNetworkGameSocketHandler::ReceiveServerGameInfo().
|
extern |
List of broadcast addresses.
Definition at line 82 of file network.cpp.
Referenced by NetworkStartUp(), and NetworkUDPBroadCast().
|
extern |
The current frame.
Definition at line 80 of file network.cpp.
Referenced by TCPListenHandler< Tsocket, EnumPacketType, Tfull_packet, Tban_packet >::AcceptClient(), ClientNetworkCoordinatorSocketHandler::ConnectSuccess(), ClientNetworkGameSocketHandler::GameLoop(), NetworkCalculateLag(), NetworkClient_Connected(), ClientNetworkGameSocketHandler::NetworkExecuteLocalCommandQueue, NetworkGameLoop(), NetworkGameSocketHandler::NetworkGameSocketHandler(), NetworkServer_Tick(), NetworkServerStart(), ServerNetworkGameSocketHandler::ReceiveClientAck(), ServerNetworkGameSocketHandler::ReceiveClientAuthenticationResponse(), ServerNetworkGameSocketHandler::ReceiveClientMapOk(), ClientNetworkGameSocketHandler::ReceiveServerFrame(), ClientNetworkGameSocketHandler::ReceiveServerMapBegin(), ClientNetworkGameSocketHandler::SendAck(), ServerNetworkGameSocketHandler::SendAuthRequest(), ServerNetworkGameSocketHandler::SendFrame(), ServerNetworkGameSocketHandler::SendMap(), ServerNetworkGameSocketHandler::SendSync(), and ServerNetworkGameSocketHandler::SendWelcome().
|
extern |
To where we may go with our clients.
Definition at line 79 of file network.cpp.
Referenced by DistributeCommandPacket(), NetworkGameLoop(), NetworkSendCommand(), NetworkServerStart(), ClientNetworkGameSocketHandler::ReceiveServerFrame(), ClientNetworkGameSocketHandler::ReceiveServerMapBegin(), and ServerNetworkGameSocketHandler::SendFrame().
|
extern |
The frame_counter of the server, if in network-mode.
Definition at line 78 of file network.cpp.
Referenced by NetworkClient_Connected(), NetworkGameLoop(), NetworkServerStart(), ClientNetworkGameSocketHandler::ReceiveServerFrame(), and ClientNetworkGameSocketHandler::ReceiveServerMapBegin().
|
extern |
Used in the server to store the last time a sync packet was sent to clients.
Definition at line 81 of file network.cpp.
Referenced by NetworkServer_Tick(), and NetworkServerStart().
|
extern |
Whether we have finished joining or not.
Definition at line 88 of file network.cpp.
Referenced by ClientNetworkGameSocketHandler::GameLoop(), NetworkInitialize(), and ClientNetworkGameSocketHandler::ReceiveServerFrame().
|
extern |
The number of bytes we already downloaded.
Definition at line 2082 of file network_gui.cpp.
Referenced by NetworkJoinStatusWindow::DrawWidget(), ClientNetworkGameSocketHandler::ReceiveServerMapBegin(), and ClientNetworkGameSocketHandler::ReceiveServerMapData().
|
extern |
The total number of bytes to download.
Definition at line 2083 of file network_gui.cpp.
Referenced by NetworkJoinStatusWindow::DrawWidget(), ClientNetworkGameSocketHandler::ReceiveServerMapBegin(), and ClientNetworkGameSocketHandler::ReceiveServerMapSize().
|
extern |
The status of joining.
Definition at line 2080 of file network_gui.cpp.
Referenced by NetworkJoinStatusWindow::DrawWidget(), NetworkClientJoinGame(), ClientNetworkGameSocketHandler::ReceiveServerMapBegin(), ClientNetworkGameSocketHandler::ReceiveServerMapDone(), ClientNetworkGameSocketHandler::ReceiveServerWaitForMap(), and ClientNetworkGameSocketHandler::SendJoin().
|
extern |
The number of clients waiting in front of us.
Definition at line 2081 of file network_gui.cpp.
Referenced by NetworkJoinStatusWindow::DrawWidget(), and ClientNetworkGameSocketHandler::ReceiveServerWaitForMap().
|
extern |
Reconnect timeout.
Definition at line 74 of file network.cpp.
Referenced by NetworkInitialize(), and ClientNetworkGameSocketHandler::ReceiveServerNewGame().
|
extern |
What type of connection the Game Coordinator detected we are on.
Definition at line 31 of file network_coordinator.cpp.
Referenced by ClientNetworkCoordinatorSocketHandler::CloseConnection(), NetworkClientListWindow::GetWidgetString(), ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorRegisterAck(), ClientNetworkCoordinatorSocketHandler::Register(), and ClientNetworkCoordinatorSocketHandler::SendReceive().
|
extern |
Our invite code as indicated by the Game Coordinator.
Definition at line 32 of file network_coordinator.cpp.
Referenced by ConServerInfo(), NetworkClientListWindow::GetWidgetString(), and ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorRegisterAck().
|
extern |
The current name of the server you are on.
Definition at line 274 of file network_client.cpp.
Referenced by NetworkClientListWindow::GetWidgetString(), ClientNetworkGameSocketHandler::ReceiveServerConfigurationUpdate(), and NetworkClientListWindow::UpdateWidgetSize().
|
extern |
The frame to perform the sync check.
Definition at line 87 of file network.cpp.
Referenced by ClientNetworkGameSocketHandler::GameLoop(), NetworkInitialize(), ClientNetworkGameSocketHandler::ReceiveServerFrame(), and ClientNetworkGameSocketHandler::ReceiveServerSync().
|
extern |
Seed to compare during sync checks.
Definition at line 83 of file network.cpp.
Referenced by ClientNetworkGameSocketHandler::GameLoop(), NetworkGameLoop(), ClientNetworkGameSocketHandler::ReceiveServerFrame(), ClientNetworkGameSocketHandler::ReceiveServerSync(), ServerNetworkGameSocketHandler::SendFrame(), and ServerNetworkGameSocketHandler::SendSync().