From 830b448690b04e288ae42c10c47f496e05629add Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 17 Feb 2014 16:17:07 +0100 Subject: [PATCH] Temp --- Code/Game/GameProtocols/ObjectProtocols.h | 93 +++---- Code/Game/GameServer/GameLobby.h | 3 +- .../GameServer/Implementation/GameLobby.cpp | 229 +++++++++--------- .../GameLobby_ProtocolParser.cpp | 31 ++- .../Implementation/GameSession_General.cpp | 1 + 5 files changed, 199 insertions(+), 158 deletions(-) diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index e3449022..ff6aa6e5 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -546,14 +546,14 @@ namespace GameLogic //#define protocol_Gameplay_ObjectCreatePlayer 359 struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject { - //ObjectType type; //ie player, box or whatever - int object_ID; - int teamId; - std::string name; - std::string meshName; - float position[3]; - float rotationQ[4]; - float scale[3]; + /*1*/ int object_ID; + /*2*/ int teamId; + /*3*/ bool owner; + /*4*/ std::string name; + /*5*/ std::string meshName; + /*6 - 8*/ float position[3]; + /*9 - 11*/ float rotationQ[4]; + /*12 - 14*/ float scale[3]; Protocol_ObjectCreatePlayer() { @@ -564,44 +564,47 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + //OWNER + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; //PLAYER-NAME - this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - //MESH-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; + //MESH-NAME + this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray; //POSITION - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float; - //ROTATION this->protocol[8].type = Oyster::Network::NetAttributeType_Float; + //ROTATION this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float; - //SCALE this->protocol[11].type = Oyster::Network::NetAttributeType_Float; + //SCALE this->protocol[12].type = Oyster::Network::NetAttributeType_Float; this->protocol[13].type = Oyster::Network::NetAttributeType_Float; + this->protocol[14].type = Oyster::Network::NetAttributeType_Float; } Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { this->object_ID = p[1].value.netInt; this->teamId = this->protocol[2].value.netInt; - this->name.assign(p[3].value.netCharPtr); - this->meshName.assign(p[4].value.netCharPtr); + this->owner = this->protocol[3].value.netBool; + this->name.assign(p[4].value.netCharPtr); + this->meshName.assign(p[5].value.netCharPtr); - this->position[0] = p[5].value.netFloat; - this->position[1] = p[6].value.netFloat; - this->position[2] = p[7].value.netFloat; + this->position[0] = p[6].value.netFloat; + this->position[1] = p[7].value.netFloat; + this->position[2] = p[8].value.netFloat; - this->rotationQ[0] = p[8].value.netFloat; - this->rotationQ[1] = p[9].value.netFloat; - this->rotationQ[2] = p[10].value.netFloat; - this->rotationQ[3] = p[11].value.netFloat; + this->rotationQ[0] = p[9].value.netFloat; + this->rotationQ[1] = p[10].value.netFloat; + this->rotationQ[2] = p[11].value.netFloat; + this->rotationQ[3] = p[12].value.netFloat; - this->scale[0] = p[12].value.netFloat; - this->scale[1] = p[13].value.netFloat; - this->scale[2] = p[14].value.netFloat; + this->scale[0] = p[13].value.netFloat; + this->scale[1] = p[14].value.netFloat; + this->scale[2] = p[15].value.netFloat; } - Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName) + Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, bool owner, int teamID, std::string name, std::string meshName) { this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; @@ -610,26 +613,29 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + //OWNER + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; //PLAYER-NAME - this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - //MESH-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; + //MESH-NAME + this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray; //POSITION - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float; - //ROTATION this->protocol[8].type = Oyster::Network::NetAttributeType_Float; + //ROTATION this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float; this->protocol[11].type = Oyster::Network::NetAttributeType_Float; - //SCALE this->protocol[12].type = Oyster::Network::NetAttributeType_Float; + //SCALE this->protocol[13].type = Oyster::Network::NetAttributeType_Float; this->protocol[14].type = Oyster::Network::NetAttributeType_Float; + this->protocol[15].type = Oyster::Network::NetAttributeType_Float; this->object_ID = ObjectID; this->teamId = teamID; + this->owner = owner; this->name = name; this->meshName = meshName; memcpy(&this->position[0], &position[0], sizeof(float)*3); @@ -641,22 +647,23 @@ namespace GameLogic this->protocol[1].value = this->object_ID; this->protocol[2].value = this->teamId; - this->protocol.Set(3, this->name); - this->protocol.Set(4, this->meshName); + this->protocol[3].value = this->owner; + this->protocol.Set(4, this->name); + this->protocol.Set(5, this->meshName); //POSITION - this->protocol[5].value = this->position[0]; - this->protocol[6].value = this->position[1]; - this->protocol[7].value = this->position[2]; + this->protocol[6].value = this->position[0]; + this->protocol[7].value = this->position[1]; + this->protocol[8].value = this->position[2]; //ROTATION - this->protocol[8].value = this->rotationQ[0]; - this->protocol[9].value = this->rotationQ[1]; - this->protocol[10].value = this->rotationQ[2]; - this->protocol[11].value = this->rotationQ[3]; + this->protocol[9].value = this->rotationQ[0]; + this->protocol[10].value = this->rotationQ[1]; + this->protocol[11].value = this->rotationQ[2]; + this->protocol[12].value = this->rotationQ[3]; //SCALE - this->protocol[12].value = this->scale[0]; - this->protocol[13].value = this->scale[1]; - this->protocol[14].value = this->scale[2]; + this->protocol[13].value = this->scale[0]; + this->protocol[14].value = this->scale[1]; + this->protocol[15].value = this->scale[2]; return protocol; } diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 86cd498a..d0cbbcc3 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -41,11 +41,12 @@ namespace DanBias //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_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: + void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: 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 LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: + void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: private: void ClientEventCallback(Oyster::Network::NetEvent e) override; diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 82599677..6f4f0a47 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -11,127 +11,132 @@ using namespace Oyster::Network; using namespace Oyster; using namespace GameLogic; -namespace DanBias +using namespace DanBias; + +GameLobby::GameLobby() +{ } +GameLobby::~GameLobby() +{ + this->clients.Clear(); +} +void GameLobby::Release() +{ + NetworkSession::CloseSession(true); + this->gameSession.CloseSession(true); +} +void GameLobby::Update() { - GameLobby::GameLobby() - { } - GameLobby::~GameLobby() - { - this->clients.Clear(); - } - void GameLobby::Release() - { - NetworkSession::CloseSession(true); - this->gameSession.CloseSession(true); - } - void GameLobby::Update() + for (unsigned int i = 0; i < this->clients.Size(); i++) { - this->ProcessClients(); - } - void GameLobby::SetGameDesc(const LobbyLevelData& desc) - { - this->description.gameMode = desc.gameMode; - this->description.gameTime = desc.gameTime; - this->description.mapNumber = desc.mapNumber; - this->description.maxClients = desc.maxClients; - } - void GameLobby::GetGameDesc(LobbyLevelData& desc) - { - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; - desc.maxClients = this->description.maxClients; - } - bool GameLobby::StartGameSession( ) - { - //Check if all clients is ready - if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) + if(this->clients[i]) { - GameSession::GameDescription desc; - desc.maxClients = this->description.maxClients; - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; - desc.owner = this; - desc.clients = this->clients; + this->clients[i]->Update(); + } + } +} +void GameLobby::SetGameDesc(const LobbyLevelData& desc) +{ + this->description.gameMode = desc.gameMode; + this->description.gameTime = desc.gameTime; + this->description.mapNumber = desc.mapNumber; + this->description.maxClients = desc.maxClients; +} +void GameLobby::GetGameDesc(LobbyLevelData& desc) +{ + desc.gameMode = this->description.gameMode; + desc.gameTime = this->description.gameTime; + desc.mapNumber = this->description.mapNumber; + desc.maxClients = this->description.maxClients; +} +bool GameLobby::StartGameSession( ) +{ +//Check if all clients is ready + if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) + { + GameSession::GameDescription desc; + desc.maxClients = this->description.maxClients; + desc.gameMode = this->description.gameMode; + desc.gameTime = this->description.gameTime; + desc.mapNumber = this->description.mapNumber; + desc.owner = this; + desc.clients = this->clients; - if(desc.gameTime == 0.0f) - desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. + if(desc.gameTime == 0.0f) + desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. - if(desc.maxClients == 0) - desc.maxClients = 10; //note: should be fetched somewhere else.. + if(desc.maxClients == 0) + desc.maxClients = 10; //note: should be fetched somewhere else.. - this->clients.Clear(); //Remove clients from lobby list + this->clients.Clear(); //Remove clients from lobby list - if(this->gameSession.Create(desc)) - { - this->gameSession.Run(); + if(this->gameSession.Create(desc)) + { + this->gameSession.Run(); - return true; + return true; + } + } + else + { + //? + } + return false; +} + +void GameLobby::ClientEventCallback(NetEvent e) +{ + switch (e.args.type) + { + case NetworkClient::ClientEventArgs::EventType_Disconnect: + + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: + + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: + printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); + e.sender->Disconnect(); + this->readyList.Remove(e.sender); + this->clients.Remove(e.sender); + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: + printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); + this->ParseProtocol(e.args.data.protocol, e.sender); + break; + } +} +void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) +{ + printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); + + if(this->gameSession) + { + Attach(client); + } + else + { + Attach(client); + Protocol_LobbyClientData p1; + Protocol_LobbyGameData p2; + + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + Protocol_LobbyClientData::PlayerData t; + t.id = this->clients[i]->GetID(); + t.ip = this->clients[i]->GetIpAddress(); + t.team = 0; + t.name = "Dennis är kung tycker Erik!"; + p1.list.Push(t); } } - else - { - //? - } - return false; + p2.majorVersion = 1; + p2.minorVersion = 0; + p2.mapName = "Dennis är kung tycker Erik!"; + + client->Send(p1.GetProtocol()); + client->Send(p2.GetProtocol()); } +} - void GameLobby::ClientEventCallback(NetEvent e) - { - switch (e.args.type) - { - case NetworkClient::ClientEventArgs::EventType_Disconnect: - - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: - - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: - printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); - e.sender->Disconnect(); - this->readyList.Remove(e.sender); - this->clients.Remove(e.sender); - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: - printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); - this->ParseProtocol(e.args.data.protocol, e.sender); - break; - } - } - void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) - { - printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); - - if(this->gameSession) - { - this->gameSession.Attach(client); - } - else - { - Attach(client); - Protocol_LobbyClientData p1; - Protocol_LobbyGameData p2; - - for (unsigned int i = 0; i < this->clients.Size(); i++) - { - if(this->clients[i]) - { - Protocol_LobbyClientData::PlayerData t; - t.id = this->clients[i]->GetID(); - t.ip = this->clients[i]->GetIpAddress(); - t.team = 0; - t.name = "Dennis är kung tycker Erik!"; - p1.list.Push(t); - } - } - p2.majorVersion = 1; - p2.minorVersion = 0; - p2.mapName = "Dennis är kung tycker Erik!"; - - client->Send(p1.GetProtocol()); - client->Send(p2.GetProtocol()); - } - } - -}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index 7493cb5a..d49f83fc 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -18,11 +18,11 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); //break; - case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); + case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); break; //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); //break; - case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); + case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); break; case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; @@ -32,6 +32,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); break; + case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + break; } } @@ -112,4 +114,29 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: this->readyList.Remove(c); } } +void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) +{ + NetClient temp; + bool found = false; + //find client in waiting list + for (unsigned int i = 0; !found && i < this->clients.Size(); i++) + { + if(this->clients[i]->GetID() == c->GetID()) + { + temp = this->clients[i]; + found = true; + } + } + + //Something is wrong + if(!found) + { + c->Disconnect(); + } + else + { + //Send game data + this->gameSession.Attach(temp); + } +} diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 647cee4a..cf82cc61 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -209,6 +209,7 @@ namespace DanBias { IPlayerData* p = this->clients[i]->GetPlayer(); Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); + //Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); this->clients[i]->GetClient()->Send(oc); } }