AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Your own Admin System (https://forums.alliedmods.net/showthread.php?t=87635)

AntiBots 03-14-2009 18:36

Your own Admin System
 
Hi, this is my first tutorial that I do in English. So sorry my bad words. xD

In this tutorial I will explain how to make your own "Admin System"
You need prior knowledge.

PHP Code:

#include <amxmodx>

// Arrays, Then we add the Dimensions.
new Array:g_steamid
new Array:g_password
new Array:g_flags
new Array:g_mode

// Array of player flags
new Array:g_playerflags

// We need to create a cvar por setinfo & for default flag.
new cvar_setinfo
new cvar_defaultflag

// Here are the flags for loggins types.
enum
{
    
KZ_JOIN_PASS = (1<<0),
    
KZ_JOIN_TAGS = (1<<1),
    
KZ_JOIN_STEAM = (1<<2),
    
KZ_JOIN_IP = (1<<3),
    
KZ_JOIN_NOPASS = (1<<4)
}

public 
plugin_precache() 
{
    
register_plugin("Admins Loggin""1.0""ReymonARG")
    
    
// Now create the 2 cvars for custom somethings.
    
cvar_setinfo register_cvar("fakeadmin_setinfo""_pw")
    
cvar_defaultflag register_cvar("fakeadmin_defaultflag""z")
    
    
register_concmd("fakeadmin_reload""fakereload"ADMIN_RCON)
    
    
// We need to create the dimensions for the Arrays
    
g_steamid ArrayCreate(321)
    
g_password ArrayCreate(321)
    
g_flags ArrayCreate(11)
    
g_mode ArrayCreate(11)
    
g_playerflags ArrayCreate(11)
    
    for( new 
0<= 32i++)
        
ArrayPushCell(g_playerflags0)
    
    
// Well now we need to get the list of admins
    
fake_get_admins("addons/amxmodx/configs/newusers.ini")
}

public 
fakereload(idlevel)
{
    if( 
get_user_flags(id) & level )
    {
        
fake_get_admins("addons/amxmodx/configs/newusers.ini")
        
        for( new 
1<= 32i++)
        {
            if( !
is_user_connected(i) ) continue
            
fakeadmin_authplayer(i)
        }
    }
    
    return 
PLUGIN_HANDLED
}

public 
fake_get_admins(const filename[])
{
    
// First we have to create some static collet the info.
    
static data[192], steamid[32], password[32], flags[32], mode[10]
    
    
// For reload admins. We need to clean all information and get again.
    
ArrayClear(g_steamid)
    
ArrayClear(g_password)
    
ArrayClear(g_flags)
    
ArrayClear(g_mode)
    
    
// Now we need to open the file and read, line per line.
    
new fopen(filename"rt" )
    while( !
feof(f) )
    {
        
fgetsfdata191)
        
// With continue if dont is the data that we want.
        
if( data[0] == '/' && data[1] == '/' || data[0] == ';' || data[0] == ' ' || data[0] == '^n') continue
        
        
// If dont are all param go to next line.
        
if( parsedatasteamid31password31flags31mode9) != ) continue
        
        
// Push the information into Arrays items.
        
ArrayPushString(g_steamidsteamid)
        
ArrayPushString(g_passwordpassword)
        
ArrayPushCell(g_flagsread_flags(flags))
        
ArrayPushCell(g_moderead_flags(flags))
    }
    
// This is very important. We need to close the file.
    
fclose(f)
    
    
// We print the num of items that SteamId Array have.
    // Why dont is -1, Because array have item 0 to.
    
server_print("%i Admin from %s"ArraySize(g_steamid), filename)
    
    return 
1
}

public 
client_connect(id)
{
    static 
defaultflags[32]
    
get_pcvar_string(cvar_defaultflagdefaultflags31)
    
    
// First of all. We set player the defaults flags. Then if is admin we edit.
    
ArraySetCell(g_playerflagsidread_flags(defaultflags) )
}

public 
client_authorized(id)
{
    
fakeadmin_authplayer(id)
}

// Player change name?
public client_infochanged(id)
{
    static 
oldname[32], newname[32]
    
get_user_name(idoldname31)
    
get_user_info(id"name"newname31)
    
    if( !
equal(oldnamenewname) )
        
fakeadmin_authplayer(idnewname)
}

// Auth Player
stock fakeadmin_authplayer(id, const newname[] = "")
{
    static 
name[32], authid[32], ip[32]
    
    
// If is seted name copy to new array, ifnot get the name.
    
if( equal(newname"") )
        
get_user_name(idname31)
    else
        
copy(name31newname)
    
    static 
plr_steamid[32], plr_password[32], plr_flagsplr_mode
    
static setinfo[32], setinfo_tag[32// If needed password
    
get_pcvar_string(cvar_setinfosetinfo_tag31)
    
    
// Now we get player steamid & ip
    
get_user_authid(idauthid31)
    
get_user_ip(idip311// Very important this. Without ip port.
    
get_user_info(idsetinfo_tagsetinfo31)
    
    for( new 
0sizeof(g_steamid); i++)
    {    
        
// First of all, we need to get the information.
        
ArrayGetString(g_steamidiplr_steamid31)
        
ArrayGetString(g_passwordiplr_password31)
        
plr_flags ArrayGetCell(g_flagsi)
        
plr_mode ArrayGetCell(g_modei)
        
        
// Now. select the login mode.
        
if( plr_mode KZ_JOIN_STEAM )
        {
            
// If equal the steamid of the list cotinue.
            
if( equal(plr_steamidauthid) )
            {
                
// Now we need to check if password required or not.
                
if( plr_mode KZ_JOIN_NOPASS )
                {
                    return 
ArraySetCell(g_playerflagsidplr_flags)
                }
                else
                {
                    
// If equal the password, Set flags
                    
if( equal(plr_passwordsetinfo) )
                    {
                        return 
ArraySetCell(g_playerflagsidplr_flags)
                    }
                    else
                    {
                        
// If is seted kick player con bad password. Kick with reason..
                        
if( plr_mode KZ_JOIN_PASS )
                        {
                            return 
server_cmd("kick #%d  You dont have Access to this Server"get_user_userid(id))
                        }
                    }
                }
            }
        }
        else if( 
plr_mode KZ_JOIN_IP )
        {            
            if( 
equal(plr_steamidip) )
            {
                if( 
plr_mode KZ_JOIN_NOPASS )
                {
                    return 
ArraySetCell(g_playerflagsidplr_flags)
                }
                else
                {
                    if( 
equal(plr_passwordsetinfo) )
                    {
                        return 
ArraySetCell(g_playerflagsidplr_flags)
                    }
                    else
                    {
                        if( 
plr_mode KZ_JOIN_PASS )
                        {
                            return 
server_cmd("kick #%d  You dont have Access to this Server"get_user_userid(id))
                        }
                    }
                }
            }
        }
        else
        {
            static 
is_tag_flag = -1
            
if( plr_mode KZ_JOIN_TAGS )
            {
                
is_tag_flag containi(nameplr_steamid)
            }
            
            if( 
is_tag_flag != -||  equal(plr_steamidname) )
            {
                if( 
plr_mode KZ_JOIN_NOPASS )
                {
                    return 
ArraySetCell(g_playerflagsidplr_flags)
                }
                else
                {
                    if( 
equal(plr_passwordsetinfo) )
                    {
                        return 
ArraySetCell(g_playerflagsidplr_flags)
                    }
                    else
                    {
                        if( 
plr_mode KZ_JOIN_PASS )
                        {
                            return 
server_cmd("kick #%d  You dont have Access to this Server"get_user_userid(id))
                        }
                    }
                }
            }            
        }    
    }
    
    return 
1


For example I use this flags in my kz plugin.

PHP Code:

enum
{
    
KZ_USER_NONE 0,
    
KZ_USER_KICK = (1<<0),
    
KZ_USER_BAN = (1<<1),
    
KZ_USER_REWARDS = (1<<2),
    
KZ_USER_GIVEREWARDS = (1<<3),
    
KZ_USER_SETSTART = (1<<4),
    
KZ_USER_COLORCHAT = (1<<5),
    
KZ_USER_RCON = (1<<6),
    
KZ_USER_RESERVATION = (1<<7),
    
KZ_USER_IMMUNITY = (1<<8),
    
KZ_USER_SETC4 = (1<<9),
    
KZ_USER_MODEL = (1<<10),
    
KZ_USER_SCOREBOARD = (1<<11),
    
KZ_USER_LEVEL_A = (1<<12),
    
KZ_USER_LEVEL_B = (1<<13),
    
KZ_USER_LEVEL_C = (1<<14),
    
KZ_USER_LEVEL_D = (1<<15),
    
KZ_USER_LEVEL_E = (1<<16),
    
KZ_USER_ADMIN = (1<<17),
    
KZ_USER_PLAYER = (1<<25)


TODO:
Add like a fakeadmin_addadmin.
SQLx Version
A Example to use flags.

Thanks for reading. I will complete with yours opinions.



Spunky 03-14-2009 23:47

Re: Your own Admin System
 
What's wrong with AMXX's admin system? O_o

AntiBots 03-15-2009 00:11

Re: Your own Admin System
 
Quote:

Originally Posted by Spunky (Post 780831)
What's wrong with AMXX's admin system? O_o

Anything. But if you want a more custom mod. :P This can be a good option.

danielkza 03-15-2009 00:16

Re: Your own Admin System
 
Quote:

Originally Posted by AntiBots (Post 780838)
Anything. But if you want a more custom mod. :P This can be a good option.

Or you need to tie admin privilleges to something else, like a player registration system.

YamiKaitou 03-15-2009 00:28

Re: Your own Admin System
 
Don't hardcode your paths

danielkza 03-15-2009 01:20

Re: Your own Admin System
 
Quote:

Originally Posted by YamiKaitou (Post 780847)
Don't hardcode your paths

And just noticed: use 'else if', it exists for a reason.

Exolent[jNr] 03-15-2009 01:49

Re: Your own Admin System
 
PHP Code:

    if( equal(newname"") ) 

:nono:
PHP Code:

    if( !newname[0] ) 


beckham9224 03-15-2009 04:27

Re: Your own Admin System
 
Pretty hard to learn it... cuz imma n00b :[

TheDS1337 02-12-2013 17:39

Re: Your own Admin System
 
Reaaaaaaaaaaly Thank's, finaly i found it

hLiaS 03-11-2013 16:31

Re: Your own Admin System
 
can anyone create natives for this??


All times are GMT -4. The time now is 12:24.

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