Browse Source

ripext

master
gsd 2 weeks ago
parent
commit
fb7b15f674
  1. 107
      ext/sourcepawn-client/Facti13BackendIntegration.sp
  2. 4
      ext/sourcepawn-client/Facti13Reports.sp
  3. 65
      ext/sourcepawn-client/trash

107
ext/sourcepawn-client/Facti13BackendIntegration.sp

@ -1,7 +1,11 @@
#include "core/globals.sp" #include "core/globals.sp"
//#define RIPEXT_SUPPORT #define RIPEXT_SUPPORT
#define STEAMWORKS_SUPPORT //#define STEAMWORKS_SUPPORT
#define DISABLE_JSON
#define DEBUG
#if defined RIPEXT_SUPPORT #if defined RIPEXT_SUPPORT
#include <ripext> #include <ripext>
@ -9,8 +13,11 @@
#endif #endif
#if defined STEAMWORKS_SUPPORT #if defined STEAMWORKS_SUPPORT
//#define SM_INT64_SUPPORTED
//#pragma dynamic 131072
#include <SteamWorks> #include <SteamWorks>
#include <json> #include <ripext>
//#include <json>
#define PLUGIN_VERSION "1.0 (SteamWorks)" #define PLUGIN_VERSION "1.0 (SteamWorks)"
#endif #endif
@ -44,7 +51,12 @@ public OnPluginEnd() {
public void OnJsonRequestComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode) public void OnJsonRequestComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode)
{ {
#if defined DEBUG
LogMessage("OnJsonRequestComplete stage")
#endif
g_updating = false; g_updating = false;
g_lastupdate = GetTime();
if (bFailure) if (bFailure)
{ {
if(g_warned) { if(g_warned) {
@ -79,13 +91,19 @@ public void OnJsonRequestComplete(Handle hRequest, bool bFailure, bool bRequestS
} }
stock void createRequest(const char[] sJsonPayload) { stock void createRequest(const char[] sJsonPayload) {
char sURL[256]; #if defined DEBUG
Format(sURL, sizeof(sURL), "%s/report", g_url); LogMessage("CreateRequest stage")
LogMessage("Use report endpoint: %s", sURL); #endif
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, sURL); //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) if (hRequest == INVALID_HANDLE)
{ {
g_updating = false;
g_lastupdate = GetTime();
LogError("Не удалось создать запрос"); LogError("Не удалось создать запрос");
return; return;
} }
@ -101,13 +119,19 @@ stock void createRequest(const char[] sJsonPayload) {
if (!SteamWorks_SendHTTPRequest(hRequest)) if (!SteamWorks_SendHTTPRequest(hRequest))
{ {
g_updating = false;
g_lastupdate = GetTime();
LogError("Cannot send server info"); LogError("Cannot send server info");
delete hRequest; delete hRequest;
} }
} }
stock void ProcessUpdateStatus() { JSONObject createPayload() {
JSON_Object payload = new JSON_Object(); #if defined DEBUG
LogMessage("CreatePayload");
#endif
JSONObject payload = new JSONObject();
payload.SetBool("status", true); payload.SetBool("status", true);
int player_count = 0; int player_count = 0;
@ -117,12 +141,12 @@ stock void ProcessUpdateStatus() {
GetCurrentMap(map_name, sizeof(map_name)); GetCurrentMap(map_name, sizeof(map_name));
payload.SetString("map_name", map_name); payload.SetString("map_name", map_name);
JSON_Array players = new JSON_Array(); JSONArray players = new JSONArray();
for(int client = 0; client <= MaxClients; client++) { for(int client = 0; client <= MaxClients; client++) {
if (IsValidClient(client)) { if (IsValidClient(client)) {
player_count++; player_count++;
JSON_Object player = new JSON_Object(); JSONObject player = new JSONObject();
/* Name */ /* Name */
char name[64]; char name[64];
GetClientName(client, name, sizeof(name)); GetClientName(client, name, sizeof(name));
@ -165,20 +189,34 @@ stock void ProcessUpdateStatus() {
/* Player team */ /* Player team */
player.SetInt("team", TF2_GetClientTeam(client)); player.SetInt("team", TF2_GetClientTeam(client));
/* push */ /* push */
players.PushObject(player); players.Push(player);
delete player;
} }
} }
payload.SetObject("players", players); payload.Set("players", players);
payload.SetInt("player_count", player_count); 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; //int payload_size = 1024*8;
char payload_str[1024*8]; char payload_str[1024*8];
payload.Encode(payload_str, 1024*8);
delete players; payload.ToString(payload_str, 1024*8);
delete payload; //payload.Encode(payload_str, 1024*8);
//payload.Remove("players");
//json_cleanup_and_delete(players);
//json_cleanup_and_delete(payload);
createRequest(payload_str); createRequest(payload_str);
} }
@ -186,7 +224,11 @@ stock void ProcessUpdateStatus() {
#endif #endif
#if defined RIPEXT_SUPPORT #if defined RIPEXT_SUPPORT
stock HTTPRequest createRequest() { HTTPRequest createRequest() {
#if defined DEBUG
LogMessage("CreateRequest");
#endif
HTTPRequest client = INVALID_HANDLE; HTTPRequest client = INVALID_HANDLE;
if (strlen(g_url)>0) { if (strlen(g_url)>0) {
client = new HTTPRequest(g_url); client = new HTTPRequest(g_url);
@ -198,7 +240,11 @@ stock HTTPRequest createRequest() {
return client; return client;
} }
stock JSONObject createPayload() { JSONObject createPayload() {
#if defined DEBUG
LogMessage("CreatePayload");
#endif
JSONObject payload = new JSONObject(); JSONObject payload = new JSONObject();
payload.SetBool("status", true); payload.SetBool("status", true);
@ -267,13 +313,23 @@ stock JSONObject createPayload() {
return payload; return payload;
} }
stock void ProcessUpdateStatus() { void ProcessUpdateStatus() {
#if defined DEBUG
LogMessage("ProcessUpdateStatus");
#endif
g_updating = true;
JSONObject payload = createPayload(); JSONObject payload = createPayload();
createRequest().Post(payload, Request_Callback); createRequest().Post(payload, Request_Callback);
} }
static void Request_Callback(HTTPResponse response, any value){ void Request_Callback(HTTPResponse response, any value){
#if defined DEBUG
LogMessage("Request Callback: %i", response.Status);
#endif
g_updating = false; g_updating = false;
g_lastupdate = GetTime();
if (response.Status == HTTPStatus_OK){ if (response.Status == HTTPStatus_OK){
if(!g_warned) { if(!g_warned) {
LogMessage("Success send payload, after error"); LogMessage("Success send payload, after error");
@ -291,14 +347,14 @@ static void Request_Callback(HTTPResponse response, any value){
} }
#endif #endif
stock UpdateStatus(){ void UpdateStatus(){
if (!g_setuped) return; if (!g_setuped) return;
if (g_updating) return; if (g_updating) return;
if (GetTime() - g_lastupdate < 5) return; if (GetTime() - g_lastupdate < 5) return;
g_updating = true; //g_updating = true;
ProcessUpdateStatus(); ProcessUpdateStatus();
g_lastupdate = GetTime(); //g_lastupdate = GetTime();
} }
public Action timerCall(Handle:t, any:d) { public Action timerCall(Handle:t, any:d) {
@ -307,7 +363,8 @@ public Action timerCall(Handle:t, any:d) {
} }
public Action TestUpdate(int client, int args){ public Action TestUpdate(int client, int args){
UpdateStatus(); //UpdateStatus();
ProcessUpdateStatus();
ReplyToCommand(client, "OK! Last update: %d", g_lastupdate) ReplyToCommand(client, "OK! Last update: %d", g_lastupdate)
return Plugin_Handled; return Plugin_Handled;
} }

4
ext/sourcepawn-client/Facti13Reports.sp

@ -1,7 +1,7 @@
#include "core/globals.sp" #include "core/globals.sp"
//#define RIPEXT_SUPPORT #define RIPEXT_SUPPORT
#define STEAMWORKS_SUPPORT //#define STEAMWORKS_SUPPORT
#if defined RIPEXT_SUPPORT #if defined RIPEXT_SUPPORT
#include <ripext> #include <ripext>

65
ext/sourcepawn-client/trash

@ -0,0 +1,65 @@
JSON_Object payload = new JSON_Object();
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);
JSON_Array players = new JSON_Array();
for(int client = 0; client <= MaxClients; client++) {
if (IsValidClient(client)) {
player_count++;
JSON_Object player = new JSON_Object();
/* 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.PushObject(player);
json_cleanup_and_delete(player);
}
}
payload.SetObject("players", players);
payload.SetInt("player_count", player_count);
Loading…
Cancel
Save