Work on overlay natives

This commit is contained in:
Jackzie 2024-05-07 12:10:16 -05:00
parent 9a5aa5dd5f
commit 74f04f4847
6 changed files with 543 additions and 117 deletions

View file

@ -0,0 +1,84 @@
#if defined _overlay_included
#endinput
#endif
#define _overlay_included
#include <ripext>
native bool SendTempUI(int client, const char[] id, int lifetime, JSONObject element);
native bool ShowUI(int client, const char[] elemNamespace, const char[] elemId, JSONObject variables);
native bool HideUI(int client, const char[] elemNamespace, const char[] elemId);
native bool PlayAudio(int client, const char[] url);
native bool IsOverlayConnected();
forward void OnUIAction(const char[] elemNamespace, const char[] elemId, const char[] action);
typedef UIActionCallback = function void (const char[][] args, int numArgs);
methodmap UIElement < JSONObject {
public UIElement(const char[] elemNamespace, const char[] elemId) {
JSONObject obj = new JSONObject();
obj.SetString("namespace", elemNamespace);
obj.SetString("id", elemId);
obj.SetBool("visibility", false);
return view_as<UIElement>(obj);
}
property bool Visible {
public get() {
return view_as<JSONObject>(this).GetBool("visibility");
}
public set(bool value) {
view_as<JSONObject>(this).SetBool("visibility", value);
this.Send();
}
}
/** Is the UI element globally sent to all connected players?
* Specify players with .AddClient() or clear with .ClearClients()
*/
property bool Global {
public get() {
return !view_as<JSONObject>(this).HasKey("steamids")
}
}
public void SetVariable(const char[] id, int value) {
view_as<JSONObject>(this).SetInt(id, value);
}
public void SetVariableFloat(const char[] id, float value) {
view_as<JSONObject>(this).SetFloat(id, value);
}
public void SetVariableString(const char[] id, const char[] value) {
view_as<JSONObject>(this).SetString(id, value);
}
public void SetVariableBool(const char[] id, bool value) {
view_as<JSONObject>(this).SetBool(id, value);
}
public void SetActionCallback(UIActionCallback callback) {}
public void AddClient(const char[] steamid) {
// if(!IsClientInGame(client) || steamidCache[client][0] == '\0') ThrowError("Client %d is not connected, ingame, or authorized");
JSONObject obj = view_as<JSONObject>(this);
JSONArray steamids = view_as<JSONArray>(obj.Get("steamids"));
if(steamids == null) {
steamids = new JSONArray();
obj.Set("steamids", steamids)
}
steamids.PushString(steamid);
}
public void ClearClients() {
view_as<JSONObject>(this).Remove("steamids");
}
public native bool Send();
}

View file

@ -5,6 +5,8 @@
#include <ripext/json>
#include <ripext/http>
#include <ripext/websocket>
#include <ripext/crypto>
/**
* Do not edit below this line!

View file

@ -0,0 +1,35 @@
methodmap Crypto
{
public native bool MD5(const char[] source, char[] buffer, int maxlength, bool uppercase = true);
public native bool MD5File(const char[] file, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA1(const char[] source, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA1File(const char[] file, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA256(const char[] source, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA256File(const char[] file, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA512(const char[] source, char[] buffer, int maxlength, bool uppercase = true);
public native bool SHA512File(const char[] file, char[] buffer, int maxlength, bool uppercase = true);
public native bool CRC16(const char[] source, char[] buffer, int maxlength, bool uppercase = true);
public native bool CRC16File(const char[] file, char[] buffer, int maxlength, bool uppercase = true);
public native bool CRC32(const char[] source, char[] buffer, int maxlength, bool uppercase = true, bool hexdecimal = true);
public native bool CRC32File(const char[] file, char[] buffer, int maxlength, bool uppercase = true, bool hexdecimal = true);
// - 1 is returned on success (the string output buffer is sufficient)
// otherwise it is the minimum buffer length required
public native int Base64Encode(const char[] source, char[] buffer, int maxlength);
// - 1 is returned on success (the string output buffer is sufficient)
// otherwise it is the minimum buffer length required
public native int Base64Decode(const char[] source, char[] buffer, int maxlength);
};

View file

@ -76,6 +76,15 @@ typeset HTTPFileCallback
function void (HTTPStatus status, any value, const char[] error);
};
typeset HTTPFileProgressCallback
{
// dltotal is the total number of bytes libcurl expects to download in this transfer
// dlnow is the number of bytes downloaded so far
// ultotal is the total number of bytes libcurl expects to upload in this transfer
// ulnow is the number of bytes uploaded so far
function void (bool isUpload, int dltotal, int dlnow, int ultotal, int ulnow);
};
methodmap HTTPRequest < Handle
{
// Creates an HTTP request.
@ -110,6 +119,27 @@ methodmap HTTPRequest < Handle
// @param password Password to use.
public native void SetBasicAuth(const char[] username, const char[] password);
/**
* Sets proxy for the request.
*
* @param proxy Hostname or dotted numerical IP address. A numerical IPv6 address must be written within [brackets].
* To specify port number in this string, append :[port] to the end of the host name (default: 1080).
* The proxy string may be prefixed with [scheme]:// to specify which kind of proxy is used.
* http://
* HTTP Proxy. Default when no scheme is specified.
* https://
* HTTPS Proxy.
* socks4://
* SOCKS4 Proxy.
* socks4a://
* SOCKS4a Proxy. Proxy resolves URL hostname.
* socks5://
* SOCKS5 Proxy.
* socks5h://
* SOCKS5 Proxy. Proxy resolves URL hostname.
*/
public native void SetProxy(const char[] proxy);
// Sets an HTTP header.
//
// @param name Header name.
@ -167,7 +197,7 @@ methodmap HTTPRequest < Handle
// @param path File path to write to.
// @param callback A function to use as a callback when the download has finished.
// @param value Optional value to pass to the callback function.
public native void DownloadFile(const char[] path, HTTPFileCallback callback, any value = 0);
public native void DownloadFile(const char[] path, HTTPFileCallback callback, HTTPFileProgressCallback progresscallback, any value = 0);
// Uploads a file.
//
@ -177,7 +207,7 @@ methodmap HTTPRequest < Handle
// @param path File path to read from.
// @param callback A function to use as a callback when the upload has finished.
// @param value Optional value to pass to the callback function.
public native void UploadFile(const char[] path, HTTPFileCallback callback, any value = 0);
public native void UploadFile(const char[] path, HTTPFileCallback callback, HTTPFileProgressCallback progresscallback, any value = 0);
// Performs an HTTP POST request with form data.
//
@ -227,6 +257,13 @@ methodmap HTTPResponse
// @param maxlength Maximum length of the string buffer.
// @return True on success, false if the header was not found.
public native bool GetHeader(const char[] name, char[] buffer, int maxlength);
// Retrieves an HTTP response string from the response.
//
// @param buffer String buffer to store value.
// @param maxlength Maximum length of the string buffer.
// @return True on success, false if the response string was not found.
public native bool GetResponseStr(char[] buffer, int maxlength);
// Retrieves the JSON data of the response.
//
@ -239,121 +276,9 @@ methodmap HTTPResponse
property HTTPStatus Status {
public native get();
}
};
// Deprecated. Use HTTPRequest instead.
methodmap HTTPClient < Handle
{
// Creates an HTTP client.
//
// The HTTPClient must be freed via delete or CloseHandle().
//
// @param baseURL Base URL to the REST API.
#pragma deprecated Use HTTPRequest instead.
public native HTTPClient(const char[] baseURL);
// Sets an HTTP header to be used for all requests.
//
// @param name Header name.
// @param value String value to set.
#pragma deprecated Use HTTPRequest.SetHeader() instead.
public native void SetHeader(const char[] name, const char[] value);
// Performs an HTTP GET request.
//
// @param endpoint API endpoint to request.
// @param callback A function to use as a callback when the request has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.Get() instead.
public native void Get(const char[] endpoint, HTTPRequestCallback callback, any value = 0);
// Performs an HTTP POST request.
//
// @param endpoint API endpoint to request.
// @param data JSON data to send.
// @param callback A function to use as a callback when the request has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.Post() instead.
public native void Post(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
// Performs an HTTP PUT request.
//
// @param endpoint API endpoint to request.
// @param data JSON data to send.
// @param callback A function to use as a callback when the request has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.Put() instead.
public native void Put(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
// Performs an HTTP PATCH request.
//
// @param endpoint API endpoint to request.
// @param data JSON data to send.
// @param callback A function to use as a callback when the request has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.Patch() instead.
public native void Patch(const char[] endpoint, JSON data, HTTPRequestCallback callback, any value = 0);
// Performs an HTTP DELETE request.
//
// @param endpoint API endpoint to request.
// @param callback A function to use as a callback when the request has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.Delete() instead.
public native void Delete(const char[] endpoint, HTTPRequestCallback callback, any value = 0);
// Downloads a file.
//
// @param endpoint API endpoint to download from.
// @param path File path to write to.
// @param callback A function to use as a callback when the download has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.DownloadFile() instead.
public native void DownloadFile(const char[] endpoint, const char[] path, HTTPFileCallback callback, any value = 0);
// Uploads a file.
//
// This function performs an HTTP PUT request. The file contents are sent in the request body.
//
// @param endpoint API endpoint to upload to.
// @param path File path to read from.
// @param callback A function to use as a callback when the upload has finished.
// @param value Optional value to pass to the callback function.
#pragma deprecated Use HTTPRequest.UploadFile() instead.
public native void UploadFile(const char[] endpoint, const char[] path, HTTPFileCallback callback, any value = 0);
// Connect timeout in seconds. Defaults to 10.
#pragma deprecated Use HTTPRequest.ConnectTimeout instead.
property int ConnectTimeout {
// Retrieves the HTTP response length.
property int ResponseDataLength {
public native get();
public native set(int connectTimeout);
}
// Follow HTTP 3xx redirects. Defaults to true.
#pragma deprecated Use HTTPRequest.MaxRedirects instead.
property bool FollowLocation {
public native get();
public native set(bool followLocation);
}
// Timeout in seconds. Defaults to 30.
#pragma deprecated Use HTTPRequest.Timeout instead.
property int Timeout {
public native get();
public native set(int timeout);
}
// Maximum upload speed in bytes per second. Defaults to unlimited speed.
#pragma deprecated Use HTTPRequest.MaxSendSpeed instead.
property int MaxSendSpeed {
public native get();
public native set(int speed);
}
// Maximum download speed in bytes per second. Defaults to unlimited speed.
#pragma deprecated Use HTTPRequest.MaxRecvSpeed instead.
property int MaxRecvSpeed {
public native get();
public native set(int speed);
}
};
};

View file

@ -0,0 +1,42 @@
typeset WebSocket_ReadCallback
{
//WebSocket_JSON
function void (WebSocket ws, JSON message, any data);
//Websocket_STRING
function void (WebSocket ws, const char[] buffer, any data);
}
typeset WebSocket_ConnectCallback
{
function void (WebSocket ws, any data);
}
enum WebSocket_Protocol {
WebSocket_JSON,
Websocket_STRING,
}
methodmap WebSocket < Handle {
// Creates an WebSocket request.
//
// The Handle must be freed via delete or CloseHandle().
//
// @param url URL to the Websocket endpoint Such as [scheme]://[hostname]:[port]?[QueryParam1]&[QueryParam2].
// [scheme] Support ws or wss
// [hostname] Support Domain or IP
// For example ws://[hostname]:[port]?test1=1&test2=2 Or wss://[hostname]:[port]?test1=1&test2=2
public native WebSocket(const char[] url);
public native bool SetHeader(const char[] header, const char[] value);
public native bool Connect();
public native bool Close();
public native bool SetReadCallback(WebSocket_Protocol protocol, WebSocket_ReadCallback callback, any data=0);
public native bool SetConnectCallback(WebSocket_ConnectCallback callback, any data=0);
public native bool SetDisconnectCallback(WebSocket_ConnectCallback callback, any data=0);
public native bool Write(JSON json);
public native bool WriteString(const char[] content);
// Returns whether the tcp stream is open
public native bool SocketOpen();
// Returns the websocket connect status
public native bool WsOpen();
}