Merge tag '14.0-beta3' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/industrytype.h
#	src/network/core/config.h
#	src/network/core/network_game_info.cpp
#	src/network/core/network_game_info.h
#	src/network/core/packet.cpp
#	src/network/core/packet.h
#	src/network/core/tcp.cpp
#	src/network/core/tcp.h
#	src/network/core/tcp_admin.cpp
#	src/network/core/tcp_content.cpp
#	src/network/core/tcp_coordinator.cpp
#	src/network/core/tcp_game.cpp
#	src/network/core/tcp_game.h
#	src/network/core/tcp_turn.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_admin.cpp
#	src/network/network_client.cpp
#	src/network/network_client.h
#	src/network/network_command.cpp
#	src/network/network_content.cpp
#	src/network/network_internal.h
#	src/network/network_query.cpp
#	src/network/network_query.h
#	src/network/network_server.cpp
#	src/network/network_server.h
#	src/network/network_turn.cpp
#	src/network/network_udp.cpp
#	src/rail_gui.cpp
#	src/road_gui.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 17:57:05 +00:00
67 changed files with 1463 additions and 1297 deletions

View File

@@ -16,6 +16,7 @@
#include "tcp.h"
#include "../network_type.h"
#include "../../core/pool_type.hpp"
#include "../../core/ring_buffer.hpp"
#include <memory>
#include <chrono>
@@ -23,7 +24,7 @@
* Enum with all types of TCP packets.
* For the exact meaning, look at #NetworkGameSocketHandler.
*/
enum PacketGameType {
enum PacketGameType : uint8_t {
/*
* These first four pair of packets (thus eight in
* total) must remain in this order for backward
@@ -142,27 +143,12 @@ const char *GetPacketTypeName(PacketGameType type);
/** Packet that wraps a command */
struct CommandPacket;
/** A queue of CommandPackets. */
class CommandQueue {
CommandPacket *first; ///< The first packet in the queue.
CommandPacket *last; ///< The last packet in the queue; only valid when first != nullptr.
uint count; ///< The number of items in the queue.
void Append(CommandPacket *p, bool move);
public:
/** Initialise the command queue. */
CommandQueue() : first(nullptr), last(nullptr), count(0) {}
/** Clear the command queue. */
~CommandQueue() { this->Free(); }
void Append(CommandPacket &p) { this->Append(&p, false); }
void Append(CommandPacket &&p) { this->Append(&p, true); }
std::unique_ptr<CommandPacket> Pop(bool ignore_paused = false);
CommandPacket *Peek(bool ignore_paused = false);
void Free();
/** Get the number of items in the queue. */
uint Count() const { return this->count; }
};
/**
* A "queue" of CommandPackets.
* Not a std::queue because, when paused, some commands remain on the queue.
* In other words, you do not always pop the first element from this queue.
*/
using CommandQueue = ring_buffer<CommandPacket>;
/** Base socket handler for all TCP sockets */
class NetworkGameSocketHandler : public NetworkTCPSocketHandler {
@@ -179,13 +165,13 @@ protected:
* Notification that the server is full.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet &p);
/**
* Notification that the client trying to join is banned.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet &p);
/**
* Try to join the server:
@@ -195,34 +181,34 @@ protected:
* uint8_t ID of the clients Language.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet &p);
/**
* The client made an error:
* uint8_t Error code caused (see NetworkErrorCode).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet &p);
/**
* Request game information.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet &p);
/**
* Sends information about the game.
* Serialized NetworkGameInfo. See game_info.h for details.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p);
/**
* Sends information about the game (extended).
* Serialized NetworkGameInfo. See game_info.h for details.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO_EXTENDED(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO_EXTENDED(Packet &p);
/**
* Send information about a client:
@@ -231,13 +217,13 @@ protected:
* string Name of the client.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p);
/**
* Indication to the client that the server needs a game password.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet &p);
/**
* Indication to the client that the server needs a company password:
@@ -245,7 +231,7 @@ protected:
* string Network ID of the server.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet &p);
/**
* Send a password to the server to authorize:
@@ -253,7 +239,7 @@ protected:
* string The password.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet &p);
/**
* Send a password to the server to authorize
@@ -261,7 +247,7 @@ protected:
* string The password.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet &p);
/**
* Send a password to the server to authorize
@@ -269,14 +255,14 @@ protected:
* string The password.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_SETTINGS_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_SETTINGS_PASSWORD(Packet &p);
/**
* Indication to the client that the setting access state has changed
* bool setting access state
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_SETTINGS_ACCESS(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_SETTINGS_ACCESS(Packet &p);
/**
* The client is joined and ready to receive their map:
@@ -285,61 +271,61 @@ protected:
* string Network ID of the server.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p);
/**
* Request the map from the server.
* uint32_t NewGRF version (release versions of OpenTTD only).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet &p);
/**
* Notification that another client is currently receiving the map:
* uint8_t Number of clients waiting in front of you.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet &p);
/**
* Sends that the server will begin with sending the map to the client:
* uint32_t Current frame.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet &p);
/**
* Sends the size of the map to the client.
* uint32_t Size of the (compressed) map (in bytes).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet &p);
/**
* Sends the data of the map to the client:
* Contains a part of the map (until max size of packet).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet &p);
/**
* Sends that all data of the map are sent to the client:
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet &p);
/**
* Tell the server that we are done receiving/loading the map.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet &p);
/**
* A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:
* uint32_t ID of the client that just joined the game.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet &p);
/**
* Sends the current frame counter to the client:
@@ -350,7 +336,7 @@ protected:
* uint8_t Random token to validate the client is actually listening (only occasionally present).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet &p);
/**
* Sends a sync-check to the client:
@@ -359,7 +345,7 @@ protected:
* uint32_t General seed 2 (dependent on compile settings, not default).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet &p);
/**
* Tell the server we are done with this frame:
@@ -367,7 +353,7 @@ protected:
* uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet &p);
/**
* Send a DoCommand to the Server:
@@ -380,7 +366,7 @@ protected:
* uint8_t ID of the callback.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet &p);
/**
* Sends a DoCommand to the client:
@@ -394,7 +380,7 @@ protected:
* uint32_t Frame of execution.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet &p);
/**
* Sends a chat-packet to the server:
@@ -405,7 +391,7 @@ protected:
* uint64_t data (used e.g. for 'give money' actions).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet &p);
/**
* Sends a chat-packet to the client:
@@ -415,7 +401,7 @@ protected:
* uint64_t data (used e.g. for 'give money' actions).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet &p);
/**
* Sends a chat-packet for external source to the client:
@@ -425,45 +411,45 @@ protected:
* string Message (max NETWORK_CHAT_LENGTH).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet &p);
/**
* Set the password for the clients current company:
* string The password.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet &p);
/**
* Gives the client a new name:
* string New name of the client.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet &p);
/**
* The client is quitting the game.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet &p);
/**
* The client made an error and is quitting the game.
* uint8_t Error of the code caused (see NetworkErrorCode).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_DESYNC_LOG(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_MSG(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_SYNC_DATA(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet &p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_LOG(Packet &p);
virtual NetworkRecvStatus Receive_SERVER_DESYNC_LOG(Packet &p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_MSG(Packet &p);
virtual NetworkRecvStatus Receive_CLIENT_DESYNC_SYNC_DATA(Packet &p);
/**
* Notification that a client left the game:
* uint32_t ID of the client.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet &p);
/**
* Inform all clients that one client made an error and thus has quit/been disconnected:
@@ -471,19 +457,19 @@ protected:
* uint8_t Code of the error caused (see NetworkErrorCode).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet &p);
/**
* Let the clients know that the server is closing.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p);
/**
* Let the clients know that the server is loading a new map.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p);
/**
* Send the result of an issues RCon command back to the client:
@@ -491,7 +477,7 @@ protected:
* string Output of the RCon command
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet &p);
/**
* Send an RCon command to the server:
@@ -499,7 +485,7 @@ protected:
* string Command to be executed.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet &p);
/**
* Sends information about all used GRFs to the client:
@@ -508,13 +494,13 @@ protected:
* 16 * uint8_t MD5 checksum of the GRF
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet &p);
/**
* Tell the server that we have the required GRFs
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet &p);
/**
* Move a client from one company into another:
@@ -522,7 +508,7 @@ protected:
* uint8_t ID of the new company.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet &p);
/**
* Request the server to move this client into another company:
@@ -530,14 +516,14 @@ protected:
* string Password, if the company is password protected.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet &p);
/**
* Update the clients knowledge of which company is password protected:
* uint16_t Bitwise representation of each company
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p);
/**
* Update the clients knowledge of the max settings:
@@ -545,9 +531,9 @@ protected:
* uint8_t Maximum number of spectators allowed.
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet &p);
NetworkRecvStatus HandlePacket(Packet *p);
NetworkRecvStatus HandlePacket(Packet &p);
NetworkGameSocketHandler(SOCKET s);
public:
@@ -588,8 +574,8 @@ public:
NetworkRecvStatus ReceivePackets();
const char *ReceiveCommand(Packet *p, CommandPacket *cp);
void SendCommand(Packet *p, const CommandPacket *cp);
const char *ReceiveCommand(Packet &p, CommandPacket &cp);
void SendCommand(Packet &p, const CommandPacket &cp);
virtual std::string GetDebugInfo() const;
virtual void LogSentPacket(const Packet &pkt) override;