mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-13 02:03:44 +00:00
Compare commits
20 Commits
v3.8.5
...
update-lua
| Author | SHA1 | Date | |
|---|---|---|---|
| 43e86a1e22 | |||
| 70fc8436ed | |||
| 6f196aca64 | |||
| 99476a2c77 | |||
| 9fa9974159 | |||
| 3ef816845d | |||
| 6ec4106ec7 | |||
| b094e35f8c | |||
| 83afafc0c3 | |||
| 31122abe10 | |||
| 0615b57a37 | |||
| 4a8378427a | |||
| b74f0c7ca8 | |||
| 420c64f6cf | |||
| add45c085b | |||
| 372076a4ef | |||
| eb2deb73c1 | |||
| 21874afb87 | |||
| 184d50bf8c | |||
| c4c894c1f7 |
@@ -19,8 +19,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- distro: debian
|
||||
version: 11
|
||||
- distro: debian
|
||||
version: 12
|
||||
- distro: ubuntu
|
||||
@@ -48,6 +46,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Git config safe directory
|
||||
shell: bash
|
||||
@@ -90,8 +89,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- distro: debian
|
||||
version: 11
|
||||
- distro: debian
|
||||
version: 12
|
||||
- distro: ubuntu
|
||||
@@ -119,6 +116,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Git config safe directory
|
||||
shell: bash
|
||||
|
||||
@@ -38,8 +38,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- distro: debian
|
||||
version: 11
|
||||
- distro: debian
|
||||
version: 12
|
||||
- distro: ubuntu
|
||||
@@ -67,6 +65,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Git config safe directory
|
||||
shell: bash
|
||||
@@ -109,8 +108,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- distro: debian
|
||||
version: 11
|
||||
- distro: debian
|
||||
version: 12
|
||||
- distro: ubuntu
|
||||
@@ -141,6 +138,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Git config safe directory
|
||||
shell: bash
|
||||
@@ -194,6 +192,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Create Build Environment
|
||||
shell: bash
|
||||
|
||||
@@ -26,6 +26,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: 'recursive'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup vcpkg
|
||||
uses: lukka/run-vcpkg@v11
|
||||
|
||||
+8
-4
@@ -80,14 +80,15 @@ set(PRJ_SOURCES
|
||||
src/ChronoWrapper.cpp
|
||||
)
|
||||
|
||||
find_package(Lua REQUIRED)
|
||||
# fix for sol2
|
||||
find_path(LUAJIT_INCLUDE_DIR lua.hpp PATH_SUFFIXES luajit)
|
||||
|
||||
# set the source file containing main()
|
||||
set(PRJ_MAIN src/main.cpp)
|
||||
# set the source file containing the test's main
|
||||
set(PRJ_TEST_MAIN test/test_main.cpp)
|
||||
# set include paths not part of libraries
|
||||
set(PRJ_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
|
||||
set(PRJ_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIR})
|
||||
# set compile features (e.g. standard version)
|
||||
set(PRJ_COMPILE_FEATURES cxx_std_20)
|
||||
# set #defines (test enable/disable not included here)
|
||||
@@ -105,9 +106,11 @@ set(PRJ_LIBRARIES
|
||||
libzip::zip
|
||||
OpenSSL::SSL OpenSSL::Crypto
|
||||
CURL::libcurl
|
||||
${LUA_LIBRARIES}
|
||||
lua51
|
||||
)
|
||||
|
||||
link_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib)
|
||||
|
||||
# add dependency find_package calls and similar here
|
||||
find_package(fmt CONFIG REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
@@ -148,7 +151,8 @@ if(UNIX)
|
||||
endif(UNIX)
|
||||
|
||||
if (WIN32)
|
||||
add_compile_options("-D_WIN32_WINNT=0x0601")
|
||||
add_compile_definitions(_WIN32_WINNT=0x0A00)
|
||||
|
||||
add_compile_options("/bigobj")
|
||||
endif(WIN32)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "BoostAliases.h"
|
||||
#include "Common.h"
|
||||
@@ -101,6 +102,8 @@ public:
|
||||
[[nodiscard]] TServer& Server() const;
|
||||
void UpdatePingTime();
|
||||
int SecondsSinceLastPing();
|
||||
void SetMagic(std::vector<uint8_t> magic) { mMagic = std::move(magic); }
|
||||
[[nodiscard]] const std::vector<uint8_t>& GetMagic() const { return mMagic; }
|
||||
|
||||
private:
|
||||
void InsertVehicle(int ID, const std::string& Data);
|
||||
@@ -125,6 +128,7 @@ private:
|
||||
std::string mDID;
|
||||
int mID = -1;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> mLastPingTime = std::chrono::high_resolution_clock::now();
|
||||
std::vector<uint8_t> mMagic;
|
||||
};
|
||||
|
||||
std::optional<std::weak_ptr<TClient>> GetClient(class TServer& Server, int ID);
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ public:
|
||||
static TConsole& Console() { return mConsole; }
|
||||
static std::string ServerVersionString();
|
||||
static const Version& ServerVersion() { return mVersion; }
|
||||
static Version ClientMinimumVersion() { return Version { 2, 2, 0 }; }
|
||||
static Version ClientMinimumVersion() { return Version { 2, 7, 0 }; }
|
||||
static std::string PPS() { return mPPS; }
|
||||
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
||||
|
||||
@@ -129,7 +129,7 @@ private:
|
||||
static inline std::mutex mShutdownHandlersMutex {};
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
|
||||
static inline Version mVersion { 3, 8, 5 };
|
||||
static inline Version mVersion { 3, 9, 0 };
|
||||
};
|
||||
|
||||
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
|
||||
|
||||
@@ -192,9 +192,7 @@ public:
|
||||
for (const auto& Event : mLuaEvents.at(EventName)) {
|
||||
for (const auto& Function : Event.second) {
|
||||
if (Event.first != IgnoreId) {
|
||||
auto Result = EnqueueFunctionCall(Event.first, Function, Arguments, EventName);
|
||||
Results.push_back(Result);
|
||||
AddResultToCheck(Result);
|
||||
Results.push_back(EnqueueFunctionCall(Event.first, Function, Arguments, EventName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public:
|
||||
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||
size_t ClientCount() const;
|
||||
|
||||
void GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network);
|
||||
void GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network, bool udp);
|
||||
static void HandleEvent(TClient& c, const std::string& Data);
|
||||
RWMutex& GetClientMutex() const { return mClientsMutex; }
|
||||
|
||||
|
||||
+5
-6
@@ -160,7 +160,7 @@ void TConsole::ChangeToRegularConsole() {
|
||||
}
|
||||
|
||||
bool TConsole::EnsureArgsCount(const std::vector<std::string>& args, size_t n) {
|
||||
if (n == 0 && args.size() != 0) {
|
||||
if (n == 0 && !args.empty()) {
|
||||
Application::Console().WriteRaw("This command expects no arguments.");
|
||||
return false;
|
||||
} else if (args.size() != n) {
|
||||
@@ -198,7 +198,7 @@ void TConsole::Command_Lua(const std::string&, const std::vector<std::string>& a
|
||||
} else {
|
||||
Application::Console().WriteRaw("Lua state '" + NewStateId + "' is not a known state. Didn't switch to Lua.");
|
||||
}
|
||||
} else if (args.size() == 0) {
|
||||
} else if (args.empty()) {
|
||||
ChangeToLuaConsole(mDefaultStateId);
|
||||
}
|
||||
}
|
||||
@@ -260,8 +260,7 @@ void TConsole::Command_Version(const std::string& cmd, const std::vector<std::st
|
||||
|
||||
Application::Console().WriteRaw("Platform: " + platform);
|
||||
Application::Console().WriteRaw("Server: v" + Application::ServerVersionString());
|
||||
std::string lua_version = fmt::format("Lua: v{}.{}.{}", LUA_VERSION_MAJOR, LUA_VERSION_MINOR, LUA_VERSION_RELEASE);
|
||||
Application::Console().WriteRaw(lua_version);
|
||||
Application::Console().WriteRaw(LUA_RELEASE);
|
||||
std::string openssl_version = fmt::format("OpenSSL: v{}.{}.{}", OPENSSL_VERSION_MAJOR, OPENSSL_VERSION_MINOR, OPENSSL_VERSION_PATCH);
|
||||
Application::Console().WriteRaw(openssl_version);
|
||||
}
|
||||
@@ -423,7 +422,7 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
|
||||
settings set <category> <setting> <value> sets specified setting to value
|
||||
)";
|
||||
|
||||
if (args.size() == 0) {
|
||||
if (args.empty()) {
|
||||
beammp_errorf("No arguments specified for command 'settings'!");
|
||||
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
||||
return;
|
||||
@@ -705,7 +704,7 @@ void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NonNilFutures.size() == 0) {
|
||||
if (NonNilFutures.empty()) {
|
||||
if (!IgnoreNotACommand) {
|
||||
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'. Type 'help' to see a list of valid commands.");
|
||||
}
|
||||
|
||||
+5
-28
@@ -30,16 +30,12 @@
|
||||
#include <condition_variable>
|
||||
#include <fmt/core.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <sol/stack_core.hpp>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
TLuaEngine* LuaAPI::MP::Engine;
|
||||
|
||||
static sol::protected_function AddTraceback(sol::state_view StateView, sol::protected_function RawFn);
|
||||
|
||||
TLuaEngine::TLuaEngine()
|
||||
: mResourceServerPath(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server") {
|
||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Starting);
|
||||
@@ -69,7 +65,7 @@ TEST_CASE("TLuaEngine ctor & dtor") {
|
||||
void TLuaEngine::operator()() {
|
||||
RegisterThread("LuaEngine");
|
||||
// lua engine main thread
|
||||
beammp_infof("Lua v{}.{}.{}", LUA_VERSION_MAJOR, LUA_VERSION_MINOR, LUA_VERSION_RELEASE);
|
||||
beammp_infof(LUA_RELEASE);
|
||||
CollectAndInitPlugins();
|
||||
|
||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
||||
@@ -131,7 +127,7 @@ void TLuaEngine::operator()() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mLuaStates.size() == 0) {
|
||||
if (mLuaStates.empty()) {
|
||||
beammp_trace("No Lua states, event loop running extremely sparsely");
|
||||
Application::SleepSafeSeconds(10);
|
||||
} else {
|
||||
@@ -496,7 +492,6 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
|
||||
sol::variadic_results LocalArgs = JsonStringToArray(Str);
|
||||
for (const auto& Handler : MyHandlers) {
|
||||
auto Fn = mStateView[Handler];
|
||||
Fn = AddTraceback(mStateView, Fn);
|
||||
if (Fn.valid()) {
|
||||
auto LuaResult = Fn(LocalArgs);
|
||||
auto Result = std::make_shared<TLuaResult>();
|
||||
@@ -505,9 +500,7 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerGlobalEvent(const std::string
|
||||
Result->Result = LuaResult;
|
||||
} else {
|
||||
Result->Error = true;
|
||||
sol::error Err = LuaResult;
|
||||
Result->ErrorMessage = Err.what();
|
||||
beammp_errorf("An error occured while executing local event handler \"{}\" for event \"{}\": {}", Handler, EventName, Result->ErrorMessage);
|
||||
Result->ErrorMessage = "Function result in TriggerGlobalEvent was invalid";
|
||||
}
|
||||
Result->MarkAsReady();
|
||||
Return.push_back(Result);
|
||||
@@ -1089,21 +1082,6 @@ void TLuaEngine::StateThreadData::RegisterEvent(const std::string& EventName, co
|
||||
mEngine->RegisterEvent(EventName, mStateId, FunctionName);
|
||||
}
|
||||
|
||||
static sol::protected_function AddTraceback(sol::state_view StateView, sol::protected_function RawFn) {
|
||||
StateView["INTERNAL_ERROR_HANDLER"] = [](lua_State *L) {
|
||||
auto Error = sol::stack::get<std::optional<std::string>>(L);
|
||||
std::string ErrorString = "<Unknown error>";
|
||||
if (Error.has_value()) {
|
||||
ErrorString = Error.value();
|
||||
}
|
||||
auto DebugTracebackFn = sol::state_view(L).globals().get<sol::table>("debug").get<sol::protected_function>("traceback");
|
||||
// 2 = start collecting the trace one above the current function (1=current function)
|
||||
std::string Traceback = DebugTracebackFn(ErrorString, 2);
|
||||
return sol::stack::push(L, Traceback);
|
||||
};
|
||||
return sol::protected_function(RawFn, StateView["INTERNAL_ERROR_HANDLER"]);
|
||||
}
|
||||
|
||||
void TLuaEngine::StateThreadData::operator()() {
|
||||
RegisterThread("Lua:" + mStateId);
|
||||
while (!Application::IsShuttingDown()) {
|
||||
@@ -1168,8 +1146,8 @@ void TLuaEngine::StateThreadData::operator()() {
|
||||
// TODO: Use TheQueuedFunction.EventName for errors, warnings, etc
|
||||
Result->StateId = mStateId;
|
||||
sol::state_view StateView(mState);
|
||||
auto RawFn = StateView[FnName];
|
||||
if (RawFn.valid() && RawFn.get_type() == sol::type::function) {
|
||||
auto Fn = StateView[FnName];
|
||||
if (Fn.valid() && Fn.get_type() == sol::type::function) {
|
||||
std::vector<sol::object> LuaArgs;
|
||||
for (const auto& Arg : Args) {
|
||||
if (Arg.valueless_by_exception()) {
|
||||
@@ -1204,7 +1182,6 @@ void TLuaEngine::StateThreadData::operator()() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto Fn = AddTraceback(StateView, RawFn);
|
||||
auto Res = Fn(sol::as_args(LuaArgs));
|
||||
if (Res.valid()) {
|
||||
Result->Error = false;
|
||||
|
||||
+35
-13
@@ -32,6 +32,8 @@
|
||||
#include <boost/asio/ip/address_v6.hpp>
|
||||
#include <boost/asio/ip/v6_only.hpp>
|
||||
#include <cstring>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <zlib.h>
|
||||
|
||||
typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO> rcv_timeout_option;
|
||||
@@ -146,23 +148,30 @@ void TNetwork::UDPServerMain() {
|
||||
}
|
||||
|
||||
if (Client->GetID() == ID) {
|
||||
// not initialized yet
|
||||
if (Client->GetUDPAddr() == ip::udp::endpoint {} || !Client->IsUDPConnected()) {
|
||||
// same IP (just a sanity check)
|
||||
if (remote_client_ep.address() == Client->GetTCPSock().remote_endpoint().address()) {
|
||||
Client->SetUDPAddr(remote_client_ep);
|
||||
Client->SetIsUDPConnected(true);
|
||||
beammp_debugf("UDP connected for client {}", ID);
|
||||
} else {
|
||||
beammp_debugf("Denied initial UDP packet due to IP mismatch");
|
||||
if (Client->GetUDPAddr() == ip::udp::endpoint {} && !Client->IsUDPConnected() && !Client->GetMagic().empty()) {
|
||||
if (Data.size() != 66) {
|
||||
beammp_debugf("Invalid size for UDP value. IP: {} ID: {}", remote_client_ep.address().to_string(), ID);
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector Magic(Data.begin() + 2, Data.end());
|
||||
|
||||
if (Magic != Client->GetMagic()) {
|
||||
beammp_debugf("Invalid value for UDP IP: {} ID: {}", remote_client_ep.address().to_string(), ID);
|
||||
return false;
|
||||
}
|
||||
|
||||
Client->SetMagic({});
|
||||
Client->SetUDPAddr(remote_client_ep);
|
||||
Client->SetIsUDPConnected(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Client->GetUDPAddr() == remote_client_ep) {
|
||||
Data.erase(Data.begin(), Data.begin() + 2);
|
||||
mServer.GlobalParser(ClientPtr, std::move(Data), mPPSMonitor, *this);
|
||||
mServer.GlobalParser(ClientPtr, std::move(Data), mPPSMonitor, *this, true);
|
||||
} else {
|
||||
beammp_debugf("Ignored UDP packet due to remote address mismatch");
|
||||
beammp_debugf("Ignored UDP packet for Client {} due to remote address mismatch. Source: {}, Client: {}", ID, remote_client_ep.address().to_string(), Client->GetUDPAddr().address().to_string());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -234,10 +243,11 @@ void TNetwork::TCPServerMain() {
|
||||
ip::tcp::socket ClientSocket = Acceptor.accept(ClientEp, ec);
|
||||
if (ec) {
|
||||
beammp_errorf("Failed to accept() new client: {}", ec.message());
|
||||
continue;
|
||||
}
|
||||
TConnection Conn { std::move(ClientSocket), ClientEp };
|
||||
std::thread ID(&TNetwork::Identify, this, std::move(Conn));
|
||||
ID.detach(); // TODO: Add to a queue and attempt to join periodically
|
||||
ID.detach();
|
||||
} catch (const std::exception& e) {
|
||||
beammp_errorf("Exception in accept routine: {}", e.what());
|
||||
}
|
||||
@@ -660,7 +670,7 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
||||
Client->Disconnect("TCPRcv failed");
|
||||
break;
|
||||
}
|
||||
mServer.GlobalParser(c, std::move(res), mPPSMonitor, *this);
|
||||
mServer.GlobalParser(c, std::move(res), mPPSMonitor, *this, false);
|
||||
}
|
||||
|
||||
if (QueueSync.joinable())
|
||||
@@ -751,6 +761,18 @@ void TNetwork::OnConnect(const std::weak_ptr<TClient>& c) {
|
||||
SyncResources(*LockedClient);
|
||||
if (LockedClient->IsDisconnected())
|
||||
return;
|
||||
std::vector<unsigned char> buf(64);
|
||||
int ret = RAND_bytes(buf.data(), buf.size());
|
||||
if (ret != 1) {
|
||||
unsigned long error = ERR_get_error();
|
||||
beammp_errorf("RAND_bytes failed with error code {}", error);
|
||||
beammp_assert(ret != 1);
|
||||
return;
|
||||
}
|
||||
|
||||
LockedClient->SetMagic(buf);
|
||||
buf.insert(buf.begin(), 'U');
|
||||
(void)Respond(*LockedClient, buf, true);
|
||||
(void)Respond(*LockedClient, StringToVector("M" + Application::Settings.getAsString(Settings::Key::General_Map)), true); // Send the Map on connect
|
||||
beammp_info(LockedClient->GetName() + " : Connected");
|
||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
|
||||
|
||||
+34
-3
@@ -161,7 +161,7 @@ size_t TServer::ClientCount() const {
|
||||
return mClients.size();
|
||||
}
|
||||
|
||||
void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network) {
|
||||
void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uint8_t>&& Packet, TPPSMonitor& PPSMonitor, TNetwork& Network, bool udp) {
|
||||
constexpr std::string_view ABG = "ABG:";
|
||||
if (Packet.size() >= ABG.size() && std::equal(Packet.begin(), Packet.begin() + ABG.size(), ABG.begin(), ABG.end())) {
|
||||
Packet.erase(Packet.begin(), Packet.begin() + ABG.size());
|
||||
@@ -198,7 +198,8 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
|
||||
auto MaybePidVid = GetPidVid(StringPacket.substr(3).substr(0, StringPacket.substr(3).find(':', 1)));
|
||||
auto pidVidPart = StringPacket.substr(3);
|
||||
auto MaybePidVid = GetPidVid(pidVidPart.substr(0, pidVidPart.find(':')));
|
||||
if (MaybePidVid) {
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
}
|
||||
@@ -213,6 +214,10 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
}
|
||||
switch (Code) {
|
||||
case 'H': // initial connection
|
||||
if (udp) {
|
||||
beammp_debugf("Received 'H' packet over UDP from client '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
if (!Network.SyncClient(Client)) {
|
||||
// TODO handle
|
||||
}
|
||||
@@ -226,12 +231,20 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
}
|
||||
return;
|
||||
case 'O':
|
||||
if (udp) {
|
||||
beammp_debugf("Received 'O' packet over UDP from client '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
if (Packet.size() > 1000) {
|
||||
beammp_debug(("Received data from: ") + LockedClient->GetName() + (" Size: ") + std::to_string(Packet.size()));
|
||||
}
|
||||
ParseVehicle(*LockedClient, StringPacket, Network);
|
||||
return;
|
||||
case 'C': {
|
||||
if (udp) {
|
||||
beammp_debugf("Received 'C' packet over UDP from client '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
if (Packet.size() < 4 || std::find(Packet.begin() + 3, Packet.end(), ':') == Packet.end())
|
||||
break;
|
||||
const auto PacketAsString = std::string(reinterpret_cast<const char*>(Packet.data()), Packet.size());
|
||||
@@ -244,6 +257,10 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
beammp_debugf("Empty chat message received from '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
if (Message.size() > 500) {
|
||||
beammp_debugf("Chat message too long from '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onChatMessage", "", LockedClient->GetID(), LockedClient->GetName(), Message);
|
||||
TLuaEngine::WaitForAll(Futures);
|
||||
LogChatMessage(LockedClient->GetName(), LockedClient->GetID(), PacketAsString.substr(PacketAsString.find(':', 3) + 1));
|
||||
@@ -262,6 +279,10 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
return;
|
||||
}
|
||||
case 'E':
|
||||
if (udp) {
|
||||
beammp_debugf("Received 'E' packet over UDP from client '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||
return;
|
||||
}
|
||||
HandleEvent(*LockedClient, StringPacket);
|
||||
return;
|
||||
case 'N':
|
||||
@@ -273,7 +294,8 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
|
||||
auto MaybePidVid = GetPidVid(StringPacket.substr(3).substr(0, StringPacket.substr(3).find(':', 1)));
|
||||
auto pidVidPart = StringPacket.substr(3);
|
||||
auto MaybePidVid = GetPidVid(pidVidPart.substr(0, pidVidPart.find(':')));
|
||||
if (MaybePidVid) {
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
}
|
||||
@@ -304,6 +326,15 @@ void TServer::HandleEvent(TClient& c, const std::string& RawData) {
|
||||
}
|
||||
std::string Name = RawData.substr(2, NameDataSep - 2);
|
||||
std::string Data = RawData.substr(NameDataSep + 1);
|
||||
|
||||
std::vector<std::string> exclude = {"onInit", "onFileChanged","onVehicleDeleted","onConsoleInput","onPlayerAuth","postPlayerAuth", "onPlayerDisconnect",
|
||||
"onPlayerConnecting","onPlayerJoining","onPlayerJoin","onChatMessage","postChatMessage","onVehicleSpawn","postVehicleSpawn","onVehicleEdited", "postVehicleEdited",
|
||||
"onVehicleReset","onVehiclePaintChanged","onShutdown"};
|
||||
|
||||
if (std::ranges::find(exclude, Name) != exclude.end()) {
|
||||
beammp_debugf("Excluded event triggered by client '{}' ({}): '{}', ignoring.", c.GetName(), c.GetID(), Name);
|
||||
return;
|
||||
}
|
||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent(Name, "", c.GetID(), Data));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
Submodule vcpkg updated: 6978381401...5bf0c55239
+10
-2
@@ -14,6 +14,14 @@
|
||||
"openssl",
|
||||
"rapidjson",
|
||||
"sol2",
|
||||
"curl"
|
||||
]
|
||||
"curl",
|
||||
"luajit"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"name": "sol2",
|
||||
"version": "3.3.1"
|
||||
}
|
||||
],
|
||||
"builtin-baseline": "5bf0c55239da398b8c6f450818c9e28d36bf9966"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user