2014-01-07 10:26:09 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2014-01-28 09:00:02 +01:00
|
|
|
#include "..\GameSessionManager.h"
|
|
|
|
#include "..\GameSession.h"
|
2014-01-07 10:26:09 +01:00
|
|
|
#include <DynamicArray.h>
|
|
|
|
|
|
|
|
using namespace DanBias;
|
|
|
|
using namespace Utility::DynamicMemory;
|
|
|
|
|
|
|
|
struct GameSessionData
|
|
|
|
{
|
|
|
|
DynamicArray< SmartPointer< GameSession > > sessions;
|
|
|
|
|
|
|
|
int freeSpot;
|
|
|
|
|
|
|
|
int Existst(int session)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < sessions.Size(); i++)
|
|
|
|
{
|
|
|
|
if(!sessions[i] && freeSpot == -1) freeSpot = i;
|
|
|
|
if(sessions[i]->GetID() == session) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int GetFree()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < sessions.Size(); i++)
|
|
|
|
{
|
|
|
|
if(!sessions[i])
|
|
|
|
{
|
|
|
|
this->freeSpot = i;
|
|
|
|
return this->freeSpot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->freeSpot = -1;
|
|
|
|
return this->freeSpot;
|
|
|
|
}
|
|
|
|
|
|
|
|
} gameSessionData;
|
|
|
|
|
|
|
|
|
|
|
|
int GameSessionManager::AddSession(GameSessionDescription& instance, bool run)
|
|
|
|
{
|
|
|
|
int k = gameSessionData.GetFree();
|
|
|
|
|
|
|
|
SmartPointer<GameSession> gs = new GameSession();
|
|
|
|
|
|
|
|
DanBias::GameSession::GameDescription desc;
|
|
|
|
desc.owner = instance.exitDestionation;
|
|
|
|
desc.clients = instance.clients;
|
|
|
|
desc.mapName = instance.mapName;
|
|
|
|
|
|
|
|
|
|
|
|
if(!gs->Create(desc)) return 0;
|
|
|
|
|
|
|
|
if(k == -1) gameSessionData.sessions.Push(gs);
|
|
|
|
else gameSessionData.sessions[k] = gs;
|
|
|
|
|
|
|
|
if(run) gs->Run();
|
|
|
|
|
|
|
|
return gs->GetID();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GameSessionManager::StartSession(int session)
|
|
|
|
{
|
|
|
|
int i = -1;
|
|
|
|
if((i = gameSessionData.Existst(session)) != -1) return false;
|
|
|
|
|
|
|
|
gameSessionData.sessions[i]->Run();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer<NetworkSession> client)
|
2014-01-07 10:26:09 +01:00
|
|
|
{
|
|
|
|
int i = -1;
|
2014-01-09 14:18:01 +01:00
|
|
|
if((i = gameSessionData.Existst(session)) == -1) return false;
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
gameSessionData.sessions[i]->Join(client);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameSessionManager::GetSessionInfo(int session, GameSessionInfo& data)
|
|
|
|
{
|
|
|
|
memset(&data, 0, sizeof(GameSessionInfo));
|
|
|
|
|
|
|
|
int i = -1;
|
|
|
|
if((i = gameSessionData.Existst(session)) != -1) return;
|
|
|
|
|
|
|
|
//data.gametime = gameSessionData.sessions[i]->
|
|
|
|
//data.mapName = gameSessionData.sessions[i]->
|
|
|
|
//data.numberOfPlayers = gameSessionData.sessions[i]->
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
void GameSessionManager::CloseSessions()
|
2014-01-09 14:18:01 +01:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < gameSessionData.sessions.Size(); i++)
|
|
|
|
{
|
|
|
|
gameSessionData.sessions[i]->CloseSession();
|
|
|
|
}
|
|
|
|
}
|
2014-01-07 10:26:09 +01:00
|
|
|
void GameSessionManager::CloseSession(int session)
|
|
|
|
{
|
|
|
|
int i = -1;
|
|
|
|
if((i = gameSessionData.Existst(session)) != -1) return;
|
|
|
|
|
|
|
|
|
|
|
|
gameSessionData.sessions[i]->CloseSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
int GameSessionManager::GetSessionSize()
|
|
|
|
{
|
|
|
|
return gameSessionData.sessions.Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|