This commit is contained in:
dean11 2014-02-17 16:17:07 +01:00 committed by Robin Engman
parent b4b5998a64
commit 5137404bb6
5 changed files with 199 additions and 158 deletions

View File

@ -546,14 +546,14 @@ namespace GameLogic
//#define protocol_Gameplay_ObjectCreatePlayer 359 //#define protocol_Gameplay_ObjectCreatePlayer 359
struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject
{ {
//ObjectType type; //ie player, box or whatever /*1*/ int object_ID;
int object_ID; /*2*/ int teamId;
int teamId; /*3*/ bool owner;
std::string name; /*4*/ std::string name;
std::string meshName; /*5*/ std::string meshName;
float position[3]; /*6 - 8*/ float position[3];
float rotationQ[4]; /*9 - 11*/ float rotationQ[4];
float scale[3]; /*12 - 14*/ float scale[3];
Protocol_ObjectCreatePlayer() Protocol_ObjectCreatePlayer()
{ {
@ -564,44 +564,47 @@ namespace GameLogic
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
//TEAM_ID //TEAM_ID
this->protocol[2].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
//OWNER
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
//PLAYER-NAME //PLAYER-NAME
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
//POSITION //POSITION
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[8].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[12].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
this->protocol[13].type = Oyster::Network::NetAttributeType_Float; this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
} }
Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p)
{ {
this->object_ID = p[1].value.netInt; this->object_ID = p[1].value.netInt;
this->teamId = this->protocol[2].value.netInt; this->teamId = this->protocol[2].value.netInt;
this->name.assign(p[3].value.netCharPtr); this->owner = this->protocol[3].value.netBool;
this->meshName.assign(p[4].value.netCharPtr); this->name.assign(p[4].value.netCharPtr);
this->meshName.assign(p[5].value.netCharPtr);
this->position[0] = p[5].value.netFloat; this->position[0] = p[6].value.netFloat;
this->position[1] = p[6].value.netFloat; this->position[1] = p[7].value.netFloat;
this->position[2] = p[7].value.netFloat; this->position[2] = p[8].value.netFloat;
this->rotationQ[0] = p[8].value.netFloat; this->rotationQ[0] = p[9].value.netFloat;
this->rotationQ[1] = p[9].value.netFloat; this->rotationQ[1] = p[10].value.netFloat;
this->rotationQ[2] = p[10].value.netFloat; this->rotationQ[2] = p[11].value.netFloat;
this->rotationQ[3] = p[11].value.netFloat; this->rotationQ[3] = p[12].value.netFloat;
this->scale[0] = p[12].value.netFloat; this->scale[0] = p[13].value.netFloat;
this->scale[1] = p[13].value.netFloat; this->scale[1] = p[14].value.netFloat;
this->scale[2] = p[14].value.netFloat; this->scale[2] = p[15].value.netFloat;
} }
Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName) Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, bool owner, int teamID, std::string name, std::string meshName)
{ {
this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer; this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
@ -610,26 +613,29 @@ namespace GameLogic
this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
//TEAM_ID //TEAM_ID
this->protocol[2].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
//OWNER
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
//PLAYER-NAME //PLAYER-NAME
this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray;
//MESH-NAME
this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray;
//POSITION //POSITION
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[8].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
//ROTATION
this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[12].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
//SCALE
this->protocol[13].type = Oyster::Network::NetAttributeType_Float; this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float; this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
this->protocol[15].type = Oyster::Network::NetAttributeType_Float;
this->object_ID = ObjectID; this->object_ID = ObjectID;
this->teamId = teamID; this->teamId = teamID;
this->owner = owner;
this->name = name; this->name = name;
this->meshName = meshName; this->meshName = meshName;
memcpy(&this->position[0], &position[0], sizeof(float)*3); memcpy(&this->position[0], &position[0], sizeof(float)*3);
@ -641,22 +647,23 @@ namespace GameLogic
this->protocol[1].value = this->object_ID; this->protocol[1].value = this->object_ID;
this->protocol[2].value = this->teamId; this->protocol[2].value = this->teamId;
this->protocol.Set(3, this->name); this->protocol[3].value = this->owner;
this->protocol.Set(4, this->meshName); this->protocol.Set(4, this->name);
this->protocol.Set(5, this->meshName);
//POSITION //POSITION
this->protocol[5].value = this->position[0]; this->protocol[6].value = this->position[0];
this->protocol[6].value = this->position[1]; this->protocol[7].value = this->position[1];
this->protocol[7].value = this->position[2]; this->protocol[8].value = this->position[2];
//ROTATION //ROTATION
this->protocol[8].value = this->rotationQ[0]; this->protocol[9].value = this->rotationQ[0];
this->protocol[9].value = this->rotationQ[1]; this->protocol[10].value = this->rotationQ[1];
this->protocol[10].value = this->rotationQ[2]; this->protocol[11].value = this->rotationQ[2];
this->protocol[11].value = this->rotationQ[3]; this->protocol[12].value = this->rotationQ[3];
//SCALE //SCALE
this->protocol[12].value = this->scale[0]; this->protocol[13].value = this->scale[0];
this->protocol[13].value = this->scale[1]; this->protocol[14].value = this->scale[1];
this->protocol[14].value = this->scale[2]; this->protocol[15].value = this->scale[2];
return protocol; return protocol;
} }

View File

@ -41,11 +41,12 @@ namespace DanBias
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create: //void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
//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_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& 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 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 LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState:
void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType:
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

@ -11,127 +11,132 @@ using namespace Oyster::Network;
using namespace Oyster; using namespace Oyster;
using namespace GameLogic; using namespace GameLogic;
namespace DanBias using namespace DanBias;
GameLobby::GameLobby()
{ }
GameLobby::~GameLobby()
{ {
GameLobby::GameLobby() this->clients.Clear();
{ } }
GameLobby::~GameLobby() void GameLobby::Release()
{
NetworkSession::CloseSession(true);
this->gameSession.CloseSession(true);
}
void GameLobby::Update()
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{ {
this->clients.Clear(); if(this->clients[i])
}
void GameLobby::Release()
{
NetworkSession::CloseSession(true);
this->gameSession.CloseSession(true);
}
void GameLobby::Update()
{
this->ProcessClients();
}
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
{
this->description.gameMode = desc.gameMode;
this->description.gameTime = desc.gameTime;
this->description.mapNumber = desc.mapNumber;
this->description.maxClients = desc.maxClients;
}
void GameLobby::GetGameDesc(LobbyLevelData& desc)
{
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.maxClients = this->description.maxClients;
}
bool GameLobby::StartGameSession( )
{
//Check if all clients is ready
if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size())
{ {
GameSession::GameDescription desc; this->clients[i]->Update();
desc.maxClients = this->description.maxClients; }
desc.gameMode = this->description.gameMode; }
desc.gameTime = this->description.gameTime; }
desc.mapNumber = this->description.mapNumber; void GameLobby::SetGameDesc(const LobbyLevelData& desc)
desc.owner = this; {
desc.clients = this->clients; this->description.gameMode = desc.gameMode;
this->description.gameTime = desc.gameTime;
this->description.mapNumber = desc.mapNumber;
this->description.maxClients = desc.maxClients;
}
void GameLobby::GetGameDesc(LobbyLevelData& desc)
{
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.maxClients = this->description.maxClients;
}
bool GameLobby::StartGameSession( )
{
//Check if all clients is ready
if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size())
{
GameSession::GameDescription desc;
desc.maxClients = this->description.maxClients;
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.owner = this;
desc.clients = this->clients;
if(desc.gameTime == 0.0f) if(desc.gameTime == 0.0f)
desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere.
if(desc.maxClients == 0) if(desc.maxClients == 0)
desc.maxClients = 10; //note: should be fetched somewhere else.. desc.maxClients = 10; //note: should be fetched somewhere else..
this->clients.Clear(); //Remove clients from lobby list this->clients.Clear(); //Remove clients from lobby list
if(this->gameSession.Create(desc)) if(this->gameSession.Create(desc))
{
this->gameSession.Run();
return true;
}
}
else
{
//?
}
return false;
}
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
switch (e.args.type)
{
case NetworkClient::ClientEventArgs::EventType_Disconnect:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
e.sender->Disconnect();
this->readyList.Remove(e.sender);
this->clients.Remove(e.sender);
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
this->ParseProtocol(e.args.data.protocol, e.sender);
break;
}
}
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
if(this->gameSession)
{
Attach(client);
}
else
{
Attach(client);
Protocol_LobbyClientData p1;
Protocol_LobbyGameData p2;
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i])
{ {
this->gameSession.Run(); Protocol_LobbyClientData::PlayerData t;
t.id = this->clients[i]->GetID();
return true; t.ip = this->clients[i]->GetIpAddress();
t.team = 0;
t.name = "Dennis är kung tycker Erik!";
p1.list.Push(t);
} }
} }
else p2.majorVersion = 1;
{ p2.minorVersion = 0;
//? p2.mapName = "Dennis är kung tycker Erik!";
}
return false; client->Send(p1.GetProtocol());
client->Send(p2.GetProtocol());
} }
}
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
{
switch (e.args.type)
{
case NetworkClient::ClientEventArgs::EventType_Disconnect:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
e.sender->Disconnect();
this->readyList.Remove(e.sender);
this->clients.Remove(e.sender);
break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
this->ParseProtocol(e.args.data.protocol, e.sender);
break;
}
}
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
{
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
if(this->gameSession)
{
this->gameSession.Attach(client);
}
else
{
Attach(client);
Protocol_LobbyClientData p1;
Protocol_LobbyGameData p2;
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 är kung tycker Erik!";
p1.list.Push(t);
}
}
p2.majorVersion = 1;
p2.minorVersion = 0;
p2.mapName = "Dennis är kung tycker Erik!";
client->Send(p1.GetProtocol());
client->Send(p2.GetProtocol());
}
}
}//End namespace DanBias

View File

@ -18,11 +18,11 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break; break;
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
//break; //break;
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
break; break;
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
//break; //break;
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c);
break; break;
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break; break;
@ -32,6 +32,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break; break;
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
break; break;
case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
break;
} }
} }
@ -112,4 +114,29 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster:
this->readyList.Remove(c); this->readyList.Remove(c);
} }
} }
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
{
NetClient temp;
bool found = false;
//find client in waiting list
for (unsigned int i = 0; !found && i < this->clients.Size(); i++)
{
if(this->clients[i]->GetID() == c->GetID())
{
temp = this->clients[i];
found = true;
}
}
//Something is wrong
if(!found)
{
c->Disconnect();
}
else
{
//Send game data
this->gameSession.Attach(temp);
}
}

View File

@ -209,6 +209,7 @@ namespace DanBias
{ {
IPlayerData* p = this->clients[i]->GetPlayer(); IPlayerData* p = this->clients[i]->GetPlayer();
Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
//Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan");
this->clients[i]->GetClient()->Send(oc); this->clients[i]->GetClient()->Send(oc);
} }
} }