Raised This Month: $ Target: $400
 0% 

[Help] create the menu-manager.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
p4rp4d30
Veteran Member
Join Date: Mar 2007
Old 03-06-2010 , 00:21   [Help] create the menu-manager.
Reply With Quote #1

I have the basics, create the administrator, but I need to remove the administrator.
How can remove administrator to the user.ini and based on this code.

Parts of the code was pulled from the plugin "admins manager" and adapt it to what I needed..


PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN    "Add Admin Menu"
#define AUTHOR    ";SoNNy"
#define VERSION    "1.0"
#define STR_LEN 64

new gConfigsDir[STR_LEN];
new 
gAdminsFile[STR_LEN];

new 
g_iMaxPlayers
new bool:g_Player[33]
new 
gAdminTargetId[33];
new 
gAdminTargetFlags;
new 
gAdminSaveMode;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /addadmin""MenuAddAdmin"ADMIN_IMMUNITY)
    
register_clcmd("say_team /addadmin""MenuAddAdmin"ADMIN_IMMUNITY)
    
g_iMaxPlayers get_maxplayers();
    
    
gAdminTargetFlags register_cvar("amx_a_flag","L");
    
gAdminSaveMode register_cvar("amx_a_savemode","0");
    
    
get_configsdir(gConfigsDirsizeof gConfigsDir 1);
    
formatex(gAdminsFilesizeof gAdminsFile 1"%s/users.ini"gConfigsDir);
    
    if(!
file_exists(gAdminsFile))
        
set_fail_state("Non-existent file.");
}

public 
client_putinserver()
{
    for(new 
0<= g_iMaxPlayers; ++i
    
g_Player[i] = false
}
    
public 
client_disconnect()
{
    for(new 
0<= g_iMaxPlayers; ++i
    
g_Player[i] = false
}

public 
MenuAddAdmin(id,level,cid)
{
    if(!
cmd_access(id,level,cid,2))
        return 
PLUGIN_HANDLED;
    
    new 
temp1[32];
    new 
temp2[2];
    new 
iPlayer;
    new 
nPlayer[50];
    new 
Menu menu_create("Selected Admin to Add:","AddMenuHandler")  
    static 
sPlayers[32], iNum;
    
get_players(sPlayersiNum"a");
    
    for (new 
iNumi++)
    {
        if (
is_user_connected(i))
        {
            
get_user_name(i,temp1,32);
            
num_to_str(i,temp2,2);
            
iPlayer str_to_num(temp2)
            
            if(!
g_Player[iPlayer])
            {
                
menu_additem(Menutemp1,temp2);
            }
            else
            {
                
formatex(nPlayercharsmax(nPlayer), "\y%s \r(ADMIN)"temp1)
                
menu_additem(MenunPlayertemp2);
            }
        }
    }
    
menu_display(idMenu0);  
    return 
PLUGIN_HANDLED;
}

public 
AddMenuHandler(idMenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(Menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6];
    new 
iAccess;
    new 
iCallback;
    new 
iName[64];
    new 
iKeys;
    
menu_item_getinfo(MenuitemiAccessiData5iName63iCallback)
    
    
iKeys str_to_num(iData)
    static 
iTarget;
    
    
iTarget get_user_index(iData);
    
gAdminTargetId[id] = iTarget;
    
    if(!
g_Player[iKeys])
    {
        
addAdmin(id);
        
g_Player[iKeys] = true
    
}
    else
    {
        
// removeAdmin(id);
        
g_Player[iKeys] = false
    
}  

    return 
PLUGIN_HANDLED
}

public 
addAdmin(id)
{
    static 
iFile;
    
iFile fopen(gAdminsFile"at+");
    new 
aAdminSaveMode 
    
new aAdminTargetFlags
    
    aAdminSaveMode 
get_pcvar_num(gAdminSaveMode)
    
aAdminTargetFlags get_pcvar_num(gAdminTargetFlags)
    
    static 
UserInfo[32];
    switch(
aAdminSaveMode)
    {
        case 
0: { get_user_ip(gAdminTargetId[id], UserInfosizeof UserInfo 11); }
        case 
1: { get_user_authid(gAdminTargetId[id], UserInfosizeof UserInfo 1); }
    }
    static 
sTemp[128];
    new 
iLine;
    
    while(!
feof(iFile))
    {
        
fgets(iFilesTempsizeof sTemp 1);
        
        
iLine++;
        
        if((
containi(sTempUserInfo) != -1) && sTemp[0] != ';')
        {
            
client_print(0print_chat"Sorry but an admin account with this account info already exists!");
            
g_Player[gAdminTargetId[id]] = false
            
return 1;
        }
    }
    
    static 
sBuffer[128];
    switch(
aAdminSaveMode)
    {
        case 
0: { formatex(sBuffersizeof sBuffer 1"^n^"%s^" ^"^" ^"%s^" ^"de^""UserInfoaAdminTargetFlags); }
        case 
1: { formatex(sBuffersizeof sBuffer 1"^n^"%s^" ^"^" ^"%s^" ^"ce^""UserInfoaAdminTargetFlags); }
    }
    
fprintf(iFilesBuffer);
    
fclose(iFile);
    
server_cmd("amx_reloadadmins");
    
gAdminTargetId[id] = 0;
    return 
1;

Thanks!

Sorry for my english! is bad!! xD

Last edited by p4rp4d30; 03-06-2010 at 00:25.
p4rp4d30 is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 03-06-2010 , 10:32   Re: [Help] create the menu-manager.
Reply With Quote #2

I think removing lines from users.ini file during game is dangerous.

You need to read the whole file, delete it and write a new one from scratch (alternatives are file renaming)

If your server crashes while doing this you will loose your users.ini and your admins.

EDIT:
I suggest to use an admin database in sql instead of file. It's safer.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
p4rp4d30
Veteran Member
Join Date: Mar 2007
Old 03-06-2010 , 14:57   Re: [Help] create the menu-manager.
Reply With Quote #3

mm ok.

I need to find ways to provide access "Flag" at player by a certain time.

can be achieved in some way?
p4rp4d30 is offline
Reply


Thread Tools
Display Modes

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 08:46.


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