Author Topic: Functions called when a client connects and disconnects from a server?  (Read 1094 times)

/title
What are they and what are their arguments?
Can they be packaged?
« Last Edit: July 12, 2015, 11:58:45 AM by -Setro- »

There's GameConnection::onDrop(%this, %reason), which is called when a client is removed from the server, with %reason being the argument of %client.delete(reason), or a pre-programmed reason in the engine like "TimedOut" or "Packet Error."

onDrop calls GameConnection::onClientLeaveGame(%this) right after it decrements the player count but doesn't have the reason string. Note that this is only called when we know for a fact that the client was connected successfully (not necessarily authenticated, though) so it's probably best to use this instead of onDrop.

If you really need the reason string, use onDrop and just make sure to check if(%client.connected) to get the same assurance (and make sure to call the parent, too)
« Last Edit: July 12, 2015, 11:53:27 PM by Val »

There's GameConnection::onDrop(%this, %reason), which is called when a client is removed from the server, with %reason being the argument of %client.delete(reason), or a pre-programmed reason in the engine like "TimedOut" or "Packet Error."

onDrop calls GameConnection::onClientLeaveGame(%this) right after it decrements the player count but doesn't have the reason string. Note that this is only called when we know for a fact that the client was connected successfully (not necessarily authenticated, though) so it's probably best to use this instead of onDrop.

If you really need the reason string, use onDrop and just make sure to check if(%client.connected) to get the same assurance (and make sure to return the parent, too)
What's the function called when the client connects in the first place?
My fault, I wrote "leaves and disconnects" instead of "connects and disconnects"

I am assuming it is Gameconnection::onconnect, please tell me if it isn't.

I think most people use the admin check, because the person will have actually fully connected at that point (ie, not banned)

In most cases, you'll want to use GameConnection::autoAdminCheck(%this). It's essentially called when a client successfully connects (not exactly, but generally it's what you'll want for simply doing things when somebody joins). Make sure you return the value returned by the parent (return Parent::autoAdminCheck(%this);). If you want to do things earlier, search Coding Help for GameConnection::onConnectRequest.