1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 10:23:51 +00:00
openmw-tes3mp/apps/master/MasterServer.hpp

57 lines
1.3 KiB
C++
Raw Normal View History

2017-04-23 05:39:38 +00:00
//
// Created by koncord on 21.04.17.
//
#ifndef NEWMASTERPROTO_MASTERSERVER_HPP
#define NEWMASTERPROTO_MASTERSERVER_HPP
#include <thread>
#include <chrono>
#include <RakPeerInterface.h>
#include <components/openmw-mp/Master/MasterData.hpp>
#include <sol.hpp>
#include <mutex>
2017-04-23 05:39:38 +00:00
class MasterServer
{
public:
2017-05-19 16:02:12 +00:00
struct SServer : QueryData
{
std::chrono::steady_clock::time_point lastUpdate;
};
2017-04-23 05:39:38 +00:00
typedef std::map<RakNet::SystemAddress, SServer> ServerMap;
2017-05-19 16:02:12 +00:00
//typedef ServerMap::const_iterator ServerCIter;
2017-04-23 05:39:38 +00:00
typedef ServerMap::iterator ServerIter;
explicit MasterServer(const std::string &luaScript);
2017-05-19 16:02:12 +00:00
~MasterServer();
void Start();
void Stop(bool wait = false);
bool isRunning();
void Wait();
ServerMap* GetServers();
void luaStuff(std::function<void(sol::state &)> f);
2017-05-19 16:02:12 +00:00
2017-09-12 12:24:50 +00:00
void ban(const std::string &addr);
void unban(const std::string &addr);
2017-04-23 05:39:38 +00:00
private:
void Thread();
private:
std::thread tMasterThread;
RakNet::RakPeerInterface* peer;
RakNet::SocketDescriptor sockdescr;
ServerMap servers;
bool run;
std::map<RakNet::RakNetGUID, std::chrono::steady_clock::time_point> pendingACKs;
sol::state state;
std::mutex luaMutex;
std::mutex banMutex;
2017-04-23 05:39:38 +00:00
};
#endif //NEWMASTERPROTO_MASTERSERVER_HPP