public OnGameModeInit()
{
mysql_log(ERROR | WARNING);
new MySQLOpt: option_id = mysql_init_options();
mysql_set_option(option_id, AUTO_RECONNECT, true);
Database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE, option_id);
if(Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0)
{
print("SERVER: Untitled Deathmatch couldn't connect to the MySQL server, closing.");
SendRconCommand("exit");
return 1;
}
print("SERVER: Untitled Deathmatch has connected to the MySQL database.");
public OnGameModeExit()
{
foreach(new i: Player)
{
if(IsPlayerConnected(i))
{
OnPlayerDisconnect(i, 1);
}
}
mysql_close(Database);
public OnPlayerConnect(playerid)
{
new DB_Query[115];
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
Corrupt_Check[playerid]++;
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1", PlayerInfo[playerid][pName]);
mysql_tquery(Database, DB_Query, "OnPlayerDataCheck", "ii", playerid, Corrupt_Check[playerid]);
public OnPlayerDisconnect(playerid, reason)
{
Corrupt_Check[playerid]++;
new DB_Query[256];
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d, `BAN` = %d, `ADMIN` = %d, `WARNINGS` = %d, `VIP` = %d, `TOKENS` = %d, `CHAT` = %d, `SKIN` = %d, `NAMECHANGES` = %d, `MODE` = %d, WHERE `ID` = %d LIMIT 1",
PlayerInfo[playerid][pScore], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pBan], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pWarnings], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pToken], PlayerInfo[playerid][pChat], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pNamechanges], PlayerInfo[playerid][pMODE], PlayerInfo[playerid][pID]);
mysql_tquery(Database, DB_Query);
if(cache_is_valid(PlayerInfo[playerid][Player_Cache]))
{
cache_delete(PlayerInfo[playerid][Player_Cache]);
PlayerInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
}
PlayerInfo[playerid][LoggedIn] = false;
print("OnPlayerDisconnect has been called.");
OnDialogResponse
{
switch (dialogid)
{
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
new Salted_Key[65];
SHA256_PassHash(inputtext, PlayerInfo[playerid][Salt], Salted_Key, 65);
if(strcmp(Salted_Key, PlayerInfo[playerid][pPassword]) == 0)
{
cache_set_active(PlayerInfo[playerid][Player_Cache]);
cache_get_value_int(0, "ID", PlayerInfo[playerid][pID]);
cache_get_value_int(0, "KILLS", PlayerInfo[playerid][pKills]);
cache_get_value_int(0, "DEATHS", PlayerInfo[playerid][pDeaths]);
cache_get_value_int(0, "SCORE", PlayerInfo[playerid][pScore]);
cache_get_value_int(0, "CASH", PlayerInfo[playerid][pCash]);
cache_get_value_int(0, "BAN", PlayerInfo[playerid][pBan]);
cache_get_value_int(0, "IP", PlayerInfo[playerid][pIP]);
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
cache_delete(PlayerInfo[playerid][Player_Cache]);
PlayerInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
PlayerInfo[playerid][LoggedIn] = true;
PlayerInfo[playerid][pMODE] = NO_MODE;
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 1729.2920, -1669.4794, 22.6151 ,42.4700, -1, -1, -1, -1, -1, -1);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 400);
SpawnPlayer(playerid);
SendClientMessageEx(playerid, -1, "SERVER: Welcome back %s", GetPlayerNameEx(playerid));
}
else
{
new String[150];
PlayerInfo[playerid][PasswordFails] += 1;
printf("%s has failed to log-in. (%d)", PlayerInfo[playerid][pName], PlayerInfo[playerid][PasswordFails]);
if (PlayerInfo[playerid][PasswordFails] >= 3)
{
format(String, sizeof(String), "SERVER: %s has been kicked, reason: (%d/3) login fails.", PlayerInfo[playerid][pName], PlayerInfo[playerid][PasswordFails]);
SendClientMessageToAll(COLOR_LIGHTRED, String);
Kick(playerid);
}
else
{
format(String, sizeof(String), "Wrong password, you have %d out of 3 tries.", PlayerInfo[playerid][PasswordFails]);
SendClientMessage(playerid, COLOR_LIGHTRED, String);
format(String, sizeof(String), "{FFFFFF}Welcome back, {00CED1}%s. {FFFFFF}Please type your password below to login into the server.", PlayerInfo[playerid][pName]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", String, "Login", "Leave");
}
}
}
case DIALOG_REGISTER:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) <= 5 || strlen(inputtext) > 60)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Invalid password length, should be 5 - 60.");
new String[150];
format(String, sizeof(String), "{FFFFFF}Welcome to Untitled Deathmatch, {00CED1}%s. {FFFFFF}Please input a password below to register.", PlayerInfo[playerid][pName]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", String, "Register", "Leave");
}
else
{
for (new i = 0; i < 10; i++)
{
PlayerInfo[playerid][Salt][i] = random(79) + 47;
}
PlayerInfo[playerid][Salt][10] = 0;
SHA256_PassHash(inputtext, PlayerInfo[playerid][Salt], PlayerInfo[playerid][pPassword], 65);
new DB_Query[225];
mysql_format(Database, DB_Query, sizeof(DB_Query), "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)\
VALUES ('%e', '%s', '%e', '20', '0', '0', '0')", PlayerInfo[playerid][pName], PlayerInfo[playerid][pPassword], PlayerInfo[playerid][Salt]);
mysql_tquery(Database, DB_Query, "OnPlayerRegister", "d", playerid);
}
forward public OnPlayerDataCheck(playerid, corrupt_check);
public OnPlayerDataCheck(playerid, corrupt_check)
{
if (corrupt_check != Corrupt_Check[playerid]) return Kick(playerid);
new String[150];
if(cache_num_rows() > 0)
{
cache_get_value(0, "PASSWORD", PlayerInfo[playerid][pPassword], 65);
cache_get_value(0, "SALT", PlayerInfo[playerid][Salt], 11);
PlayerInfo[playerid][Player_Cache] = cache_save();
format(String, sizeof(String), "{FFFFFF}Welcome back, {00CED1}%s. {FFFFFF}Please type your password below to login into the server.", PlayerInfo[playerid][pName]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", String, "Login", "Leave");
}
else
{
format(String, sizeof(String), "{FFFFFF}Welcome to Untitled Deathmatch, {00CED1}%s. {FFFFFF}Please input a password below to register.", PlayerInfo[playerid][pName]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", String, "Register", "Leave");
}
return 1;
}
forward public OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
TogglePlayerControllable(playerid, false);
SendClientMessage(playerid, COLOR_WHITE, "Welcome to Untitled Deathmatch.");
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 1729.2920, -1669.4794, 22.6151 ,42.4700, -1, -1, -1, -1, -1, -1);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 400);
SpawnPlayer(playerid);
PlayerInfo[playerid][LoggedIn] = true;
return 1;
}
Your DB_Query variable you use to send the update query is too short.
When you replace the %d with 1234567890 (which is 10 chars long and is the length of an integer as text), the query gets to 342 characters long, yours is only 256 chars long. Even without replacing the %d with any value, your query is already 230 chars long. You need to foresee this because players can have up to 2.1 billion dollars (32-bit integer), even score, bankaccount and other values might get that high. Make it at least 350 chars long and try again. |
Your DB_Query variable you use to send the update query is too short.
When you replace the %d with 1234567890 (which is 10 chars long and is the length of an integer as text), the query gets to 342 characters long, yours is only 256 chars long. Even without replacing the %d with any value, your query is already 230 chars long. You need to foresee this because players can have up to 2.1 billion dollars (32-bit integer), even score, bankaccount and other values might get that high. Make it at least 350 chars long and try again. |
[13:15:36] [DEBUG] mysql_init_options()
[13:15:36] [DEBUG] mysql_init_options: return value: '1'
[13:15:36] [DEBUG] mysql_set_option(1, 0)
[13:15:36] [DEBUG] mysql_set_option: return value: '1'
[13:15:36] [DEBUG] mysql_connect("localhost", "root", "*****", "testone", 1)
[13:15:36] [DEBUG] CHandleManager::Create(this=0x300898, host='localhost', user='root', pass='****', db='testone', options=0x386868)
[13:15:36] [WARNING] mysql_connect: no password specified
[13:15:36] [DEBUG] CConnection::CConnection(this=0x341d08, host='localhost', user='root', passw='****', db='testone', options=0x386868)
[13:15:36] [DEBUG] CConnection::CConnection - new connection = 0x3ac768
[13:15:36] [DEBUG] CConnection::CConnection(this=0x4573020, host='localhost', user='root', passw='****', db='testone', options=0x386868)
[13:15:36] [DEBUG] CConnection::CConnection - new connection = 0x3ab3e0
[13:15:36] [DEBUG] CThreadedConnection::WorkerFunc(this=0x4573020, connection=0x4573020)
[13:15:36] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x4573020, connection=0x4573020)
[13:15:36] [DEBUG] CConnectionPool::CConnectionPool(size=2, this=0x342388)
[13:15:36] [DEBUG] CConnection::CConnection(this=0x4748020, host='localhost', user='root', passw='****', db='testone', options=0x386868)
[13:15:36] [DEBUG] CConnection::CConnection - new connection = 0x3ab7c8
[13:15:36] [DEBUG] CThreadedConnection::WorkerFunc(this=0x4748020, connection=0x4748020)
[13:15:36] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x4748020, connection=0x4748020)
[13:15:36] [DEBUG] CConnection::CConnection(this=0x4915020, host='localhost', user='root', passw='****', db='testone', options=0x386868)
[13:15:36] [DEBUG] CConnection::CConnection - new connection = 0x3abbb0
[13:15:36] [DEBUG] CThreadedConnection::WorkerFunc(this=0x4915020, connection=0x4915020)
[13:15:36] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x4915020, connection=0x4915020)
[13:15:36] [DEBUG] CHandleManager::Create - new handle = 0x364640
[13:15:36] [DEBUG] mysql_connect: return value: '1'
[13:15:36] [DEBUG] mysql_errno(1)
[13:15:36] [DEBUG] CHandle::GetErrorId(this=0x364640)
[13:15:36] [DEBUG] CConnection::GetError(this=0x341d08, connection=0x3ac768)
[13:15:36] [DEBUG] CHandle::GetErrorId - return value: true, error id: '0', error msg: ''
[13:15:36] [DEBUG] mysql_errno: return value: '0'
[13:15:45] [DEBUG] mysql_format(1, 0x041E84BC, 3000, "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1")
[13:15:45] [DEBUG] CHandle::EscapeString(this=0x364640, src='Test')
[13:15:45] [DEBUG] CConnection::EscapeString(src='Test', this=0x341d08, connection=0x3ac768)
[13:15:45] [DEBUG] CHandle::EscapeString - return value: true, escaped string: 'Test'
[13:15:45] [DEBUG] mysql_format: return value: '57'
[13:15:45] [DEBUG] mysql_tquery(1, "SELECT * FROM `PLAYERS` WHERE `USERNAME` = 'Test' LIMIT 1", "OnPlayerDataCheck", "ii")
[13:15:45] [DEBUG] CCallback::Create(amx=0x27cfdc0, name='OnPlayerDataCheck', format='ii', params=0x41e84a0, param_offset=5)
[13:15:45] [DEBUG] CCallback::Create - callback index for 'OnPlayerDataCheck': 31
[13:15:45] [DEBUG] processing specifier 'i' with parameter index 0
[13:15:45] [DEBUG] retrieved and pushed value '0'
[13:15:45] [DEBUG] processing specifier 'i' with parameter index 1
[13:15:45] [DEBUG] retrieved and pushed value '1'
[13:15:45] [DEBUG] created delayed callback with 2 parameters
[13:15:45] [DEBUG] CHandle::Execute(this=0x364640, type=1, query=0x3a3200)
[13:15:45] [DEBUG] CHandle::Execute - return value: true
[13:15:45] [DEBUG] mysql_tquery: return value: '1'
[13:15:45] [DEBUG] CConnection::Execute(query=0x3a3200, this=0x4573020, connection=0x3ab3e0)
[13:15:45] [DEBUG] CQuery::Execute(this=0x3a3200, connection=0x3ab3e0)
[13:15:45] [DEBUG] CResultSet::Create(connection=0x3ab3e0, query_str='SELECT * FROM `PLAYERS` WHERE `USERNAME` = 'Test' LIMIT 1')
[13:15:45] [DEBUG] created new resultset '0x3eb8b8'
[13:15:45] [DEBUG] fetched MySQL result '0x387468'
[13:15:45] [DEBUG] allocated 0 bytes for PAWN result
[13:15:45] [DEBUG] CCallback::Execute(amx=0x27cfdc0, index=31, num_params=2)
[13:15:45] [DEBUG] processing internal specifier 'c'
[13:15:45] [DEBUG] pushed value '1' onto AMX stack
[13:15:45] [DEBUG] processing internal specifier 'c'
[13:15:45] [DEBUG] pushed value '0' onto AMX stack
[13:15:45] [DEBUG] executing AMX callback with index '31'
[13:15:45] [DEBUG] cache_get_row_count(0x041EB838)
[13:15:45] [DEBUG] cache_get_row_count: return value: '1'
[13:15:45] [DEBUG] AMX callback executed with error '0'
[13:15:51] [DEBUG] mysql_format(1, 0x041E8BB4, 3000, "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('%e', '%s', '%e', '20', '0', '0', '0')")
[13:15:51] [DEBUG] CHandle::EscapeString(this=0x364640, src='Test')
[13:15:51] [DEBUG] CConnection::EscapeString(src='Test', this=0x341d08, connection=0x3ac768)
[13:15:51] [DEBUG] CHandle::EscapeString - return value: true, escaped string: 'Test'
[13:15:51] [DEBUG] CHandle::EscapeString(this=0x364640, src='peQ;U3<SCZ')
[13:15:51] [DEBUG] CConnection::EscapeString(src='peQ;U3<SCZ', this=0x341d08, connection=0x3ac768)
[13:15:51] [DEBUG] CHandle::EscapeString - return value: true, escaped string: 'peQ;U3<SCZ'
[13:15:51] [DEBUG] mysql_format: return value: '298'
[13:15:51] [DEBUG] mysql_tquery(1, "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')", "OnPlayerRegister", "d")
[13:15:51] [DEBUG] CCallback::Create(amx=0x27cfdc0, name='OnPlayerRegister', format='d', params=0x41e8b9c, param_offset=5)
[13:15:51] [DEBUG] CCallback::Create - callback index for 'OnPlayerRegister': 51
[13:15:51] [DEBUG] processing specifier 'd' with parameter index 0
[13:15:51] [DEBUG] retrieved and pushed value '0'
[13:15:51] [DEBUG] created delayed callback with 1 parameter
[13:15:51] [DEBUG] CHandle::Execute(this=0x364640, type=1, query=0x3a3758)
[13:15:51] [DEBUG] CHandle::Execute - return value: true
[13:15:51] [DEBUG] mysql_tquery: return value: '1'
[13:15:51] [DEBUG] CConnection::Execute(query=0x3a3758, this=0x4573020, connection=0x3ab3e0)
[13:15:51] [DEBUG] CQuery::Execute(this=0x3a3758, connection=0x3ab3e0)
[13:15:51] [ERROR] error #1136 while executing query "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')": Column count doesn't match value count at row 1
[13:15:51] [DEBUG] CConnection::GetError(this=0x4573020, connection=0x3ab3e0)
[13:15:51] [DEBUG] CCallback::Create(amx=0x27cfdc0, name='OnQueryError', format='dsssd)
[13:15:51] [ERROR] error #1136 while executing query "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`, `BAN`, `IP`, `ADMIN`, `WARNINGS`, `VIP`, `TOKENS`, `CHAT`, `SKIN`, `NAMECHANGES`, `MODE`)VALUES ('Test', 'E9958A1A4DE7CE6280A7D5D39C06FFAFEFB6FFA337A74E86BCAA5FBA2B180416', 'peQ;U3<SCZ', '20', '0', '0', '0')": Column count doesn't match value count at row 1
Looks like you've miscounted the columns you're trying to insert.
pawn Код:
|
cache_get_value_int(0, "ID", PlayerInfo[playerid][pID]);
cache_get_value_int(0, "KILLS", PlayerInfo[playerid][pKills]);
cache_get_value_int(0, "DEATHS", PlayerInfo[playerid][pDeaths]);
cache_get_value_int(0, "SCORE", PlayerInfo[playerid][pScore]);
cache_get_value_int(0, "CASH", PlayerInfo[playerid][pCash]);
cache_get_value_int(0, "BAN", PlayerInfo[playerid][pBan]);
cache_get_value_int(0, "IP", PlayerInfo[playerid][pIP]);
cache_get_value_int(0, "ADMIN", PlayerInfo[playerid][pAdmin]);
cache_get_value_int(0, "WARNINGS", PlayerInfo[playerid][pWarnings]);
cache_get_value_int(0, "VIP", PlayerInfo[playerid][pVIP]);
cache_get_value_int(0, "TOKENS", PlayerInfo[playerid][pToken]);
cache_get_value_int(0, "CHAT", PlayerInfo[playerid][pChat]);
cache_get_value_int(0, "SKIN", PlayerInfo[playerid][pSkin]);
cache_get_value_int(0, "NAMECHANGES", PlayerInfo[playerid][pNamechanges]);
cache_get_value_int(0, "MODE", PlayerInfo[playerid][pMODE]);