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

86 lines
1.7 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
{
2013-12-17 14:15:20 +01:00
while (!ClientListLock.try_lock()); //Possible Deadlock
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.size(); i++)
2013-12-13 23:47:16 +01:00
{
if(!this->clients[i])
2013-12-17 14:15:20 +01:00
k = i;
}
if(k == -1)
{
this->clients.push_back(client);
this->clients[this->clients.size() - 1]->SetPostbox(&this->box);
}
else
{
this->clients[k]->SetPostbox(&this->box);
2013-12-13 23:47:16 +01:00
}
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)
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
this->clients[i] = 0;
}
}
void NetworkSession::DetachClient(ClientObject* client)
{
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-12 09:33:59 +01:00
void NetworkSession::DetachClient(short ID)
{
2013-12-16 09:00:11 +01:00
for (unsigned int i = 0; i < this->clients.size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == ID)
this->clients[i] = 0;
}
2013-12-12 09:33:59 +01:00
}
void NetworkSession::DetachClient()
2013-12-12 09:33:59 +01:00
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
this->clients[i] = 0;
}
2013-12-12 09:33:59 +01:00
}
2013-12-12 09:33:59 +01:00
void NetworkSession::Kick()
{
for (unsigned int i = 0; i < this->clients.size(); i++)
{
this->clients[i]->NetClient_Object()->Disconnect();
this->clients[i] = 0;
}
2013-12-12 09:33:59 +01:00
}
}//End namespace DanBias