Add identity-safe player moderation runtimes for T5 and T6
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <json.hpp>
|
||||
#include "http.hpp"
|
||||
namespace game {
|
||||
struct scr_entref_t { unsigned short entnum = 0, classnum = 0; };
|
||||
inline std::vector<std::pair<int,std::string>> messages;
|
||||
inline void SV_GameSendServerCommand(int slot, int, const char* message) { messages.emplace_back(slot,message); }
|
||||
}
|
||||
namespace scripting {
|
||||
struct entity { game::scr_entref_t ref; game::scr_entref_t get_entity_reference() const { return ref; } };
|
||||
struct array {};
|
||||
inline std::function<void()> shutdown;
|
||||
inline void on_shutdown(std::function<void()> callback) { shutdown=callback; }
|
||||
}
|
||||
namespace plugin {
|
||||
struct callbacks { std::function<void(unsigned)> connect, disconnect; void on_player_connect(std::function<void(unsigned)> fn) {connect=fn;} void on_player_disconnect(std::function<void(unsigned)> fn) {disconnect=fn;} };
|
||||
struct iface { plugin::callbacks c; plugin::callbacks* callbacks() {return &c;} };
|
||||
struct plugin { iface i; iface* get_interface() {return &i;} };
|
||||
}
|
||||
struct component_interface { virtual ~component_interface()=default; virtual void on_startup(plugin::plugin*) {} };
|
||||
#define REGISTER_COMPONENT(x)
|
||||
namespace command { inline std::function<void()> on_execute; inline std::vector<std::string> commands; inline void execute(std::string command,bool sync) {assert(sync); commands.push_back(command); if(on_execute)on_execute();} }
|
||||
namespace scheduler { struct pool { std::vector<std::function<void()>> tasks; void push(std::function<void()> fn) {tasks.push_back(fn);} void flush() {auto copy=tasks; tasks.clear(); for(auto& fn:copy)fn();} }; inline pool thread_pool; }
|
||||
namespace gsc::function {
|
||||
inline std::function<bool(std::string,std::string,std::string,int)> configure;
|
||||
inline std::function<void()> pump;
|
||||
template<typename F> void add(const char*,F fn) {
|
||||
if constexpr(std::is_invocable_r_v<bool,F,std::string,std::string,std::string,int>)configure=fn;
|
||||
else if constexpr(std::is_invocable_r_v<void,F>) { if constexpr(std::is_same_v<std::invoke_result_t<F>,void>)pump=fn; }
|
||||
}
|
||||
}
|
||||
namespace gsc::method { inline std::function<bool(scripting::entity,std::string,std::string)> observe; template<typename F> void add(const char*,F fn) {observe=fn;} }
|
||||
namespace utils::cryptography::sha256 { inline std::string compute(const std::string& input, bool hex) { assert(hex); return std::to_string(std::hash<std::string>{}(input)); } }
|
||||
namespace utils::http {
|
||||
inline std::string response, request;
|
||||
inline std::optional<result> get_data(const std::string& url,const std::string& fields,const headers& hdrs,const std::string& method,const timeouts& limits) {
|
||||
assert(url=="https://controller/api/moderation/runtime"); assert(method=="POST"); assert(hdrs.at("Authorization").starts_with("Bearer ec_moderation_")); assert(limits.max_response_bytes==1024*1024);
|
||||
request=fields; result out; out.status=200; out.code=CURLE_OK; out.buffer=response; return out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user