Added final protocols, and a bit of support for them on server side

This commit is contained in:
Dennis Andersen 2014-01-22 15:22:52 +01:00
parent 8792aab992
commit 22a5db97f8
17 changed files with 288 additions and 237 deletions

View File

@ -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

View File

@ -186,6 +186,8 @@
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
<ClCompile Include="LobbySessions\GameLobby.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\NetworkSession.cpp" />
</ItemGroup>

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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)));
}

View File

@ -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);
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

View File

@ -8,6 +8,7 @@
#include "GameLobby.h"
#include <Protocols.h>
#include <PostBox\IPostBox.h>
#include <WinTimer.h>
namespace DanBias
{
@ -20,20 +21,26 @@ namespace DanBias
void Frame();
void SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box);
Oyster::IPostBox<NetworkSession::NetEvent>* 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<NetworkSession::NetEvent> *box;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameLobby>> gameLobby;
Utility::WinTimer timer;
float refreshFrequency;
private:
friend class AdminInterface;

View File

@ -154,7 +154,7 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ControlProtocols.h" />
<ClInclude Include="GeneralProtocols.h" />
<ClInclude Include="GameplayProtocols.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="LobbyProtocols.h" />

View File

@ -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 <CustomNetProtocol.h>
#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;
}

View File

@ -9,12 +9,8 @@
#include <CustomNetProtocol.h>
#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 <DynamicArray.h>
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<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[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<char*>(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;
};

View File

@ -4,17 +4,6 @@
#include <CustomNetProtocol.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
{
struct Protocol_ObjectPickup :public Oyster::Network::CustomProtocolObject

View File

@ -8,13 +8,16 @@
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
#include <bitset>
//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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;
}
}
@ -88,3 +87,38 @@ 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];
}

View File

@ -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;