diff options
author | rubidium <rubidium@openttd.org> | 2007-01-12 20:19:49 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-01-12 20:19:49 +0000 |
commit | f66b373b52b2daef69507c402577a1a02b65c40b (patch) | |
tree | 23bff1b129004614fd68cb0c30436a14bbe240e9 /src/network/core/tcp.h | |
parent | ee1021d29c6baa6380faf17e270fd5194d2b330c (diff) | |
download | openttd-f66b373b52b2daef69507c402577a1a02b65c40b.tar.xz |
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
Diffstat (limited to 'src/network/core/tcp.h')
-rw-r--r-- | src/network/core/tcp.h | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index ab5c9b8e0..c15f851aa 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -6,6 +6,7 @@ #ifdef ENABLE_NETWORK #include "os_abstraction.h" +#include "core.h" #include "packet.h" /** @@ -54,9 +55,54 @@ enum { 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 */ |