PHP Code:
hook OnPlayerConnect(playerid)
{
new
Query[ 150 ],
DBResult: Result,
name[ MAX_PLAYER_NAME ]
;
new
ipstring[16],
ipbyte[4];
// SPAWN INFO
SetSpawnInfo(playerid, NO_TEAM, 0, DEFAULT_POS_X, DEFAULT_POS_Y, DEFAULT_POS_Z, 0.0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
//
GetPlayerIp(playerid, ipstring, 16);
BanCheck(playerid);
sscanf(ipstring, "p<.>a<d>[4]", ipbyte);
Player_IP[playerid] = ((ipbyte[0] << 24) | (ipbyte[1] << 16) | (ipbyte[2] << 8) | ipbyte[3]);
GetPlayerName(playerid, name, sizeof(name));
format(Query, sizeof(Query), "SELECT `name` FROM `users` WHERE `name` = '%s'", DB_Escape(name));
Result = db_query(MainDB, Query);
if(db_num_rows(Result))
{
inline Response(pid, dialogid, response, listitem, string:inputtext[])
{
#pragma unused pid, dialogid, listitem
if(response)
{
if(strlen(inputtext) > 24 || strlen(inputtext) < 3)
{
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password.", name, playerid);
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "{FFFFFF}Register System", Query, "Register", "Leave");
SendClientMessage(playerid, -1, "Your password length must be from 3 - 24 characters!");
}
else
{
format(Query, sizeof(Query), "INSERT INTO `users` (`name`, `password`, `ip`, `Level`, `cash`, `adminlevel`) VALUES('%s','%s','%d','1','500','0')", DB_Escape(name), DB_Escape(inputtext), GetPlayerIpAsInt(playerid));
db_query(MainDB, Query);
SetPVarInt(playerid, "LoggedIn", 1);
GivePlayerMoney(playerid, 500);
SetPlayerScore(playerid, 0);
SendClientMessage(playerid, -1, "You have "COL_GREEN"successfully{FFFFFF} registered! You have been automatically logged in!");
}
}
}
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting your password.", name, playerid);
Dialog_ShowCallback(playerid, using inline Response, DIALOG_STYLE_INPUT, "{FFFFFF}Register System", Query, "Login", "Leave");
}
else
{
inline Response(pid, dialogid, response, listitem, string:inputtext[])
{
#pragma unused pid, dialogid, listitem
if(response)
{
format(Query, sizeof(Query), "SELECT * FROM `users` WHERE `name` = '%s' AND `password` = '%s'", DB_Escape(name), DB_Escape(inputtext));
Result = db_query(MainDB, Query);
if(db_num_rows(Result))
{
SetPVarInt(playerid, "SQLID", db_get_field_assoc_int(Result, "sqlid"));
SetPVarInt(playerid, "Level", db_get_field_assoc_int(Result, "Level"));
SetPlayerScore(playerid, GetPVarInt(playerid, "Level"));
SetPVarInt(playerid, "Admin", db_get_field_assoc_int(Result, "adminlevel"));
SetPVarInt(playerid, "Cash", db_get_field_assoc_int(Result, "cash"));
GivePlayerMoney(playerid, GetPVarInt(playerid, "Cash"));
SetPVarInt(playerid, "LoggedIn", 1);
SendPlayerToSpawn(playerid);
SendClientMessage(playerid, -1, "Tqven Warmatebit Giaret "COL_GREEN"Avtorizacia{FFFFFF}");
}
else
{
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting your password.", name, playerid);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{FFFFFF}Register System", Query, "Login", "Leave");
SendClientMessage(playerid, -1, ""COL_RED"Araswori{FFFFFF} Paroli, Scadet Axlidan!");
}
}
else Kick(playerid);
}
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password.", name, playerid);
Dialog_ShowCallback(playerid, using inline Response, DIALOG_STYLE_INPUT, "{FFFFFF}Register System", Query, "Register", "Leave");
}
db_free_result(Result);
//db_free_result_hook(Result);
return 1;
}