Sending custom IDisconnectionReason from server extension

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

OlegPumpkin
Posts: 4
Joined: 28 Aug 2017, 06:47

Sending custom IDisconnectionReason from server extension

Postby OlegPumpkin » 11 Apr 2018, 01:50

In my server extension's USER_JOIN_ZONE event handler a pass a custom IDisconnectionReason when I call User.disconnect. When this code is executed I never receive a call to my CONNECTION_LOST event handler on the client (Unity). The server logs or client logging show nothing. If I instead pass ClientDisconnectionReason.KICK to User.disconnect everything works as expected.

    Are custom IDisconnectionReason supported?
    Do I need to register them in the client, like how custom error codes are registered with SFSErrorCodes.SetErrorMessage?
    Are there any values other than the ones defined by ClientDisconnectionReason that the custom values cannot overlap with?

This is my IDisconnectionReason implementation:

Code: Select all

public enum MyCustomDisconnectReason implements IDisconnectionReason {
    JOIN_ROOM_FAILED(100),
    ROOM_DESTROYED(101);

    private final int value;

    MyCustomDisconnectReason(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public byte getByteValue() {
        //noinspection NumericCastThatLosesPrecision
        return (byte) value;
    }
}


This is how I use it (edited for brevity):

Code: Select all

public void handleServerEvent(ISFSEvent event) {
    User user = (User) event.getParameter(SFSEventParam.USER);
    try {
        getApi().joinRoom(user, getRoomToJoin(user.getSession()));
    } catch (SFSCreateRoomException | SFSJoinRoomException exception) {
        user.disconnect(MyCustomDisconnectReason.JOIN_ROOM_FAILED);
    }
}
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending custom IDisconnectionReason from server extension

Postby Lapo » 11 Apr 2018, 07:10

Hi,
no this is not supported. In particular, the the custom server-side DisconnectionReason won't be recognized on the client.

I would suggest a different strategy instead: send the disconnection reason via a custom Extension message, then schedule the disconnection to be executed 1 second later. This way your client will have time to receive the first message and react to it before getting actually disconnected.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 43 guests