diff options
Diffstat (limited to 'src/connectionhandler.h')
-rw-r--r-- | src/connectionhandler.h | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/src/connectionhandler.h b/src/connectionhandler.h index d56fc09d..1b4e8036 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -59,6 +59,7 @@ class ClientData class ConnectionHandler { public: + virtual ~ConnectionHandler() {} /** * Open the server socket. @@ -77,33 +78,66 @@ class ConnectionHandler void process(); /** - * Called when a computer connects to a network session. + * Called when a computer sends a packet to the network session. */ - void computerConnected(NetComputer *computer); + //void receivePacket(NetComputer *computer, Packet *packet); /** - * Called when a computer reconnects to a network session. + * Registers a message handler to handle a certain message type. */ - //void computerReconnected(NetComputer *computer); + void registerHandler(unsigned int msgId, MessageHandler *handler); /** - * Called when a computer disconnects from a network session. - * - * <b>Note:</b> After returning from this method the NetComputer - * reference is no longer guaranteed to be valid. + * Send packet to every client, used for announcements. */ - void computerDisconnected(NetComputer *computer); + void sendToEveryone(MessageOut &); /** - * Called when a computer sends a packet to the network session. + * Return the number of connected clients. */ - //void receivePacket(NetComputer *computer, Packet *packet); + unsigned int getClientNumber(); + + private: + ENetAddress address; /**< Includes the port to listen to. */ + ENetHost *host; /**< The host that listen for connections. */ + + typedef std::map< unsigned int, MessageHandler * > HandlerMap; + HandlerMap handlers; + protected: /** - * Registers a message handler to handle a certain message type. + * Called when a computer connects to the server. Initialize + * an object derived of NetComputer. */ - void registerHandler(unsigned int msgId, MessageHandler *handler); + virtual NetComputer *computerConnected(ENetPeer *) = 0; + + /** + * Called when a computer reconnects to the server. + */ + //virtual NetComputer *computerReconnected(ENetPeer *) = 0; + + /** + * Called when a computer disconnects from the server. + * + * <b>Note:</b> After returning from this method the NetComputer + * reference is no longer guaranteed to be valid. + */ + virtual void computerDisconnected(NetComputer *) = 0; + typedef std::list<NetComputer*> NetComputers; + /** + * A list of pointers to the client structures created by + * computerConnected. + */ + NetComputers clients; +}; + +/** + * Temporary placeholder until the connection handlers have been split. + */ +class ClientConnectionHandler: public ConnectionHandler +{ + public: /** * Send packet to client with matching BeingPtr */ @@ -115,11 +149,6 @@ class ConnectionHandler void sendTo(std::string name, MessageOut &); /** - * Send packet to every client, used for announcements. - */ - void sendToEveryone(MessageOut &); - - /** * Send packet to every client around the client on screen. */ void sendAround(tmwserv::BeingPtr, MessageOut &); @@ -130,11 +159,6 @@ class ConnectionHandler void sendInChannel(short channelId, MessageOut &); /** - * Return the number of connected clients. - */ - unsigned int getClientNumber(); - - /** * tells a list of user they're leaving a channel. */ void makeUsersLeaveChannel(const short channelId); @@ -146,17 +170,11 @@ class ConnectionHandler const std::string& userName, const char eventId); - private: - ENetAddress address; /**< Includes the port to listen to. */ - ENetHost *host; /**< The host that listen for connections. */ - - typedef std::map< unsigned int, MessageHandler * > HandlerMap; - HandlerMap handlers; - - typedef std::list<NetComputer*> NetComputers; - NetComputers clients; + protected: + virtual NetComputer *computerConnected(ENetPeer *); + virtual void computerDisconnected(NetComputer *); }; -extern ConnectionHandler *connectionHandler; +extern ClientConnectionHandler *connectionHandler; #endif |