public OnGameModeInit()
{
//===> MySQL CONNECTION <===
mysql_debug(1); //1 if you want to have log of all mysql actions; 0 if you don't want it
new connection = mysql_connect(DB_IP,DB_USER,DB_NAME,DB_PASS);
if(connection)
{
new stats[256];
mysql_stat(stats);
print(stats);
print("[mysql] MySQL connection successfull!");
}
else
{
print("[mysql] MySQL connection un-successfull; server closed ...");
return GameModeExit();
}
//===========================
for(new x=0; x<MAX_VEHICLES; x++)
{
vInfo[x][vBuyAble] = 0;
}
public OnPlayerConnect(playerid)
{
new
string[128],
PlayerName[24];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
TextDrawShowForPlayer(playerid, Wesbite);
TextDrawShowForPlayer(playerid, Logo);
TextDrawShowForPlayer(playerid, Name);
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "%s has joined the server.", pName);
SendClientMessageToAll(COLOR_LIGHTRED, string);
SendClientMessage(playerid, LIGHTGREEN, "[NotimeBot(v1.1)]: Starting up Notime Defense System...");
SetTimerEx("NTDSstart", 10000, 0, "i", playerid);
Report[playerid] = 0;
SetWeather(10);
//===> MySQL CHECK <===
PlayerInfo[playerid][pSQLId] = INVALID_SQL_ID;
FindPlayerSQL(playerid);
if(PlayerInfo[playerid][pSQLId] > INVALID_SQL_ID)
{
gPlayerAccount[playerid] = 1;
ShowLoginDialog(playerid);
}
else
{
gPlayerAccount[playerid] = 0;
ShowRegDialog(playerid);
}
//====================
public CheckSQL()
{
if(mysql_ping() == (-1))
{
mysql_connect(DB_IP,DB_USER,DB_NAME,DB_PASS);
print("[mysql] MySQL connection lost! Reconnecting ...");
}
return 1;
}
Originally Posted by _Xerxes_
I never see you check whether the database already has a table/row for that player or not.
|
public MySQLCheckUserExistance(playerid)
{
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(query, sizeof(query), "SELECT `reg_id` FROM `users` WHERE `name` = '%s'", PlayerName);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_num_rows() == 0)
{
return 0;
}
else
{
return 1;
}
}
if(MySQLCheckUserExistance(playerid))
{
//User is in the database (exists)
}
public FindPlayerSQL(playerid)
{
CheckSQL();
new query[128],pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
mysql_real_escape_string(pname,pname);
format(query,sizeof(query),"SELECT playerid FROM `players` WHERE name='%s' LIMIT 1",pname);
mysql_query(query);
mysql_store_result();
PlayerInfo[playerid][pSQLId] = mysql_fetch_int();
mysql_free_result();
return 1;
}
public MySQLCheckUserExistance(playerid)
{
new PlayerName[128];
new query[265];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(query, sizeof(query), "SELECT `reg_id` FROM `users` WHERE `name` = '%s'", PlayerName);
mysql_query(query);
if(mysql_num_rows() == 0)
{
return 0;
}
else
{
return 1;
}
}
//===> MySQL CHECK <===
MySQLCheckUserExistance(playerid);
PlayerInfo[playerid][pSQLId] = INVALID_SQL_ID;
FindPlayerSQL(playerid);
if(MySQLCheckUserExistance(playerid))
{
gPlayerAccount[playerid] = 1;
ShowLoginDialog(playerid);
}
else
{
gPlayerAccount[playerid] = 0;
ShowRegDialog(playerid);
}
//====================