21.09.2014, 01:35
I was testing this function to implement a packetloss kicker and found it to be completely unreliable here is the code.
pawn Код:
#include <YSI\y_hooks>
#define PACKET_LOSS_DELAY 60000
#define PACKET_LOSS_INFRACTIONS 3
static Float:LastPacketLoss[MAX_PLAYERS];
static PacketLossTime[MAX_PLAYERS];
static PacketLossInfractions[MAX_PLAYERS];
hook OnGameModeInit()
{
SetTimer("LossChecker", 1000, true);
return 1;
}
hook OnPlayerConnect(playerid)
{
LastPacketLoss[playerid] = 0.0;
PacketLossTime[playerid] = GetTickCount();
PacketLossInfractions[playerid] = 0;
return 1;
}
LossChecker();
public LossChecker()
{
new Float:loss;
foreach(new i : Player)
{
loss = NetStats_PacketLossPercent(i);
// Loss detected
if(loss > LastPacketLoss[i])
{
if(GetTickCount() - PacketLossTime[i] > PACKET_LOSS_DELAY) PacketLossInfractions[i] = 1;
else PacketLossInfractions[i]++;
PacketLossTime[i] = GetTickCount();
if(PacketLossInfractions[i] == PACKET_LOSS_INFRACTIONS)
{
Disconnect_Reason[i] = DISCONNECT_PACKETLOSS;
DelayKick(i);
}
}
LastPacketLoss[i] = loss;
}
return 1;
}