AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting a list of ALL admins, including non-present ones (https://forums.alliedmods.net/showthread.php?t=131759)

AdamR 07-08-2010 15:06

Getting a list of ALL admins, including non-present ones
 
Hi,

I'm trying to retrieve a list of all administrators stored in AMXX's dynamic list. I see that in amxmodx.inc there is a function admins_lookup() to do this, but perhaps I'm using it wrong:
PHP Code:

static iAdmins;
static 
fFlags;
static 
szAuthData[44];

new 
szAdmins[MAX_ADMINS_LENGTH]
format(szAdminsMAX_ADMINS_LENGTH"VALVE_ID_LOOPBACK")

iAdmins admins_num();

for (new 
0iAdminsi++)
{
    
fFlags admins_lookup(iAdminProp_Flags);
    
admins_lookup(iAdminProp_AuthszAuthDatasizeof(szAuthData) - 1);

    if (
fFlags FLAG_AUTHID || fFlags FLAG_IP)
        
format(szAdminsMAX_ADMINS_LENGTH"%s;%s"szAdminsszAuthData)


Basically I'm trying to get all administrators into a string, split by a semi-colon. It should not matter if the administrators are stored in a file or SQL table as I want to read them after they are loaded by the core.

The main issue I'm finding is iAdmins is always 0 -- so the admin_num() function isn't returning anything, or is being called after the core plug-in has loaded the list of administrators.

fysiks 07-08-2010 16:39

Re: Getting a list of ALL admins, including non-present ones
 
Quote:

Originally Posted by AdamR (Post 1232240)
The main issue I'm finding is iAdmins is always 0 -- so the admin_num() function isn't returning anything, or is being called after the core plug-in has loaded the list of administrators.

Why don't you test this theory?

Bugsy 07-08-2010 19:44

Re: Getting a list of ALL admins, including non-present ones
 
When exactly are you attempting to use that code. I just tested it (calling at plugin_init) and it is returning admins for me...or perhaps I am not understanding your objective/question. I don't use SQL or anything for admins, just users.ini.

PHP Code:

const MAX_ADMINS_LENGTH 1000;

public 
plugin_init() 
{
    
LoadAdmins();
}

public 
LoadAdmins()
{
    static 
iAdmins;
    static 
fFlags;
    static 
szAuthData[44];
    
    new 
szAdmins[MAX_ADMINS_LENGTH]
    
format(szAdminsMAX_ADMINS_LENGTH"VALVE_ID_LOOPBACK")
    
    
iAdmins admins_num();
    
    for (new 
0iAdminsi++)
    {
        
fFlags admins_lookup(iAdminProp_Flags);
        
admins_lookup(iAdminProp_AuthszAuthDatasizeof(szAuthData) - 1);
    
        if (
fFlags FLAG_AUTHID || fFlags FLAG_IP)
            
format(szAdminsMAX_ADMINS_LENGTH"%s;%s"szAdminsszAuthData)
    }
    
    
server_printszAdmins );


Result (I am the only admin on my test server)
Code:

VALVE_ID_LOOPBACK;loopback;STEAM_0:0:XXXXX

AdamR 07-09-2010 05:29

Re: Getting a list of ALL admins, including non-present ones
 
It's probably because I'm using SQL tables, perhaps there is a delay before the core plug-in has finished loading the admins from it.

Perhaps I should attempt to call it again after 15 seconds if it doesn't find any admins the first time round.

Bugsy 07-09-2010 08:53

Re: Getting a list of ALL admins, including non-present ones
 
When exactly are you trying to execute the code?

AdamR 07-09-2010 08:54

Re: Getting a list of ALL admins, including non-present ones
 
plugin_init() calls ReadAdmins().

I've fixed this by trying again 5 seconds later after a fail, though it sets a global bool to true so it only tries again once.

Bugsy 07-09-2010 09:16

Re: Getting a list of ALL admins, including non-present ones
 
Quote:

Originally Posted by AdamR (Post 1233002)
plugin_init() calls ReadAdmins().

I've fixed this by trying again 5 seconds later after a fail, though it sets a global bool to true so it only tries again once.

Try doing it at plugin_cfg()?

AdamR 07-09-2010 11:10

Re: Getting a list of ALL admins, including non-present ones
 
Does plugin_cfg() run after admins have been loaded? (even from SQL)

Bugsy 07-09-2010 13:45

Re: Getting a list of ALL admins, including non-present ones
 
I have no idea if it makes any difference for what you're doing but it never hurts to try.

fysiks 07-09-2010 19:33

Re: Getting a list of ALL admins, including non-present ones
 
Looks to me like it loads at the same time that it would if it wasn't SQL.


All times are GMT -4. The time now is 07:10.

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