2014-01-28 09:00:02 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "..\GameClient.h"
|
|
|
|
#include <NetworkSession.h>
|
|
|
|
#include <Protocols.h>
|
|
|
|
|
|
|
|
using namespace Utility::DynamicMemory;
|
2014-01-29 10:18:01 +01:00
|
|
|
using namespace Oyster::Network;
|
2014-01-28 09:00:02 +01:00
|
|
|
using namespace DanBias;
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
|
|
|
|
2014-02-18 11:34:24 +01:00
|
|
|
GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> nwClient)
|
2014-01-28 09:00:02 +01:00
|
|
|
{
|
2014-02-20 08:33:07 +01:00
|
|
|
this->isInvalid = false;
|
|
|
|
this->failedPackagesCount = 0;
|
2014-02-18 11:34:24 +01:00
|
|
|
this->client = nwClient;
|
2014-02-18 08:55:38 +01:00
|
|
|
this->player = 0;
|
2014-02-27 11:41:17 +01:00
|
|
|
this->isReady = false;
|
2014-02-21 12:38:25 +01:00
|
|
|
this->character = L"char_orca.dan";
|
2014-02-18 08:55:38 +01:00
|
|
|
this->alias = L"Unknown";
|
|
|
|
this->secondsSinceLastResponse = 0.0f;
|
2014-01-28 09:00:02 +01:00
|
|
|
}
|
|
|
|
GameClient::~GameClient()
|
|
|
|
{
|
2014-02-27 11:41:17 +01:00
|
|
|
this->client->Disconnect();
|
2014-02-26 14:55:29 +01:00
|
|
|
if(this->player)
|
|
|
|
{
|
|
|
|
this->player->Inactivate();
|
|
|
|
}
|
2014-02-27 11:41:17 +01:00
|
|
|
|
2014-02-18 08:55:38 +01:00
|
|
|
this->isReady = false;
|
2014-02-21 12:38:25 +01:00
|
|
|
this->character = L"char_orca.dan";
|
2014-02-18 08:55:38 +01:00
|
|
|
this->alias = L"Unknown";
|
|
|
|
this->secondsSinceLastResponse = 0.0f;
|
2014-02-20 16:52:36 +01:00
|
|
|
this->client = 0;
|
|
|
|
this->player = 0;
|
2014-01-28 09:00:02 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 08:55:38 +01:00
|
|
|
void GameClient::SetPlayer(GameLogic::IPlayerData* player)
|
2014-01-28 09:00:02 +01:00
|
|
|
{
|
2014-02-18 08:55:38 +01:00
|
|
|
this->player = player;
|
2014-01-31 08:41:08 +01:00
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
void GameClient::SetReadyState(bool r)
|
|
|
|
{
|
|
|
|
this->isReady = r;
|
|
|
|
}
|
|
|
|
void GameClient::SetSinceLastResponse(float s)
|
|
|
|
{
|
|
|
|
this->secondsSinceLastResponse = s;
|
|
|
|
}
|
2014-02-18 08:55:38 +01:00
|
|
|
void GameClient::SetAlias(std::wstring alias)
|
|
|
|
{
|
|
|
|
this->alias = alias;
|
|
|
|
}
|
|
|
|
void GameClient::SetCharacter(std::wstring character)
|
|
|
|
{
|
|
|
|
this->character = character;
|
|
|
|
}
|
2014-02-18 16:38:08 +01:00
|
|
|
void GameClient::SetState(ClientState state)
|
|
|
|
{
|
|
|
|
this->state = state;
|
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
|
2014-02-20 16:52:36 +01:00
|
|
|
bool GameClient::IsInvalid()
|
|
|
|
{
|
|
|
|
return this->isInvalid;
|
|
|
|
}
|
2014-02-20 08:33:07 +01:00
|
|
|
void GameClient::Invalidate()
|
|
|
|
{
|
2014-02-27 11:41:17 +01:00
|
|
|
GameLogic::IPlayerData* player;
|
|
|
|
this->client->Disconnect();
|
2014-02-20 08:33:07 +01:00
|
|
|
this->isReady = false;
|
2014-02-27 11:41:17 +01:00
|
|
|
this->isInvalid = true; //TODO: Fix this, should be true
|
|
|
|
this->secondsSinceLastResponse = 0.0f;
|
|
|
|
this->failedPackagesCount = 0;
|
|
|
|
this->character = L"char_orca.dan";
|
|
|
|
this->alias = L"Unknown";
|
2014-02-20 08:33:07 +01:00
|
|
|
this->state = ClientState_Invalid;
|
2014-02-27 11:41:17 +01:00
|
|
|
this->player->Release();
|
|
|
|
this->player = 0;
|
2014-02-20 08:33:07 +01:00
|
|
|
}
|
|
|
|
int GameClient::IncrementFailedProtocol()
|
|
|
|
{
|
|
|
|
this->failedPackagesCount++;
|
|
|
|
return this->failedPackagesCount;
|
|
|
|
}
|
|
|
|
void GameClient::ResetFailedProtocolCount()
|
|
|
|
{
|
|
|
|
this->failedPackagesCount = 0;
|
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
|
2014-02-18 11:34:24 +01:00
|
|
|
void GameClient::SetOwner(Oyster::Network::NetworkSession* owner)
|
|
|
|
{
|
|
|
|
this->client->SetOwner(owner);
|
|
|
|
}
|
|
|
|
void GameClient::UpdateClient()
|
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case ClientState_Ready:
|
|
|
|
this->client->Update();
|
|
|
|
break;
|
|
|
|
}
|
2014-02-18 11:34:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IPlayerData* GameClient::ReleasePlayer()
|
|
|
|
{
|
|
|
|
IPlayerData* temp = this->player;
|
|
|
|
this->player = 0;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
NetClient GameClient::ReleaseClient()
|
|
|
|
{
|
|
|
|
NetClient temp = this->client;
|
|
|
|
this->client = 0;
|
|
|
|
return temp;
|
|
|
|
}
|