PDA

View Full Version : Stop this spamming queries.


Dokins
17/04/2017, 03:45 PM
if(Taser[playerid] == 0 && WepAmmo[weapon] == 0 && weapon == 0 && PaintballGun[playerid] == 0 && PlayerUsingTempWep[playerid] == 0 && UsingMolotov[playerid] == 0 && weaponid != 46 && weaponid != WepModel[model])//&& weaponid != 46 && (UsingMolotov[playerid] == 0 && GetWeaponSlot(playerid) == 8)
{
ResetPlayerWeapons(playerid);

new playerip[24], query[256];
format(string, sizeof(string), "[Auto-Ban] %s has been banned by the server for weapon hacking.", GetNameEx(playerid));
SendClientMessageToAll(COLOUR_REALRED, string);
GetPlayerIp(playerid, playerip, sizeof(playerip));
MySQL_SetInteger(PlayerSQLID[playerid], "Banned" , 1, "accounts");
format(string,sizeof(string), "Your IP: {FF0000}%s {FFFFFF}has been{FF0000} BANNED{FFFFFF} from Bone County Roleplay.", playerip);
SendClientMessage(playerid, COLOUR_WHITE, string);
format(string, sizeof(string),"Reason: {FF0000}Suspected Weapon Hacks.");
SendClientMessage(playerid, COLOUR_WHITE, string);
SendClientMessage(playerid, COLOUR_REALRED, "{FFFFFF}PLEASE POST A {FF0000}BAN APPEAL {FFFFFF}AT http://forum.bonecountyrp.com");

GetPlayerIp(playerid, playerip, sizeof(playerip));
format(query, sizeof(query), "SELECT * FROM `bans` WHERE `ip` = '%s'", playerip);
mysql_tquery(dbHandle, query, "IsPlayerAlreadyBanned", "i", playerid);

SavePlayerData(playerid);
RemovePlayerVehicles(playerid);
ClearPlayerID(playerid);

}


This is under OnPlayerWeaponShot.

This is a must as it isn't always detected when changing weapons, but it sadly spams the database if it is like a mini-gun or something.

IsPlayerAlreadyBanned is supposed to check, but there is a 0.2 second kick timer, perhaps the cause?


forward IsPlayerAlreadyBanned(playerid);
public IsPlayerAlreadyBanned(playerid)
{
new rows, fields;
cache_get_data(rows, fields);
new pip[64];
GetPlayerIp(playerid, pip, sizeof(pip));
if(rows)
{
SetTimerEx("KickPlayer", 200, false, "i",playerid);// Kicks player in 500ms
}
else
{
switch(BanReason[playerid])
{
case 0:
{
new query[256];
format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), pip, gettime());
mysql_tquery(dbHandle, query, "", "");
SetTimerEx("KickPlayer", 200,false,"i",playerid);
}
case 1:
{
new query[256];
format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Vehicle Teleporting', %d, 0)", GetName(playerid), pip, gettime());
mysql_tquery(dbHandle, query, "", "");
SetTimerEx("KickPlayer", 200,false,"i",playerid);
}
case 2:
{
new query[256];
format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Fly Hacking', %d, 0)", GetName(playerid), pip, gettime());
mysql_tquery(dbHandle, query, "", "");
SetTimerEx("KickPlayer", 200,false,"i",playerid);
}
default:
{
new query[256];
format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), pip, gettime());
mysql_tquery(dbHandle, query, "", "");
SetTimerEx("KickPlayer", 200,false,"i",playerid);
}
}
}
return 1;
}


How can I stop the database being spammed?

AndreiWow
17/04/2017, 04:55 PM
How can the player be already banned if he is playing? Also what are you trying to do?

Jefff
17/04/2017, 04:55 PM
Just set Taser[playerid] = 1; or UsingMolotov before ResetPlayerWeapons thats all

Vince
17/04/2017, 04:58 PM
My first thought would be to use a unique key but there isn't really any field that you can use for that. So my second thought is to execute the actual query AFTER the kick. And my third thought is using a variable "queryBeingExecuted" to check if any query is currently in progress.

Dokins
17/04/2017, 05:03 PM
I see what you mean Jeff, not a bad idea aha.

Unique key would really be the IP.

I could do that after the kick, I do get the impression there may be an issue with the timer on kick, because it's almost random.