moving plugins from steamworks to ripext with sourcemod 1.13 upgrade

This commit is contained in:
jenz
2026-09-22 01:49:53 +02:00
parent 74e72bfdac
commit 0eb42312fc
2 changed files with 47 additions and 111 deletions
+30 -37
View File
@@ -1,6 +1,5 @@
#include <sourcemod>
#include <SteamWorks>
#include <json>
#include <ripext>
#include <cstrike>
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<JSONObject>(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<JSONObject>(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;
}