Danbias/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp

109 lines
2.1 KiB
C++
Raw Normal View History

2013-12-16 09:00:11 +01:00
2013-12-13 23:47:16 +01:00
#include "ClientObject.h"
2013-12-12 09:33:59 +01:00
#include "NetworkSession.h"
#include <mutex>
2013-12-12 09:33:59 +01:00
2013-12-17 14:15:20 +01:00
static std::mutex ClientListLock;
2013-12-12 09:33:59 +01:00
namespace DanBias
{
NetworkSession::NetworkSession()
{
2013-12-12 09:33:59 +01:00
}
NetworkSession::~NetworkSession()
{
2013-12-12 09:33:59 +01:00
}
2013-12-13 23:47:16 +01:00
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client)
2013-12-12 09:33:59 +01:00
{
ClientListLock.lock();
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.size(); i++)
{
if(!this->clients[i])
k = i;
}
if(k == -1)
{
this->clients.push_back(client);
2013-12-18 08:44:10 +01:00
this->clients[this->clients.size() - 1]->SetPostbox(this->box);
}
else
{
2013-12-18 08:44:10 +01:00
this->clients[k]->SetPostbox(this->box);
}
2013-12-17 14:15:20 +01:00
ClientListLock.unlock();
2013-12-12 09:33:59 +01:00
}
2013-12-16 09:00:11 +01:00
void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
{
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
this->clients[i] = 0;
}
ClientListLock.unlock();
2013-12-16 09:00:11 +01:00
}
void NetworkSession::DetachClient(ClientObject* client)
{
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id())
this->clients[i] = 0;
}
2013-12-16 09:00:11 +01:00
ClientListLock.unlock();
2013-12-16 09:00:11 +01:00
}
2013-12-12 09:33:59 +01:00
void NetworkSession::DetachClient(short ID)
{
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == ID)
this->clients[i] = 0;
}
ClientListLock.unlock();
2013-12-12 09:33:59 +01:00
}
void NetworkSession::DetachClient()
2013-12-12 09:33:59 +01:00
{
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.size(); i++)
{
this->clients[i] = 0;
}
ClientListLock.unlock();
2013-12-12 09:33:59 +01:00
}
2013-12-12 09:33:59 +01:00
void NetworkSession::Kick()
{
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.size(); i++)
{
this->clients[i]->NetClient_Object()->Disconnect();
this->clients[i] = 0;
}
ClientListLock.unlock();
}
void NetworkSession::SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{
this->box = box;
2013-12-12 09:33:59 +01:00
}
}//End namespace DanBias