src/network/core/tcp.h
changeset 5624 6afe9d27430a
parent 5527 7a624281971a
child 5864 a95a2849b0e1
equal deleted inserted replaced
5623:d983df942a05 5624:6afe9d27430a
     4 #define NETWORK_CORE_TCP_H
     4 #define NETWORK_CORE_TCP_H
     5 
     5 
     6 #ifdef ENABLE_NETWORK
     6 #ifdef ENABLE_NETWORK
     7 
     7 
     8 #include "os_abstraction.h"
     8 #include "os_abstraction.h"
       
     9 #include "core.h"
     9 #include "packet.h"
    10 #include "packet.h"
    10 
    11 
    11 /**
    12 /**
    12  * @file tcp.h Basic functions to receive and send TCP packets.
    13  * @file tcp.h Basic functions to receive and send TCP packets.
    13  */
    14  */
    52 	PACKET_SERVER_RCON,
    53 	PACKET_SERVER_RCON,
    53 	PACKET_CLIENT_RCON,
    54 	PACKET_CLIENT_RCON,
    54 	PACKET_END                   ///< Must ALWAYS be on the end of this list!! (period)
    55 	PACKET_END                   ///< Must ALWAYS be on the end of this list!! (period)
    55 };
    56 };
    56 
    57 
    57 void NetworkSend_Packet(Packet *packet, NetworkClientState *cs);
    58 typedef struct CommandPacket {
    58 Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status);
    59 	struct CommandPacket *next;
    59 bool NetworkSend_Packets(NetworkClientState *cs);
    60 	PlayerByte player; ///< player that is executing the command
       
    61 	uint32 cmd;        ///< command being executed
       
    62 	uint32 p1;         ///< parameter p1
       
    63 	uint32 p2;         ///< parameter p2
       
    64 	TileIndex tile;    ///< tile command being executed on
       
    65 	char text[80];
       
    66 	uint32 frame;      ///< the frame in which this packet is executed
       
    67 	byte callback;     ///< any callback function executed upon successful completion of the command
       
    68 } CommandPacket;
       
    69 
       
    70 typedef enum {
       
    71 	STATUS_INACTIVE,   ///< The client is not connected nor active
       
    72 	STATUS_AUTH,       ///< The client is authorized
       
    73 	STATUS_MAP_WAIT,   ///< The client is waiting as someone else is downloading the map
       
    74 	STATUS_MAP,        ///< The client is downloading the map
       
    75 	STATUS_DONE_MAP,   ///< The client has downloaded the map
       
    76 	STATUS_PRE_ACTIVE, ///< The client is catching up the delayed frames
       
    77 	STATUS_ACTIVE,     ///< The client is an active player in the game
       
    78 } ClientStatus;
       
    79 
       
    80 /** Base socket handler for all TCP sockets */
       
    81 class NetworkTCPSocketHandler : public NetworkSocketHandler {
       
    82 /* TODO: rewrite into a proper class */
       
    83 public:
       
    84 	uint16 index;
       
    85 	uint32 last_frame;
       
    86 	uint32 last_frame_server;
       
    87 	byte lag_test; // This byte is used for lag-testing the client
       
    88 
       
    89 	ClientStatus status;
       
    90 	bool writable; // is client ready to write to?
       
    91 
       
    92 	Packet *packet_queue; // Packets that are awaiting delivery
       
    93 	Packet *packet_recv; // Partially received packet
       
    94 
       
    95 	CommandPacket *command_queue; // The command-queue awaiting delivery
       
    96 
       
    97 	NetworkRecvStatus CloseConnection();
       
    98 	void Initialize();
       
    99 };
       
   100 
       
   101 
       
   102 
       
   103 void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs);
       
   104 Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *status);
       
   105 bool NetworkSend_Packets(NetworkTCPSocketHandler *cs);
    60 
   106 
    61 #endif /* ENABLE_NETWORK */
   107 #endif /* ENABLE_NETWORK */
    62 
   108 
    63 #endif /* NETWORK_CORE_TCP_H */
   109 #endif /* NETWORK_CORE_TCP_H */