GL - merge with gameserver, crash on collision in gameLogic
This commit is contained in:
commit
3f144289ec
|
@ -186,6 +186,8 @@
|
||||||
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
|
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
|
||||||
<ClCompile Include="LobbySessions\GameLobby.cpp" />
|
<ClCompile Include="LobbySessions\GameLobby.cpp" />
|
||||||
<ClCompile Include="GameSession\GameSession_Logic.cpp" />
|
<ClCompile Include="GameSession\GameSession_Logic.cpp" />
|
||||||
|
<ClCompile Include="LobbySessions\LobbyGeneralProtocolParser.cpp" />
|
||||||
|
<ClCompile Include="LobbySessions\LobbyProtocolParser.cpp" />
|
||||||
<ClCompile Include="LobbySessions\MainLobby.cpp" />
|
<ClCompile Include="LobbySessions\MainLobby.cpp" />
|
||||||
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
|
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -76,10 +76,6 @@ namespace DanBias
|
||||||
case protocol_General_Status:
|
case protocol_General_Status:
|
||||||
switch (p[1].value.netInt)
|
switch (p[1].value.netInt)
|
||||||
{
|
{
|
||||||
case GameLogic::Protocol_General_Status::States_bussy:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GameLogic::Protocol_General_Status::States_disconected:
|
case GameLogic::Protocol_General_Status::States_disconected:
|
||||||
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
|
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
|
||||||
this->RemoveClient(c);
|
this->RemoveClient(c);
|
||||||
|
@ -92,12 +88,19 @@ namespace DanBias
|
||||||
case GameLogic::Protocol_General_Status::States_ready:
|
case GameLogic::Protocol_General_Status::States_ready:
|
||||||
|
|
||||||
break;
|
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;
|
break;
|
||||||
|
|
||||||
case protocol_General_Text:
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,15 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
return this->box;
|
return this->box;
|
||||||
}
|
}
|
||||||
|
void MainLobby::SetRefreshFrequency(float delta)
|
||||||
|
{
|
||||||
|
this->refreshFrequency = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
float MainLobby::GetRefreshFrequency() const
|
||||||
|
{
|
||||||
|
return this->refreshFrequency;
|
||||||
|
}
|
||||||
//////// Private
|
//////// Private
|
||||||
void MainLobby::ParseEvents()
|
void MainLobby::ParseEvents()
|
||||||
{
|
{
|
||||||
|
@ -44,67 +52,11 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
NetEvent &e = this->box->Fetch();
|
NetEvent &e = this->box->Fetch();
|
||||||
|
|
||||||
ParseProtocol(e.protocol, e.sender);
|
short type = e.protocol[0].value.netShort;
|
||||||
|
|
||||||
|
if(ProtocolIsLobby(type)) ParseLobbyProtocol(e.protocol, e.sender);
|
||||||
|
else if(ProtocolIsGeneral(type)) ParseGeneralProtocol(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
}//End namespace DanBias
|
|
@ -8,6 +8,7 @@
|
||||||
#include "GameLobby.h"
|
#include "GameLobby.h"
|
||||||
#include <Protocols.h>
|
#include <Protocols.h>
|
||||||
#include <PostBox\IPostBox.h>
|
#include <PostBox\IPostBox.h>
|
||||||
|
#include <WinTimer.h>
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
|
@ -20,20 +21,26 @@ namespace DanBias
|
||||||
|
|
||||||
void Frame();
|
void Frame();
|
||||||
|
|
||||||
|
void SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box);
|
||||||
Oyster::IPostBox<NetworkSession::NetEvent>* GetPostbox();
|
Oyster::IPostBox<NetworkSession::NetEvent>* GetPostbox();
|
||||||
|
|
||||||
|
void SetRefreshFrequency(float delta);
|
||||||
|
float GetRefreshFrequency() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ParseEvents();
|
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 CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c);
|
||||||
void JoinLobby(GameLogic::Protocol_LobbyJoinLobby& p, DanBias::LobbyClient* c);
|
void JoinLobby(GameLogic::Protocol_LobbyJoin& p, DanBias::LobbyClient* c);
|
||||||
|
|
||||||
void SendUpdate();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Oyster::IPostBox<NetworkSession::NetEvent> *box;
|
Oyster::IPostBox<NetworkSession::NetEvent> *box;
|
||||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameLobby>> gameLobby;
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameLobby>> gameLobby;
|
||||||
|
Utility::WinTimer timer;
|
||||||
|
float refreshFrequency;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class AdminInterface;
|
friend class AdminInterface;
|
||||||
|
|
|
@ -154,7 +154,7 @@
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="ControlProtocols.h" />
|
<ClInclude Include="GeneralProtocols.h" />
|
||||||
<ClInclude Include="GameplayProtocols.h" />
|
<ClInclude Include="GameplayProtocols.h" />
|
||||||
<ClInclude Include="Protocols.h" />
|
<ClInclude Include="Protocols.h" />
|
||||||
<ClInclude Include="LobbyProtocols.h" />
|
<ClInclude Include="LobbyProtocols.h" />
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H
|
#ifndef GAMELOGIC_GENERAL_PROTOCOLS_H
|
||||||
#define GAMELOGIC_CONTROL_PROTOCOLS_H
|
#define GAMELOGIC_GENERAL_PROTOCOLS_H
|
||||||
|
|
||||||
#include <CustomNetProtocol.h>
|
#include <CustomNetProtocol.h>
|
||||||
#include "ProtocolIdentificationID.h"
|
#include "ProtocolIdentificationID.h"
|
||||||
|
@ -12,9 +12,8 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
States_ready,
|
States_ready,
|
||||||
States_idle,
|
States_idle,
|
||||||
States_bussy,
|
|
||||||
State_waiting,
|
|
||||||
States_disconected,
|
States_disconected,
|
||||||
|
States_leave
|
||||||
};
|
};
|
||||||
States status;
|
States status;
|
||||||
|
|
||||||
|
@ -25,6 +24,11 @@ namespace GameLogic
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
|
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)
|
Protocol_General_Status(States state)
|
||||||
{
|
{
|
||||||
this->protocol[protocol_INDEX_ID].value = protocol_General_Status;
|
this->protocol[protocol_INDEX_ID].value = protocol_General_Status;
|
||||||
|
@ -45,18 +49,21 @@ namespace GameLogic
|
||||||
|
|
||||||
struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject
|
struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
char* text;
|
std::string text; //The text to send
|
||||||
int destination;
|
int destination; //The destination if any (Ie a whisper to a player)
|
||||||
|
|
||||||
Protocol_General_Text()
|
Protocol_General_Text()
|
||||||
|
: destination(-1) {}
|
||||||
|
Protocol_General_Text(Oyster::Network::CustomNetProtocol& p)
|
||||||
{
|
{
|
||||||
this->protocol[protocol_INDEX_ID].value = protocol_General_Text;
|
destination = p.Get(1).value.netInt;
|
||||||
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
text = p.Get(2).value.netCharPtr;
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
|
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
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;
|
return &protocol;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,8 @@
|
||||||
#include <CustomNetProtocol.h>
|
#include <CustomNetProtocol.h>
|
||||||
#include "ProtocolIdentificationID.h"
|
#include "ProtocolIdentificationID.h"
|
||||||
|
|
||||||
//#define protocol_Lobby_CreateGame 200
|
#include <DynamicArray.h>
|
||||||
//#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
|
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
@ -25,7 +21,7 @@ namespace GameLogic
|
||||||
|
|
||||||
Protocol_LobbyCreateGame()
|
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[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
|
@ -53,7 +49,7 @@ namespace GameLogic
|
||||||
|
|
||||||
Protocol_LobbyStartGame()
|
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[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
|
||||||
|
@ -68,20 +64,18 @@ namespace GameLogic
|
||||||
Oyster::Network::CustomNetProtocol protocol;
|
Oyster::Network::CustomNetProtocol protocol;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject
|
struct Protocol_LobbyLogin :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
char gameId;
|
// Login stuff
|
||||||
|
Protocol_LobbyLogin()
|
||||||
Protocol_LobbyJoinGame()
|
|
||||||
{
|
{
|
||||||
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[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
|
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
||||||
{
|
{
|
||||||
protocol[1].value = gameId;
|
|
||||||
return &protocol;
|
return &protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,42 +83,26 @@ namespace GameLogic
|
||||||
Oyster::Network::CustomNetProtocol protocol;
|
Oyster::Network::CustomNetProtocol protocol;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Protocol_LobbyJoinLobby :public Oyster::Network::CustomProtocolObject
|
struct Protocol_LobbyJoin :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
int LobbyID;
|
short value;
|
||||||
Protocol_LobbyJoinLobby(int id = -1)
|
|
||||||
{
|
|
||||||
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinLobby;
|
|
||||||
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
|
Protocol_LobbyJoin()
|
||||||
LobbyID = id;
|
|
||||||
}
|
|
||||||
Protocol_LobbyJoinLobby(Oyster::Network::CustomNetProtocol& o)
|
|
||||||
{
|
{
|
||||||
LobbyID = o[1].value.netInt;
|
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join;
|
||||||
}
|
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
||||||
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
|
||||||
{
|
}
|
||||||
this->protocol[1].value = LobbyID;
|
Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p)
|
||||||
|
{
|
||||||
return &protocol;
|
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;
|
||||||
private:
|
value = p[1].value.netShort;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
||||||
{
|
{
|
||||||
|
protocol[1].value = value;
|
||||||
return &protocol;
|
return &protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,48 +112,74 @@ namespace GameLogic
|
||||||
|
|
||||||
struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject
|
struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
struct LobbyUpdateData
|
|
||||||
{
|
|
||||||
std::string mapName;
|
|
||||||
int LobbyId;
|
|
||||||
};
|
|
||||||
int count;
|
|
||||||
LobbyUpdateData* data;
|
|
||||||
Protocol_LobbyRefresh()
|
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<PlayerData> list;
|
||||||
|
|
||||||
|
Protocol_LobbyGameData()
|
||||||
|
{
|
||||||
|
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData;
|
||||||
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
|
list.Reserve(10);
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
||||||
{
|
{
|
||||||
this->protocol[1].value.netInt = count;
|
int a = 1;
|
||||||
for (int i = 2; i < count; i++)
|
for (unsigned int i = 0; i < list.Size(); i++)
|
||||||
{
|
{
|
||||||
protocol[i].type = Oyster::Network::NetAttributeType_CharArray;
|
this->protocol[a].type = Oyster::Network::NetAttributeType_Int;
|
||||||
protocol[i+1].type = Oyster::Network::NetAttributeType_Int;
|
this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray;
|
||||||
|
|
||||||
protocol[i].value.netCharPtr = const_cast<char*>(data[i-2].mapName.c_str());
|
this->protocol[a].value = list[i].id;
|
||||||
protocol[i+1].value.netInt = data[i-1].LobbyId;
|
this->protocol.Set(a, list[i].name);
|
||||||
}
|
}
|
||||||
return &protocol;
|
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:
|
private:
|
||||||
Oyster::Network::CustomNetProtocol protocol;
|
Oyster::Network::CustomNetProtocol protocol;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,17 +4,6 @@
|
||||||
#include <CustomNetProtocol.h>
|
#include <CustomNetProtocol.h>
|
||||||
#include "ProtocolIdentificationID.h"
|
#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
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
struct Protocol_ObjectPickup :public Oyster::Network::CustomProtocolObject
|
struct Protocol_ObjectPickup :public Oyster::Network::CustomProtocolObject
|
||||||
|
|
|
@ -8,13 +8,16 @@
|
||||||
|
|
||||||
#include <CustomNetProtocol.h>
|
#include <CustomNetProtocol.h>
|
||||||
#include "ProtocolIdentificationID.h"
|
#include "ProtocolIdentificationID.h"
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
|
//protocol_Gameplay_PlayerMovement 300
|
||||||
|
//protocol_Gameplay_PlayerMouseMovement 301
|
||||||
|
//protocol_Gameplay_PlayerChangeWeapon 302
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject
|
struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
|
|
||||||
bool bForward;
|
bool bForward;
|
||||||
bool bBackward;
|
bool bBackward;
|
||||||
bool bLeft;
|
bool bLeft;
|
||||||
|
@ -116,63 +119,6 @@ namespace GameLogic
|
||||||
Oyster::Network::CustomNetProtocol protocol;
|
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
|
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#define protocol_GeneralMIN 100
|
#define protocol_GeneralMIN 100
|
||||||
#define protocol_General_Status 100
|
#define protocol_General_Status 100
|
||||||
#define protocol_General_Text 101
|
#define protocol_General_Text 101
|
||||||
#define protocol_General_Disconnect 102
|
|
||||||
#define protocol_General_Login 110
|
|
||||||
#define protocol_GeneralMAX 199
|
#define protocol_GeneralMAX 199
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,12 +32,13 @@
|
||||||
/********* LOBBY PROTOCOLS ***************************************************************************************************/
|
/********* LOBBY PROTOCOLS ***************************************************************************************************/
|
||||||
/***********[ 200 - 299 ]***********/
|
/***********[ 200 - 299 ]***********/
|
||||||
#define protocol_LobbyMIN 200
|
#define protocol_LobbyMIN 200
|
||||||
#define protocol_Lobby_CreateGame 200
|
#define protocol_Lobby_Create 200
|
||||||
#define protocol_Lobby_StartGame 201
|
#define protocol_Lobby_Start 201
|
||||||
#define protocol_Lobby_JoinGame 202
|
#define protocol_Lobby_Join 202
|
||||||
#define protocol_Lobby_JoinLobby 203
|
#define protocol_Lobby_Login 203
|
||||||
#define protocol_Lobby_LeaveLobby 204
|
#define protocol_Lobby_Refresh 204
|
||||||
#define protocol_Lobby_Refresh 205
|
#define protocol_Lobby_MainData 205
|
||||||
|
#define protocol_Lobby_GameData 206
|
||||||
#define protocol_LobbyMAX 299
|
#define protocol_LobbyMAX 299
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "ObjectProtocols.h"
|
#include "ObjectProtocols.h"
|
||||||
#include "PlayerProtocols.h"
|
#include "PlayerProtocols.h"
|
||||||
#include "LobbyProtocols.h"
|
#include "LobbyProtocols.h"
|
||||||
#include "ControlProtocols.h"
|
#include "GeneralProtocols.h"
|
||||||
#include "GameplayProtocols.h"
|
#include "GameplayProtocols.h"
|
||||||
|
|
||||||
#endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H
|
#endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H
|
||||||
|
|
|
@ -51,7 +51,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
|
||||||
|
|
||||||
serverThread = std::thread(ServerFnc);
|
serverThread = std::thread(ServerFnc);
|
||||||
|
|
||||||
Sleep(100);
|
Sleep(200);
|
||||||
|
|
||||||
clientThread = std::thread(ClientFnc);
|
clientThread = std::thread(ClientFnc);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ struct CustomNetProtocol::PrivateData
|
||||||
if(size == 0) continue;
|
if(size == 0) continue;
|
||||||
|
|
||||||
attributes[i->first].value.netCharPtr = new char[size + 1];
|
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);
|
memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1);
|
||||||
attributes[i->first].type = NetAttributeType_CharArray;
|
attributes[i->first].type = NetAttributeType_CharArray;
|
||||||
}
|
}
|
||||||
|
@ -49,8 +48,8 @@ struct CustomNetProtocol::PrivateData
|
||||||
switch (i->second.type)
|
switch (i->second.type)
|
||||||
{
|
{
|
||||||
case NetAttributeType_CharArray:
|
case NetAttributeType_CharArray:
|
||||||
//delete [] i->second.value.netCharPtr;
|
delete [] i->second.value.netCharPtr;
|
||||||
i->second.value.netCharPtr = 0;
|
//i->second.value.netCharPtr = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,3 +87,38 @@ NetAttributeContainer& CustomNetProtocol::operator[](int ID)
|
||||||
|
|
||||||
return this->privateData->attributes[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];
|
||||||
|
}
|
|
@ -87,6 +87,9 @@ namespace Oyster
|
||||||
const CustomNetProtocol& operator=(const CustomNetProtocol& o);
|
const CustomNetProtocol& operator=(const CustomNetProtocol& o);
|
||||||
|
|
||||||
NetAttributeContainer& operator[](int ID);
|
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:
|
private:
|
||||||
struct PrivateData;
|
struct PrivateData;
|
||||||
|
|
Loading…
Reference in New Issue