2013-12-12 09:33:59 +01:00
|
|
|
#ifndef DANBIASSERVER_GAME_SESSION_H
|
|
|
|
#define DANBIASSERVER_GAME_SESSION_H
|
|
|
|
|
|
|
|
#include "NetworkSession.h"
|
2013-12-18 13:07:10 +01:00
|
|
|
#include <PostBox\IPostBox.h>
|
|
|
|
#include <Thread\OysterThread.h>
|
2013-12-12 09:33:59 +01:00
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
2013-12-18 13:07:10 +01:00
|
|
|
class ClientObject;
|
|
|
|
class GameSession :private NetworkSession, public Oyster::Thread::IThreadObject
|
2013-12-12 09:33:59 +01:00
|
|
|
{
|
2013-12-18 13:07:10 +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-18 13:07:10 +01:00
|
|
|
};
|
|
|
|
|
2013-12-12 09:33:59 +01:00
|
|
|
public:
|
|
|
|
GameSession();
|
2013-12-18 13:07:10 +01:00
|
|
|
virtual~GameSession();
|
|
|
|
|
2013-12-19 12:32:23 +01:00
|
|
|
void Run(GameSessionDescription& desc);
|
2013-12-18 13:07:10 +01:00
|
|
|
|
2013-12-19 12:32:23 +01:00
|
|
|
void Join(Utility::DynamicMemory::SmartPointer<ClientObject> client);
|
2013-12-18 13:07:10 +01:00
|
|
|
|
|
|
|
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;
|
2013-12-18 13:07:10 +01:00
|
|
|
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;
|
2013-12-18 13:07:10 +01:00
|
|
|
bool DoWork ( ) override;
|
|
|
|
|
|
|
|
private:
|
2013-12-19 12:32:23 +01:00
|
|
|
bool Init(GameSessionDescription& desc);
|
2013-12-18 13:07:10 +01:00
|
|
|
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:
|
2013-12-18 13:07:10 +01:00
|
|
|
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
|