diff options
author | rubidium <rubidium@openttd.org> | 2010-10-15 13:47:37 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-10-15 13:47:37 +0000 |
commit | 0ca7e4e82e3657b6e935bc618403192b82b5dcc0 (patch) | |
tree | a373b6dd186d9b726d891855dd57301c0194661b /src/network/core/tcp_game.h | |
parent | 8eb07d097e2ab53f0b41a6b7af541c4937732e0b (diff) | |
download | openttd-0ca7e4e82e3657b6e935bc618403192b82b5dcc0.tar.xz |
(svn r20924) -Codechange: make the game connection packet handling look more like UDP/content packet handling
Diffstat (limited to 'src/network/core/tcp_game.h')
-rw-r--r-- | src/network/core/tcp_game.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index 77da6218c..f083396e8 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -27,7 +27,7 @@ * it protects old clients from joining newer servers * (because SERVER_ERROR is the respond to a wrong revision) */ -enum TCPPacketType { +enum PacketGameType { PACKET_SERVER_FULL, PACKET_SERVER_BANNED, PACKET_CLIENT_JOIN, @@ -113,12 +113,59 @@ typedef NetworkGameSocketHandler NetworkClientSocket; typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientSocketPool; extern NetworkClientSocketPool _networkclientsocket_pool; +#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 NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkTCPSocketHandler { /* TODO: rewrite into a proper class */ private: NetworkClientInfo *info; ///< Client info related to this socket + protected: + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FULL); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_BANNED); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_JOIN); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_INFO); + 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_CLIENT_GAME_PASSWORD); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WELCOME); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MAP); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK); + 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_CLIENT_ACK); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMMAND); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_CHAT); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_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_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_CLIENT_RCON); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MOVE); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_CLIENT_MOVE); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_UPDATE); + DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CONFIG_UPDATE); + + NetworkRecvStatus HandlePacket(Packet *p); + NetworkGameSocketHandler(SOCKET s); public: ClientID client_id; ///< Client identifier @@ -137,6 +184,8 @@ public: inline void SetInfo(NetworkClientInfo *info) { assert(info != NULL && this->info == NULL); this->info = info; } inline NetworkClientInfo *GetInfo() const { return this->info; } + NetworkRecvStatus Recv_Packets(); + const char *Recv_Command(Packet *p, CommandPacket *cp); void Send_Command(Packet *p, const CommandPacket *cp); }; |