summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/GlobalAPI
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
committernavewindre <nw@moneybot.cc>2023-12-04 18:06:10 +0100
commitaef0d1c1268ab7d4bc18996c9c6b4da16a40aadc (patch)
tree43e766b51704f4ab8b383583bdc1871eeeb9c698 /sourcemod/scripting/include/GlobalAPI
parent38f1140c11724da05a23a10385061200b907cf6e (diff)
bbbbbbbbwaaaaaaaaaaa
Diffstat (limited to 'sourcemod/scripting/include/GlobalAPI')
-rw-r--r--sourcemod/scripting/include/GlobalAPI/iterable.inc55
-rw-r--r--sourcemod/scripting/include/GlobalAPI/request.inc185
-rw-r--r--sourcemod/scripting/include/GlobalAPI/requestdata.inc534
-rw-r--r--sourcemod/scripting/include/GlobalAPI/responses.inc575
-rw-r--r--sourcemod/scripting/include/GlobalAPI/stocks.inc67
5 files changed, 1416 insertions, 0 deletions
diff --git a/sourcemod/scripting/include/GlobalAPI/iterable.inc b/sourcemod/scripting/include/GlobalAPI/iterable.inc
new file mode 100644
index 0000000..585873b
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/iterable.inc
@@ -0,0 +1,55 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_Iterable_included_
+#endinput
+#endif
+#define _GlobalAPI_Iterable_included_
+
+// =========================================================== //
+
+#include <json>
+
+// =========================================================== //
+
+/*
+ Helper methodmap for JSON_Object arrays
+*/
+methodmap APIIterable < JSON_Object
+{
+ /**
+ * Creates a new APIIterable
+ *
+ * @param hItems JSON_Object array handle
+ * @return A new APIIterable handle
+ */
+ public APIIterable(JSON_Object hItems)
+ {
+ if (hItems.HasKey("result"))
+ {
+ return view_as<APIIterable>(hItems.GetObject("result"));
+ }
+ return view_as<APIIterable>(hItems);
+ }
+
+ /*
+ Gets count of the items in the array
+ */
+ property int Count
+ {
+ public get() { return this.Length; }
+ }
+
+ /**
+ * Gets an object from the array by index
+ *
+ * @note This is an alias to GetObjectIndexed
+ * @param index Index of the object we want to retrieve
+ * @return JSON_Object handle to the object retrieved
+ */
+ public JSON_Object GetById(int index)
+ {
+ return this.GetObjectIndexed(index);
+ }
+}
+
+// =========================================================== // \ No newline at end of file
diff --git a/sourcemod/scripting/include/GlobalAPI/request.inc b/sourcemod/scripting/include/GlobalAPI/request.inc
new file mode 100644
index 0000000..e683125
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/request.inc
@@ -0,0 +1,185 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_Request_included_
+#endinput
+#endif
+#define _GlobalAPI_Request_included_
+
+// =========================================================== //
+
+static char gC_acceptTypePhrases[][] =
+{
+ "application/json",
+ "application/octet-stream"
+};
+
+static char gC_contentTypePhrases[][] =
+{
+ "application/json",
+ "application/octet-stream"
+};
+
+// =========================================================== //
+
+methodmap GlobalAPIRequest < Handle
+{
+ /**
+ * Creates a new GlobalAPIRequest
+ *
+ * @param url URL of the request
+ * @param method SteamWorks k_ETTPMethod of the request
+ * @return A new GlobalAPIRequest handle
+ */
+ public GlobalAPIRequest(char[] url, EHTTPMethod method)
+ {
+ Handle request = SteamWorks_CreateHTTPRequest(method, url);
+ return view_as<GlobalAPIRequest>(request);
+ }
+
+ /**
+ * Sets request timeout
+ *
+ * @param seconds Timeout in seconds
+ * @return Whether the operation was successful
+ */
+ public bool SetTimeout(int seconds)
+ {
+ return SteamWorks_SetHTTPRequestAbsoluteTimeoutMS(this, seconds * 1000);
+ }
+
+ /**
+ * Sets request body
+ *
+ * @param hData GlobalAPIRequestData containing contentType
+ * @param body Request body to set
+ * @param maxlength Maxlength of the body
+ * @return Whether the operation was successful
+ */
+ public bool SetBody(GlobalAPIRequestData hData, char[] body, int maxlength)
+ {
+ return SteamWorks_SetHTTPRequestRawPostBody(this, gC_contentTypePhrases[hData.ContentType], body, maxlength);
+ }
+
+ /**
+ * Sets request body from a file
+ *
+ * @param hData GlobalAPIRequestData containing contentType
+ * @return Whether the operation was successful
+ */
+ public bool SetBodyFromFile(GlobalAPIRequestData hData, char[] file)
+ {
+ return SteamWorks_SetHTTPRequestRawPostBodyFromFile(this, gC_contentTypePhrases[hData.ContentType], file);
+ }
+
+ /**
+ * Sets a request context value
+ *
+ * @param data Any data to pass
+ * @return Whether the operation was successful
+ */
+ public bool SetData(any data1, any data2 = 0)
+ {
+ return SteamWorks_SetHTTPRequestContextValue(this, data1, data2);
+ }
+
+ /**
+ * Sets predefined HTTP callbacks
+ *
+ * @note Predefined values respectively:
+ * @note Global_HTTP_Completed, Global_HTTP_Headers and Global_HTTP_DataReceived
+ * @noreturn
+ */
+ public void SetCallbacks()
+ {
+ SteamWorks_SetHTTPCallbacks(this, Global_HTTP_Completed, Global_HTTP_Headers, Global_HTTP_DataReceived);
+ }
+
+ /**
+ * Sets "Accept" header
+ *
+ * @param hData GlobalAPIRequestData containing acceptType
+ * @return Whether the operation was successful
+ */
+ public bool SetAcceptHeaders(GlobalAPIRequestData hData)
+ {
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "Accept", gC_acceptTypePhrases[hData.AcceptType]);
+ }
+
+ /**
+ * Sets "powered by" header
+ *
+ * @return Whether the operation was successful
+ */
+ public bool SetPoweredByHeader()
+ {
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "X-Powered-By", GlobalAPI_Plugin_NameVersion);
+ }
+
+ /**
+ * Sets authentication header
+ *
+ * @return Whether the operation was successful
+ */
+ public bool SetAuthenticationHeader(char[] apiKey)
+ {
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "X-ApiKey", apiKey);
+ }
+
+ /**
+ * Sets envinroment headers (MetaMod & SourceMod)
+ *
+ * @param mmVersion MetaMod version string
+ * @param smVersion SourceMod version string
+ * @return Whether the operation was successful
+ */
+ public bool SetEnvironmentHeaders(char[] mmVersion, char[] smVersion)
+ {
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "X-MetaMod-Version", mmVersion)
+ && SteamWorks_SetHTTPRequestHeaderValue(this, "X-SourceMod-Version", smVersion);
+ }
+
+ /**
+ * Sets content type header
+ *
+ * @param hData GlobalAPIRequestData containing contentType
+ * @return Whether the operation was successful
+ */
+ public bool SetContentTypeHeader(GlobalAPIRequestData hData)
+ {
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "Content-Type", gC_contentTypePhrases[hData.ContentType]);
+ }
+
+ /**
+ * Sets request origin header
+ *
+ * @param hData GlobalAPIRequestData containing pluginName
+ * @return Whether the operation was successful
+ */
+ public bool SetRequestOriginHeader(GlobalAPIRequestData hData)
+ {
+ char pluginName[GlobalAPI_Max_PluginName_Length];
+ hData.GetString("pluginName", pluginName, sizeof(pluginName));
+
+ char pluginVersion[GlobalAPI_Max_PluginVersion_Length + 2];
+ hData.GetString("pluginVersion", pluginVersion, sizeof(pluginVersion));
+
+ char fullPluginDisplay[sizeof(pluginName) + sizeof(pluginVersion) + 6];
+ Format(fullPluginDisplay, sizeof(fullPluginDisplay), "%s (V.%s)", pluginName, pluginVersion);
+
+ return SteamWorks_SetHTTPRequestHeaderValue(this, "X-Request-Origin", fullPluginDisplay);
+ }
+
+ /**
+ * Sends our request with all available data
+ *
+ * @param hData GlobalAPIRequestData handle with all required keys
+ * @return Whether the operation was successful
+ */
+ public bool Send(GlobalAPIRequestData hData)
+ {
+ Call_Private_OnHTTPStart(this, hData);
+ return SteamWorks_SendHTTPRequest(this);
+ }
+}
+
+// =========================================================== // \ No newline at end of file
diff --git a/sourcemod/scripting/include/GlobalAPI/requestdata.inc b/sourcemod/scripting/include/GlobalAPI/requestdata.inc
new file mode 100644
index 0000000..f055ee8
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/requestdata.inc
@@ -0,0 +1,534 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_RequestData_included_
+#endinput
+#endif
+#define _GlobalAPI_RequestData_included_
+
+// =========================================================== //
+
+#include <json>
+
+// =========================================================== //
+
+/*
+ Helper methodmap for wrapping data related to requests
+*/
+methodmap GlobalAPIRequestData < JSON_Object
+{
+ /**
+ * Creates a new GlobalAPIRequestData
+ *
+ * @note You can pass a plugin handle or name and/or version
+ * @note Plugin handle is always preferred
+ * @param plugin Handle to calling plugin
+ * @param pluginName Name of the calling plugin
+ * @param pluginVersion Version of the calling plugin
+ * @return A new GlobalAPIRequestData handle
+ */
+ public GlobalAPIRequestData(Handle plugin = null, char[] pluginName = "Unknown", char[] pluginVersion = "Unknown")
+ {
+ JSON_Object requestData = new JSON_Object();
+
+ if (plugin == null)
+ {
+ requestData.SetString("pluginName", pluginName);
+ requestData.SetString("pluginVersion", pluginVersion);
+ }
+ else
+ {
+ requestData.SetString("pluginName", GetPluginDisplayName(plugin));
+ requestData.SetString("pluginVersion", GetPluginVersion(plugin));
+ }
+
+ requestData.SetKeyHidden("pluginName", true);
+ requestData.SetKeyHidden("pluginVersion", true);
+
+ requestData.SetInt("acceptType", 0);
+ requestData.SetKeyHidden("acceptType", true);
+
+ requestData.SetInt("contentType", 0);
+ requestData.SetKeyHidden("contentType", true);
+
+ return view_as<GlobalAPIRequestData>(requestData);
+ }
+
+ /**
+ * Sets a key as default
+ *
+ * @note This sets them as "Handle" type
+ * @note - See GlobalAPI.inc for default values
+ * @param key Key to set as default
+ * @noreturn
+ */
+ public void SetDefault(char[] key)
+ {
+ this.SetHandle(key);
+ this.SetKeyHidden(key, true);
+ }
+
+ /**
+ * Sets url to the request data
+ *
+ * @param url Url to set
+ * @noreturn
+ */
+ public void AddUrl(char[] url)
+ {
+ this.SetString("url", url);
+ this.SetKeyHidden("url", true);
+ }
+
+ /**
+ * Sets endpoint to the request data
+ *
+ * @param endpoint Endpoint to set
+ * @noreturn
+ */
+ public void AddEndpoint(char[] endpoint)
+ {
+ this.SetString("endpoint", endpoint);
+ this.SetKeyHidden("endpoint", true);
+ }
+
+ /**
+ * Sets body file path to the request data
+ *
+ * @note Path to file with data to be posted
+ * @param path Body file (path) to set
+ * @noreturn
+ */
+ public void AddBodyFile(char[] path)
+ {
+ this.SetString("bodyFile", path);
+ this.SetKeyHidden("bodyFile", true);
+ }
+
+ /**
+ * Sets data file path to the request data
+ *
+ * @note Path for downloaded files
+ * @param path Data path to set
+ * @noreturn
+ */
+ public void AddDataPath(char[] path)
+ {
+ this.SetString("dataFilePath", path);
+ this.SetKeyHidden("dataFilePath", true);
+ }
+
+ /*
+ Get or set the request's "acceptType"
+ */
+ property int AcceptType
+ {
+ public get()
+ {
+ return this.GetInt("acceptType");
+ }
+ public set(int type)
+ {
+ this.SetInt("acceptType", type);
+ }
+ }
+
+ /*
+ Get or set the request's "contentType"
+ */
+ property int ContentType
+ {
+ public get()
+ {
+ return this.GetInt("contentType");
+ }
+ public set(int type)
+ {
+ this.SetInt("contentType", type);
+ }
+ }
+
+ /*
+ Get or set the request's "keyRequired"
+ */
+ property bool KeyRequired
+ {
+ public get()
+ {
+ return this.GetBool("keyRequired");
+ }
+ public set(bool required)
+ {
+ this.SetBool("keyRequired", required);
+ this.SetKeyHidden("keyRequired", true);
+ }
+ }
+
+ /*
+ Get or set the request's "isRetried"
+ */
+ property bool IsRetried
+ {
+ public get()
+ {
+ return this.GetBool("isRetried");
+ }
+ public set(bool retried)
+ {
+ this.SetBool("isRetried", retried);
+ this.SetKeyHidden("isRetried", true);
+ }
+ }
+
+ /*
+ Get or set the request's "bodyLength"
+ */
+ property int BodyLength
+ {
+ public get()
+ {
+ return this.GetInt("bodyLength");
+ }
+ public set(int length)
+ {
+ this.SetInt("bodyLength", length);
+ this.SetKeyHidden("bodyLength", true);
+ }
+ }
+
+ /*
+ Get or set the request's "status"
+ */
+ property int Status
+ {
+ public get()
+ {
+ return this.GetInt("status");
+ }
+ public set(int status)
+ {
+ this.SetInt("status", status);
+ this.SetKeyHidden("status", true);
+ }
+ }
+
+ /*
+ Get or set the request's "responseTime"
+ */
+ property int ResponseTime
+ {
+ public get()
+ {
+ return this.GetInt("responseTime");
+ }
+ public set(int responseTime)
+ {
+ this.SetInt("responseTime", responseTime);
+ this.SetKeyHidden("responseTime", true);
+ }
+ }
+
+ /*
+ Get or set the request's "requestType"
+ */
+ property int RequestType
+ {
+ public get()
+ {
+ return this.GetInt("requestType");
+ }
+ public set(int type)
+ {
+ this.SetInt("requestType", type);
+ this.SetKeyHidden("requestType", true);
+ }
+ }
+
+ /*
+ Get or set the request's "failure"
+ */
+ property bool Failure
+ {
+ public get()
+ {
+ return this.GetBool("failure");
+ }
+ public set(bool failure)
+ {
+ this.SetBool("failure", failure);
+ this.SetKeyHidden("failure", true);
+ }
+ }
+
+ /*
+ Get or set the request's "callback"
+ */
+ property Handle Callback
+ {
+ public get()
+ {
+ return view_as<Handle>(this.GetInt("callback"));
+ }
+ public set(Handle hFwd)
+ {
+ this.SetHandle("callback", hFwd);
+ this.SetKeyType("callback", Type_Int);
+ this.SetKeyHidden("callback", true);
+ }
+ }
+
+ /*
+ Get or set the request's "data"
+ */
+ property any Data
+ {
+ public get()
+ {
+ return this.GetInt("data");
+ }
+ public set(any data)
+ {
+ this.SetInt("data", data);
+ this.SetKeyHidden("data", true);
+ }
+ }
+
+ /**
+ * Adds a number to the request data
+ *
+ * @note Default values are added as "defaults"
+ * @note See GlobalAPI.inc for the default values
+ * @param key Key name to set
+ * @param value Value of the key
+ * @noreturn
+ */
+ public void AddNum(char[] key, int value)
+ {
+ if (value == -1)
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ this.SetInt(key, value);
+ }
+ }
+
+ /**
+ * Adds a float to the request data
+ *
+ * @note Default values are added as "defaults"
+ * @note See GlobalAPI.inc for the default values
+ * @param key Key name to set
+ * @param value Value of the key
+ * @noreturn
+ */
+ public void AddFloat(char[] key, float value)
+ {
+ if (value == -1.000000)
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ this.SetFloat(key, value);
+ }
+ }
+
+ /**
+ * Adds a string to the request data
+ *
+ * @note Default values are added as "defaults"
+ * @note See GlobalAPI.inc for the default values
+ * @param key Key name to set
+ * @param value Value of the key
+ * @noreturn
+ */
+ public void AddString(char[] key, char[] value)
+ {
+ if (StrEqual(value, ""))
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ this.SetString(key, value);
+ }
+ }
+
+ /**
+ * Adds a boolean to the request data
+ *
+ * @note Default values are added as "defaults"
+ * @note See GlobalAPI.inc for the default values
+ * @param key Key name to set
+ * @param value Value of the key
+ * @noreturn
+ */
+ public void AddBool(char[] key, bool value)
+ {
+ if (value != true && value != false)
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ this.SetBool(key, value);
+ }
+ }
+
+ /**
+ * Adds integer array to the request data
+ *
+ * @note Max length <= 0 are added as defaults
+ * @param key Key name to set
+ * @param value Values (array) of the key
+ * @param maxlength Max length of the values array
+ * @noreturn
+ */
+ public void AddIntArray(char[] key, int[] value, int maxlength)
+ {
+ if (maxlength <= 0)
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ JSON_Object hArray = new JSON_Object(true);
+
+ for (int i = 0; i < maxlength; i++)
+ {
+ hArray.PushInt(value[i]);
+ }
+
+ this.SetObject(key, hArray);
+ }
+ }
+
+ /**
+ * Adds string array to the request data
+ *
+ * @note Item count <= 0 are added as defaults
+ * @param key Key name to set
+ * @param itemCount Amount of strings in the array
+ * @noreturn
+ */
+ public void AddStringArray(char[] key, char[][] value, int itemCount)
+ {
+ if (itemCount <= 0)
+ {
+ this.SetDefault(key);
+ }
+ else
+ {
+ JSON_Object hArray = new JSON_Object(true);
+
+ for (int i = 0; i < itemCount; i++)
+ {
+ hArray.PushString(value[i]);
+ }
+
+ this.SetObject(key, hArray);
+ }
+ }
+
+ /**
+ * Converts all of the request data into a query string representation
+ *
+ * @note This ignores "hidden" keys
+ * @param queryString Buffer to store the result in
+ * @param maxlength Max length of the buffer
+ * @noreturn
+ */
+ public void ToString(char[] queryString, int maxlength)
+ {
+ StringMapSnapshot paramsMap = this.Snapshot();
+
+ char key[64];
+ char value[1024];
+
+ int paramCount = 0;
+
+ for (int i = 0; i < paramsMap.Length; i++)
+ {
+ paramsMap.GetKey(i, key, sizeof(key));
+ if (this.GetKeyHidden(key) || json_is_meta_key(key))
+ {
+ continue;
+ }
+
+ switch(this.GetKeyType(key))
+ {
+ case Type_String:
+ {
+ this.GetString(key, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ case Type_Float:
+ {
+ float temp = this.GetFloat(key);
+ FloatToString(temp, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ case Type_Int:
+ {
+ int temp = this.GetInt(key);
+ IntToString(temp, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ case Type_Bool:
+ {
+ bool temp = this.GetBool(key);
+ BoolToString(temp, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ case Type_Object:
+ {
+ JSON_Object hObject = this.GetObject(key);
+
+ if (!hObject.IsArray) continue;
+
+ for (int x = 0; x < hObject.Length; x++)
+ {
+ switch (hObject.GetKeyTypeIndexed(x))
+ {
+ case Type_Int:
+ {
+ int temp = hObject.GetIntIndexed(x);
+ IntToString(temp, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ case Type_String:
+ {
+ hObject.GetStringIndexed(x, value, sizeof(value));
+ AppendToQueryString(paramCount, queryString, maxlength, key, value);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ delete paramsMap;
+ }
+}
+
+// =====[ PRIVATE ]=====
+
+static void BoolToString(bool value, char[] buffer, int maxlength)
+{
+ FormatEx(buffer, maxlength, "%s", value ? "true" : "false");
+}
+
+static void AppendToQueryString(int &index, char[] buffer, int maxlength, char[] key, char[] value)
+{
+ if (index == 0)
+ {
+ index++;
+ Format(buffer, maxlength, "?%s=%s", key, value);
+ }
+ else
+ {
+ index++;
+ Format(buffer, maxlength, "%s&%s=%s", buffer, key, value);
+ }
+}
diff --git a/sourcemod/scripting/include/GlobalAPI/responses.inc b/sourcemod/scripting/include/GlobalAPI/responses.inc
new file mode 100644
index 0000000..62ebfd2
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/responses.inc
@@ -0,0 +1,575 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_Responses_included_
+#endinput
+#endif
+#define _GlobalAPI_Responses_included_
+
+// =========================================================== //
+
+#include <json>
+#include <GlobalAPI/iterable>
+
+// =========================================================== //
+
+methodmap APIAuth < JSON_Object
+{
+ public APIAuth(JSON_Object hAuth)
+ {
+ return view_as<APIAuth>(hAuth);
+ }
+
+ public bool GetType(char[] buffer, int maxlength)
+ {
+ return this.GetString("Type", buffer, maxlength);
+ }
+
+ property bool IsValid
+ {
+ public get() { return this.GetBool("IsValid"); }
+ }
+
+ property int Identity
+ {
+ public get() { return this.GetInt("Identity"); }
+ }
+}
+
+// =========================================================== //
+
+methodmap APIBan < JSON_Object
+{
+ public APIBan(JSON_Object hBan)
+ {
+ return view_as<APIBan>(hBan);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ property int UpdatedById
+ {
+ public get() { return this.GetInt("updated_by_id"); }
+ }
+
+ public void GetStats(char[] buffer, int maxlength)
+ {
+ this.GetString("stats", buffer, maxlength);
+ }
+
+ public void GetBanType(char[] buffer, int maxlength)
+ {
+ this.GetString("ban_type", buffer, maxlength);
+ }
+
+ public void GetExpiresOn(char[] buffer, int maxlength)
+ {
+ this.GetString("expires_on", buffer, maxlength);
+ }
+
+ public void GetSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid64", buffer, maxlength);
+ }
+
+ public void GetPlayerName(char[] buffer, int maxlength)
+ {
+ this.GetString("player_name", buffer, maxlength);
+ }
+
+ public void GetNotes(char[] buffer, int maxlength)
+ {
+ this.GetString("notes", buffer, maxlength);
+ }
+
+ public void GetSteamId(char[] buffer, int maxlength)
+ {
+ this.GetString("steam_id", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+
+ property int ServerId
+ {
+ public get() { return this.GetInt("server_id"); }
+ }
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIJumpstat < JSON_Object
+{
+ public APIJumpstat(JSON_Object hJump)
+ {
+ return view_as<APIJumpstat>(hJump);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ property int ServerId
+ {
+ public get() { return this.GetInt("server_id"); }
+ }
+
+ public void GetSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid64", buffer, maxlength);
+ }
+
+ public void GetName(char[] buffer, int maxlength)
+ {
+ this.GetString("player_name", buffer, maxlength);
+ }
+
+ public void GetSteamId(char[] buffer, int maxlength)
+ {
+ this.GetString("steam_id", buffer, maxlength);
+ }
+
+ property int JumpType
+ {
+ public get() { return this.GetInt("jump_type"); }
+ }
+
+ property float Distance
+ {
+ public get() { return this.GetFloat("distance"); }
+ }
+
+ property int TickRate
+ {
+ public get() { return this.GetInt("tickrate"); }
+ }
+
+ property int MslCount
+ {
+ public get() { return this.GetInt("msl_count"); }
+ }
+
+ property int StrafeCount
+ {
+ public get() { return this.GetInt("strafe_count"); }
+ }
+
+ property bool IsCrouchBind
+ {
+ public get() { return this.GetBool("is_crouch_bind"); }
+ }
+
+ property bool IsForwardBind
+ {
+ public get() { return this.GetBool("is_forward_bind"); }
+ }
+
+ property bool IsCrouchBoost
+ {
+ public get() { return this.GetBool("is_crouch_boost"); }
+ }
+
+ property int UpdatedById
+ {
+ public get() { return this.GetInt("updated_by_id"); }
+ }
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIMap < JSON_Object
+{
+ public APIMap(JSON_Object hMap)
+ {
+ return view_as<APIMap>(hMap);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ public void GetName(char[] buffer, int maxlength)
+ {
+ this.GetString("name", buffer, maxlength);
+ }
+
+ property int Filesize
+ {
+ public get() { return this.GetInt("filesize"); }
+ }
+
+ property bool IsValidated
+ {
+ public get() { return this.GetBool("validated"); }
+ }
+
+ property int Difficulty
+ {
+ public get() { return this.GetInt("difficulty"); }
+ }
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+
+ public void GetApprovedBySteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("approved_by_steamid64", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIMode < JSON_Object
+{
+ public APIMode(JSON_Object hMode)
+ {
+ return view_as<APIMode>(hMode);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ public void GetName(char[] buffer, int maxlength)
+ {
+ this.GetString("name", buffer, maxlength);
+ }
+
+ public void GetDescription(char[] buffer, int maxlength)
+ {
+ this.GetString("description", buffer, maxlength);
+ }
+
+ property int LatestVersion
+ {
+ public get() { return this.GetInt("latest_version"); }
+ }
+
+ public void GetLatestVersionDesc(char[] buffer, int maxlength)
+ {
+ this.GetString("latest_version_description", buffer, maxlength);
+ }
+
+ public void GetWebsite(char[] buffer, int maxlength)
+ {
+ this.GetString("website", buffer, maxlength);
+ }
+
+ public void GetRepository(char[] buffer, int maxlength)
+ {
+ this.GetString("repo", buffer, maxlength);
+ }
+
+ public void GetContactSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("contact_steamid64", buffer, maxlength);
+ }
+
+ // TODO: Add supported_tickrates
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedById(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_by_id", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIPlayerRank < JSON_Object
+{
+ public APIPlayerRank(JSON_Object hPlayerRank)
+ {
+ return view_as<APIPlayerRank>(hPlayerRank);
+ }
+
+ property int Points
+ {
+ public get() { return this.GetInt("points"); }
+ }
+
+ property int PointsOverall
+ {
+ public get() { return this.GetInt("points_overall"); }
+ }
+
+ property float Average
+ {
+ public get() { return this.GetFloat("average"); }
+ }
+
+ property float Rating
+ {
+ public get() { return this.GetFloat("rating"); }
+ }
+
+ property int Finishes
+ {
+ public get() { return this.GetInt("finishes"); }
+ }
+
+ public void GetSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid64", buffer, maxlength);
+ }
+
+ public void GetSteamId(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid", buffer, maxlength);
+ }
+
+ public void GetPlayerName(char[] buffer, int maxlength)
+ {
+ this.GetString("player_name", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIPlayer < JSON_Object
+{
+ public APIPlayer(JSON_Object hPlayer)
+ {
+ return view_as<APIPlayer>(hPlayer);
+ }
+
+ public void GetSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid64", buffer, maxlength);
+ }
+
+ public void GetSteamId(char[] buffer, int maxlength)
+ {
+ this.GetString("steam_id", buffer, maxlength);
+ }
+
+ property bool IsBanned
+ {
+ public get() { return this.GetBool("is_banned"); }
+ }
+
+ property int TotalRecords
+ {
+ public get() { return this.GetInt("total_records"); }
+ }
+
+ public void GetName(char[] buffer, int maxlength)
+ {
+ this.GetString("name", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIRecord < JSON_Object
+{
+ public APIRecord(JSON_Object hRecord)
+ {
+ return view_as<APIRecord>(hRecord);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ public void GetSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("steamid64", buffer, maxlength);
+ }
+
+ public void GetPlayerName(char[] buffer, int maxlength)
+ {
+ this.GetString("player_name", buffer, maxlength);
+ }
+
+ public void GetSteamId(char[] buffer, int maxlength)
+ {
+ this.GetString("steam_id", buffer, maxlength);
+ }
+
+ property int ServerId
+ {
+ public get() { return this.GetInt("server_id"); }
+ }
+
+ property int MapId
+ {
+ public get() { return this.GetInt("map_id"); }
+ }
+
+ property int Stage
+ {
+ public get() { return this.GetInt("stage"); }
+ }
+
+ public void GetMode(char[] buffer, int maxlength)
+ {
+ this.GetString("mode", buffer, maxlength);
+ }
+
+ property int TickRate
+ {
+ public get() { return this.GetInt("tickrate"); }
+ }
+
+ property float Time
+ {
+ public get() { return this.GetFloat("time"); }
+ }
+
+ property int Teleports
+ {
+ public get() { return this.GetInt("teleports"); }
+ }
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+
+ property int UpdatedBy
+ {
+ public get() { return this.GetInt("updated_by"); }
+ }
+
+ public void GetServerName(char[] buffer, int maxlength)
+ {
+ this.GetString("server_name", buffer, maxlength);
+ }
+
+ public void GetMapName(char[] buffer, int maxlength)
+ {
+ this.GetString("map_name", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIServer < JSON_Object
+{
+ public APIServer(JSON_Object hServer)
+ {
+ return view_as<APIServer>(hServer);
+ }
+
+ property int Port
+ {
+ public get() { return this.GetInt("port"); }
+ }
+
+ public void GetIPAddress(char[] buffer, int maxlength)
+ {
+ this.GetString("ip", buffer, maxlength);
+ }
+
+ public void GetName(char[] buffer, int maxlength)
+ {
+ this.GetString("name", buffer, maxlength);
+ }
+
+ public void GetOwnerSteamId64(char[] buffer, int maxlength)
+ {
+ this.GetString("owner_steamid64", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
+
+methodmap APIRecordFilter < JSON_Object
+{
+ public APIRecordFilter(JSON_Object hRecordFilter)
+ {
+ return view_as<APIRecordFilter>(hRecordFilter);
+ }
+
+ property int Id
+ {
+ public get() { return this.GetInt("id"); }
+ }
+
+ property int MapId
+ {
+ public get() { return this.GetInt("map_id"); }
+ }
+
+ property int Stage
+ {
+ public get() { return this.GetInt("stage"); }
+ }
+
+ property int ModeId
+ {
+ public get() { return this.GetInt("mode_id"); }
+ }
+
+ property int TickRate
+ {
+ public get() { return this.GetInt("tickrate"); }
+ }
+
+ property bool HasTeleports
+ {
+ public get() { return this.GetBool("has_teleports"); }
+ }
+
+ public void GetCreatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("created_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedOn(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_on", buffer, maxlength);
+ }
+
+ public void GetUpdatedById(char[] buffer, int maxlength)
+ {
+ this.GetString("updated_by_id", buffer, maxlength);
+ }
+}
+
+// =========================================================== //
diff --git a/sourcemod/scripting/include/GlobalAPI/stocks.inc b/sourcemod/scripting/include/GlobalAPI/stocks.inc
new file mode 100644
index 0000000..52596c4
--- /dev/null
+++ b/sourcemod/scripting/include/GlobalAPI/stocks.inc
@@ -0,0 +1,67 @@
+// ================== DOUBLE INCLUDE ========================= //
+
+#if defined _GlobalAPI_Stocks_included_
+#endinput
+#endif
+#define _GlobalAPI_Stocks_included_
+
+// =========================================================== //
+
+/**
+ * Gets plugin's display name from its handle
+ *
+ * @param plugin Plugin handle to retrieve name from
+ * @return String representation of the plugin name
+ */
+stock char[] GetPluginDisplayName(Handle plugin)
+{
+ char pluginName[GlobalAPI_Max_PluginName_Length] = "Unknown";
+ GetPluginInfo(plugin, PlInfo_Name, pluginName, sizeof(pluginName));
+
+ return pluginName;
+}
+
+/**
+ * Gets plugin's version from its handle
+ *
+ * @param plugin Plugin handle to retrieve version from
+ * @return String representation of the plugin version
+ */
+stock char[] GetPluginVersion(Handle plugin)
+{
+ char pluginVersion[GlobalAPI_Max_PluginVersion_Length] = "Unknown";
+ GetPluginInfo(plugin, PlInfo_Version, pluginVersion, sizeof(pluginVersion));
+
+ return pluginVersion;
+}
+
+/**
+ * Gets current map's "display name"
+ *
+ * @param buffer Buffer to store the result in
+ * @param maxlength Max length of the buffer
+ * @noreturn
+ */
+stock void GetMapDisplay(char[] buffer, int maxlength)
+{
+ char map[PLATFORM_MAX_PATH];
+ GetCurrentMap(map, sizeof(map));
+ GetMapDisplayName(map, map, sizeof(map));
+
+ FormatEx(buffer, maxlength, map);
+}
+
+/**
+ * Gets current map's full (game dir) path
+ *
+ * @param buffer Buffer to store result in
+ * @param maxlength Max length of the buffer
+ * @noreturn
+ */
+stock void GetMapFullPath(char[] buffer, int maxlength)
+{
+ char mapPath[PLATFORM_MAX_PATH];
+ GetCurrentMap(mapPath, sizeof(mapPath));
+
+ Format(buffer, maxlength, "maps/%s.bsp", mapPath);
+}