Go to the documentation of this file.
10 #include "../stdafx.h"
12 #include "../saveload/saveload.h"
13 #include "../saveload/saveload_filter.h"
14 #include "../command_func.h"
15 #include "../console_func.h"
16 #include "../strings_func.h"
17 #include "../window_func.h"
18 #include "../company_func.h"
19 #include "../company_base.h"
20 #include "../company_gui.h"
21 #include "../core/random_func.hpp"
22 #include "../date_func.h"
23 #include "../gfx_func.h"
30 #include "../core/backup_type.hpp"
31 #include "../thread.h"
33 #include "table/strings.h"
35 #include "../safeguards.h"
42 static const size_t CHUNK = 32 * 1024;
58 for (
auto p : this->blocks) {
69 assert(this->read_bytes == 0);
71 size_t in_packet = p->
size - p->
pos;
72 size_t to_write = std::min<size_t>(this->bufe - this->buf, in_packet);
75 this->written_bytes += in_packet;
77 memcpy(this->buf, pbuf, to_write);
78 this->buf += to_write;
82 if (to_write == in_packet)
return;
86 to_write = in_packet - to_write;
87 this->blocks.push_back(this->buf = CallocT<byte>(
CHUNK));
88 this->bufe = this->buf +
CHUNK;
90 memcpy(this->buf, pbuf, to_write);
91 this->buf += to_write;
94 size_t Read(
byte *rbuf,
size_t size)
override
97 size_t ret_size = size = std::min(this->written_bytes - this->read_bytes, size);
98 this->read_bytes += ret_size;
99 const byte *rbufe = rbuf + ret_size;
101 while (rbuf != rbufe) {
102 if (this->buf == this->bufe) {
103 this->buf = *this->block++;
104 this->bufe = this->buf +
CHUNK;
107 size_t to_write = std::min(this->bufe - this->buf, rbufe - rbuf);
108 memcpy(rbuf, this->buf, to_write);
110 this->buf += to_write;
118 this->read_bytes = 0;
120 this->block = this->blocks.data();
121 this->buf = *this->block++;
122 this->bufe = this->buf +
CHUNK;
135 const char *filename =
"netsave.sav";
136 DEBUG(net, 0,
"Client: Performing emergency save (%s)", filename);
170 if (this->
sock == INVALID_SOCKET)
return status;
212 default: errorno = NETWORK_ERROR_GENERAL;
break;
279 #ifdef NETWORK_SEND_DOUBLE_SEED
284 ShowNetworkError(STR_NETWORK_ERROR_DESYNC);
286 DEBUG(net, 0,
"Sync error detected!");
441 my_client->NetworkGameSocketHandler::SendCommand(p, cp);
595 for (uint i = 0; i < NETWORK_VEH_END; i++) {
598 for (uint i = 0; i < NETWORK_VEH_END; i++) {
671 static const StringID network_error_strings[] = {
672 STR_NETWORK_ERROR_LOSTCONNECTION,
673 STR_NETWORK_ERROR_LOSTCONNECTION,
674 STR_NETWORK_ERROR_LOSTCONNECTION,
675 STR_NETWORK_ERROR_LOSTCONNECTION,
676 STR_NETWORK_ERROR_LOSTCONNECTION,
677 STR_NETWORK_ERROR_LOSTCONNECTION,
678 STR_NETWORK_ERROR_SERVER_ERROR,
679 STR_NETWORK_ERROR_SERVER_ERROR,
680 STR_NETWORK_ERROR_WRONG_REVISION,
681 STR_NETWORK_ERROR_LOSTCONNECTION,
682 STR_NETWORK_ERROR_WRONG_PASSWORD,
683 STR_NETWORK_ERROR_SERVER_ERROR,
684 STR_NETWORK_ERROR_KICKED,
685 STR_NETWORK_ERROR_CHEATER,
686 STR_NETWORK_ERROR_SERVER_FULL,
687 STR_NETWORK_ERROR_TOO_MANY_COMMANDS,
688 STR_NETWORK_ERROR_TIMEOUT_PASSWORD,
689 STR_NETWORK_ERROR_TIMEOUT_COMPUTER,
690 STR_NETWORK_ERROR_TIMEOUT_MAP,
691 STR_NETWORK_ERROR_TIMEOUT_JOIN,
693 static_assert(
lengthof(network_error_strings) == NETWORK_ERROR_END);
697 StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
698 if (
error < (ptrdiff_t)
lengthof(network_error_strings)) err = network_error_strings[
error];
725 for (; grf_count > 0; grf_count--) {
733 char buf[
sizeof(c.
md5sum) * 2 + 1];
881 this->
last_packet = std::chrono::steady_clock::now();
903 ShowJoinStatusWindow();
920 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
926 #ifdef NETWORK_SEND_DOUBLE_SEED
953 #ifdef NETWORK_SEND_DOUBLE_SEED
969 if (err !=
nullptr) {
998 case NETWORK_ACTION_CHAT_CLIENT:
1005 case NETWORK_ACTION_CHAT_COMPANY: {
1009 GetString(name, str,
lastof(name));
1022 if (ci !=
nullptr) {
1035 if (ci !=
nullptr) {
1052 if (ci !=
nullptr) {
1053 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, ci->
client_name,
nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
1056 DEBUG(net, 0,
"Unknown client (%d) is leaving the game",
client_id);
1072 if (ci !=
nullptr) {
1136 DEBUG(net, 0,
"[move] received invalid client index = 0");
1158 _network_server_max_companies = p->
Recv_uint8();
1183 std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->
last_packet;
1184 if (lag < std::chrono::seconds(5))
return;
1188 if (lag > std::chrono::seconds(20)) {
1194 static std::chrono::steady_clock::duration last_lag = {};
1195 if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag))
return;
1198 SetDParam(0, std::chrono::duration_cast<std::chrono::seconds>(lag).count());
1199 ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION,
WL_INFO);
1246 if (ci->client_playas != cid)
continue;
1247 NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR,
CC_DEFAULT,
false, ci->client_name);
1261 if (ci ==
nullptr)
return;
1310 if (ci->client_playas == cio->
client_playas && ci != cio)
return true;
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override
Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far...
uint16 num_station[NETWORK_VEH_END]
How many stations are there of this type?
uint32 _network_join_bytes_total
The total number of bytes to download.
void NetworkClientSendRcon(const char *password, const char *command)
Send a remote console command.
Year inaugurated_year
What year the company started in.
DestType
Destination of our chat messages.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override
Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
uint32 _frame_counter
The current frame.
@ PACKET_CLIENT_ERROR
A client reports an error to the server.
void NetworkClientSetCompanyPassword(const char *password)
Set/Reset company password on the client side.
static NetworkRecvStatus SendSetName(const char *name)
Tell the server that we like to change the name of the client.
NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override
Sends information about the companies (one packet per company): uint8 Version of the structure of thi...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
uint8 max_spectators
maximum amount of spectators
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
@ NETWORK_RECV_STATUS_DESYNC
A desync did occur.
@ STATUS_AUTH_COMPANY
Last action was requesting company password.
static uint8 _network_server_max_spectators
Maximum number of spectators of the currently joined server.
static uint32 _password_game_seed
One bit of 'entropy' used to generate a salt for the company passwords.
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat-packet over the network.
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
uint8 _network_join_waiting
The number of clients waiting in front of us.
byte * buffer
The buffer of this packet, of basically variable length up to SEND_MTU.
Class to backup a specific variable and restore it later.
Money company_value
The company value.
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override
Notification that the client trying to join is banned.
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
CompanyID client_playas
As which company is this client playing (CompanyID)
void AddPacket(const Packet *p)
Add a packet to this buffer.
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
CompanyID _network_join_as
Who would we like to join as.
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
DateFract _date_fract
Fractional part of the day.
bool _network_server
network-server is active
SaveLoadOperation
Operation performed on the file.
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
NetworkAction
Actions that can be used for NetworkTextMessage.
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
static NetworkRecvStatus SendMove(CompanyID company, const char *password)
Ask the server to move us.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
uint32 frame
the frame in which this packet is executed
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
@ WC_CLIENT_LIST
Client list; Window numbers:
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override
Update the clients knowledge of which company is password protected: uint16 Bitwise representation of...
void CheckConnection()
Check the connection's state, i.e.
void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
static bool GameLoop()
Actual game loop for the client.
byte ** block
The block we're reading from/writing to.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
@ PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
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...
@ DFT_GAME_FILE
Save game or scenario file.
SOCKET sock
The socket currently connected to.
bool NetworkFindName(char *new_name, const char *last)
Check whether a name is unique, and otherwise try to make it unique.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
size_t written_bytes
The total number of bytes we've written.
void NetworkUpdateClientName()
Send the server our name.
Randomizer _random
Random used in the game state calculations.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
ClientSettings _settings_client
The current settings for this game.
@ PACKET_CLIENT_QUIT
A client tells the server it is going to quit.
NetworkJoinStatus _network_join_status
The status of joining.
@ PACKET_CLIENT_GETMAP
Client requests the actual map.
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override
The client made an error: uint8 Error code caused (see NetworkErrorCode).
@ WC_COMPANY
Company view; Window numbers:
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
static ClientNetworkGameSocketHandler * my_client
This is us!
virtual NetworkRecvStatus CloseConnection(bool error=true)
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
const char * _network_join_company_password
Company password from -P argument.
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override
Sends that the server will begin with sending the map to the client: uint32 Current frame.
Owner
Enum for all companies/owners.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
Base socket handler for all TCP sockets.
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.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
virtual void Reset()
Reset this filter to read from the beginning of the file.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
size_t Read(byte *rbuf, size_t size) override
Read a given number of bytes from the savegame.
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override
Send information about a client: uint32 ID of the client (always unique on a server.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static const TextColour CC_DEFAULT
Default colour of the console.
uint32 _frame_counter_max
To where we may go with our clients.
Read some packets, and when do use that data as initial load filter.
uint32 grfid
GRF ID (defined by Action 0x08)
bool _network_first_time
Whether we have finished joining or not.
@ PACKET_CLIENT_CHAT
Client said something that should be distributed.
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override
Let the clients know that the server is loading a new map.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
size_t read_bytes
The total number of read bytes.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
@ PACKET_CLIENT_JOIN
The client telling the server it wants to join.
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override
Indication to the client that the server needs a company password: uint32 Generation seed.
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override
Indication to the client that the server needs a game password.
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
static uint32 last_ack_frame
Last frame we performed an ack.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
uint32 _frame_counter_server
The frame_counter of the server, if in network-mode.
Basic data to distinguish a GRF.
@ STATUS_MAP
The client is downloading the map.
void ClearErrorMessages()
Clear all errors from the queue.
char clients[NETWORK_CLIENTS_LENGTH]
The clients that control this company (Name1, name2, ..)
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p) override
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
@ COMPANY_NEW_COMPANY
The client wants a new company.
@ SLO_LOAD
File is being loaded.
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override
Notification that the server is full.
const char * _network_join_server_password
Login password from -p argument.
uint16 num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
static const size_t CHUNK
32 KiB chunks of memory.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
@ NETWORK_RECV_STATUS_CONN_LOST
The connection is 'just' lost.
Everything we need to know about a command to be able to execute it.
Date _date
Current date in days (day counter)
@ SLO_SAVE
File is being saved.
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override
Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repe...
Information about GRF, used in the game and (part of it) in savegames.
std::vector< byte * > blocks
Buffer with blocks of allocated memory.
@ NETWORK_RECV_STATUS_NEWGRF_MISMATCH
We did not have the required NewGRFs.
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
@ NETWORK_RECV_STATUS_SERVER_FULL
The server is full.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
#define DEBUG(name, level,...)
Output a line of debugging information.
void Send_string(const char *data)
Sends a string over the network.
@ NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
@ PACKET_CLIENT_COMPANY_INFO
Request information about all companies.
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override
The client is joined and ready to receive his map: uint32 Own client ID.
ClientID
'Unique' identifier to be given to clients
PacketSize size
The size of the whole packet for received packets.
NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
@ NETWORK_RECV_STATUS_SERVER_BANNED
The server has banned us.
char company_name[NETWORK_COMPANY_NAME_LENGTH]
Company name.
void NetworkClient_Connected()
Is called after a client is connected to the server.
@ STATUS_COMPANY_INFO
We are trying to get company information.
@ PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
@ CCA_NEW
Create a new company.
uint32 _sync_seed_1
Seed to compare during sync checks.
void Reset() override
Reset this filter to read from the beginning of the file.
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
bool autosave_on_network_disconnect
save an autosave when you get disconnected from a network game with an error?
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ STATUS_JOIN
We are trying to join a server.
@ NETWORK_COMPANY_PASSWORD
The password of the company.
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
@ NETWORK_RECV_STATUS_CLOSE_QUERY
Done querying the server.
virtual void SendPacket(Packet *packet)
This function puts the packet in the send-queue and it is send as soon as possible.
@ CLIENT_ID_SERVER
Servers always have this ID.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static const uint NETWORK_SERVER_ID_LENGTH
The maximum length of the network id of the servers, in bytes including '\0'.
bool _networking
are we in networking mode?
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
bool my_cmd
did the command originate from "me"
bool CanReadFromPacket(uint bytes_to_read)
Is it safe to read from the packet, i.e.
static char _password_server_id[NETWORK_SERVER_ID_LENGTH]
The other bit of 'entropy' used to generate a salt for the company passwords.
uint8 _network_reconnect
Reconnect timeout.
@ PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
Internal entity of a packet.
static const byte NETWORK_COMPANY_INFO_VERSION
What version of company info is this?
GameMode
Mode which defines the state of the game.
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means.
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
uint32 state[2]
The state of the randomizer.
byte * buf
Buffer we're going to write to/read from.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
bool prefer_teamchat
choose the chat message target with <ENTER>, true=all clients, false=your team
static uint8 _network_server_max_companies
Maximum number of companies of the currently joined server.
void StateGameLoop()
State controlling game loop.
ClientID _network_own_client_id
Our client identifier.
static NetworkRecvStatus SendCompanyInformationQuery()
Make sure the server ID length is the same as a md5 hash.
ClientNetworkGameSocketHandler(SOCKET s)
Create a new socket for the client side of the game connection.
@ PACKET_CLIENT_SET_NAME
A client changes its name.
static bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override
Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
SwitchMode _switch_mode
The next mainloop command.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
CompanyID _current_company
Company currently doing an action.
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
bool CanSendReceive()
Check whether this socket can send or receive something.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static NetworkRecvStatus SendSetPassword(const char *password)
Tell the server that we like to change the password of the company.
DetailedFileType
Kinds of files in each AbstractFileType.
static NetworkRecvStatus SendRCon(const char *password, const char *command)
Send a console command.
static size_t GetNumItems()
Returns number of valid items in the pool.
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
void Restore()
Restore the variable.
bool Recv_bool()
Read a boolean from the packet.
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p) override
Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of th...
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
@ NO_DIRECTORY
A path without any base directory.
@ STATUS_AUTHORIZED
The client is authorized at the server.
@ COMPANY_SPECTATOR
The client is spectating.
@ WC_NETWORK_WINDOW
Network window; Window numbers:
@ PACKET_CLIENT_GAME_PASSWORD
Clients sends the (hashed) game password.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override
Sends a sync-check to the client: uint32 Frame counter.
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
byte token
The token we need to send back to the server to prove we're the right client.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
@ STATUS_AUTH_GAME
Last action was requesting game (server) password.
byte * bufe
End of the buffer we write to/read from.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
Money money
The amount of money the company has.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Subdirectory
The different kinds of subdirectories OpenTTD uses.
uint16 performance
What was his performance last month?
bool ai
Is this company an AI.
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
@ PACKET_CLIENT_RCON
Client asks the server to execute some command.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
const char * GetNetworkRevisionString()
Get the network version string used by this build.
~ClientNetworkGameSocketHandler()
Clear whatever we assigned.
static const TextColour CC_ERROR
Colour for error lines.
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override
Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
@ SM_MENU
Switch to game intro menu.
Class for handling the client side of the game connection.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override
Let the clients know that the server is closing.
CommandQueue incoming_queue
The command-queue awaiting handling.
uint32 _sync_frame
The frame to perform the sync check.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
ClientID client_id
Client identifier.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
static NetworkRecvStatus SendGetMap()
Request the map from the server.
Interface for filtering a savegame till it is loaded.
#define lengthof(x)
Return the length of an fixed size array.
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override
Send the result of an issues RCon command back to the client: uint16 Colour code.
NetworkSettings network
settings related to the network
@ WN_NETWORK_WINDOW_LOBBY
Network lobby window.
uint64 Recv_uint64()
Read a 64 bits integer from the packet.
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
Money income
How much did the company earned last year.
@ PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
@ PACKET_CLIENT_MOVE
A client would like to be moved to another company.
struct PacketReader * savegame
Packet reader for reading the savegame.
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
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.
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override
Sends that all data of the map are sent to the client:
PacketReader()
Initialise everything.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ STATUS_ACTIVE
The client is active within in the game.
ServerStatus status
Status of the connection with the server.
@ FGCM_EXACT
Only find Grfs matching md5sum.
@ NETWORK_RECV_STATUS_SAVEGAME
Something went wrong (down)loading the savegame.
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override
Sends the size of the map to the client.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override
Notification that a client left the game: uint32 ID of the client.
Company information stored at the client side.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
#define lastof(x)
Get the last element of an fixed size array.
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override
Move a client from one company into another: uint32 ID of the client.
static void Send()
Send the packets of this socket handler.
uint32 _network_join_bytes
The number of bytes we already downloaded.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
NetworkErrorCode
The error codes we send around in the protocols.
Container for all information known about a client.
@ PACKET_CLIENT_SET_PASSWORD
A client (re)sets its company's password.
void CDECL IConsolePrintF(TextColour colour_code, const char *format,...)
Handle the printing of text entered into the console or redirected there by any other means.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ PACKET_CLIENT_COMPANY_PASSWORD
Client sends the (hashed) company password.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
@ NETWORK_GAME_PASSWORD
The password of the game.
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
uint8 max_companies
maximum amount of companies
PacketSize pos
The current read/write position in the packet.
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override
Notification that another client is currently receiving the map: uint8 Number of clients waiting in f...
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
bool use_password
Is there a password.