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_HOST, SQL_USER, SQL_DB, SQL_PASS);
if(mysql_errno()!=0)
{
printf("MySQL Connection failed");
}
else
{
printf("MySQL Connection connected");
}
LoadGroups();
return 1;
}
public OnPlayerConnect(playerid)
{
TogglePlayerSpectating(playerid, true);
new
query[128];
mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", GetName(playerid));
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
return 1;
}
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new
rows,
fields,
string[120];
cache_get_data(rows,fields,mysql);
format(string, 120, "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(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Login" , "Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Register", string, "Register" , "Quit");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_LOGIN:
{
if(!response) Kick(playerid);
new
hashpass[129],
query[100],
string[120];
WP_Hash(hashpass, sizeof(hashpass),inputtext);
if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1",GetName(playerid));
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
}
else
{
format(string, 120, "Welcome, %s!\nPlease type in your password to continue.", GetName(playerid));
SendClientMessage(playerid, -1, "You have specified an incorrect password");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Login" , "Quit");
}
}
case DIALOG_REGISTER:
{
if(!response) Kick(playerid);
if(strlen(inputtext) < 5)
{
new string[120];
format(string, 120, "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(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", string, "Register", "Quit");
}
new
query[512],
playerip[16];
GetPlayerIp(playerid, playerip, 16);
WP_Hash(PlayerInfo[playerid][Password],129,inputtext);
mysql_format(mysql, query, sizeof(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(mysql, query, "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(playerid, false);
GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
SetSpawnInfo(playerid, 0, 299, SPAWN_X, SPAWN_Y, SPAWN_Z, 0.0, 0, 0, 0, 0, 0, 0);
SetPlayerInterior(playerid, SPAWN_INT);
SetPlayerVirtualWorld(playerid, SPAWN_VW);
SpawnPlayer(playerid);
SendClientMessage(playerid, -1, "Welcome to "SV_NAME" "SV_MODE_ABREV"!");
SetPlayerHealth(playerid, 999999);
SetPlayerArmour(playerid, 999999);
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(playerid, false);
SetSpawnInfo(playerid, 0, 299, SPAWN_X, SPAWN_Y, SPAWN_Z, 0.0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SendClientMessage(playerid, -1, "Welcome to "SV_NAME" "SV_MODE_ABREV"!");
SetPlayerHealth(playerid, 999999);
SetPlayerArmour(playerid, 999999);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new
query[128];
mysql_format(mysql, query, sizeof(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(mysql, query,"","");
FloodByPlayer[playerid] = 0;
KillTimer(FloodTimer[playerid]);
if(PlayerNeedsHelp[playerid] == 1)
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(PlayerInfo[i][Admin] > 0)
{
SendClientMessage(i, 0x00FF00FF, "The player who made the report has left the server.");
}
}
PlayerNeedsHelp[playerid] = 0;
}
for(new i = 0; i < MAX_REPORTS; i ++)
{
if(ReportInfo[i][rExists] && ReportInfo[i][rReporter] == playerid)
{
ReportInfo[i][rExists] = 0;
}
}
return 1;
}
PHP код:
SaveStats(playerid)
{
new query[128], name[MAX_PLAYER_NAME], i = PlayerInfo[playerid][Group];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
if(Iter_Contains(Gangs, i) && i != -1)
mysql_format(mysql, query, sizeof(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(mysql, query, sizeof(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(mysql, query,"","");
return 1;
}