mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
Fixed lua crash caused by lion with optimizations
This commit is contained in:
parent
f52308c439
commit
9b1bf071a8
@ -12,7 +12,7 @@
|
||||
class TLuaEngine : public IThreaded {
|
||||
public:
|
||||
explicit TLuaEngine(TServer& Server, TTCPServer& TCPServer, TUDPServer& UDPServer);
|
||||
~TLuaEngine();
|
||||
//~TLuaEngine();
|
||||
|
||||
using TSetOfLuaFile = std::set<std::unique_ptr<TLuaFile>>;
|
||||
|
||||
|
@ -20,7 +20,7 @@ class TLuaEngine;
|
||||
|
||||
class TLuaFile {
|
||||
public:
|
||||
void Init();
|
||||
void Load();
|
||||
void RegisterEvent(const std::string& Event, const std::string& FunctionName);
|
||||
void UnRegisterEvent(const std::string& Event);
|
||||
void SetLastWrite(fs::file_time_type time);
|
||||
@ -33,7 +33,7 @@ public:
|
||||
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);
|
||||
void Init(const std::string& PluginName, const std::string& FileName, fs::file_time_type LastWrote);
|
||||
explicit TLuaFile(TLuaEngine& Engine, bool Console = false);
|
||||
~TLuaFile();
|
||||
void SetStopThread(bool StopThread) { mStopThread = StopThread; }
|
||||
|
@ -18,14 +18,14 @@ public:
|
||||
|
||||
TServer(int argc, char** argv);
|
||||
|
||||
void InsertClient(std::shared_ptr<TClient> Ptr);
|
||||
void InsertClient(const std::shared_ptr<TClient>& Ptr);
|
||||
std::weak_ptr<TClient> InsertNewClient();
|
||||
void RemoveClient(std::weak_ptr<TClient>);
|
||||
void RemoveClient(const std::weak_ptr<TClient>&);
|
||||
// in Fn, return true to continue, return false to break
|
||||
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||
size_t ClientCount() const;
|
||||
|
||||
static void GlobalParser(std::weak_ptr<TClient> Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer);
|
||||
static void GlobalParser(const std::weak_ptr<TClient>& Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer);
|
||||
static void HandleEvent(TClient& c, const std::string& Data);
|
||||
|
||||
private:
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "Common.h"
|
||||
|
||||
#include "TConsole.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <zlib.h>
|
||||
|
@ -10,7 +10,7 @@ void THeartbeatThread::operator()() {
|
||||
std::string T;
|
||||
|
||||
// these are "hot-change" related variables
|
||||
static std::string Last = "";
|
||||
static std::string Last;
|
||||
|
||||
static std::chrono::high_resolution_clock::time_point LastNormalUpdateTime = std::chrono::high_resolution_clock::now();
|
||||
bool isAuth = false;
|
||||
|
@ -83,10 +83,11 @@ void TLuaEngine::RegisterFiles(const std::string& Path, bool HotSwap) {
|
||||
if (pos != std::string::npos && entry.path().string().length() - pos == 4) {
|
||||
if (!HotSwap || NewFile(entry.path().string())) {
|
||||
auto FileName = entry.path().string();
|
||||
std::unique_ptr<TLuaFile> ScriptToInsert(new TLuaFile(*this, Name, FileName, fs::last_write_time(FileName)));
|
||||
std::unique_ptr<TLuaFile> ScriptToInsert(new TLuaFile(*this));
|
||||
auto& Script = *ScriptToInsert;
|
||||
mLuaFiles.insert(std::move(ScriptToInsert));
|
||||
Script.Init();
|
||||
Script.Init(Name, FileName, fs::last_write_time(FileName));
|
||||
//Script.Load();
|
||||
if (HotSwap)
|
||||
info(("[HOTSWAP] Added : ") + Script.GetFileName().substr(Script.GetFileName().find('\\')));
|
||||
}
|
||||
@ -102,5 +103,5 @@ bool TLuaEngine::NewFile(const std::string& Path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TLuaEngine::~TLuaEngine() {
|
||||
}
|
||||
/*TLuaEngine::~TLuaEngine() {
|
||||
}*/
|
||||
|
@ -131,7 +131,7 @@ int lua_RegisterEvent(lua_State* L) {
|
||||
if (Args == 2 && lua_isstring(L, 1) && lua_isstring(L, 2)) {
|
||||
Script.RegisterEvent(lua_tostring(L, 1), lua_tostring(L, 2));
|
||||
} else
|
||||
SendError(Engine(), L, ("RegisterEvent invalid argument count expected 2 got ") + std::to_string(Args));
|
||||
SendError(Engine(), L, "RegisterEvent invalid argument count expected 2 got " + std::to_string(Args));
|
||||
return 0;
|
||||
}
|
||||
int lua_TriggerEventL(lua_State* L) {
|
||||
@ -308,7 +308,7 @@ int lua_GetGuest(lua_State* L) {
|
||||
}
|
||||
int lua_GetAllPlayers(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
Engine().Server().ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
Engine().Server().ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (ClientPtr.expired())
|
||||
return true;
|
||||
auto Client = ClientPtr.lock();
|
||||
@ -575,9 +575,8 @@ int lua_Print(lua_State* L) {
|
||||
|
||||
int lua_TempFix(lua_State* L);
|
||||
|
||||
TLuaFile::TLuaFile(TLuaEngine& Engine, const std::string& PluginName, const std::string& FileName, fs::file_time_type LastWrote, bool Console)
|
||||
: mEngine(Engine)
|
||||
, mLuaState(luaL_newstate()) {
|
||||
|
||||
void TLuaFile::Init(const std::string& PluginName, const std::string& FileName, fs::file_time_type LastWrote){
|
||||
// set global engine for lua_* functions
|
||||
if (!TheEngine) {
|
||||
TheEngine = &mEngine;
|
||||
@ -590,14 +589,16 @@ TLuaFile::TLuaFile(TLuaEngine& Engine, const std::string& PluginName, const std:
|
||||
SetFileName(FileName);
|
||||
}
|
||||
SetLastWrite(LastWrote);
|
||||
Init();
|
||||
Load();
|
||||
}
|
||||
|
||||
TLuaFile::TLuaFile(TLuaEngine& Engine, bool Console)
|
||||
: mEngine(Engine)
|
||||
, mLuaState(luaL_newstate()) {
|
||||
mConsole = Console;
|
||||
Init();
|
||||
if(Console) {
|
||||
mConsole = Console;
|
||||
Load();
|
||||
}
|
||||
}
|
||||
|
||||
void TLuaFile::Execute(const std::string& Command) {
|
||||
@ -642,7 +643,7 @@ void TLuaFile::SetFileName(const std::string& Name) {
|
||||
mFileName = Name;
|
||||
}
|
||||
|
||||
void TLuaFile::Init() {
|
||||
void TLuaFile::Load() {
|
||||
Assert(mLuaState);
|
||||
luaL_openlibs(mLuaState);
|
||||
lua_register(mLuaState, "TriggerGlobalEvent", lua_TriggerEventG);
|
||||
|
@ -29,7 +29,7 @@ void TPPSMonitor::operator()() {
|
||||
Application::SetPPS("-");
|
||||
continue;
|
||||
}
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto c = ClientPtr.lock();
|
||||
if (c->GetCarCount() > 0) {
|
||||
|
@ -18,8 +18,8 @@ TServer::TServer(int argc, char** argv) {
|
||||
if (argc > 1) {
|
||||
Application::Settings.CustomIP = argv[1];
|
||||
size_t n = std::count(Application::Settings.CustomIP.begin(), Application::Settings.CustomIP.end(), '.');
|
||||
auto p = Application::Settings.CustomIP.find_first_not_of((".0123456789"));
|
||||
if (p != std::string::npos || n != 3 || Application::Settings.CustomIP.substr(0, 3) == ("127")) {
|
||||
auto p = Application::Settings.CustomIP.find_first_not_of(".0123456789");
|
||||
if (p != std::string::npos || n != 3 || Application::Settings.CustomIP.substr(0, 3) == "127") {
|
||||
Application::Settings.CustomIP.clear();
|
||||
warn("IP Specified is invalid! Ignoring");
|
||||
} else {
|
||||
@ -28,7 +28,7 @@ TServer::TServer(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
void TServer::RemoveClient(std::weak_ptr<TClient> WeakClientPtr) {
|
||||
void TServer::RemoveClient(const std::weak_ptr<TClient>& WeakClientPtr) {
|
||||
if (!WeakClientPtr.expired()) {
|
||||
TClient& Client = *WeakClientPtr.lock();
|
||||
debug("removing client " + Client.GetName() + " (" + std::to_string(ClientCount()) + ")");
|
||||
@ -59,7 +59,7 @@ size_t TServer::ClientCount() const {
|
||||
return mClients.size();
|
||||
}
|
||||
|
||||
void TServer::GlobalParser(std::weak_ptr<TClient> Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer) {
|
||||
void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer) {
|
||||
if (Packet.find("Zp") != std::string::npos && Packet.size() > 500) {
|
||||
abort();
|
||||
}
|
||||
@ -271,7 +271,7 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
||||
c.SetCarData(VID, Header + Buffer.GetString());
|
||||
}
|
||||
|
||||
void TServer::InsertClient(std::shared_ptr<TClient> NewClient) {
|
||||
void TServer::InsertClient(const std::shared_ptr<TClient>& NewClient) {
|
||||
debug("inserting client (" + std::to_string(ClientCount()) + ")");
|
||||
WriteLock Lock(mClientsMutex);
|
||||
(void)mClients.insert(NewClient);
|
||||
|
@ -113,7 +113,7 @@ void TTCPServer::Authentication(SOCKET TCPSock) {
|
||||
|
||||
debug("Name -> " + Client->GetName() + ", Guest -> " + std::to_string(Client->IsGuest()) + ", Roles -> " + Client->GetRoles());
|
||||
debug("There are " + std::to_string(mServer.ClientCount()) + " known clients");
|
||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||
if (!ClientPtr.expired()) {
|
||||
auto Cl = ClientPtr.lock();
|
||||
info("Client Iteration: Name -> " + Client->GetName() + ", Guest -> " + std::to_string(Client->IsGuest()) + ", Roles -> " + Client->GetRoles());
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "TResourceManager.h"
|
||||
#include "TServer.h"
|
||||
#include "TUDPServer.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <TTCPServer.h>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user