Danbias/Code/Game/GameProtocols/LobbyProtocols.h

364 lines
9.6 KiB
C
Raw Normal View History

2013-12-19 12:32:23 +01:00
//////////////////////////////////////////////////////////
// Created 2013 //
// Dennis Andersen, Linda Andersson //
//////////////////////////////////////////////////////////
#ifndef GAMELOGIC_LOBBY_PROTOCOLS_H
#define GAMELOGIC_LOBBY_PROTOCOLS_H
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
#include <DynamicArray.h>
2014-01-21 14:32:42 +01:00
2014-02-05 15:16:31 +01:00
/** OBS!
** It seems like if a string is set in the middle of a data set,
** the reciever will crach when trying to use the protocol.
** Only tested on Protocol_LobbyStartGame.
**/
2013-12-19 12:32:23 +01:00
namespace GameLogic
{
2014-02-14 17:12:38 +01:00
struct Protocol_QuerryGameType :public Oyster::Network::CustomProtocolObject
{
public:
Protocol_QuerryGameType()
{
this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
this->protocol[0].value = protocol_Lobby_QuerryGameType;
}
::Oyster::Network::CustomNetProtocol GetProtocol() override
{
return this->protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
2013-12-19 12:32:23 +01:00
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
{
short clientID; // The unuiqe id reprsenting a specific client
2014-02-05 15:16:31 +01:00
std::string modelName;
float worldMatrix[16];
2013-12-19 12:32:23 +01:00
Protocol_LobbyCreateGame()
2013-12-19 12:32:23 +01:00
{
2014-02-05 15:16:31 +01:00
int c = 0;
2014-02-14 17:12:38 +01:00
this->protocol[c].value = protocol_Lobby_CreateGame;
2014-02-05 15:16:31 +01:00
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
2013-12-19 12:32:23 +01:00
2014-02-05 15:16:31 +01:00
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
for (int i = 0; i <= 16; i++)
{
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
}
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
2014-01-28 09:00:02 +01:00
}
Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16])
{
2014-02-05 15:16:31 +01:00
int c = 0;
2014-02-14 17:12:38 +01:00
this->protocol[c].value = protocol_Lobby_CreateGame;
2014-02-05 15:16:31 +01:00
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
for (int i = 0; i <= 16; i++)
{
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
}
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
clientID = _clientID;
2014-02-05 15:16:31 +01:00
modelName = name;
memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16);
}
Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o)
2014-01-28 09:00:02 +01:00
{
2014-02-05 15:16:31 +01:00
int c = 1;
clientID = o[c++].value.netInt;
for (int i = 0; i <= 16; i++)
{
this->worldMatrix[i] = o[c++].value.netFloat;
}
modelName.assign(o[c++].value.netCharPtr);
2013-12-19 12:32:23 +01:00
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
2013-12-19 12:32:23 +01:00
{
2014-02-05 15:16:31 +01:00
int c = 1;
protocol[c++].value = clientID;
for (int i = 0; i <= 16; i++)
{
this->protocol[c++].value = this->worldMatrix[i];
}
protocol.Set(c++, this->modelName);
2014-01-31 22:52:52 +01:00
return protocol;
2013-12-19 12:32:23 +01:00
}
private:
Oyster::Network::CustomNetProtocol protocol;
2014-02-05 15:16:31 +01:00
2013-12-19 12:32:23 +01:00
};
struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject
{
float seconds;
Protocol_LobbyStartGame()
{
2014-02-14 17:12:38 +01:00
this->protocol[0].value = protocol_Lobby_StartGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
seconds = 0;
}
Protocol_LobbyStartGame(float _seconds)
{
2014-02-14 17:12:38 +01:00
this->protocol[0].value = protocol_Lobby_StartGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
seconds = _seconds;
}
Protocol_LobbyStartGame(Oyster::Network::CustomNetProtocol& o)
{
seconds = o[1].value.netFloat;
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = seconds;
return protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
2014-02-14 17:12:38 +01:00
struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject
2013-12-19 12:32:23 +01:00
{
// Login stuff
2014-02-14 17:12:38 +01:00
Protocol_LobbyJoinGame()
2013-12-19 12:32:23 +01:00
{
2014-02-14 17:12:38 +01:00
this->protocol[0].value = protocol_Lobby_JoinGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
2013-12-19 12:32:23 +01:00
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
2014-01-28 09:00:02 +01:00
}
2014-02-14 17:12:38 +01:00
Protocol_LobbyJoinGame(Oyster::Network::CustomNetProtocol& p)
2014-01-28 09:00:02 +01:00
{
2013-12-19 12:32:23 +01:00
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
2013-12-19 12:32:23 +01:00
{
2014-01-31 22:52:52 +01:00
return protocol;
2013-12-19 12:32:23 +01:00
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
//struct Protocol_LobbyJoin :public Oyster::Network::CustomProtocolObject
//{
// short value;
//
// Protocol_LobbyJoin()
// {
// this->protocol[0].value = protocol_Lobby_Join;
// this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// }
// Protocol_LobbyJoin(Oyster::Network::CustomNetProtocol& p)
// {
// this->protocol[0].value = protocol_Lobby_Join;
// this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// value = p[1].value.netShort;
// }
2014-01-31 22:52:52 +01:00
// Oyster::Network::CustomNetProtocol GetProtocol() override
// {
// protocol[1].value = value;
// return &protocol;
// }
//
// private:
// Oyster::Network::CustomNetProtocol protocol;
//};
2013-12-19 12:32:23 +01:00
struct Protocol_LobbyRefresh :public Oyster::Network::CustomProtocolObject
2013-12-19 12:32:23 +01:00
{
Protocol_LobbyRefresh()
2013-12-19 12:32:23 +01:00
{
this->protocol[0].value = protocol_Lobby_Login;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
2014-01-28 09:00:02 +01:00
}
Protocol_LobbyRefresh(Oyster::Network::CustomNetProtocol& o)
{
2013-12-19 12:32:23 +01:00
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
{ return protocol; }
2013-12-19 12:32:23 +01:00
private:
Oyster::Network::CustomNetProtocol protocol;
};
/**
* A protocol that contains all data to send to client when update game lobby
*/
struct Protocol_LobbyClientData :public Oyster::Network::CustomProtocolObject
2014-01-07 10:26:09 +01:00
{
// Player list
struct PlayerData
2014-01-07 10:26:09 +01:00
{
std::string name;
std::string ip;
int id;
int team;
2014-01-07 10:26:09 +01:00
};
Utility::DynamicMemory::DynamicArray<PlayerData> list;
Protocol_LobbyClientData()
2014-01-07 10:26:09 +01:00
{
this->protocol[0].value = protocol_Lobby_ClientData;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
list.Reserve(10);
2014-01-07 10:26:09 +01:00
}
Protocol_LobbyClientData(Oyster::Network::CustomNetProtocol& p)
{
unsigned int size = this->protocol[1].value.netUInt;
list.Reserve(size);
int a = 2;
for (unsigned int i = 0; i < list.Size(); i++)
{
PlayerData d;
d.id = this->protocol[a++].value.netInt;
d.team = this->protocol[a++].value.netInt;
d.name = this->protocol.Get(a++).value.netCharPtr;
d.ip = this->protocol.Get(a++).value.netCharPtr;
list.Push(d);
}
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
2014-01-07 10:26:09 +01:00
{
this->protocol[1].value = list.Size();
int a = 2;
for (unsigned int i = 0; i < list.Size(); i++)
2014-01-07 10:26:09 +01:00
{
this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // client-id
this->protocol[a++].value = list[i].id;
this->protocol[a].type = Oyster::Network::NetAttributeType_Int; // team-id
this->protocol[a++].value = list[i].team;
this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; // clientName
this->protocol.Set(a++, list[i].name);
this->protocol[a].type = Oyster::Network::NetAttributeType_CharArray; // clientIP
this->protocol.Set(a++, list[i].ip);
2014-01-07 10:26:09 +01:00
}
2014-01-31 22:52:52 +01:00
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;
}
2014-01-31 22:52:52 +01:00
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = majorVersion;
this->protocol[2].value = minorVersion;
this->protocol.Set(3, mapName.c_str());
2014-01-31 22:52:52 +01:00
return protocol;
2014-01-07 10:26:09 +01:00
}
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[0].value = protocol_Lobby_MainData;
// this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
//
// this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
// }
// Protocol_LobbyMainData(Oyster::Network::CustomNetProtocol& p)
// {
//
// }
2014-01-31 22:52:52 +01:00
// Oyster::Network::CustomNetProtocol GetProtocol() override
// {
// return &protocol;
// }
//
// private:
// Oyster::Network::CustomNetProtocol protocol;
//};
2014-02-15 22:33:40 +01:00
struct Protocol_LobbyClientReadyState :public Oyster::Network::CustomProtocolObject
{
bool isReady;
Protocol_LobbyClientReadyState()
{
this->protocol[0].value = protocol_Lobby_ClientReadyState;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
}
Protocol_LobbyClientReadyState(bool isReady)
{
this->isReady = isReady;
}
Protocol_LobbyClientReadyState(Oyster::Network::CustomNetProtocol& p)
{
this->isReady = p[1].value.netBool;
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = this->isReady;
return protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
2013-12-19 12:32:23 +01:00
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H