16.07.2012, 09:19
H1, I represent you system of registration of an account on mysql
It approaches as well as to new.pwn and to GF.
+ (SQL inject).
>> Data Base:
>> #include
>> #define
>> enum
>> public OnGameModeInit()
>> public OnGameModeExit()
>> public OnPlayerRequestClass(playerid, classid)
>> public OnPlayerConnect(playerid):
>> public OnPlayerDisconnect(playerid, reason)
>> public OnPlayerSpawn(playerid)
>> public OnPlayerText(playerid, text[])
>> public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
Author: Jeff_Hardy
It approaches as well as to new.pwn and to GF.
+ (SQL inject).
>> Data Base:
PHP код:
CREATE TABLE IF NOT EXISTS `Players` (
`UID` bigint(20) NOT NULL AUTO_INCREMENT,
`Name` varchar(24) COLLATE cp1251_bin NOT NULL,
`Key` varchar(32) COLLATE cp1251_bin NOT NULL,
`Level` int(11) NOT NULL,
PRIMARY KEY (`UID`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bin AUTO_INCREMENT=1 ;
PHP код:
#include <a_mysql>
PHP код:
#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_DB "database"
#define MySQL_PASS ""
PHP код:
enum pInfo
{
pUID,
pKey[15],
pPassWrong,
pLoggedPlayer,
pLevel,
};
new Player[MAX_PLAYERS][pInfo];
PHP код:
mysql_connect(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS);
PHP код:
public OnGameModeExit()
{
mysql_close();
return 1;
}
PHP код:
new query[128], string[128];
format(query, sizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s' LIMIT 1", PlayerName(playerid));
if(mysql_query(query) && mysql_store_result() && mysql_num_rows())
{
format(string, sizeof(string),"Welcome to ther Server!.\nNick name: %s,\n\nEnter the password", PlayerName(playerid));
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Authorization",string,"Go","X");
}
else
{
format(string, sizeof(string),"Welcome to ther Server!\nNick name: %s, not registred.\n\nThe password should be from 6 to 15 symbols.", PlayerName(playerid));
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register new Account",string,"Next","X");
}
mysql_free_result();
PHP код:
Player[playerid][pPassWrong] = 0;
Player[playerid][pLoggedPlayer] = 0;
Player[playerid][pLevel] = 0;
PHP код:
if(Player[playerid][pLoggedPlayer] == 1)return OnPlayerUpdateEx(playerid);
PHP код:
if(Player[playerid][pLoggedPlayer] == 0)return Kick(playerid);
PHP код:
if(Player[playerid][pLoggedPlayer] == 0) return 0;
PHP код:
new string[256], password[64];
if(dialogid == 0)
{
if(!response)return SendClientMessage(playerid, -1, "Exit, (/q)"), Kick(playerid);
if(!strlen(inputtext))
{
format(string, sizeof(string),"Welcome to ther Server!.\nNick name: %s,\n\nEnter the password", PlayerName(playerid));
return ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Authorization",string,"Go","X");
}
OnPlayerLoginEx(playerid, password);
}
if(dialogid == 1)
{
if(!response)return SendClientMessage(playerid, -1, "Exit, (/q)"), Kick(playerid);
if(!strlen(inputtext) || strlen(inputtext) < 6 || strlen(inputtext) > 15)
{
format(string, sizeof(string),"Welcome to ther Server!\nNick name: %s, not registred.\n\nThe password should be from 6 to 15 symbols.", PlayerName(playerid));
return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register New Account",string,"Next","X");
}
OnPlayerRegisterEx(playerid, inputtext), Player[playerid][pLoggedPlayer] = 1;
}
if(dialogid == 2)
{
if(response)
{
format(string, sizeof(string),"Welcome to ther Server!.\nNick name: %s,\n\nEnter the password", PlayerName(playerid));
return ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Authorization",string,"Go","X");
}
else return SendClientMessage(playerid, -1, "Exit, (/q)"), Kick(playerid);
}
PHP код:
static stock OnPlayerRegisterEx(playerid, password[])
{
new query[150], name[MAX_PLAYER_NAME], pass[32], string[128];
mysql_real_escape_string(PlayerName(playerid), name), mysql_real_escape_string(password, pass);
format(query, sizeof(query), "INSERT INTO `Players` (`Name`, `Key`) VALUE ('%s', '%s')", name, pass);
mysql_query(query), ResetPlayerMoney(playerid);
strmid(Player[playerid][pKey], password, 0, 64, 255);
format(string,sizeof(string),"* Account Registred, your password \"%s\"",password);
SendClientMessage(playerid,-1,string);
Player[playerid][pLoggedPlayer] = 1, SpawnPlayer(playerid),
Player[playerid][pLevel] = 1, GivePlayerMoney(playerid, 100);
SetPlayerScore(playerid, Player[playerid][pLevel]);
return 1;
}
static stock OnPlayerLoginEx(playerid, password[])
{
new query[128], pass[32], name[24], result[256], wrong[128];
mysql_real_escape_string(password, pass), mysql_real_escape_string(PlayerName(playerid), name);
format(query, sizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s' AND `Key` = '%s'", name, pass);
mysql_query(query);
mysql_store_result();
if(mysql_query(query) && mysql_store_result())
{
if(mysql_num_rows())
{
if(mysql_fetch_row_format(result))
{
OnPlayerLoginCallBack(playerid);
}
}
else
{
if(Player[playerid][pPassWrong] == 5)return SendClientMessage(playerid, -1, "* Wrong password of 5 times (/q)!"), Kick(playerid);
Player[playerid][pPassWrong] ++;
format(wrong, sizeof(wrong), "Wrong Password.\n>> %d/5 <<", 5 - Player[playerid][pPassWrong]);
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_MSGBOX, "Wrong", wrong, "Ok", "X");
}
}
mysql_free_result();
return 1;
}
static stock OnPlayerLoginCallBack(playerid)
{
new query[128], name[24];
mysql_real_escape_string(PlayerName(playerid), name);
format(query, sizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s'", name);
mysql_query(query);
mysql_store_result();
MySQLGetInt("Level", Player[playerid][pLevel]);
mysql_free_result();
format(query,sizeof(query), "* Welcome %s",
PlayerName(playerid)), SendClientMessage(playerid, -1, query);
Player[playerid][pLoggedPlayer] = 1, SpawnPlayer(playerid);
SetPlayerScore(playerid,Player[playerid][pLevel]);
return 1;
}
static stock OnPlayerUpdateEx(playerid)
{
if(Player[playerid][pLoggedPlayer] == 1)
{
if(mysql_ping() == -1) mysql_reconnect();
new query[256], str[128];
strcat(query, "UPDATE `Players` SET ");
format(str, sizeof(str), "`Level` = '%i' WHERE `Name` = '%s'", Player[playerid][pLevel], PlayerName(playerid)); strcat(query, str);
print("Account Save'ed!!!");
mysql_query(query);
}
return 1;
}
static stock MySQLGetInt(data[], &variable)
{
new request[128];
mysql_fetch_field_row(request, data);
variable = strval(request);
}
static stock PlayerName(playerid) { new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid,pname,sizeof(pname)); return pname; }