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
+15 -72
View File
@@ -1,6 +1,5 @@
#include <sourcemod>
#include <SteamWorks>
#include <json>
#include <ripext>
#include <ccc>
#include <cstrike>
#include <unloze_playtime>
@@ -208,47 +207,28 @@ public void check_client_racetimer_rank(int client)
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<JSONObject>(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;
}
+29 -36
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;
}