2014-01-28 09:00:02 +01:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
#include "..\GameLobby.h"
|
|
|
|
|
#include <PlayerProtocols.h>
|
|
|
|
|
#include <PostBox\PostBox.h>
|
2014-01-29 15:01:14 +01:00
|
|
|
|
#include <Protocols.h>
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
|
|
using namespace Utility::DynamicMemory;
|
|
|
|
|
using namespace Oyster::Network;
|
|
|
|
|
using namespace Oyster;
|
2014-01-30 11:11:04 +01:00
|
|
|
|
using namespace GameLogic;
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
|
{
|
|
|
|
|
GameLobby::GameLobby()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
GameLobby::~GameLobby()
|
2014-01-31 22:52:52 +01:00
|
|
|
|
{
|
|
|
|
|
this->clients.Clear();
|
|
|
|
|
}
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
|
|
void GameLobby::Release()
|
2014-01-29 10:18:01 +01:00
|
|
|
|
{
|
|
|
|
|
NetworkSession::CloseSession(true);
|
2014-02-04 16:07:10 +01:00
|
|
|
|
this->gameSession.CloseSession(true);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
|
void GameLobby::Update()
|
2014-01-28 09:00:02 +01:00
|
|
|
|
{
|
2014-01-29 10:18:01 +01:00
|
|
|
|
this->ProcessClients();
|
2014-01-28 09:00:02 +01:00
|
|
|
|
}
|
2014-01-30 11:11:04 +01:00
|
|
|
|
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
|
2014-01-28 09:00:02 +01:00
|
|
|
|
{
|
2014-01-30 11:11:04 +01:00
|
|
|
|
this->description.gameMode = desc.gameMode;
|
|
|
|
|
this->description.gameTime = desc.gameTime;
|
|
|
|
|
this->description.mapNumber = desc.mapNumber;
|
|
|
|
|
this->description.maxClients = desc.maxClients;
|
2014-01-30 00:19:00 +01:00
|
|
|
|
}
|
2014-01-30 11:11:04 +01:00
|
|
|
|
void GameLobby::GetGameDesc(LobbyLevelData& desc)
|
2014-01-30 00:19:00 +01:00
|
|
|
|
{
|
2014-01-30 11:11:04 +01:00
|
|
|
|
desc.gameMode = this->description.gameMode;
|
|
|
|
|
desc.gameTime = this->description.gameTime;
|
|
|
|
|
desc.mapNumber = this->description.mapNumber;
|
|
|
|
|
desc.maxClients = this->description.maxClients;
|
2014-01-30 00:19:00 +01:00
|
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
|
bool GameLobby::StartGameSession( )
|
2014-01-30 00:19:00 +01:00
|
|
|
|
{
|
2014-02-15 22:33:40 +01:00
|
|
|
|
//Check if all clients is ready
|
|
|
|
|
if(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;
|
2014-01-31 08:41:08 +01:00
|
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
|
if(desc.gameTime == 0.0f)
|
|
|
|
|
desc.gameTime = (int)(60.0f * 10.0f); //note: Default game time length should be fetched from somewhere.
|
2014-02-15 09:29:54 +01:00
|
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
|
if(desc.maxClients == 0)
|
|
|
|
|
desc.maxClients = 10; //note: Default should be fetched somewhere else..
|
2014-02-15 09:29:54 +01:00
|
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
|
this->clients.Clear(); //Remove clients from lobby list
|
2014-01-30 14:15:25 +01:00
|
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
|
if(this->gameSession.Create(desc))
|
|
|
|
|
{
|
|
|
|
|
this->gameSession.Run();
|
2014-02-04 16:07:10 +01:00
|
|
|
|
|
2014-02-15 22:33:40 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//?
|
2014-01-30 00:19:00 +01:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-01-28 09:00:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
|
void GameLobby::ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.args.type)
|
|
|
|
|
{
|
|
|
|
|
case NetworkClient::ClientEventArgs::EventType_Disconnect:
|
2014-02-15 22:33:40 +01:00
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
|
break;
|
|
|
|
|
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
|
2014-02-15 22:33:40 +01:00
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
|
break;
|
|
|
|
|
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
|
2014-01-29 15:01:14 +01:00
|
|
|
|
printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
|
|
|
|
e.sender->Disconnect();
|
2014-02-15 22:33:40 +01:00
|
|
|
|
this->readyList.Remove(e.sender);
|
|
|
|
|
this->clients.Remove(e.sender);
|
2014-01-29 10:18:01 +01:00
|
|
|
|
break;
|
|
|
|
|
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
|
2014-01-29 15:01:14 +01:00
|
|
|
|
printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str());
|
2014-01-29 10:18:01 +01:00
|
|
|
|
this->ParseProtocol(e.args.data.protocol, e.sender);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client)
|
2014-01-28 09:00:02 +01:00
|
|
|
|
{
|
2014-01-29 15:01:14 +01:00
|
|
|
|
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
|
2014-01-30 11:11:04 +01:00
|
|
|
|
|
2014-01-31 22:52:52 +01:00
|
|
|
|
if(this->gameSession)
|
2014-01-30 14:15:25 +01:00
|
|
|
|
{
|
2014-02-09 16:42:26 +01:00
|
|
|
|
this->gameSession.Attach(client);
|
2014-01-31 22:52:52 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Attach(client);
|
|
|
|
|
Protocol_LobbyClientData p1;
|
|
|
|
|
Protocol_LobbyGameData p2;
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < this->clients.Size(); i++)
|
2014-01-30 14:15:25 +01:00
|
|
|
|
{
|
2014-01-31 22:52:52 +01:00
|
|
|
|
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 <20>r kung tycker Erik!";
|
|
|
|
|
p1.list.Push(t);
|
|
|
|
|
}
|
2014-01-30 14:15:25 +01:00
|
|
|
|
}
|
2014-01-31 22:52:52 +01:00
|
|
|
|
p2.majorVersion = 1;
|
|
|
|
|
p2.minorVersion = 0;
|
|
|
|
|
p2.mapName = "Dennis <20>r kung tycker Erik!";
|
2014-01-30 14:15:25 +01:00
|
|
|
|
|
2014-01-31 22:52:52 +01:00
|
|
|
|
client->Send(p1.GetProtocol());
|
|
|
|
|
client->Send(p2.GetProtocol());
|
|
|
|
|
}
|
2014-01-28 09:00:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//End namespace DanBias
|