GameServer - Added acces directly to clients in network session

This commit is contained in:
Dennis Andersen 2014-01-30 14:15:25 +01:00
parent 2a69af5c9f
commit 09f39ec26d
11 changed files with 199 additions and 127 deletions

View File

@ -19,8 +19,8 @@ namespace GameLogic
Protocol_General_Status() Protocol_General_Status()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_General_Status; this->protocol[0].value = protocol_General_Status;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
} }
@ -31,8 +31,8 @@ namespace GameLogic
} }
Protocol_General_Status(States state) Protocol_General_Status(States state)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_General_Status; this->protocol[0].value = protocol_General_Status;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->status = state; this->status = state;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
} }
@ -61,7 +61,7 @@ namespace GameLogic
} }
Oyster::Network::CustomNetProtocol* GetProtocol() override 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(1, destination, Oyster::Network::NetAttributeType_Int);
this->protocol.Set(2, text); this->protocol.Set(2, text);
return &protocol; return &protocol;

View File

@ -22,8 +22,8 @@ namespace GameLogic
Protocol_LobbyCreateGame() Protocol_LobbyCreateGame()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Create; this->protocol[0].value = protocol_Lobby_Create;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
this->protocol[2].type = Oyster::Network::NetAttributeType_Char; this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
@ -50,8 +50,8 @@ namespace GameLogic
Protocol_LobbyStartGame() Protocol_LobbyStartGame()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Start; this->protocol[0].value = protocol_Lobby_Start;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
} }
@ -74,8 +74,8 @@ namespace GameLogic
// Login stuff // Login stuff
Protocol_LobbyLogin() Protocol_LobbyLogin()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; this->protocol[0].value = protocol_Lobby_Join;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
} }
@ -98,14 +98,14 @@ namespace GameLogic
// //
// Protocol_LobbyJoin() // Protocol_LobbyJoin()
// { // {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; // this->protocol[0].value = protocol_Lobby_Join;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; // this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// } // }
// Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p) // Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p)
// { // {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Join; // this->protocol[0].value = protocol_Lobby_Join;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; // this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// value = p[1].value.netShort; // value = p[1].value.netShort;
// } // }
@ -123,8 +123,8 @@ namespace GameLogic
{ {
Protocol_LobbyRefresh() Protocol_LobbyRefresh()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_Login; this->protocol[0].value = protocol_Lobby_Login;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
} }
Protocol_LobbyRefresh(Oyster::Network::CustomNetProtocol& o) Protocol_LobbyRefresh(Oyster::Network::CustomNetProtocol& o)
{ {
@ -147,35 +147,90 @@ namespace GameLogic
struct PlayerData struct PlayerData
{ {
std::string name; std::string name;
std::string ip;
int id; int id;
int team;
}; };
Utility::DynamicMemory::DynamicArray<PlayerData> list; Utility::DynamicMemory::DynamicArray<PlayerData> list;
Protocol_LobbyClientData() Protocol_LobbyClientData()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData; this->protocol[0].value = protocol_Lobby_ClientData;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_UnsignedInt; //DataType
list.Reserve(10); list.Reserve(10);
} }
Protocol_LobbyClientData(Oyster::Network::CustomNetProtocol& p) Protocol_LobbyClientData(Oyster::Network::CustomNetProtocol& p)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_GameData; unsigned int size = this->protocol[1].value.netUInt;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; list.Reserve(size);
int a = 2;
list.Reserve(10); 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 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++) for (unsigned int i = 0; i < list.Size(); i++)
{ {
this->protocol[a].type = Oyster::Network::NetAttributeType_Int; this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // client-id
this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[a++].value = list[i].id;
this->protocol[a].value = list[i].id; this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // team-id
this->protocol.Set(a, list[i].name); 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<char*>(mapName.c_str());
return &protocol; return &protocol;
} }
@ -192,8 +247,8 @@ namespace GameLogic
// //
// Protocol_LobbyMainData() // Protocol_LobbyMainData()
// { // {
// this->protocol[protocol_INDEX_ID].value = protocol_Lobby_MainData; // this->protocol[0].value = protocol_Lobby_MainData;
// this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; // this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
// //
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short; // this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// } // }

View File

@ -13,8 +13,8 @@ namespace GameLogic
Protocol_ObjectPickup() Protocol_ObjectPickup()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPickup; this->protocol[0].value = protocol_Gameplay_ObjectPickup;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Short; this->protocol[2].type = Oyster::Network::NetAttributeType_Short;
@ -28,8 +28,8 @@ namespace GameLogic
} }
Protocol_ObjectPickup(int objectID, short pickupID) Protocol_ObjectPickup(int objectID, short pickupID)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; this->protocol[0].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Short; this->protocol[2].type = Oyster::Network::NetAttributeType_Short;
@ -56,8 +56,8 @@ namespace GameLogic
Protocol_ObjectDamage() Protocol_ObjectDamage()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage; this->protocol[0].value = protocol_Gameplay_ObjectDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -71,8 +71,8 @@ namespace GameLogic
} }
Protocol_ObjectDamage(int id, float hp) Protocol_ObjectDamage(int id, float hp)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDamage; this->protocol[0].value = protocol_Gameplay_ObjectDamage;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -97,8 +97,8 @@ namespace GameLogic
Protocol_ObjectPosition() Protocol_ObjectPosition()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; this->protocol[0].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -115,8 +115,8 @@ namespace GameLogic
} }
Protocol_ObjectPosition(float m[16], int id) Protocol_ObjectPosition(float m[16], int id)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition; this->protocol[0].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -149,8 +149,8 @@ namespace GameLogic
Protocol_ObjectEnable() Protocol_ObjectEnable()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; this->protocol[0].value = protocol_Gameplay_ObjectEnabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -167,8 +167,8 @@ namespace GameLogic
} }
Protocol_ObjectEnable(float m[16], int id) Protocol_ObjectEnable(float m[16], int id)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectEnabled; this->protocol[0].value = protocol_Gameplay_ObjectEnabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
@ -199,8 +199,8 @@ namespace GameLogic
Protocol_ObjectDisable() Protocol_ObjectDisable()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].value = protocol_Gameplay_ObjectDisabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -211,8 +211,8 @@ namespace GameLogic
} }
Protocol_ObjectDisable(int id, float time) Protocol_ObjectDisable(int id, float time)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].value = protocol_Gameplay_ObjectDisabled;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -239,8 +239,8 @@ namespace GameLogic
Protocol_ObjectCreate() Protocol_ObjectCreate()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[0].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
@ -256,8 +256,8 @@ namespace GameLogic
} }
Protocol_ObjectCreate(float m[16], int id, char *path) Protocol_ObjectCreate(float m[16], int id, char *path)
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectCreate; this->protocol[0].value = protocol_Gameplay_ObjectCreate;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; this->protocol[0].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;

View File

@ -25,8 +25,8 @@ namespace GameLogic
Protocol_PlayerMovement() Protocol_PlayerMovement()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMovement; this->protocol[0].value = protocol_Gameplay_PlayerMovement;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; this->protocol[2].type = Oyster::Network::NetAttributeType_Bool;
@ -69,8 +69,8 @@ namespace GameLogic
Protocol_PlayerLook() Protocol_PlayerLook()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerLookDir; this->protocol[0].value = protocol_Gameplay_PlayerLookDir;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -109,8 +109,8 @@ namespace GameLogic
Protocol_PlayerChangeWeapon() Protocol_PlayerChangeWeapon()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerChangeWeapon; this->protocol[0].value = protocol_Gameplay_PlayerChangeWeapon;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -140,8 +140,8 @@ namespace GameLogic
Protocol_PlayerShot() Protocol_PlayerShot()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerShot; this->protocol[0].value = protocol_Gameplay_PlayerShot;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
} }
@ -170,8 +170,8 @@ namespace GameLogic
Protocol_PlayerJump() Protocol_PlayerJump()
{ {
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerJump; this->protocol[0].value = protocol_Gameplay_PlayerJump;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
} }

View File

@ -8,11 +8,6 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ /* 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 ***************************************************************************************************/ /********* RESERVERD PROTOCOLS ***************************************************************************************************/
/********** [ 0 - 99 ] *********/ /********** [ 0 - 99 ] *********/
@ -37,7 +32,7 @@
#define protocol_Lobby_Join 202 #define protocol_Lobby_Join 202
#define protocol_Lobby_Login 203 #define protocol_Lobby_Login 203
#define protocol_Lobby_Refresh 204 #define protocol_Lobby_Refresh 204
#define protocol_Lobby_MainData 205 #define protocol_Lobby_ClientData 205
#define protocol_Lobby_GameData 206 #define protocol_Lobby_GameData 206
#define protocol_LobbyMAX 299 #define protocol_LobbyMAX 299

View File

@ -42,8 +42,8 @@ namespace DanBias
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join: //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 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 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 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: private:
void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override; void ClientEventCallback(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override;

View File

@ -52,12 +52,8 @@ namespace DanBias
desc.gameTime = this->description.gameTime; desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber; desc.mapNumber = this->description.mapNumber;
desc.owner = this; desc.owner = this;
while (this->GetClientCount()) desc.clients = this->clients;
{
NetClient c;
if((c = this->Detach()))
desc.clients.Push(c);
}
if(this->gameSession.Create(desc)) if(this->gameSession.Create(desc))
{ {
this->gameSession.Run(); this->gameSession.Run();
@ -89,9 +85,27 @@ namespace DanBias
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
Attach(client); 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 }//End namespace DanBias

View File

@ -23,7 +23,9 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break; break;
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break; 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; break;
//case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); //case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
//break; //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) 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) //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) void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
{ {
//Dont need to handle this on the server... //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::LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c)
{ {
} }
//void GameLobby::LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c)
//{
//
//}

View File

@ -74,7 +74,7 @@ namespace DanBias
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) 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 ); case protocol_Gameplay_PlayerMovement: this->Gameplay_PlayerMovement ( Protocol_PlayerMovement (p), c );
break; break;

View File

@ -16,7 +16,6 @@ using namespace Oyster::Network;
struct NetworkSession::PrivateSessionData struct NetworkSession::PrivateSessionData
{ {
Utility::DynamicMemory::DynamicArray<NetClient> clients;
NetworkClient::ClientEventFunction messageCallback; NetworkClient::ClientEventFunction messageCallback;
std::mutex clientListLock; std::mutex clientListLock;
NetworkSession* owner; //Where clients end up when session is closed. NetworkSession* owner; //Where clients end up when session is closed.
@ -34,7 +33,7 @@ NetworkSession::NetworkSession()
{} {}
NetworkSession::NetworkSession(const NetworkSession& orig) NetworkSession::NetworkSession(const NetworkSession& orig)
{ {
this->data->clients = orig.data->clients; this->clients = orig.clients;
this->data->owner = orig.data->owner; this->data->owner = orig.data->owner;
this->clientCount = orig.clientCount; this->clientCount = orig.clientCount;
this->data->id = orig.data->id; this->data->id = orig.data->id;
@ -43,7 +42,7 @@ NetworkSession::NetworkSession(const NetworkSession& orig)
const NetworkSession& NetworkSession::operator=(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->data->owner = orig.data->owner;
this->clientCount = orig.clientCount; this->clientCount = orig.clientCount;
this->data->id = orig.data->id; this->data->id = orig.data->id;
@ -54,7 +53,7 @@ const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
NetworkSession::~NetworkSession() NetworkSession::~NetworkSession()
{ {
this->data->clients.Clear(); this->clients.Clear();
this->clientCount = 0; this->clientCount = 0;
this->data->messageCallback = 0; this->data->messageCallback = 0;
delete this->data; delete this->data;
@ -63,9 +62,9 @@ NetworkSession::~NetworkSession()
void NetworkSession::ProcessClients() 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(); this->data->clientListLock.lock();
int k = -1; 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; k = i;
} }
if(k == -1) if(k == -1)
{ {
this->data->clients.Push(client); this->clients.Push(client);
} }
else else
{ {
this->data->clients[k] = client; this->clients[k] = client;
} }
this->clientCount++; this->clientCount++;
@ -101,18 +100,18 @@ void NetworkSession::DetachAll()
{ {
if(this->data->owner) 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->owner->Attach(this->clients[i]);
this->data->clients[i] = 0; this->clients[i] = 0;
} }
} }
else 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->clients[i]->Disconnect();
this->data->clients[i] = 0; this->clients[i] = 0;
} }
} }
this->clientCount = 0; this->clientCount = 0;
@ -124,12 +123,12 @@ NetClient NetworkSession::Detach(const NetworkClient* client)
this->data->clientListLock.lock(); 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]; val = this->clients[i];
this->data->clients[i] = 0; this->clients[i] = 0;
this->clientCount--; this->clientCount--;
} }
} }
@ -145,12 +144,12 @@ NetClient NetworkSession::Detach(short ID)
this->data->clientListLock.lock(); 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]; val = this->clients[i];
this->data->clients[i] = 0; this->clients[i] = 0;
this->clientCount--; this->clientCount--;
} }
} }
@ -166,12 +165,12 @@ NetClient NetworkSession::Detach()
this->data->clientListLock.lock(); 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]; val = this->clients[i];
this->data->clients[i] = 0; this->clients[i] = 0;
this->clientCount--; this->clientCount--;
break; break;
} }
@ -185,11 +184,11 @@ NetClient NetworkSession::Detach()
bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol) bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
{ {
bool returnValue = false; 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; returnValue = true;
} }
} }
@ -199,11 +198,11 @@ bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID) 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; return true;
} }
} }
@ -214,17 +213,17 @@ void NetworkSession::CloseSession(bool dissconnectClients)
{ {
this->data->clientListLock.lock(); 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(); if(dissconnectClients) this->clients[i]->Disconnect();
else if(this->data->owner) this->data->owner->Attach(this->data->clients[i]); else if(this->data->owner) this->data->owner->Attach(this->clients[i]);
else this->data->clients[i]->Disconnect(); //Idiot check, clients have to go somewhere.. else this->clients[i]->Disconnect(); //Idiot check, clients have to go somewhere..
} }
} }
this->data->clients.Clear(); this->clients.Clear();
this->clientCount = 0; this->clientCount = 0;
this->data->clientListLock.unlock(); this->data->clientListLock.unlock();

View File

@ -6,6 +6,9 @@
//warning C4150: deletion of pointer to incomplete type, no destructor called //warning C4150: deletion of pointer to incomplete type, no destructor called
#pragma warning(disable : 4150) #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 "NetworkAPI_Preprocessor.h"
#include "NetworkServerEventStruct.h" #include "NetworkServerEventStruct.h"
@ -18,6 +21,7 @@ namespace Oyster
namespace Network namespace Network
{ {
typedef Utility::DynamicMemory::SmartPointer<NetworkClient> NetClient; typedef Utility::DynamicMemory::SmartPointer<NetworkClient> NetClient;
typedef Utility::DynamicMemory::DynamicArray<NetClient> NetClientList;
class NET_API_EXPORT NetworkSession class NET_API_EXPORT NetworkSession
{ {
public: public:
@ -92,6 +96,9 @@ namespace Oyster
*/ */
virtual void ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0; virtual void ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0;
protected:
NetClientList clients;
private: private:
int clientCount; int clientCount;
struct PrivateSessionData; struct PrivateSessionData;