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" 29 #include "../core/backup_type.hpp" 30 #include "../thread.h" 32 #include "table/strings.h" 34 #include "../safeguards.h" 41 static const size_t CHUNK = 32 * 1024;
57 for (
auto p : this->blocks) {
68 assert(this->read_bytes == 0);
70 size_t in_packet = p->
size - p->
pos;
71 size_t to_write =
min((
size_t)(this->bufe - this->buf), in_packet);
74 this->written_bytes += in_packet;
76 memcpy(this->buf, pbuf, to_write);
77 this->buf += to_write;
81 if (to_write == in_packet)
return;
85 to_write = in_packet - to_write;
86 this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
87 this->bufe = this->buf +
CHUNK;
89 memcpy(this->buf, pbuf, to_write);
90 this->buf += to_write;
93 size_t Read(byte *rbuf,
size_t size)
override 96 size_t ret_size = size =
min(this->written_bytes - this->read_bytes, size);
97 this->read_bytes += ret_size;
98 const byte *rbufe = rbuf + ret_size;
100 while (rbuf != rbufe) {
101 if (this->buf == this->bufe) {
102 this->buf = *this->block++;
103 this->bufe = this->buf +
CHUNK;
106 size_t to_write =
min(this->bufe - this->buf, rbufe - rbuf);
107 memcpy(rbuf, this->buf, to_write);
109 this->buf += to_write;
117 this->read_bytes = 0;
119 this->block = this->blocks.data();
120 this->buf = *this->block++;
121 this->bufe = this->buf +
CHUNK;
134 const char *filename =
"netsave.sav";
135 DEBUG(net, 0,
"Client: Performing emergency save (%s)", filename);
169 if (this->
sock == INVALID_SOCKET)
return status;
211 default: errorno = NETWORK_ERROR_GENERAL;
break;
270 #ifdef NETWORK_SEND_DOUBLE_SEED 275 NetworkError(STR_NETWORK_ERROR_DESYNC);
277 DEBUG(net, 0,
"Sync error detected!");
432 my_client->NetworkGameSocketHandler::SendCommand(p, cp);
586 for (uint i = 0; i < NETWORK_VEH_END; i++) {
589 for (uint i = 0; i < NETWORK_VEH_END; i++) {
662 static const StringID network_error_strings[] = {
663 STR_NETWORK_ERROR_LOSTCONNECTION,
664 STR_NETWORK_ERROR_LOSTCONNECTION,
665 STR_NETWORK_ERROR_LOSTCONNECTION,
666 STR_NETWORK_ERROR_LOSTCONNECTION,
667 STR_NETWORK_ERROR_LOSTCONNECTION,
668 STR_NETWORK_ERROR_LOSTCONNECTION,
669 STR_NETWORK_ERROR_SERVER_ERROR,
670 STR_NETWORK_ERROR_SERVER_ERROR,
671 STR_NETWORK_ERROR_WRONG_REVISION,
672 STR_NETWORK_ERROR_LOSTCONNECTION,
673 STR_NETWORK_ERROR_WRONG_PASSWORD,
674 STR_NETWORK_ERROR_SERVER_ERROR,
675 STR_NETWORK_ERROR_KICKED,
676 STR_NETWORK_ERROR_CHEATER,
677 STR_NETWORK_ERROR_SERVER_FULL,
678 STR_NETWORK_ERROR_TOO_MANY_COMMANDS,
679 STR_NETWORK_ERROR_TIMEOUT_PASSWORD,
680 STR_NETWORK_ERROR_TIMEOUT_COMPUTER,
681 STR_NETWORK_ERROR_TIMEOUT_MAP,
682 STR_NETWORK_ERROR_TIMEOUT_JOIN,
688 StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
689 if (error < (ptrdiff_t)
lengthof(network_error_strings)) err = network_error_strings[
error];
709 for (; grf_count > 0; grf_count--) {
717 char buf[
sizeof(c.
md5sum) * 2 + 1];
755 p->
Recv_string(_password_server_id,
sizeof(_password_server_id));
777 p->
Recv_string(_password_server_id,
sizeof(_password_server_id));
887 ShowJoinStatusWindow();
904 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME 910 #ifdef NETWORK_SEND_DOUBLE_SEED 937 #ifdef NETWORK_SEND_DOUBLE_SEED 953 if (err !=
nullptr) {
982 case NETWORK_ACTION_CHAT_CLIENT:
989 case NETWORK_ACTION_GIVE_MONEY:
993 case NETWORK_ACTION_CHAT_COMPANY: {
997 GetString(name, str,
lastof(name));
1010 if (ci !=
nullptr) {
1023 if (ci !=
nullptr) {
1040 if (ci !=
nullptr) {
1041 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, ci->
client_name,
nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
1044 DEBUG(net, 0,
"Unknown client (%d) is leaving the game", client_id);
1060 if (ci !=
nullptr) {
1122 if (client_id == 0) {
1124 DEBUG(net, 0,
"[move] received invalid client index = 0");
1146 _network_server_max_companies = p->
Recv_uint8();
1147 _network_server_max_spectators = p->
Recv_uint8();
1176 if (lag < 5)
return;
1186 static uint last_lag = 0;
1187 if (last_lag == lag)
return;
1191 ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION,
WL_INFO);
1238 if (ci->client_playas != cid)
continue;
1239 NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR,
CC_DEFAULT,
false, ci->client_name);
1253 if (ci ==
nullptr)
return;
1302 if (ci->client_playas == cio->
client_playas && ci != cio)
return true;
Client acknowledges that it has all required NewGRFs.
Owner
Enum for all companies/owners.
We are trying to get company information.
NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override
Sends information about the companies (one packet per company): uint8 Version of the structure of thi...
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
used in multiplayer to create a new companies etc.
bool _networking
are we in networking mode?
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override
Notification that the server is full.
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.
char clients[NETWORK_CLIENTS_LENGTH]
The clients that control this company (Name1, name2, ..)
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
Container for all information known about a client.
SOCKET sock
The socket currently connected to.
uint32 _sync_seed_1
Seed to compare during sync checks.
struct PacketReader * savegame
Packet reader for reading the savegame.
uint32 _realtime_tick
The real time in the game.
Internal entity of a packet.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
A client changes its name.
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
size_t written_bytes
The total number of bytes we've written.
static bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
Subdirectory
The different kinds of subdirectories OpenTTD uses.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
The client is authorized at the server.
NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Client list; Window numbers:
PacketSize pos
The current read/write position in the packet.
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override
Let the clients know that the server is loading a new map.
const char * _network_join_server_password
Login password from -p argument.
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
Switch to game intro menu.
const char * _network_join_company_password
Company password from -P argument.
bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=nullptr)
Load the specified savegame but on error do different things.
bool ai
Is this company an AI.
static uint8 _network_server_max_spectators
Maximum number of spectators of the currently joined server.
GUIs related to networking.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
void Send_string(const char *data)
Sends a string over the network.
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
Something went wrong (down)loading the savegame.
byte ** block
The block we're reading from/writing to.
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
NetworkErrorCode
The error codes we send around in the protocols.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
char company_name[NETWORK_COMPANY_NAME_LENGTH]
Company name.
Clients sends the (hashed) game password.
NetworkJoinStatus _network_join_status
The status of joining.
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override
Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
The client wants a new company.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Client part of the network protocol.
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
static uint8 _network_server_max_companies
Maximum number of companies of the currently joined server.
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override
Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed...
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
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.
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override
Let the clients know that the server is closing.
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
void CSleep(int milliseconds)
Sleep on the current thread for a defined time.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat message.
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override
The client is joined and ready to receive his map: uint32 Own client ID.
#define lastof(x)
Get the last element of an fixed size array.
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override
Update the clients knowledge of which company is password protected: uint16 Bitwise representation of...
static const TextColour CC_DEFAULT
Default colour of the console.
Money company_value
The company value.
bool IsValidConsoleColour(TextColour c)
Check whether the given TextColour is valid for console usage.
Base core network types and some helper functions to access them.
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
ClientNetworkGameSocketHandler(SOCKET s)
Create a new socket for the client side of the game connection.
static NetworkRecvStatus SendSetPassword(const char *password)
Tell the server that we like to change the password of the company.
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override
Sends a sync-check to the client: uint32 Frame counter.
const char * GetNetworkRevisionString()
Get the network version string used by this build.
void Append(CommandPacket *p)
Append a CommandPacket at the end of the queue.
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
void AddPacket(const Packet *p)
Add a packet to this buffer.
Class for handling the client side of the game connection.
ClientID
'Unique' identifier to be given to clients
uint32 _sync_frame
The frame to perform the sync check.
The server told us we made an error.
The client tells the server which frame it has executed.
Basic data to distinguish a GRF.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Client asks the server to execute some command.
The password of the company.
CommandQueue incoming_queue
The command-queue awaiting handling.
Class to backup a specific variable and restore it later.
size_t Read(byte *rbuf, size_t size) override
Read a given number of bytes from the savegame.
static const size_t CHUNK
32 KiB chunks of memory.
uint16 num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
Save game or scenario file.
Done querying the server.
Interface for filtering a savegame till it is loaded.
Year inaugurated_year
What year the company started in.
~ClientNetworkGameSocketHandler()
Clear whatever we assigned.
Critical errors, the MessageBox is shown in all cases.
void StateGameLoop()
State controlling game loop.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
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)...
bool prefer_teamchat
choose the chat message target with <ENTER>, true=all clients, false=your team
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
NetworkSettings network
settings related to the network
CompanyID client_playas
As which company is this client playing (CompanyID)
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
A client would like to be moved to another company.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
DateFract _date_fract
Fractional part of the day.
byte * buffer
The buffer of this packet, of basically variable length up to SEND_MTU.
The client is spectating.
Information about GRF, used in the game and (part of it) in savegames.
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
GameMode
Mode which defines the state of the game.
Client sends the (hashed) company password.
uint8 max_spectators
maximum amount of spectators
Company information stored at the client side.
void IConsolePrint(TextColour colour_code, const char *string)
Handle the printing of text entered into the console or redirected there by any other means...
Read some packets, and when do use that data as initial load filter.
size_t read_bytes
The total number of read bytes.
void CheckConnection()
Check the connection's state, i.e.
ClientID _network_own_client_id
Our client identifier.
ClientSettings _settings_client
The current settings for this game.
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
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...
A path without any base directory.
The client is waiting as someone else is downloading the map.
void NetworkClientsToSpectators(CompanyID cid)
Move the clients of a company to the spectators.
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override
Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far...
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...
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override
Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
virtual void Reset()
Reset this filter to read from the beginning of the file.
void NetworkUpdateClientName()
Send the server our name.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
uint8 _network_reconnect
Reconnect timeout.
static ClientNetworkGameSocketHandler * my_client
This is us!
Subdirectory of save for autosaves.
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override
Indication to the client that the server needs a game password.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
A client (re)sets its company's password.
void Reset() override
Reset this filter to read from the beginning of the file.
assert_compile(NETWORK_SERVER_ID_LENGTH==16 *2+1)
Make sure the server ID length is the same as a md5 hash.
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override
Sends that all data of the map are sent to the client:
byte * buf
Buffer we're going to write to/read from.
std::vector< byte * > blocks
Buffer with blocks of allocated memory.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
We did not have the required NewGRFs.
Basic functions/variables used all over the place.
PacketSize size
The size of the whole packet for received packets.
SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
#define lengthof(x)
Return the length of an fixed size array.
uint last_packet
Time we received the last frame.
static T min(const T a, const T b)
Returns the minimum of two values.
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
uint32 frame
the frame in which this packet is executed
ServerStatus status
Status of the connection with the server.
static NetworkRecvStatus SendRCon(const char *password, const char *command)
Send a console command.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static NetworkRecvStatus SendMove(CompanyID company, const char *password)
Ask the server to move us.
A client reports an error to the server.
bool Recv_bool()
Read a boolean from the packet.
uint32 _network_join_bytes
The number of bytes we already downloaded.
SaveLoadOperation
Operation performed on the file.
void NetworkClient_Connected()
Is called after a client is connected to the server.
uint16 performance
What was his performance last month?
uint8 max_companies
maximum amount of companies
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
Tell whether the client has team members where he/she can chat to.
The connection is 'just' lost.
#define DEBUG(name, level,...)
Output a line of debugging information.
Network status window; Window numbers:
ClientID client_id
Client identifier.
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override
Send information about a client: uint32 ID of the client (always unique on a server.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static NetworkRecvStatus SendCompanyInformationQuery()
Query the server for company information.
The password of the game.
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override
Send the result of an issues RCon command back to the client: uint16 Colour code. ...
bool NetworkFindName(char *new_name, const char *last)
Check whether a name is unique, and otherwise try to make it unique.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
bool use_password
Is there a password.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Client requests the actual map.
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
uint32 _frame_counter
The current frame.
The server has banned us.
uint64 Recv_uint64()
Read a 64 bits integer from the packet.
void ClearErrorMessages()
Clear all errors from the queue.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Randomizer _random
Random used in the game state calculations.
static size_t GetNumItems()
Returns number of valid items in the pool.
PacketReader()
Initialise everything.
CompanyID _network_join_as
Who would we like to join as.
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
void NetworkClientSetCompanyPassword(const char *password)
Set/Reset company password on the client side.
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...
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override
Indication to the client that the server needs a company password: uint32 Generation seed...
Client executed a command and sends it to the server.
virtual NetworkRecvStatus CloseConnection(bool error=true)
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
void NetworkClientSendRcon(const char *password, const char *command)
Send a remote console command.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
The client telling the server it wants to join.
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...
uint32 _frame_counter_server
The frame_counter of the server, if in network-mode.
uint16 num_station[NETWORK_VEH_END]
How many stations are there of this type?
static const uint NETWORK_SERVER_ID_LENGTH
The maximum length of the network id of the servers, in bytes including '\0'.
Network window; Window numbers:
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Maximum number of companies.
The client is active within in the game.
byte * bufe
End of the buffer we write to/read from.
SwitchMode _switch_mode
The next mainloop command.
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.
const char * ReceiveCommand(Packet *p, CommandPacket *cp)
Receives a command from the network.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
static uint32 _password_game_seed
One bit of 'entropy' used to generate a salt for the company passwords.
A client tells the server it is going to quit.
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override
Notification that the client trying to join is banned.
bool _network_server
network-server is active
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
CompanyID _current_company
Company currently doing an action.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static const TextColour CC_ERROR
Colour for error lines.
We are trying to join a server.
Everything we need to know about a command to be able to execute it.
static void Send()
Send the packets of this socket handler.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static NetworkRecvStatus SendSetName(const char *name)
Tell the server that we like to change the name of the client.
uint32 grfid
GRF ID (defined by Action 0x08)
We apparently send a malformed packet.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint32 _network_join_bytes_total
The total number of bytes to download.
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override
Notification that a client left the game: uint32 ID of the client.
The client is downloading the map.
Client said something that should be distributed.
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
virtual void SendPacket(Packet *packet)
This function puts the packet in the send-queue and it is send as soon as possible.
static NetworkRecvStatus SendGetMap()
Request the map from the server.
void Restore()
Restore the variable.
static NetworkRecvStatus SendCommand(const CommandPacket *cp)
Send a command to the server.
Servers always have this ID.
Money money
The amount of money the company has.
void ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Last action was requesting game (server) password.
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
bool CanSendReceive()
Check whether this socket can send or receive something.
Base socket handler for all TCP sockets.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Last action was requesting company password.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
static uint32 last_ack_frame
Last frame we performed an ack.
Only find Grfs matching md5sum.
uint32 state[2]
The state of the randomizer.
static const byte NETWORK_COMPANY_INFO_VERSION
What version of company info is this?
uint8 _network_join_waiting
The number of clients waiting in front of us.
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
Send a chat-packet over the network.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
bool my_cmd
did the command originate from "me"
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override
Sends that the server will begin with sending the map to the client: uint32 Current frame...
Date _date
Current date in days (day counter)
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override
Move a client from one company into another: uint32 ID of the client.
Company view; Window numbers:
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
DetailedFileType
Kinds of files in each AbstractFileType.
uint32 _frame_counter_max
To where we may go with our clients.
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override
The client made an error: uint8 Error code caused (see NetworkErrorCode).
static bool GameLoop()
Actual game loop for the client.
bool _network_first_time
Whether we have finished joining or not.
byte token
The token we need to send back to the server to prove we're the right client.
DestType
Destination of our chat messages.
Money income
How much did the company earned last year.
static char _password_server_id[NETWORK_SERVER_ID_LENGTH]
The other bit of 'entropy' used to generate a salt for the company passwords.
NetworkAction
Actions that can be used for NetworkTextMessage.
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override
Sends the size of the map to the client.
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override
Notification that another client is currently receiving the map: uint8 Number of clients waiting in f...
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.
Request information about all companies.
bool autosave_on_network_disconnect
save an autosave when you get disconnected from a network game with an error?
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
Client tells the server that it received the whole map.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.