diff --git a/Bin/Script/PLACEHOLDER b/Bin/Script/PLACEHOLDER deleted file mode 100644 index e69de29b..00000000 diff --git a/Bin/Settings/ServerInit.ini b/Bin/Settings/ServerInit.ini deleted file mode 100644 index a3b8f420..00000000 --- a/Bin/Settings/ServerInit.ini +++ /dev/null @@ -1,2 +0,0 @@ -port 15151 -clients 200 \ No newline at end of file diff --git a/Bin/Settings/serversearchpath.ini b/Bin/Settings/serversearchpath.ini deleted file mode 100644 index 6dc44cff..00000000 --- a/Bin/Settings/serversearchpath.ini +++ /dev/null @@ -1,4 +0,0 @@ -ServerInit ..\Settings\ServerInit.ini -More a -more b -more c \ No newline at end of file diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 5e8f837e..4dedaaa2 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -39,10 +39,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameP EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Game\DanBiasServerLauncher\DanBiasServerLauncher.vcxproj", "{060B1890-CBF3-4808-BA99-A4776222093B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Physics lab", "Physics lab\Physics lab.vcxproj", "{5128BD77-6472-4C4A-BE6F-724AD0E589C2}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameServer", "Game\GameServer\GameServer.vcxproj", "{143BD516-20A1-4890-A3E4-F8BFD02220E7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Mixed Platforms = Debug|Mixed Platforms @@ -257,18 +259,18 @@ Global {060B1890-CBF3-4808-BA99-A4776222093B}.Release|Win32.Build.0 = Release|Win32 {060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.ActiveCfg = Release|x64 {060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.Build.0 = Release|x64 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64 - {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.ActiveCfg = Debug|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.Build.0 = Debug|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.ActiveCfg = Debug|x64 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.Build.0 = Debug|x64 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.Build.0 = Release|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.ActiveCfg = Release|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.Build.0 = Release|Win32 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.ActiveCfg = Release|x64 + {5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.Build.0 = Release|x64 {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Debug|Win32.ActiveCfg = Debug|Win32 @@ -281,6 +283,18 @@ Global {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|Win32.Build.0 = Release|Win32 {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|x64.ActiveCfg = Release|x64 {143BD516-20A1-4890-A3E4-F8BFD02220E7}.Release|x64.Build.0 = Release|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64 + {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -295,7 +309,7 @@ Global {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A} {060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A} - {666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A} {143BD516-20A1-4890-A3E4-F8BFD02220E7} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A} EndGlobalSection EndGlobal diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 360d1c60..c5293738 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -88,18 +88,15 @@ struct GameRecieverObject :public Oyster::Network::NetworkClient case protocol_Gameplay_ObjectPosition: { - Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; - protocolData->object_ID = p[1].value.netInt; + Client::GameClientState::ObjPos protocolData; + protocolData.object_ID = p[1].value.netInt; for(int i = 0; i< 16; i++) { - protocolData->worldPos[i] = p[i+2].value.netFloat; + protocolData.worldPos[i] = p[i+2].value.netFloat; } if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - - delete protocolData; - protocolData = NULL; + ((Client::GameState*)gameClientState)->Protocol(&protocolData); } break; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 3a090c0f..26c40ada 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -85,7 +85,7 @@ bool GameState::LoadModels(std::wstring mapFile) scale.v[1].y = 8; scale.v[2].z = 8; modelData.world = scale; //modelData.world * translate - modelData.modelPath = L"ball.dan"; + modelData.modelPath = L"..\\Content\\Models\\ball.dan"; modelData.id = 0; obj = new C_Player(); @@ -96,7 +96,7 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.world = Oyster::Math3D::Float4x4::identity; translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-5,15,0)); modelData.world = modelData.world * translate; - modelData.modelPath = L"box.dan"; + modelData.modelPath = L"..\\Content\\Models\\box.dan"; modelData.id = 1; obj = new C_Player(); @@ -104,7 +104,6 @@ bool GameState::LoadModels(std::wstring mapFile) privData->object[privData->object.size() -1 ]->Init(modelData); modelData.world = Oyster::Math3D::Float4x4::identity; - // add player model modelData.world = Oyster::Math3D::Float4x4::identity; translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 15, 0)); @@ -199,8 +198,6 @@ bool GameState::Release() privData->object[i] = NULL; } - delete this->camera; - delete privData; privData = NULL; return true; diff --git a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp index fbf19b57..62e2b828 100644 --- a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp +++ b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp @@ -19,12 +19,17 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh WindowShell::CreateConsoleWindow(); - DanBias::GameServerAPI::GameInitDesc desc; + DanBias::GameServerAPI::ServerInitDesc desc; desc.listenPort = 15151; - if(DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess) + if(DanBias::GameServerAPI::ServerInitiate(desc) == DanBias::DanBiasServerReturn_Sucess) { - DanBias::GameServerAPI::Start(); - DanBias::GameServerAPI::Terminate(); + DanBias::GameServerAPI::ServerStart(); + while (!(GetAsyncKeyState(0x51))) //Q for exit + { + DanBias::GameServerAPI::ServerUpdate(); + Sleep(1); + } + DanBias::GameServerAPI::ServerStop(); } return cmdShow; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 6bb4cdc9..53cb75ec 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -93,6 +93,7 @@ void Game::CreateTeam() bool Game::NewFrame() { + for (unsigned int i = 0; i < this->players.Size(); i++) { if(this->players[i]->player) this->players[i]->player->BeginFrame(); @@ -126,17 +127,7 @@ bool Game::NewFrame() { if(this->players[i]->player) this->players[i]->player->EndFrame(); } - for (unsigned int i = 0; i < this->players.Size(); i++) - { - if(this->players[i]->player) this->players[i]->player->BeginFrame(); - } - API::Instance().Update(); - - for (unsigned int i = 0; i < this->players.Size(); i++) - { - if(this->players[i]->player) this->players[i]->player->EndFrame(); - } //gameInstance.onMoveFnc(this->level); return true; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e9a0a8b4..1b9a5d69 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -27,7 +27,8 @@ Game::PlayerData::~PlayerData() delete this->player; } -void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement){ +void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement) +{ this->player->Move(movement); } void Game::PlayerData::UseWeapon(const WEAPON_FIRE &usage) diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 8968de74..87aad62e 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -14,6 +14,7 @@ namespace GameLogic { + /* struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject { char* mapName; @@ -42,7 +43,7 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; - + */ struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject { short gameId; diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 47e3b329..2b9f4bc4 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -20,14 +20,16 @@ namespace DanBias void Release(); void Update(); - operator bool(); + void SetGameDesc(const GameSession::GameDescription& desc); + void GetGameDesc(GameSession::GameDescription& desc); + bool StartGameSession(); private: void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c); void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status: 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 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: @@ -42,7 +44,8 @@ namespace DanBias private: Utility::WinTimer timer; float refreshFrequency; - GameSession* gameSession; + GameSession gameSession; + GameSession::GameDescription description; }; }//End namespace DanBias #endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h index cc03ec01..e76b4264 100644 --- a/Code/Game/GameServer/GameServerAPI.h +++ b/Code/Game/GameServer/GameServerAPI.h @@ -28,17 +28,39 @@ namespace DanBias class DANBIAS_SERVER_DLL GameServerAPI { public: - struct GameInitDesc + struct ServerInitDesc { + char* serverName; int listenPort; - bool threaded; + ServerInitDesc() + : serverName("Game Server") + , listenPort(15151) + {}; + }; + struct GameServerInfo + { + unsigned int listenPort; // If set to 0, the default port 15151 will be used + const char *serverIp; // This cant be mofidfied.. }; public: - static DanBiasServerReturn Create(const GameInitDesc& desc); - static void Start(); - static void Stop(); - static void Terminate(); + static DanBiasServerReturn ServerInitiate(const ServerInitDesc& desc); + static void ServerStart(); + static void ServerStop(); + static void ServerUpdate(); + static GameServerInfo ServerGetInfo(); + + static void GameSetMapId(const int& val); + static void GameSetMaxClients(const int& val); + static void GameSetGameMode(const int& val); + static void GameSetGameTime(const int& val); + static int GameGetMapId(); + static int GameGetMaxClients(); + static int GameGetGameMode(); + static int GameGetGameTime(); + static const char* GameGetGameName(); + static bool GameStart(); + };//End class DanBiasServer }//End Extern "C" diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index eca2f3e8..30ba0811 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -31,7 +31,11 @@ namespace DanBias */ struct GameDescription { - std::wstring mapName; + int mapNumber; + int maxClients; + int gameMode; + int gameTime; + std::string gameName; Oyster::Network::NetworkSession* owner; Utility::DynamicMemory::DynamicArray clients; }; @@ -83,6 +87,9 @@ namespace DanBias void General_Status ( GameLogic::Protocol_General_Status& p, DanBias::GameClient* c ); void General_Text ( GameLogic::Protocol_General_Text& p, DanBias::GameClient* c ); + //Callback method recieving from gamelogic + static void ObjectMove(GameLogic::IObjectData* movedObject); + //Private member variables private: Utility::DynamicMemory::DynamicArray> clients; @@ -93,10 +100,10 @@ namespace DanBias bool isCreated; bool isRunning; Utility::WinTimer timer; + GameDescription description; - //Callback method recieving from gamelogic - static void ObjectMove(GameLogic::IObjectData* movedObject); - + //TODO: Remove this uggly hax + static GameSession* gameSession; };//End GameSession }//End namespace DanBias diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 9396d71d..24ca7887 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -25,14 +25,27 @@ namespace DanBias void GameLobby::Update() { - if(GetAsyncKeyState(VK_DOWN)) + if(GetAsyncKeyState(VK_DOWN)) //TODO: Dont forget to remove this... this->Send(*GameLogic::Protocol_General_Status().GetProtocol()); this->ProcessClients(); } - GameLobby::operator bool() + void GameLobby::SetGameDesc(const GameSession::GameDescription& desc) { - return true; + this->description = desc; + } + void GameLobby::GetGameDesc(GameSession::GameDescription& desc) + { + desc = this->description; + } + bool GameLobby::StartGameSession() + { + if(this->gameSession.Create(this->description)) + { + this->gameSession.Run(); + return true; + } + return false; } void GameLobby::ClientEventCallback(NetEvent e) diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index 335bf55b..0de7b062 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -13,8 +13,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); break; - case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); - break; + //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); + //break; case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); break; case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); @@ -54,10 +54,10 @@ void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network { printf(p.text.c_str()); } -void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c) -{ - -} +//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c) +//{ +// +//} void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c) { diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index d98794a4..0489a12d 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include using namespace DanBias; using namespace Oyster::Network; @@ -28,37 +28,37 @@ namespace GameLobby lobby; NetworkServer server; WinTimer timer; - GameServerAPI instance; - //typedef void(*WorkerThreadFnc)(GameServerAPI*); } -DanBiasServerReturn GameServerAPI::Create(const GameInitDesc& desc) + +DanBiasServerReturn GameServerAPI::ServerInitiate(const ServerInitDesc& desc) { - if(server.Init(desc.listenPort, &lobby) == NetworkServer::ServerReturnCode_Error) { 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); return DanBiasServerReturn_Sucess; } -void GameServerAPI::Start() +void GameServerAPI::ServerStart() { + timer.reset(); server.Start(); - timer.reset(); - - while (true) - { - server.ProcessConnectedClients(); - lobby.Update(); - - if(GetAsyncKeyState(0x51)) //Q for exit - break; - } + +} +void GameServerAPI::ServerStop() +{ + lobby.Release(); + server.Shutdown(); + double total = timer.getElapsedSeconds(); int time = (int)total; @@ -72,23 +72,87 @@ void GameServerAPI::Start() printf( "Server has been running for: %i:%i:%i - [hh:mm:ss] \n\n", hour, min, sec ); printf( "Terminating in : "); - for (int i = 0; i < 4; i++) + for (int i = 0; i < 3; i++) { printf( "%i ", 3-i ); Sleep(1000); } - + printf( "\nServer terminated!" ); } -void GameServerAPI::Stop() +void GameServerAPI::ServerUpdate() { - server.Stop(); - lobby.ProcessClients(); -} -void GameServerAPI::Terminate() -{ - lobby.Release(); - server.Shutdown(); - - printf( "Server terminated!" ); + server.Update(); + lobby.Update(); } + +GameServerAPI::GameServerInfo GameServerAPI::ServerGetInfo() +{ + GameServerAPI::GameServerInfo i; + i.serverIp = server.GetLanAddress().c_str(); + i.listenPort = server.GetPort(); + return i; +} +void GameServerAPI::GameSetMapId(const int& val) +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + d.mapNumber = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetMaxClients(const int& val) +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + d.maxClients = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetGameMode(const int& val) +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + d.gameMode = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetGameTime(const int& val) +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + d.gameTime = val; + lobby.SetGameDesc(d); +} +int GameServerAPI::GameGetMapId() +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + return d.mapNumber; +} +int GameServerAPI::GameGetMaxClients() +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + return d.maxClients; +} +int GameServerAPI::GameGetGameMode() +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + return d.gameMode; +} +int GameServerAPI::GameGetGameTime() +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + return d.gameTime; +} +const char* GameServerAPI::GameGetGameName() +{ + GameSession::GameDescription d; + lobby.GetGameDesc(d); + return d.gameName.c_str(); +} +bool GameServerAPI::GameStart() +{ + return lobby.StartGameSession(); +} + diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 306837d9..945198af 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -19,12 +19,17 @@ using namespace GameLogic; namespace DanBias { + GameSession* GameSession::gameSession = nullptr; + GameSession::GameSession() :gameInstance(GameAPI::Instance()) { this->owner = 0; this->isCreated = false; this->isRunning = false; + this->gameSession = this; + + memset(&this->description, 0, sizeof(GameDescription)); } GameSession::~GameSession() @@ -39,10 +44,10 @@ namespace DanBias bool GameSession::Create(GameDescription& desc) { + this->description = desc; /* Do some error checking */ if(desc.clients.Size() == 0) return false; if(!desc.owner) return false; - if(!desc.mapName.size()) return false; if(this->isCreated) return false; /* standard initialization of some data */ diff --git a/Code/Game/aDanBiasGameLauncher/Launcher.cpp b/Code/Game/aDanBiasGameLauncher/Launcher.cpp index 17e3c8bc..e13baff1 100644 --- a/Code/Game/aDanBiasGameLauncher/Launcher.cpp +++ b/Code/Game/aDanBiasGameLauncher/Launcher.cpp @@ -11,13 +11,19 @@ void ServerFnc() { - DanBias::GameServerAPI::GameInitDesc desc; + DanBias::GameServerAPI::ServerInitDesc desc; desc.listenPort = 15151; - if( DanBias::GameServerAPI::Create(desc) == DanBias::DanBiasServerReturn_Sucess) + if(DanBias::GameServerAPI::ServerInitiate(desc) == DanBias::DanBiasServerReturn_Sucess) { - DanBias::GameServerAPI::Start(); - DanBias::GameServerAPI::Terminate(); + DanBias::GameServerAPI::ServerStart(); + while (!(GetAsyncKeyState(0x51))) //Q for exit + { + DanBias::GameServerAPI::ServerUpdate(); + Sleep(1); + } + DanBias::GameServerAPI::ServerStop(); } + Sleep(100); } void ClientFnc() diff --git a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj index 4133d396..f9b46097 100644 --- a/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj +++ b/Code/Game/aDanBiasGameLauncher/aDanBiasGameLauncher.vcxproj @@ -111,7 +111,7 @@ Windows true DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) - DanBiasGame_$(PlatformShortName)D.lib;DanBiasServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -127,7 +127,7 @@ Windows true DanBiasGame_$(PlatformShortName)D.dll;GameServer_$(PlatformShortName)D.dll;%(DelayLoadDLLs) - DanBiasGame_$(PlatformShortName)D.lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName)D.lib;GameServer_$(PlatformShortName)D.lib;%(AdditionalDependencies) @@ -147,7 +147,7 @@ true true DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs) - DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies) @@ -167,7 +167,7 @@ true true DanBiasGame_$(PlatformShortName).dll;GameServer_$(PlatformShortName).dll;%(DelayLoadDLLs) - DanBiasGame_$(PlatformShortName).lib;%(AdditionalDependencies) + DanBiasGame_$(PlatformShortName).lib;GameServer_$(PlatformShortName).lib;%(AdditionalDependencies) diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index 45807e84..79c7c700 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -296,7 +296,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker) } OYSTER_THREAD_ERROR OysterThread::Terminate() { - return this->privateData->Terminate(); + if(this->privateData) + return this->privateData->Terminate(); + return OYSTER_THREAD_ERROR_SUCCESS; } OYSTER_THREAD_ERROR OysterThread::Wait() { diff --git a/Code/Network/NetworkAPI/NetworkServer.cpp b/Code/Network/NetworkAPI/NetworkServer.cpp index 9a4195a2..4bdc4abf 100644 --- a/Code/Network/NetworkAPI/NetworkServer.cpp +++ b/Code/Network/NetworkAPI/NetworkServer.cpp @@ -224,7 +224,7 @@ void NetworkServer::Shutdown() this->privateData->isReleased = true; } -int NetworkServer::ProcessConnectedClients() +int NetworkServer::Update() { int c = 0; while(!this->privateData->clientQueue.IsEmpty()) @@ -282,6 +282,10 @@ std::string NetworkServer::GetLanAddress() szLocalIP = buff; return szLocalIP; } +int NetworkServer::GetPort() +{ + return this->privateData->port; +} diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h index ca33ebbe..97a3e024 100644 --- a/Code/Network/NetworkAPI/NetworkServer.h +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -46,6 +46,10 @@ namespace Oyster */ ServerReturnCode Start(); + /** Parses asynchronous connected clients. + */ + int Update(); + /** * */ @@ -55,10 +59,6 @@ namespace Oyster */ void Shutdown(); - /** Parses asynchronous connected clients. - */ - int ProcessConnectedClients(); - /** Set the main session connected clients will enter when connected to server. * @param mainSession The session to connect as main server session. */ @@ -84,6 +84,11 @@ namespace Oyster */ std::string GetLanAddress(); + /** + * + */ + int NetworkServer::GetPort(); + private: struct PrivateData; PrivateData* privateData;