mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-02-16 11:50:39 +00:00
fully implement lua
This commit is contained in:
committed by
Anonymous275
parent
459814a6ec
commit
4cda6e8bc3
@@ -17,7 +17,7 @@ class Application final {
|
||||
public:
|
||||
// types
|
||||
struct TSettings {
|
||||
TSettings()
|
||||
TSettings() noexcept
|
||||
: DebugModeEnabled(true) { }
|
||||
std::string ServerName;
|
||||
std::string ServerDesc;
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
bool DebugModeEnabled;
|
||||
int Port;
|
||||
std::string CustomIP;
|
||||
bool HasCustomIP() const { return !CustomIP.empty(); }
|
||||
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
|
||||
|
||||
// new settings
|
||||
std::string ResourceFolder;
|
||||
@@ -44,20 +44,21 @@ public:
|
||||
static void RegisterShutdownHandler(const TShutdownHandler& Handler);
|
||||
// Causes all threads to finish up and exit gracefull gracefully
|
||||
static void GracefullyShutdown();
|
||||
static TConsole& Console() { return *_Console; }
|
||||
static TConsole& Console() { return *mConsole; }
|
||||
static std::string ServerVersion() { return "v1.20"; }
|
||||
|
||||
static inline TSettings Settings {};
|
||||
|
||||
private:
|
||||
static std::unique_ptr<TConsole> _Console;
|
||||
static inline std::mutex _ShutdownHandlersMutex {};
|
||||
static inline std::vector<TShutdownHandler> _ShutdownHandlers {};
|
||||
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) { \
|
||||
|
||||
@@ -11,6 +11,5 @@ public:
|
||||
void Write(const std::string& str);
|
||||
|
||||
private:
|
||||
Commandline _Commandline;
|
||||
Commandline mCommandline;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Common.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TServer.h"
|
||||
#include <lua.hpp>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
@@ -11,13 +12,15 @@ class TLuaFile;
|
||||
|
||||
class TLuaEngine : public IThreaded {
|
||||
public:
|
||||
explicit TLuaEngine(TServer& Server);
|
||||
|
||||
using TSetOfLuaFile = std::set<std::unique_ptr<TLuaFile>>;
|
||||
|
||||
TLuaEngine();
|
||||
void operator()() override;
|
||||
|
||||
virtual void operator()() override;
|
||||
|
||||
const TSetOfLuaFile& LuaFiles() const { return _LuaFiles; }
|
||||
[[nodiscard]] const TSetOfLuaFile& LuaFiles() const { return mLuaFiles; }
|
||||
[[nodiscard]] TServer& Server() { return mServer; }
|
||||
[[nodiscard]] const TServer& Server() const { return mServer; }
|
||||
|
||||
std::optional<std::reference_wrapper<TLuaFile>> GetScript(lua_State* L);
|
||||
|
||||
@@ -26,7 +29,8 @@ private:
|
||||
void RegisterFiles(const std::string& Path, bool HotSwap);
|
||||
bool NewFile(const std::string& Path);
|
||||
|
||||
TSetOfLuaFile _LuaFiles;
|
||||
TServer& mServer;
|
||||
TSetOfLuaFile mLuaFiles;
|
||||
};
|
||||
|
||||
#endif // TLUAENGINE_H
|
||||
|
||||
@@ -21,7 +21,6 @@ class TLuaFile {
|
||||
public:
|
||||
void Init();
|
||||
void RegisterEvent(const std::string& Event, const std::string& FunctionName);
|
||||
std::string GetRegistered(const std::string& Event) const;
|
||||
void UnRegisterEvent(const std::string& Event);
|
||||
void SetLastWrite(fs::file_time_type time);
|
||||
bool IsRegistered(const std::string& Event);
|
||||
@@ -29,30 +28,31 @@ public:
|
||||
void Execute(const std::string& Command);
|
||||
void SetFileName(const std::string& Name);
|
||||
fs::file_time_type GetLastWrite();
|
||||
std::string GetPluginName() const;
|
||||
std::string GetFileName() const;
|
||||
lua_State* GetState();
|
||||
const lua_State* GetState() const;
|
||||
std::string GetOrigin();
|
||||
std::mutex Lock;
|
||||
void Reload();
|
||||
TLuaFile(TLuaEngine& Engine, const std::string& PluginName, const std::string& FileName, fs::file_time_type LastWrote, bool Console = false);
|
||||
TLuaFile(TLuaEngine& Engine, bool Console = false);
|
||||
explicit TLuaFile(TLuaEngine& Engine, bool Console = false);
|
||||
~TLuaFile();
|
||||
void SetStopThread(bool StopThread) { _StopThread = StopThread; }
|
||||
bool GetStopThread() const { return _StopThread; }
|
||||
TLuaEngine& Engine() { return _Engine; }
|
||||
const TLuaEngine& Engine() const { return _Engine; }
|
||||
void SetStopThread(bool StopThread) { mStopThread = StopThread; }
|
||||
TLuaEngine& Engine() { return mEngine; }
|
||||
[[nodiscard]] std::string GetPluginName() const;
|
||||
[[nodiscard]] std::string GetFileName() const;
|
||||
[[nodiscard]] const lua_State* GetState() const;
|
||||
[[nodiscard]] bool GetStopThread() const { return mStopThread; }
|
||||
[[nodiscard]] const TLuaEngine& Engine() const { return mEngine; }
|
||||
[[nodiscard]] std::string GetRegistered(const std::string& Event) const;
|
||||
|
||||
private:
|
||||
TLuaEngine& _Engine;
|
||||
std::set<std::pair<std::string, std::string>> _RegisteredEvents;
|
||||
lua_State* luaState { nullptr };
|
||||
fs::file_time_type _LastWrote;
|
||||
std::string _PluginName {};
|
||||
std::string _FileName {};
|
||||
bool _StopThread = false;
|
||||
bool _Console = false;
|
||||
TLuaEngine& mEngine;
|
||||
std::set<std::pair<std::string, std::string>> mRegisteredEvents;
|
||||
lua_State* mLuaState { nullptr };
|
||||
fs::file_time_type mLastWrote;
|
||||
std::string mPluginName {};
|
||||
std::string mFileName {};
|
||||
bool mStopThread = false;
|
||||
bool mConsole = false;
|
||||
};
|
||||
|
||||
#endif // TLUAFILE_H
|
||||
|
||||
@@ -17,10 +17,10 @@ public:
|
||||
|
||||
std::weak_ptr<TClient> InsertNewClient();
|
||||
void RemoveClient(std::weak_ptr<TClient>);
|
||||
void ForEachClient(std::function<bool(std::weak_ptr<TClient>)>);
|
||||
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||
size_t ClientCount() const;
|
||||
|
||||
private:
|
||||
TClientSet _Clients;
|
||||
mutable RWMutex _ClientsMutex;
|
||||
TClientSet mClients;
|
||||
mutable RWMutex mClientsMutex;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user