Danbias/Code/Game/DanBiasServer/ServerObjects/GameSession.h

57 lines
1.9 KiB
C
Raw Normal View History

2013-12-12 09:33:59 +01:00
#ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H
#include "NetworkSession.h"
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
2013-12-12 09:33:59 +01:00
namespace DanBias
{
class ClientObject;
class GameSession :private NetworkSession, public Oyster::Thread::IThreadObject
2013-12-12 09:33:59 +01:00
{
public:
struct GameSessionDescription
{
NetworkSession* owner;
2013-12-19 12:32:23 +01:00
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
};
2013-12-12 09:33:59 +01:00
public:
GameSession();
virtual~GameSession();
2013-12-19 12:32:23 +01:00
void Run(GameSessionDescription& desc);
2013-12-19 12:32:23 +01:00
void Join(Utility::DynamicMemory::SmartPointer<ClientObject> client);
private: //overriden NetworkSession functions
void Close();
2013-12-19 12:32:23 +01:00
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(Oyster::Network::NetworkClient* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(ClientObject* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(short ID) override;
void Send(Oyster::Network::CustomNetProtocol& protocol) override;
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override;
void SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box) override;
void CloseSession(NetworkSession* clientDestination) override;
private: //overriden Threading functions
2013-12-19 12:32:23 +01:00
void ThreadEntry( ) override;
void ThreadExit( ) override;
bool DoWork ( ) override;
private:
2013-12-19 12:32:23 +01:00
bool Init(GameSessionDescription& desc);
void Frame();
void ParseEvents();
2013-12-19 12:32:23 +01:00
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c);
2013-12-12 09:33:59 +01:00
private:
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
2013-12-12 09:33:59 +01:00
};//End GameSession
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_SESSION_H