09.01.2018, 23:56
hello, i am kinda new to mysql, i succesfully installed the plugin, it all loaded fine and compiled fine and once i added register system using this tutorial my server didn't start, sending me this logs:
before that everything was fine, that's my code:
thanks in advance to anyone who can help, i did create a database using xampp and localhost, via this tutorial.
p.s. - the script compiles fine.
Код:
[22:58:08] |--------------------------------------------------- [22:58:08] |--- LS BeachSide Filterscript [22:58:08] |-- Script v1.03 [22:58:08] |-- 19th April 2015 [22:58:08] |--------------------------------------------------- [22:58:08] |-- LS BeachSide Building Elevator created [22:58:08] |--------------------------------------------------- [22:58:08] Loaded 7 filterscripts. [22:58:08] [22:58:08] [22:58:08] [22:58:08] ======================================= [22:58:08] | | [22:58:08] | YSI version 4.00.0001 | [22:58:08] | By Alex "******" Cole | [22:58:08] | | [22:58:08] ======================================= [22:58:08] [22:58:08] I couldn't connect to the MySQL server, closing. [22:58:08] |=====================================| [22:58:08] Number of vehicle models: 0 [22:58:08] --- Server Shutting Down. [22:58:08] |-- LS BeachSide Building Elevator destroyed [22:58:08] |--------------------------------------------------- [22:58:08] [22:58:08] ==================== [22:58:08] [22:58:08] Whirlpool unloaded [22:58:08] [22:58:08] ==================== [22:58:08] [22:58:08] *** Streamer Plugin v2.8.2 by Incognito unloaded *** [22:58:08] [22:58:08] =============================== [22:58:08] sscanf plugin unloaded. [22:58:08] =============================== [22:58:08] plugin.mysql: Unloading plugin... [22:58:08] plugin.mysql: Plugin unloaded.
Код:
#include <a_samp>
#include <izcmd>
#include <streamer>
#include <sscanf2>
#include <YSI\y_ini>
#include <a_mysql>
#include <foreach>
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASS "root"
#define MYSQL_DATABASE "pc-rp"
#define DIALOG_REGISTER (0)
#define DIALOG_LOGIN (1)
new
MySQL: Database, Corrupt_Check[MAX_PLAYERS];
enum ENUM_PLAYER_DATA
{
ID,
Name[25],
Password[65],
Salt[11],
PasswordFails,
Kills,
Deaths,
Score,
Cash,
Cache: Player_Cache,
bool:LoggedIn
}
new pInfo[MAX_PLAYERS][ENUM_PLAYER_DATA];
main()
public OnGameModeInit()
{
SetGameModeText("PC-RP v1.0");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
// --------------------------- [ MAPPINGS ] ----------------------------------//
// • City, Surroundings, Perm. Maps • //
CreateDynamicObject(4515, 2124.57349, 41.37568, 27.02320, 0.00000, 0.00000, -90.00000);
CreateDynamicObject(4515, 2102.04565, 41.53327, 27.02320, 0.00000, 0.00000, 90.00000);
CreateDynamicObject(2990, 2079.24341, 41.66508, 27.64204, 0.00000, 0.00000, -90.00000);
CreateDynamicObject(987, 2079.10645, 36.54919, 25.24349, 0.00000, 0.00000, -180.00000);
CreateDynamicObject(987, 2067.41504, 46.81593, 25.24350, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(10832, 2161.34521, -102.31136, 3.20977, 0.00000, 0.00000, -59.22001);
CreateDynamicObject(6188, 2115.80835, -91.85583, -10.03053, 0.00000, 0.00000, -65.16000);
CreateDynamicObject(6959, 2033.06531, -126.00623, 2.35770, 0.00000, 0.00000, -65.16000);
CreateDynamicObject(1231, 2126.60889, -69.13006, 4.93131, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(1231, 2101.81519, -80.74225, 4.93131, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(1231, 2034.27942, -112.00071, 4.93131, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(1231, 2059.30884, -135.58391, 4.93131, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(1231, 2138.85547, -98.94057, 4.93131, 0.00000, 0.00000, 0.00000);
CreateDynamicObject(987, 2059.60400, -136.41808, 2.37245, 0.00000, 0.00000, -156.41971);
CreateDynamicObject(987, 2048.65601, -141.18265, 2.37245, 0.00000, 0.00000, -156.41971);
CreateDynamicObject(987, 2037.70618, -145.96671, 2.37245, 0.00000, 0.00000, -156.41971);
CreateDynamicObject(987, 2026.66968, -150.74884, 2.37245, 0.00000, 0.00000, -243.77971);
CreateDynamicObject(987, 2021.39282, -140.05527, 2.37245, 0.00000, 0.00000, -243.77971);
CreateDynamicObject(987, 2016.12292, -129.35016, 2.37245, 0.00000, 0.00000, -243.77971);
CreateDynamicObject(987, 2014.79565, -126.68587, 2.37245, 0.00000, 0.00000, -243.77971);
CreateDynamicObject(12990, 2004.86682, -101.76212, 0.45096, 0.00000, 0.00000, -333.11917);
CreateDynamicObject(12990, 2019.94336, -94.30769, 0.37851, 0.00000, 0.00000, -333.11920);
CreateDynamicObject(12990, 2034.49915, -88.37093, 0.45958, 0.00000, 0.00000, -333.11917);
CreateDynamicObject(17026, 2096.63501, 40.44657, -0.83109, 0.00000, 0.00000, 49.20000);
CreateDynamicObject(987, 2017.28906, -110.94136, -3.88655, 0.00000, 0.00000, -155.33972);
CreateDynamicObject(987, 2028.05652, -105.86536, -3.88655, 0.00000, 0.00000, -155.33972);
CreateDynamicObject(987, 2038.86072, -100.75689, -3.88655, 0.00000, 0.00000, -155.33972);
CreateDynamicObject(987, 2042.54834, -98.96587, -3.88655, 0.00000, 0.00000, -155.33972);
CreateDynamicObject(987, 2047.51257, -109.80777, -3.88655, 0.00000, 0.00000, -244.91953);
CreateDynamicObject(987, 2048.31372, -141.39090, -3.88655, 0.00000, 0.00000, -334.19934);
CreateDynamicObject(987, 2037.62402, -146.33983, -3.88655, 0.00000, 0.00000, -335.75928);
CreateDynamicObject(987, 2023.84180, -152.54688, -3.88655, 0.00000, 0.00000, -335.75928);
CreateDynamicObject(987, 2026.71411, -151.25125, -3.88655, 0.00000, 0.00000, -335.75928);
CreateDynamicObject(987, 2018.65393, -141.34091, -3.88655, 0.00000, 0.00000, -424.73883);
CreateDynamicObject(987, 2014.00098, -130.86195, -3.88655, 0.00000, 0.00000, -425.63879);
CreateDynamicObject(987, 2008.99414, -120.01417, -3.88655, 0.00000, 0.00000, -425.63879);
CreateDynamicObject(987, 2006.51306, -115.77018, -3.88655, 0.00000, 0.00000, -422.81891);
CreateDynamicObject(3361, 2009.62012, -111.16472, 0.20199, 0.00000, 0.00000, 116.76003);
CreateDynamicObject(3361, 2025.01270, -104.02151, 0.24002, 0.00000, 0.00000, 116.76003);
CreateDynamicObject(3361, 2038.86316, -97.55944, 0.24002, 0.00000, 0.00000, 116.76003);
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("I couldn't connect to the MySQL server, closing.");
SendRconCommand("exit");
return 1;
}
print("I have connected to the MySQL server.");
mysql_tquery(Database, "CREATE TABLE IF NOT EXISTS `PLAYERS` (`ID` int(11) NOT NULL AUTO_INCREMENT,`USERNAME` varchar(24) NOT NULL,`PASSWORD` char(65) NOT NULL,`SALT` char(11) NOT NULL,`SCORE` mediumint(7), `KILLS` mediumint(7), `CASH` mediumint(7) NOT NULL DEFAULT '0',`DEATHS` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `USERNAME` (`USERNAME`))");
return 1;
}
public OnGameModeExit()
{
foreach(new i: Player)
{
if(IsPlayerConnected(i))
{
OnPlayerDisconnect(i, 1);
}
}
mysql_close(Database);
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
// --------------------------- [ MAPPINGS ] ----------------------------------//
// • Removed maps • //
RemoveBuildingForPlayer(playerid, 13483, 2113.5781, -96.7344, 0.9844, 0.25);
RemoveBuildingForPlayer(playerid, 766, 2147.7500, 29.5859, 24.7734, 0.25);
RemoveBuildingForPlayer(playerid, 766, 2164.7109, 27.8672, 24.4297, 0.25);
RemoveBuildingForPlayer(playerid, 766, 2136.3594, 51.5391, 25.0859, 0.25);
RemoveBuildingForPlayer(playerid, 766, 2155.1250, 51.4375, 24.7734, 0.25);
RemoveBuildingForPlayer(playerid, 766, 2171.7578, 52.2266, 24.7734, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2139.7891, 90.2891, 31.8906, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2151.5391, 88.4453, 29.5859, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2163.3281, 86.6016, 27.4688, 0.25);
RemoveBuildingForPlayer(playerid, 12909, 2159.4297, 91.1250, 19.1719, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2142.5469, 97.5859, 31.1875, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2154.4609, 95.6406, 29.1797, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2166.3828, 93.6875, 27.2109, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2103.7578, 94.2734, 32.8359, 0.25);
RemoveBuildingForPlayer(playerid, 3276, 2106.7266, 102.9688, 32.8750, 0.25);
RemoveBuildingForPlayer(playerid, 13508, 2207.5938, -272.1094, 17.9922, 0.25);
RemoveBuildingForPlayer(playerid, 12990, 2113.5781, -96.7344, 0.9844, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2119.8203, -84.4063, -0.0703, 0.25);
RemoveBuildingForPlayer(playerid, 1369, 2104.0156, -105.2656, 1.7031, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2122.3750, -83.3828, 0.4609, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2119.5313, -82.8906, -0.1641, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2120.5156, -79.0859, 0.2188, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2119.4688, -69.7344, 0.2266, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2119.4922, -73.6172, 0.1250, 0.25);
RemoveBuildingForPlayer(playerid, 12991, 2161.6328, -102.4766, 1.7500, 0.25);
RemoveBuildingForPlayer(playerid, 923, 2160.3516, -100.8594, 2.6094, 0.25);
RemoveBuildingForPlayer(playerid, 933, 2159.4063, -93.9219, 1.8047, 0.25);
RemoveBuildingForPlayer(playerid, 933, 2158.1094, -94.1406, 2.2969, 0.25);
RemoveBuildingForPlayer(playerid, 933, 2155.9141, -121.0391, 0.0859, 0.25);
RemoveBuildingForPlayer(playerid, 935, 2117.8438, -67.8359, 0.1328, 0.25);
RemoveBuildingForPlayer(playerid, 13509, 2444.2500, -246.3750, 30.5938, 0.25);
// • Vehicles • //
CreateVehicle(493, 2028.0920, -97.5883, 0.7023, 25.8000, -1, -1, 100);
CreateVehicle(493, 2013.6060, -105.7542, 0.7023, 25.8000, -1, -1, 100);
CreateVehicle(522, 2028.4812, -147.4007, 2.9541, 0.0000, -1, -1, 100);
CreateVehicle(522, 2030.9824, -145.7179, 2.9541, 0.0000, -1, -1, 100);
//----------------------------------------------------------------------------//
new DB_Query[115];
pInfo[playerid][Kills] = 0;
pInfo[playerid][Deaths] = 0;
pInfo[playerid][PasswordFails] = 0;
GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME); // Getting the player's name.
Corrupt_Check[playerid]++;
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1", pInfo[playerid][Name]);
mysql_tquery(Database, DB_Query, "OnPlayerDataCheck", "ii", playerid, Corrupt_Check[playerid]);
return 1;
}
forward public OnPlayerDataCheck(playerid, corrupt_check);
public OnPlayerDataCheck(playerid, corrupt_check)
{
if (corrupt_check != Corrupt_Check[playerid]) return Kick(playerid);
// You'd have asked already what's corrput_check and how it'd benefit me?
// Well basically MySQL query takes long, incase a player leaves while its not proceeded
// With ID 1 for example, then another player comes as ID 1 it'll basically corrupt the data
// So, once the query is done, the player will have the wrong data assigned for himself.
new String[150];
if(cache_num_rows() > 0)
{
// If the player exists, everything is okay and nothing is wrongly detected
// The player's password and Saltion key gets stored as seen below
// So we won't have to get a headache just to match player's password.
cache_get_value(0, "PASSWORD", pInfo[playerid][Password], 65);
cache_get_value(0, "SALT", pInfo[playerid][Salt], 11);
pInfo[playerid][Player_Cache] = cache_save();
// ^ Storing the cache ID of the player for further use later.
format(String, sizeof(String), "{FFFFFF}Welcome back, %s.\n\n{0099FF}This account is already registered.\n\
{0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave");
}
else
{
format(String, sizeof(String), "{FFFFFF}Welcome %s.\n\n{0099FF}This account is not registered.\n\
{0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Corrupt_Check[playerid]++;
new DB_Query[256];
//Running a query to save the player's data using the stored stuff.
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `KILLS` = %d, `DEATHS` = %d WHERE `ID` = %d LIMIT 1",
pInfo[playerid][Score], pInfo[playerid][Cash], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
if(cache_is_valid(pInfo[playerid][Player_Cache])) //Checking if the player's cache ID is valid.
{
cache_delete(pInfo[playerid][Player_Cache]); // Deleting the cache.
pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE; // Setting the stored player Cache as invalid.
}
pInfo[playerid][LoggedIn] = false;
print("OnPlayerDisconnect has been called."); // Sending message once OnPlayerDisconnect is called.
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, 2035.9792,-130.5733,3.3265);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID) // Checking if the killer of the player is valid.
{
//Increasing the kills of the killer and the deaths of the player.
pInfo[killerid][Kills]++;
pInfo[playerid][Deaths]++;
}
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
// cmd
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)
{
if(pInfo[playerid][LoggedIn] == false) return 0;
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_LOGIN:
{
if(!response) return Kick(playerid);
new Salted_Key[65];
SHA256_PassHash(inputtext, pInfo[playerid][Salt], Salted_Key, 65);
if(strcmp(Salted_Key, pInfo[playerid][Password]) == 0)
{
// Now, password should be correct as well as the strings
// Matched with each other, so nothing is wrong until now.
// We will activate the cache of player to make use of it e.g.
// Retrieve their data.
cache_set_active(pInfo[playerid][Player_Cache]);
// Okay, we are retrieving the information now..
cache_get_value_int(0, "ID", pInfo[playerid][ID]);
cache_get_value_int(0, "KILLS", pInfo[playerid][Kills]);
cache_get_value_int(0, "DEATHS", pInfo[playerid][Deaths]);
cache_get_value_int(0, "SCORE", pInfo[playerid][Score]);
cache_get_value_int(0, "CASH", pInfo[playerid][Cash]);
SetPlayerScore(playerid, pInfo[playerid][Score]);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pInfo[playerid][Cash]);
// So, we have successfully retrieved data? Now deactivating the cache.
cache_delete(pInfo[playerid][Player_Cache]);
pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
pInfo[playerid][LoggedIn] = true;
SendClientMessage(playerid, 0x00FF00FF, "Logged in to the account.");
}
else
{
new String[150];
pInfo[playerid][PasswordFails] += 1;
printf("%s has been failed to login. (%d)", pInfo[playerid][Name], pInfo[playerid][PasswordFails]);
// Printing the message that someone has failed to login to his account.
if (pInfo[playerid][PasswordFails] >= 3) // If the fails exceeded the limit we kick the player.
{
format(String, sizeof(String), "%s has been kicked Reason: {FF0000}(%d/3) Login fails.", pInfo[playerid][Name], pInfo[playerid][PasswordFails]);
SendClientMessageToAll(0x969696FF, String);
Kick(playerid);
}
else
{
// If the player didn't exceed the limits we send him a message that the password is wrong.
format(String, sizeof(String), "Wrong password, you have %d out of 3 tries.", pInfo[playerid][PasswordFails]);
SendClientMessage(playerid, 0xFF0000FF, String);
format(String, sizeof(String), "{FFFFFF}Welcome back, %s.\n\n{0099FF}This account is already registered.\n\
{0099FF}Please, input your password below to proceed to the game.\n\n", pInfo[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave");
}
}
}
case DIALOG_REGISTER:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) <= 5 || strlen(inputtext) > 60)
{
// If the password length is less than or equal to 5 and more than 60
// It repeats the process and shows error message as seen below.
SendClientMessage(playerid, 0x969696FF, "Invalid password length, should be 5 - 60.");
new String[150];
format(String, sizeof(String), "{FFFFFF}Welcome %s.\n\n{0099FF}This account is not registered.\n\
{0099FF}Please, input your password below to proceed.\n\n", pInfo[playerid][Name]);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave");
}
else
{
// Salting the player's password using SHA256 for a better security.
for (new i = 0; i < 10; i++)
{
pInfo[playerid][Salt][i] = random(79) + 47;
}
pInfo[playerid][Salt][10] = 0;
SHA256_PassHash(inputtext, pInfo[playerid][Salt], pInfo[playerid][Password], 65);
new DB_Query[225];
// Storing player's information if everything goes right.
mysql_format(Database, DB_Query, sizeof(DB_Query), "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `DEATHS`)\
VALUES ('%e', '%s', '%e', '20', '0', '0', '0')", pInfo[playerid][Name], pInfo[playerid][Password], pInfo[playerid][Salt]);
mysql_tquery(Database, DB_Query, "OnPlayerRegister", "d", playerid);
}
}
}
return 1;
}
forward public OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
// This gets called only when the player registers a new account.
SendClientMessage(playerid, 0x00FF00FF, "You are now registered and has been logged in.");
pInfo[playerid][LoggedIn] = true;
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
p.s. - the script compiles fine.



