2014-01-07 10:26:09 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef DANBIASSERVER_GAME_SESSION_H
|
|
|
|
#define DANBIASSERVER_GAME_SESSION_H
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer.
|
2014-01-07 10:26:09 +01:00
|
|
|
#pragma warning(disable: 4150)
|
|
|
|
|
|
|
|
#include "..\LobbySessions\NetworkSession.h"
|
2014-01-13 12:44:33 +01:00
|
|
|
#include <WinTimer.h>
|
2014-01-07 10:26:09 +01:00
|
|
|
#include <PostBox\IPostBox.h>
|
|
|
|
#include <Thread\OysterThread.h>
|
2014-01-20 15:47:52 +01:00
|
|
|
#include <GameAPI.h>
|
2014-01-15 11:03:25 +01:00
|
|
|
#include <Queue.h>
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
namespace DanBias
|
|
|
|
{
|
|
|
|
class LobbyClient;
|
|
|
|
class GameClient;
|
|
|
|
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
|
|
|
|
{
|
|
|
|
public:
|
2014-01-13 12:44:33 +01:00
|
|
|
/**
|
|
|
|
* A container to use when initiating a new session
|
|
|
|
*/
|
2014-01-07 10:26:09 +01:00
|
|
|
struct GameDescription
|
|
|
|
{
|
|
|
|
std::wstring mapName;
|
|
|
|
NetworkSession* owner;
|
|
|
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
|
|
|
|
};
|
2014-01-28 15:04:25 +01:00
|
|
|
static GameSession* gameSession;
|
2014-01-07 10:26:09 +01:00
|
|
|
public:
|
|
|
|
GameSession();
|
|
|
|
virtual~GameSession();
|
|
|
|
|
|
|
|
/** Initiates and creates a game session. */
|
|
|
|
bool Create(GameDescription& desc);
|
|
|
|
|
|
|
|
/** Runs the game session (ie starts the game loop). */
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
/** Join an existing/running game session
|
|
|
|
* @param client The client to attach to the session
|
|
|
|
*/
|
|
|
|
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
|
|
|
|
|
|
|
|
/**
|
2014-01-13 12:44:33 +01:00
|
|
|
* Closes the game session
|
|
|
|
* @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session.
|
2014-01-07 10:26:09 +01:00
|
|
|
*/
|
2014-01-13 12:44:33 +01:00
|
|
|
void CloseSession(bool disconnectClients = false);
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
inline bool IsCreated() const { return this->isCreated; }
|
|
|
|
inline bool IsRunning() const { return this->isRunning; }
|
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//Private member functions
|
2014-01-07 10:26:09 +01:00
|
|
|
private:
|
2014-01-13 12:44:33 +01:00
|
|
|
//Handles all events recieved
|
2014-01-07 10:26:09 +01:00
|
|
|
void ParseEvents();
|
2014-01-13 12:44:33 +01:00
|
|
|
//Handles all gameplay events
|
2014-01-07 10:26:09 +01:00
|
|
|
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
|
2014-01-13 12:44:33 +01:00
|
|
|
//Handles all general events
|
2014-01-07 10:26:09 +01:00
|
|
|
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
|
2014-01-13 12:44:33 +01:00
|
|
|
//Adds a client to the client list
|
2014-01-20 15:47:52 +01:00
|
|
|
void InsertClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
|
2014-01-13 12:44:33 +01:00
|
|
|
//Removes a client from the client list
|
|
|
|
void RemoveClient(DanBias::GameClient* obj);
|
|
|
|
//Sends a protocol ta all clients in session
|
2014-01-07 10:26:09 +01:00
|
|
|
void Send(Oyster::Network::CustomNetProtocol* p);
|
2014-01-13 12:44:33 +01:00
|
|
|
//Frame function, derived from IThreadObject
|
2014-01-07 10:26:09 +01:00
|
|
|
bool DoWork ( ) override;
|
2014-01-13 12:44:33 +01:00
|
|
|
//Sends a client to the owner, if obj is NULL then all clients is sent
|
|
|
|
void SendToOwner(DanBias::GameClient* obj);
|
|
|
|
//Do a cleanup on all the private data
|
|
|
|
void Clean();
|
2014-01-15 11:03:25 +01:00
|
|
|
//Update game objects if needed
|
|
|
|
void UpdateGameObjects();
|
2014-01-07 10:26:09 +01:00
|
|
|
|
2014-01-13 12:44:33 +01:00
|
|
|
//Private member variables
|
2014-01-07 10:26:09 +01:00
|
|
|
private:
|
2014-01-13 12:44:33 +01:00
|
|
|
|
2014-01-07 10:26:09 +01:00
|
|
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
|
|
|
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
|
|
|
|
Oyster::Thread::OysterThread worker;
|
2014-01-20 15:47:52 +01:00
|
|
|
GameLogic::GameAPI& gameInstance;
|
|
|
|
GameLogic::ILevelData *levelData;
|
2014-01-13 12:44:33 +01:00
|
|
|
NetworkSession* owner;
|
2014-01-07 10:26:09 +01:00
|
|
|
bool isCreated;
|
|
|
|
bool isRunning;
|
2014-01-20 15:47:52 +01:00
|
|
|
Utility::WinTimer timer;
|
|
|
|
|
|
|
|
static void ObjectMove(GameLogic::IObjectData* movedObject);
|
2014-01-07 10:26:09 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class AdminInterface;
|
|
|
|
|
|
|
|
};//End GameSession
|
|
|
|
}//End namespace DanBias
|
|
|
|
#endif // !DANBIASSERVER_GAME_SESSION_H
|