2014-01-13 12:44:33 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#include "GameSession.h"
|
|
|
|
#include "GameClient.h"
|
|
|
|
|
2014-01-14 09:25:22 +01:00
|
|
|
#include <Protocols.h>
|
2014-01-13 12:44:33 +01:00
|
|
|
#include <PostBox\PostBox.h>
|
|
|
|
#include <GameLogicStates.h>
|
|
|
|
#include <OysterMath.h>
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Utility::DynamicMemory;
|
|
|
|
using namespace Oyster;
|
|
|
|
using namespace Oyster::Network;
|
|
|
|
using namespace Oyster::Thread;
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
|
|
|
void GameSession::ParseEvents()
|
|
|
|
{
|
|
|
|
if( !this->box->IsEmpty() )
|
|
|
|
{
|
|
|
|
NetworkSession::NetEvent &e = this->box->Fetch();
|
2014-01-20 15:47:52 +01:00
|
|
|
static int ii = 0;
|
|
|
|
printf("%i - Message recieved! [%i]\n", ii++, e.protocol[0].value);
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
|
|
|
|
|
|
|
|
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
|
|
|
|
ParseGameplayEvent(e.protocol, e.gameClient);
|
|
|
|
|
|
|
|
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
|
|
|
|
ParseGeneralEvent(e.protocol, e.gameClient);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
|
|
|
|
{
|
|
|
|
switch (p[protocol_INDEX_ID].value.netShort)
|
|
|
|
{
|
2014-01-21 09:52:48 +01:00
|
|
|
case protocol_Gameplay_PlayerMovement:
|
2014-01-13 12:44:33 +01:00
|
|
|
{
|
|
|
|
if(p[1].value.netBool) //bool bForward;
|
2014-01-15 11:03:25 +01:00
|
|
|
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
|
2014-01-13 12:44:33 +01:00
|
|
|
if(p[2].value.netBool) //bool bBackward;
|
2014-01-15 11:03:25 +01:00
|
|
|
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
|
2014-01-21 09:52:48 +01:00
|
|
|
if(p[3].value.netBool) //bool bStrafeLeft;
|
2014-01-15 11:03:25 +01:00
|
|
|
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
|
2014-01-21 09:52:48 +01:00
|
|
|
if(p[4].value.netBool) //bool bStrafeRight;
|
|
|
|
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
|
2014-01-13 12:44:33 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case protocol_Gameplay_PlayerMouseMovement:
|
2014-01-21 09:52:48 +01:00
|
|
|
{
|
|
|
|
Protocol_PlayerMouse m; m = p;
|
|
|
|
c->GetPlayer()->Rotate(m.dxMouse, m.dyMouse);
|
|
|
|
}
|
2014-01-13 12:44:33 +01:00
|
|
|
break;
|
2014-01-21 09:52:48 +01:00
|
|
|
case protocol_Gameplay_PlayerChangeWeapon:
|
2014-01-14 09:25:22 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
break;
|
2014-01-21 14:32:42 +01:00
|
|
|
case protocol_Gameplay_ObjectDamage:
|
2014-01-21 09:52:48 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
|
|
|
|
{
|
|
|
|
switch (p[protocol_INDEX_ID].value.netShort)
|
|
|
|
{
|
|
|
|
case protocol_General_Status:
|
|
|
|
switch (p[1].value.netInt)
|
|
|
|
{
|
|
|
|
case GameLogic::Protocol_General_Status::States_disconected:
|
|
|
|
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
|
|
|
|
this->RemoveClient(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GameLogic::Protocol_General_Status::States_idle:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GameLogic::Protocol_General_Status::States_ready:
|
|
|
|
|
|
|
|
break;
|
2014-01-22 15:22:52 +01:00
|
|
|
|
|
|
|
case GameLogic::Protocol_General_Status::States_leave:
|
|
|
|
|
|
|
|
break;
|
2014-01-13 12:44:33 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case protocol_General_Text:
|
2014-01-22 15:22:52 +01:00
|
|
|
{
|
|
|
|
GameLogic::Protocol_General_Text temp(p);
|
|
|
|
printf("Message recieved from (%i):\t %s\n", c->GetID(), temp.text.c_str());
|
|
|
|
}
|
2014-01-13 12:44:33 +01:00
|
|
|
break;
|
2014-01-22 15:22:52 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
|
|
|
|
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
|
|
|
|
{
|
2014-01-21 09:52:48 +01:00
|
|
|
movedObject->GetID();
|
|
|
|
movedObject->GetOrientation();
|
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
}
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
}//End namespace DanBias
|
|
|
|
|