Gamelogic - Publication to others...

This commit is contained in:
dean11 2013-12-16 09:00:11 +01:00
parent 17aa38d865
commit 9eb8fcba40
12 changed files with 90 additions and 22 deletions

View File

@ -187,6 +187,7 @@
<ClCompile Include="ServerObjects\NetworkSession.cpp" /> <ClCompile Include="ServerObjects\NetworkSession.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Event\EventManager.h" />
<ClInclude Include="GameServer.h" /> <ClInclude Include="GameServer.h" />
<ClInclude Include="Include\DanBiasServerAPI.h" /> <ClInclude Include="Include\DanBiasServerAPI.h" />
<ClInclude Include="ServerInitReader.h" /> <ClInclude Include="ServerInitReader.h" />

View File

@ -54,7 +54,6 @@ namespace DanBias
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error; if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
this->initiated = true; this->initiated = true;
return DanBiasServerReturn_Sucess; return DanBiasServerReturn_Sucess;

View File

@ -9,7 +9,8 @@
namespace DanBias namespace DanBias
{ {
class ClientObject :public Oyster::Network::ProtocolRecieverObject class ClientObject
:public Oyster::Network::ProtocolRecieverObject
{ {
public: public:
ClientObject(const Oyster::Network::NetworkClient& client); ClientObject(const Oyster::Network::NetworkClient& client);
@ -20,8 +21,8 @@ namespace DanBias
GameLogic::Player* Logic_Object(); GameLogic::Player* Logic_Object();
Oyster::Network::NetworkClient* NetClient_Object(); Oyster::Network::NetworkClient* NetClient_Object();
private: /** This method is NOT threadsafe. */
void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override; virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override;
private: private:
GameLogic::Player logicPlayer; GameLogic::Player logicPlayer;

View File

@ -1,5 +1,5 @@
#include "MainLobby.h" #include "MainLobby.h"
#include <PlayerProtocols.h>
namespace DanBias namespace DanBias
{ {
@ -13,14 +13,31 @@ namespace DanBias
} }
void MainLobby::Release() void MainLobby::Release()
{ {
this->clients.clear(); this->DetachClient();
} }
void MainLobby::Frame() void MainLobby::Frame()
{ {
if(!this->box.IsEmpty()) 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 }//End namespace DanBias

View File

@ -2,8 +2,6 @@
#define DANBIASSERVER_MAINLOBBY_H #define DANBIASSERVER_MAINLOBBY_H
#include "..\NetworkSession.h" #include "..\NetworkSession.h"
#include <thread>
#include <future>
namespace DanBias namespace DanBias
{ {
@ -17,7 +15,7 @@ namespace DanBias
void Frame(); void Frame();
private: private:
void ParseEvent(NetEvent& e);
}; };
}//End namespace DanBias }//End namespace DanBias

View File

@ -1,3 +1,4 @@
#include "ClientObject.h" #include "ClientObject.h"
#include "NetworkSession.h" #include "NetworkSession.h"
#include <mutex> #include <mutex>
@ -20,15 +21,38 @@ namespace DanBias
if(!this->clients[i]) if(!this->clients[i])
{ {
this->clients[i] = client; this->clients[i] = client;
//this->clients[i]->SetPostbox(&this->box); this->clients[i]->SetPostbox(&this->box);
return; return;
} }
} }
this->clients.push_back(client); 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) 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() void NetworkSession::DetachClient()
{ {

View File

@ -1,10 +1,14 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_NETWORK_SESSION_H #ifndef DANBIASSERVER_NETWORK_SESSION_H
#define DANBIASSERVER_NETWORK_SESSION_H #define DANBIASSERVER_NETWORK_SESSION_H
#define NOMINMAX #define NOMINMAX
#include "Utilities.h" #include "Utilities.h"
#include <PostBox\PostBox.h> #include <PostBox\PostBox.h>
#include <PlayerProtocols.h> #include <CustomNetProtocol.h>
#include <NetworkClient.h>
#include <vector> #include <vector>
namespace DanBias namespace DanBias
@ -13,12 +17,10 @@ namespace DanBias
class NetworkSession class NetworkSession
{ {
public: public:
struct ClientEvent struct NetEvent
{ {
ClientObject* reciever; ClientObject* reciever;
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
ClientEvent() { reciever = 0; }
~ClientEvent() { }
}; };
public: public:
@ -27,6 +29,8 @@ namespace DanBias
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client); void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client);
void DetachClient(Oyster::Network::NetworkClient* client);
void DetachClient(ClientObject* client);
void DetachClient(short ID); void DetachClient(short ID);
void DetachClient(); void DetachClient();
@ -36,10 +40,11 @@ namespace DanBias
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID); void Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
//TODO: Do more lobby features //TODO: Do more lobby features
//virtual void
protected: protected:
std::vector<Utility::DynamicMemory::SmartPointer<ClientObject>> clients; std::vector<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
Oyster::PostBox<DanBias::NetworkSession::ClientEvent> box; Oyster::PostBox<DanBias::NetworkSession::NetEvent> box;
}; };
}//End namespace DanBias }//End namespace DanBias
#endif // !DANBIASSERVER_NETWORK_SESSION_H #endif // !DANBIASSERVER_NETWORK_SESSION_H

View File

@ -154,6 +154,7 @@
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="LobbyProtocols.h" />
<ClInclude Include="ObjectProtocols.h" /> <ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" /> <ClInclude Include="PlayerProtocols.h" />
<ClInclude Include="ProtocolIdentificationID.h" /> <ClInclude Include="ProtocolIdentificationID.h" />

View File

@ -1,12 +1,21 @@
/////////////////////////////////////////////////////////////////////
// Created 2013 by:
// [Dennis Andersen], [Linda Andersson]
/////////////////////////////////////////////////////////////////////
#ifndef GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H #ifndef GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H
#define GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H #define GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_PlayerNavigation 0 #define protocol_PlayerNavigation 0
#define protocol_PlayerPosition 1 #define protocol_PlayerPosition 1
#define protocol_ObjectPosition 2 #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 #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H

View File

@ -245,4 +245,14 @@ void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCal
bool NetworkClient::operator ==(const NetworkClient& obj) bool NetworkClient::operator ==(const NetworkClient& obj)
{ {
return (this->privateData->data->ID == obj.privateData->data->ID); 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;
} }

View File

@ -45,6 +45,9 @@ namespace Oyster
//Compares the internal ID. //Compares the internal ID.
bool operator ==(const NetworkClient& obj); bool operator ==(const NetworkClient& obj);
bool operator ==(const int& ID);
int Id() const;
private: private:
struct PrivateData; struct PrivateData;

View File

@ -41,7 +41,7 @@ int main()
//Connect to server //Connect to server
//errorCode = client->Connect(15151, "193.11.186.101"); //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); client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function);
if(errorCode != 0) if(errorCode != 0)