SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
|
09-17-2014
, 06:06
[UNSOLVED]Passing Data through Timers
|
#1
|
So I'm working on removing admins from my mysql database.
I got this so far:
PHP Code:
public Action:VIP_Remove(client, args)
{
// Check arguments count
if(args < 1)
{
if(client > 0) PrintToChat(client, "[VIP-Manager] Use vipm_rm <\"name\">");
else PrintToServer("[VIP-Manager] Use vipm_rm <\"name\">");
return Plugin_Continue;
}
// Get Name
decl String:Name[255] = "\0";
GetCmdArg(1, Name, sizeof(Name));
// Create connection to sql server
decl String:error[255] = "\0";
new Handle:connection = SQL_DefConnect(error, sizeof(error));
if(connection == INVALID_HANDLE)
{
// Log error
if(GetConVarBool(VIP_Log)) LogToFileEx(logFilePath, "[VIP-Manager] Couldn't connect to SQL server! Error: %s", error);
if(client > 0) PrintToChat(client, "[VIP-Manager] Couldn't connect to SQL server! Error: %s", error);
else PrintToServer("[VIP-Manager] Couldn't connect to SQL server! Error: %s", error);
return Plugin_Continue;
}
else
{
new Handle:hQuery;
decl String:Query[255] = "\0";
// Set SQL query
Format(Query, sizeof(Query), "SELECT identity, name FROM sm_admins WHERE name LIKE '%s%s%s' AND flags = '1:@vip'", '%', Name, '%');
hQuery = SQL_Query(connection, Query);
if(hQuery == INVALID_HANDLE)
{
// Log error
SQL_GetError(connection, error, sizeof(error));
if(GetConVarBool(VIP_Log)) LogToFileEx(logFilePath, "[VIP-Manager] Error on Query! Error: %s", error);
if(client > 0) PrintToChat(client, "[VIP-Manager] Error on Query! Error: %s", error);
else PrintToServer("[VIP-Manager] Error on Query! Error: %s", error);
return Plugin_Continue;
}
else
{
// Check count of founded VIPs
if(SQL_GetRowCount(hQuery) > 1)
{
// Print error
if(client > 0) PrintToChat(client, "[VIP-Manager] Found more than one VIP with the name like '%s'!", Name);
else PrintToServer("[VIP-Manager] Found more than one VIP with the name like '%s'!", Name);
return Plugin_Continue;
}
else if(SQL_GetRowCount(hQuery) == 0)
{
// Print error
if(client > 0) PrintToChat(client, "[VIP-Manager] Can't find VIP with the name: '%s'!", Name);
else PrintToServer("[VIP-Manager] Can't find VIP with the name: '%s'!", Name);
return Plugin_Continue;
}
// Get SteamID
decl String:SteamID[64] = "\0";
if(SQL_FetchRow(hQuery))
{
SQL_FetchString(hQuery, 0, SteamID, sizeof(SteamID));
SQL_FetchString(hQuery, 1, Name, sizeof(Name));
}
else
{
// Log error
SQL_GetError(connection, error, sizeof(error));
if(GetConVarBool(VIP_Log)) LogToFileEx(logFilePath, "[VIP-Manager] Error on Query! Error: %s", error);
if(client > 0) PrintToChat(client, "[VIP-Manager] Error on Query! Error: %s", error);
else PrintToServer("[VIP-Manager] Error on Query! Error: %s", error);
return Plugin_Continue;
}
// Delete VIP
Format(Query, sizeof(Query), "DELETE FROM sm_admins WHERE identity = '%s' AND flags = '1:@vip'", SteamID);
if(!SQL_FastQuery(connection, Query))
{
// Log error
SQL_GetError(connection, error, sizeof(error));
if(GetConVarBool(VIP_Log)) LogToFileEx(logFilePath, "[VIP-Manager] Error while deleting VIPs! Error: %s", error);
if(client > 0) PrintToChat(client, "[VIP-Manager] Error while deleting VIPs! Error: %s", error);
else PrintToServer("[VIP-Manager] Error while deleting VIPs! Error: %s", error);
return Plugin_Continue;
}
else
{
ServerCommand("sm_sql_setadmingroups \"steam\" \"%s\" \"\"", SteamID);
new Handle:rData = CreateDataPack();
WritePackCell(rData, client);
WritePackString(rData, client);
WritePackString(rData, connection);
WritePackString(rData, SteamID);
WritePackString(rData, Name);
CreateTimer(3.0, RemoveVIP, rData);
}
}
// Close Query
CloseHandle(hQuery);
}
//Close connection
CloseHandle(connection);
return Plugin_Handled;
}
public Action:RemoveVIP(Handle:timer, any:data)
{
ResetPack(data);
decl String:rClient[128];
new rClient;
// Fetch Client
new rClient;
rClient = ReadPackCell(rData);
(no idea if this is right)
//Fetch SteamID
decl String:rSteamID[64];
ReadPackString(no idea what to put here);
//Fetch Name
decl String:rName[255];
ReadPackString(no idea what to put here);
//Fetch connection
new Handle:rConnection
(no idea what to put here)
// Execute custom SQL queries
Execute_Custom_OnRemove_Queries(rClient, rConnection, rSteamID, rName);
// Log deleted VIP
decl String:cName[255] = "\0";
if(client > 0) GetClientName(client, cName, sizeof(cName));
else cName = "Server console";
if(GetConVarBool(VIP_Log)) LogToFileEx(logFilePath, "[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!", rName, rSteamID, cName);
if(client > 0) PrintToChat(client, "[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!", rName, rSteamID, cName);
else PrintToServer("[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!", rName, rSteamID, cName);
}
As you can see, i moved the last code to a timer, as the database needs some time to execute the "sm_sql_setadmingroups", now im having trouble passing all the data that the code below the "//Execute custom SQL queries" uses. I have no idea what to do, i couldnt find enough documentation for me to understand, especially the part where i need to pass the "Handle:connection".
So if someone could show me how to hook all these up, thatd be great
Cheers
__________________
SourcePawn Coding Level: Novice
Last edited by DJ Data; 09-17-2014 at 11:09.
Reason: Removed SQL from title, has nothing to do with problem
|
|