/* $Id: clientcommunicator.hpp,v 1.5 2005/12/04 22:44:48 chfreund Exp $ */ #ifndef _CLIENTCOMMUNICATOR_HPP_ #define _CLIENTCOMMUNICATOR_HPP_ #include // #include #include #include #include "event.hpp" #include "string.hpp" #include "message.hpp" #include "playerinput.hpp" #include "serverconnectionfactory.hpp" #include "tcpconnection.hpp" class ServerConnection; class World; class Player; struct ServerEntry; class Client; //! Class the handles the connection to a server on the client class ClientCommunicator : public TCPProgressListener { private: //! The client using this communicator Client* m_client; //! The unique ID identifying this client on the server Uint8 m_clientID; //! List of all players that are connected through this client with the server std::vector m_player; //! Handles for querying events of all players std::vector m_playerInput; //! A factory for creating remote connections ServerConnectionFactory m_serverConnectionFactory; //! The connection to the server ServerConnection* m_serverConnection; //! A UDP socket UDPsocket m_baitSocket; //! A UDP packet UDPpacket* m_baitPacket; //! Storage for the last message to be processed Message* m_lastMessage; //! The world handled by this communicator World* m_world; //! A timer for the frequent actions to be done every frame SDL_TimerID m_frameTimer; //! A mutex SDL_mutex* m_mutex; //! A condition variable SDL_cond* m_cond; Player* m_waitingPlayer; public: //! Constructor ClientCommunicator( Client* client ); //! Destructor ~ClientCommunicator(); //! Open a connection to a server bool openConnection( ServerEntry& server ); //! Close active connection void closeConnection(); //! Get the connection state bool isConnected() { return m_serverConnection != 0; } //! Add a local player void addPlayer( Player* player, PlayerInput* input ); //! Remove a local player void removePlayer( Player* player ); //! Process echo messages void processEchos(); //! Process event messages void processEvents(); //! Make the connection active void setActive(); //! Get the world World* getWorld() { return m_world; } //! Callback function for the frame timer static Uint32 frameHandler( Uint32 interval, void* data ); //! Send a chat message void sendChatMessage( String& message, const SDL_Color& color ); //! Look for running servers std::vector lookForServers(); //! Get information about the current server InfoMessage* getServerInfo(); void sendProgress( Sint32 size, Sint32 sent ) { } void recvProgress( Sint32 size, Sint32 received ); private: //! Get the local player number for a player Uint8 getPlayerNumber( Player* player ) const; }; #endif // _CLIENTCOMMUNICATOR_HPP_