add PPSMonitor

This commit is contained in:
Lion Kortlepel
2021-02-16 13:19:39 +01:00
committed by Anonymous275
parent 72607583bf
commit f19a012509
15 changed files with 185 additions and 66 deletions

View File

@@ -24,11 +24,11 @@ public:
std::string Resource;
std::string MapName;
std::string Key;
int MaxPlayers;
bool Private;
int MaxCars;
int MaxPlayers {};
bool Private {};
int MaxCars {};
bool DebugModeEnabled;
int Port;
int Port {};
std::string CustomIP;
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
@@ -46,22 +46,33 @@ public:
static void GracefullyShutdown();
static TConsole& Console() { return *mConsole; }
static std::string ServerVersion() { return "v1.20"; }
static std::string ClientVersion() { return "v1.80"; }
static std::string PPS() { return mPPS; }
static void SetPPS(std::string NewPPS) { mPPS = NewPPS; }
static inline TSettings Settings {};
private:
static inline std::string mPPS;
static std::unique_ptr<TConsole> mConsole;
static inline std::mutex mShutdownHandlersMutex {};
static inline std::vector<TShutdownHandler> mShutdownHandlers {};
};
#define warn(x) Application::Console().Write(std::string("[WARN] ") + (x))
#define error(x) Application::Console().Write(std::string("[ERROR] ") + (x))
#define info(x) Application::Console().Write(std::string("[INFO] ") + (x))
#define luaprint(x) Application::Console().Write(std::string("[LUA] ") + (x))
#define debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
Application::Console().Write(std::string("[DEBUG] ") + (x)); \
} \
} while (false)
static inline void warn(const std::string& str) {
Application::Console().Write(std::string("[WARN] ") + str);
}
static inline void error(const std::string& str) {
Application::Console().Write(std::string("[ERROR] ") + str);
}
static inline void info(const std::string& str) {
Application::Console().Write(std::string("[INFO] ") + str);
}
static inline void debug(const std::string& str) {
if (Application::Settings.DebugModeEnabled) {
Application::Console().Write(std::string("[DEBUG] ") + str);
}
}
static inline void luaprint(const std::string& str) {
Application::Console().Write(std::string("[LUA] ") + str);
}

View File

@@ -7,10 +7,10 @@ class IThreaded {
public:
IThreaded()
// invokes operator() on this object
: _Thread(std::thread([this] { (*this)(); })) { }
: mThread(std::thread([this] { (*this)(); })) { }
virtual void operator()() = 0;
protected:
std::thread _Thread;
std::thread mThread;
};

View File

@@ -5,6 +5,7 @@
#include <mutex>
#include <sio_client.h>
#include <thread>
#include <memory>
/*
* We send relevant server events over socket.io to the backend.
@@ -44,10 +45,10 @@ public:
~SocketIO();
void SetAuthenticated(bool auth) { _Authenticated = auth; }
void SetAuthenticated(bool auth) { mAuthenticated = auth; }
private:
SocketIO();
SocketIO() noexcept;
void ThreadMain();
@@ -57,12 +58,12 @@ private:
std::string Data;
};
bool _Authenticated { false };
sio::client _Client;
std::thread _Thread;
std::atomic_bool _CloseThread { false };
std::mutex _QueueMutex;
std::deque<Event> _Queue;
bool mAuthenticated { false };
sio::client mClient;
std::thread mThread;
std::atomic_bool mCloseThread { false };
std::mutex mQueueMutex;
std::deque<Event> mQueue;
friend std::unique_ptr<SocketIO> std::make_unique<SocketIO>();
};

View File

@@ -7,6 +7,6 @@ public:
TConfig(const std::string& ConfigFile);
private:
std::string RemoveComments(const std::string& Line);
void SetValues(const std::string& Line, int Index);
static std::string RemoveComments(const std::string& Line);
static void SetValues(const std::string& Line, int Index);
};

View File

@@ -1,10 +1,21 @@
#pragma once
#include "IThreaded.h"
#include "Common.h"
#include "IThreaded.h"
#include "TResourceManager.h"
#include "TServer.h"
class THeartbeatThread : public IThreaded {
public:
THeartbeatThread();
THeartbeatThread(TResourceManager& ResourceManager, TServer& Server);
~THeartbeatThread();
void operator()() override;
private:
std::string GenerateCall();
std::string GetPlayers();
bool mShutdown = false;
TResourceManager& mResourceManager;
TServer& mServer;
};

View File

@@ -3,13 +3,12 @@
#include "Common.h"
#include "IThreaded.h"
#include "TLuaFile.h"
#include "TServer.h"
#include <lua.hpp>
#include <memory>
#include <set>
class TLuaFile;
class TLuaEngine : public IThreaded {
public:
explicit TLuaEngine(TServer& Server);

View File

@@ -1,7 +1,6 @@
#ifndef TLUAFILE_H
#define TLUAFILE_H
#include "TLuaEngine.h"
#include <any>
#include <filesystem>
#include <lua.hpp>
@@ -17,6 +16,8 @@ struct TLuaArg {
void PushArgs(lua_State* State);
};
class TLuaEngine;
class TLuaFile {
public:
void Init();

18
include/TPPSMonitor.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include "Common.h"
#include "IThreaded.h"
#include "TServer.h"
class TPPSMonitor : public IThreaded {
public:
TPPSMonitor(TServer& Server);
void operator()() override;
private:
TServer& mServer;
bool mShutdown { false };
int mInternalPPS { 0 };
};