05.09.2009, 00:44
For an accounts system, I suggest you use dini for your scriptfiles.
Creating a PlayerInfo array.
You should look up about enums if you don't understand.
_________________________________________________
[size=15px]For the regster command:[/size]
Check if they're already logged:
dini_Exists tells you weather or not their account (file with their name) already exists.
dini_Create creates their account (a file). dini_Set sets a String into their account (file). dini_IntSet sets an Integer into their account (file).
And finally tell them to login.
_________________________________________________
[size=15px]For the login command:[/size]
Check if they're already logged:
dini_Get gets a string from a file.
Set them to logged:
dini_Int gets an integer from a file. Set their admin level:
And finish the command:
_________________________________________________
[size=15px]Simple /kick command:[/size]
Check their level is correct:
_________________________________________________
[size=15px]FYI:[/size]
Gets the value of a string.
string[6] (6 = char in which to start) would be "11aa". The value of it would be 11.
Make sure to set their admin level to 0 when they login!
pawn Код:
#include <dini>
pawn Код:
enum pInfo
{
logged,
admin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
_________________________________________________
[size=15px]For the regster command:[/size]
pawn Код:
if(strcmp("/register", cmdtext, true, 9) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts/%s.acc", pname); //format "string" as where you save the account too
//this isn't nessessary but it makes life easyer.
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
pawn Код:
if(dini_Exists(string) == 1) return SendClientMessage(playerid, red, "Your account is registered, please /login"); // account already exists
if(strlen(cmdtext[10]) == 0) return SendClientMessage(playerid, red, "Usage: /register [password]");
if(strlen(cmdtext[12]) == 0) return SendClientMessage(playerid, red, "Your password is not long enough"); // their pass must be more then 2 chars
pawn Код:
dini_Create(string); // create their account
dini_Set(string, "password", cmdtext[10]); // put their pass in it
dini_IntSet(string, "admin", 0); // create an admin level variable
pawn Код:
format(string, sizeof(string), "Welcome %s, you may now /login", pname);
SendClientMessage(playerid, yellow, string);
return 1;
}
[size=15px]For the login command:[/size]
pawn Код:
if(strcmp("/login", cmdtext, true, 6) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts//%s.acc", pname);
pawn Код:
if(PlayerInfo[playerid][logged] == 1) return SendClientMessage(playerid, red, "You are already logged in");
pawn Код:
if(dini_Exists(string) == 0) return SendClientMessage(playerid, red, "You do not have an account, please /register"); // their account (file with their name) does not exist
if(strlen(cmdtext[7]) == 0) return SendClientMessage(playerid, red, "Usage: /login [password]");
if(strcmp(dini_Get(string, "password"), cmdtext[7], true) != 0) return SendClientMessage(playerid, red, "Passwords did not match"); // pass they entered and pass in the file
pawn Код:
PlayerInfo[playerid][logged] = 1;
pawn Код:
PlayerInfo[playerid][admin] = dini_Int(string, "admin");
pawn Код:
return 1;
}
[size=15px]Simple /kick command:[/size]
pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0)
{
new pname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "accounts//%s.acc", pname);
pawn Код:
if(dini_Int(string, "admin") != 1) return SendClientMessage(playerid, red, "You are not a level 1 admin!"); // they where not level 1
// include more checks to see if they're connected and all that
Kick(strval(cmdtext[5])); // kick them
//tell everyone they're kicked
return 1;
}
[size=15px]FYI:[/size]
pawn Код:
strval
pawn Код:
new string[128];
0123456789
string = "hello 11aa".
Make sure to set their admin level to 0 when they login!