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:
20dka
2022-11-14 00:10:36 +01:00
committed by Lion Kortlepel
parent 056827546e
commit 468a6b340e
10 changed files with 140 additions and 50 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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
};