/* $Id: servercommunicator.hpp,v 1.4 2005/12/04 22:44:49 chfreund Exp $ */ #ifndef _SERVERCOMMUNICATOR_HPP_ #define _SERVERCOMMUNICATOR_HPP_ #include #include #include #include "message.hpp" #include "tcpconnection.hpp" class ClientConnection; class ClientConnectionDirect; class ClientConnectionListener; class ServerConnectionDirect; class GameReplay; // Zentrale Klasse für die Verwaltung aller Verbindungen // auf dem Server //! Class for the management of connections on the server /*! Client connections can be idle or active. Idle clients have not * received the world, therefore the exchange of event/echo messages * is not necessary. Once a client requests the world, its connection * gets active and will be included in the event/echo mechanism. */ class ServerCommunicator : public TCPProgressListener { private: //! Vector of listener objects std::vector m_listeners; //! Vector of idle connections std::vector m_idleConnections; //! Vector of active connections std::vector m_activeConnections; //! A direct connection object for a local client ServerConnectionDirect* m_directConnection; //! List with free client IDs std::deque m_freeClientIDs; //! An echo message EchoMessage m_echoMessage; //! The server world World* m_world; //! A message counter Uint32 m_frameSequenceCounter; //! The game replay GameReplay* m_replay; public: //! Constructor //! \param world The server world ServerCommunicator( World* world, GameReplay* replay = 0 ); //! Destructor ~ServerCommunicator(); //! Listen for new client connections void listenForClients(); //! Collect events from active clients void collectEvents(); //! Broadcast echo to active clients void broadcastEcho(); //! Handle incoming messages from all clients void handleMessages(); //! Add a new connection Uint8 addConnection( ClientConnection* connection ); //! Get the direct connection object ClientConnectionDirect* getDirectConnection ( ServerConnectionDirect* serverConnection ); //! Get the current echo message EchoMessage getEchoMessage() const { return m_echoMessage; } //! Get the world World* getWorld() { return m_world; } //! Callback for message sending progress notification void sendProgress( Sint32 size, Sint32 sent ); void recvProgress( Sint32 size, Sint32 received ); private: //! Broadcast a message to all clients void broadcastMessage( Message* message ); //! Cleanup a closed/lost connection void cleanupConnection( ClientConnection* connection ); }; #endif // _SERVERCOMMUNICATOR_HPP_