diff --git a/Code/Game/GameProtocols/GeneralProtocols.h b/Code/Game/GameProtocols/GeneralProtocols.h index 98b7c060..02763ba0 100644 --- a/Code/Game/GameProtocols/GeneralProtocols.h +++ b/Code/Game/GameProtocols/GeneralProtocols.h @@ -19,8 +19,8 @@ namespace GameLogic Protocol_General_Status() { - this->protocol[protocol_INDEX_ID].value = protocol_General_Status; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_General_Status; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } @@ -31,8 +31,8 @@ namespace GameLogic } Protocol_General_Status(States state) { - this->protocol[protocol_INDEX_ID].value = protocol_General_Status; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_General_Status; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->status = state; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } @@ -61,7 +61,7 @@ namespace GameLogic } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol.Set(protocol_INDEX_ID, protocol_General_Text, Oyster::Network::NetAttributeType_Short); + this->protocol.Set(0, protocol_General_Text, Oyster::Network::NetAttributeType_Short); this->protocol.Set(1, destination, Oyster::Network::NetAttributeType_Int); this->protocol.Set(2, text); return &protocol; diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 8b333a54..c653f556 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -22,8 +22,8 @@ namespace GameLogic Protocol_LobbyCreateGame() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Create; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_Create; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[2].type = Oyster::Network::NetAttributeType_Char; @@ -50,8 +50,8 @@ namespace GameLogic Protocol_LobbyStartGame() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Start; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_Start; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } @@ -74,8 +74,8 @@ namespace GameLogic // Login stuff Protocol_LobbyLogin() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_Join; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } @@ -98,14 +98,14 @@ namespace GameLogic // // Protocol_LobbyJoin() // { - // this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; - // this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + // this->protocol[0].value = protocol_Lobby_Join; + // this->protocol[0].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[0].value = protocol_Lobby_Join; + // this->protocol[0].type = Oyster::Network::NetAttributeType_Short; // this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // value = p[1].value.netShort; // } @@ -123,8 +123,8 @@ namespace GameLogic { Protocol_LobbyRefresh() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Login; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_Login; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; } Protocol_LobbyRefresh(Oyster::Network::CustomNetProtocol& o) { @@ -147,35 +147,90 @@ namespace GameLogic struct PlayerData { std::string name; + std::string ip; int id; + int team; }; Utility::DynamicMemory::DynamicArray list; - + Protocol_LobbyClientData() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_ClientData; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_UnsignedInt; //DataType list.Reserve(10); } 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; - - list.Reserve(10); + unsigned int size = this->protocol[1].value.netUInt; + list.Reserve(size); + int a = 2; + for (unsigned int i = 0; i < list.Size(); i++) + { + PlayerData d; + d.id = this->protocol[a++].value.netInt; + d.team = this->protocol[a++].value.netInt; + d.name = this->protocol.Get(a++).value.netCharPtr; + d.ip = this->protocol.Get(a++).value.netCharPtr; + list.Push(d); + } } Oyster::Network::CustomNetProtocol* GetProtocol() override { - int a = 1; + this->protocol[1].value = list.Size(); + + int a = 2; for (unsigned int i = 0; i < list.Size(); i++) { - this->protocol[a].type = Oyster::Network::NetAttributeType_Int; - this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; + this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // client-id + this->protocol[a++].value = list[i].id; - this->protocol[a].value = list[i].id; - this->protocol.Set(a, list[i].name); + this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // team-id + this->protocol[a++].value = list[i].team; + + this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; // clientName + this->protocol.Set(a++, list[i].name); + + this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; // clientIP + this->protocol.Set(a++, list[i].ip); } + + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + struct Protocol_LobbyGameData :public Oyster::Network::CustomProtocolObject + { + std::string mapName; + int majorVersion; + int minorVersion; + + Protocol_LobbyGameData() + { + this->protocol[0].value = protocol_Lobby_GameData; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; + } + Protocol_LobbyGameData(Oyster::Network::CustomNetProtocol& p) + { + majorVersion = (int)p.Get(1).value.netInt; + minorVersion = (int)p.Get(2).value.netInt; + mapName = p.Get(3).value.netCharPtr; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = majorVersion; + this->protocol[2].value = minorVersion; + this->protocol[3].value.netCharPtr = const_cast(mapName.c_str()); + return &protocol; } @@ -192,8 +247,8 @@ namespace GameLogic // // Protocol_LobbyMainData() // { - // this->protocol[protocol_INDEX_ID].value = protocol_Lobby_MainData; - // this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + // this->protocol[0].value = protocol_Lobby_MainData; + // this->protocol[0].type = Oyster::Network::NetAttributeType_Short; // // this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 9c4e2df1..5df97855 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -13,8 +13,8 @@ namespace GameLogic Protocol_ObjectPickup() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPickup; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectPickup; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Short; @@ -28,8 +28,8 @@ namespace GameLogic } Protocol_ObjectPickup(int objectID, short pickupID) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectPosition; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Short; @@ -56,8 +56,8 @@ namespace GameLogic Protocol_ObjectDamage() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectDamage; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -71,8 +71,8 @@ namespace GameLogic } Protocol_ObjectDamage(int id, float hp) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectDamage; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -97,8 +97,8 @@ namespace GameLogic Protocol_ObjectPosition() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectPosition; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -115,8 +115,8 @@ namespace GameLogic } Protocol_ObjectPosition(float m[16], int id) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectPosition; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -149,8 +149,8 @@ namespace GameLogic Protocol_ObjectEnable() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectEnabled; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -167,8 +167,8 @@ namespace GameLogic } Protocol_ObjectEnable(float m[16], int id) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectEnabled; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -199,8 +199,8 @@ namespace GameLogic Protocol_ObjectDisable() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectDisabled; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -211,8 +211,8 @@ namespace GameLogic } Protocol_ObjectDisable(int id, float time) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectDisabled; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -239,8 +239,8 @@ namespace GameLogic Protocol_ObjectCreate() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_ObjectCreate; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; @@ -256,8 +256,8 @@ namespace GameLogic } Protocol_ObjectCreate(float m[16], int id, char *path) { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; + this->protocol[0].value = protocol_Gameplay_ObjectCreate; + this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index d33ef9c3..7f8b81f0 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -25,8 +25,8 @@ namespace GameLogic Protocol_PlayerMovement() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMovement; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_PlayerMovement; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; @@ -69,8 +69,8 @@ namespace GameLogic Protocol_PlayerLook() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerLookDir; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_PlayerLookDir; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -109,8 +109,8 @@ namespace GameLogic Protocol_PlayerChangeWeapon() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerChangeWeapon; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_PlayerChangeWeapon; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; @@ -140,8 +140,8 @@ namespace GameLogic Protocol_PlayerShot() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerShot; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_PlayerShot; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; } @@ -170,8 +170,8 @@ namespace GameLogic Protocol_PlayerJump() { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerJump; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Gameplay_PlayerJump; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; } diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 180f6541..cb596a1c 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -8,11 +8,6 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -/** Index where the identifier is located(aka protocol identification index) **/ -/* Use this as id accesser since it may change in the future. */ -#define protocol_INDEX_ID 0 - - /***********************************/ /********* RESERVERD PROTOCOLS ***************************************************************************************************/ /********** [ 0 - 99 ] *********/ @@ -37,7 +32,7 @@ #define protocol_Lobby_Join 202 #define protocol_Lobby_Login 203 #define protocol_Lobby_Refresh 204 -#define protocol_Lobby_MainData 205 +#define protocol_Lobby_ClientData 205 #define protocol_Lobby_GameData 206 #define protocol_LobbyMAX 299 diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 8463b9d9..8a421e1d 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -42,8 +42,8 @@ namespace DanBias //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 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 e) override; diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 308e4ae6..4291f44b 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -52,12 +52,8 @@ namespace DanBias 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); - } + desc.clients = this->clients; + if(this->gameSession.Create(desc)) { this->gameSession.Run(); @@ -89,9 +85,27 @@ namespace DanBias printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); Attach(client); - Protocol_LobbyClientData p; + Protocol_LobbyClientData p1; + Protocol_LobbyGameData p2; - client->Send(p.GetProtocol()); + 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ÄrKung"; + p1.list.Push(t); + } + } + p2.majorVersion = 1; + p2.minorVersion = 0; + p2.mapName = "BetsMap"; + + 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 1c841519..3a86bc6b 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -23,7 +23,9 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; - case protocol_Lobby_MainData: this->LobbyMainData (Protocol_LobbyClientData (p), c); + case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); + break; + case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); break; //case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); //break; @@ -60,7 +62,7 @@ void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network //} void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c) { - + //TODO: Prio 1 } //void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c) //{ @@ -80,14 +82,14 @@ void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::N void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c) { //Dont need to handle this on the server... +} +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) -//{ -// -//} diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index a17f1ce8..0a528f04 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -74,7 +74,7 @@ namespace DanBias void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) { - switch (p[protocol_INDEX_ID].value.netShort) + switch (p[0].value.netShort) { case protocol_Gameplay_PlayerMovement: this->Gameplay_PlayerMovement ( Protocol_PlayerMovement (p), c ); break; diff --git a/Code/Network/NetworkAPI/NetworkSession.cpp b/Code/Network/NetworkAPI/NetworkSession.cpp index 35352243..c7bf15ba 100644 --- a/Code/Network/NetworkAPI/NetworkSession.cpp +++ b/Code/Network/NetworkAPI/NetworkSession.cpp @@ -16,7 +16,6 @@ using namespace Oyster::Network; struct NetworkSession::PrivateSessionData { - Utility::DynamicMemory::DynamicArray clients; NetworkClient::ClientEventFunction messageCallback; std::mutex clientListLock; NetworkSession* owner; //Where clients end up when session is closed. @@ -34,7 +33,7 @@ NetworkSession::NetworkSession() {} NetworkSession::NetworkSession(const NetworkSession& orig) { - this->data->clients = orig.data->clients; + this->clients = orig.clients; this->data->owner = orig.data->owner; this->clientCount = orig.clientCount; this->data->id = orig.data->id; @@ -43,7 +42,7 @@ NetworkSession::NetworkSession(const NetworkSession& orig) const NetworkSession& NetworkSession::operator=(const NetworkSession& orig) { - this->data->clients = orig.data->clients; + this->clients = orig.clients; this->data->owner = orig.data->owner; this->clientCount = orig.clientCount; this->data->id = orig.data->id; @@ -54,7 +53,7 @@ const NetworkSession& NetworkSession::operator=(const NetworkSession& orig) NetworkSession::~NetworkSession() { - this->data->clients.Clear(); + this->clients.Clear(); this->clientCount = 0; this->data->messageCallback = 0; delete this->data; @@ -63,9 +62,9 @@ NetworkSession::~NetworkSession() void NetworkSession::ProcessClients() { - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i]) this->data->clients[i]->Update(); + if(this->clients[i]) this->clients[i]->Update(); } } @@ -74,19 +73,19 @@ bool NetworkSession::Attach(NetClient client) this->data->clientListLock.lock(); int k = -1; - for (unsigned int i = 0; (k == -1) && i < this->data->clients.Size(); i++) + for (unsigned int i = 0; (k == -1) && i < this->clients.Size(); i++) { - if(!this->data->clients[i]->IsConnected()) //TODO: Dont check connection status, check more general status.. + if(!this->clients[i]->IsConnected()) //TODO: Dont check connection status, check more general status.. k = i; } if(k == -1) { - this->data->clients.Push(client); + this->clients.Push(client); } else { - this->data->clients[k] = client; + this->clients[k] = client; } this->clientCount++; @@ -101,18 +100,18 @@ void NetworkSession::DetachAll() { if(this->data->owner) { - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - this->data->owner->Attach(this->data->clients[i]); - this->data->clients[i] = 0; + this->data->owner->Attach(this->clients[i]); + this->clients[i] = 0; } } else { - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - this->data->clients[i]->Disconnect(); - this->data->clients[i] = 0; + this->clients[i]->Disconnect(); + this->clients[i] = 0; } } this->clientCount = 0; @@ -124,12 +123,12 @@ NetClient NetworkSession::Detach(const NetworkClient* client) this->data->clientListLock.lock(); - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i] && this->data->clients[0]->GetID() == client->GetID()) + if(this->clients[i] && this->clients[0]->GetID() == client->GetID()) { - val = this->data->clients[i]; - this->data->clients[i] = 0; + val = this->clients[i]; + this->clients[i] = 0; this->clientCount--; } } @@ -145,12 +144,12 @@ NetClient NetworkSession::Detach(short ID) this->data->clientListLock.lock(); - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i] && this->data->clients[0]->GetID() == ID) + if(this->clients[i] && this->clients[0]->GetID() == ID) { - val = this->data->clients[i]; - this->data->clients[i] = 0; + val = this->clients[i]; + this->clients[i] = 0; this->clientCount--; } } @@ -166,12 +165,12 @@ NetClient NetworkSession::Detach() this->data->clientListLock.lock(); - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i]) + if(this->clients[i]) { - val = this->data->clients[i]; - this->data->clients[i] = 0; + val = this->clients[i]; + this->clients[i] = 0; this->clientCount--; break; } @@ -185,11 +184,11 @@ NetClient NetworkSession::Detach() bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol) { bool returnValue = false; - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i]) + if(this->clients[i]) { - this->data->clients[i]->Send(&protocol); + this->clients[i]->Send(&protocol); returnValue = true; } } @@ -199,11 +198,11 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol) bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID) { - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i] && this->data->clients[i]->GetID() == ID) + if(this->clients[i] && this->clients[i]->GetID() == ID) { - this->data->clients[i]->Send(&protocol); + this->clients[i]->Send(&protocol); return true; } } @@ -214,17 +213,17 @@ void NetworkSession::CloseSession(bool dissconnectClients) { this->data->clientListLock.lock(); - for (unsigned int i = 0; i < this->data->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->data->clients[i]) + if(this->clients[i]) { - if(dissconnectClients) this->data->clients[i]->Disconnect(); - else if(this->data->owner) this->data->owner->Attach(this->data->clients[i]); - else this->data->clients[i]->Disconnect(); //Idiot check, clients have to go somewhere.. + if(dissconnectClients) this->clients[i]->Disconnect(); + else if(this->data->owner) this->data->owner->Attach(this->clients[i]); + else this->clients[i]->Disconnect(); //Idiot check, clients have to go somewhere.. } } - this->data->clients.Clear(); + this->clients.Clear(); this->clientCount = 0; this->data->clientListLock.unlock(); diff --git a/Code/Network/NetworkAPI/NetworkSession.h b/Code/Network/NetworkAPI/NetworkSession.h index ffe047a4..b44f5c61 100644 --- a/Code/Network/NetworkAPI/NetworkSession.h +++ b/Code/Network/NetworkAPI/NetworkSession.h @@ -6,6 +6,9 @@ //warning C4150: deletion of pointer to incomplete type, no destructor called #pragma warning(disable : 4150) +//needs to have dll-interface to be used by clients of class 'Oyster::Network::NetworkSession' +#pragma warning(disable : 4251) + #include "NetworkAPI_Preprocessor.h" #include "NetworkServerEventStruct.h" @@ -18,6 +21,7 @@ namespace Oyster namespace Network { typedef Utility::DynamicMemory::SmartPointer NetClient; + typedef Utility::DynamicMemory::DynamicArray NetClientList; class NET_API_EXPORT NetworkSession { public: @@ -92,6 +96,9 @@ namespace Oyster */ virtual void ClientEventCallback(NetEvent e) = 0; + protected: + NetClientList clients; + private: int clientCount; struct PrivateSessionData;