2014-01-28 09:00:02 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef NETWORK_API_NETWORK_SESSION_H
|
|
|
|
#define NETWORK_API_NETWORK_SESSION_H
|
|
|
|
|
|
|
|
//warning C4150: deletion of pointer to incomplete type, no destructor called
|
|
|
|
#pragma warning(disable : 4150)
|
2014-01-30 14:15:25 +01:00
|
|
|
//needs to have dll-interface to be used by clients of class 'Oyster::Network::NetworkSession'
|
|
|
|
#pragma warning(disable : 4251)
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
#include "NetworkAPI_Preprocessor.h"
|
|
|
|
#include "NetworkServerEventStruct.h"
|
|
|
|
#include "NetworkClient.h"
|
2014-01-30 15:02:02 +01:00
|
|
|
#include "..\Misc\Utilities.h"
|
2014-01-30 11:11:04 +01:00
|
|
|
#include "DynamicArray.h"
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Network
|
|
|
|
{
|
2014-01-29 10:18:01 +01:00
|
|
|
typedef Utility::DynamicMemory::SmartPointer<NetworkClient> NetClient;
|
2014-01-30 14:15:25 +01:00
|
|
|
typedef Utility::DynamicMemory::DynamicArray<NetClient> NetClientList;
|
2014-01-28 09:00:02 +01:00
|
|
|
class NET_API_EXPORT NetworkSession
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NetworkSession();
|
|
|
|
NetworkSession(const NetworkSession& orig);
|
|
|
|
const NetworkSession& operator=(const NetworkSession& orig);
|
|
|
|
virtual~NetworkSession();
|
|
|
|
|
|
|
|
/** Parse session events such as protocols recieved etc.
|
|
|
|
*/
|
|
|
|
void ProcessClients();
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual bool Attach(NetClient client);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
2014-01-29 10:18:01 +01:00
|
|
|
/**
|
|
|
|
* Detaches all clients and sends them to owner.
|
|
|
|
* If no owner is set the clients is disconnected.
|
|
|
|
*/
|
2014-01-30 11:11:04 +01:00
|
|
|
virtual void DetachAll();
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual NetClient Detach(const NetworkClient* client);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual NetClient Detach(short ID);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
2014-01-30 11:11:04 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
virtual NetClient Detach();
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
/** Send a message to all clients in this session
|
|
|
|
* @param message The message
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual bool Send(Oyster::Network::CustomNetProtocol& message);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/** Send a message to a specific client in this session
|
|
|
|
* @param message The message
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual void CloseSession( bool dissconnectClients = false );
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the owner that clients will be returned to.
|
|
|
|
* @param owner If owner is NULL, clients will be disconnected when session is over.
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual void SetOwner(NetworkSession* owner);
|
|
|
|
|
|
|
|
/** Get the number of clients active in this session
|
|
|
|
* @return The client count
|
|
|
|
*/
|
2014-01-30 11:11:04 +01:00
|
|
|
inline int GetClientCount() const { return this->clientCount; }
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual void ClientConnectedEvent(NetClient client);
|
2014-01-28 09:00:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 10:18:01 +01:00
|
|
|
virtual void ClientEventCallback(NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e) = 0;
|
2014-01-28 09:00:02 +01:00
|
|
|
|
2014-01-30 14:15:25 +01:00
|
|
|
protected:
|
|
|
|
NetClientList clients;
|
|
|
|
|
2014-01-28 09:00:02 +01:00
|
|
|
private:
|
2014-01-30 11:11:04 +01:00
|
|
|
int clientCount;
|
2014-01-28 09:00:02 +01:00
|
|
|
struct PrivateSessionData;
|
|
|
|
PrivateSessionData* data;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}//End namespace DanBias
|
|
|
|
|
|
|
|
#endif // !DANBIASSERVER_NETWORK_SESSION_H
|