(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 473ed1d351
commit 98e462e564
17 changed files with 306 additions and 270 deletions

View File

@@ -6,11 +6,11 @@
#ifdef ENABLE_NETWORK
#include "os_abstraction.h"
#include "core.h"
#include "game.h"
#include "packet.h"
#include "../../newgrf_config.h"
#include "../../debug.h"
#include "../network_data.h"
/**
* @file udp.h Basic functions to receive and send UDP packets.
@@ -91,11 +91,11 @@ enum PacketUDPType {
#define DECLARE_UDP_RECEIVE_COMMAND(type) virtual void NetworkPacketReceive_## type ##_command(Packet *p, const struct sockaddr_in *)
class NetworkUDPSocketHandler {
private:
SOCKET udp;
/** Base socket handler for all UDP sockets */
class NetworkUDPSocketHandler : public NetworkSocketHandler {
protected:
NetworkClientState cs;
NetworkRecvStatus CloseConnection();
/* Declare all possible packets here. If it can be received by the
* a specific handler, it has to be implemented. */
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER);
@@ -121,10 +121,8 @@ protected:
*/
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); }
public:
NetworkUDPSocketHandler();
virtual ~NetworkUDPSocketHandler() { this->Close(); }
bool IsListening() { return this->udp != INVALID_SOCKET; }
bool Listen(uint32 host, uint16 port, bool broadcast);
void Close();