///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// #ifndef DANBIASSERVER_NETWORK_SESSION_H #define DANBIASSERVER_NETWORK_SESSION_H //warning C4150: deletion of pointer to incomplete type, no destructor called #pragma warning(disable : 4150) #define NOMINMAX #include "INetworkSession.h" #include #include #include #include #include #include #include #include namespace DanBias { class LobbyClient; class GameClient; class NetworkSession :public INetworkSession { public: struct NetEvent { LobbyClient* sender; GameClient* gameClient; Oyster::Network::CustomNetProtocol protocol; NetEvent():sender(0), gameClient(0){} }; public: NetworkSession(); NetworkSession(const NetworkSession& orig); const NetworkSession& operator=(const NetworkSession& orig); virtual~NetworkSession(); virtual bool Attach(Utility::DynamicMemory::SmartPointer client); virtual Utility::DynamicMemory::SmartPointer Detach(Oyster::Network::NetworkClient* client); virtual Utility::DynamicMemory::SmartPointer Detach(const LobbyClient* client); virtual Utility::DynamicMemory::SmartPointer Detach(const LobbyClient& client); virtual Utility::DynamicMemory::SmartPointer Detach(short ID); Utility::DynamicMemory::SmartPointer FindClient(LobbyClient& obj); Utility::DynamicMemory::SmartPointer FindClient(LobbyClient* obj); Utility::DynamicMemory::SmartPointer FindClient(int ID); /** * Sends a message to all clients in this session. */ virtual bool Send(Oyster::Network::CustomNetProtocol& message); /** * Sends a message to a specific client in this session. */ virtual bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID); /** * Set the callback to all clients to where a messages is recieved. */ virtual void SetCallback(Oyster::Callback::OysterCallback value); /** * Closes the session and sends the clients to given owner session if any. * If session is null, clients is assumed to already be elsewhere and only releases a reference. */ virtual void CloseSession(bool dissconnectClients = false); /** Set where the clients is returned on closed session. */ inline void SetOwner(NetworkSession* owner) { this->owner = owner; } protected: Utility::DynamicMemory::DynamicArray> clients; NetworkSession* owner; //Where clients end up when session is closed. private: std::mutex clientListLock; int clientCount; private: friend class AdminInterface; }; }//End namespace DanBias #endif // !DANBIASSERVER_NETWORK_SESSION_H