moving plugins from steamworks to ripext with sourcemod 1.13 upgrade
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <SteamWorks>
|
#include <ripext>
|
||||||
#include <json>
|
|
||||||
#include <ccc>
|
#include <ccc>
|
||||||
#include <cstrike>
|
#include <cstrike>
|
||||||
#include <unloze_playtime>
|
#include <unloze_playtime>
|
||||||
@@ -140,7 +139,7 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
{
|
{
|
||||||
if(!IsClientAuthorized(client) || IsClientSourceTV(client))
|
if(!IsClientAuthorized(client) || IsClientSourceTV(client))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (IsFakeClient(client))
|
if (IsFakeClient(client))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -207,48 +206,29 @@ public void check_client_racetimer_rank(int client)
|
|||||||
char sRequest[256];
|
char sRequest[256];
|
||||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||||
FormatEx(sRequest, sizeof(sRequest), "https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/player/%s", 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);
|
HTTPRequest hRequest = new HTTPRequest(sRequest);
|
||||||
if (!hRequest ||
|
hRequest.Get(OnTransferComplete, GetClientSerial(client));
|
||||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
|
|
||||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, GetClientSerial(client)) ||
|
|
||||||
!SteamWorks_SendHTTPRequest(hRequest))
|
|
||||||
{
|
|
||||||
delete hRequest;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int OnTransferComplete(Handle hRequest, bool bFailure, bool bSuccessful, EHTTPStatusCode eStatusCode, int iSerial)
|
public void OnTransferComplete(HTTPResponse response, any iSerial)
|
||||||
{
|
{
|
||||||
int client = GetClientFromSerial(iSerial);
|
int client = GetClientFromSerial(iSerial);
|
||||||
if (!client) //Player disconnected.
|
if (!client) //Player disconnected.
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (response.Status != HTTPStatus_OK || response.Data == null)
|
||||||
{
|
{
|
||||||
delete hRequest;
|
LogError("Request-Error: %d", response.Status);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
JSONObject obj = view_as<JSONObject>(response.Data);
|
||||||
{
|
|
||||||
delete hRequest;
|
|
||||||
LogError("Request-Error: %d", eStatusCode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnTransferResponse, iSerial);
|
int I_player_points = -1; //if no endpoint for steamID default value is -1
|
||||||
return 0;
|
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)
|
if (I_player_points < 1000)
|
||||||
{
|
{
|
||||||
I_player_points = 1000; //setting level 1
|
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);
|
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)
|
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);
|
Format(tag, sizeof(tag), "\x07%s[L\x07%sV\x07%sL %s] ", hexadecimals, hexadecimals2, hexadecimals3, coloured_numbers);
|
||||||
CCC_SetTag(client, tag);
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <SteamWorks>
|
#include <ripext>
|
||||||
#include <json>
|
|
||||||
#include <cstrike>
|
#include <cstrike>
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
@@ -8,7 +7,7 @@ public Plugin myinfo =
|
|||||||
name = "Toplvl",
|
name = "Toplvl",
|
||||||
author = "jenz",
|
author = "jenz",
|
||||||
description = "show toplvl for racetimer",
|
description = "show toplvl for racetimer",
|
||||||
version = "1.0",
|
version = "1.1",
|
||||||
url = ""
|
url = ""
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -20,57 +19,52 @@ public void OnPluginStart()
|
|||||||
OnMapStart();
|
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;
|
int counter = 0;
|
||||||
while (counter < 100)
|
while (counter < 100)
|
||||||
{
|
{
|
||||||
char s_counter[3];
|
char s_counter[4];
|
||||||
IntToString(counter, s_counter, sizeof(s_counter))
|
IntToString(counter, s_counter, sizeof(s_counter));
|
||||||
JSON_Object position_obj = obj.GetObject(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");
|
int I_player_points = position_obj.GetInt("PlayerPoints");
|
||||||
|
|
||||||
char player_name[64];
|
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);
|
Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "%s LVL: %i", player_name, I_player_points/1000);
|
||||||
|
|
||||||
|
delete position_obj;
|
||||||
counter++;
|
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)
|
delete obj;
|
||||||
{
|
|
||||||
if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
|
||||||
{
|
|
||||||
delete hRequest;
|
|
||||||
LogError("Request-Error: %d", eStatusCode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnTransferResponse);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
{
|
{
|
||||||
char sRequest[256];
|
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");
|
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 ||
|
HTTPRequest hRequest = new HTTPRequest(sRequest);
|
||||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
|
hRequest.Get(OnTransferComplete);
|
||||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, 5) ||
|
|
||||||
!SteamWorks_SendHTTPRequest(hRequest))
|
|
||||||
{
|
|
||||||
delete hRequest;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
|
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;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user