PHP Code:
#include <sourcemod>
new Handle:hDatabase = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "Authentication",
author = " ",
description = "Client Authentication",
version = "1.0.0.0",
url = " "
};
public OnPluginStart()
{
StartSQL()
}
public OnClientAuthorized(client)
{
decl String:auth[32];
GetClientAuthString(client, auth, sizeof(auth));
CheckSteamID(client, auth)
}
public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
LogError("Database failure: %s", error);
}
else
{
hDatabase = hndl;
}
}
public T_CheckSteamID(Handle:owner, Handle:hndl, const String:error[], any:client)
{
/* Make sure the client didn't disconnect while the thread was running */
if (!IsClientConnected(client))
{
return;
}
if (hndl == INVALID_HANDLE)
{
LogError("Query failed! %s", error);
KickClient(client, "Authorization failed");
}
else if (!SQL_GetRowCount(hndl))
{
KickClient(client, "You are not a member");
}
}
StartSQL()
{
SQL_TConnect(GotDatabase);
}
CheckSteamID(userid, const String:auth[])
{
decl String:query[255];
Format(query, sizeof(query), "SELECT steamid FROM cpay_users WHERE steamid = '%s'", auth);
SQL_TQuery(hDatabase, T_CheckSteamID, query, userid)
}