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-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-30 00:19:00 +01:00
|
|
|
|
if(GetAsyncKeyState(VK_DOWN)) //TODO: Dont forget to remove this...
|
2014-01-31 22:52:52 +01:00
|
|
|
|
this->Send(GameLogic::Protocol_General_Status().GetProtocol());
|
2014-01-29 15:01:14 +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
|
|
|
|
}
|
|
|
|
|
bool GameLobby::StartGameSession()
|
|
|
|
|
{
|
2014-01-30 11:11:04 +01:00
|
|
|
|
GameSession::GameDescription desc;
|
|
|
|
|
desc.gameMode = this->description.gameMode;
|
|
|
|
|
desc.gameTime = this->description.gameTime;
|
|
|
|
|
desc.mapNumber = this->description.mapNumber;
|
|
|
|
|
desc.owner = this;
|
2014-01-30 14:15:25 +01:00
|
|
|
|
desc.clients = this->clients;
|
2014-01-31 08:41:08 +01:00
|
|
|
|
|
|
|
|
|
this->clients.Clear();
|
2014-01-30 14:15:25 +01:00
|
|
|
|
|
2014-01-30 11:11:04 +01:00
|
|
|
|
if(this->gameSession.Create(desc))
|
2014-01-30 00:19:00 +01:00
|
|
|
|
{
|
|
|
|
|
this->gameSession.Run();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
|
break;
|
|
|
|
|
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
|
|
|
|
|
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-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-01-31 22:52:52 +01:00
|
|
|
|
this->gameSession.ClientConnectedEvent(client);
|
|
|
|
|
}
|
|
|
|
|
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
|