forked from UNLOZE/sm-plugins
Make ForumIntegration request username, and thus use this in listwinners to make the whole thing async.
Rework listwinners (reward) plugin so now it's async and simple. go back to ded
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
/* STRINGS */
|
||||
char G_sGroup[MAXPLAYERS+1][64];
|
||||
char G_sName[MAXPLAYERS+1][32];
|
||||
|
||||
/* BOOLS */
|
||||
bool G_bPreAdminChecked[MAXPLAYERS+1];
|
||||
@@ -25,10 +26,10 @@ bool G_bResponsePassed[MAXPLAYERS+1];
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "UNLOZE Forum Integration",
|
||||
author = ".George & zaCade (Original by Botox)",
|
||||
name = "UNLOZE Forum Integration",
|
||||
author = ".George & zaCade (Original by Botox)",
|
||||
description = "Handles forum access ingame",
|
||||
version = "1.2.1"
|
||||
version = "1.2.1"
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -58,6 +59,7 @@ public void OnPluginStart()
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
CreateNative("AsyncHasSteamIDReservedSlot", Native_AsyncHasSteamIDReservedSlot);
|
||||
CreateNative("GetClientForumName", Native_GetClientForumName);
|
||||
|
||||
RegPluginLibrary("UNLOZE_ForumIntegration");
|
||||
|
||||
@@ -109,6 +111,7 @@ public void OnClientDisconnect(int client)
|
||||
G_bResponsePassed[client] = false;
|
||||
|
||||
G_sGroup[client][0] = 0;
|
||||
G_sName[client][0] = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -118,21 +121,21 @@ public void OnClientAuthorized(int client, const char[] sSteamID32)
|
||||
{
|
||||
if (IsFakeClient(client))
|
||||
return;
|
||||
char sSteamID64[32];
|
||||
SteamID32toSteamID64(sSteamID32, sSteamID64, sizeof(sSteamID64));
|
||||
char sSteamID64[32];
|
||||
SteamID32toSteamID64(sSteamID32, sSteamID64, sizeof(sSteamID64));
|
||||
|
||||
char sRequest[256];
|
||||
FormatEx(sRequest, sizeof(sRequest), "https://unloze.com/api/private_api.php?api_key=%s&steam_id=%s", UNLOZE_APIKEY, sSteamID64);
|
||||
char sRequest[256];
|
||||
FormatEx(sRequest, sizeof(sRequest), "https://unloze.com/api/private_api.php?api_key=%s&steam_id=%s", UNLOZE_APIKEY, sSteamID64);
|
||||
|
||||
int iSerial = GetClientSerial(client);
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnClientAuthorized_OnTransferComplete) ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, iSerial) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
delete hRequest;
|
||||
}
|
||||
int iSerial = GetClientSerial(client);
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnClientAuthorized_OnTransferComplete) ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, iSerial) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
delete hRequest;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -147,7 +150,7 @@ public int OnClientAuthorized_OnTransferComplete(Handle hRequest, bool bFailure,
|
||||
delete hRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (bFailure || !bSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
||||
{
|
||||
G_bResponseFailed[client] = true;
|
||||
@@ -158,7 +161,7 @@ public int OnClientAuthorized_OnTransferComplete(Handle hRequest, bool bFailure,
|
||||
delete hRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SteamWorks_GetHTTPResponseBodyCallback(hRequest, OnClientAuthorized_OnTransferResponse, iSerial);
|
||||
}
|
||||
|
||||
@@ -167,6 +170,8 @@ public int OnClientAuthorized_OnTransferComplete(Handle hRequest, bool bFailure,
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public int OnClientAuthorized_OnTransferResponse(char[] sData, int iSerial)
|
||||
{
|
||||
char splitData[2][32];
|
||||
|
||||
int client = GetClientFromSerial(iSerial);
|
||||
|
||||
if (!client) //Player disconnected.
|
||||
@@ -175,13 +180,23 @@ public int OnClientAuthorized_OnTransferResponse(char[] sData, int iSerial)
|
||||
TrimString(sData);
|
||||
StripQuotes(sData);
|
||||
|
||||
LogMessage("reached sData with status 200: %s", sData);
|
||||
strcopy(G_sGroup[client], sizeof(G_sGroup[]), sData);
|
||||
LogMessage("reached sData with status 200: %s", sData);
|
||||
ExplodeString(sData, "\r\n", splitData, 2, sizeof(splitData[]));
|
||||
|
||||
G_bResponsePassed[client] = true;
|
||||
if(strlen(splitData[1]) > 0)
|
||||
strcopy(G_sName[client], sizeof(G_sName[]), splitData[1]);
|
||||
|
||||
if (G_bPreAdminChecked[client])
|
||||
NotifyPostAdminCheck(client);
|
||||
if(!StrEqual(splitData[0], "NOGROUP"))
|
||||
{
|
||||
strcopy(G_sGroup[client], sizeof(G_sGroup[]), splitData[0]);
|
||||
|
||||
G_bResponsePassed[client] = true;
|
||||
|
||||
if (G_bPreAdminChecked[client])
|
||||
NotifyPostAdminCheck(client);
|
||||
}
|
||||
else
|
||||
G_bResponseFailed[client] = true; //users with just a forum name did not pass the VIP check! so the response "failed" (but we store their forum name for later!)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -238,6 +253,15 @@ stock void ApplyGroupFlags(int client)
|
||||
}
|
||||
}
|
||||
|
||||
public int Native_GetClientForumName(Handle plugin, int numParams)
|
||||
{
|
||||
int len = GetNativeCell(2);
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
SetNativeString(2, G_sName[client], len+1);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -310,11 +334,15 @@ public int Native_AsyncHasSteamIDReservedSlot_OnTransferResponse(char[] sData, D
|
||||
any data;
|
||||
data = hDataPack.ReadCell();
|
||||
|
||||
static char splitData[32];
|
||||
|
||||
TrimString(sData);
|
||||
StripQuotes(sData);
|
||||
|
||||
SplitString(sData, "\r\n", splitData, sizeof(splitData));
|
||||
|
||||
int result;
|
||||
if (StrEqual(sData, "Game-Donator", false))
|
||||
if (StrEqual(splitData, "Game-Donator", false))
|
||||
result = 1;
|
||||
else
|
||||
result = 0;
|
||||
|
||||
Reference in New Issue
Block a user