2014-07-06 23:54:47 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include <thread>
|
2014-07-06 23:54:47 +00:00
|
|
|
#include "GameServerConnection.h"
|
2014-07-09 23:05:07 +00:00
|
|
|
#include "INotificationListener.h"
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
using std::thread;
|
|
|
|
|
|
|
|
class GameServer : public IGameBroadcaster
|
2014-07-06 23:54:47 +00:00
|
|
|
{
|
|
|
|
private:
|
2014-07-09 22:29:07 +00:00
|
|
|
static unique_ptr<GameServer> Instance;
|
|
|
|
unique_ptr<thread> _serverThread;
|
|
|
|
atomic<bool> _stop;
|
|
|
|
|
|
|
|
unique_ptr<Socket> _listener;
|
2015-07-02 03:17:14 +00:00
|
|
|
uint16_t _port;
|
2014-07-06 23:54:47 +00:00
|
|
|
list<shared_ptr<GameServerConnection>> _openConnections;
|
|
|
|
bool _initialized = false;
|
|
|
|
|
2014-07-09 22:29:07 +00:00
|
|
|
void AcceptConnections();
|
|
|
|
void UpdateConnections();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2014-07-09 22:29:07 +00:00
|
|
|
void Exec();
|
|
|
|
void Stop();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
|
|
|
public:
|
2014-07-09 22:29:07 +00:00
|
|
|
GameServer();
|
|
|
|
~GameServer();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
static void StartServer(uint16_t port);
|
2014-07-09 22:29:07 +00:00
|
|
|
static void StopServer();
|
|
|
|
static bool Started();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2014-07-09 22:29:07 +00:00
|
|
|
virtual void BroadcastInput(uint8_t inputData, uint8_t port);
|
2014-07-06 23:54:47 +00:00
|
|
|
};
|