View Single Post
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 06-22-2015 , 14:10   [REQ] 1.4.11 SM Add Admin Native
Reply With Quote #1

Because I'm terrible at figuring out database-anything, can someone please edit 1.4.11 to add this native:

(sm_command not necessary).

PHP Code:
#define ADMIN_ADD_ADMINS    (1<<1)
#define PLEASE_SELECT       -2
#define NO_PERMISSIONS      -3
#define CUSTOM_PERMISSIONS  'c'
#define NEW_ADMIN_GROUP     'n'
#define GRP_ROOT            1
#define GRP_ADMIN           2
#define GRP_BITDONOR        3
#define GRP_REGULAR         4
#define GRP_MEGADONOR       5
#define GRP_GIGADONOR       6

#define GRP_WEBMINZ         2
#define GRP_WEBROOT         3

#define MIN_PASS_LENGTH     4

SB_AddAdmin(iClientString:szLoginName[], String:szSteamId[], String:szEmail[] = ""String:szWebPanelPassword[] = ""String:szWebPanelPasswordConfirm[] = ""String:szServerAdminPassword[] = "",
    
String:szServerAdminGroup[] = "No Permissions"String:szWebAdminGroup[] = "No Permissions"String:szServerAccess[] = "")
{
    if (!
IsClientRcon(iClient))
    {
        
ReplyToCommand("Hacking Attempt %L tried to add an admin, but doesnt have access."iClient);
        return;
    }

    new 
iMask ADMIN_ADD_ADMINS// This is intended for adding a Web Panel admin.
    
new String:szSrvMask[] = "0";
    new 
String:server_a_pass[] = "-1";
    new 
String:grp[] = "g1"
    
new String:svr[] = ""//"s3,s4,s5" ,s6
    
new serverg PLEASE_SELECT;
    new 
webg PLEASE_SELECT;

    if (
serverg == NO_PERMISSIONS)
    {
        
szSrvMask[0] = '\0';
    }

    if (
webg == NO_PERMISSIONS)
    {
        
iMask 0;
    }

    if (
szLoginName[0] == '\0')
    {
        
ReplyToCommand(iClient"You must type a name for the admin.");
        return;
    }
    else
    {
        if (
StrContains(szLoginName"'") != -1)
        {
            
ReplyToCommand(iClient"An admin name can not contain a \" ' \".");
            return;
        }
        else
        {
            if (
is_taken("admins""user"$a_name))
            {
                
ReplyToCommand(iClient"An admin with this name already exists.");
                return;
            }
        }
    }

    if (!
IsValidSteamId(szSteamId, -1))
    {
        
ReplyToCommand(iClient"Please enter a valid Steam ID or Community ID. for the admin.")
        return;
    }
    else
    {
        if (
is_taken("admins""authid"$a_steam))
        {
            
$admins $userbank->GetAllAdmins();
            foreach(
$admins as $admin)
            {
                if (
$admin['authid'] == $a_steam)
                {
                    
$name $admin['user'];
                    break;
                }
            }

            
ReplyToCommand(iClient"Admin %s already uses this Steam ID."htmlspecialchars(addslashes(szVarName)));
            return;
        }
    }

    if (
iMask != 0)
    {
        if (
szWebPanelPassword[0] == '\0')
        {
            
// A password is only required for users with web permissions.
            
            
ReplyToCommand(iClient"You must type a password.");
            return;
        }
        
        if (
strlen(szWebPanelPassword) < MIN_PASS_LENGTH)
        {
            
ReplyToCommand(iClient"Your password must be at-least %i characters long."MIN_PASS_LENGTH);
            return;
        }
        else 
        {
            if (
szWebPanelPassword[0] == '\0')
            {
                
ReplyToCommand(iClient"You must confirm the password.");
                return;
            }
            else if (!
StrEqual(szWebPanelPasswordszWebPanelPasswordConfirm))
            {
                
ReplyToCommand(iClient"Your passwords don't match.")
                return;
            }
        }
    
        
// No email
        
if(szEmail[0] == '\0')
        {
            
// An E-Mail address is only required for users with web permissions.
            
ReplyToCommand(iClient"You must type an e-mail address.");
            return;
        }
        else
        {
            
// Is an other admin already registred with that email address?
            
if (is_taken("admins""email"$a_email))
            {
                
$admins $userbank->GetAllAdmins();
                foreach(
$admins as $admin)
                {
                    if(
$admin['email'] == $a_email)
                    {
                        
$name $admin['user'];
                        break;
                    }
                }

                
ReplyToCommand(iClient"This email address is already being used by %s."htmlspecialchars(addslashes($name)));
                return;
            }
        }

        switch (
webg)
        {
            case 
PLEASE_SELECT:
            {
                
ReplyToCommand(iClient"You must choose a group.");
                return;
            }
        }
    }

    if (
szServerAdminPassword[0] != '\0')
    {
        
strcopy(server_a_passsizeof(server_a_pass), szServerAdminPassword)
    }

    
// Choose to use a server password
    
if (server_a_pass != "-1"// This is initialized to -1 and is only overwrriten if the code above executes
    
{
        
//if (server_a_pass[0] == '\0') // This should be unreachable code.
        //{
        //  ReplyToCommand("You must type a server password or uncheck the box.");
        //}
        // 
        // else
        
if (strlen(server_a_pass) < MIN_PASS_LENGTH)
        {
            
ReplyToCommand(iClient"Your password must be at least %i characters long."MIN_PASS_LENGTH);
            return;
        }

        
// At this point the server password would be set to whatever was entered
    
}
    else
    {
        
// Don't set "-1" as password ;)
        
server_a_pass[0] = '\0';
    }
    
    switch (
serverg)
    {
        case 
PLEASE_SELECT// if they didn't choose a server group
        
{
            
ReplyToCommand(iClient"You must choose a group.");
            return;
        }
    }

    
xajax_AddAdmin(iMaskszSrvMaskszLoginNameszSteamIdszEmailszWebPanelPasswordservergwebgserver_a_pass""""grpsrv);
}

xajax_AddAdmin(iMaskString:szSrvMaskString:szLoginNameString:szSteamIdString:szEmailString:szWebPanelPasswordservergwebgString:server_a_passString:a_webnameString:a_servernameString:grpString:srv)
{

// ##############################################################
// ##                     Start adding to DB                   ##
// ##############################################################
    
    
$gid 0;
    
$groupID 0;
    
$inGroup false;
    
$wgid NextAid();
    new 
iImmunity 0;
    
    
// Extract immunity from server mask string
    
new iPos StrContains(szSrvMask"#"); 
    if (
iPos != -1)
    {
        
iImmunity 0;
        
// Extract xyz from alkfnak[#xyz]m3m2n23o and convert to int
    
}
    
    
// Avoid negative immunity
    
iImmunity = (iImmunity 0) ? iImmunity 0;

    if (
webg == 'c' || webg <= 0)
    {
        
webg = -1// Custom permissions -> no group
    
}

    new 
String:server_admin_group[255];
    new 
server_admin_group_int = -1;
    
    
// Handle Serverpermissions
    // Chose to create a new server admin group
    
if (serverg != 'c' && serverg 0)
    {
        
server_admin_group $GLOBALS['db']->GetOne("SELECT `name` FROM ".DB_PREFIX."_srvgroups WHERE id = '" . (int)$serverg "'");
        new 
server_admin_group_int serverg;
    }
    
// Custom permissions -> no group
    
else
    {
        
server_admin_group[0] = '\0';
        
server_admin_group_int = -1;
    }
    
    
// Add the admin
    
$aid $userbank->AddAdmin($a_name$a_steam$a_password$a_emailwebg$mask$server_admin_groupszSrvMaskiImmunity$a_serverpass);
    
    if (
$aid > -1)
    {
        
// Grant permissions to the selected server groups
        
$srv_groups explode(","$server);
        
$addtosrvgrp $GLOBALS['db']->Prepare("INSERT INTO ".DB_PREFIX."_admins_servers_groups(admin_id,group_id,srv_group_id,server_id) VALUES (?,?,?,?)");
        foreach(
$srv_groups AS $srv_group)
        {
            if(!empty(
$srv_group))
                
$GLOBALS['db']->Execute($addtosrvgrp,array($aid$server_admin_group_intsubstr($srv_group1), '-1'));
        }
        
        
// Grant permissions to individual servers
        
$srv_arr explode(","$singlesrv);
        
$addtosrv $GLOBALS['db']->Prepare("INSERT INTO ".DB_PREFIX."_admins_servers_groups(admin_id,group_id,srv_group_id,server_id) VALUES (?,?,?,?)");
        foreach(
$srv_arr AS $server)
        {
            if(!empty(
$server))
                
$GLOBALS['db']->Execute($addtosrv,array($aid$server_admin_group_int'-1'substr($server1)));
        }
        if(isset(
$GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1)
        {
            
// rehash the admins on the servers
            
$serveraccessq $GLOBALS['db']->GetAll("SELECT s.sid FROM `".DB_PREFIX."_servers` s
                                                LEFT JOIN `"
.DB_PREFIX."_admins_servers_groups` asg ON asg.admin_id = '".(int)$aid."'
                                                LEFT JOIN `"
.DB_PREFIX."_servers_groups` sg ON sg.group_id = asg.srv_group_id
                                                WHERE ((asg.server_id != '-1' AND asg.srv_group_id = '-1')
                                                OR (asg.srv_group_id != '-1' AND asg.server_id = '-1'))
                                                AND (s.sid IN(asg.server_id) OR s.sid IN(sg.server_id)) AND s.enabled = 1"
);
            
$allservers = array();
            foreach(
$serveraccessq as $access) {
                if(!
in_array($access['sid'], $allservers)) {
                    
$allservers[] = $access['sid'];
                }
            }
            
$objResponse->addScript("ShowRehashBox('".implode(","$allservers)."','Admin Added', 'The admin has been added successfully', 'green', 'index.php?p=admin&c=admins');TabToReload();");
        } else
            
$objResponse->addScript("ShowBox('Admin Added', 'The admin has been added successfully', 'green', 'index.php?p=admin&c=admins');TabToReload();");
        
        
$log = new CSystemLog("m""Admin added""Admin (" $a_name ") has been added");
        return 
$objResponse;
    }
    else
    {
        
$objResponse->addScript("ShowBox('User NOT Added', 'The admin failed to be added to the database. Check the logs for any SQL errors.', 'red', 'index.php?p=admin&c=admins');");
    }

must be a normal native to be called by other plugins

based on the web panel's add admin page

Edit:

Basically I'm looking for this to be ported to Sourcepawn:

https://github.com/GameConnect/sourc...lback.php#L835

edit:

Almost done converting everything except for setting up SQL database related stuff (reading / writing data).
__________________

Last edited by Chdata; 07-01-2015 at 13:42.
Chdata is offline