sm-plugins/track_player.sp

75 lines
1.7 KiB
SourcePawn

/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#define AI_VERSION "1.0"
new Handle:dbcon = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "Autoinvite Tracking",
author = "Chefe",
description = "Tracks players for AI",
version = AI_VERSION,
url = "www.chefgaming.de"
}
public OnPluginStart()
{
SQL_TConnect(DBInit, "default");
}
public DBInit(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
LogError("[AI] Database connection failed: %s", error);
SetFailState("Unable to connect to database, look for more infos in the error logs!");
return;
}
dbcon = hndl;
}
public OnClientAuthorized(client, const String:auth[])
{
if (strcmp(auth, "BOT", false) != 0 && dbcon != INVALID_HANDLE)
{
new String:sqlstring[255];
Format(sqlstring, sizeof(sqlstring), "SELECT id FROM autoinvite_player WHERE steamid = '%s'", auth);
SQL_TQuery(dbcon, InitDBCheck1, sqlstring, client);
}
}
public InitDBCheck1(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE || strlen(error) > 0)
{
LogError("AI Query error: %s", error);
return;
}
if (IsClientConnected(data))
{
if (SQL_GetRowCount(hndl) == 0)
{
new String:auth[100];
GetClientAuthString(data, auth, sizeof(auth));
new String:createsql[250];
Format(createsql, sizeof(createsql), "INSERT INTO autoinvite_player(steamid) VALUES ('%s')", auth);
SQL_TQuery(dbcon, EmptyResultSet, createsql);
}
}
}
public EmptyResultSet(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE || strlen(error) > 0)
{
LogError("LP Query error: %s", error);
return;
}
}