#pragma once #include #include #include #include #include #include #include #include #include #include #include #include "http.hpp" namespace game { struct scr_entref_t { unsigned short entnum = 0, classnum = 0; }; inline std::vector> 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 shutdown; inline void on_shutdown(std::function callback) { shutdown=callback; } } namespace plugin { struct callbacks { std::function connect, disconnect; void on_player_connect(std::function fn) {connect=fn;} void on_player_disconnect(std::function 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 on_execute; inline std::vector 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> tasks; void push(std::function 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 configure; inline std::function pump; template void add(const char*,F fn) { if constexpr(std::is_invocable_r_v)configure=fn; else if constexpr(std::is_invocable_r_v) { if constexpr(std::is_same_v,void>)pump=fn; } } } namespace gsc::method { inline std::function observe; template 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{}(input)); } } namespace utils::http { inline std::string response, request; inline std::optional 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; } }