Desync Check
#1

Hi, I just made a desync check, but it's not working properly. It keeps raising my drunk level means my screen starts shaking. I created a new thread because the old one was "drunk level" and was not about this, but here I need someone who knows what's wrong with it. Anyways here's the code:
Code:
public OnPlayerSpawn(playerid)
{
	new drunklevel;
	
	drunklevel = GetPlayerDrunkLevel(playerid);
	SetPlayerDrunkLevel(playerid, drunklevel + 200);

        SetTimerEx("CheckDesync", 1000, false, "dd", playerid, drunklevel);
        return 1;
}

forward CheckDesync(playerid, drunklevel);
public CheckDesync(playerid, drunklevel)
{
	if (!IsPlayerSpawned(playerid))
		return 0;

	if (GetPlayerDrunkLevel(playerid) <= drunklevel) GameTextForPlayer(playerid, "~w~You are desynced~n~Please relog as soon~n~as possible", 1000, 3);
	else SetPlayerDrunkLevel(playerid, GetPlayerDrunkLevel(playerid)-200);
	
	drunklevel = GetPlayerDrunkLevel(playerid);
	SetPlayerDrunkLevel(playerid, drunklevel + 200);
		
	SetTimerEx("CheckDesync", 1000, false, "dd", playerid, drunklevel);
	return 1;
}
What's wrong with it? How can I make it work properly? If anyone finds any other problems in the code then tell me that as well please. :P
Reply
#2

Just saying, by the code you made, you will have a message saying that you're desynced all the time.
Because the drunk level is adjusted by the clients FPS, which is dynamic and changes all the time depending on how many frames there's.
So using the drunk level to check this is not a great idea.
Reply
#3

Yes, but if you are desynced then SetPlayerDrunkLevel shouldn't work, means that drunklevel will be either the same or smaller when checking.
Reply
#4

Quote:
Originally Posted by GoldenLion
View Post
Yes, but if you are desynced then SetPlayerDrunkLevel shouldn't work, means that drunklevel will be either the same or smaller when checking.
You don't understand..
If I got 120 fps, which I do have, I will probably trigger your deysnced, because I will got -120 drunk level each second.
Reply
#5

Uh, how else could I do that then? One guy on my Skype made that with drunk level and it worked perfectly.
Reply
#6

Quote:
Originally Posted by GoldenLion
View Post
Uh, how else could I do that then? One guy on my Skype made that with drunk level and it worked perfectly.
What's his FPS? If it's low, it'll work for him, but for people with like 100fps, like I have, they'll trigger it.

Try using some of the netstat functions.
https://sampwiki.blast.hk/wiki/Category:NetStats_Functions

But, if you make the timer 999 it might work, because the drunk level go down each second.
Reply
#7

Uh, he was a scripter on a server, it didn't only work for him, but everyone including me.
Reply
#8

Anyone? I really need that. :P Are there any other ways to detect desync? I don't want to set health or armor, etc. Also I think netstat functions have nothing to do with it. Or maybe someone knows how to fix my code?
Reply
#9

Well your code is pretty alright, only 1 thing is too much here,
drunklevel = GetPlayerDrunkLevel(playerid);
in the timer's public function makes it go too high, as a player would lose like 100 tops, then he would have 100 extra, these can easily add up to 2000 drunk level, which is the point which the screen starts shaking if a player is dysnced.
so remove the else clause, change the next line to
drunklevel = GetPlayerDrunkLevel(playerid)-200;

And it will be fixed.
Note that I'm just checking technical problems, I have no idea if this method will actually work for finding dysnced players.

Oh and btw using set and then get after that has a high chance of giving the old value since it's not updated for the player yet I guess.
Reply
#10

Uh, seems to be good now, at least drunk level is not going high. Not sure if it works though.
Reply
#11

The best way to check for Desync or lagging players is to get their packet loss + ping.
Reply
#12

Yes, but you may have high ping for a few seconds then back good again and you won't be desynced, that won't work I guess.
Reply
#13

but packetloss will work, if the packetloss reaches 0.5%+ then the player is going to be desync-ed or is desync.
Reply
#14

Is that true? If yes I'll do that.
Reply
#15

Yes it is, try searching for the function to get the packetloss of the player.

EDIT:
https://sampwiki.blast.hk/wiki/NetStats_PacketLossPercent
Reply
#16

How much ping would a player have with 0.5%+ packet loss? I tried warning player of being desynced when their packetloss is 0.5%+, but when I spawn it tells me that while I'm not lagging at all. So I guess adding GetPlayerPing will fix it?
Reply
#17

Quote:
Originally Posted by GoldenLion
View Post
How much ping would a player have with 0.5%+ packet loss? I tried warning player of being desynced when their packetloss is 0.5%+, but when I spawn it tells me that while I'm not lagging at all. So I guess adding GetPlayerPing will fix it?
Packetloss is caused by not receiving the packets at the right time and causes the server to resend the packet. packetloss causes the desync, packetloss is caused by extreme ping or server lag. Go in a testing server which is hosted and download some stuff via torrent, steam or your browser or just simply, open all the wi-fi devices, press and hold F5 and you will see your connection info. There's not any specific ping where player will loose packet, its up to their connection and (or) or the server
Reply
#18

How can I fix this then?
Here's the part of PlayerCheck, the timer repeats every second.
Code:
forward PlayerCheck();
public PlayerCheck()
{
	foreach (new i : Player)
	{		
		if (NetStats_PacketLossPercent(i) >= 0.5 && !PlayerData[i][pDesynced])
			PlayerData[i][pDesynced] = true;

		if (PlayerData[i][pDesynced])
			GameTextForPlayer(i, "~w~You are desynced~n~Please relog as soon~n~as possible", 1200, 3);
        }
}
Reply
#19

Quote:
Originally Posted by GoldenLion
View Post
How can I fix this then?
Here's the part of PlayerCheck, the timer repeats every second.
Code:
forward PlayerCheck();
public PlayerCheck()
{
	foreach (new i : Player)
	{		
		if (NetStats_PacketLossPercent(i) >= 0.5 && !PlayerData[i][pDesynced])
			PlayerData[i][pDesynced] = true;

		if (PlayerData[i][pDesynced])
			GameTextForPlayer(i, "~w~You are desynced~n~Please relog as soon~n~as possible", 1200, 3);
        }
}
A friend of mine runs a CoD server and he has scripted complete de-synchronization checker, I will ask him how he did that and run the timer every 5-10 seconds, packetloss doesn't increase that much in a second. Have you tried testing it on a hosted server and running some downloads or services which use internet?.

Testing code for debugging: using printf if the message is not sent.
Code:
forward PlayerCheck();
public PlayerCheck()
{
	foreach (new i : Player)
	{		
		if (NetStats_PacketLossPercent(i) >= 0.5 && !PlayerData[i][pDesynced])
			PlayerData[i][pDesynced] = true;

		if(PlayerData[i][pDesynced] && GetPlayerPing(i) >= 500)
			SendClientMessage(playerid, -1, "Lost bravo");
			printf("%d has lost bravo", i);

		if(NetStats_PacketLossPercent(i) >= 1.0)
			SendClientMessage(playerid, -1, "Lost alpha");
			printf("%d has lost alpha", i);

		if (PlayerData[i][pDesynced])
			GameTextForPlayer(i, "~w~You are desynced~n~Please relog as soon~n~as possible", 1200, 3);
			printf("%d has lost junior", i);
        }
}
Reply
#20

Uh, how could I slow down connection? I got new internet it's 5x faster than the old one... Also when doing that with drunk level I had a separate timer at OnPlayerSpawn, but it was causing random lag.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)