Danbias/Code/Network/NetworkAPI/NetworkServer.h

146 lines
3.2 KiB
C
Raw Permalink Normal View History

2013-12-10 08:32:08 +01:00
#ifndef NETWORK_API_NETWORK_SERVER_H
#define NETWORK_API_NETWORK_SERVER_H
2014-01-28 09:00:02 +01:00
//////////////////////////////////////
// Created by Pontus Fransson 2013 //
// Modified by Dennis Andersen 2014 //
//////////////////////////////////////
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
#include "NetworkAPI_Preprocessor.h"
#include "NetworkClient.h"
2014-01-28 09:00:02 +01:00
#include "NetworkSession.h"
2013-12-13 23:47:16 +01:00
#include <vld.h>
2013-12-10 08:32:08 +01:00
namespace Oyster
{
namespace Network
{
extern "C"
2013-12-10 08:32:08 +01:00
{
struct ServerOptions
{
struct BroadcastOptions
{
2014-02-21 09:34:09 +01:00
bool broadcast;
float broadcastInterval;
std::wstring subnetToBroadcast;
CustomNetProtocol broadcastMessage;
BroadcastOptions()
{
broadcast = true;
broadcastInterval = 1.0f;
subnetToBroadcast = L"192.168.0.1";
}
} broadcastOptions;
struct MainOptions
{
NetworkSession* ownerSession;
int listenPort;
MainOptions()
{
ownerSession = 0;
listenPort = 0;
}
} mainOptions;
};
2014-01-28 09:00:02 +01:00
class NET_API_EXPORT NetworkServer
2013-12-10 08:32:08 +01:00
{
public:
2014-01-28 09:00:02 +01:00
enum ServerReturnCode
2013-12-10 08:32:08 +01:00
{
2014-01-28 09:00:02 +01:00
ServerReturnCode_Error,
ServerReturnCode_Sucess
};
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
public:
NetworkServer();
2014-01-28 09:00:02 +01:00
NetworkServer(const NetworkServer&);
const NetworkServer& operator=(const NetworkServer&);
virtual ~NetworkServer();
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
/** Creates a server that clients can connect to
* @param port The port the server will be listening for clients.
* @param mainSession The main session the server will send connected clients to.
* @return The server returncode
*/
ServerReturnCode Init(ServerOptions& options);
2014-01-28 09:00:02 +01:00
/** Starts the server allowing clients to connect
* @return The server returncode
*/
ServerReturnCode Start();
2014-01-30 00:19:00 +01:00
/** Parses asynchronous connected clients.
*/
int Update();
2014-01-28 09:00:02 +01:00
/**
*
*/
void Stop();
2014-01-28 09:00:02 +01:00
/** Shutdown the server and return all resources.
*/
void Shutdown();
2013-12-10 08:32:08 +01:00
2014-01-28 09:00:02 +01:00
/** Set the main session connected clients will enter when connected to server.
* @param mainSession The session to connect as main server session.
*/
void SetSession(NetworkSession const* mainSession);
/** Get the main session connected with the server
* @return Returns the main session
*/
NetworkSession const* GetMainSession();
/** Sets the main session to NULL and returns it
* @return Returns the main session
*/
2014-01-29 10:18:01 +01:00
NetworkSession const* ReleaseMainSession();
2014-01-28 09:00:02 +01:00
/**
*
*/
bool IsRunning() const;
2013-12-10 08:32:08 +01:00
2014-01-29 10:18:01 +01:00
/**
*
*/
std::string GetLanAddress();
2014-01-28 09:00:02 +01:00
/** Returns the port the server is listening on.
* @return Returns the port the server has been initiated with.
2014-01-30 00:19:00 +01:00
*/
int NetworkServer::GetPort();
2014-02-21 09:34:09 +01:00
/***************************************
Broadcast functions
***************************************/
//Set broadcast settings.
void SetBroadcast(CustomNetProtocol& broadcastMessage, float interval = 1.0f, bool enable = true);
//Set broadcast settings.
void SetBroadcastMessage(CustomNetProtocol& broadcastMessage);
//Enable/disable broadcast.
void SetBroadcast(bool enable);
//Set interval between each broadcast message in seconds.
void SetBroadcastInterval(float interval);
private:
struct PrivateData;
PrivateData* privateData;
2013-12-10 08:32:08 +01:00
};
2013-12-10 08:32:08 +01:00
}
}
}
#endif