2014-01-07 10:26:09 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "GameClient.h"
|
|
|
|
#include "..\LobbySessions\NetworkSession.h"
|
2014-01-13 12:44:33 +01:00
|
|
|
#include <Game.h>
|
2014-01-14 09:25:22 +01:00
|
|
|
#include <Protocols.h>
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
using namespace Utility::DynamicMemory;
|
|
|
|
using namespace DanBias;
|
2014-01-13 12:44:33 +01:00
|
|
|
using namespace GameLogic;
|
2014-01-07 10:26:09 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
static int gameClientIDCount = 1;
|
|
|
|
|
2014-01-15 11:03:25 +01:00
|
|
|
GameClient::GameClient(SmartPointer<LobbyClient> client, Game::PlayerData* player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
|
2014-01-07 10:26:09 +01:00
|
|
|
{
|
|
|
|
this->callbackValue = value;
|
|
|
|
this->client = client;
|
2014-01-13 12:44:33 +01:00
|
|
|
this->id = gameClientIDCount++;
|
|
|
|
this->player = player;
|
2014-01-07 10:26:09 +01:00
|
|
|
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
|
|
|
|
c.callbackType = Oyster::Callback::CallbackType_Object;
|
|
|
|
c.value = this;
|
|
|
|
this->client->SetCallback(c);
|
|
|
|
|
|
|
|
}
|
|
|
|
GameClient::~GameClient()
|
|
|
|
{
|
2014-01-13 12:44:33 +01:00
|
|
|
if(this->client) this->client->Disconnect();
|
2014-01-15 11:03:25 +01:00
|
|
|
this->player = 0;
|
2014-01-13 12:44:33 +01:00
|
|
|
this->id = -1;
|
2014-01-07 10:26:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
|
|
|
|
{
|
|
|
|
this->callbackValue = value;
|
|
|
|
}
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
GameLogic::Game::PlayerData* GameClient::GetPlayer()
|
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
return this->player;
|
2014-01-13 12:44:33 +01:00
|
|
|
}
|
2014-01-15 11:03:25 +01:00
|
|
|
GameLogic::Game::PlayerData* GameClient::ReleasePlayer()
|
2014-01-07 10:26:09 +01:00
|
|
|
{
|
2014-01-15 11:03:25 +01:00
|
|
|
GameLogic::Game::PlayerData *temp = this->player;
|
|
|
|
this->player = 0;
|
2014-01-13 12:44:33 +01:00
|
|
|
return temp;
|
2014-01-07 10:26:09 +01:00
|
|
|
}
|
2014-01-13 12:44:33 +01:00
|
|
|
LobbyClient* GameClient::GetClient() const
|
2014-01-07 10:26:09 +01:00
|
|
|
{
|
|
|
|
return this->client;
|
|
|
|
}
|
2014-01-13 12:44:33 +01:00
|
|
|
Utility::DynamicMemory::SmartPointer<LobbyClient> GameClient::ReleaseClient()
|
|
|
|
{
|
|
|
|
SmartPointer<LobbyClient> temp = this->client;
|
|
|
|
this->client = 0;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
int GameClient::GetID() const
|
|
|
|
{
|
|
|
|
return this->id;
|
|
|
|
}
|
2014-01-07 10:26:09 +01:00
|
|
|
void GameClient::ObjectCallback(NetworkSession::NetEvent e)
|
|
|
|
{
|
|
|
|
e.gameClient = this;
|
|
|
|
this->callbackValue(e);
|
|
|
|
}
|