GameServer - Fixed a small error regarding not reaching some data

This commit is contained in:
Dennis Andersen 2014-01-30 11:11:04 +01:00
parent fa29cd7307
commit 05740665da
13 changed files with 179 additions and 136 deletions

View File

@ -72,7 +72,7 @@
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>$(SolutionDir)..\External\Lib\;$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)Game\GameServer\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
@ -80,7 +80,7 @@
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<LibraryPath>$(SolutionDir)..\External\Lib\;$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)Game\GameServer\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
@ -88,7 +88,7 @@
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>$(SolutionDir)..\External\Lib\;$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)Game\GameServer\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
@ -96,7 +96,7 @@
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<LibraryPath>$(SolutionDir)..\External\Lib\;$(SolutionDir)..\Bin\DLL;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include</IncludePath>
<IncludePath>$(SolutionDir)..\External\Include\;$(SolutionDir)Game\GameProtocols\;$(SolutionDir)Network/NetworkAPI;$(IncludePath);C:\Program Files %28x86%29\Visual Leak Detector\include;$(SolutionDir)Game\GameServer\</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -190,6 +190,9 @@
<ProjectReference Include="..\..\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference>
<ProjectReference Include="..\GameServer\GameServer.vcxproj">
<Project>{143bd516-20a1-4890-a3e4-f8bfd02220e7}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="GameClientState\Camera.cpp" />

View File

@ -7,7 +7,7 @@
//--------------------------------------------------------------------------------------
#define NOMINMAX
#include <Windows.h>
#include <
#include "DllInterfaces/GFXAPI.h"
//#include "IGame.h"

View File

@ -13,13 +13,6 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient
// parsing protocols and sending it to the gameState
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{
//if( IsGameplayProtocol(p[protocol_INDEX_ID].value.netShort) )
//ParseGameplayEvent(e.protocol, e.gameClient);
//if( IsGeneralProtocol(p[protocol_INDEX_ID].value.netShort) )
//ParseGeneralEvent(e.protocol, e.gameClient);
int pType = p[0].value.netInt;
switch (pType)
{

View File

@ -335,8 +335,8 @@ void GameState::Protocol( ObjPos* pos )
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
if(i == 2) // playerobj
{
//camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
//camera->UpdateViewMatrix();
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
camera->UpdateViewMatrix();
}
}
}

View File

@ -2,7 +2,7 @@
// Launcher to launch Danbias server //
// Created by [Dennis Andersen] [2013] //
//////////////////////////////////////////////////
#define NOMINMAX //Blame it on windows
#define NOMINMAX //Blame it on microsoft
#include <Windows.h>
#include <vld.h>
#include <iostream>
@ -23,7 +23,9 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
desc.listenPort = 15151;
if(DanBias::GameServerAPI::ServerInitiate(desc) == DanBias::DanBiasServerReturn_Sucess)
{
DanBias::GameServerAPI::ServerStart();
//DanBias::GameServerAPI::GameStart();
while (!(GetAsyncKeyState(0x51))) //Q for exit
{
DanBias::GameServerAPI::ServerUpdate();

View File

@ -92,32 +92,32 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_LobbyJoin :public Oyster::Network::CustomProtocolObject
{
short value;
Protocol_LobbyJoin()
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p)
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
value = p[1].value.netShort;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
protocol[1].value = value;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
//struct Protocol_LobbyJoin :public Oyster::Network::CustomProtocolObject
//{
// short value;
//
// Protocol_LobbyJoin()
// {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// }
// Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p)
// {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// value = p[1].value.netShort;
// }
// Oyster::Network::CustomNetProtocol* GetProtocol() override
// {
// protocol[1].value = value;
// return &protocol;
// }
//
// private:
// Oyster::Network::CustomNetProtocol protocol;
//};
struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject
{
@ -140,7 +140,8 @@ namespace GameLogic
/**
* A protocol that contains all data to send to client when update game lobby
*/
struct Protocol_LobbyGameData :public Oyster::Network::CustomProtocolObject
struct Protocol_LobbyClientData :public Oyster::Network::CustomProtocolObject
{
// Player list
struct PlayerData
@ -150,14 +151,14 @@ namespace GameLogic
};
Utility::DynamicMemory::DynamicArray<PlayerData> list;
Protocol_LobbyGameData()
Protocol_LobbyClientData()
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
list.Reserve(10);
}
Protocol_LobbyGameData(Oyster::Network::CustomNetProtocol& p)
Protocol_LobbyClientData(Oyster::Network::CustomNetProtocol& p)
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
@ -181,32 +182,33 @@ namespace GameLogic
private:
Oyster::Network::CustomNetProtocol protocol;
};
/**
* A protocol that contains all data to send to client when update main lobby
*/
struct Protocol_LobbyMainData :public Oyster::Network::CustomProtocolObject
{
// Game instance list
Protocol_LobbyMainData()
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_MainData;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_LobbyMainData(Oyster::Network::CustomNetProtocol& p)
{
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
//struct Protocol_LobbyMainData :public Oyster::Network::CustomProtocolObject
//{
// // Game instance list
//
// Protocol_LobbyMainData()
// {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_MainData;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
//
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// }
// Protocol_LobbyMainData(Oyster::Network::CustomNetProtocol& p)
// {
//
// }
// Oyster::Network::CustomNetProtocol* GetProtocol() override
// {
// return &protocol;
// }
//
// private:
// Oyster::Network::CustomNetProtocol protocol;
//};
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -12,6 +12,14 @@
namespace DanBias
{
struct LobbyLevelData
{
int mapNumber;
int maxClients;
int gameMode;
int gameTime;
std::string gameName;
};
class GameLobby :public Oyster::Network::NetworkSession
{
public:
@ -20,8 +28,8 @@ namespace DanBias
void Release();
void Update();
void SetGameDesc(const GameSession::GameDescription& desc);
void GetGameDesc(GameSession::GameDescription& desc);
void SetGameDesc(const LobbyLevelData& desc);
void GetGameDesc(LobbyLevelData& desc);
bool StartGameSession();
private:
@ -31,11 +39,11 @@ namespace DanBias
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text:
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
void LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
void LobbyMainData(GameLogic::Protocol_LobbyMainData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:
//void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
private:
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
@ -45,7 +53,7 @@ namespace DanBias
Utility::WinTimer timer;
float refreshFrequency;
GameSession gameSession;
GameSession::GameDescription description;
LobbyLevelData description;
};
}//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H

View File

@ -32,10 +32,8 @@ namespace DanBias
struct GameDescription
{
int mapNumber;
int maxClients;
int gameMode;
int gameTime;
std::string gameName;
Oyster::Network::NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Oyster::Network::NetClient> clients;
};

View File

@ -9,6 +9,7 @@
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
using namespace GameLogic;
namespace DanBias
{
@ -30,17 +31,34 @@ namespace DanBias
this->ProcessClients();
}
void GameLobby::SetGameDesc(const GameSession::GameDescription& desc)
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
{
this->description = desc;
this->description.gameMode = desc.gameMode;
this->description.gameTime = desc.gameTime;
this->description.mapNumber = desc.mapNumber;
this->description.maxClients = desc.maxClients;
}
void GameLobby::GetGameDesc(GameSession::GameDescription& desc)
void GameLobby::GetGameDesc(LobbyLevelData& desc)
{
desc = this->description;
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.maxClients = this->description.maxClients;
}
bool GameLobby::StartGameSession()
{
if(this->gameSession.Create(this->description))
GameSession::GameDescription desc;
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.owner = this;
while (this->GetClientCount())
{
NetClient c;
if((c = this->Detach()))
desc.clients.Push(c);
}
if(this->gameSession.Create(desc))
{
this->gameSession.Run();
return true;
@ -70,6 +88,10 @@ namespace DanBias
{
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
Attach(client);
Protocol_LobbyClientData p;
client->Send(p.GetProtocol());
}
}//End namespace DanBias

View File

@ -17,16 +17,16 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
//break;
case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
break;
case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
break;
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
//break;
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyLogin (p), c);
break;
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break;
case protocol_Lobby_MainData: this->LobbyMainData (Protocol_LobbyMainData (p), c);
break;
case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
case protocol_Lobby_MainData: this->LobbyMainData (Protocol_LobbyClientData (p), c);
break;
//case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
//break;
}
}
@ -62,17 +62,17 @@ void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Ne
{
}
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
{
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
//{
// if (this->gameLobby[i]->GetID() == p.value)
// {
// this->gameLobby[i]->Attach(Detach(c));
// return;
// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
// //{
// // if (this->gameLobby[i]->GetID() == p.value)
// // {
// // this->gameLobby[i]->Attach(Detach(c));
// // return;
// // }
// //}
//}
//}
}
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c)
{
@ -81,13 +81,13 @@ void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Networ
{
//Dont need to handle this on the server...
}
void GameLobby::LobbyMainData(GameLogic::Protocol_LobbyMainData& p, Oyster::Network::NetworkClient* c)
{
}
void GameLobby::LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c)
void GameLobby::LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c)
{
}
//void GameLobby::LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c)
//{
//
//}

View File

@ -39,9 +39,6 @@ DanBiasServerReturn GameServerAPI::ServerInitiate(const ServerInitDesc& desc)
return DanBiasServerReturn_Error;
}
GameSession::GameDescription d;
lobby.GetGameDesc(d);
d.gameName.assign(desc.serverName);
lobby.SetGameDesc(d);
std::printf("Server created!\t-\t%s: [%i]\n\n", server.GetLanAddress().c_str(), desc.listenPort);
@ -95,59 +92,59 @@ GameServerAPI::GameServerInfo GameServerAPI::ServerGetInfo()
}
void GameServerAPI::GameSetMapId(const int& val)
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
d.mapNumber = val;
lobby.SetGameDesc(d);
}
void GameServerAPI::GameSetMaxClients(const int& val)
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
d.maxClients = val;
lobby.SetGameDesc(d);
}
void GameServerAPI::GameSetGameMode(const int& val)
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
d.gameMode = val;
lobby.SetGameDesc(d);
}
void GameServerAPI::GameSetGameTime(const int& val)
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
d.gameTime = val;
lobby.SetGameDesc(d);
}
int GameServerAPI::GameGetMapId()
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
return d.mapNumber;
}
int GameServerAPI::GameGetMaxClients()
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
return d.maxClients;
}
int GameServerAPI::GameGetGameMode()
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
return d.gameMode;
}
int GameServerAPI::GameGetGameTime()
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
return d.gameTime;
}
const char* GameServerAPI::GameGetGameName()
{
GameSession::GameDescription d;
LobbyLevelData d;
lobby.GetGameDesc(d);
return d.gameName.c_str();
}

View File

@ -20,11 +20,9 @@ struct NetworkSession::PrivateSessionData
NetworkClient::ClientEventFunction messageCallback;
std::mutex clientListLock;
NetworkSession* owner; //Where clients end up when session is closed.
int clientCount;
int id;
NetworkSession::PrivateSessionData()
: clientCount(0)
, owner(0)
: owner(0)
, id(GID())
{}
};
@ -38,7 +36,7 @@ NetworkSession::NetworkSession(const NetworkSession& orig)
{
this->data->clients = orig.data->clients;
this->data->owner = orig.data->owner;
this->data->clientCount = orig.data->clientCount;
this->clientCount = orig.clientCount;
this->data->id = orig.data->id;
this->data->messageCallback = orig.data->messageCallback;
}
@ -47,7 +45,7 @@ const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
{
this->data->clients = orig.data->clients;
this->data->owner = orig.data->owner;
this->data->clientCount = orig.data->clientCount;
this->clientCount = orig.clientCount;
this->data->id = orig.data->id;
this->data->messageCallback = orig.data->messageCallback;
@ -57,7 +55,7 @@ const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
NetworkSession::~NetworkSession()
{
this->data->clients.Clear();
this->data->clientCount = 0;
this->clientCount = 0;
this->data->messageCallback = 0;
delete this->data;
this->data = 0;
@ -91,7 +89,7 @@ bool NetworkSession::Attach(NetClient client)
this->data->clients[k] = client;
}
this->data->clientCount++;
this->clientCount++;
client->SetOwner(this);
this->data->clientListLock.unlock();
@ -99,7 +97,7 @@ bool NetworkSession::Attach(NetClient client)
return true;
}
void NetworkSession::Detach()
void NetworkSession::DetachAll()
{
if(this->data->owner)
{
@ -117,6 +115,7 @@ void NetworkSession::Detach()
this->data->clients[i] = 0;
}
}
this->clientCount = 0;
}
NetClient NetworkSession::Detach(const NetworkClient* client)
@ -131,7 +130,7 @@ NetClient NetworkSession::Detach(const NetworkClient* client)
{
val = this->data->clients[i];
this->data->clients[i] = 0;
this->data->clientCount--;
this->clientCount--;
}
}
@ -152,7 +151,29 @@ NetClient NetworkSession::Detach(short ID)
{
val = this->data->clients[i];
this->data->clients[i] = 0;
this->data->clientCount--;
this->clientCount--;
}
}
this->data->clientListLock.unlock();
return val;
}
NetClient NetworkSession::Detach()
{
NetClient val;
this->data->clientListLock.lock();
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[i])
{
val = this->data->clients[i];
this->data->clients[i] = 0;
this->clientCount--;
break;
}
}
@ -204,7 +225,7 @@ void NetworkSession::CloseSession(bool dissconnectClients)
}
this->data->clients.Clear();
this->data->clientCount = 0;
this->clientCount = 0;
this->data->clientListLock.unlock();
}
@ -214,16 +235,6 @@ void NetworkSession::SetOwner(NetworkSession* owner)
this->data->owner = owner;
}
int NetworkSession::GetClientCount() const
{
int c = 0;
for (unsigned int i = 0; i < this->data->clients.Size(); i++)
{
if(this->data->clients[i]) c++;
}
return c;
}
void NetworkSession::ClientConnectedEvent(NetClient client)
{
this->Attach(client);

View File

@ -11,6 +11,7 @@
#include "NetworkServerEventStruct.h"
#include "NetworkClient.h"
#include "Utilities.h"
#include "DynamicArray.h"
namespace Oyster
{
@ -38,7 +39,7 @@ namespace Oyster
* Detaches all clients and sends them to owner.
* If no owner is set the clients is disconnected.
*/
virtual void Detach();
virtual void DetachAll();
/**
*
@ -50,6 +51,11 @@ namespace Oyster
*/
virtual NetClient Detach(short ID);
/**
*
*/
virtual NetClient Detach();
/** Send a message to all clients in this session
* @param message The message
*/
@ -74,7 +80,7 @@ namespace Oyster
/** Get the number of clients active in this session
* @return The client count
*/
int GetClientCount() const;
inline int GetClientCount() const { return this->clientCount; }
/**
*
@ -87,6 +93,7 @@ namespace Oyster
virtual void ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0;
private:
int clientCount;
struct PrivateSessionData;
PrivateSessionData* data;
};