How do I detect player(-client) disconnects correctly?

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

How do I detect player(-client) disconnects correctly?

Post by Hyrelius »

Hello,

since I am writing some scripts, that depend on the players being online, I'd like to know if there is a way to detect disconnects on the server side. I'd prefer a reliable way, but any way is good.

So far I've been trying to find workarounds - e.g. if a player makes an attempt to login with another char etc. But what I'd really like to do, is be able to reliably determine if a given player is not offline.
The problem is, that so far I determined different behaviors depending on how the user disconnects. If it's a BufferOverflow, caused by e.g. a malformed L2-HTML-file, the client crashes, but it seems it - sometimes - sends a notification to the server about being closed. It seems not to do this if e.g. the connection to the server is closed on the client-side by removing the LAN-cable from the computer.

Does someone know how to - reliably if possible - check, whether a given player is online or not?

Thanks in advance!
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: How do I detect player(-client) disconnects correctly?

Post by Zoey76 »

What about loggin/disconnect listeners??
Powered by Eclipse 4.34 ๐ŸŒŒ | Eclipse Temurin 21 โ˜• | MariaDB 11.3.2 ๐Ÿ—ƒ๏ธ | L2J Server 2.6.3.0 - High Five ๐Ÿš€

๐Ÿ”— Join our Discord! ๐ŸŽฎ๐Ÿ’ฌ
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: How do I detect player(-client) disconnects correctly?

Post by UnAfraid »

player logout listener will catch L2PcInstance being deleted so it means it will catch every possible logging out.
Image
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: How do I detect player(-client) disconnects correctly?

Post by Hyrelius »

Alright - so basically onPlayerLogout is what I'd be using, right?

It seems, that onPlayerLogout correctly catches any kind of player logout. However: when a player disconnects it does not necessarily mean, that the player logs out (from what I've seen). Sometimes you see a toon ingame, yet the player client already crashed and the toon did not log out.

So while your information, @UnAfraid, is most likely correct - it is not exactly what I am looking for as I want to be able to catch "onPlayerDisconnect"-events. Currently I implemented behavior on player log-out + log-in in order to determine what to do in such a case. But it is not reliable enough and I also cannot differentiate between a forced player client logout (by killing the L2.exe-process) from a typical client crash. I guess I won't be able to do that, because the client does not send any information to the client in this regard, right?

Anyway - thanks for the suggestions so far :), but is there a way to better determine player client disconnects?
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
Post Reply