(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.

This commit is contained in:
rubidium
2007-01-12 20:19:49 +00:00
parent ee1021d29c
commit f66b373b52
17 changed files with 306 additions and 270 deletions

View File

@@ -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 */