netstats_ functions doesn't work in OnPlayerDisconnect.
#1

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?
Reply
#2

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?
Reply
#3

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.
Reply
#4

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?
Reply
#5

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.
Reply
#6

GetPlayerIP don't work OnPlayerDisconnect too so ^^
Reply
#7

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.
Reply
#8

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.
Reply
#9

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()
Reply
#10

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).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)