mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 22:23:03 +00:00
fix lua file stuff and more file stuff
This commit is contained in:
@@ -3,10 +3,10 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <lua.hpp>
|
|
||||||
#include <any>
|
#include <any>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <lua.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -43,14 +43,13 @@ private:
|
|||||||
std::set<std::pair<std::string, std::string>> _RegisteredEvents;
|
std::set<std::pair<std::string, std::string>> _RegisteredEvents;
|
||||||
lua_State* luaState { nullptr };
|
lua_State* luaState { nullptr };
|
||||||
fs::file_time_type _LastWrote;
|
fs::file_time_type _LastWrote;
|
||||||
std::string _PluginName;
|
std::string _PluginName {};
|
||||||
std::string _FileName;
|
std::string _FileName {};
|
||||||
bool _StopThread = false;
|
bool _StopThread = false;
|
||||||
bool _Console = false;
|
bool _Console = false;
|
||||||
// this is called by the ctor to ensure RAII
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void Init();
|
||||||
void RegisterEvent(const std::string& Event, const std::string& FunctionName);
|
void RegisterEvent(const std::string& Event, const std::string& FunctionName);
|
||||||
std::string GetRegistered(const std::string& Event) const;
|
std::string GetRegistered(const std::string& Event) const;
|
||||||
void UnRegisterEvent(const std::string& Event);
|
void UnRegisterEvent(const std::string& Event);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ void RegisterFiles(const std::string& Path, bool HotSwap) {
|
|||||||
std::unique_ptr<Lua> ScriptToInsert(new Lua(Name, FileName, fs::last_write_time(FileName)));
|
std::unique_ptr<Lua> ScriptToInsert(new Lua(Name, FileName, fs::last_write_time(FileName)));
|
||||||
auto& Script = *ScriptToInsert;
|
auto& Script = *ScriptToInsert;
|
||||||
PluginEngine.insert(std::move(ScriptToInsert));
|
PluginEngine.insert(std::move(ScriptToInsert));
|
||||||
|
Script.Init();
|
||||||
if (HotSwap)
|
if (HotSwap)
|
||||||
info(Sec("[HOTSWAP] Added : ") + Script.GetFileName().substr(Script.GetFileName().find('\\')));
|
info(Sec("[HOTSWAP] Added : ") + Script.GetFileName().substr(Script.GetFileName().find('\\')));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ bool CheckLua(lua_State* L, int r) {
|
|||||||
auto MaybeS = GetScript(L);
|
auto MaybeS = GetScript(L);
|
||||||
if (MaybeS.has_value()) {
|
if (MaybeS.has_value()) {
|
||||||
Lua& S = MaybeS.value();
|
Lua& S = MaybeS.value();
|
||||||
std::string a = S.GetFileName().substr(S.GetFileName().find('\\'));
|
std::string a = fs::path(S.GetFileName()).filename().string();
|
||||||
warn(a + " | " + msg);
|
warn(a + " | " + msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ int lua_TriggerEventG(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* ThreadOrigin(Lua* lua) {
|
char* ThreadOrigin(Lua* lua) {
|
||||||
std::string T = "Thread in " + lua->GetFileName().substr(lua->GetFileName().find('\\'));
|
std::string T = "Thread in " + fs::path(lua->GetFileName()).filename().string();
|
||||||
char* Data = new char[T.size() + 1];
|
char* Data = new char[T.size() + 1];
|
||||||
ZeroMemory(Data, T.size() + 1);
|
ZeroMemory(Data, T.size() + 1);
|
||||||
memcpy(Data, T.c_str(), T.size());
|
memcpy(Data, T.c_str(), T.size());
|
||||||
@@ -542,13 +542,11 @@ Lua::Lua(const std::string& PluginName, const std::string& FileName, fs::file_ti
|
|||||||
}
|
}
|
||||||
SetLastWrite(LastWrote);
|
SetLastWrite(LastWrote);
|
||||||
_Console = Console;
|
_Console = Console;
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Lua::Lua(bool Console)
|
Lua::Lua(bool Console)
|
||||||
: luaState(luaL_newstate()) {
|
: luaState(luaL_newstate()) {
|
||||||
_Console = Console;
|
_Console = Console;
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lua::Execute(const std::string& Command) {
|
void Lua::Execute(const std::string& Command) {
|
||||||
|
|||||||
+18
-23
@@ -27,32 +27,27 @@ void UnixSignalHandler(int sig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
try {
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// ignore SIGPIPE, the signal that is sent for example when a client
|
// ignore SIGPIPE, the signal that is sent for example when a client
|
||||||
// disconnects while data is being sent to him ("broken pipe").
|
// disconnects while data is being sent to him ("broken pipe").
|
||||||
signal(SIGPIPE, UnixSignalHandler);
|
signal(SIGPIPE, UnixSignalHandler);
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
// curl needs to be initialized to properly deallocate its resources later
|
// curl needs to be initialized to properly deallocate its resources later
|
||||||
Assert(curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK);
|
Assert(curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::thread t1(loop);
|
std::thread t1(loop);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
#endif
|
#endif
|
||||||
ConsoleInit();
|
ConsoleInit();
|
||||||
InitServer(argc, argv);
|
InitServer(argc, argv);
|
||||||
InitConfig();
|
InitConfig();
|
||||||
InitLua();
|
InitLua();
|
||||||
InitRes();
|
InitRes();
|
||||||
HBInit();
|
HBInit();
|
||||||
StatInit();
|
StatInit();
|
||||||
NetMain();
|
NetMain();
|
||||||
// clean up curl at the end to be sure
|
// clean up curl at the end to be sure
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
} catch (const std::exception& e) {
|
|
||||||
error(std::string(e.what()));
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user