Raised This Month: $51 Target: $400
 12% 

[UNSOLVED]Passing Data through Timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-17-2014 , 06:06   [UNSOLVED]Passing Data through Timers
Reply With Quote #1

So I'm working on removing admins from my mysql database.

I got this so far:

PHP Code:
public Action:VIP_Remove(clientargs)
{
    
// Check arguments count
    
if(args 1)
    {
        if(
client 0PrintToChat(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(1Namesizeof(Name));
    
    
// Create connection to sql server
    
decl String:error[255] = "\0";
    new 
Handle:connection SQL_DefConnect(errorsizeof(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 0PrintToChat(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(Querysizeof(Query), "SELECT identity, name FROM sm_admins WHERE name LIKE '%s%s%s' AND flags = '1:@vip'"'%'Name'%');
        
hQuery SQL_Query(connectionQuery);
        
        if(
hQuery == INVALID_HANDLE)
        {
            
// Log error
            
SQL_GetError(connectionerrorsizeof(error));
            if(
GetConVarBool(VIP_Log)) LogToFileEx(logFilePath"[VIP-Manager] Error on Query! Error: %s"error);
            if(
client 0PrintToChat(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 0PrintToChat(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 0PrintToChat(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(hQuery0SteamIDsizeof(SteamID));
                
SQL_FetchString(hQuery1Namesizeof(Name));

            }
            else
            {
                
// Log error
                
SQL_GetError(connectionerrorsizeof(error));
                if(
GetConVarBool(VIP_Log)) LogToFileEx(logFilePath"[VIP-Manager] Error on Query! Error: %s"error);
                if(
client 0PrintToChat(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(Querysizeof(Query), "DELETE FROM sm_admins WHERE identity = '%s' AND flags = '1:@vip'"SteamID);
            
            if(!
SQL_FastQuery(connectionQuery))
            {
                
// Log error
                
SQL_GetError(connectionerrorsizeof(error));
                if(
GetConVarBool(VIP_Log)) LogToFileEx(logFilePath"[VIP-Manager] Error while deleting VIPs! Error: %s"error);
                if(
client 0PrintToChat(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(rDataclient);
                
WritePackString(rDataclient);
                
WritePackString(rDataconnection);
                
WritePackString(rDataSteamID);
                
WritePackString(rDataName);
                
                
CreateTimer(3.0RemoveVIPrData);
            }
        }
        
        
// Close Query
        
CloseHandle(hQuery);
    }
    
    
//Close connection
    
CloseHandle(connection);
    
    return 
Plugin_Handled;
}

public 
Action:RemoveVIP(Handle:timerany: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(rClientrConnectionrSteamIDrName);

    
// Log deleted VIP
    
decl String:cName[255] = "\0";
    if(
client 0GetClientName(clientcNamesizeof(cName));
    else 
cName "Server console";

    if(
GetConVarBool(VIP_Log)) LogToFileEx(logFilePath"[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!"rNamerSteamIDcName);
    if(
client 0PrintToChat(client"[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!"rNamerSteamIDcName);
    else 
PrintToServer("[VIP-Manager] Deleted VIP '%s' (SteamID: %s). Reason: Removed by %s!"rNamerSteamIDcName);

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
DJ Data is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-19-2014 , 10:29   Re: [UNSOLVED]Passing Data through Timers
Reply With Quote #2

bump?
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 09-19-2014 , 11:49   Re: [UNSOLVED]Passing Data through Timers
Reply With Quote #3

Code:
                WritePackCell(rData, client); 
                WritePackString(rData, client);
Code:
decl String:rClient[128]; 
    new rClient; 
     
    // Fetch Client 
    new rClient; 
    rClient = ReadPackCell(rData); 
And third http://wiki.alliedmods.net/SQL_%28So...d_Scripting%29
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 09-19-2014 at 11:49.
Dr. Greg House is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-19-2014 , 17:39   Re: [UNSOLVED]Passing Data through Timers
Reply With Quote #4

Switch to client serials or userids, in other words.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode