diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index e2e81cf5..9093654c 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -107,7 +107,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 ++; obj = new C_DynamicObj(); @@ -162,6 +162,10 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI movePlayer.bForward = true; send = true; key_forward = true; + + GameLogic::Protocol_General_Text tp; + tp.text = "What!?"; + this->privData->nwClient->Send(tp); } } else diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index b491c65e..74223981 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -186,6 +186,8 @@ + + diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index c14b8e41..5dac3c3e 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -76,10 +76,6 @@ namespace DanBias case protocol_General_Status: switch (p[1].value.netInt) { - case GameLogic::Protocol_General_Status::States_bussy: - - break; - case GameLogic::Protocol_General_Status::States_disconected: printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); this->RemoveClient(c); @@ -92,12 +88,19 @@ namespace DanBias case GameLogic::Protocol_General_Status::States_ready: break; + + case GameLogic::Protocol_General_Status::States_leave: + + break; } break; - case protocol_General_Text: - + { + GameLogic::Protocol_General_Text temp(p); + printf("Message recieved from (%i):\t %s\n", c->GetID(), temp.text.c_str()); + } break; + } } diff --git a/Code/Game/DanBiasServer/LobbySessions/LobbyGeneralProtocolParser.cpp b/Code/Game/DanBiasServer/LobbySessions/LobbyGeneralProtocolParser.cpp new file mode 100644 index 00000000..cb19336f --- /dev/null +++ b/Code/Game/DanBiasServer/LobbySessions/LobbyGeneralProtocolParser.cpp @@ -0,0 +1,64 @@ +#include "MainLobby.h" +#include "LobbyClient.h" + +using namespace DanBias; +using namespace GameLogic; + +void MainLobby::ParseGeneralProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c) +{ + switch (p[0].value.netShort) + { + case protocol_General_Status: + { + GeneralStatus(GameLogic::Protocol_General_Status(p), c); + } break; + case protocol_General_Text: + { + GameLogic::Protocol_General_Text(p); + } break; + case protocol_Lobby_Login: + { + + } break; + case protocol_Lobby_Join: + { + JoinLobby(GameLogic::Protocol_LobbyJoin(p), c); + } break; + } +} + +void MainLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, DanBias::LobbyClient* c) +{ + switch (p.status) + { + case Protocol_General_Status::States_ready: + { + + } + case Protocol_General_Status::States_idle: + { + + } + case Protocol_General_Status::States_leave: + { + + } + case Protocol_General_Status::States_disconected: + { + Detach(c)->Disconnect(); + } + } +} + +void MainLobby::JoinLobby(GameLogic::Protocol_LobbyJoin& p, DanBias::LobbyClient* c) +{ + for (unsigned int i = 0; i < this->gameLobby.Size(); i++) + { + if (this->gameLobby[i]->GetID() == p.value) + { + this->gameLobby[i]->Attach(Detach(c)); + return; + } + } +} + diff --git a/Code/Game/DanBiasServer/LobbySessions/LobbyProtocolParser.cpp b/Code/Game/DanBiasServer/LobbySessions/LobbyProtocolParser.cpp new file mode 100644 index 00000000..27aade71 --- /dev/null +++ b/Code/Game/DanBiasServer/LobbySessions/LobbyProtocolParser.cpp @@ -0,0 +1,37 @@ +#include "MainLobby.h" + +using namespace DanBias; + +void MainLobby::ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c) +{ + switch (p[0].value.netShort) + { + case protocol_Lobby_Create: + CreateGame(GameLogic::Protocol_LobbyCreateGame(p), c); + break; + + case protocol_Lobby_Start: + + break; + + case protocol_Lobby_Refresh: + GameLogic::Protocol_LobbyRefresh(); + break; + } +} + +void MainLobby::CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c) +{ + for (unsigned int i = 0; i < this->gameLobby.Size(); i++) + { + if(!gameLobby[i]) + { + gameLobby[i] = new GameLobby(NetworkSession::Detach(c)); + return; + } + } + + this->gameLobby.Push(new GameLobby(NetworkSession::Detach(c))); +} + + diff --git a/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp b/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp index ffdfa62e..ef5765c7 100644 --- a/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp +++ b/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp @@ -36,7 +36,15 @@ namespace DanBias { return this->box; } + void MainLobby::SetRefreshFrequency(float delta) + { + this->refreshFrequency = delta; + } + float MainLobby::GetRefreshFrequency() const + { + return this->refreshFrequency; + } //////// Private void MainLobby::ParseEvents() { @@ -44,67 +52,11 @@ namespace DanBias { NetEvent &e = this->box->Fetch(); - ParseProtocol(e.protocol, e.sender); - - } - } - void MainLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c) - { - bool update = false; - switch (p[0].value.netShort) - { - case protocol_Lobby_CreateGame: - { - GameLogic::Protocol_LobbyCreateGame val(p); - CreateGame(val, c); - update = true; - } - break; - case protocol_Lobby_JoinLobby: - { - GameLogic::Protocol_LobbyJoinLobby val(p); - JoinLobby(val, c); - } - break; - case protocol_Lobby_LeaveLobby: - { - Detach(c)->Disconnect(); - } - break; - } + short type = e.protocol[0].value.netShort; - if(update) SendUpdate(); - } - - void MainLobby::CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c) - { - for (unsigned int i = 0; i < this->gameLobby.Size(); i++) - { - if(!gameLobby[i]) - { - gameLobby[i] = new GameLobby(NetworkSession::Detach(c)); - return; - } + if(ProtocolIsLobby(type)) ParseLobbyProtocol(e.protocol, e.sender); + else if(ProtocolIsGeneral(type)) ParseGeneralProtocol(e.protocol, e.sender); } - - this->gameLobby.Push(new GameLobby(NetworkSession::Detach(c))); - } - void MainLobby::JoinLobby(GameLogic::Protocol_LobbyJoinLobby& p, DanBias::LobbyClient* c) - { - for (unsigned int i = 0; i < this->gameLobby.Size(); i++) - { - if (this->gameLobby[i]->GetID() == p.LobbyID) - { - this->gameLobby[i]->Attach(Detach(c)); - return; - } - } - } - - void MainLobby::SendUpdate() - { - //Send Lobbys - GameLogic::Protocol_LobbyRefresh(); } }//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/LobbySessions/MainLobby.h b/Code/Game/DanBiasServer/LobbySessions/MainLobby.h index a28d90e9..13e1bab5 100644 --- a/Code/Game/DanBiasServer/LobbySessions/MainLobby.h +++ b/Code/Game/DanBiasServer/LobbySessions/MainLobby.h @@ -8,6 +8,7 @@ #include "GameLobby.h" #include #include +#include namespace DanBias { @@ -20,20 +21,26 @@ namespace DanBias void Frame(); + void SetPostbox(Oyster::IPostBox* box); Oyster::IPostBox* GetPostbox(); + void SetRefreshFrequency(float delta); + float GetRefreshFrequency() const; + private: void ParseEvents(); - void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c); + void ParseGeneralProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c); + void ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c); + void GeneralStatus(GameLogic::Protocol_General_Status& p, DanBias::LobbyClient* c); void CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c); - void JoinLobby(GameLogic::Protocol_LobbyJoinLobby& p, DanBias::LobbyClient* c); - - void SendUpdate(); + void JoinLobby(GameLogic::Protocol_LobbyJoin& p, DanBias::LobbyClient* c); private: Oyster::IPostBox *box; Utility::DynamicMemory::DynamicArray> gameLobby; + Utility::WinTimer timer; + float refreshFrequency; private: friend class AdminInterface; diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index e01959b8..a5d5b19f 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,7 +154,7 @@ - + diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/GeneralProtocols.h similarity index 63% rename from Code/Game/GameProtocols/ControlProtocols.h rename to Code/Game/GameProtocols/GeneralProtocols.h index 0aba4dc6..98b7c060 100644 --- a/Code/Game/GameProtocols/ControlProtocols.h +++ b/Code/Game/GameProtocols/GeneralProtocols.h @@ -1,5 +1,5 @@ -#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H -#define GAMELOGIC_CONTROL_PROTOCOLS_H +#ifndef GAMELOGIC_GENERAL_PROTOCOLS_H +#define GAMELOGIC_GENERAL_PROTOCOLS_H #include #include "ProtocolIdentificationID.h" @@ -12,9 +12,8 @@ namespace GameLogic { States_ready, States_idle, - States_bussy, - State_waiting, States_disconected, + States_leave }; States status; @@ -25,6 +24,11 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } + Protocol_General_Status(Oyster::Network::CustomNetProtocol& p) + { + this->protocol = p; + status = (States)p[1].value.netShort; + } Protocol_General_Status(States state) { this->protocol[protocol_INDEX_ID].value = protocol_General_Status; @@ -45,18 +49,21 @@ namespace GameLogic struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject { - char* text; - int destination; + std::string text; //The text to send + int destination; //The destination if any (Ie a whisper to a player) Protocol_General_Text() + : destination(-1) {} + Protocol_General_Text(Oyster::Network::CustomNetProtocol& p) { - this->protocol[protocol_INDEX_ID].value = protocol_General_Text; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray; + destination = p.Get(1).value.netInt; + text = p.Get(2).value.netCharPtr; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value.netCharPtr = text; + this->protocol.Set(protocol_INDEX_ID, 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 ae175691..f043a7a2 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -9,12 +9,8 @@ #include #include "ProtocolIdentificationID.h" -//#define protocol_Lobby_CreateGame 200 -//#define protocol_Lobby_StartGame 201 -//#define protocol_Lobby_JoinGame 202 -//#define protocol_Lobby_JoinLobby 203 -//#define protocol_Lobby_LeaveLobby 204 -//#define protocol_Lobby_Refresh 205 +#include + namespace GameLogic { @@ -25,7 +21,7 @@ namespace GameLogic Protocol_LobbyCreateGame() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_CreateGame; + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Create; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray; @@ -53,7 +49,7 @@ namespace GameLogic Protocol_LobbyStartGame() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_StartGame; + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Start; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Char; @@ -68,20 +64,18 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject + struct Protocol_LobbyLogin :public Oyster::Network::CustomProtocolObject { - char gameId; - - Protocol_LobbyJoinGame() + // Login stuff + Protocol_LobbyLogin() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinGame; + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - protocol[1].value = gameId; return &protocol; } @@ -89,42 +83,26 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_LobbyJoinLobby :public Oyster::Network::CustomProtocolObject + struct Protocol_LobbyJoin :public Oyster::Network::CustomProtocolObject { - int LobbyID; - Protocol_LobbyJoinLobby(int id = -1) - { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinLobby; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + short value; - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - LobbyID = id; - } - Protocol_LobbyJoinLobby(Oyster::Network::CustomNetProtocol& o) + Protocol_LobbyJoin() { - LobbyID = o[1].value.netInt; - } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { - this->protocol[1].value = LobbyID; - - return &protocol; - } - - private: - Oyster::Network::CustomNetProtocol protocol; - }; - - struct Protocol_LobbyLeaveLobby :public Oyster::Network::CustomProtocolObject - { - - Protocol_LobbyLeaveLobby() - { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_LeaveLobby; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + } + Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p) + { + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + value = p[1].value.netShort; } Oyster::Network::CustomNetProtocol* GetProtocol() override { + protocol[1].value = value; return &protocol; } @@ -134,48 +112,74 @@ namespace GameLogic struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject { - struct LobbyUpdateData - { - std::string mapName; - int LobbyId; - }; - int count; - LobbyUpdateData* data; Protocol_LobbyRefresh() { - this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Refresh; + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Login; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { return &protocol; } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + + /** + * A protocol that contains all data to send to client when update game lobby + */ + struct Protocol_LobbyGameData :public Oyster::Network::CustomProtocolObject + { + // Player list + struct PlayerData + { + std::string name; + int id; + }; + Utility::DynamicMemory::DynamicArray list; + + Protocol_LobbyGameData() + { + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData; this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - } - Protocol_LobbyRefresh( Oyster::Network::CustomNetProtocol* p ) - { - count = (*p)[1].value.netInt; - data = new LobbyUpdateData[count]; - for (int i = 0; i < count; i++) - { - //data[i].mapName = (*p)[i].value. - } - } - ~Protocol_LobbyRefresh() - { - delete [] data; - data = 0; + list.Reserve(10); } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value.netInt = count; - for (int i = 2; i < count; i++) + int a = 1; + for (unsigned int i = 0; i < list.Size(); i++) { - protocol[i].type = Oyster::Network::NetAttributeType_CharArray; - protocol[i+1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[a].type = Oyster::Network::NetAttributeType_Int; + this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; - protocol[i].value.netCharPtr = const_cast(data[i-2].mapName.c_str()); - protocol[i+1].value.netInt = data[i-1].LobbyId; + this->protocol[a].value = list[i].id; + this->protocol.Set(a, list[i].name); } return &protocol; } + private: + Oyster::Network::CustomNetProtocol protocol; + }; + /** + * A protocol that contains all data to send to client when update main lobby + */ + struct Protocol_LobbyMainData :public Oyster::Network::CustomProtocolObject + { + // Game instance list + + Protocol_LobbyMainData() + { + this->protocol[protocol_INDEX_ID].value = protocol_Lobby_MainData; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + return &protocol; + } + private: Oyster::Network::CustomNetProtocol protocol; }; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 31452d68..d37aee44 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -4,17 +4,6 @@ #include #include "ProtocolIdentificationID.h" -//protocol_Gameplay_PlayerMovement 300 -//protocol_Gameplay_PlayerMouseMovement 301 -//protocol_Gameplay_PlayerChangeWeapon 302 - -//#define protocol_Gameplay_ObjectPickup 303 -//#define protocol_Gameplay_ObjectDamage 304 -//#define protocol_Gameplay_ObjectPosition 305 -//#define protocol_Gameplay_ObjectEnabled 306 -//#define protocol_Gameplay_ObjectDisabled 307 -//#define protocol_Gameplay_ObjectCreate 308 - namespace GameLogic { struct Protocol_ObjectPickup :public Oyster::Network::CustomProtocolObject diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 36ccf497..b91cb46d 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -8,13 +8,16 @@ #include #include "ProtocolIdentificationID.h" +#include +//protocol_Gameplay_PlayerMovement 300 +//protocol_Gameplay_PlayerMouseMovement 301 +//protocol_Gameplay_PlayerChangeWeapon 302 namespace GameLogic { struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject { - bool bForward; bool bBackward; bool bLeft; @@ -116,63 +119,6 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_PlayerDamage :public Oyster::Network::CustomProtocolObject - { - - int hp; - // look at dir - - Protocol_PlayerDamage() - { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - - } - const Protocol_PlayerDamage& operator=(Oyster::Network::CustomNetProtocol& val) - { - hp = val[1].value.netInt; - return *this; - } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { - this->protocol[1].value =hp; - return &protocol; - } - - private: - Oyster::Network::CustomNetProtocol protocol; - }; - - struct Protocol_PlayerPickup :public Oyster::Network::CustomProtocolObject - { - int pickupID; - - Protocol_PlayerPickup() - { - this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPickup; - this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - - } - const Protocol_PlayerPickup& operator=(Oyster::Network::CustomNetProtocol& val) - { - pickupID = val[3].value.netInt; - - return *this; - } - Oyster::Network::CustomNetProtocol* GetProtocol() override - { - this->protocol[3].value = pickupID; - return &protocol; - } - - private: - Oyster::Network::CustomNetProtocol protocol; - }; - } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 5293093b..7b742eb9 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -25,8 +25,6 @@ #define protocol_GeneralMIN 100 #define protocol_General_Status 100 #define protocol_General_Text 101 -#define protocol_General_Disconnect 102 -#define protocol_General_Login 110 #define protocol_GeneralMAX 199 @@ -34,12 +32,13 @@ /********* LOBBY PROTOCOLS ***************************************************************************************************/ /***********[ 200 - 299 ]***********/ #define protocol_LobbyMIN 200 -#define protocol_Lobby_CreateGame 200 -#define protocol_Lobby_StartGame 201 -#define protocol_Lobby_JoinGame 202 -#define protocol_Lobby_JoinLobby 203 -#define protocol_Lobby_LeaveLobby 204 -#define protocol_Lobby_Refresh 205 +#define protocol_Lobby_Create 200 +#define protocol_Lobby_Start 201 +#define protocol_Lobby_Join 202 +#define protocol_Lobby_Login 203 +#define protocol_Lobby_Refresh 204 +#define protocol_Lobby_MainData 205 +#define protocol_Lobby_GameData 206 #define protocol_LobbyMAX 299 diff --git a/Code/Game/GameProtocols/Protocols.h b/Code/Game/GameProtocols/Protocols.h index 6e084b75..1e7236c8 100644 --- a/Code/Game/GameProtocols/Protocols.h +++ b/Code/Game/GameProtocols/Protocols.h @@ -4,7 +4,7 @@ #include "ObjectProtocols.h" #include "PlayerProtocols.h" #include "LobbyProtocols.h" -#include "ControlProtocols.h" +#include "GeneralProtocols.h" #include "GameplayProtocols.h" #endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H diff --git a/Code/Game/aDanBiasGameLauncher/Launcher.cpp b/Code/Game/aDanBiasGameLauncher/Launcher.cpp index 8f8e6252..c4ff4194 100644 --- a/Code/Game/aDanBiasGameLauncher/Launcher.cpp +++ b/Code/Game/aDanBiasGameLauncher/Launcher.cpp @@ -51,7 +51,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh serverThread = std::thread(ServerFnc); - Sleep(100); + Sleep(200); clientThread = std::thread(ClientFnc); diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index d34832d7..6d4ea1bf 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -23,7 +23,6 @@ struct CustomNetProtocol::PrivateData if(size == 0) continue; attributes[i->first].value.netCharPtr = new char[size + 1]; - //strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr); memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1); attributes[i->first].type = NetAttributeType_CharArray; } @@ -49,8 +48,8 @@ struct CustomNetProtocol::PrivateData switch (i->second.type) { case NetAttributeType_CharArray: - //delete [] i->second.value.netCharPtr; - i->second.value.netCharPtr = 0; + delete [] i->second.value.netCharPtr; + //i->second.value.netCharPtr = 0; break; } } @@ -87,4 +86,39 @@ NetAttributeContainer& CustomNetProtocol::operator[](int ID) } return this->privateData->attributes[ID]; +} + +void CustomNetProtocol::Set(int ID, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type) +{ + this->privateData->attributes[ID].type = type; + + switch (type) + { + case Oyster::Network::NetAttributeType_Bool: + case Oyster::Network::NetAttributeType_Char: + case Oyster::Network::NetAttributeType_UnsignedChar: + case Oyster::Network::NetAttributeType_Short: + case Oyster::Network::NetAttributeType_UnsignedShort: + case Oyster::Network::NetAttributeType_Int: + case Oyster::Network::NetAttributeType_UnsignedInt: + case Oyster::Network::NetAttributeType_Int64: + case Oyster::Network::NetAttributeType_UnsignedInt64: + case Oyster::Network::NetAttributeType_Float: + case Oyster::Network::NetAttributeType_Double: + this->privateData->attributes[ID].value = val; + break; + } +} +void CustomNetProtocol::Set(int ID, std::string s) +{ + if(s.size() == 0) return; + + this->privateData->attributes[ID].type = Oyster::Network::NetAttributeType_CharArray; + + this->privateData->attributes[ID].value.netCharPtr = new char[s.size() + 1]; + memcpy(&this->privateData->attributes[ID].value.netCharPtr[0], &s[0], s.size() + 1); +} +const NetAttributeContainer& CustomNetProtocol::Get(int id) +{ + return this->privateData->attributes[id]; } \ No newline at end of file diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index 82d92c99..85997c51 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -87,6 +87,9 @@ namespace Oyster const CustomNetProtocol& operator=(const CustomNetProtocol& o); NetAttributeContainer& operator[](int ID); + void Set(int id, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type); + void Set(int ID, std::string s); + const NetAttributeContainer& Get(int id); private: struct PrivateData;