Makeadmin saving security cod - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Makeadmin saving security cod (
/showthread.php?tid=599566)
Makeadmin saving security cod [ solved] -
Deny1 - 27.01.2016
Код:
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
Re: Makeadmin saving security cod -
rambalili2 - 27.01.2016
Код:
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.
Re: Makeadmin saving security cod -
itsCody - 27.01.2016
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.php?pid=1349155#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(playerid, COLOR_RED, "Usage: /login [admin code]");
if(strcmp(nmr, AdminKod[playerid], false))
return SendClientMessage(playerid, COLOR_RED, "Wrong admin code");
SendClientMessage(playerid, COLOR_RED, "You have logged in as administrator!");
AdminLogovan[playerid] = 1;
return true;
}
CMD:makeadmin(playerid, params[])
{
new id, string[128], level, code[5];
generateCode(code, 5);
if(PlayerInfo[playerid][pAdmin] < 7)
return SendClientMessage(playerid, COLOR_BLUE, "You don't have acces to that command.");
if(sscanf(params, "dd", id, level))
return SendClientMessage(playerid, COLOR_RED, "SERVER: /makeadmin [ID] [LEVEL]");
format(string, sizeof(string), "%s promoted you to level %i.\nSecurity Code: %s", PlayerName(playerid), level, code);
ShowPlayerDialog(id,DIALOG_ADMINBOX,DIALOG_STYLE_MSGBOX, "You are an admin", string, "Ok", "");
format(string, sizeof(string), "You promoted %s to level %i.", PlayerName(id), level);
SendClientMessage(playerid, COLOR_BLUE, string);
PlayerInfo[id][pAdmin] = level;
format(AdminKod[playerid], 6, code); // Stores the code into the string
return 1;
}