Код:
OnPlayerConnect
{
mysql_format(mysql, query, sizeof(query),"SELECT `Password` FROM `players` WHERE `Username` = '%e'", GetName(playerid));
mysql_tquery(mysql, query, "CheckPlayer", "i", playerid);
}
forward CheckPlayer(playerid);
public CheckPlayer(playerid)
{
if(strfind(GetName(playerid), "kontol", true) != -1 || strfind(GetName(playerid), "memek", true) != -1 || strfind(GetName(playerid), "anjing", true) != -1 || strfind(GetName(playerid), "server", true) != -1)
{
SCM(playerid, -1, server"{FF2400}sorry, you can not join this server because your name");
}
else
{
new rows, fields,string[400];
cache_get_data(rows, fields, mysql);
if(rows)
{
format(string, sizeof(string),"{FFFFFF}Welcome to the server \n\nAccount Name: %s \nStatus: {00FF00}registered{ffffff}\nplease enter the password in the box provided below:", GetName(playerid));
cache_get_field_content(0, "Password", PlayerInfo[playerid][Password], mysql, 129);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login Dialog",string,"Login","");
}
else
{
format(string, sizeof(string),"{FFFFFF}Welcome to the server \n\nAccount Name: %s \nStatus: not{FF0000}register{ffffff}\nplease enter the password in the box provided below:", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register Dialog",string,"Register","");
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
new string[200];
if(!response)
{
SCM(playerid, -1, warning"Kamu tidak register, kicked!");
KickEx(playerid);
}
if (strlen(inputtext) < 4 || strlen(inputtext) > 20)
{
format(string, sizeof(string),"{FFFFFF}Welcome to the server \n\nAccount Name: %s \nStatus: not{FF0000}register{ffffff}\nplease enter the password in the box provided below:", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register Dialog",string,"Register","");
}
new query[600];
WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES ('%e','%e','%e')", GetName(playerid),PlayerInfo[playerid][Password],GetIP(playerid));
mysql_tquery(mysql, query, "RegisterPlayer", "i", playerid);
}
case DIALOG_LOGIN:
{
if(response)
{
new hpass[129],query[254];
WP_Hash(hpass, 129, inputtext);
if(!strcmp(hpass, PlayerInfo[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GetName(playerid));
mysql_tquery(mysql, query, "LoadPlayer", "i", playerid);
}
else
{
format(query, sizeof(query),"{FFFFFF}Welcome to the server \n\nAccount Name: %s\nStatus: {00FF00}registered{ffffff}\nplease enter the password in the box provided below:", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login Dialog",query,"Login","");
}
}
else
{
SCM(playerid, -1, warning"Kamu tidak login, kicked!");
KickEx(playerid);
}
}
}
return 1;
}
forward RegisterPlayer(playerid);
public RegisterPlayer(playerid)
{
new str[254];
SCM(playerid, -1, account"Successfully registered.");
PlayerInfo[playerid][ID] = cache_insert_id();
PlayerInfo[playerid][Logged] = 1;
return 1;
}
forward LoadPlayer(playerid);
public LoadPlayer(playerid)
{
new str[254];
SCM(playerid, -1, account"Successfully Loaded.");
PlayerInfo[playerid][Logged] = 1;
return 1;
}