mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
make the compiler happy
This commit is contained in:
parent
a0241d1b36
commit
5468e5c854
@ -48,6 +48,7 @@ set(PRJ_HEADERS
|
||||
include/Value.h
|
||||
include/VehicleData.h
|
||||
include/Network.h
|
||||
include/Env.h
|
||||
)
|
||||
# add all source files (.cpp) to this, except the one with main()
|
||||
set(PRJ_SOURCES
|
||||
@ -66,6 +67,7 @@ set(PRJ_SOURCES
|
||||
src/Value.cpp
|
||||
src/VehicleData.cpp
|
||||
src/Network.cpp
|
||||
src/Env.cpp
|
||||
)
|
||||
|
||||
find_package(Lua REQUIRED)
|
||||
@ -96,6 +98,7 @@ set(PRJ_LIBRARIES
|
||||
${LUA_LIBRARIES}
|
||||
zstd::libzstd_static
|
||||
Boost::thread
|
||||
Boost::json
|
||||
glm::glm
|
||||
)
|
||||
|
||||
@ -103,7 +106,7 @@ set(PRJ_LIBRARIES
|
||||
find_package(fmt CONFIG REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
find_package(doctest CONFIG REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS thread)
|
||||
find_package(Boost REQUIRED COMPONENTS thread json)
|
||||
find_package(httplib CONFIG REQUIRED)
|
||||
find_package(libzip CONFIG REQUIRED)
|
||||
find_package(RapidJSON CONFIG REQUIRED)
|
||||
|
@ -23,7 +23,11 @@
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <filesystem>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/ostream.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <fmt/std.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "Error.h"
|
||||
#include "Value.h"
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
@ -17,7 +18,7 @@ public:
|
||||
/// Self-managing pointer type of this plugin.
|
||||
using Pointer = std::unique_ptr<Plugin>;
|
||||
/// Allocates a Plugin of the specific derived plugin type.
|
||||
template<typename T, typename... Args>
|
||||
template <typename T, typename... Args>
|
||||
static Pointer make_pointer(Args&&... args) {
|
||||
return std::unique_ptr<Plugin>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
@ -65,4 +66,3 @@ public:
|
||||
/// should be returned regardless.
|
||||
virtual size_t memory_usage() const = 0;
|
||||
};
|
||||
|
||||
|
@ -30,8 +30,6 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class TLuaEngine;
|
||||
|
||||
class TConsole {
|
||||
public:
|
||||
TConsole();
|
||||
@ -41,7 +39,7 @@ public:
|
||||
|
||||
void Write(const std::string& str);
|
||||
void WriteRaw(const std::string& str);
|
||||
void InitializeLuaConsole(TLuaEngine& Engine);
|
||||
// void InitializeLuaConsole(TLuaEngine& Engine);
|
||||
void BackupOldLog();
|
||||
void StartLoggingToFile();
|
||||
Commandline& Internal() { return *mCommandline; }
|
||||
@ -81,7 +79,6 @@ private:
|
||||
std::unique_ptr<Commandline> mCommandline { nullptr };
|
||||
std::vector<std::string> mCachedLuaHistory;
|
||||
std::vector<std::string> mCachedRegularHistory;
|
||||
TLuaEngine* mLuaEngine { nullptr };
|
||||
bool mIsLuaConsole { false };
|
||||
bool mFirstTime { true };
|
||||
std::string mStateId;
|
||||
|
@ -40,18 +40,18 @@ void FileWatcher::on_tick(const boost::system::error_code& err) {
|
||||
timer->expires_at(timer->expires_at() + *m_seconds);
|
||||
|
||||
if (err) {
|
||||
l::error("FileWatcher encountered error: {}", err.message());
|
||||
beammp_errorf("FileWatcher encountered error: {}", err.message());
|
||||
// TODO: Should any further action be taken?
|
||||
} else {
|
||||
try {
|
||||
check_files();
|
||||
} catch (const std::exception& e) {
|
||||
l::error("FileWatcher exception while checking files: {}", e.what());
|
||||
beammp_errorf("FileWatcher exception while checking files: {}", e.what());
|
||||
}
|
||||
try {
|
||||
check_directories();
|
||||
} catch (const std::exception& e) {
|
||||
l::error("FileWatcher exception while checking directories: {}", e.what());
|
||||
beammp_errorf("FileWatcher exception while checking directories: {}", e.what());
|
||||
}
|
||||
}
|
||||
// finally start the timer again, deadline has already been set at the beginning
|
||||
|
104
src/LuaAPI.cpp
104
src/LuaAPI.cpp
@ -19,9 +19,9 @@
|
||||
#include "LuaAPI.h"
|
||||
#include "Common.h"
|
||||
#include "CustomAssert.h"
|
||||
#include "TLuaEngine.h"
|
||||
#include "Value.h"
|
||||
|
||||
#include <boost/json/serialize.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sol/types.hpp>
|
||||
|
||||
@ -60,12 +60,12 @@ static inline std::pair<bool, std::string> InternalTriggerClientEvent(int Player
|
||||
} else {
|
||||
auto MaybeClient = GetClient(LuaAPI::MP::Engine->Server(), PlayerID);
|
||||
if (!MaybeClient) {
|
||||
beammp_lua_errorf("TriggerClientEvent invalid Player ID '{}'", PlayerID);
|
||||
beammp_errorff("TriggerClientEvent invalid Player ID '{}'", PlayerID);
|
||||
return { false, "Invalid Player ID" };
|
||||
}
|
||||
auto c = MaybeClient.value();
|
||||
if (!LuaAPI::MP::Engine->Network().Respond(*c, StringToVector(Packet), true)) {
|
||||
beammp_lua_errorf("Respond failed, dropping client {}", PlayerID);
|
||||
beammp_errorff("Respond failed, dropping client {}", PlayerID);
|
||||
LuaAPI::MP::Engine->Network().Disconnect(*c);
|
||||
return { false, "Respond failed, dropping client" };
|
||||
}
|
||||
@ -83,7 +83,7 @@ std::pair<bool, std::string> LuaAPI::MP::DropPlayer(int ID, std::optional<std::s
|
||||
/*
|
||||
auto MaybeClient = GetClient(Engine->Server(), ID);
|
||||
if (!MaybeClient) {
|
||||
beammp_lua_errorf("Tried to drop client with id {}, who doesn't exist", ID);
|
||||
beammp_errorff("Tried to drop client with id {}, who doesn't exist", ID);
|
||||
return { false, "Player does not exist" };
|
||||
}
|
||||
auto c = MaybeClient.value();
|
||||
@ -118,7 +118,7 @@ std::pair<bool, std::string> LuaAPI::MP::SendChatMessage(int ID, const std::stri
|
||||
}
|
||||
Result.first = true;
|
||||
} else {
|
||||
beammp_lua_error("SendChatMessage invalid argument [1] invalid ID");
|
||||
beammp_errorf("SendChatMessage invalid argument [1] invalid ID");
|
||||
Result.first = false;
|
||||
Result.second = "Invalid Player ID";
|
||||
}
|
||||
@ -134,7 +134,7 @@ std::pair<bool, std::string> LuaAPI::MP::RemoveVehicle(int PID, int VID) {
|
||||
std::pair<bool, std::string> Result;
|
||||
auto MaybeClient = GetClient(Engine->Server(), PID);
|
||||
if (!MaybeClient) {
|
||||
beammp_lua_error("RemoveVehicle invalid Player ID");
|
||||
beammp_errorf("RemoveVehicle invalid Player ID");
|
||||
Result.first = false;
|
||||
Result.second = "Invalid Player ID";
|
||||
return Result;
|
||||
@ -160,7 +160,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.DebugModeEnabled = NewValue.as<bool>();
|
||||
beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false"));
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected boolean");
|
||||
beammp_errorf("set invalid argument [2] expected boolean");
|
||||
}
|
||||
break;
|
||||
case 1: // private
|
||||
@ -168,7 +168,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.Private = NewValue.as<bool>();
|
||||
beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false"));
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected boolean");
|
||||
beammp_errorf("set invalid argument [2] expected boolean");
|
||||
}
|
||||
break;
|
||||
case 2: // max cars
|
||||
@ -176,7 +176,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.MaxCars = NewValue.as<int>();
|
||||
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars));
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected integer");
|
||||
beammp_errorf("set invalid argument [2] expected integer");
|
||||
}
|
||||
break;
|
||||
case 3: // max players
|
||||
@ -184,7 +184,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.MaxPlayers = NewValue.as<int>();
|
||||
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers));
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected integer");
|
||||
beammp_errorf("set invalid argument [2] expected integer");
|
||||
}
|
||||
break;
|
||||
case 4: // Map
|
||||
@ -192,7 +192,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.MapName = NewValue.as<std::string>();
|
||||
beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName);
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected string");
|
||||
beammp_errorf("set invalid argument [2] expected string");
|
||||
}
|
||||
break;
|
||||
case 5: // Name
|
||||
@ -200,7 +200,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.ServerName = NewValue.as<std::string>();
|
||||
beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName);
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected string");
|
||||
beammp_errorf("set invalid argument [2] expected string");
|
||||
}
|
||||
break;
|
||||
case 6: // Desc
|
||||
@ -208,7 +208,7 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
Application::Settings.ServerDesc = NewValue.as<std::string>();
|
||||
beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc);
|
||||
} else {
|
||||
beammp_lua_error("set invalid argument [2] expected string");
|
||||
beammp_errorf("set invalid argument [2] expected string");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -217,10 +217,6 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
||||
}
|
||||
}
|
||||
|
||||
void LuaAPI::MP::Sleep(size_t Ms) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(Ms));
|
||||
}
|
||||
|
||||
bool LuaAPI::MP::IsPlayerConnected(int ID) {
|
||||
throw std::runtime_error(fmt::format("NOT IMPLEMENTED: {}", __func__));
|
||||
/*
|
||||
@ -244,11 +240,6 @@ bool LuaAPI::MP::IsPlayerGuest(int ID) {
|
||||
*/
|
||||
}
|
||||
|
||||
int LuaAPI::PanicHandler(lua_State* State) {
|
||||
beammp_lua_error("PANIC: " + sol::stack::get<std::string>(State, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename FnT, typename... ArgsT>
|
||||
static std::pair<bool, std::string> FSWrapper(FnT Fn, ArgsT&&... Args) {
|
||||
std::error_code errc;
|
||||
@ -452,7 +443,7 @@ std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) {
|
||||
for (size_t i = 0; i < Args.size(); ++i) {
|
||||
auto Obj = Args[i];
|
||||
if (!Obj.is<std::string>()) {
|
||||
beammp_lua_error("FS.Concat called with non-string argument");
|
||||
beammp_errorf("FS.Concat called with non-string argument");
|
||||
return "";
|
||||
}
|
||||
Path += Obj.as<std::string>();
|
||||
@ -466,7 +457,7 @@ std::string LuaAPI::FS::ConcatPaths(sol::variadic_args Args) {
|
||||
|
||||
static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, const sol::object& right, bool is_array, size_t depth = 0) {
|
||||
if (depth > 100) {
|
||||
beammp_lua_error("json serialize will not go deeper than 100 nested tables, internal references assumed, aborted this path");
|
||||
beammp_errorf("json serialize will not go deeper than 100 nested tables, internal references assumed, aborted this path");
|
||||
return;
|
||||
}
|
||||
std::string key {};
|
||||
@ -480,7 +471,7 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c
|
||||
case sol::type::thread:
|
||||
case sol::type::function:
|
||||
case sol::type::table:
|
||||
beammp_lua_error("JsonEncode: left side of table field is unexpected type");
|
||||
beammp_errorf("JsonEncode: left side of table field is unexpected type");
|
||||
return;
|
||||
case sol::type::string:
|
||||
key = left.as<std::string>();
|
||||
@ -542,18 +533,18 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c
|
||||
}
|
||||
}
|
||||
|
||||
static std::string lua_to_json_impl(const sol::object& args) {
|
||||
static std::string lua_to_json_impl(const sol::object& obj) {
|
||||
// used as the invalid value provider in sol_obj_to_value.
|
||||
auto special_stringifier = [](const sol::object& object) -> Result<Value> {
|
||||
beammp_lua_debugf("Cannot convert from type {} to json, ignoring (using null)", sol::to_string(object.get_type()));
|
||||
return { Null };
|
||||
beammp_debugf("Cannot convert from type {} to json, ignoring (using null)", int(object.get_type()));
|
||||
return { Null {} };
|
||||
};
|
||||
auto maybe_val = sol_obj_to_value(obj, special_stringifier);
|
||||
if (maybe_val) {
|
||||
auto result = boost::apply_visitor(ValueToJsonVisitor(ValueToStringVisitor::Flag::NONE), maybe_val.move());
|
||||
return result.dump();
|
||||
auto result = boost::apply_visitor(ValueToJsonVisitor {}, maybe_val.move());
|
||||
return boost::json::serialize(result);
|
||||
} else {
|
||||
beammp_lua_errorf("Failed to convert an argument to json: {}", maybe_val.error);
|
||||
beammp_errorf("Failed to convert an argument to json: {}", maybe_val.error);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -564,11 +555,11 @@ std::string LuaAPI::Util::JsonEncode(const sol::object& object) {
|
||||
|
||||
std::string LuaAPI::Util::JsonDiff(const std::string& a, const std::string& b) {
|
||||
if (!nlohmann::json::accept(a)) {
|
||||
beammp_lua_error("JsonDiff first argument is not valid json: `" + a + "`");
|
||||
beammp_error("JsonDiff first argument is not valid json: `" + a + "`");
|
||||
return "";
|
||||
}
|
||||
if (!nlohmann::json::accept(b)) {
|
||||
beammp_lua_error("JsonDiff second argument is not valid json: `" + b + "`");
|
||||
beammp_error("JsonDiff second argument is not valid json: `" + b + "`");
|
||||
return "";
|
||||
}
|
||||
auto a_json = nlohmann::json::parse(a);
|
||||
@ -578,11 +569,11 @@ std::string LuaAPI::Util::JsonDiff(const std::string& a, const std::string& b) {
|
||||
|
||||
std::string LuaAPI::Util::JsonDiffApply(const std::string& data, const std::string& patch) {
|
||||
if (!nlohmann::json::accept(data)) {
|
||||
beammp_lua_error("JsonDiffApply first argument is not valid json: `" + data + "`");
|
||||
beammp_error("JsonDiffApply first argument is not valid json: `" + data + "`");
|
||||
return "";
|
||||
}
|
||||
if (!nlohmann::json::accept(patch)) {
|
||||
beammp_lua_error("JsonDiffApply second argument is not valid json: `" + patch + "`");
|
||||
beammp_error("JsonDiffApply second argument is not valid json: `" + patch + "`");
|
||||
return "";
|
||||
}
|
||||
auto a_json = nlohmann::json::parse(data);
|
||||
@ -593,7 +584,7 @@ std::string LuaAPI::Util::JsonDiffApply(const std::string& data, const std::stri
|
||||
|
||||
std::string LuaAPI::Util::JsonPrettify(const std::string& json) {
|
||||
if (!nlohmann::json::accept(json)) {
|
||||
beammp_lua_error("JsonPrettify argument is not valid json: `" + json + "`");
|
||||
beammp_error("JsonPrettify argument is not valid json: `" + json + "`");
|
||||
return "";
|
||||
}
|
||||
return nlohmann::json::parse(json).dump(4);
|
||||
@ -601,7 +592,7 @@ std::string LuaAPI::Util::JsonPrettify(const std::string& json) {
|
||||
|
||||
std::string LuaAPI::Util::JsonMinify(const std::string& json) {
|
||||
if (!nlohmann::json::accept(json)) {
|
||||
beammp_lua_error("JsonMinify argument is not valid json: `" + json + "`");
|
||||
beammp_error("JsonMinify argument is not valid json: `" + json + "`");
|
||||
return "";
|
||||
}
|
||||
return nlohmann::json::parse(json).dump(-1);
|
||||
@ -609,7 +600,7 @@ std::string LuaAPI::Util::JsonMinify(const std::string& json) {
|
||||
|
||||
std::string LuaAPI::Util::JsonFlatten(const std::string& json) {
|
||||
if (!nlohmann::json::accept(json)) {
|
||||
beammp_lua_error("JsonFlatten argument is not valid json: `" + json + "`");
|
||||
beammp_error("JsonFlatten argument is not valid json: `" + json + "`");
|
||||
return "";
|
||||
}
|
||||
return nlohmann::json::parse(json).flatten().dump(-1);
|
||||
@ -617,16 +608,26 @@ std::string LuaAPI::Util::JsonFlatten(const std::string& json) {
|
||||
|
||||
std::string LuaAPI::Util::JsonUnflatten(const std::string& json) {
|
||||
if (!nlohmann::json::accept(json)) {
|
||||
beammp_lua_error("JsonUnflatten argument is not valid json: `" + json + "`");
|
||||
beammp_error("JsonUnflatten argument is not valid json: `" + json + "`");
|
||||
return "";
|
||||
}
|
||||
return nlohmann::json::parse(json).unflatten().dump(-1);
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> LuaAPI::MP::TriggerClientEventJson(int PlayerID, const std::string& EventName, const sol::table& Data) {
|
||||
return InternalTriggerClientEvent(PlayerID, EventName, JsonEncode(Data));
|
||||
return InternalTriggerClientEvent(PlayerID, EventName, Util::JsonEncode(Data));
|
||||
}
|
||||
|
||||
size_t LuaAPI::MP::GetPlayerCount() { return 0; }
|
||||
|
||||
template <typename T>
|
||||
static void AddToTable(sol::table& table, const std::string& left, const T& value) {
|
||||
if (left.empty()) {
|
||||
table[table.size() + 1] = value;
|
||||
} else {
|
||||
table[left] = value;
|
||||
}
|
||||
}
|
||||
size_t LuaAPI::MP::GetPlayerCount() { return Engine->Server().ClientCount(); }
|
||||
|
||||
static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, const std::string& left, const nlohmann::json& right) {
|
||||
switch (right.type()) {
|
||||
@ -666,7 +667,7 @@ static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, c
|
||||
AddToTable(table, left, right.get<double>());
|
||||
break;
|
||||
case nlohmann::detail::value_t::binary:
|
||||
beammp_lua_error("JsonDecode can't handle binary blob in json, ignoring");
|
||||
beammp_errorf("JsonDecode can't handle binary blob in json, ignoring");
|
||||
return;
|
||||
case nlohmann::detail::value_t::discarded:
|
||||
return;
|
||||
@ -675,10 +676,11 @@ static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, c
|
||||
}
|
||||
}
|
||||
|
||||
sol::table LuaAPI::Util::JsonDecode(sol::this_state s, const std::string& string) {
|
||||
sol::state_view StateView(s);
|
||||
auto table = StateView.create_tab if (!nlohmann::json::accept(str)) {
|
||||
beammp_lua_error("string given to JsonDecode is not valid json: `" + str + "`");
|
||||
sol::table LuaAPI::Util::JsonDecode(sol::this_state s, const std::string& str) {
|
||||
sol::state_view StateView(s.lua_state());
|
||||
auto table = StateView.create_table(StateView);
|
||||
if (!nlohmann::json::accept(str)) {
|
||||
beammp_error("string given to JsonDecode is not valid json: `" + str + "`");
|
||||
return sol::lua_nil;
|
||||
}
|
||||
nlohmann::json json = nlohmann::json::parse(str);
|
||||
@ -691,17 +693,17 @@ sol::table LuaAPI::Util::JsonDecode(sol::this_state s, const std::string& string
|
||||
JsonDecodeRecursive(StateView, table, "", entry);
|
||||
}
|
||||
} else {
|
||||
beammp_lua_error("JsonDecode expected array or object json, instead got " + std::string(json.type_name()));
|
||||
beammp_error("JsonDecode expected array or object json, instead got " + std::string(json.type_name()));
|
||||
return sol::lua_nil;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
sol::table LuaAPI::FS::ListDirectories(sol::this_state s, const std::string& path) {
|
||||
sol::table LuaAPI::FS::ListDirectories(sol::this_state s, const std::string& Path) {
|
||||
if (!std::filesystem::exists(Path)) {
|
||||
return sol::lua_nil;
|
||||
}
|
||||
auto table = s.create_table();
|
||||
auto table = sol::state_view(s.lua_state()).create_table();
|
||||
for (const auto& entry : std::filesystem::directory_iterator(Path)) {
|
||||
if (entry.is_directory()) {
|
||||
table[table.size() + 1] = entry.path().lexically_relative(Path).string();
|
||||
@ -710,11 +712,11 @@ sol::table LuaAPI::FS::ListDirectories(sol::this_state s, const std::string& pat
|
||||
return table;
|
||||
}
|
||||
|
||||
sol::table LuaAPI::FS::ListFiles(sol::this_state s, const std::string& path) {
|
||||
sol::table LuaAPI::FS::ListFiles(sol::this_state s, const std::string& Path) {
|
||||
if (!std::filesystem::exists(Path)) {
|
||||
return sol::lua_nil;
|
||||
}
|
||||
auto table = s.create_table();
|
||||
auto table = sol::state_view(s.lua_state()).create_table();
|
||||
for (const auto& entry : std::filesystem::directory_iterator(Path)) {
|
||||
if (entry.is_regular_file() || entry.is_symlink()) {
|
||||
table[table.size() + 1] = entry.path().lexically_relative(Path).string();
|
||||
|
@ -11,10 +11,6 @@
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/ostream.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <fmt/std.h>
|
||||
#include <functional>
|
||||
#include <lauxlib.h>
|
||||
#include <lua.h>
|
||||
@ -157,8 +153,8 @@ Error LuaPlugin::initialize_libraries() {
|
||||
};
|
||||
|
||||
glob["MP"]["GetOSName"] = &LuaAPI::MP::GetOSName;
|
||||
glob["MP"]["GetTimeMS"] = &LuaAPI::MP::GetTimeMS;
|
||||
glob["MP"]["GetTimeS"] = &LuaAPI::MP::GetTimeS;
|
||||
//glob["MP"]["GetTimeMS"] = &LuaAPI::MP::GetTimeMS;
|
||||
//glob["MP"]["GetTimeS"] = &LuaAPI::MP::GetTimeS;
|
||||
|
||||
glob.create_named("Util");
|
||||
glob["Util"]["JsonEncode"] = &LuaAPI::Util::JsonEncode;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "Packet.h"
|
||||
#include "ProtocolVersion.h"
|
||||
#include "ServerInfo.h"
|
||||
#include "TLuaEngine.h"
|
||||
#include "Transport.h"
|
||||
#include "Util.h"
|
||||
#include <boost/asio/buffer.hpp>
|
||||
@ -920,7 +919,7 @@ void Network::handle_authentication(ClientID id, const bmp::Packet& packet, std:
|
||||
disconnect(id, err);
|
||||
return;
|
||||
}
|
||||
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerAuth", "", client->name.get(), client->role.get(), client->is_guest.get(), client->identifiers.get());
|
||||
/* auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerAuth", "", client->name.get(), client->role.get(), client->is_guest.get(), client->identifiers.get());
|
||||
TLuaEngine::WaitForAll(Futures);
|
||||
bool NotAllowed = std::any_of(Futures.begin(), Futures.end(),
|
||||
[](const std::shared_ptr<TLuaResult>& Result) {
|
||||
@ -935,6 +934,10 @@ void Network::handle_authentication(ClientID id, const bmp::Packet& packet, std:
|
||||
}
|
||||
return false;
|
||||
});
|
||||
*/
|
||||
std::string Reason {};
|
||||
bool NotAllowed = false;
|
||||
bool NotAllowedWithReason = false;
|
||||
|
||||
if (NotAllowed) {
|
||||
bmp::Packet auth_fail_packet {
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#include "CustomAssert.h"
|
||||
#include "LuaAPI.h"
|
||||
#include "TLuaEngine.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
@ -154,6 +153,7 @@ void TConsole::StartLoggingToFile() {
|
||||
|
||||
void TConsole::ChangeToLuaConsole(const std::string& LuaStateId) {
|
||||
if (!mIsLuaConsole) {
|
||||
/*
|
||||
if (!mLuaEngine) {
|
||||
beammp_error("Lua engine not initialized yet, please wait and try again");
|
||||
return;
|
||||
@ -170,6 +170,7 @@ void TConsole::ChangeToLuaConsole(const std::string& LuaStateId) {
|
||||
}
|
||||
mCachedRegularHistory = mCommandline->history();
|
||||
mCommandline->set_history(mCachedLuaHistory);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,11 +223,13 @@ void TConsole::Command_Lua(const std::string&, const std::vector<std::string>& a
|
||||
if (args.size() == 1) {
|
||||
auto NewStateId = args.at(0);
|
||||
beammp_assert(!NewStateId.empty());
|
||||
/*
|
||||
if (mLuaEngine->HasState(NewStateId)) {
|
||||
ChangeToLuaConsole(NewStateId);
|
||||
} else {
|
||||
Application::Console().WriteRaw("Lua state '" + NewStateId + "' is not a known state. Didn't switch to Lua.");
|
||||
}
|
||||
*/
|
||||
} else if (args.size() == 0) {
|
||||
ChangeToLuaConsole(mDefaultStateId);
|
||||
}
|
||||
@ -446,6 +449,7 @@ void TConsole::Command_Status(const std::string&, const std::vector<std::string>
|
||||
|
||||
auto ElapsedTime = mUptimeTimer.GetElapsedTime();
|
||||
|
||||
/*
|
||||
auto network = mLuaEngine->Network();
|
||||
auto clients = network->all_clients();
|
||||
|
||||
@ -473,12 +477,13 @@ void TConsole::Command_Status(const std::string&, const std::vector<std::string>
|
||||
<< "\t\tBad: [ " << SystemsBadList << " ]\n"
|
||||
<< "\t\tShutting down: [ " << SystemsShuttingDownList << " ]\n"
|
||||
<< "\t\tShut down: [ " << SystemsShutdownList << " ]\n"
|
||||
<< "";
|
||||
<< "";*/
|
||||
|
||||
Application::Console().WriteRaw(Status.str());
|
||||
}
|
||||
|
||||
void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
|
||||
/*
|
||||
auto FutureIsNonNil =
|
||||
[](const std::shared_ptr<TLuaResult>& Future) {
|
||||
if (!Future->Error && Future->Result.valid()) {
|
||||
@ -522,9 +527,11 @@ void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
|
||||
}
|
||||
Application::Console().WriteRaw(Reply.str());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void TConsole::HandleLuaInternalCommand(const std::string& cmd) {
|
||||
/*
|
||||
if (cmd == "exit") {
|
||||
ChangeToRegularConsole();
|
||||
} else if (cmd == "queued") {
|
||||
@ -574,6 +581,7 @@ Commands
|
||||
} else {
|
||||
beammp_error("internal command '" + cmd + "' is not known");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
TConsole::TConsole() {
|
||||
@ -592,6 +600,7 @@ void TConsole::InitializeCommandline() {
|
||||
auto [cmd, args] = ParseCommand(TrimmedCmd);
|
||||
mCommandline->write(mCommandline->prompt() + TrimmedCmd);
|
||||
if (mIsLuaConsole) {
|
||||
/*
|
||||
if (!mLuaEngine) {
|
||||
beammp_info("Lua not started yet, please try again in a second");
|
||||
} else if (!cmd.empty() && cmd.at(0) == ':') {
|
||||
@ -603,7 +612,9 @@ void TConsole::InitializeCommandline() {
|
||||
beammp_lua_error("error in " + mStateId + ": " + Future->ErrorMessage);
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
if (!mLuaEngine) {
|
||||
beammp_error("Attempted to run a command before Lua engine started. Please wait and try again.");
|
||||
} else if (cmd == "exit") {
|
||||
@ -619,7 +630,7 @@ void TConsole::InitializeCommandline() {
|
||||
} else {
|
||||
RunAsCommand(TrimmedCmd);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate.");
|
||||
@ -629,6 +640,7 @@ void TConsole::InitializeCommandline() {
|
||||
std::vector<std::string> suggestions;
|
||||
try {
|
||||
if (mIsLuaConsole) { // if lua
|
||||
/*
|
||||
if (!mLuaEngine) {
|
||||
beammp_info("Lua not started yet, please try again in a second");
|
||||
} else {
|
||||
@ -650,7 +662,6 @@ void TConsole::InitializeCommandline() {
|
||||
if (stub.rfind('.') != stub.size() - 1 && !tablekeys.empty()) {
|
||||
tablekeys.pop_back();
|
||||
}
|
||||
|
||||
auto keys = mLuaEngine->GetStateTableKeysForState(mStateId, tablekeys);
|
||||
|
||||
for (const auto& key : keys) { // go through each bottom-level key
|
||||
@ -666,17 +677,18 @@ void TConsole::InitializeCommandline() {
|
||||
suggestions.push_back(prefix + before_last_atom + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} else { // if not lua
|
||||
if (stub.find("lua") == 0) { // starts with "lua" means we should suggest state names
|
||||
std::string after_prefix = TrimString(stub.substr(3));
|
||||
auto stateNames = mLuaEngine->GetLuaStateNames();
|
||||
/*auto stateNames = mLuaEngine->GetLuaStateNames();
|
||||
|
||||
for (const auto& name : stateNames) {
|
||||
if (name.find(after_prefix) == 0) {
|
||||
suggestions.push_back("lua " + name);
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
for (const auto& [cmd_name, cmd_fn] : mCommandMap) {
|
||||
if (cmd_name.find(stub) == 0) {
|
||||
@ -712,6 +724,8 @@ void TConsole::WriteRaw(const std::string& str) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void TConsole::InitializeLuaConsole(TLuaEngine& Engine) {
|
||||
mLuaEngine = &Engine;
|
||||
}
|
||||
*/
|
||||
|
@ -415,7 +415,7 @@ boost::json::value ValueToJsonVisitor::operator()(const HashMap<std::string, Val
|
||||
auto jo = boost::json::object();
|
||||
for (const auto& [key, val] : map) {
|
||||
auto json_val = boost::apply_visitor(ValueToJsonVisitor(), val);
|
||||
jo.emplace(key, json_val);
|
||||
jo.emplace(std::string(key), json_val);
|
||||
}
|
||||
return jo;
|
||||
}
|
||||
|
16
src/main.cpp
16
src/main.cpp
@ -20,12 +20,12 @@
|
||||
#include "Common.h"
|
||||
#include "Http.h"
|
||||
#include "LuaAPI.h"
|
||||
#include "LuaPlugin.h"
|
||||
#include "Plugin.h"
|
||||
#include "PluginManager.h"
|
||||
#include "SignalHandling.h"
|
||||
#include "TConfig.h"
|
||||
#include "THeartbeatThread.h"
|
||||
#include "TLuaEngine.h"
|
||||
#include "TPluginMonitor.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
@ -148,23 +148,27 @@ int BeamMPServerMain(MainArguments Arguments) {
|
||||
Application::SetSubsystemStatus("Main", Application::Status::ShuttingDown);
|
||||
Shutdown = true;
|
||||
});
|
||||
/*
|
||||
Application::RegisterShutdownHandler([] {
|
||||
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onShutdown", "");
|
||||
TLuaEngine::WaitForAll(Futures, std::chrono::seconds(5));
|
||||
});
|
||||
|
||||
auto LuaEngine = std::make_shared<TLuaEngine>();
|
||||
Application::Console().InitializeLuaConsole(*LuaEngine);
|
||||
|
||||
*/
|
||||
|
||||
RegisterThread("Main");
|
||||
|
||||
beammp_trace("Running in debug mode on a debug build");
|
||||
std::shared_ptr<Network> network = std::make_shared<Network>();
|
||||
THeartbeatThread Heartbeat(network);
|
||||
LuaEngine->SetNetwork(network);
|
||||
// LuaEngine->SetNetwork(network);
|
||||
Application::CheckForUpdates();
|
||||
|
||||
TPluginMonitor PluginMonitor(fs::path(Application::Settings.Resource) / "Server", LuaEngine);
|
||||
// TPluginMonitor PluginMonitor(fs::path(Application::Settings.Resource) / "Server", LuaEngine);
|
||||
PluginManager PluginManager;
|
||||
(void)PluginManager.add_plugin(Plugin::make_pointer<LuaPlugin>("Resources/Server/Test"));
|
||||
|
||||
if (Application::Settings.HTTPServerEnabled) {
|
||||
Http::Server::THttpServerInstance HttpServerInstance {};
|
||||
|
@ -7,6 +7,7 @@
|
||||
"boost-uuid",
|
||||
"boost-variant",
|
||||
"boost-iostreams",
|
||||
"boost-json",
|
||||
"cpp-httplib",
|
||||
"doctest",
|
||||
"fmt",
|
||||
|
Loading…
x
Reference in New Issue
Block a user