VIP_Reward: the code is currently absolutely garbage... Whoever re-writes this for XF2, make sure to rewrite the mysql queries asynchronous!!!!!! The forum runs on a different machine than the gameserver now, so the current synchronized queries are a terrible practice (well they have always have been a terrible practice, but when this was created like 3 years ago I didnt know any better). Otherwise the server might just freeze from time to time.
This commit is contained in:
parent
5e8be5eace
commit
280dc0ca67
312
VIP_Reward/scripting/VIP_Reward.sp
Normal file
312
VIP_Reward/scripting/VIP_Reward.sp
Normal file
@ -0,0 +1,312 @@
|
|||||||
|
#include <sourcemod>
|
||||||
|
#include <zombiereloaded>
|
||||||
|
#include <cstrike>
|
||||||
|
#include <sdktools>
|
||||||
|
|
||||||
|
ConVar g_cvarEventIsOn = null;
|
||||||
|
char g_directory_path[128];
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public Plugin myinfo =
|
||||||
|
{
|
||||||
|
name = "Unloze_VIP_Reward",
|
||||||
|
author = "Neon + WASD",
|
||||||
|
description = "",
|
||||||
|
version = "1.1",
|
||||||
|
url = "https://steamcommunity.com/id/n3ontm"
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void OnPluginStart()
|
||||||
|
{
|
||||||
|
RegAdminCmd("sm_listwinners", Command_Winners, ADMFLAG_GENERIC);
|
||||||
|
g_cvarEventIsOn = CreateConVar("sv_event_is_on", "0", "Cvar decides whether event mode is on or not.", _);
|
||||||
|
HookEvent("round_end", Event_Round_End)
|
||||||
|
|
||||||
|
BuildPath(Path_SM, g_directory_path, sizeof(g_directory_path), "data/events/");
|
||||||
|
|
||||||
|
if (!DirExists(g_directory_path, false)) {
|
||||||
|
CreateDirectory(g_directory_path, 457, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public Action Command_Winners(int iClient, int iArgs)
|
||||||
|
{
|
||||||
|
|
||||||
|
CheckMYSQL(iClient);
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public Action Event_Round_End(Handle event, const char[] name, bool dontBroadcast)
|
||||||
|
{
|
||||||
|
if (g_cvarEventIsOn.IntValue == 1 && GetEventInt(event, "winner") == CS_TEAM_CT) {
|
||||||
|
int t_score = GetTeamScore(CS_TEAM_T);
|
||||||
|
int ct_score = GetTeamScore(CS_TEAM_CT);
|
||||||
|
|
||||||
|
char date[20];
|
||||||
|
FormatTime(date, sizeof(date), "%Y%m%d");
|
||||||
|
|
||||||
|
char map[90];
|
||||||
|
GetCurrentMap(map, sizeof(map));
|
||||||
|
|
||||||
|
char file_path[256];
|
||||||
|
Format(file_path, sizeof(file_path), "%s%s-%s.txt", g_directory_path, date, map);
|
||||||
|
|
||||||
|
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);
|
||||||
|
WriteFileLine(file_handle, "\n");
|
||||||
|
CloseHandle(file_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Saves all winners into a textfile located in sourcemod/data/events/.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
CheckMYSQL_2(Handle file_handle)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose: Prints all winners to the caller of sm_listwinners.
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
CheckMYSQL(int iCaller)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
stock int IsValidClient(int client, bool nobots = true)
|
||||||
|
{
|
||||||
|
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return IsClientInGame(client);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user