Danbias/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp

97 lines
1.7 KiB
C++
Raw Normal View History

2013-12-19 12:32:23 +01:00
2013-12-12 09:33:59 +01:00
#include "MainLobby.h"
2013-12-19 12:32:23 +01:00
#include "..\..\Helpers\ProtocolParser.h"
#include "..\ClientObject.h"
2013-12-16 09:00:11 +01:00
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>
2013-12-12 09:33:59 +01:00
2013-12-19 12:32:23 +01:00
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
2013-12-12 09:33:59 +01:00
namespace DanBias
{
MainLobby::MainLobby()
2013-12-19 12:32:23 +01:00
:gameLobby(5)
2013-12-12 09:33:59 +01:00
{
2013-12-19 12:32:23 +01:00
this->box = new PostBox<DanBias::NetworkSession::NetEvent>();
2013-12-12 09:33:59 +01:00
}
MainLobby::~MainLobby()
{
delete this->box;
this->box = 0;
2013-12-12 09:33:59 +01:00
}
void MainLobby::Release()
{
this->CloseSession(0);
2013-12-13 23:47:16 +01:00
}
void MainLobby::Frame()
{
2013-12-16 09:50:23 +01:00
ParseEvents();
2013-12-16 09:00:11 +01:00
}
2013-12-19 12:32:23 +01:00
IPostBox<NetworkSession::NetEvent>* MainLobby::GetPostbox()
{
return this->box;
}
2013-12-16 09:00:11 +01:00
//////// Private
2013-12-16 09:50:23 +01:00
void MainLobby::ParseEvents()
2013-12-16 09:00:11 +01:00
{
if(this->box && !this->box->IsEmpty())
2013-12-16 09:50:23 +01:00
{
2013-12-18 08:44:10 +01:00
NetEvent &e = this->box->Fetch();
2013-12-16 09:00:11 +01:00
2013-12-19 12:32:23 +01:00
ParseProtocol(e.protocol, *e.reciever);
}
}
void MainLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
//switch (p[0].value.netChar)
//{
// case protocol_Lobby_CreateGame:
// {
// GameLogic::Protocol_LobbyCreateGame val(p);
// CreateGame(val, c);
// }
// break;
// case protocol_Lobby_JoinGame:
// {
//
// }
// break;
// case protocol_Lobby_JoinLobby:
// {
//
// }
// break;
// case protocol_Lobby_LeaveLobby:
// {
//
// }
// break;
//}
2013-12-12 09:33:59 +01:00
2013-12-19 12:32:23 +01:00
}
void MainLobby::CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::ClientObject& c)
{
SmartPointer<ClientObject> sc = NetworkSession::FindClient(c);
NetworkSession::DetachClient(&c);
2013-12-16 09:50:23 +01:00
2013-12-19 12:32:23 +01:00
if(!sc) return;
for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
{
if(!gameLobby[i])
2013-12-16 09:50:23 +01:00
{
2013-12-19 12:32:23 +01:00
gameLobby[i] = new GameLobby(sc);
return;
2013-12-16 09:50:23 +01:00
}
2013-12-13 23:47:16 +01:00
}
2013-12-19 12:32:23 +01:00
this->gameLobby.Push(new GameLobby(sc));
2013-12-12 09:33:59 +01:00
}
2013-12-16 09:00:11 +01:00
2013-12-12 09:33:59 +01:00
}//End namespace DanBias