mySQL saving
#6

PHP код:
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_DB "deathmatch"
#define SQL_PASS ""

new    mysql;

native WP_Hash(buffer[],len,const str[]);

enum pInfo
{
    
ID,
    
Name[MAX_PLAYER_NAME],
    
Password[129],
    
IP[16],
    
Admin,
    
VIP,
    
Money,
    
Group,
    
GroupRank,
    
Kills,
    
Deaths,
    
Score,
    
HighKS
}
new 
PlayerInfo[MAX_PLAYERS][pInfo];

public 
OnGameModeInit()
{
    
// Don't use these lines if it's a filterscript
    
DisableInteriorEnterExits();
    
SetGameModeText(""SV_MODE" "SV_VERSION"");
    
mysql_log(LOG_ALL);
    
mysql mysql_connect(SQL_HOSTSQL_USERSQL_DBSQL_PASS); 
    if(
mysql_errno()!=0)
    {
        
printf("MySQL Connection failed");
    }
    else
    {
        
printf("MySQL Connection connected");
    }
    
LoadGroups();
    return 
1;
}

public 
OnPlayerConnect(playerid)
{

    
TogglePlayerSpectating(playeridtrue);
    new
        
query[128];

    
mysql_format(mysqlquerysizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1"GetName(playerid));
    
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    return 
1;
}

forward OnAccountCheck(playerid);
public 
OnAccountCheck(playerid)
{
    new
        
rows,
        
fields,
        
string[120];
    
cache_get_data(rows,fields,mysql);

    
format(string120"Welcome, %s!\nPlease type in your password to continue."GetName(playerid));

    if(
rows)
    {
        
cache_get_field_content(0"Password",PlayerInfo[playerid][Password],mysql,129);
        
PlayerInfo[playerid][ID] = cache_get_field_content_int(0"ID");
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT"Login"string"Login" "Quit");
    }
    else
    {
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT"Register"string"Register" "Quit");
    }
    return 
1;
}

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{

    switch(
dialogid)
    {
        case 
DIALOG_LOGIN:
        {
            if(!
responseKick(playerid);

            new
                
hashpass[129],
                
query[100],
                
string[120];

            
WP_Hash(hashpasssizeof(hashpass),inputtext);

            if(!
strcmp(hashpassPlayerInfo[playerid][Password]))
            {
                
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1",GetName(playerid));
                
mysql_tquery(mysqlquery"OnAccountLoad""i"playerid);
            }
            else
            {
                
format(string120"Welcome, %s!\nPlease type in your password to continue."GetName(playerid));
                
SendClientMessage(playerid, -1"You have specified an incorrect password");
                
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT"Login"string"Login" "Quit");
            }
        }
        case 
DIALOG_REGISTER:
        {
            if(!
responseKick(playerid);

            if(
strlen(inputtext) < 5)
            {
                new 
string[120];
                
format(string120"Welcome, %s!\nPlease type in your password to continue."GetName(playerid));
                
SendClientMessage(playerid, -1"Your password must at least contain more than 4 characters");
                return 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Register"string"Register""Quit");
            }
            new
                
query[512],
                
playerip[16];

            
GetPlayerIp(playeridplayerip16);
            
WP_Hash(PlayerInfo[playerid][Password],129,inputtext);
            
mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `Group`, `GroupRank`, `Kills`, `Deaths`, `Score`, `HighKS`) VALUES('%e','%e','%e',0,0,0,0,0)"GetName(playerid), PlayerInfo[playerid][Password],playerip,PlayerInfo[playerid][Kills],PlayerInfo[playerid][Deaths],
                
PlayerInfo[playerid][Score],PlayerInfo[playerid][HighKS]);
            
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid);
        }
       }
}

forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    
PlayerInfo[playerid][Admin] = cache_get_field_content_int(0,"Admin");
    
PlayerInfo[playerid][VIP] = cache_get_field_content_int(0,"VIP");
    
PlayerInfo[playerid][Money] = cache_get_field_content_int(0,"Money");
    
PlayerInfo[playerid][Group] = cache_get_field_content_int(0,"Group");
    
PlayerInfo[playerid][GroupRank] = cache_get_field_content_int(0,"GroupRank");
    
PlayerInfo[playerid][Kills] = cache_get_field_content_int(0,"Kills");
    
PlayerInfo[playerid][Deaths] = cache_get_field_content_int(0,"Deaths");
    
PlayerInfo[playerid][Score] = cache_get_field_content_int(0,"Score");
    
PlayerInfo[playerid][HighKS] = cache_get_field_content_int(0,"HighKS");

    
TogglePlayerSpectating(playeridfalse);

    
GivePlayerMoney(playeridPlayerInfo[playerid][Money]);

    
SetSpawnInfo(playerid0299SPAWN_XSPAWN_YSPAWN_Z0.0000000);
    
SetPlayerInterior(playeridSPAWN_INT);
    
SetPlayerVirtualWorld(playeridSPAWN_VW);
    
SpawnPlayer(playerid);

    
SendClientMessage(playerid, -1"Welcome to "SV_NAME" "SV_MODE_ABREV"!");

    
SetPlayerHealth(playerid999999);
    
SetPlayerArmour(playerid999999);
    return 
1;
}

forward OnAccountRegister(playerid);
public 
OnAccountRegister(playerid)
{
    
PlayerInfo[playerid][ID] = cache_insert_id();
    
printf("[SYS] New account registered. Database ID: [%d]"PlayerInfo[playerid][ID]);

    
TogglePlayerSpectating(playeridfalse);

    
SetSpawnInfo(playerid0299SPAWN_XSPAWN_YSPAWN_Z0.0000000);
    
SpawnPlayer(playerid);

    
SendClientMessage(playerid, -1"Welcome to "SV_NAME" "SV_MODE_ABREV"!");

    
SetPlayerHealth(playerid999999);
    
SetPlayerArmour(playerid999999);
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    new
        
query[128];

    
mysql_format(mysqlquerysizeof(query), "UPDATE `accounts` SET `Money` = %d, `VIP` = %d, `Admin` = %d, `Group` = %d, `GroupRank` = %d, `Kills` = %d, `Deaths` = %d, `Score` = %d, `HighKS` = %d,  WHERE `ID` = %d"
        
GetPlayerMoney(playerid), PlayerInfo[playerid][VIP], PlayerInfo[playerid][Admin], PlayerInfo[playerid][Group], PlayerInfo[playerid][GroupRank], PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Score],
        
PlayerInfo[playerid][HighKS]);
    
mysql_tquery(mysqlquery,"","");
    
FloodByPlayer[playerid] = 0;
    
KillTimer(FloodTimer[playerid]);

    if(
PlayerNeedsHelp[playerid] == 1)
    {
        for(new 
i=0i<MAX_PLAYERSi++)
        {
            if(
PlayerInfo[i][Admin] > 0)
            {
                
SendClientMessage(i0x00FF00FF"The player who made the report has left the server.");
            }
        }
        
PlayerNeedsHelp[playerid] = 0;
    }
    for(new 
0MAX_REPORTS++)
    {
        if(
ReportInfo[i][rExists] && ReportInfo[i][rReporter] == playerid)
        {
            
ReportInfo[i][rExists] = 0;
        }
    }
    return 
1;

SaveStats

PHP код:
SaveStats(playerid)
{
    new 
query[128], name[MAX_PLAYER_NAME], PlayerInfo[playerid][Group];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    if(
Iter_Contains(Gangsi) && != -1)
        
mysql_format(mysqlquerysizeof(query), "UPDATE `accounts` SET `Admin` = %d, `VIP` = %d, `Money` = %d, `Kills` = %d, `Deaths` = %d, `Score` = %d, `HighKS` = %d, `Group` = %d, `Rank` = %d WHERE `ID` = '%d'",
            
PlayerInfo[playerid][Admin], PlayerInfo[playerid][VIP], PlayerInfo[playerid][Money], PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Score], PlayerInfo[playerid][HighKS], PlayerInfo[playerid][Group], PlayerInfo[playerid][GroupRank], PlayerInfo[playerid][ID]);
    else
        
mysql_format(mysqlquerysizeof(query), "UPDATE `accounts` SET `Admin` = %d, `VIP` = %d, `Money` = %d, `Kills` = %d, `Deaths` = %d, `Score` = %d, `HighKS` = %d, `Group` = -1 WHERE `ID` = '%d'",
            
PlayerInfo[playerid][Admin], PlayerInfo[playerid][VIP], PlayerInfo[playerid][Money], PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Score], PlayerInfo[playerid][HighKS], PlayerInfo[playerid][ID]);
    
mysql_tquery(mysqlquery,"","");
    return 
1;

Reply


Messages In This Thread
mySQL saving - by NealPeteros - 02.01.2018, 09:57
Re: mySQL saving - by MEW273 - 02.01.2018, 10:00
Re: mySQL saving - by NealPeteros - 02.01.2018, 10:14
Re: mySQL saving - by NealPeteros - 02.01.2018, 21:50
Re: mySQL saving - by GTLS - 03.01.2018, 07:44
Re: mySQL saving - by NealPeteros - 03.01.2018, 09:56
Re: mySQL saving - by NealPeteros - 05.01.2018, 09:21
Re: mySQL saving - by NealPeteros - 06.01.2018, 07:53
Re: mySQL saving - by NealPeteros - 06.01.2018, 08:09
Re: mySQL saving - by MEW273 - 06.01.2018, 08:10

Forum Jump:


Users browsing this thread: 1 Guest(s)