2014-01-14 10:25:49 +01:00
|
|
|
#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H
|
|
|
|
#define DANBIAS_CLIENTRECIEVEROBJECT_H
|
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
//WTF!? No headers included???
|
2014-01-31 14:14:20 +01:00
|
|
|
#include "../DanBiasGame/Include/DanBiasGame.h"
|
|
|
|
#include "../GameProtocols/GeneralProtocols.h"
|
2014-02-04 16:07:10 +01:00
|
|
|
#include "..\GameProtocols\Protocols.h"
|
2014-02-05 15:16:31 +01:00
|
|
|
#include <Utilities.h>
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-01-14 10:25:49 +01:00
|
|
|
namespace DanBias
|
|
|
|
{
|
2014-01-31 08:41:08 +01:00
|
|
|
|
|
|
|
struct GameRecieverObject :public Oyster::Network::NetworkClient
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-01-31 08:41:08 +01:00
|
|
|
Client::GameClientState* gameClientState;
|
|
|
|
|
|
|
|
// receiver function for server messages
|
|
|
|
// parsing protocols and sending it to the gameState
|
2014-02-04 16:07:10 +01:00
|
|
|
//void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
|
|
|
|
void GameRecieverObject::DataRecieved(Oyster::Network::NetEvent<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> e) override
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
Oyster::Network::CustomNetProtocol p = e.args.data.protocol;
|
2014-01-31 08:41:08 +01:00
|
|
|
int pType = p[0].value.netInt;
|
2014-02-04 16:07:10 +01:00
|
|
|
|
|
|
|
//printf("Message(%i) arrived at client(%i)\n", pType, this->GetID());
|
|
|
|
|
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
switch (pType)
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-01-31 08:41:08 +01:00
|
|
|
case protocol_General_Status:
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-01-31 08:41:08 +01:00
|
|
|
GameLogic::Protocol_General_Status::States state;
|
|
|
|
state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort;
|
|
|
|
if( state == GameLogic::Protocol_General_Status::States_disconected)
|
|
|
|
{
|
|
|
|
// server disconnected
|
|
|
|
DanBiasGame::Release();
|
|
|
|
}
|
2014-01-14 10:25:49 +01:00
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
break;
|
|
|
|
case protocol_Gameplay_ObjectCreate:
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
Client::GameClientState::NewObj protocolData;// = new Client::GameClientState::NewObj;
|
|
|
|
protocolData.object_ID = p[1].value.netInt;
|
|
|
|
protocolData.path = p[2].value.netCharPtr;
|
2014-01-31 08:41:08 +01:00
|
|
|
for(int i = 0; i< 16; i++)
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
protocolData.worldPos[i] = p[i+3].value.netFloat;
|
2014-01-31 08:41:08 +01:00
|
|
|
}
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
if(dynamic_cast<Client::GameState*>(gameClientState))
|
2014-02-04 16:07:10 +01:00
|
|
|
((Client::GameState*)gameClientState)->Protocol(&protocolData);
|
2014-01-31 08:41:08 +01:00
|
|
|
|
2014-02-04 16:07:10 +01:00
|
|
|
//delete p[2].value.netCharPtr; //delete char array
|
|
|
|
//delete protocolData;
|
|
|
|
//protocolData = NULL;
|
2014-01-31 08:41:08 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case protocol_Gameplay_ObjectDisabled:
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-01-31 08:41:08 +01:00
|
|
|
Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj;
|
|
|
|
protocolData->object_ID = p[1].value.netInt;
|
|
|
|
|
|
|
|
if(dynamic_cast<Client::GameState*>(gameClientState))
|
|
|
|
((Client::GameState*)gameClientState)->Protocol(protocolData);
|
|
|
|
|
|
|
|
delete protocolData;
|
|
|
|
protocolData = NULL;
|
2014-01-14 10:25:49 +01:00
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
break;
|
|
|
|
case protocol_Gameplay_ObjectPosition:
|
|
|
|
{
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
Client::GameClientState::ObjPos protocolData;
|
|
|
|
protocolData.object_ID = p[1].value.netInt;
|
|
|
|
for(int i = 0; i< 16; i++)
|
|
|
|
{
|
|
|
|
protocolData.worldPos[i] = p[i+2].value.netFloat;
|
|
|
|
}
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
if(dynamic_cast<Client::GameState*>(gameClientState))
|
|
|
|
((Client::GameState*)gameClientState)->Protocol(&protocolData);
|
|
|
|
}
|
|
|
|
break;
|
2014-02-09 16:42:26 +01:00
|
|
|
case protocol_Lobby_Create:
|
2014-01-31 13:56:22 +01:00
|
|
|
{
|
|
|
|
if(dynamic_cast<Client::LobbyState*>(gameClientState))
|
|
|
|
{
|
2014-02-09 16:42:26 +01:00
|
|
|
int id = p.Get(1).value.netInt;
|
2014-02-05 15:16:31 +01:00
|
|
|
std::string name = p.Get(19).value.netCharPtr;
|
|
|
|
Oyster::Math::Float4x4 w;
|
|
|
|
for(int i = 0; i< 16; i++)
|
|
|
|
{
|
2014-02-09 16:42:26 +01:00
|
|
|
w[i] = p[i+2].value.netFloat;
|
2014-02-05 15:16:31 +01:00
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
|
2014-01-31 13:56:22 +01:00
|
|
|
gameClientState->Release();
|
|
|
|
delete gameClientState;
|
2014-02-05 15:16:31 +01:00
|
|
|
|
2014-01-31 13:56:22 +01:00
|
|
|
gameClientState = new Client::GameState();
|
2014-02-04 16:07:10 +01:00
|
|
|
gameClientState->Init(this);
|
2014-02-05 15:16:31 +01:00
|
|
|
std::wstring temp;
|
|
|
|
Utility::String::StringToWstring(name, temp);
|
|
|
|
((Client::GameState*)gameClientState)->InitiatePlayer(id, temp, w);
|
2014-02-09 16:42:26 +01:00
|
|
|
|
|
|
|
//Do some wait state?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case protocol_Lobby_Start:
|
|
|
|
{
|
|
|
|
if(dynamic_cast<Client::GameState*>(gameClientState))
|
|
|
|
{
|
|
|
|
//Game state should start in n seconds
|
|
|
|
GameLogic::Protocol_LobbyStartGame p(p);
|
|
|
|
p.seconds;
|
|
|
|
|
|
|
|
//Sleep((int)(p.seconds * 1000));
|
2014-02-04 16:07:10 +01:00
|
|
|
}
|
2014-01-31 13:56:22 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
if(ProtocolIsLobby(p[0].value.netInt)) ParseLobbyProtocol(p);
|
|
|
|
}
|
2014-01-14 10:25:49 +01:00
|
|
|
|
2014-01-31 08:41:08 +01:00
|
|
|
void ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p)
|
|
|
|
{
|
|
|
|
switch (p[0].value.netShort)
|
|
|
|
{
|
|
|
|
case protocol_General_Status: //this->GeneralStatus (Protocol_General_Status (p), c);
|
|
|
|
break;
|
|
|
|
case protocol_General_Text: //this->GeneralText (Protocol_General_Text (p), c);
|
|
|
|
break;
|
|
|
|
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
|
|
|
|
//break;
|
|
|
|
case protocol_Lobby_Start: //this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
|
|
|
|
break;
|
|
|
|
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
|
|
|
|
//break;
|
|
|
|
case protocol_Lobby_Login: //this->LobbyLogin (Protocol_LobbyLogin (p), c);
|
|
|
|
break;
|
|
|
|
case protocol_Lobby_Refresh: //this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
|
|
|
|
break;
|
|
|
|
case protocol_Lobby_GameData: //this->LobbyGameData (Protocol_LobbyGameData (p), c);
|
2014-01-14 10:25:49 +01:00
|
|
|
{
|
2014-01-31 14:14:20 +01:00
|
|
|
//GameLogic::Protocol_LobbyGameData temp(p);
|
|
|
|
//printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion);
|
2014-01-14 10:25:49 +01:00
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
break;
|
|
|
|
case protocol_Lobby_ClientData: //this->LobbyMainData (Protocol_LobbyClientData (p), c);
|
|
|
|
break;
|
|
|
|
//case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c);
|
|
|
|
//break;
|
2014-01-14 10:25:49 +01:00
|
|
|
}
|
2014-01-31 08:41:08 +01:00
|
|
|
}
|
|
|
|
};
|
2014-01-14 10:25:49 +01:00
|
|
|
}
|
|
|
|
#endif
|