Makeadmin saving security cod
#1

Код:
new AdminKod[MAX_PLAYERS], 
    AdminLogovan[MAX_PLAYERS]; 

GiveAdminCode(playerid) { //When promoting, use 
    new rr = randomEx(1000,999999); 
    new string[128]; 
    format(string,sizeof(string),"Your admin code is %i",rr); 
    SendClientMessage(playerid,COLOR_RED,string); 
    AdminKod[playerid] = rr; 
    return true; 
} 


CMD:login(playerid,params[]) { //how to login as administrator 
    new nmr; 
    if(sscanf(params,"i",nmr)) return SendClientMessage(playerid,COLOR_RED,"Usage: /login [admin code]"); 
    if(nmr != AdminKod[playerid]) return SendClientMessage(playerid,COLOR_RED,"Wrong admin code"); 
    AdminLogovan[playerid] = 1; //admin logged in  
    SendClientMessage(playerid,COLOR_RED,"You have logged in as administrator!"); 
    return true; 
} 

CMD:makeadmin(playerid, params[]) //credits Cody 
{ 
    if(PlayerInfo[playerid][pAdmin] < 7) 
        return SendClientMessage(playerid, COLOR_BLUE, "You don't have acces to that command."); 

    new id, string[128], level; 
    if(sscanf(params, "dd", id, level)) 
        return SendClientMessage(playerid, COLOR_RED, "SERVER: /makeadmin [ID] [LEVEL]"); 

    //ShowPlayerDialog(id,DIALOG_ADMINBOX,DIALOG_STYLE_MSGBOX, "You are an admin", string, "Ok", ""); 
    format(string, sizeof(string), "%s promoted you to level %i.", PlayerName(playerid), level); 
    SendClientMessage(id, COLOR_BLUE, string); 
    PlayerInfo[id][pAdmin] = level; 
    GiveAdminCode(id); //Giving them a code 
    return 1; 
}
This is now makeadmin cmd but now problem is when player relog and try to use /login [code] he get error scm You don't have acces to that command
Reply
#2

Код:
CMD:login(playerid,params[]) { //how to login as administrator 
    new nmr; 
    if(sscanf(params,"i",nmr)) return SendClientMessage(playerid,COLOR_RED,"Usage: /login [admin code]"); 
    if(nmr != AdminKod[playerid]) return SendClientMessage(playerid,COLOR_RED,"Wrong admin code"); 
    AdminLogovan[playerid] = 1; //admin logged in  
    PlayerInfo[playerid][pAdmin] = 7; 
    SendClientMessage(playerid,COLOR_RED,"You have logged in as administrator!"); 
    return true; 
}
this system is not good. you will have to do it rank by rank and set the permission to another varible or something, I don't have the time to do it for you.
Reply
#3

Basically redid some basic parts, and included something to make codes more secure... And cleaned it up a bit.

When you save them, use the
PHP код:
AdminKod[playerid
variable, when loading format it.

This can be improved upon, I just don't have time right now.

PHP код:
new AdminKod[MAX_PLAYERS], AdminLogovan[MAX_PLAYERS]; 
generateCode(strDest[], strLen 10// ( https://sampforum.blast.hk/showthread.ph...pid1349155 )
{
    while(
strLen--)
        
strDest[strLen] = random(2) ? (random(26) + (random(2) ? 'a' 'A')) : (random(10) + '0');
}
CMD:login(playerid,params[])
{
    new 
nmr[6]; 
    if(
sscanf(params,"s[6]"nmr)) 
        return 
SendClientMessage(playeridCOLOR_RED"Usage: /login [admin code]"); 
        
    if(
strcmp(nmrAdminKod[playerid], false))
        return 
SendClientMessage(playeridCOLOR_RED"Wrong admin code"); 
  
    
SendClientMessage(playeridCOLOR_RED"You have logged in as administrator!"); 
    
AdminLogovan[playerid] = 1;
    return 
true

CMD:makeadmin(playeridparams[])

    new 
idstring[128], levelcode[5];
    
generateCode(code5);
    if(
PlayerInfo[playerid][pAdmin] < 7
        return 
SendClientMessage(playeridCOLOR_BLUE"You don't have acces to that command."); 
        
    if(
sscanf(params"dd"idlevel)) 
        return 
SendClientMessage(playeridCOLOR_RED"SERVER: /makeadmin [ID] [LEVEL]"); 
    
format(stringsizeof(string), "%s promoted you to level %i.\nSecurity Code: %s"PlayerName(playerid), levelcode);
    
ShowPlayerDialog(id,DIALOG_ADMINBOX,DIALOG_STYLE_MSGBOX"You are an admin"string"Ok"""); 
    
    
format(stringsizeof(string), "You promoted %s to level %i."PlayerName(id), level); 
    
SendClientMessage(playeridCOLOR_BLUEstring);
    
    
PlayerInfo[id][pAdmin] = level
    
format(AdminKod[playerid], 6code); // Stores the code into the string
    
return 1

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)