Gamelogic - Publication to others...
This commit is contained in:
parent
17aa38d865
commit
9eb8fcba40
|
@ -187,6 +187,7 @@
|
|||
<ClCompile Include="ServerObjects\NetworkSession.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Event\EventManager.h" />
|
||||
<ClInclude Include="GameServer.h" />
|
||||
<ClInclude Include="Include\DanBiasServerAPI.h" />
|
||||
<ClInclude Include="ServerInitReader.h" />
|
||||
|
|
|
@ -54,7 +54,6 @@ namespace DanBias
|
|||
|
||||
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
|
||||
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
|
||||
if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
|
||||
|
||||
this->initiated = true;
|
||||
return DanBiasServerReturn_Sucess;
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
namespace DanBias
|
||||
{
|
||||
class ClientObject :public Oyster::Network::ProtocolRecieverObject
|
||||
class ClientObject
|
||||
:public Oyster::Network::ProtocolRecieverObject
|
||||
{
|
||||
public:
|
||||
ClientObject(const Oyster::Network::NetworkClient& client);
|
||||
|
@ -20,8 +21,8 @@ namespace DanBias
|
|||
GameLogic::Player* Logic_Object();
|
||||
Oyster::Network::NetworkClient* NetClient_Object();
|
||||
|
||||
private:
|
||||
void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override;
|
||||
/** This method is NOT threadsafe. */
|
||||
virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override;
|
||||
|
||||
private:
|
||||
GameLogic::Player logicPlayer;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "MainLobby.h"
|
||||
|
||||
#include <PlayerProtocols.h>
|
||||
|
||||
namespace DanBias
|
||||
{
|
||||
|
@ -13,14 +13,31 @@ namespace DanBias
|
|||
}
|
||||
void MainLobby::Release()
|
||||
{
|
||||
this->clients.clear();
|
||||
this->DetachClient();
|
||||
}
|
||||
|
||||
void MainLobby::Frame()
|
||||
{
|
||||
if(!this->box.IsEmpty())
|
||||
{
|
||||
|
||||
NetEvent &e = this->box.Fetch();
|
||||
ParseEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
//////// Private
|
||||
void MainLobby::ParseEvent(NetEvent& e)
|
||||
{
|
||||
static const short i = MAXSHORT;
|
||||
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
|
||||
|
||||
short f = e.protocol[0].value.netShort;
|
||||
|
||||
switch (f)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}//End namespace DanBias
|
|
@ -2,8 +2,6 @@
|
|||
#define DANBIASSERVER_MAINLOBBY_H
|
||||
|
||||
#include "..\NetworkSession.h"
|
||||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
namespace DanBias
|
||||
{
|
||||
|
@ -17,7 +15,7 @@ namespace DanBias
|
|||
void Frame();
|
||||
|
||||
private:
|
||||
|
||||
void ParseEvent(NetEvent& e);
|
||||
|
||||
};
|
||||
}//End namespace DanBias
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
#include "ClientObject.h"
|
||||
#include "NetworkSession.h"
|
||||
#include <mutex>
|
||||
|
@ -20,15 +21,38 @@ namespace DanBias
|
|||
if(!this->clients[i])
|
||||
{
|
||||
this->clients[i] = client;
|
||||
//this->clients[i]->SetPostbox(&this->box);
|
||||
this->clients[i]->SetPostbox(&this->box);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->clients.push_back(client);
|
||||
}
|
||||
|
||||
void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->clients.size(); i++)
|
||||
{
|
||||
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
|
||||
this->clients[i] = 0;
|
||||
}
|
||||
}
|
||||
void NetworkSession::DetachClient(ClientObject* client)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->clients.size(); i++)
|
||||
{
|
||||
if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id())
|
||||
this->clients[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
void NetworkSession::DetachClient(short ID)
|
||||
{
|
||||
//this->clients[0]->NetClient_Object()->
|
||||
for (unsigned int i = 0; i < this->clients.size(); i++)
|
||||
{
|
||||
if(this->clients[0]->NetClient_Object()->Id() == ID)
|
||||
this->clients[i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
void NetworkSession::DetachClient()
|
||||
{
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#ifndef DANBIASSERVER_NETWORK_SESSION_H
|
||||
#define DANBIASSERVER_NETWORK_SESSION_H
|
||||
|
||||
#define NOMINMAX
|
||||
#include "Utilities.h"
|
||||
#include <PostBox\PostBox.h>
|
||||
#include <PlayerProtocols.h>
|
||||
#include <CustomNetProtocol.h>
|
||||
#include <NetworkClient.h>
|
||||
#include <vector>
|
||||
|
||||
namespace DanBias
|
||||
|
@ -13,12 +17,10 @@ namespace DanBias
|
|||
class NetworkSession
|
||||
{
|
||||
public:
|
||||
struct ClientEvent
|
||||
struct NetEvent
|
||||
{
|
||||
ClientObject* reciever;
|
||||
Oyster::Network::CustomNetProtocol protocol;
|
||||
ClientEvent() { reciever = 0; }
|
||||
~ClientEvent() { }
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -27,6 +29,8 @@ namespace DanBias
|
|||
|
||||
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client);
|
||||
|
||||
void DetachClient(Oyster::Network::NetworkClient* client);
|
||||
void DetachClient(ClientObject* client);
|
||||
void DetachClient(short ID);
|
||||
void DetachClient();
|
||||
|
||||
|
@ -36,10 +40,11 @@ namespace DanBias
|
|||
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
|
||||
|
||||
//TODO: Do more lobby features
|
||||
//virtual void
|
||||
|
||||
protected:
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
|
||||
Oyster::PostBox<DanBias::NetworkSession::ClientEvent> box;
|
||||
Oyster::PostBox<DanBias::NetworkSession::NetEvent> box;
|
||||
};
|
||||
}//End namespace DanBias
|
||||
#endif // !DANBIASSERVER_NETWORK_SESSION_H
|
||||
|
|
|
@ -154,6 +154,7 @@
|
|||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="LobbyProtocols.h" />
|
||||
<ClInclude Include="ObjectProtocols.h" />
|
||||
<ClInclude Include="PlayerProtocols.h" />
|
||||
<ClInclude Include="ProtocolIdentificationID.h" />
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created 2013 by:
|
||||
// [Dennis Andersen], [Linda Andersson]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#ifndef GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H
|
||||
#define GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H
|
||||
|
||||
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
|
||||
|
||||
#define protocol_PlayerNavigation 0
|
||||
#define protocol_PlayerPosition 1
|
||||
#define protocol_ObjectPosition 2
|
||||
#define protocol_PlayerNavigation 0
|
||||
#define protocol_PlayerPosition 1
|
||||
#define protocol_ObjectPosition 2
|
||||
|
||||
#define PROTOCOL_TEST 1000
|
||||
#define protocol_Lobby_Msg 60
|
||||
|
||||
#define protocol_General_Disconnect 100
|
||||
#define protocol_General_Ping 101
|
||||
|
||||
#define PROTOCOL_TEST 1000
|
||||
|
||||
#endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H
|
||||
|
|
|
@ -245,4 +245,14 @@ void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCal
|
|||
bool NetworkClient::operator ==(const NetworkClient& obj)
|
||||
{
|
||||
return (this->privateData->data->ID == obj.privateData->data->ID);
|
||||
}
|
||||
|
||||
bool NetworkClient::operator ==(const int& ID)
|
||||
{
|
||||
return this->privateData->data->ID == ID;
|
||||
}
|
||||
|
||||
int NetworkClient::Id() const
|
||||
{
|
||||
return this->privateData->data->ID;
|
||||
}
|
|
@ -45,6 +45,9 @@ namespace Oyster
|
|||
|
||||
//Compares the internal ID.
|
||||
bool operator ==(const NetworkClient& obj);
|
||||
bool operator ==(const int& ID);
|
||||
|
||||
int Id() const;
|
||||
|
||||
private:
|
||||
struct PrivateData;
|
||||
|
|
|
@ -41,7 +41,7 @@ int main()
|
|||
|
||||
//Connect to server
|
||||
//errorCode = client->Connect(15151, "193.11.186.101");
|
||||
errorCode = client->Connect(15151, "127.0.0.1");
|
||||
errorCode = client.Connect(15151, "127.0.0.1");
|
||||
client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function);
|
||||
|
||||
if(errorCode != 0)
|
||||
|
|
Loading…
Reference in New Issue