From 0eb42312fc76dc2301bb0a57aa271d926fb4ecd5 Mon Sep 17 00:00:00 2001 From: jenz Date: Tue, 22 Sep 2026 01:49:53 +0200 Subject: [PATCH] moving plugins from steamworks to ripext with sourcemod 1.13 upgrade --- RaceTimer/scripting/racetimer_rank.sp | 91 +++++---------------------- RaceTimer/scripting/toplvl.sp | 67 +++++++++----------- 2 files changed, 47 insertions(+), 111 deletions(-) diff --git a/RaceTimer/scripting/racetimer_rank.sp b/RaceTimer/scripting/racetimer_rank.sp index 1ed119d..74fe5bf 100644 --- a/RaceTimer/scripting/racetimer_rank.sp +++ b/RaceTimer/scripting/racetimer_rank.sp @@ -1,6 +1,5 @@ #include -#include -#include +#include #include #include #include @@ -140,7 +139,7 @@ public void OnClientPostAdminCheck(int client) { if(!IsClientAuthorized(client) || IsClientSourceTV(client)) return; - + if (IsFakeClient(client)) { return; @@ -207,48 +206,29 @@ public void check_client_racetimer_rank(int client) char sRequest[256]; GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); FormatEx(sRequest, sizeof(sRequest), "https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/player/%s", sSID); - - Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest); - if (!hRequest || - !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || - !SteamWorks_SetHTTPRequestContextValue(hRequest, GetClientSerial(client)) || - !SteamWorks_SendHTTPRequest(hRequest)) - { - delete hRequest; - } + + HTTPRequest hRequest = new HTTPRequest(sRequest); + hRequest.Get(OnTransferComplete, GetClientSerial(client)); } -public int OnTransferComplete(Handle hRequest, bool bFailure, bool bSuccessful, EHTTPStatusCode eStatusCode, int iSerial) +public void OnTransferComplete(HTTPResponse response, any iSerial) { int client = GetClientFromSerial(iSerial); if (!client) //Player disconnected. + return; + + if (response.Status != HTTPStatus_OK || response.Data == null) { - delete hRequest; - return 0; + LogError("Request-Error: %d", response.Status); + return; } - if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK) - { - delete hRequest; - LogError("Request-Error: %d", eStatusCode); - return 0; - } + JSONObject obj = view_as(response.Data); - SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnTransferResponse, iSerial); - return 0; -} + int I_player_points = -1; //if no endpoint for steamID default value is -1 + if (obj.HasKey("PlayerPoints")) + I_player_points = obj.GetInt("PlayerPoints"); -public int OnTransferResponse(char[] sData, int iSerial) -{ - int client = GetClientFromSerial(iSerial); - if (!client) //Player disconnected. - { - return 0; - } - - JSON_Object obj = json_decode(sData); //https://github.com/clugg/sm-json - - int I_player_points = obj.GetInt("PlayerPoints") //if no endpoint for steamID default value is -1 if (I_player_points < 1000) { I_player_points = 1000; //setting level 1 @@ -272,8 +252,8 @@ public int OnTransferResponse(char[] sData, int iSerial) set_level_tag(client, I_player_points/1000); } } - json_cleanup_and_delete(obj); - return 0; + + delete obj; } public bool player_has_no_chattag(int client) @@ -373,40 +353,3 @@ public void set_level_tag(int client, int lvl) Format(tag, sizeof(tag), "\x07%s[L\x07%sV\x07%sL %s] ", hexadecimals, hexadecimals2, hexadecimals3, coloured_numbers); CCC_SetTag(client, tag); } - -//just a lazy place for applying server side fix for clan tags -//needed since august 24th 2026. -public Action OnClientCommandKeyValues(int client, KeyValues kv) -{ - if (client <= 0 || client > MaxClients || !IsClientInGame(client) || IsFakeClient(client)) - return Plugin_Continue; - - char clanTag[32]; - kv.GetString("tag", clanTag, sizeof(clanTag), ""); - - if (clanTag[0] == '\0') - return Plugin_Continue; - - DataPack dp; - CreateDataTimer(0.1, Timer_SetClanTag, dp); - dp.WriteCell(GetClientUserId(client)); - dp.WriteString(clanTag); - - return Plugin_Continue; -} - -public Action Timer_SetClanTag(Handle timer, DataPack pack) -{ - pack.Reset(); - int userId = pack.ReadCell(); - int client = GetClientOfUserId(userId); - - char clanTag[32]; - pack.ReadString(clanTag, sizeof(clanTag)); - - if (client && IsClientInGame(client)) - { - CS_SetClientClanTag(client, clanTag); - } - return Plugin_Stop; -} diff --git a/RaceTimer/scripting/toplvl.sp b/RaceTimer/scripting/toplvl.sp index 448d072..5c20327 100644 --- a/RaceTimer/scripting/toplvl.sp +++ b/RaceTimer/scripting/toplvl.sp @@ -1,6 +1,5 @@ #include -#include -#include +#include #include public Plugin myinfo = @@ -8,7 +7,7 @@ public Plugin myinfo = name = "Toplvl", author = "jenz", description = "show toplvl for racetimer", - version = "1.0", + version = "1.1", url = "" }; @@ -20,57 +19,52 @@ public void OnPluginStart() OnMapStart(); } -public int OnTransferResponse(char[] sData) +public void OnTransferComplete(HTTPResponse response, any value) { - JSON_Object obj = json_decode(sData); //https://github.com/clugg/sm-json - + if (response.Status != HTTPStatus_OK || response.Data == null) + { + LogError("Request-Error: %d", response.Status); + return; + } + + JSONObject obj = view_as(response.Data); + int counter = 0; while (counter < 100) { - char s_counter[3]; - IntToString(counter, s_counter, sizeof(s_counter)) - JSON_Object position_obj = obj.GetObject(s_counter); + char s_counter[4]; + IntToString(counter, s_counter, sizeof(s_counter)); + + if (!obj.HasKey(s_counter)) + { + g_cTimeRecords[counter][0] = '\0'; + counter++; + continue; + } + + JSONObject position_obj = view_as(obj.Get(s_counter)); int I_player_points = position_obj.GetInt("PlayerPoints"); char player_name[64]; - position_obj.GetString("name", player_name, sizeof(player_name)); + if (!position_obj.GetString("name", player_name, sizeof(player_name))) + player_name[0] = '\0'; Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "%s LVL: %i", player_name, I_player_points/1000); + + delete position_obj; counter++; } - //just cleaning the outmost object should be enough. - json_cleanup_and_delete(obj); - return 0; -} -public int OnTransferComplete(Handle hRequest, bool bFailure, bool bSuccessful, EHTTPStatusCode eStatusCode) -{ - if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK) - { - delete hRequest; - LogError("Request-Error: %d", eStatusCode); - return 0; - } - - SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnTransferResponse); - return 0; + delete obj; } public void OnMapStart() { char sRequest[256]; - //fucking bitch ass nigger shit was not saying anything about the http response being too large for heap in sourcepawn. instead of - //saying something or throwing an error message the shit just kept failing sillently and it took me fucking 1-2 days before i realized - //its because of the fucking json response being too large for sourcemod heap or something shit. fucking shit. FormatEx(sRequest, sizeof(sRequest), "https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/leaderboard/minified/0"); - Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest); - if (!hRequest || - !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || - !SteamWorks_SetHTTPRequestContextValue(hRequest, 5) || - !SteamWorks_SendHTTPRequest(hRequest)) - { - delete hRequest; - } + + HTTPRequest hRequest = new HTTPRequest(sRequest); + hRequest.Get(OnTransferComplete); } public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2) @@ -100,4 +94,3 @@ public Action Command_topLVL(int client, int args) return Plugin_Handled; } -