PHP код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <foreach>
#include "../include/gl_spawns.inc"
#include "../include/gl_common.inc"
#include <float>
#include <core>
#include <sscanf2>
#include <streamer>
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_DATABASE "myserver"
#define MYSQL_PASSWORD ""
#define SPAWN_X 1685.6680
#define SPAWN_Y -2332.9236
#define SPAWN_Z 13.5469
#define SPAWN_A 2.3834
#define COLOR_WHITE 0xFFFFFFFF
#define GAMETEXT_COLOR 1
enum
{
LoginDialog,
RegisterDialog,
AgeDialog,
GenderDialog,
EmailDialog
};
new
mysql;
native WP_Hash(buffer[], len, const str[]);
enum PlayerData
{
ID,
Name[MAX_PLAYER_NAME],
Password[129],
IP[16],
Admin,
VIP,
Money,
Float:posX,
Float:posY,
Float:posZ,
Float:posA
};
new Player[MAX_PLAYERS][PlayerData];
public OnGameModeInit()
{
AddPlayerClass(0,1685.6680,-2332.9236,13.5469,2.3834,0,0,0,0,0,0);
mysql_log(LOG_ALL);
mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
if(mysql_errno() != 0)
{
printf("[MySQL] The connection has failed.");
}
else
{
printf("[MySQL] The connection was successful.");
}
return 1;
}
public OnPlayerConnect(playerid)
{
SetPlayerColor(playerid, COLOR_WHITE);
SendClientMessage(playerid,COLOR_WHITE,"{FFFFFF}Welcome to {0000CD}Indonesia Real Life Roleplay");
SendClientMessage(playerid,COLOR_WHITE,"{FFFFFF}Visit {00FF00}www.new.IRL-RP.com {FFFFFF}to register new character!");
new
query[128],
playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
return true;
}
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new
rows,
fields,
name[MAX_PLAYER_NAME];
cache_get_data(rows, fields, mysql);
GetPlayerName(playerid,name,sizeof(name));
if(rows)
{
new string1[400],string[400],ip[50];
GetPlayerIp(playerid, ip, sizeof(ip));
cache_get_field_content(0, "Password", Player[playerid][Password], mysql, 129);
Player[playerid][ID] = cache_get_field_content_int(0, "ID");
format(string, 128, "{FF0000}Indonesia Real Life Roleplay\n\n");
strcat(string1,string);
format(string, 128, "{FFFFFF}Nama : {FF0000}%s\n{FFFFFF}IP : {FF0000}%s", name, ip);
strcat(string1,string);
format(string, 128, "\n\n{FFFFFF}Silahkan masukkan password anda untuk melakukan Log In pada server.\n");
strcat(string1,string);
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT,"{FF0000}Indonesia Real Life Roleplay - {FF0000}Login",string1,"Log-in","Quit");
}
else
{
new string1[400],string[400],ip[50];
GetPlayerIp(playerid, ip, sizeof(ip));
format(string, 128, "{FF0000}Indonesia Real Life Roleplay\n\n");
strcat(string1,string);
format(string, 128, "{FFFFFF}Nama : {FF0000}%s\n{FFFFFF}IP : {FF0000}%s", name, ip);
strcat(string1,string);
format(string, 128, "\n\n{FFFFFF}Silahkan masukkan password anda untuk melakukan registrasi pada server ini.\n");
strcat(string1,string);
ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_LIST,"{FF0000}Indonesia Real Life Roleplay - {FF0000}Register",string1,"Register","Quit");
}
return true;
}
public OnPlayerDisconnect(playerid, reason)
{
new
query[128],
Float:pos[4];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
GetPlayerFacingAngle(playerid, pos[3]);
mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Money` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f WHERE `ID` = %d",
GetPlayerMoney(playerid), pos[0], pos[1], pos[2], pos[3], Player[playerid][ID]);
mysql_tquery(mysql, query, "", "");
TextDrawHideForPlayer(playerid, Time), TextDrawHideForPlayer(playerid, Date), TextDrawHideForPlayer(playerid, IRLRP);
return true;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case LoginDialog:
{
if(!response) Kick(playerid);
new
hashpass[129],
query[100],
name[MAX_PLAYER_NAME],
playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(playerid,name,sizeof(name));
WP_Hash(hashpass, sizeof(hashpass), inputtext);
if(!strcmp(hashpass, Player[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
}
else
{
new string1[400],string[400],ip[50];
GetPlayerIp(playerid, ip, sizeof(ip));
SendClientMessage(playerid, -1, "You have specified an incorrect password!");
format(string, 128, "{FF0000}Indonesia Real Life Roleplay\n\n");
strcat(string1,string);
format(string, 128, "{FFFFFF}Nama : {FF0000}%s\n{FFFFFF}IP : {FF0000}%s", name, ip);
strcat(string1,string);
format(string, 128, "\n\n{FFFFFF}Silahkan masukkan password anda untuk melakukan Log In pada server.\n");
strcat(string1,string);
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT,"{FF0000}Indonesia Real Life Roleplay - {FF0000}Login",string1,"Log-in","Quit");
}
}
case RegisterDialog:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 5)
{
SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
new string1[400],string[400],ip[50],name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
GetPlayerIp(playerid, ip, sizeof(ip));
format(string, 128, "{FF0000}Indonesia Real Life Roleplay\n\n");
strcat(string1,string);
format(string, 128, "{FFFFFF}Nama : {FF0000}%s\n{FFFFFF}IP : {FF0000}%s", name, ip);
strcat(string1,string);
format(string, 128, "\n\n{FFFFFF}Silahkan masukkan password anda untuk melakukan registrasi pada server ini.\n");
strcat(string1,string);
return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT,"{FF0000}Indonesia Real Life Roleplay - {FF0000}Register",string1,"Register","Quit");
}
new
query[512],
playername[MAX_PLAYER_NAME],
playerip[16];
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerIp(playerid, playerip, sizeof(playerip));
WP_Hash(Player[playerid][Password], 129, inputtext);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)", playername, Player[playerid][Password], playerip, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
}
}
return false;
}
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
new name[MAX_PLAYER_NAME];
new string[500];
GetPlayerName(playerid,name,sizeof(name));
Player[playerid][Admin] = cache_get_field_content_int(0, "Admin");
Player[playerid][VIP] = cache_get_field_content_int(0, "VIP");
Player[playerid][Money] = cache_get_field_content_int(0, "Money");
Player[playerid][posX] = cache_get_field_content_float(0, "PosX");
Player[playerid][posY] = cache_get_field_content_float(0, "PosY");
Player[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
Player[playerid][posA] = cache_get_field_content_float(0, "PosA");
GivePlayerMoney(playerid, Player[playerid][Money]);
SetSpawnInfo(playerid, 0, 61, Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
format(string, sizeof(string), "{0000CD}[SERVER] {FFFFFF}Welcome Back {00FF00}%s, {FFFFFF}you are now logged in.", name);
SendClientMessage(playerid, -1, string);
return true;
}
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
new name[MAX_PLAYER_NAME];
new string[500];
GetPlayerName(playerid,name,sizeof(name));
Player[playerid][ID] = cache_insert_id();
printf("[Registration] New account registered. Database ID: [%d]", Player[playerid][ID]);
SetSpawnInfo(playerid, 0, 61, SPAWN_X, SPAWN_Y, SPAWN_Z, SPAWN_A, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
format(string, sizeof(string), "{0000CD}[SERVER] {FFFFFF}Welcome New Player {00FF00}%s, {FFFFFF}you are registered now.", name);
SendClientMessage(playerid, -1, string);
return true;
}
How to add GenderDialog after create new password in RegisterDialog and add AgeDialog after select Gender in Gender Dialog??