SA-MP Forums Archive
netstats_ functions doesn't work in OnPlayerDisconnect. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: Bug Reports (https://sampforum.blast.hk/forumdisplay.php?fid=20)
+--- Thread: netstats_ functions doesn't work in OnPlayerDisconnect. (/showthread.php?tid=497928)



netstats_ functions doesn't work in OnPlayerDisconnect. - QuaTTrO - 01.03.2014

I tried this code in OnPlayerDisconnect:
pawn Код:
printf("Connected time: %dms", NetStats_GetConnectedTime(playerid));
    printf("MSG Reveived: %d", NetStats_MessagesReceived(playerid));
    printf("Messages Sent: %d", NetStats_MessagesSent(playerid));
    printf("Bytes Sent:%d", NetStats_BytesSent(playerid));
    printf("Messages per second: %d", NetStats_MessagesRecvPerSecond(playerid));
    printf("Packet Loss: %f", NetStats_PacketLossPercent(playerid));
    printf("Connection status: %d", NetStats_ConnectionStatus(playerid));
And it always output:
Код:
[09:48:18] Connected time: 0ms
[09:48:18] MSG Reveived: 0
[09:48:18] Messages Sent: 0
[09:48:18] Bytes Sent:0
[09:48:18] Messages per second: 0
[09:48:18] Packet Loss: 0.000000
[09:48:18] Connection status: -1
[09:48:18] [part] QuaTTrO has left the server (0:1)
Is there a chance to fix it?


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - iJumbo - 01.03.2014

Well you can store the last > 0 or > -1 values and save them on disconnect ( i think you want save the stats to player data) right?


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - QuaTTrO - 01.03.2014

Quote:
Originally Posted by iJumbo
Посмотреть сообщение
Well you can store the last > 0 or > -1 values and save them on disconnect ( i think you want save the stats to player data) right?
Yes i want to save them. And i'm using timer to do that because of this bug.


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - fiki574 - 01.03.2014

Well, you get that output due to data being freed and reset when player disconnects (or is it something else maybe?). Have you tried using these functions in other callbacks rather than in OnPlayerDisconnect?


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - QuaTTrO - 01.03.2014

It works everywhere instead in OnPlayerDisconnect. I think the netstats data is reseted before OnPlayerDisconnect is called and IMO it should be reseted after OnPlayerDisconnect is called, like PVars do.


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - StreetGT - 01.03.2014

GetPlayerIP don't work OnPlayerDisconnect too so ^^


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - PowerPC603 - 02.03.2014

Isn't this normal behaviour?
After all, the client has already closed the connection to the server, and the server probably checks this and calls OnPlayerDisconnect.
The client cannot respond to server-calls anymore, so getting player-data is nearly impossible and unreliable.

You could use a timer to update the netstats every 5 seconds or so and store those values in variables/enums/arrays/whatever.

When OnPlayerDisconnect is called, save that data from those variables and save them.


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - wups - 02.03.2014

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Isn't this normal behaviour?
After all, the client has already closed the connection to the server, and the server probably checks this and calls OnPlayerDisconnect.
The client cannot respond to server-calls anymore, so getting player-data is nearly impossible and unreliable.

You could use a timer to update the netstats every 5 seconds or so and store those values in variables/enums/arrays/whatever.

When OnPlayerDisconnect is called, save that data from those variables and save them.
Most of the player data is only erased after this callback is called, so no, not very normal. I think the devs should stick to a standard to avoid problems(either erase the data before or after for everything). If it were erased after the callback, that would save us some resources.


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - Michael@Belgium - 02.03.2014

Ye, I can confirm this - I would like to see this changed/fixed. I tried to save total online time before of a player when the player disconnects with NetStats_GetConnectedTime(playerid) but indeed it didn't worked. It would be a lot easier if those functions would work in OnPlayerDisconnect()


Re: netstats_ functions doesn't work in OnPlayerDisconnect. - MP2 - 03.03.2014

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Isn't this normal behaviour?
After all, the client has already closed the connection to the server, and the server probably checks this and calls OnPlayerDisconnect.
The client cannot respond to server-calls anymore, so getting player-data is nearly impossible and unreliable.
Actually the data for the player's network stats is probably (it'd make the most sense) stored on the server, not requested from the client.

This is the case for most (if not all) things in SA-MP, for example if a player has 100 health and you run this code:

pawn Код:
SetPlayerHealth(playerid, 69);
new Float:health;
GetPlayerHealth(playerid, health);
printf("Health: %f", health);
You'd find that it prints out '100', not the '69' you'd expect. This is because the player's health is stored on the server, and won't be updated until the player syncs with the server (when OnPlayerUpdate is called).