Danbias/Code/Game/GameServer/Implementation/GameLobby.cpp

122 lines
3.3 KiB
C++
Raw Normal View History

2014-01-28 09:00:02 +01:00
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\GameLobby.h"
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>
#include <Protocols.h>
2014-01-28 09:00:02 +01:00
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
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 10:18:01 +01:00
this->ProcessClients();
2014-01-28 09:00:02 +01:00
}
void GameLobby::SetGameDesc(const LobbyLevelData& desc)
2014-01-28 09:00:02 +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
}
void GameLobby::GetGameDesc(LobbyLevelData& desc)
2014-01-30 00:19:00 +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()
{
GameSession::GameDescription desc;
desc.gameMode = this->description.gameMode;
desc.gameTime = this->description.gameTime;
desc.mapNumber = this->description.mapNumber;
desc.owner = this;
desc.clients = this->clients;
this->clients.Clear();
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:
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:
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
{
printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str());
2014-01-31 22:52:52 +01:00
if(this->gameSession)
{
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-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-31 22:52:52 +01:00
p2.majorVersion = 1;
p2.minorVersion = 0;
p2.mapName = "Dennis <20>r kung tycker Erik!";
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