///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// #ifndef DANBIASSERVER_GAME_SESSION_H #define DANBIASSERVER_GAME_SESSION_H //warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer. #pragma warning(disable: 4150) #include "..\LobbySessions\NetworkSession.h" #include #include #include #include namespace DanBias { class LobbyClient; class GameClient; class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession { public: /** * A container to use when initiating a new session */ struct GameDescription { std::wstring mapName; NetworkSession* owner; Utility::DynamicMemory::DynamicArray> clients; }; public: GameSession(); virtual~GameSession(); /** Initiates and creates a game session. */ bool Create(GameDescription& desc); /** Runs the game session (ie starts the game loop). */ void Run(); /** Join an existing/running game session * @param client The client to attach to the session */ bool Join(Utility::DynamicMemory::SmartPointer client); /** * Closes the game session * @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session. */ void CloseSession(bool disconnectClients = false); inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } //Private member functions private: //Handles all events recieved void ParseEvents(); //Handles all gameplay events void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); //Handles all general events void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); //Adds a client to the client list void AddClient(Utility::DynamicMemory::SmartPointer obj); //Removes a client from the client list void RemoveClient(DanBias::GameClient* obj); //Sends a protocol ta all clients in session void Send(Oyster::Network::CustomNetProtocol* p); //Frame function, derived from IThreadObject bool DoWork ( ) override; //Sends a client to the owner, if obj is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); //Do a cleanup on all the private data void Clean(); //Private member variables private: Utility::DynamicMemory::DynamicArray> clients; Oyster::IPostBox *box; Oyster::Thread::OysterThread worker; GameLogic::Game gameInstance; NetworkSession* owner; Utility::WinTimer timer; bool isCreated; bool isRunning; private: friend class AdminInterface; };//End GameSession }//End namespace DanBias #endif // !DANBIASSERVER_GAME_SESSION_H