15.06.2014, 14:08
Hi, I'm an amateur SA:MP scripter and I've started working on a roleplay script.
I'm using mySQL r38 (BlueG's)
This script works fine, everything saves (enums etc)
However when a player gets kicked, all his mySQL tables get reset to 0, I have tried to diagnose (debugging) this problem for days, I have had professional scripters try to help me but they couldn't even find the problem.
There is nothing out of the ordinary in the mysql_log.
.sql file:
Summary:
Everything saves normally on disconnect/gmx but when a player is kicked (enter incorrect password for auto kick) all his mySQL tables get reset to 0 in phpmyadmin
There are also no errors or warnings in the gamemode itself or in mysql_log
Please help me!
I'm using mySQL r38 (BlueG's)
This script works fine, everything saves (enums etc)
However when a player gets kicked, all his mySQL tables get reset to 0, I have tried to diagnose (debugging) this problem for days, I have had professional scripters try to help me but they couldn't even find the problem.
There is nothing out of the ordinary in the mysql_log.
pawn Код:
#include <a_samp>
#include <a_mysql>
#include <sscanf2>
#include <zcmd>
#include <foreach>
/* Connection */
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DB "roleplay"
#define revision "0.2"
#define SCM SendClientMessage
/* Color defines */
#define WHITE 0xFFFFFFAA
#define GRAD1 0xB4B5B7FF
#define GRAD2 0xBFC0C2FF
#define GREY 0xAFAFAFAA
#define GREEN 0x33AA33AA
#define CYAN 0x40FFFFFF
#define DARKRED 0xAA3333AA
#define RED 0xFF0000AA
#define LIGHTRED 0xFF6347AA
#define LIGHTYELLOW 0xFFFF91FF
#define BLACK 0x000001FF
#define BLUE 0x007BD0FF
#define LIGHTRED 0xFF6347AA
#define LIGHTBLUE 0x33CCFFAA
#define LIGHTGREEN 0x9ACD32AA
#define YELLOW 0xFFFF00AA
#define WHITE 0xFFFFFFAA
#define PURPLE 0xC2A2DAAA
#define DBLUE 0x2641FEAA
/* Dialog defines */
#define DIALOG_LOGIN 0
#define DIALOG_REGISTER 1
/* Admin level defines */
#define ADMIN_L1 (1)
#define ADMIN_L2 (2)
#define ADMIN_L3 (3)
#define ADMIN_L4 (4)
#define ADMIN_L5 (5)
#define ADMIN_L6 (6)
/* Enumerators */
enum pInfo
{
pUsername[24],
pPassword[64],
pIP[16],
pMoney,
pAdmin,
pVip,
pKills,
pDeaths,
pLogged,
pScore,
Float:PosX,
Float:PosY,
Float:PosZ,
pSkin
};
/* Global variables */
new dbHandle;
new InvalidPass[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][pInfo];
new standardchat = 1;
/* Forwards */
forward KickEx(playerid);
forward ABroadCast(color, const string[], level);
/* Stocks */
stock pName(playerid)
{
new gName[MAX_PLAYER_NAME];
GetPlayerName( playerid, gName, sizeof gName );
return gName;
}
stock ErrorMessage(playerid, text[])
{
new string[128];
format(string, sizeof(string), "{00FF9A}Error:{FFFFFF} %s", text);
return SendClientMessage(playerid, WHITE, string);
}
stock GetAdminRank(playerid)
{
new rank[50];
switch(PlayerInfo[playerid][pAdmin])
{
case 0: { format(rank, sizeof(rank), "Player"); }
case 1: { format(rank, sizeof(rank), "Secret Admin"); }
case 2: { format(rank, sizeof(rank), "Junior Admin"); }
case 3: { format(rank, sizeof(rank), "General Admin"); }
case 4: { format(rank, sizeof(rank), "Senior Admin"); }
case 5: { format(rank, sizeof(rank), "Head Admin"); }
case 6: { format(rank, sizeof(rank), "Executive Admin"); }
}
return rank;
}
stock AuthorityMessage(playerid)
{
SCM(playerid, WHITE, "You are not authorized to use that command.");
return 1;
}
stock LoginMessage(playerid)
{
SCM(playerid, WHITE, "You must be logged in to use this command.");
return 1;
}
stock IsPlayerLoggedIn(playerid)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pLogged] != 0)
{
return 1;
} else return 0;
} else return 0;
}
// Function: Remove's the '_' from the player's name.
stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
return 1;
}
//Gets players name without underscore for RP text
stock GetPlayerNameEx(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, 24);
strreplace(name, '_', ' ');
return name;
}
stock ClearChat(playerid)
{
for(new i = 0; i < 50; i++)
{
SCM(playerid, -1, "");
}
return 1;
}
stock MySQL_Register(playerid, passwordstring[])
{
new Query[512],
IP[16];
GetPlayerIp(playerid, IP, sizeof(IP));
strcat(Query,"INSERT INTO `PlayerData`(`Username`,`Password`,`pMoney`,`pAdmin`,`pVip`,`pKills`,`pDeaths`,`pIP`,`pScore`)");
strcat(Query," VALUES ('%s', SHA1('%s'), 0, 0, 0, 0, 0, '%s', 0)");
mysql_format(dbHandle, Query,sizeof(Query), Query, pName(playerid), passwordstring,IP);
mysql_query(dbHandle, Query, false);
ClearChat(playerid);
SCM(playerid, -1, "You have successfully registered an account!");
//need to add spawn info for this aka newbie spawn
PlayerInfo[playerid][pLogged] = 1;
return 1;
}
stock MySQL_Login(playerid)
{
if(IsPlayerConnected(playerid))
{
new Query[512],
savestr[50],
rows,
fields;
mysql_format(dbHandle, Query, sizeof(Query), "SELECT * FROM `PlayerData` WHERE `Username` = '%s'", pName(playerid));
mysql_query(dbHandle, Query);
cache_get_data(rows, fields);
if(rows)
{
cache_get_field_content(0, "pMoney", savestr); PlayerInfo[playerid][pMoney] = strval(savestr);
cache_get_field_content(0, "pAdmin", savestr); PlayerInfo[playerid][pAdmin] = strval(savestr);
cache_get_field_content(0, "pVip", savestr); PlayerInfo[playerid][pVip] = strval(savestr);
cache_get_field_content(0, "pKills", savestr); PlayerInfo[playerid][pKills] = strval(savestr);
cache_get_field_content(0, "pDeaths", savestr); PlayerInfo[playerid][pDeaths] = strval(savestr);
cache_get_field_content(0, "pScore", savestr); PlayerInfo[playerid][pScore] = strval(savestr);
cache_get_field_content(0, "PosX", savestr); PlayerInfo[playerid][PosX] = strval(savestr);
cache_get_field_content(0, "PosY", savestr); PlayerInfo[playerid][PosY] = strval(savestr);
cache_get_field_content(0, "PosZ", savestr); PlayerInfo[playerid][PosZ] = strval(savestr);
cache_get_field_content(0, "pSkin", savestr); PlayerInfo[playerid][pSkin] = strval(savestr);
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ], 0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
PlayerInfo[playerid][pLogged] = 1;
}
/*new Float:kd = floatdiv(PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths]);
new str1[300];
format(str1,sizeof(str1),"User Name: %s\nMoney: %i\nAdmin Level: %i\nVip Level: %i\nKill: %i\nDeaths: %i\nKill Deah Ratio: %0.2f (KDR)",
pName(playerid),PlayerInfo[playerid][pMoney],PlayerInfo[playerid][pAdmin],PlayerInfo[playerid][pVip],PlayerInfo[playerid][pKills],PlayerInfo[playerid][pDeaths],kd);
ShowPlayerDialog(playerid, DIALOG_STATISTIC, DIALOG_STYLE_MSGBOX, "Statistic", str1,"Close", "");*/
}
return 1;
}
stock SaveStats(playerid)
{
new Query[256],
Float:Pos[3];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
mysql_format(dbHandle, Query, sizeof(Query), "UPDATE `PlayerData` SET `pMoney` = '%d', `pAdmin` = '%d', `pVip` = '%d', `PosX` = '%f', `PosY` = '%f', `PosZ` = '%f', `pSkin` = '%d' WHERE `Username` = '%s'",
GetPlayerMoney(playerid),
PlayerInfo[playerid][pAdmin],
PlayerInfo[playerid][pVip],
Pos[0],
Pos[1],
Pos[2],
PlayerInfo[playerid][pSkin],
pName(playerid));
mysql_query(dbHandle, Query, false);
mysql_format(dbHandle, Query, sizeof(Query), "UPDATE `PlayerData` SET `pKills` = '%d', `pDeaths` = '%d', `pScore` = '%d' WHERE `Username` = '%s'",
PlayerInfo[playerid][pKills],
PlayerInfo[playerid][pDeaths],
GetPlayerScore(playerid),
pName(playerid));
mysql_query(dbHandle, Query, false);
printf("query size: %i", strlen(Query));
return 1;
}
stock ProxDetector(Float:radi, playerid, string[], color)
{
new Float:x,
Float:y,
Float:z;
GetPlayerPos(playerid, x, y, z);
foreach(Player, i)
{
if(IsPlayerInRangeOfPoint(i,radi,x,y,z))
{
SCM(i, color, string);
}
}
}
main()
{
}
public KickEx(playerid)
{
SaveStats(playerid);
Kick(playerid);
}
public ABroadCast(color,const string[],level)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if (PlayerInfo[i][pAdmin] >= level)
{
SendClientMessage(i, color, string);
printf("%s", string);
}
}
}
return 1;
}
public OnGameModeInit()
{
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
dbHandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
if(!mysql_errno())
{
print("[SUCCESS] You have successfully connected to the mysql database");
}
else
{
print("[ERROR] Could not connect to mysql database");
SendRconCommand("exit");
}
print("\n-----------LOADING------------------");
print("Script by Kris Yellow");
print("------------LOADED------------------\n");
SetGameModeText(revision);
return 1;
}
public OnGameModeExit()
{
mysql_close();
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
InterpolateCameraPos(playerid, 1514.16, -1307.44, 344.42, 2251.13, -1772.94, 50.65 ,50000, CAMERA_MOVE);
InterpolateCameraLookAt(playerid, 1513.8353, -1655.7241, 58.0422, 1513.8353, -1655.7241, 58.0422, 50000, CAMERA_MOVE);
ClearChat(playerid);
new Query[300],
rows,
fields,
titlestring[128],
bodystring[256];
mysql_format(dbHandle, Query, sizeof(Query), "SELECT * FROM `PlayerData` WHERE `Username` = '%e'", pName(playerid));
mysql_query(dbHandle, Query);
cache_get_data(rows, fields);
if(rows)
{
format(titlestring, sizeof(titlestring), "Login - %s", GetPlayerNameEx(playerid));
format(bodystring,sizeof(bodystring),"{FFFFFF}Welcome {00FF9A}%s{FFFFFF}.\nThis name is registered, please enter your password below.", GetPlayerNameEx(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, titlestring, bodystring, "Login", "Quit");
SCM(playerid, WHITE, "Welcome back to the server.");
}
else if(!rows)
{
format(titlestring, sizeof(titlestring), "Register - %s", GetPlayerNameEx(playerid));
format(bodystring, sizeof(bodystring),"{FFFFFF}Welcome {00FF9A}%s{FFFFFF}.\nThis account is not registered,\nPlease enter a password below in order to register this account.", GetPlayerNameEx(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, titlestring, bodystring, "Register", "Quit");
SCM(playerid, WHITE, "Welcome to the server.");
}
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveStats(playerid);
PlayerInfo[playerid][pLogged] = 0;
print("onplayerdisconnect is getting called when u get kicked..");
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[killerid][pKills] ++;
PlayerInfo[playerid][pDeaths] ++;
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
if(standardchat)
{
new string[128],
string2[128];
format(string, sizeof(string), "%s says: %s", GetPlayerNameEx(playerid), text);
ProxDetector(15.0, playerid, string, WHITE);
format(string2, sizeof(string2), "says: %s", GetPlayerNameEx(playerid), text);
SetPlayerChatBubble(playerid, string2, WHITE, 30.0, 10000);
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 128)
{
new titlestring[128],
bodystring[255];
SCM(playerid, -1, "You must insert a password between 1-128 characters!");
format(titlestring, sizeof(titlestring), "Register - %s", GetPlayerNameEx(playerid));
format(bodystring, sizeof(bodystring),"{FFFFFF}Welcome {00FF9A}%s{FFFFFF}.\nThis account is not registered,\nPlease enter a password below in order to register this account.", GetPlayerNameEx(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, titlestring, bodystring, "Register", "Quit");
return 1;
}
else if(strlen(inputtext) > 0 && strlen(inputtext) < 128)
{
new escpass[100];
mysql_escape_string(inputtext, escpass);
MySQL_Register(playerid, escpass);
}
}
if(!response)
{
SCM(playerid, -1, "You have chose to quit, therefore you have been kicked, goodbye.");
SetTimerEx("KickEx", 200, 0, "i", playerid);
}
}
case DIALOG_LOGIN:
{
if(!response)
{
SCM(playerid, -1, "You have chose to quit, therefore you have been kicked, goodbye.");
SetTimerEx("KickEx", 200, 0, "i", playerid);
}
if(response)
{
new query[200], rows, fields;
mysql_format(dbHandle, query, sizeof(query), "SELECT `Username` FROM PlayerData WHERE Username = '%s' AND Password = SHA1('%e')", pName(playerid), inputtext);
mysql_query(dbHandle, query);
cache_get_data(rows, fields);
if(rows) MySQL_Login(playerid);
if(!rows)
{
InvalidPass[playerid]++;
if(InvalidPass[playerid] == 3)
{
SetTimerEx("KickEx", 200, 0, "i", playerid);
}
else
{
new titlestring[128],
bodystring[255];
format(titlestring, sizeof(titlestring), "Login - %s", GetPlayerNameEx(playerid));
format(bodystring,sizeof(bodystring),"{FFFFFF}Wrong password, {00FF9A}%s{FFFFFF}.\nPlease enter the correct password below in order to login.\nYou have %d/3 attempt[s] left to login.", GetPlayerNameEx(playerid), 3-InvalidPass[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, titlestring, bodystring, "Login", "Quit");
}
}
}
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
Код:
-- phpMyAdmin SQL Dump -- version 4.1.6 -- http://www.phpmyadmin.netnl675c1ea63819e...6.11440977-- Host: 127.0.0.1 -- Generation Time: Jun 15, 2014 at 04:30 PM -- Server version: 5.6.16 -- PHP Version: 5.5.9 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `roleplay` -- -- -------------------------------------------------------- -- -- Table structure for table `playerdata` -- CREATE TABLE IF NOT EXISTS `playerdata` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `Username` varchar(24) COLLATE utf8_unicode_ci NOT NULL, `Password` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `pIP` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `pMoney` int(16) NOT NULL, `pAdmin` int(3) NOT NULL, `pVip` int(2) NOT NULL, `pKills` int(11) NOT NULL, `pDeaths` int(11) NOT NULL, `pScore` int(11) NOT NULL, `PosX` float NOT NULL, `PosY` float NOT NULL, `PosZ` float NOT NULL, `pSkin` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=147 ; -- -- Dumping data for table `playerdata` -- INSERT INTO `playerdata` (`ID`, `Username`, `Password`, `pIP`, `pMoney`, `pAdmin`, `pVip`, `pKills`, `pDeaths`, `pScore`, `PosX`, `PosY`, `PosZ`, `pSkin`) VALUES (144, 'Kris_Yellooww', '403926033d001b5279df37cbbe5287b7c7c267fa', '192.168.1.2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (145, 'Nigga_Please', '403926033d001b5279df37cbbe5287b7c7c267fa', '192.168.1.2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (146, 'Kris_Yellow', '403926033d001b5279df37cbbe5287b7c7c267fa', '192.168.1.2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Everything saves normally on disconnect/gmx but when a player is kicked (enter incorrect password for auto kick) all his mySQL tables get reset to 0 in phpmyadmin
There are also no errors or warnings in the gamemode itself or in mysql_log
Please help me!