mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-05 15:26:19 +00:00
add event 'onPlayerRequestMods', restructure modloading
now every player has their own list of allowed client mods, this can be modified by lua upon joining and is later used as a whitelist to ensure only those files can be sent to each client
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "BoostAliases.h"
|
||||
#include "Common.h"
|
||||
#include "Compat.h"
|
||||
#include "TResourceManager.h"
|
||||
#include "VehicleData.h"
|
||||
|
||||
class TServer;
|
||||
@@ -103,6 +104,8 @@ public:
|
||||
|
||||
TimeType::time_point ConnectionTime {};
|
||||
|
||||
ModMap AllowedMods;
|
||||
|
||||
private:
|
||||
void InsertVehicle(int ID, const std::string& Data);
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ constexpr std::string_view StrLogChat = "LogChat";
|
||||
constexpr std::string_view StrSendErrors = "Misc.SendErrors";
|
||||
constexpr std::string_view StrSendErrorsMessageEnabled = "Misc.SendErrorsShowMessage";
|
||||
constexpr std::string_view StrHideUpdateMessages = "Misc.ImScaredOfUpdates";
|
||||
constexpr std::string_view StrIncludeSubdirectories = "Misc.IncludeSubdirectories";
|
||||
|
||||
// HTTP
|
||||
constexpr std::string_view StrHTTPServerEnabled = "HTTP.HTTPServerEnabled";
|
||||
@@ -79,6 +80,9 @@ struct Version {
|
||||
template <typename T>
|
||||
using SparseArray = std::unordered_map<size_t, T>;
|
||||
|
||||
template <typename K, typename V>
|
||||
using HashMap = std::unordered_map<K, V>;
|
||||
|
||||
using boost::variant;
|
||||
using boost::container::flat_map;
|
||||
|
||||
|
||||
@@ -35,14 +35,15 @@ namespace fs = std::filesystem;
|
||||
/**
|
||||
* std::variant means, that TLuaArgTypes may be one of the Types listed as template args
|
||||
*/
|
||||
using TLuaValue = std::variant<std::string, int, JsonString, bool, std::unordered_map<std::string, std::string>, float>;
|
||||
using TLuaValue = std::variant<std::string, int, JsonString, bool, std::unordered_map<std::string, std::string>, std::unordered_map<std::string, size_t>, float>;
|
||||
enum TLuaType {
|
||||
String = 0,
|
||||
Int = 1,
|
||||
Json = 2,
|
||||
Bool = 3,
|
||||
StringStringMap = 4,
|
||||
Float = 5,
|
||||
StringSizeTMap = 5,
|
||||
Float = 6,
|
||||
};
|
||||
|
||||
class TLuaPlugin;
|
||||
|
||||
@@ -46,6 +46,7 @@ private:
|
||||
void Looper(const std::weak_ptr<TClient>& c);
|
||||
int OpenID();
|
||||
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr);
|
||||
ModMap GetClientMods(TClient& Client);
|
||||
void HandleResourcePackets(TClient& c, const std::vector<uint8_t>& Packet);
|
||||
void SendFile(TClient& c, const std::string& Name);
|
||||
static bool TCPSendRaw(TClient& C, ip::tcp::socket& socket, const uint8_t* Data, size_t Size);
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include <optional>
|
||||
|
||||
using ModMap = HashMap<std::string, size_t>;
|
||||
|
||||
class TResourceManager {
|
||||
public:
|
||||
TResourceManager();
|
||||
|
||||
[[nodiscard]] size_t MaxModSize() const { return mMaxModSize; }
|
||||
[[nodiscard]] std::string FileList() const { return mFileList; }
|
||||
[[nodiscard]] std::string TrimmedList() const { return mTrimmedList; }
|
||||
[[nodiscard]] std::string FileSizes() const { return mFileSizes; }
|
||||
[[nodiscard]] int ModsLoaded() const { return mModsLoaded; }
|
||||
[[nodiscard]] size_t TotalModsSize() const { return mTotalModSize; }
|
||||
[[nodiscard]] ModMap FileMap() const { return mMods; }
|
||||
[[nodiscard]] static std::string FormatForBackend(const ModMap& mods);
|
||||
[[nodiscard]] static std::string FormatForClient(const ModMap& mods);
|
||||
[[nodiscard]] static std::optional<std::string> IsModValid(std::string& pathString, const ModMap& mods);
|
||||
[[nodiscard]] int LoadedModCount() const { return mMods.size(); }
|
||||
|
||||
private:
|
||||
size_t mMaxModSize = 0;
|
||||
std::string mFileSizes;
|
||||
std::string mFileList;
|
||||
std::string mTrimmedList;
|
||||
int mModsLoaded = 0;
|
||||
size_t mTotalModSize = 0; // size of all mods
|
||||
ModMap mMods; // map of mod names
|
||||
};
|
||||
Reference in New Issue
Block a user