diff options
author | rubidium <rubidium@openttd.org> | 2011-05-01 11:30:03 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-05-01 11:30:03 +0000 |
commit | 2e572b98deba13708c3ea5c4c0d417b742e424ae (patch) | |
tree | 9449c9af8005428b6b8aa8122ca2a257f5a4f59d /src | |
parent | d4737e07241d6b001f40f81de463ffa66a0eac76 (diff) | |
download | openttd-2e572b98deba13708c3ea5c4c0d417b742e424ae.tar.xz |
(svn r22400) -Codechange: replace some defines in the tcp/game code so doxygen can create better documentation
Diffstat (limited to 'src')
-rw-r--r-- | src/network/core/tcp_game.cpp | 189 | ||||
-rw-r--r-- | src/network/core/tcp_game.h | 133 | ||||
-rw-r--r-- | src/network/network_client.cpp | 54 | ||||
-rw-r--r-- | src/network/network_client.h | 54 | ||||
-rw-r--r-- | src/network/network_server.cpp | 34 | ||||
-rw-r--r-- | src/network/network_server.h | 32 |
6 files changed, 267 insertions, 229 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp index 73fece057..4f0202c60 100644 --- a/src/network/core/tcp_game.cpp +++ b/src/network/core/tcp_game.cpp @@ -74,49 +74,49 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p) this->last_packet = _realtime_tick; switch (this->HasClientQuit() ? PACKET_END : type) { - GAME_COMMAND(PACKET_SERVER_FULL) - GAME_COMMAND(PACKET_SERVER_BANNED) - GAME_COMMAND(PACKET_CLIENT_JOIN) - GAME_COMMAND(PACKET_SERVER_ERROR) - GAME_COMMAND(PACKET_CLIENT_COMPANY_INFO) - GAME_COMMAND(PACKET_SERVER_COMPANY_INFO) - GAME_COMMAND(PACKET_SERVER_CLIENT_INFO) - GAME_COMMAND(PACKET_SERVER_NEED_GAME_PASSWORD) - GAME_COMMAND(PACKET_SERVER_NEED_COMPANY_PASSWORD) - GAME_COMMAND(PACKET_CLIENT_GAME_PASSWORD) - GAME_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD) - GAME_COMMAND(PACKET_SERVER_WELCOME) - GAME_COMMAND(PACKET_CLIENT_GETMAP) - GAME_COMMAND(PACKET_SERVER_WAIT) - GAME_COMMAND(PACKET_SERVER_MAP_BEGIN) - GAME_COMMAND(PACKET_SERVER_MAP_SIZE) - GAME_COMMAND(PACKET_SERVER_MAP_DATA) - GAME_COMMAND(PACKET_SERVER_MAP_DONE) - GAME_COMMAND(PACKET_CLIENT_MAP_OK) - GAME_COMMAND(PACKET_SERVER_JOIN) - GAME_COMMAND(PACKET_SERVER_FRAME) - GAME_COMMAND(PACKET_SERVER_SYNC) - GAME_COMMAND(PACKET_CLIENT_ACK) - GAME_COMMAND(PACKET_CLIENT_COMMAND) - GAME_COMMAND(PACKET_SERVER_COMMAND) - GAME_COMMAND(PACKET_CLIENT_CHAT) - GAME_COMMAND(PACKET_SERVER_CHAT) - GAME_COMMAND(PACKET_CLIENT_SET_PASSWORD) - GAME_COMMAND(PACKET_CLIENT_SET_NAME) - GAME_COMMAND(PACKET_CLIENT_QUIT) - GAME_COMMAND(PACKET_CLIENT_ERROR) - GAME_COMMAND(PACKET_SERVER_QUIT) - GAME_COMMAND(PACKET_SERVER_ERROR_QUIT) - GAME_COMMAND(PACKET_SERVER_SHUTDOWN) - GAME_COMMAND(PACKET_SERVER_NEWGAME) - GAME_COMMAND(PACKET_SERVER_RCON) - GAME_COMMAND(PACKET_CLIENT_RCON) - GAME_COMMAND(PACKET_SERVER_CHECK_NEWGRFS) - GAME_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED) - GAME_COMMAND(PACKET_SERVER_MOVE) - GAME_COMMAND(PACKET_CLIENT_MOVE) - GAME_COMMAND(PACKET_SERVER_COMPANY_UPDATE) - GAME_COMMAND(PACKET_SERVER_CONFIG_UPDATE) + case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p); + case PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p); + case PACKET_CLIENT_JOIN: return this->Receive_CLIENT_JOIN(p); + case PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p); + case PACKET_CLIENT_COMPANY_INFO: return this->Receive_CLIENT_COMPANY_INFO(p); + case PACKET_SERVER_COMPANY_INFO: return this->Receive_SERVER_COMPANY_INFO(p); + case PACKET_SERVER_CLIENT_INFO: return this->Receive_SERVER_CLIENT_INFO(p); + case PACKET_SERVER_NEED_GAME_PASSWORD: return this->Receive_SERVER_NEED_GAME_PASSWORD(p); + case PACKET_SERVER_NEED_COMPANY_PASSWORD: return this->Receive_SERVER_NEED_COMPANY_PASSWORD(p); + case PACKET_CLIENT_GAME_PASSWORD: return this->Receive_CLIENT_GAME_PASSWORD(p); + case PACKET_CLIENT_COMPANY_PASSWORD: return this->Receive_CLIENT_COMPANY_PASSWORD(p); + case PACKET_SERVER_WELCOME: return this->Receive_SERVER_WELCOME(p); + case PACKET_CLIENT_GETMAP: return this->Receive_CLIENT_GETMAP(p); + case PACKET_SERVER_WAIT: return this->Receive_SERVER_WAIT(p); + case PACKET_SERVER_MAP_BEGIN: return this->Receive_SERVER_MAP_BEGIN(p); + case PACKET_SERVER_MAP_SIZE: return this->Receive_SERVER_MAP_SIZE(p); + case PACKET_SERVER_MAP_DATA: return this->Receive_SERVER_MAP_DATA(p); + case PACKET_SERVER_MAP_DONE: return this->Receive_SERVER_MAP_DONE(p); + case PACKET_CLIENT_MAP_OK: return this->Receive_CLIENT_MAP_OK(p); + case PACKET_SERVER_JOIN: return this->Receive_SERVER_JOIN(p); + case PACKET_SERVER_FRAME: return this->Receive_SERVER_FRAME(p); + case PACKET_SERVER_SYNC: return this->Receive_SERVER_SYNC(p); + case PACKET_CLIENT_ACK: return this->Receive_CLIENT_ACK(p); + case PACKET_CLIENT_COMMAND: return this->Receive_CLIENT_COMMAND(p); + case PACKET_SERVER_COMMAND: return this->Receive_SERVER_COMMAND(p); + case PACKET_CLIENT_CHAT: return this->Receive_CLIENT_CHAT(p); + case PACKET_SERVER_CHAT: return this->Receive_SERVER_CHAT(p); + case PACKET_CLIENT_SET_PASSWORD: return this->Receive_CLIENT_SET_PASSWORD(p); + case PACKET_CLIENT_SET_NAME: return this->Receive_CLIENT_SET_NAME(p); + case PACKET_CLIENT_QUIT: return this->Receive_CLIENT_QUIT(p); + case PACKET_CLIENT_ERROR: return this->Receive_CLIENT_ERROR(p); + case PACKET_SERVER_QUIT: return this->Receive_SERVER_QUIT(p); + case PACKET_SERVER_ERROR_QUIT: return this->Receive_SERVER_ERROR_QUIT(p); + case PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p); + case PACKET_SERVER_NEWGAME: return this->Receive_SERVER_NEWGAME(p); + case PACKET_SERVER_RCON: return this->Receive_SERVER_RCON(p); + case PACKET_CLIENT_RCON: return this->Receive_CLIENT_RCON(p); + case PACKET_SERVER_CHECK_NEWGRFS: return this->Receive_SERVER_CHECK_NEWGRFS(p); + case PACKET_CLIENT_NEWGRFS_CHECKED: return this->Receive_CLIENT_NEWGRFS_CHECKED(p); + case PACKET_SERVER_MOVE: return this->Receive_SERVER_MOVE(p); + case PACKET_CLIENT_MOVE: return this->Receive_CLIENT_MOVE(p); + case PACKET_SERVER_COMPANY_UPDATE: return this->Receive_SERVER_COMPANY_UPDATE(p); + case PACKET_SERVER_CONFIG_UPDATE: return this->Receive_SERVER_CONFIG_UPDATE(p); default: this->CloseConnection(); @@ -150,61 +150,58 @@ NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets() } /** - * Create stub implementations for all receive commands that only - * show a warning that the given command is not available for the - * socket where the packet came from. - * @param type the packet type to create the stub for + * Helper for logging receiving invalid packets. + * @param type The received packet type. + * @return The status the network should have, in this case: "malformed packet error". */ -#define DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(type) \ -NetworkRecvStatus NetworkGameSocketHandler::NetworkPacketReceive_## type ##_command(Packet *p) \ -{ \ - DEBUG(net, 0, "[tcp/game] received illegal packet type %d from client %d", \ - type, this->client_id); \ - return NETWORK_RECV_STATUS_MALFORMED_PACKET; \ +NetworkRecvStatus NetworkGameSocketHandler::ReceiveInvalidPacket(PacketGameType type) +{ + DEBUG(net, 0, "[tcp/game] received illegal packet type %d from client %d", type, this->client_id); + return NETWORK_RECV_STATUS_MALFORMED_PACKET; } -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FULL) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_BANNED) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_JOIN) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_GAME_PASSWORD) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_COMPANY_PASSWORD) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GAME_PASSWORD) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DATA) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DONE) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_JOIN) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FRAME) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SYNC) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ACK) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_CHAT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHAT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_QUIT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ERROR) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_QUIT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_RCON) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_RCON) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MOVE) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MOVE) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_UPDATE) -DEFINE_UNAVAILABLE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CONFIG_UPDATE) +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_FULL); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_BANNED); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_JOIN); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_INFO); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_INFO); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_GAME_PASSWORD); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_COMPANY_PASSWORD); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_PASSWORD); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_PASSWORD); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_WELCOME); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GETMAP); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_WAIT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_BEGIN); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_SIZE); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DATA); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MAP_DONE); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MAP_OK); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_JOIN); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_FRAME); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SYNC); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ACK); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMMAND); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMMAND); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_CHAT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHAT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_PASSWORD); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_NAME); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_QUIT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_ERROR); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_QUIT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR_QUIT); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_SHUTDOWN); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEWGAME); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_RCON); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_RCON); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHECK_NEWGRFS); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_NEWGRFS_CHECKED); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_MOVE); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); } +NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); } #endif /* ENABLE_NETWORK */ diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index decbe00c5..afa2879cb 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -148,9 +148,6 @@ public: uint Count() const { return this->count; } }; -#define DECLARE_GAME_RECEIVE_COMMAND(type) virtual NetworkRecvStatus NetworkPacketReceive_## type ##_command(Packet *p) -#define DEF_GAME_RECEIVE_COMMAND(cls, type) NetworkRecvStatus cls ##NetworkGameSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p) - /** Base socket handler for all TCP sockets */ class NetworkGameSocketHandler : public NetworkTCPSocketHandler { /* TODO: rewrite into a proper class */ @@ -158,16 +155,19 @@ private: NetworkClientInfo *info; ///< Client info related to this socket protected: + NetworkRecvStatus ReceiveInvalidPacket(PacketGameType type); /** * Notification that the server is full. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FULL); + virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p); /** * Notification that the client trying to join is banned. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_BANNED); + virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p); /** * Try to join the server: @@ -175,19 +175,22 @@ protected: * string Name of the client (max NETWORK_NAME_LENGTH). * uint8 ID of the company to play as (1..MAX_COMPANIES). * uint8 ID of the clients Language. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_JOIN); + virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p); /** * The client made an error: * uint8 Error code caused (see NetworkErrorCode). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR); + virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p); /** * Request company information (in detail). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO); + virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p); /** * Sends information about the companies (one packet per company): @@ -213,96 +216,111 @@ protected: * uint16 Number of harbours. * bool Company is an AI. * string Client names (comma separated list) + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO); + virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p); /** * Send information about a client: * uint32 ID of the client (always unique on a server. 1 = server, 0 is invalid). * uint8 ID of the company the client is playing as (255 for spectators). * string Name of the client. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_GAME_PASSWORD); + virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p); /** * Indication to the client that the server needs a company password: * uint32 Generation seed. * string Network ID of the server. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_COMPANY_PASSWORD); + virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p); /** * Send a password to the server to authorize: * uint8 Password type (see NetworkPasswordType). * string The password. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GAME_PASSWORD); + virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p); /** * Send a password to the server to authorize * uint8 Password type (see NetworkPasswordType). * string The password. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD); + virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p); /** * The client is joined and ready to receive his map: * uint32 Own client ID. * uint32 Generation seed. * string Network ID of the server. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME); + virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p); /** * Request the map from the server. * uint32 NewGRF version (release versions of OpenTTD only). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP); + virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p); /** * Notification that another client is currently receiving the map: * uint8 Number of clients waiting in front of you. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT); + virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p); /** * Sends that the server will begin with sending the map to the client: * uint32 Current frame. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN); + virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p); /** * Sends the size of the map to the client. * uint32 Size of the (compressed) map (in bytes). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DATA); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DONE); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK); + 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 ID of the client that just joined the game. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_JOIN); + virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p); /** * Sends the current frame counter to the client: @@ -311,23 +329,26 @@ protected: * uint32 General seed 1 (dependant on compile settings, not default). * uint32 General seed 2 (dependant on compile settings, not default). * uint8 Random token to validate the client is actually listening (only occasionally present). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FRAME); + virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p); /** * Sends a sync-check to the client: * uint32 Frame counter. * uint32 General seed 1. * uint32 General seed 2 (dependant on compile settings, not default). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SYNC); + virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p); /** * Tell the server we are done with this frame: * uint32 Current frame counter of the client. * uint8 The random token that the server sent in the PACKET_SERVER_FRAME packet. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ACK); + virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p); /** * Send a DoCommand to the Server: @@ -338,8 +359,9 @@ protected: * uint32 Tile where this is taking place. * string Text. * uint8 ID of the callback. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND); + virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p); /** * Sends a DoCommand to the client: @@ -351,8 +373,9 @@ protected: * string Text. * uint8 ID of the callback. * uint32 Frame of execution. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMMAND); + virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p); /** * Sends a chat-packet to the server: @@ -361,8 +384,9 @@ protected: * uint32 ID of the client or company (destination of the chat). * string Message (max NETWORK_CHAT_LENGTH). * uint64 data (used e.g. for 'give money' actions). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_CHAT); + virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p); /** * Sends a chat-packet to the client: @@ -370,108 +394,125 @@ protected: * uint32 ID of the client (origin of the chat). * string Message (max NETWORK_CHAT_LENGTH). * uint64 data (used e.g. for 'give money' actions). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHAT); + virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p); /** * Set the password for the clients current company: * string The password. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME); + virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p); /** * The client is quiting the game. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_QUIT); + virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p); /** * The client made an error and is quiting the game. * uint8 Error of the code caused (see NetworkErrorCode). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ERROR); + virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p); /** * Notification that a client left the game: * uint32 ID of the client. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_QUIT); + virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p); /** * Inform all clients that one client made an error and thus has quit/been disconnected: * uint32 ID of the client that caused the error. * uint8 Code of the error caused (see NetworkErrorCode). + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME); + virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p); /** * Send the result of an issues RCon command back to the client: * uint16 Colour code. * string Output of the RCon command + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_RCON); + virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p); /** * Send an RCon command to the server: * string RCon password. * string Command to be executed. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_RCON); + virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p); /** * Sends information about all used GRFs to the client: * uint8 Amount of GRFs (the following data is repeated this many times, i.e. per GRF data). * uint32 GRF ID * 16 * uint8 MD5 checksum of the GRF + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS); + 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. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED); + virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p); /** * Move a client from one company into another: * uint32 ID of the client. * uint8 ID of the new company. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MOVE); + virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p); /** * Request the server to move this client into another company: * uint8 ID of the company the client wants to join. * string Password, if the company is password protected. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MOVE); + virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p); /** * Update the clients knowledge of which company is password protected: * uint16 Bitwise representation of each company + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_UPDATE); + virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p); /** * Update the clients knowledge of the max settings: * uint8 Maximum number of companies allowed. * uint8 Maximum number of spectators allowed. + * @param p The packet that was just received. */ - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CONFIG_UPDATE); + virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p); NetworkRecvStatus HandlePacket(Packet *p); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 35741f09a..406f71448 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -489,7 +489,7 @@ bool ClientNetworkGameSocketHandler::IsConnected() extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); extern StringID _switch_mode_errorstr; -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_FULL) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { /* We try to join a server which is full */ _switch_mode_errorstr = STR_NETWORK_ERROR_SERVER_FULL; @@ -498,7 +498,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_FULL) return NETWORK_RECV_STATUS_SERVER_FULL; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_BANNED) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p) { /* We try to join a server where we are banned */ _switch_mode_errorstr = STR_NETWORK_ERROR_SERVER_BANNED; @@ -507,7 +507,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_BANNED) return NETWORK_RECV_STATUS_SERVER_BANNED; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_COMPANY_INFO) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { if (this->status != STATUS_COMPANY_INFO) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -551,7 +551,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_COMPANY_INFO) /* This packet contains info about the client (playas and name) * as client we save this in NetworkClientInfo, linked via 'client_id' * which is always an unique number on a server. */ -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CLIENT_INFO) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p) { NetworkClientInfo *ci; ClientID client_id = (ClientID)p->Recv_uint32(); @@ -604,7 +604,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CLIENT_INFO) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_ERROR) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p) { NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8(); @@ -642,7 +642,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_ERROR) return NETWORK_RECV_STATUS_SERVER_ERROR; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHECK_NEWGRFS) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(Packet *p) { if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -675,7 +675,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHECK_NEWGRFS) return ret; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEED_GAME_PASSWORD) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) { if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET; this->status = STATUS_AUTH_GAME; @@ -690,7 +690,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEED_GAME_PASSWORD) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEED_COMPANY_PASSWORD) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) { if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_COMPANY) return NETWORK_RECV_STATUS_MALFORMED_PACKET; this->status = STATUS_AUTH_COMPANY; @@ -709,7 +709,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEED_COMPANY_PASSWORD) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WELCOME) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME(Packet *p) { if (this->status < STATUS_JOIN || this->status >= STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; this->status = STATUS_AUTHORIZED; @@ -724,7 +724,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WELCOME) return SendGetMap(); } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WAIT) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT(Packet *p) { /* We set the internal wait state when requesting the map. */ if (this->status != STATUS_MAP_WAIT) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -737,7 +737,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WAIT) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packet *p) { if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET; this->status = STATUS_MAP; @@ -757,7 +757,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_BEGIN) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_SIZE) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *p) { if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET; if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -768,7 +768,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_SIZE) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DATA) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *p) { if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET; if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -782,7 +782,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DATA) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DONE) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *p) { if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET; if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -838,7 +838,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DONE) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_FRAME) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p) { if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -871,7 +871,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_FRAME) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_SYNC) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC(Packet *p) { if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -884,7 +884,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_SYNC) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_COMMAND) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *p) { if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -903,7 +903,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_COMMAND) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHAT) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p) { if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -955,7 +955,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CHAT) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_ERROR_QUIT) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p) { if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -972,7 +972,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_ERROR_QUIT) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_QUIT) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p) { if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -992,7 +992,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_QUIT) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_JOIN) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p) { if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -1008,7 +1008,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_JOIN) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_SHUTDOWN) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet *p) { /* Only when we're trying to join we really * care about the server shutting down. */ @@ -1019,7 +1019,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_SHUTDOWN) return NETWORK_RECV_STATUS_SERVER_ERROR; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEWGAME) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet *p) { /* Only when we're trying to join we really * care about the server shutting down. */ @@ -1034,7 +1034,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEWGAME) return NETWORK_RECV_STATUS_SERVER_ERROR; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_RCON) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON(Packet *p) { if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -1049,7 +1049,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_RCON) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MOVE) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p) { if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -1077,7 +1077,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MOVE) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CONFIG_UPDATE) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; @@ -1087,7 +1087,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_CONFIG_UPDATE) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_COMPANY_UPDATE) +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p) { if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; diff --git a/src/network/network_client.h b/src/network/network_client.h index c1ded6035..8f4cc603b 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -44,33 +44,33 @@ protected: friend void NetworkClose(bool close_admins); static ClientNetworkGameSocketHandler *my_client; - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FULL); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_BANNED); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_GAME_PASSWORD); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_COMPANY_PASSWORD); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_BEGIN); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_SIZE); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DATA); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP_DONE); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_JOIN); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FRAME); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SYNC); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMMAND); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHAT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_QUIT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_RCON); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MOVE); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_UPDATE); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CONFIG_UPDATE); + virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p); + virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p); static NetworkRecvStatus SendNewGRFsOk(); static NetworkRecvStatus SendGetMap(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 1a14623b8..53198f970 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -760,12 +760,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate() * DEF_SERVER_RECEIVE_COMMAND has parameter: NetworkClientSocket *cs, Packet *p ************/ -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMPANY_INFO) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) { return this->SendCompanyInfo(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_NEWGRFS_CHECKED) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) { if (this->status != STATUS_NEWGRFS_CHECK) { /* Illegal call, return error and ignore the packet */ @@ -786,7 +786,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_NEWGRFS_CHECKED) return this->SendWelcome(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_JOIN) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) { if (this->status != STATUS_INACTIVE) { /* Illegal call, return error and ignore the packet */ @@ -855,13 +855,13 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_JOIN) if (_grfconfig == NULL) { /* Behave as if we received PACKET_CLIENT_NEWGRFS_CHECKED */ - return this->NetworkPacketReceive_PACKET_CLIENT_NEWGRFS_CHECKED_command(NULL); + return this->Receive_CLIENT_NEWGRFS_CHECKED(NULL); } return this->SendNewGRFCheck(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GAME_PASSWORD) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(Packet *p) { if (this->status != STATUS_AUTH_GAME) { return this->SendError(NETWORK_ERROR_NOT_EXPECTED); @@ -886,7 +886,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GAME_PASSWORD) return this->SendWelcome(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMPANY_PASSWORD) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p) { if (this->status != STATUS_AUTH_COMPANY) { return this->SendError(NETWORK_ERROR_NOT_EXPECTED); @@ -908,7 +908,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMPANY_PASSWORD) return this->SendWelcome(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GETMAP) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(Packet *p) { NetworkClientSocket *new_cs; @@ -950,7 +950,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_GETMAP) return this->SendMap(); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MAP_OK) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *p) { /* Client has the map, now start syncing */ if (this->status == STATUS_DONE_MAP && !this->HasClientQuit()) { @@ -997,7 +997,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MAP_OK) * The client has done a command and wants us to handle it * @param p the packet in which the command was sent */ -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMMAND) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *p) { /* The client was never joined.. so this is impossible, right? * Ignore the packet, give the client a warning, and close his connection */ @@ -1061,7 +1061,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_COMMAND) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ERROR) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p) { /* This packets means a client noticed an error and is reporting this * to us. Display the error and report it to the other clients */ @@ -1095,7 +1095,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ERROR) return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_QUIT) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p) { /* The client wants to leave. Display this and report it to the other * clients. */ @@ -1122,7 +1122,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_QUIT) return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST); } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_ACK) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p) { if (this->status < STATUS_AUTHORIZED) { /* Illegal call, return error and ignore the packet */ @@ -1281,7 +1281,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co } } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_CHAT) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p) { if (this->status < STATUS_AUTHORIZED) { /* Illegal call, return error and ignore the packet */ @@ -1313,7 +1313,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_CHAT) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_PASSWORD) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *p) { if (this->status != STATUS_ACTIVE) { /* Illegal call, return error and ignore the packet */ @@ -1330,7 +1330,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_PASSWORD) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_NAME) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *p) { if (this->status != STATUS_ACTIVE) { /* Illegal call, return error and ignore the packet */ @@ -1356,7 +1356,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_NAME) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_RCON) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) { if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); @@ -1381,7 +1381,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_RCON) return NETWORK_RECV_STATUS_OKAY; } -DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_MOVE) +NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) { if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); diff --git a/src/network/network_server.h b/src/network/network_server.h index 8fb19b53c..2aa0bef34 100644 --- a/src/network/network_server.h +++ b/src/network/network_server.h @@ -26,22 +26,22 @@ extern NetworkClientSocketPool _networkclientsocket_pool; /** Class for handling the server side of the game connection. */ class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> { protected: - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_JOIN); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GAME_PASSWORD); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ACK); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_CHAT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_QUIT); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_ERROR); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_RCON); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED); - DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MOVE); + virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p); + virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p); NetworkRecvStatus SendCompanyInfo(); NetworkRecvStatus SendNewGRFCheck(); |