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

View File

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

View File

@ -13,13 +13,6 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient
// parsing protocols and sending it to the gameState // parsing protocols and sending it to the gameState
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override 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; int pType = p[0].value.netInt;
switch (pType) switch (pType)
{ {

View File

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

View File

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

View File

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

View File

@ -12,6 +12,14 @@
namespace DanBias namespace DanBias
{ {
struct LobbyLevelData
{
int mapNumber;
int maxClients;
int gameMode;
int gameTime;
std::string gameName;
};
class GameLobby :public Oyster::Network::NetworkSession class GameLobby :public Oyster::Network::NetworkSession
{ {
public: public:
@ -20,8 +28,8 @@ namespace DanBias
void Release(); void Release();
void Update(); void Update();
void SetGameDesc(const GameSession::GameDescription& desc); void SetGameDesc(const LobbyLevelData& desc);
void GetGameDesc(GameSession::GameDescription& desc); void GetGameDesc(LobbyLevelData& desc);
bool StartGameSession(); bool StartGameSession();
private: private:
@ -31,11 +39,11 @@ namespace DanBias
void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text: 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 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 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 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 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 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: //void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
private: private:
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override; void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;
@ -45,7 +53,7 @@ namespace DanBias
Utility::WinTimer timer; Utility::WinTimer timer;
float refreshFrequency; float refreshFrequency;
GameSession gameSession; GameSession gameSession;
GameSession::GameDescription description; LobbyLevelData description;
}; };
}//End namespace DanBias }//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H #endif // !DANBIASGAME_GAMELOBBY_H

View File

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

View File

@ -9,6 +9,7 @@
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace Oyster::Network; using namespace Oyster::Network;
using namespace Oyster; using namespace Oyster;
using namespace GameLogic;
namespace DanBias namespace DanBias
{ {
@ -30,17 +31,34 @@ namespace DanBias
this->ProcessClients(); 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() 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(); this->gameSession.Run();
return true; return true;
@ -70,6 +88,10 @@ namespace DanBias
{ {
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
Attach(client); Attach(client);
Protocol_LobbyClientData p;
client->Send(p.GetProtocol());
} }
}//End namespace DanBias }//End namespace DanBias

View File

@ -17,16 +17,16 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
//break; //break;
case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
break; break;
case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
break; //break;
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyLogin (p), c); case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyLogin (p), c);
break; break;
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break; break;
case protocol_Lobby_MainData: this->LobbyMainData (Protocol_LobbyMainData (p), c); case protocol_Lobby_MainData: this->LobbyMainData (Protocol_LobbyClientData (p), c);
break;
case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
break; 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) //void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c)
{ //{
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++) // //for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
//{ // //{
// if (this->gameLobby[i]->GetID() == p.value) // // if (this->gameLobby[i]->GetID() == p.value)
// { // // {
// this->gameLobby[i]->Attach(Detach(c)); // // this->gameLobby[i]->Attach(Detach(c));
// return; // // return;
// } // // }
//} // //}
} //}
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c) 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... //Dont need to handle this on the server...
} }
void GameLobby::LobbyMainData(GameLogic::Protocol_LobbyMainData& 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)
{ {
} }
//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; return DanBiasServerReturn_Error;
} }
GameSession::GameDescription d; 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); 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) void GameServerAPI::GameSetMapId(const int& val)
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
d.mapNumber = val; d.mapNumber = val;
lobby.SetGameDesc(d); lobby.SetGameDesc(d);
} }
void GameServerAPI::GameSetMaxClients(const int& val) void GameServerAPI::GameSetMaxClients(const int& val)
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
d.maxClients = val; d.maxClients = val;
lobby.SetGameDesc(d); lobby.SetGameDesc(d);
} }
void GameServerAPI::GameSetGameMode(const int& val) void GameServerAPI::GameSetGameMode(const int& val)
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
d.gameMode = val; d.gameMode = val;
lobby.SetGameDesc(d); lobby.SetGameDesc(d);
} }
void GameServerAPI::GameSetGameTime(const int& val) void GameServerAPI::GameSetGameTime(const int& val)
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
d.gameTime = val; d.gameTime = val;
lobby.SetGameDesc(d); lobby.SetGameDesc(d);
} }
int GameServerAPI::GameGetMapId() int GameServerAPI::GameGetMapId()
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
return d.mapNumber; return d.mapNumber;
} }
int GameServerAPI::GameGetMaxClients() int GameServerAPI::GameGetMaxClients()
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
return d.maxClients; return d.maxClients;
} }
int GameServerAPI::GameGetGameMode() int GameServerAPI::GameGetGameMode()
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
return d.gameMode; return d.gameMode;
} }
int GameServerAPI::GameGetGameTime() int GameServerAPI::GameGetGameTime()
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
return d.gameTime; return d.gameTime;
} }
const char* GameServerAPI::GameGetGameName() const char* GameServerAPI::GameGetGameName()
{ {
GameSession::GameDescription d; LobbyLevelData d;
lobby.GetGameDesc(d); lobby.GetGameDesc(d);
return d.gameName.c_str(); return d.gameName.c_str();
} }

View File

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

View File

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