diff -r d983df942a05 -r 6afe9d27430a src/network/core/tcp.h --- a/src/network/core/tcp.h Fri Jan 12 18:32:39 2007 +0000 +++ b/src/network/core/tcp.h Fri Jan 12 20:19:49 2007 +0000 @@ -6,6 +6,7 @@ #ifdef ENABLE_NETWORK #include "os_abstraction.h" +#include "core.h" #include "packet.h" /** @@ -54,9 +55,54 @@ PACKET_END ///< Must ALWAYS be on the end of this list!! (period) }; -void NetworkSend_Packet(Packet *packet, NetworkClientState *cs); -Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status); -bool NetworkSend_Packets(NetworkClientState *cs); +typedef struct CommandPacket { + struct CommandPacket *next; + PlayerByte player; ///< player that is executing the command + uint32 cmd; ///< command being executed + uint32 p1; ///< parameter p1 + uint32 p2; ///< parameter p2 + TileIndex tile; ///< tile command being executed on + char text[80]; + uint32 frame; ///< the frame in which this packet is executed + byte callback; ///< any callback function executed upon successful completion of the command +} CommandPacket; + +typedef enum { + STATUS_INACTIVE, ///< The client is not connected nor active + STATUS_AUTH, ///< The client is authorized + STATUS_MAP_WAIT, ///< The client is waiting as someone else is downloading the map + STATUS_MAP, ///< The client is downloading the map + STATUS_DONE_MAP, ///< The client has downloaded the map + STATUS_PRE_ACTIVE, ///< The client is catching up the delayed frames + STATUS_ACTIVE, ///< The client is an active player in the game +} ClientStatus; + +/** Base socket handler for all TCP sockets */ +class NetworkTCPSocketHandler : public NetworkSocketHandler { +/* TODO: rewrite into a proper class */ +public: + uint16 index; + uint32 last_frame; + uint32 last_frame_server; + byte lag_test; // This byte is used for lag-testing the client + + ClientStatus status; + bool writable; // is client ready to write to? + + Packet *packet_queue; // Packets that are awaiting delivery + Packet *packet_recv; // Partially received packet + + CommandPacket *command_queue; // The command-queue awaiting delivery + + NetworkRecvStatus CloseConnection(); + void Initialize(); +}; + + + +void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs); +Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *status); +bool NetworkSend_Packets(NetworkTCPSocketHandler *cs); #endif /* ENABLE_NETWORK */