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:
@@ -1,5 +1,5 @@
|
||||
#include <sourcemod>
|
||||
#include <zombiereloaded>
|
||||
#include <unloze>
|
||||
#include <cstrike>
|
||||
#include <sdktools>
|
||||
|
||||
@@ -12,7 +12,7 @@ char g_directory_path[128];
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Unloze_VIP_Reward",
|
||||
author = "Neon + WASD",
|
||||
author = "Neon + WASD + ??????????",
|
||||
description = "",
|
||||
version = "1.1",
|
||||
url = "https://steamcommunity.com/id/n3ontm"
|
||||
@@ -39,8 +39,19 @@ public void OnPluginStart()
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_Winners(int iClient, int iArgs)
|
||||
{
|
||||
static char sSID[64];
|
||||
static char sName[64];
|
||||
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsValidWinner(client))
|
||||
{
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
GetForumNameFormat(client, sName, sizeof(sName));
|
||||
PrintToConsole(iClient, "%s --- %N --- %s", sSID, client, sName);
|
||||
}
|
||||
}
|
||||
|
||||
CheckMYSQL(iClient);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
@@ -65,240 +76,44 @@ public Action Event_Round_End(Handle event, const char[] name, bool dontBroadcas
|
||||
Handle file_handle = OpenFile(file_path, "a", false);
|
||||
|
||||
WriteFileLine(file_handle, "Current score: (CT) : %d - (T): %d", ct_score, t_score);
|
||||
CheckMYSQL_2(file_handle);
|
||||
|
||||
static char sSID[64];
|
||||
static char sName[64];
|
||||
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(IsValidWinner(client))
|
||||
{
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
GetForumNameFormat(client, sName, sizeof(sName));
|
||||
WriteFileLine(file_handle, "%s --- %N --- %s", sSID, client, sName);
|
||||
}
|
||||
}
|
||||
|
||||
WriteFileLine(file_handle, "\n");
|
||||
CloseHandle(file_handle);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Saves all winners into a textfile located in sourcemod/data/events/.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
CheckMYSQL_2(Handle file_handle)
|
||||
GetForumNameFormat(int client, char[] sName, int sNameLen)
|
||||
{
|
||||
char error[255];
|
||||
Database db;
|
||||
|
||||
if (SQL_CheckConfig("xenforo"))
|
||||
{
|
||||
db = SQL_Connect("xenforo", true, error, sizeof(error));
|
||||
}
|
||||
|
||||
if (db == null)
|
||||
{
|
||||
LogError("Could not connect to database: %s", error);
|
||||
delete db;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
if (IsPlayerAlive(client))
|
||||
{
|
||||
if (GetClientTeam(client) == CS_TEAM_CT)
|
||||
{
|
||||
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client))
|
||||
{
|
||||
char sSID[64];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
|
||||
char sQuery[255];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user_field_value WHERE field_value = '%s'", sSID);
|
||||
DBResultSet rs;
|
||||
|
||||
int iUserID;
|
||||
|
||||
if ((rs = SQL_Query(db, sQuery)) == null)
|
||||
{
|
||||
delete rs;
|
||||
delete db;
|
||||
LogError("Database Error: %s", error);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!(rs.RowCount > 0))
|
||||
{
|
||||
char sSID64[64];
|
||||
GetClientAuthId(client, AuthId_SteamID64, sSID64, sizeof(sSID64));
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user_external_auth WHERE provider_key = '%s'", sSID64);
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
if (!(rs.RowCount > 0))
|
||||
{
|
||||
WriteFileLine(file_handle, "%s --- %N --- NO FORUM ACCOUNT", sSID, client);
|
||||
delete rs;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int iField;
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("user_id", iField);
|
||||
iUserID = rs.FetchInt(iField);
|
||||
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user WHERE user_id = '%d'", iUserID);
|
||||
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("username", iField);
|
||||
|
||||
char sUsername[255];
|
||||
rs.FetchString(iField, sUsername, sizeof(sUsername));
|
||||
WriteFileLine(file_handle, "%s --- %N --- FORUM NAME: %s", sSID, client, sUsername);
|
||||
delete rs;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
int iField;
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("user_id", iField);
|
||||
iUserID = rs.FetchInt(iField);
|
||||
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user WHERE user_id = '%d'", iUserID);
|
||||
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("username", iField);
|
||||
|
||||
char sUsername[255];
|
||||
rs.FetchString(iField, sUsername, sizeof(sUsername));
|
||||
|
||||
WriteFileLine(file_handle, "%s --- %N --- FORUM NAME: %s", sSID, client, sUsername);
|
||||
|
||||
delete rs;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete db;
|
||||
char sForumName[64];
|
||||
GetClientForumName(client, sForumName, sizeof(sForumName));
|
||||
|
||||
if(strlen(sForumName) > 0)
|
||||
Format(sName, sNameLen, "FORUM NAME: %s", sForumName);
|
||||
else
|
||||
Format(sName, sNameLen, "NO FORUM ACCOUNT");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Prints all winners to the caller of sm_listwinners.
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
CheckMYSQL(int iCaller)
|
||||
stock bool IsValidWinner(int client)
|
||||
{
|
||||
if (iCaller == 0)
|
||||
return;
|
||||
|
||||
char error[255];
|
||||
Database db;
|
||||
|
||||
if (SQL_CheckConfig("xenforo"))
|
||||
{
|
||||
db = SQL_Connect("xenforo", true, error, sizeof(error));
|
||||
}
|
||||
|
||||
if (db == null)
|
||||
{
|
||||
LogError("Could not connect to database: %s", error);
|
||||
delete db;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
if (IsPlayerAlive(client))
|
||||
{
|
||||
if (GetClientTeam(client) == CS_TEAM_CT)
|
||||
{
|
||||
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client))
|
||||
{
|
||||
char sSID[64];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
|
||||
char sQuery[255];
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user_field_value WHERE field_value = '%s'", sSID);
|
||||
DBResultSet rs;
|
||||
|
||||
int iUserID;
|
||||
|
||||
if ((rs = SQL_Query(db, sQuery)) == null)
|
||||
{
|
||||
delete rs;
|
||||
delete db;
|
||||
LogError("Database Error: %s", error);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!(rs.RowCount > 0))
|
||||
{
|
||||
char sSID64[64];
|
||||
GetClientAuthId(client, AuthId_SteamID64, sSID64, sizeof(sSID64));
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user_external_auth WHERE provider_key = '%s'", sSID64);
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
if (!(rs.RowCount > 0))
|
||||
{
|
||||
PrintToConsole(iCaller, "%s --- %N --- NO FORUM ACCOUNT", sSID, client);
|
||||
delete rs;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int iField;
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("user_id", iField);
|
||||
iUserID = rs.FetchInt(iField);
|
||||
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user WHERE user_id = '%d'", iUserID);
|
||||
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("username", iField);
|
||||
|
||||
char sUsername[255];
|
||||
rs.FetchString(iField, sUsername, sizeof(sUsername));
|
||||
PrintToConsole(iCaller, "%s --- %N --- FORUM NAME: %s", sSID, client, sUsername);
|
||||
delete rs;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
int iField;
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("user_id", iField);
|
||||
iUserID = rs.FetchInt(iField);
|
||||
|
||||
Format(sQuery, sizeof(sQuery), "SELECT * FROM xf_user WHERE user_id = '%d'", iUserID);
|
||||
|
||||
rs = SQL_Query(db, sQuery);
|
||||
|
||||
rs.FetchRow();
|
||||
rs.FieldNameToNum("username", iField);
|
||||
|
||||
char sUsername[255];
|
||||
rs.FetchString(iField, sUsername, sizeof(sUsername));
|
||||
|
||||
PrintToConsole(iCaller, "%s --- %N --- FORUM NAME: %s", sSID, client, sUsername);
|
||||
|
||||
delete rs;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete db;
|
||||
if (IsValidClient(client, true) && IsPlayerAlive(client) && GetClientTeam(client) == CS_TEAM_CT && !IsClientSourceTV(client))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user