Browse Source

ripext http only

master
gsd 2 weeks ago
parent
commit
5aac810bbb
  1. 209
      ext/sourcepawn-client/Facti13BackendIntegration.sp
  2. 116
      ext/sourcepawn-client/Facti13Reports.sp

209
ext/sourcepawn-client/Facti13BackendIntegration.sp

@ -1,24 +1,14 @@
#include "core/globals.sp"
#define RIPEXT_SUPPORT
//#define STEAMWORKS_SUPPORT
//#define DEBUG
#define REPLACE_HTTPS_TO_HTTP
#define DISABLE_JSON
#define DEBUG
#if defined RIPEXT_SUPPORT
#include <ripext>
#define PLUGIN_VERSION "1.0 (RipExt)"
#endif
#if defined STEAMWORKS_SUPPORT
//#define SM_INT64_SUPPORTED
//#pragma dynamic 131072
#include <SteamWorks>
#include <ripext>
//#include <json>
#define PLUGIN_VERSION "1.0 (SteamWorks)"
#if defined REPLACE_HTTPS_TO_HTTP
#define PLUGIN_VERSION "1.0 (RipExt) - HTTP ONLY"
#else
#define PLUGIN_VERSION "1.0 (RipExt)"
#endif
public Plugin myinfo = {
@ -47,183 +37,6 @@ public OnPluginEnd() {
}
}
#if defined STEAMWORKS_SUPPORT
public void OnJsonRequestComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode)
{
#if defined DEBUG
LogMessage("OnJsonRequestComplete stage")
#endif
g_updating = false;
g_lastupdate = GetTime();
if (bFailure)
{
if(g_warned) {
LogMessage("Failed response! Code: %i", eStatusCode);
g_warned = false;
}
delete hRequest;
return;
}
if (!bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
{
if(g_warned) {
LogMessage("Failed response! Code: %i", eStatusCode);
g_warned = false;
}
delete hRequest;
return;
}
if (eStatusCode == k_EHTTPStatusCode200OK) {
if(!g_warned) {
LogMessage("Success send payload, after error");
g_warned = true;
}
}
delete hRequest;
return;
}
stock void createRequest(const char[] sJsonPayload) {
#if defined DEBUG
LogMessage("CreateRequest stage")
#endif
//char sURL[256];
//Format(sURL, sizeof(sURL), "%s/report", g_url);
LogMessage("Use report endpoint: %s", g_url);
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, g_url);
if (hRequest == INVALID_HANDLE)
{
g_updating = false;
g_lastupdate = GetTime();
LogError("Не удалось создать запрос");
return;
}
SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json; charset=UTF-8", sJsonPayload, strlen(sJsonPayload));
if (strlen(g_cookie) > 0)
{
SteamWorks_SetHTTPRequestHeaderValue(hRequest, "Cookie", g_cookie);
}
SteamWorks_SetHTTPCallbacks(hRequest, OnJsonRequestComplete);
if (!SteamWorks_SendHTTPRequest(hRequest))
{
g_updating = false;
g_lastupdate = GetTime();
LogError("Cannot send server info");
delete hRequest;
}
}
JSONObject createPayload() {
#if defined DEBUG
LogMessage("CreatePayload");
#endif
JSONObject payload = new JSONObject();
payload.SetBool("status", true);
int player_count = 0;
payload.SetInt("max_players", MaxClients);
char map_name[128];
GetCurrentMap(map_name, sizeof(map_name));
payload.SetString("map_name", map_name);
JSONArray players = new JSONArray();
for(int client = 0; client <= MaxClients; client++) {
if (IsValidClient(client)) {
player_count++;
JSONObject player = new JSONObject();
/* Name */
char name[64];
GetClientName(client, name, sizeof(name));
player.SetString("name", name);
/* Score */
player.SetInt("score", GetClientFrags(client));
player.SetInt("deads", GetClientDeaths(client));
/* Duration */
char duration[16];
int ct = RoundFloat(GetClientTime(client));
int h = ct / 3600;
int m = ct % 3600 / 60;
int s = ct % 60;
Format(duration, sizeof(duration), "%02d:%02d:%02d", h, m, s);
player.SetString("duration", duration);
/* Id */
player.SetInt("id", GetClientUserId(client));
/* Ip */
char ip[32];
GetClientIP(client, ip, sizeof(ip), false);
player.SetString("ip", ip);
/* Loss */
player.SetInt("loss",RoundFloat(GetClientAvgLoss(client, NetFlow_Both)*1000.0));
/* Ping */
player.SetInt("ping",RoundFloat(GetClientLatency(client, NetFlow_Both)*1000.0));
/* State */
player.SetString("state", "active")
/* Steam 2 так надо, не надо спрашивать почему*/
char steam2[32];
GetClientAuthId(client, AuthId_Steam3, steam2, sizeof(steam2));
player.SetString("steam2", steam2);
/* Position on map */
float pos[3];
GetClientAbsOrigin(client, pos);
player.SetFloat("pos_x", pos[0]);
player.SetFloat("pos_y", pos[1]);
player.SetFloat("pos_z", pos[2]);
/* Player class */
player.SetInt("clz", TF2_GetPlayerClass(client));
/* Player team */
player.SetInt("team", TF2_GetClientTeam(client));
/* push */
players.Push(player);
}
}
payload.Set("players", players);
payload.SetInt("player_count", player_count);
return payload;
}
stock void ProcessUpdateStatus() {
g_updating = true;
#if defined DEBUG
LogMessage("ProcessUpdateStatus stage")
#endif
JSONObject payload = createPayload();
//int payload_size = 1024*8;
char payload_str[1024*8];
payload.ToString(payload_str, 1024*8);
//payload.Encode(payload_str, 1024*8);
//payload.Remove("players");
//json_cleanup_and_delete(players);
//json_cleanup_and_delete(payload);
createRequest(payload_str);
}
#endif
#if defined RIPEXT_SUPPORT
HTTPRequest createRequest() {
#if defined DEBUG
LogMessage("CreateRequest");
@ -231,7 +44,14 @@ HTTPRequest createRequest() {
HTTPRequest client = INVALID_HANDLE;
if (strlen(g_url)>0) {
client = new HTTPRequest(g_url);
char sURL[128];
strcopy(sURL, 128, g_url);
#if defined REPLACE_HTTPS_TO_HTTP
ReplaceString(sURL, 128, "https://", "http://")
#endif
client = new HTTPRequest(sURL);
client.SetHeader("Cookie", g_cookie);
client.Timeout = 3;
} else {
@ -345,7 +165,6 @@ void Request_Callback(HTTPResponse response, any value){
return;
}
}
#endif
void UpdateStatus(){
if (!g_setuped) return;

116
ext/sourcepawn-client/Facti13Reports.sp

@ -1,19 +1,14 @@
#include "core/globals.sp"
#define RIPEXT_SUPPORT
//#define STEAMWORKS_SUPPORT
#if defined RIPEXT_SUPPORT
#include <ripext>
#endif
#define REPLACE_HTTPS_TO_HTTP
#if defined STEAMWORKS_SUPPORT
#include <SteamWorks>
#include <json>
#if defined REPLACE_HTTPS_TO_HTTP
#define PLUGIN_VERSION "1.0 (RipExt) - HTTP ONLY"
#else
#define PLUGIN_VERSION "1.0 (RipExt)"
#endif
#define PLUGIN_VERSION "1.0"
public Plugin myinfo = {
name = "Facti13 Reports",
author = "gsd",
@ -110,107 +105,19 @@ public void OnClientPutInServer(int cid){
g_clients_reported_uid[cid] = -1;
}
#if defined STEAMWORKS_SUPPORT
stock void createRequest(const char[] sJsonPayload, int uid) {
char sURL[256];
Format(sURL, sizeof(sURL), "%s/report", g_url);
LogMessage("Use report endpoint: %s", sURL);
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL);
if (hRequest == INVALID_HANDLE)
{
LogError("Не удалось создать запрос");
return;
}
SteamWorks_SetHTTPRequestContextValue(hRequest, uid);
SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json; charset=UTF-8", sJsonPayload, strlen(sJsonPayload));
if (strlen(g_cookie) > 0)
{
SteamWorks_SetHTTPRequestHeaderValue(hRequest, "Cookie", g_cookie);
}
SteamWorks_SetHTTPCallbacks(hRequest, OnJsonRequestComplete);
if (!SteamWorks_SendHTTPRequest(hRequest))
{
LogError("Cannot send report");
delete hRequest;
}
}
public void OnJsonRequestComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, any value)
{
int cid_author = GetClientOfUserId(value);
if (bFailure)
{
OnClientPutInServer(cid_author);
PrintToChat(cid_author, "РЕПОРТ НЕ БЫЛ ДОСТАВЛЕН, ПОВТОРИ ПОПЫТКУ ПОЗЖЕ");
LogError("[OnJsonRequestComplete] pizdec");
delete hRequest;
return;
}
if (!bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
{
OnClientPutInServer(cid_author);
PrintToChat(cid_author, "РЕПОРТ НЕ БЫЛ ДОСТАВЛЕН, ПОВТОРИ ПОПЫТКУ ПОЗЖЕ");
LogError("[OnJsonRequestComplete] return status code: %d", eStatusCode);
delete hRequest;
return;
}
if (eStatusCode == k_EHTTPStatusCode200OK) {
PrintToChat(cid_author, "Репорт отправлен!");
}
delete hRequest;
return;
}
static void SendReport(const char[] reason, int uid){
int cid_author = GetClientOfUserId(uid);
int cid_reported = GetClientOfUserId(g_clients_reported_uid[cid_author]);
LogMessage("author: %N, reported: %N", cid_author, cid_reported);
char author_steam64[64];
char reported_steam64[64];
GetClientAuthId(cid_author, AuthId_SteamID64, author_steam64, 64);
if (cid_reported != 0)
GetClientAuthId(cid_reported, AuthId_SteamID64, reported_steam64, 64);
JSON_Object payload_obj = new JSON_Object();
payload_obj.SetString("author_steam64", author_steam64);
payload_obj.SetString("reason", reason);
if (cid_reported != 0)
payload_obj.SetString("reported_steam64", reported_steam64);
char payload_str[1024];
payload_obj.Encode(payload_str, 1024);
delete payload_obj;
createRequest(payload_str, uid);
////////////////////////////////////////////////////////////////
g_clients_cooldown[cid_author] = GetTime();
g_clients_reported_uid[cid_author] = -1;
g_clients_reasons_wait[cid_author] = false;
////////////////////////////////////////////////////////////////
}
#endif
#if defined RIPEXT_SUPPORT
//RIPEXT START
stock HTTPRequest createRequest() {
HTTPRequest client = INVALID_HANDLE;
char url[256];
Format(url, sizeof(url), "%s/report", g_url);
LogMessage("Use report endpoint: %s", url);
if (strlen(url)>0) {
#if defined REPLACE_HTTPS_TO_HTTP
ReplaceString(url, 128, "https://", "http://");
#endif
client = new HTTPRequest(url);
client.SetHeader("Cookie", g_cookie);
client.Timeout = 3;
@ -262,7 +169,6 @@ static void Report_Callback(HTTPResponse response, any value){
}
}
//RIPEXT END
#endif
public Action COMMAND_ClientReport(int cid, int args){

Loading…
Cancel
Save