Hi,
I need help in creating a plugin. I am not a dev so anything that you ask me to do from a dev perspective will go over my head !
I am in particular looking at a plugin that will check if a connecting player STEAMID is in a DB and if not it disconnects him with a message. If the player's STEAMID is in DB it will further check if his subscription validity date is not expired (when I add the player on DB it will have date column with the "subscription valid till" date).So if the current date is beyond this expiry date it will again disconnect the player and show the message that his access is expired.
I did come across this post,
https://forums.alliedmods.net/showthread.php?t=280933 I guess the coding is in bits and pieces.
Your plugin listed here is on same line. Would it be possible to guide me in getting this done correctly ?
I tried doing some scripting with the available scripts (this post and the post I have linked to) & my very very limited knowledge of Sourcepawn ; I have and reached here
PHP Code:
#pragma tabsize 0
#include <sourcemod>
#define PLUGIN_VERSION "1.0"
new Handle:db = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "Subscription Check",
version = "1.0",
};
public OnPluginStart()
{
SQL_TConnect(SQL_OnConnect, "idchk");
}
public SQL_OnConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
LogError("Error connecting to the database: %s", error);
}
else
{
db = hndl;
PrintToServer("Connection successful");
}
}
public OnClientPostAdminCheck(client)
{
if(IsClientInGame(client)&&!IsFakeClient(client)) return;
if(CheckCommandAccess(client, "sm_rcon", ADMFLAG_RCON)) return;
{
new String:steamid[20];
GetClientAuthId(client, steamid, sizeof(steamid));
new String:query[512];
new String:auth[50];
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
}
Format(query, sizeof(query), "SELECT steamid FROM billing WHERE steamid='%s'", auth);
new Transaction:txn = SQL_CreateTransaction();
SQL_AddQuery(txn, query, 1); // First query, does steamid exist in database.table
Format(query, sizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date >= DATE(now()) ORDER BY expire_date DESC LIMIT 1", auth);
SQL_AddQuery(txn, query, 2); // Second query, get fresh records by steamid
Format(query, sizeof(query), "SELECT expire_date FROM billing WHERE steamid='%s' AND expire_date < DATE(now()) ORDER BY expire_date DESC LIMIT 1", auth);
SQL_AddQuery(txn, query, 3); // Third query, get old records
SQL_ExecuteTransaction(db, txn, onSuccess, onError, GetClientUserId(client));
}
public onSuccess(Database database, any data, int numQueries, Handle[] results, any[] queryData)
{
new client = GetClientOfUserId(data);
if(client == 0) return;
if(numQueries <= 0) KickClient(client, "Something went wrong...");
new String:buffer[512];
for(new i = 0; i < numQueries; i++)
{
if(queryData[i] == 1 && !SQL_FetchRow(results[i])) // steamid not found
{
KickClient(client, "You are not in database");
break;
}
if(queryData[i] == 2 && SQL_FetchRow(results[i])) // Fresh records found
{
// break loop to not continue next query results.
//SQL_FetchString(results[i], 0, buffer, sizeof(buffer));
//PrintToServer("- %s", buffer);
break;
}
if(queryData[i] == 3 && SQL_FetchRow(results[i])) // Old records found
{
SQL_FetchString(results[i], 0, buffer, sizeof(buffer));
KickClient(client, "Your record has expired %s", buffer);
break;
}
}
}
public onError(Database database, any data, int numQueries, const char[] error, int failIndex, any[] queryData)
{
//PrintToServer("onError");
}
On Compiling, i get the following errors
PHP Code:
Compiling idchk.sp...
SourcePawn Compiler 1.10.0.6502
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC
idchk.sp(39) : error 035: argument type mismatch (argument 2)
idchk.sp(39) : error 035: argument type mismatch (argument 3)
idchk.sp(40) : warning 204: symbol is assigned a value that is never used: "query"
idchk.sp(45) : error 017: undefined symbol "query"
idchk.sp(45) : error 072: "sizeof" operator is invalid on "function" symbols
idchk.sp(48) : error 017: undefined symbol "query"
idchk.sp(50) : error 017: undefined symbol "query"
idchk.sp(50) : error 072: "sizeof" operator is invalid on "function" symbols
idchk.sp(51) : error 017: undefined symbol "query"
idchk.sp(53) : error 017: undefined symbol "query"
idchk.sp(53) : error 072: "sizeof" operator is invalid on "function" symbols
idchk.sp(54) : error 017: undefined symbol "query"
11 Errors.
Appreciate any help to complete this.
I assume I have to create a mysql db and add the user details, manually for this plugin to connect to check & do its stuff.