2014-07-06 19:54:47 -04:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
2015-07-01 23:17:14 -04:00
|
|
|
#include <thread>
|
2014-07-06 19:54:47 -04:00
|
|
|
#include "GameServerConnection.h"
|
2014-07-09 19:05:07 -04:00
|
|
|
#include "INotificationListener.h"
|
2017-11-19 23:08:23 -05:00
|
|
|
#include "IInputProvider.h"
|
|
|
|
#include "IInputRecorder.h"
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2015-07-01 23:17:14 -04:00
|
|
|
using std::thread;
|
2018-07-01 15:21:05 -04:00
|
|
|
class Console;
|
2015-07-01 23:17:14 -04:00
|
|
|
|
2018-07-02 18:11:12 -04:00
|
|
|
class GameServer : public IInputRecorder, public IInputProvider, public INotificationListener
|
2014-07-06 19:54:47 -04:00
|
|
|
{
|
|
|
|
private:
|
2018-07-02 18:11:12 -04:00
|
|
|
static shared_ptr<GameServer> Instance;
|
2018-07-01 15:21:05 -04:00
|
|
|
shared_ptr<Console> _console;
|
2014-07-09 18:29:07 -04:00
|
|
|
unique_ptr<thread> _serverThread;
|
|
|
|
atomic<bool> _stop;
|
|
|
|
unique_ptr<Socket> _listener;
|
2015-07-01 23:17:14 -04:00
|
|
|
uint16_t _port;
|
2018-06-16 14:02:12 -04:00
|
|
|
string _password;
|
2014-07-06 19:54:47 -04:00
|
|
|
list<shared_ptr<GameServerConnection>> _openConnections;
|
|
|
|
bool _initialized = false;
|
|
|
|
|
2016-02-06 15:33:45 -05:00
|
|
|
string _hostPlayerName;
|
|
|
|
uint8_t _hostControllerPort;
|
|
|
|
|
2014-07-09 18:29:07 -04:00
|
|
|
void AcceptConnections();
|
|
|
|
void UpdateConnections();
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2014-07-09 18:29:07 -04:00
|
|
|
void Exec();
|
|
|
|
void Stop();
|
2014-07-06 19:54:47 -04:00
|
|
|
|
|
|
|
public:
|
2018-07-01 15:21:05 -04:00
|
|
|
GameServer(shared_ptr<Console> console, uint16_t port, string password, string hostPlayerName);
|
2018-06-11 19:07:05 -04:00
|
|
|
virtual ~GameServer();
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2018-07-02 18:11:12 -04:00
|
|
|
void RegisterServerInput();
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
static void StartServer(shared_ptr<Console> console, uint16_t port, string password, string hostPlayerName);
|
2014-07-09 18:29:07 -04:00
|
|
|
static void StopServer();
|
|
|
|
static bool Started();
|
2014-07-06 19:54:47 -04:00
|
|
|
|
2016-02-06 15:33:45 -05:00
|
|
|
static string GetHostPlayerName();
|
|
|
|
static uint8_t GetHostControllerPort();
|
|
|
|
static void SetHostControllerPort(uint8_t port);
|
|
|
|
static uint8_t GetAvailableControllers();
|
|
|
|
static vector<PlayerInfo> GetPlayerList();
|
|
|
|
static void SendPlayerList();
|
|
|
|
|
|
|
|
static list<shared_ptr<GameServerConnection>> GetConnectionList();
|
|
|
|
|
2017-11-19 23:08:23 -05:00
|
|
|
bool SetInput(BaseControlDevice *device) override;
|
2017-11-21 17:54:54 -05:00
|
|
|
void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
|
2018-07-02 18:11:12 -04:00
|
|
|
|
|
|
|
// Inherited via INotificationListener
|
|
|
|
virtual void ProcessNotification(ConsoleNotificationType type, void * parameter) override;
|
2014-07-06 19:54:47 -04:00
|
|
|
};
|