Using DelayKickBan to process delayed Kick/Ban/BanEx properly -
fall3n - 05.10.2014
Using DelayKickBan to process delayed Kick/Ban/BanEx properly
Introduction
Since the release of 0.3x, the kick/ban functions are meant to be faster for the sake of security improvements on servers. However due to that, many of them had started to do a delay for kicks but many of them still don't know how to properly do that. I've written an include called DelayKickBan which even handles callbacks which can handle return values and also provides the function to specify the delay time. This tutorial is a simple one and shows to use kick/ban functions properly using DelayedKickBan.
Requirements
Other than SA-MP 0.3x / 0.3z package, you will require the DelayKickBan include.
https://sampforum.blast.hk/showthread.php?tid=535927
Delayed Kicks/Bans
The include DelayKickBan supports 4 functions which are:
pawn Код:
native DelayKick(playerid, delay_ms=150);
native DelayBan(playerid, delay_ms=150);
native DelayBanEx(playerid, const reason[], delay_ms=150);
native IsKickBanProcessed(playerid);
The
delay_ms is an optional parameter and lets you to specify the time for doing the delayed process. Suppose that if you got many things to be done when a player is getting banned - for example, updating MySQL tables, adding ban data and many things like that, some servers even use textdraw to display the BAN info. Use the
delay_ms parameter according to how much functions are there to be passed, the work load time they require. For what I've mentioned above you can use
DelayBan(playerid, 300); which means within 300 ms, the player will be banned!
Some of the examples in relating to put the value of delay_ms could be:
pawn Код:
public OnAntiCheatDetect(playerid, cheatid)
{
//random callback
if(cheatid == SUPER_CHEATS)
{
new
playerName[MAX_PLAYER_NAME],
string[144];
GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
format(string, sizeof(string), "AntiCheat : %s (ID:%d) has been banned from the server for cheating!", playerName, playerid);
SendClientMessageToAll(-1, string);
UpdatePlayerData(CHANGE_BAN_VALUE, 1); //Some MySQL functions.
ShowPlayerBanInfo(playerid, "Super Cheats"); //Super cheats as the reason.
//Consider that ShowPlayerBan might have some textdraws.
DelayBan(playerid, 300); //Increase more, it depends on player's ping anyway.
}
return 1;
}
Use of GetPlayerPing to set the time
The function GetPlayerPing can be a lot useful to check how much ms can be used for delay_ms parameter. If you don't know how ping works then I suggest you to check it over ******. There's enough explanations there and it'd be alot more better than what I type about ping here. You can get the player's ping and add some more ms as a constant value for every kicks/bans using DelayKickBan include. This will ensure that if player completely gets the data before being kicked/banned from the server.
pawn Код:
DelayKick(playerid, GetPlayerPing(playerid) + 70); //Here, 70ms is my constant ms.
The constant can also be set according to the work load.
Handling callbacks, avoiding callbacks to run over kick/ban processed players
This part is very important. Even though the include supports some callbacks not to be called, you can still check it over your own callbacks, custom forwarded ones or functions. The function used for it is
IsKickBanProcessed. That function will return 1 if it's being processed, 0 if not. An example in relating to it:
pawn Код:
forward OnPlayerAchieveMedal(playerid); //A callback which is called when player achieves a medal.
//In case if that medal can be called when player does some thing using cheats and
//if my anti-cheat has detected and called a delayed kick/ban, I should prevent
//the player from achieving medal.
public OnPlayerAchieveMedal(playerid)
{
if(IsKickBanProcessed(playerid)) //If it's processed.
return 0; //Then I'm returning my callback here itself, no more calls.
//Medal stuffs.
return 1;
}
Conclusion
By this tutorial I'm letting everyone know to properly delay kick or ban anyone. I'm just sharing the concept used by me. You don't really have to use DelayKickBan include, you can even create your own custom kick/ban functions by considering what I've said above if you weren't aware about that earlier. Handling callbacks is one of the main thing you've to ever do to avoid cheaters using the delayed time as an exploit. Also, letting you know that GetPlayerPing can be used for such purposes and if you know how ping really works, it can be even used for a lot more things. Let me know if I have done any mistakes, I consider to learn and improve from my mistakes.
Before ending, I've to say that Kick/Ban/BanEx functions aren't bugged. They're meant to work like that. You can even use Kick/Ban/BanEx functions in case of emergency. (Thanks to ****** for pointing that out when I once considered them to be different)
Re: Using DelayKickBan to process delayed Kick/Ban/BanEx properly -
YanLanger - 05.10.2014
Not explained at
ALL
Re: Using DelayKickBan to process delayed Kick/Ban/BanEx properly -
Vince - 05.10.2014
Usage of GetPlayerPing is actually really smart. However, I'm not sure about linearly increasing the time in conjunction with how many things still have to be done. After all, you still have the playerid and all their data in OnPlayerDisconnect.
Re: Using DelayKickBan to process delayed Kick/Ban/BanEx properly -
fall3n - 05.10.2014
Quote:
Originally Posted by YanLanger
Not explained at ALL
|
Could you please let me know what I haven't explained at all? Let me know and I'll improve if there's anything wrong with my topic. If it's because you don't see too much code, FYI - I've explained how things work on what I've typed. This tutorial isn't meant to teach how to use DelayKickBan include. I explained how to properly delay kick/ban functions and to prevent callbacks to undergo data execution while kick/ban is processed for a player, using DelayKickBan.