2014-02-16 01:38:03 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2014-01-29 10:18:01 +01:00
|
|
|
#include "..\GameLobby.h"
|
|
|
|
|
|
|
|
using namespace DanBias;
|
|
|
|
using namespace GameLogic;
|
|
|
|
using namespace Oyster::Network;
|
|
|
|
|
|
|
|
|
|
|
|
void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClient* c)
|
|
|
|
{
|
|
|
|
switch (p[0].value.netShort)
|
|
|
|
{
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
|
2014-01-30 14:15:25 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c);
|
2014-02-15 22:33:40 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c);
|
2014-01-29 10:18:01 +01:00
|
|
|
break;
|
2014-02-18 08:55:38 +01:00
|
|
|
case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c);
|
2014-02-17 16:17:07 +01:00
|
|
|
break;
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
|
|
|
switch (p.status)
|
|
|
|
{
|
|
|
|
case Protocol_General_Status::States_ready:
|
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
int temp = FindClient(c);
|
|
|
|
if(temp != -1 )
|
|
|
|
{
|
|
|
|
switch (this->gClients[temp]->GetState())
|
|
|
|
{
|
|
|
|
case GameClient::ClientState_CreatingGame:
|
|
|
|
{
|
|
|
|
this->gameSession.Join(this->gClients[temp]);
|
|
|
|
this->gClients[temp] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c->Disconnect();
|
|
|
|
}
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
2014-02-18 16:38:08 +01:00
|
|
|
break;
|
2014-01-29 10:18:01 +01:00
|
|
|
case Protocol_General_Status::States_idle:
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-02-18 16:38:08 +01:00
|
|
|
break;
|
2014-01-29 10:18:01 +01:00
|
|
|
case Protocol_General_Status::States_leave:
|
2014-02-18 16:38:08 +01:00
|
|
|
break;
|
2014-01-29 10:18:01 +01:00
|
|
|
case Protocol_General_Status::States_disconected:
|
|
|
|
{
|
|
|
|
Detach(c)->Disconnect();
|
|
|
|
}
|
2014-02-18 16:38:08 +01:00
|
|
|
break;
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
2014-02-18 08:55:38 +01:00
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
if(this->gClients[i])
|
2014-02-18 08:55:38 +01:00
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
this->gClients[i]->GetClient()->Send(p);
|
2014-02-18 08:55:38 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-29 10:18:01 +01:00
|
|
|
printf(p.text.c_str());
|
|
|
|
}
|
|
|
|
void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
if(this->sessionOwner->GetClient()->GetID() == c->GetID())
|
|
|
|
{
|
2014-02-18 08:55:38 +01:00
|
|
|
//Send countdown timer before lobby shuts down
|
2014-02-18 16:38:08 +01:00
|
|
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
2014-02-18 08:55:38 +01:00
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
this->gClients[i]->GetClient()->Send(Protocol_LobbyStartGame(3.0f));
|
2014-02-18 08:55:38 +01:00
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Someone else tried to start the server..
|
|
|
|
}
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
2014-02-18 08:55:38 +01:00
|
|
|
void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
|
2014-01-29 10:18:01 +01:00
|
|
|
{
|
2014-02-18 08:55:38 +01:00
|
|
|
//for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
|
|
|
|
//{
|
|
|
|
// if (this->gameLobby[i]->GetID() == p.value)
|
|
|
|
// {
|
|
|
|
// this->gameLobby[i]->Attach(Detach(c));
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//}
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
|
|
|
void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
|
|
|
//Dont need to handle this on the server...
|
2014-01-30 14:15:25 +01:00
|
|
|
}
|
|
|
|
void GameLobby::LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
}
|
2014-01-30 11:11:04 +01:00
|
|
|
void GameLobby::LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c)
|
2014-01-29 10:18:01 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-02-15 22:33:40 +01:00
|
|
|
void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
|
|
|
if(p.isReady)
|
|
|
|
{
|
|
|
|
this->readyList.PushBack(c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->readyList.Remove(c);
|
2014-02-18 08:55:38 +01:00
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-17 16:17:07 +01:00
|
|
|
void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
2014-02-18 11:34:24 +01:00
|
|
|
if(this->gameSession)
|
2014-02-17 16:17:07 +01:00
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
int temp = FindClient(c);
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-02-18 11:34:24 +01:00
|
|
|
//Something is wrong
|
2014-02-18 16:38:08 +01:00
|
|
|
if(temp == -1)
|
2014-02-18 11:34:24 +01:00
|
|
|
{
|
|
|
|
c->Disconnect();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Send game data
|
2014-02-18 16:38:08 +01:00
|
|
|
Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string()));
|
|
|
|
c->Send(lcg);
|
|
|
|
this->gClients[temp]->SetState(GameClient::ClientState_CreatingGame);
|
2014-02-18 11:34:24 +01:00
|
|
|
}
|
2014-02-17 16:17:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-18 16:38:08 +01:00
|
|
|
// Nothing.-
|
2014-02-17 16:17:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 16:38:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
int GameLobby::FindClient(Oyster::Network::NetworkClient* c)
|
|
|
|
{
|
|
|
|
int temp = -1;
|
|
|
|
|
|
|
|
//find client in waiting list
|
|
|
|
for (unsigned int i = 0; i < this->gClients.Size(); i++)
|
|
|
|
{
|
|
|
|
if(this->gClients[i]->GetClient()->GetID() == c->GetID())
|
|
|
|
{
|
|
|
|
temp = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|