36#include "table/strings.h"
61 assert(this->read_bytes == 0);
62 p.
TransferOut([
this](std::span<const uint8_t> source) {
63 std::ranges::copy(source, std::back_inserter(this->buffer));
68 size_t Read(uint8_t *rbuf,
size_t size)
override
71 size_t read_size = std::min(this->buffer.size() - this->read_bytes, size);
73 std::copy_n(this->iterator, read_size, rbuf);
74 std::advance(this->iterator, read_size);
75 this->read_bytes += read_size;
83 this->iterator = this->buffer.cbegin();
123 assert(this->
sock != INVALID_SOCKET);
234#ifdef NETWORK_SEND_DOUBLE_SEED
241 Debug(net, 0,
"Sync error detected");
289 Debug(net, 9,
"Client::SendJoin()");
291 Debug(net, 9,
"Client::status = JOIN");
293 Debug(net, 9,
"Client::join_status = Authorizing");
299 p->Send_uint32(_openttd_newgrf_version);
311 Debug(net, 9,
"Client::SendIdentify()");
326 Debug(net, 9,
"Client::SendNewGRFsOk()");
339 Debug(net, 9,
"Client::SendAuthResponse()");
342 my_client->authentication_handler->SendResponse(*p);
354 Debug(net, 9,
"Client::SendGetMap()");
356 Debug(net, 9,
"Client::status = MAP_WAIT");
370 Debug(net, 9,
"Client::SendMapOk()");
372 Debug(net, 9,
"Client::status = ACTIVE");
386 Debug(net, 9,
"Client::SendAck()");
403 Debug(net, 9,
"Client::SendCommand(): cmd={}", cp.
cmd);
406 my_client->NetworkGameSocketHandler::SendCommand(*p, cp);
423 Debug(net, 9,
"Client::SendChat(): action={}, type={}, dest={}", action, type, dest);
429 p->Send_uint32(dest);
431 p->Send_uint64(data);
444 Debug(net, 9,
"Client::SendError(): errorno={}", errorno);
460 Debug(net, 9,
"Client::SendSetName()");
464 p->Send_string(name);
475 Debug(net, 9,
"Client::SendQuit()");
491 Debug(net, 9,
"Client::SendRCon()");
494 p->Send_string(pass);
495 p->Send_string(command);
507 Debug(net, 9,
"Client::SendMove(): company={}", company);
510 p->Send_uint8(company);
534 Debug(net, 9,
"Client::ReceiveServerFull()");
544 Debug(net, 9,
"Client::ReceiveServerBanned()");
561 Debug(net, 9,
"Client::ReceiveServerClientInfo(): client_id={}, playas={}",
client_id, playas);
633 return STR_NETWORK_ERROR_LOSTCONNECTION;
639 return STR_NETWORK_ERROR_SERVER_ERROR;
659 Debug(net, 9,
"Client::ReceiveServerError(): error={}", error);
684 Debug(net, 9,
"Client::ReceiveServerCheckNewGRFs(): grf_count={}", grf_count);
687 for (; grf_count > 0; grf_count--) {
726 Debug(net, 9,
"Client::status = AUTH_GAME");
729 Debug(net, 9,
"Client::ReceiveServerAuthenticationRequest()");
752 Debug(net, 9,
"Client::ReceiveServerEnableEncryption()");
760 Debug(net, 9,
"Client::status = ENCRYPTED");
769 Debug(net, 9,
"Client::status = AUTHORIZED");
785 Debug(net, 9,
"Client::ReceiveServerWaitForMap()");
788 Debug(net, 9,
"Client::join_status = Waiting");
799 Debug(net, 9,
"Client::status = MAP");
804 this->
savegame = std::make_shared<PacketReader>();
813 Debug(net, 9,
"Client::join_status = Downloading");
852 Debug(net, 9,
"Client::ReceiveServerMapDone()");
854 Debug(net, 9,
"Client::join_status = Processing");
870 this->
last_packet = std::chrono::steady_clock::now();
896 Debug(net, 9,
"Client::join_status = Registering");
917#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
920#ifdef NETWORK_SEND_DOUBLE_SEED
927#ifdef NETWORK_SEND_DOUBLE_SEED
952#ifdef NETWORK_SEND_DOUBLE_SEED
970 Debug(net, 9,
"Client::ReceiveServerCommand(): cmd={}, frame={}", cp.
cmd, cp.
frame);
972 if (err.has_value()) {
995 Debug(net, 9,
"Client::ReceiveServerChat(): action={}, client_id={}, self_send={}", action,
client_id, self_send);
1005 name = ci_to->client_name;
1013 name =
GetString(str, ci_to->client_playas);
1022 name = ci_to->client_name;
1026 if (ci !=
nullptr) {
1041 Debug(net, 9,
"Client::ReceiveServerExternalChat(): source={}", source);
1056 Debug(net, 9,
"Client::ReceiveServerErrorQuit(): client_id={}",
client_id);
1059 if (ci !=
nullptr) {
1075 Debug(net, 9,
"Client::ReceiveServerQuit(): client_id={}",
client_id);
1078 if (ci !=
nullptr) {
1082 Debug(net, 1,
"Unknown client ({}) is leaving the game",
client_id);
1097 Debug(net, 9,
"Client::ReceiveServerClientJoined(): client_id={}",
client_id);
1100 if (ci !=
nullptr) {
1111 Debug(net, 9,
"Client::ReceiveServerShutdown()");
1126 Debug(net, 9,
"Client::ReceiveServerNewGame()");
1147 Debug(net, 9,
"Client::ReceiveServerRemoteConsoleCommand()");
1165 CompanyID company_id = (CompanyID)p.
Recv_uint8();
1167 Debug(net, 9,
"Client::ReceiveServerMove(): client_id={}, company_id={}",
client_id, company_id);
1171 Debug(net, 1,
"Received invalid client index = 0");
1212 std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->
last_packet;
1213 if (lag < std::chrono::seconds(5))
return;
1217 if (lag > std::chrono::seconds(20)) {
1223 static std::chrono::steady_clock::duration last_lag = {};
1224 if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag))
return;
1229 GetEncodedString(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, std::chrono::duration_cast<std::chrono::seconds>(lag).count()),
1242 Debug(net, 9,
"Client::NetworkClient_Connected()");
1278 if (ci->client_playas != cid)
continue;
1295 if (client_name.empty())
return false;
1296 if (client_name[0] ==
' ')
return false;
1343 if (ci ==
nullptr)
return;
1352 std::string temporary_name = client_name;
1386 if (ci->client_playas == cio->
client_playas && ci != cio)
return true;
Class for backupping variables and making sure they are restored later.
constexpr enable_if_t< is_integral_v< T >, T > byteswap(T x) noexcept
Custom implementation of std::byteswap; remove once we build with C++23.
Handles requests by immediately returning the server password, or show the user to password window.
void SendResponse() override
Callback to trigger sending the response for the password request.
void AskUserForPassword(std::shared_ptr< NetworkAuthenticationPasswordRequest > request) override
Callback to trigger asking the user for the password.
static ClientNetworkGameSocketHandler * my_client
This is us!
NetworkRecvStatus ReceiveServerQuit(Packet &p) override
Notification that a client left the game: uint32_t ID of the client.
NetworkRecvStatus ReceiveServerFull(Packet &p) override
Notification that the server is full.
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
NetworkRecvStatus ReceiveServerExternalChat(Packet &p) override
Sends a chat-packet for external source to the client: string Name of the source this message came fr...
NetworkRecvStatus ReceiveServerCommand(Packet &p) override
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
static bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
NetworkRecvStatus ReceiveServerClientInfo(Packet &p) override
Send information about a client: uint32_t ID of the client (always unique on a server.
std::string connection_string
Address we are connected to.
~ClientNetworkGameSocketHandler() override
Clear whatever we assigned.
NetworkRecvStatus ReceiveServerBanned(Packet &p) override
Notification that the client trying to join is banned.
static NetworkRecvStatus SendIdentify()
Identify ourselves to the server.
ServerStatus status
Status of the connection with the server.
static NetworkRecvStatus SendMove(CompanyID company)
Ask the server to move us.
std::unique_ptr< class NetworkAuthenticationClientHandler > authentication_handler
The handler for the authentication.
std::shared_ptr< struct PacketReader > savegame
Packet reader for reading the savegame.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
NetworkRecvStatus ReceiveServerChat(Packet &p) override
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
uint8_t token
The token we need to send back to the server to prove we're the right client.
static NetworkRecvStatus SendSetName(const std::string &name)
Tell the server that we like to change the name of the client.
NetworkRecvStatus ReceiveServerNewGame(Packet &p) override
Let the clients know that the server is loading a new map.
NetworkRecvStatus ReceiveServerEnableEncryption(Packet &p) override
Indication to the client that authentication is complete and encryption has to be used from here on f...
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
static NetworkRecvStatus SendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, int64_t data)
Send a chat-packet over the network.
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
NetworkRecvStatus ReceiveServerMapBegin(Packet &p) override
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
void CheckConnection()
Check the connection's state, i.e.
NetworkRecvStatus ReceiveServerCheckNewGRFs(Packet &p) override
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is re...
NetworkRecvStatus ReceiveServerWaitForMap(Packet &p) override
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in...
ClientNetworkGameSocketHandler(SOCKET s, std::string_view connection_string)
Create a new socket for the client side of the game connection.
NetworkRecvStatus ReceiveServerRemoteConsoleCommand(Packet &p) override
Send the result of an issues RCon command back to the client: uint16_t Colour code.
NetworkRecvStatus ReceiveServerShutdown(Packet &p) override
Let the clients know that the server is closing.
NetworkRecvStatus ReceiveServerMapDone(Packet &p) override
Sends that all data of the map are sent to the client:
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
NetworkRecvStatus ReceiveServerMove(Packet &p) override
Move a client from one company into another: uint32_t ID of the client.
static NetworkRecvStatus SendAuthResponse()
Set the game password as requested.
NetworkRecvStatus ReceiveServerFrame(Packet &p) override
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how...
NetworkRecvStatus ReceiveServerSync(Packet &p) override
Sends a sync-check to the client: uint32_t Frame counter.
static bool GameLoop()
Actual game loop for the client.
NetworkRecvStatus ReceiveServerError(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
static void Send()
Send the packets of this socket handler.
@ STATUS_JOIN
We are trying to join a server.
@ STATUS_ENCRYPTED
The game authentication has completed and from here on the connection to the server is encrypted.
@ STATUS_MAP
The client is downloading the map.
@ STATUS_AUTH_GAME
Last action was requesting game (server) password.
@ STATUS_ACTIVE
The client is active within in the game.
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
@ STATUS_AUTHORIZED
The client is authorized at the server.
static NetworkRecvStatus SendRCon(std::string_view password, std::string_view command)
Send a console command.
static NetworkRecvStatus SendCommand(const CommandPacket &cp)
Send a command to the server.
NetworkRecvStatus ReceiveServerErrorQuit(Packet &p) override
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of ...
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
NetworkRecvStatus ReceiveServerMapData(Packet &p) override
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
static NetworkRecvStatus SendGetMap()
Request the map from the server.
NetworkRecvStatus ReceiveServerConfigurationUpdate(Packet &p) override
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
NetworkRecvStatus ReceiveServerWelcome(Packet &p) override
The client is joined and ready to receive their map: uint32_t Own client ID.
NetworkRecvStatus ReceiveServerMapSize(Packet &p) override
Sends the size of the map to the client.
NetworkRecvStatus ReceiveServerClientJoined(Packet &p) override
A client joined (PacketGameType::ClientMapOk), what usually directly follows is a PacketGameType::Ser...
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
NetworkRecvStatus ReceiveServerAuthenticationRequest(Packet &p) override
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to us...
@ AwaitUserInput
We have requested some user input, but must wait on that.
@ Invalid
We have received an invalid request.
@ ReadyForResponse
We do not have to wait for user input, and can immediately respond to the server.
static std::unique_ptr< NetworkAuthenticationClientHandler > Create(std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > password_handler, std::string &secret_key, std::string &public_key)
Create a NetworkAuthenticationClientHandler.
Callback interface for client implementations to provide the handling of the password requests.
bool IsPendingDeletion() const
Is this pending for deletion and as such should not be accessed anymore.
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
std::optional< std::string_view > ReceiveCommand(Packet &p, CommandPacket &cp)
Receives a command from the network.
ClientID client_id
Client identifier.
CommandQueue incoming_queue
The command-queue awaiting handling.
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
void DeferDeletion()
Mark this socket handler for deletion, once iterating the socket handlers is done.
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
void MarkClosed()
Mark the connection as closed.
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
std::unique_ptr< class NetworkEncryptionHandler > send_encryption_handler
The handler for encrypting sent packets.
std::unique_ptr< class NetworkEncryptionHandler > receive_encryption_handler
The handler for decrypting received packets.
SOCKET sock
The socket currently connected to.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
static void EventEnterMultiplayer(uint map_width, uint map_height)
Event: user entered a multiplayer game.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
CompanyID _current_company
Company currently doing an action.
Command definitions related to companies.
Functions related to companies.
GUI Functions related to companies.
@ New
Create a new company.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
static constexpr CompanyID COMPANY_NEW_COMPANY
The client wants a new company.
@ None
Dummy reason for actions that don't need one.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
static const uint NETWORK_PUBLIC_KEY_LENGTH
The maximum length of the hexadecimal encoded public keys, in bytes including '\0'.
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Console functions used outside of the console code.
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
static const TextColour CC_WARNING
Colour for warning lines.
static const TextColour CC_DEFAULT
Default colour of the console.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
@ NETWORK_RECV_STATUS_DESYNC
A desync did occur.
@ NETWORK_RECV_STATUS_CLIENT_QUIT
The connection is lost gracefully. Other clients are already informed of this leaving client.
@ NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
@ NETWORK_RECV_STATUS_SAVEGAME
Something went wrong (down)loading the savegame.
@ NETWORK_RECV_STATUS_CLOSE_QUERY
Done querying the server.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
@ NETWORK_RECV_STATUS_NEWGRF_MISMATCH
We did not have the required NewGRFs.
@ NETWORK_RECV_STATUS_SERVER_FULL
The server is full.
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
@ NETWORK_RECV_STATUS_SERVER_BANNED
The server has banned us.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Functions related to errors.
void ClearErrorMessages()
Clear all errors from the queue.
@ WL_ERROR
Errors (eg. saving/loading failed).
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
SaveLoadOperation
Operation performed on the file.
@ Load
File is being loaded.
DetailedFileType
Kinds of files in each AbstractFileType.
@ GameFile
Save game or scenario file.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ None
A path without any base directory.
GameSessionStats _game_session_stats
Statistics about the current session.
SwitchMode _switch_mode
The next mainloop command.
Functions related to the gfx engine.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve a short translateable string of the error code.
uint32_t _frame_counter_server
The frame_counter of the server, if in network-mode.
uint32_t _frame_counter
The current frame.
uint8_t _network_reconnect
Reconnect timeout.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
uint32_t _sync_seed_1
Seed to compare during sync checks.
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.
uint32_t _sync_frame
The frame to perform the sync check.
void ShowNetworkError(StringID error_string)
There was a non-recoverable error, drop back to the main menu with a nice error.
ClientID _network_own_client_id
Our client identifier.
bool _network_first_time
Whether we have finished joining or not.
uint32_t _frame_counter_max
To where we may go with our clients.
Basic functions/variables used all over the place.
Base core network types and some helper functions to access them.
void NetworkUpdateClientName(const std::string &client_name)
Send the server our name as callback from the setting.
NetworkJoinInfo _network_join
Information about the game to join to.
void NetworkClientSendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, int64_t data)
Send a chat message.
bool NetworkValidateOurClientName()
Convenience method for NetworkValidateClientName on _settings_client.network.client_name.
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
static uint32_t last_ack_frame
Last frame we performed an ack.
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr< LoadFilter > lf)
Load the specified savegame but on error do different things.
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
void NetworkClientSendRcon(std::string_view password, std::string_view command)
Send a remote console command.
uint NetworkMaxCompaniesAllowed()
Get the maximum number of companies that are allowed by the server.
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
static StringID GetLongNetworkErrorString(NetworkErrorCode error)
Get a long form translateable string for a NetworkErrorCode.
static uint8_t _network_server_max_companies
Maximum number of companies of the currently joined server.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members who they can chat to.
std::string _network_server_name
The current name of the server you are on.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
bool NetworkValidateClientName(std::string &client_name)
Trim the given client name in place, i.e.
bool NetworkIsValidClientName(std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
Client part of the network protocol.
NetworkJoinInfo _network_join
Information about the game to join to.
void NetworkClient_Connected()
Is called after a client is connected to the server.
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
std::string_view GetNetworkRevisionString()
Get the network version string used by this build.
void DeserializeGRFIdentifier(Packet &p, GRFIdentifier &grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Handling of the list of games.
NetworkJoinStatus _network_join_status
The status of joining.
uint8_t _network_join_waiting
The number of clients waiting in front of us.
void ShowJoinStatusWindow()
Open the window showing the status of joining the server.
void ShowClientList()
Open the client list window.
uint32_t _network_join_bytes_total
The total number of bytes to download.
uint32_t _network_join_bytes
The number of bytes we already downloaded.
void ShowNetworkNeedPassword(std::shared_ptr< NetworkAuthenticationPasswordRequest > request)
Update the NetworkJoinStatusWindow to start requesting the server password.
GUIs related to networking.
@ Waiting
Waiting for other clients to finish downloading the map.
@ Processing
Loading the savegame.
@ Registering
Creating a new company.
@ Authorizing
Starting authorizing the client to join the game and optionally company.
@ Downloading
Downloading the map from the server.
bool NetworkMakeClientNameUnique(std::string &new_name)
Check whether a name is unique, and otherwise try to make it unique.
NetworkErrorCode
The error codes we send around in the protocols.
@ WrongRevision
The client is using the wrong revision.
@ General
Fallback error code in case nothing matches.
@ Desync
Client tells that they desynced.
@ SavegameFailed
Client tells they could not load the savegame.
@ Cheater
The client is trying control companies in a way they are not supposed to.
@ TimeoutPassword
The client has timed out providing a password.
@ TooManyCommands
The client has sent too many commands in a short time.
@ TimeoutComputer
The client has timed out because the computer could not keep up with the server.
@ TimeoutMap
The client has timed out because it took too long to download the map.
@ NotAuthorized
The client tried to do something there are not authorized to.
@ ServerFull
The server is full.
@ InvalidClientName
The client tried to set an invalid name.
@ TimeoutJoin
The client has timed out because getting up to speed with the server failed.
@ NotOnAllowList
The client is not on the allow list.
@ WrongPassword
The client entered a wrong password.
@ NotExpected
The request/packet was not expected in the current state.
@ Kicked
The client got kicked.
@ ConnectionLost
Connection to the client was lost.
@ IllegalPacket
A packet was received that has invalid content.
@ NameInUse
The client has a duplicate name (and we couldn't make it unique).
@ NoAuthenticationMethodAvailable
The client and server could not find a common authentication method.
@ CompanyMismatch
The client was impersonating another company.
@ NewGRFMismatch
Client does not have the right NewGRFs.
NetworkAction
Actions that can be used for NetworkTextMessage.
@ ChatExternal
An external application sent a message over the admin port.
@ ChatTeam
A chat sent to all clients of a team/company.
@ ClientNameChange
A client changed their name.
@ ClientJoin
A client joined the server.
@ CompanySpectator
A client joined the spectators.
@ ChatClient
A chat sent to a specific client.
@ ClientLeave
A client left the server.
NetworkChatDestinationType
Destination of our chat messages.
ClientID
'Unique' identifier to be given to clients
@ CLIENT_ID_SERVER
Servers always have this ID.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
@ Exact
Only find Grfs matching md5sum.
void StateGameLoop()
State controlling game loop.
GameMode
Mode which defines the state of the game.
@ SM_MENU
Switch to game intro menu.
Randomizer _random
Random used in the game state calculations.
Pseudo random number generator.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Functions/types related to saving and loading games.
Declaration of filters used for saving and loading savegames.
ClientSettings _settings_client
The current settings for this game.
Interface definitions for game to report/respond to social integration.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
void StrTrimInPlace(std::string &str)
Trim the spaces from given string in place, i.e.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Class to backup a specific variable and restore it later.
void Restore()
Restore the variable.
Everything we need to know about a command to be able to execute it.
uint32_t frame
the frame in which this packet is executed
bool my_cmd
did the command originate from "me"
Commands cmd
command being executed.
A savegame name automatically numbered.
Information about GRF, used in the game and (part of it) in savegames.
Basic data to distinguish a GRF.
uint32_t grfid
GRF ID (defined by Action 0x08).
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF).
Interface for filtering a savegame till it is loaded.
LoadFilter(std::shared_ptr< LoadFilter > chain)
Initialise this filter.
static uint SizeX()
Get the size of the map along the X.
static uint SizeY()
Get the size of the map along the Y.
Container for all information known about a client.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
CompanyID client_playas
As which company is this client playing (CompanyID).
std::string client_name
Name of the client.
std::string public_key
The public key of the client.
Information required to join a server.
size_t Read(uint8_t *rbuf, size_t size) override
Read a given number of bytes from the savegame.
std::deque< uint8_t > Buffer
The underlying buffer type that's being use.
PacketReader()
Initialise everything.
size_t read_bytes
The total number of read bytes.
void AddPacket(Packet &p)
Add a packet to this buffer.
Buffer::const_iterator iterator
Buffer we're going to write to/read from.
void Reset() override
Reset this filter to read from the beginning of the file.
Buffer buffer
Buffer with the raw save game data.
Internal entity of a packet.
uint16_t Recv_uint16()
Read a 16 bits integer from the packet.
uint64_t Recv_uint64()
Read a 64 bits integer from the packet.
bool Recv_bool()
Read a boolean from the packet.
uint32_t Recv_uint32()
Read a 32 bits integer from the packet.
std::string Recv_string(size_t length, StringValidationSettings settings=StringValidationSetting::ReplaceWithQuestionMark)
Reads characters (bytes) from the packet until it finds a '\0', or reaches a maximum of length charac...
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
bool CanReadFromPacket(size_t bytes_to_read, bool close_connection=false)
Is it safe to read from the packet, i.e.
ssize_t TransferOut(F transfer_function)
Transfer data from the packet to the given function.
static Pool::IterateWrapper< NetworkClientInfo > Iterate(size_t from=0)
static size_t GetNumItems()
static bool CanAllocateItem(size_t n=1)
static bool IsValidID(auto index)
static T * Create(Targs &&... args)
@ ClientCommand
Client executed a command and sends it to the server.
@ ClientQuit
A client tells the server it is going to quit.
@ ClientAck
The client tells the server which frame it has executed.
@ ClientRemoteConsoleCommand
Client asks the server to execute some command.
@ ClientJoin
The client telling the server it wants to join.
@ ClientNewGRFsChecked
Client acknowledges that it has all required NewGRFs.
@ ClientSetName
A client changes its name.
@ ClientError
A client reports an error to the server.
@ ClientMapOk
Client tells the server that it received the whole map.
@ ClientMove
A client would like to be moved to another company.
@ ClientGetMap
Client requests the actual map.
@ ClientChat
Client said something that should be distributed.
@ ClientAuthenticationResponse
The client responds to the authentication request.
@ ClientIdentify
Client telling the server the client's name and requested company.
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
Definition of the game-calendar-timer.
Definition of the tick-based game-timer.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
@ WC_CLIENT_LIST
Client list; Window numbers:
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers: