27.08.2017, 21:45
This is a repost with the new code.
I've got this code which sometimes causes the server to lose connection to mysql db.
I've got this code which sometimes causes the server to lose connection to mysql db.
PHP код:
under OnPlayerConnect
CheckPlayerBan(playerid)
{
format(BanInfo[playerid][bip],20,"%s",ReturnPlayerIp(playerid));
new ORM:ormid2 = BanInfo[playerid][ORM_ID] = orm_create("pbans", c_handle);
orm_addvar_string(ormid2, BanInfo[playerid][bname], 25, "pBanned");
orm_addvar_string(ormid2, BanInfo[playerid][badmin], 25, "pBannedBy");
orm_addvar_string(ormid2, BanInfo[playerid][btime], 30, "pBanTime");
orm_addvar_string(ormid2, BanInfo[playerid][bdate], 30, "pBanDate");
orm_addvar_string(ormid2, BanInfo[playerid][bip], 20, "IP");
orm_addvar_string(ormid2, BanInfo[playerid][breason], 128, "pBanReason");
orm_setkey(ormid2, "IP");
orm_select(ormid2, "pbancheck", "d", playerid);
return 1;
}
PHP код:
forward pbancheck(playerid);
public pbancheck(playerid)
{
if(playerid != INVALID_PLAYER_ID) // if the player is still connected
{
switch(orm_errno(BanInfo[playerid][ORM_ID]))
{
case ERROR_OK:
{
new string[128];
format(string, sizeof(string), "%s, you were banned by %s for %s. Time: %s, %s", GetPlayerNameEx(playerid), BanInfo[playerid][badmin], BanInfo[playerid][breason], BanInfo[playerid][bdate], BanInfo[playerid][btime]);
SendClientMessage(playerid, COLOR_WHITE, " ");
SendClientMessage(playerid, COLOR_WHITE, " ");
SendClientMessage(playerid, COLOR_RED,string);
SendClientMessage(playerid, COLOR_CYAN2, "To play again visit: www.paruni.com");
SendClientMessage(playerid, COLOR_CYAN2, "This connection has been put on record.");
new query2[128];
mysql_format(c_handle,query2, sizeof(query2), "UPDATE pbans SET pBanEvade = %d WHERE `pBanned` = '%e'", 1, GetPlayerNameEx(playerid));
mysql_tquery(c_handle, query2, "SendQuery", "");
printf("%s Has Been Blocked From Connecting To The Server. IP: %s",GetPlayerNameEx(playerid),ReturnPlayerIp(playerid));
PlayerPlaySound(playerid, 1062, 0.0, 0.0, 0.0);
orm_destroy(BanInfo[playerid][ORM_ID]);
for(new bInfo:e; e < bInfo; ++e)
{
BanInfo[playerid][e] = 0;
}
KickEx(playerid);
}
case ERROR_NO_DATA:
{
orm_destroy(BanInfo[playerid][ORM_ID]);
new query[128];
mysql_format(c_handle,query, sizeof(query), "SELECT * FROM `tban` WHERE `IP` = '%e' OR `Name` = '%e'", ReturnPlayerIp(playerid), GetPlayerNameEx(playerid));
mysql_tquery(c_handle, query, "tbancheck", "i", playerid);
}
case ERROR_INVALID:
{
CheckPlayerBan(playerid);
}
}
}
return 1;
}