Register Account System (MySQL)
#1

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:
PHP код:
CREATE TABLE IF NOT EXISTS `Players` (
  `
UIDbigint(20NOT NULL AUTO_INCREMENT,
  `
Namevarchar(24COLLATE cp1251_bin NOT NULL,
  `
Keyvarchar(32COLLATE cp1251_bin NOT NULL,
  `
Levelint(11NOT NULL,
  
PRIMARY KEY (`UID`)
ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bin AUTO_INCREMENT=
>> #include
PHP код:
#include <a_mysql> 
>> #define
PHP код:
#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_DB   "database"
#define MySQL_PASS "" 
>> enum
PHP код:
enum pInfo
{
pUID,
pKey[15],
pPassWrong,
pLoggedPlayer,
pLevel,
};
new 
Player[MAX_PLAYERS][pInfo]; 
>> public OnGameModeInit()
PHP код:
mysql_connect(MySQL_HOSTMySQL_USERMySQL_DBMySQL_PASS); 
>> public OnGameModeExit()
PHP код:
public OnGameModeExit()
{
    
mysql_close();
    return 
1;

>> public OnPlayerRequestClass(playerid, classid)
PHP код:
    new query[128], string[128];
     
format(querysizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s' LIMIT 1"PlayerName(playerid));
     if(
mysql_query(query) && mysql_store_result() && mysql_num_rows())
     {
          
format(stringsizeof(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(stringsizeof(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(); 
>> public OnPlayerConnect(playerid):
PHP код:
Player[playerid][pPassWrong] = 0;
Player[playerid][pLoggedPlayer] = 0;
Player[playerid][pLevel] = 0
>> public OnPlayerDisconnect(playerid, reason)
PHP код:
if(Player[playerid][pLoggedPlayer] == 1)return OnPlayerUpdateEx(playerid); 
>> public OnPlayerSpawn(playerid)
PHP код:
if(Player[playerid][pLoggedPlayer] == 0)return Kick(playerid); 
>> public OnPlayerText(playerid, text[])
PHP код:
if(Player[playerid][pLoggedPlayer] == 0) return 0
>> public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
PHP код:
    new string[256], password[64];
    if(
dialogid == 0)
    {
        if(!
response)return SendClientMessage(playerid, -1"Exit, (/q)"), Kick(playerid);
        if(!
strlen(inputtext))
        {
            
format(stringsizeof(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(playeridpassword);
    }
    if(
dialogid == 1)
    {
        if(!
response)return SendClientMessage(playerid, -1"Exit, (/q)"), Kick(playerid);
        if(!
strlen(inputtext) || strlen(inputtext) < || strlen(inputtext) > 15)
        {
            
format(stringsizeof(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(playeridinputtext), Player[playerid][pLoggedPlayer] = 1;
    }
    if(
dialogid == 2)
    {
        if(
response)
        {
            
format(stringsizeof(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(playeridpassword[])
{
    new 
query[150], name[MAX_PLAYER_NAME], pass[32], string[128];
    
mysql_real_escape_string(PlayerName(playerid), name), mysql_real_escape_string(passwordpass);
    
format(querysizeof(query), "INSERT INTO `Players` (`Name`, `Key`) VALUE ('%s', '%s')"namepass);
    
mysql_query(query), ResetPlayerMoney(playerid);
    
strmid(Player[playerid][pKey], password064255);
    
format(string,sizeof(string),"* Account Registred, your password \"%s\"",password);
    
SendClientMessage(playerid,-1,string);
    
Player[playerid][pLoggedPlayer] = 1SpawnPlayer(playerid),
    
Player[playerid][pLevel] = 1GivePlayerMoney(playerid100);
    
SetPlayerScore(playeridPlayer[playerid][pLevel]);
    return 
1;
}
static 
stock OnPlayerLoginEx(playeridpassword[])
{
    new 
query[128], pass[32], name[24], result[256], wrong[128];
    
mysql_real_escape_string(passwordpass), mysql_real_escape_string(PlayerName(playerid), name);
    
format(querysizeof(query), "SELECT * FROM `Players` WHERE `Name` = '%s' AND `Key` = '%s'"namepass);
    
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(wrongsizeof(wrong), "Wrong Password.\n>> %d/5 <<"Player[playerid][pPassWrong]);
            
ShowPlayerDialog(playerid2DIALOG_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(querysizeof(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, -1query);
    
Player[playerid][pLoggedPlayer] = 1SpawnPlayer(playerid);
    
SetPlayerScore(playerid,Player[playerid][pLevel]);
    return 
1;
}
static 
stock OnPlayerUpdateEx(playerid)
{
    if(
Player[playerid][pLoggedPlayer] == 1)
    {
        if(
mysql_ping() == -1mysql_reconnect();
        new 
query[256], str[128];
        
strcat(query"UPDATE `Players` SET ");
        
format(strsizeof(str), "`Level` = '%i' WHERE `Name` = '%s'"Player[playerid][pLevel], PlayerName(playerid)); strcat(querystr);
        print(
"Account Save'ed!!!");
        
mysql_query(query);
    }
    return 
1;
}
static 
stock MySQLGetInt(data[], &variable)
{
    new 
request[128];
    
mysql_fetch_field_row(requestdata);
    
variable strval(request);
}
static 
stock PlayerName(playerid) { new pname[MAX_PLAYER_NAME]; GetPlayerName(playerid,pname,sizeof(pname)); return pname; } 
Author: Jeff_Hardy
Reply
#2

This is an english speaking forum
Reply
#3

I think his editing the post now xD
Reply
#4

Well I translate a post on English!
Reply
#5

GTABBS jeff_hardy?
Reply
#6

Nice work
Reply
#7

Quote:
Originally Posted by Soap_MacTavish
Посмотреть сообщение
GTABBS jeff_hardy?
&

What ?
Reply
#8

Up!!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)