How to add custom validation before user join room

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

Moderators: Lapo, Bax

hng
Posts: 2
Joined: 01 Nov 2021, 18:17

How to add custom validation before user join room

Postby hng » 01 Nov 2021, 18:44

How to add custom validation before user join room.

I want to check if user already join the specific room before but got disconnected and from client the user login again and want to join room again the server need to reject the user if less than 1 hour.

in Room Extension :

Code: Select all

 addEventHandler(SFSEventType.USER_JOIN_ROOM, event -> {
    if(SomeCheckFunc()){
       SFSErrorData errorData = new SFSErrorData(SFSErrorCode.JOIN_ROOM_LOCKED);
                errorData.addParameter("Error bla bla bla");
                throw new SFSJoinRoomException("error", errorData);
    }
 }



and in client :

Code: Select all


        sfs.addEventListener(SFSEvent.ROOM_JOIN, evt -> {
            showGameRoom();
        });
       
        sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, evt -> {
            System.out.println("Room joining failed: " + evt.getArguments().get("errorMessage"));
        });


ROOM_JOIN_ERROR is NEVER called. Is there anyway add validation on server side and force trigger ROOM_JOIN_ERROR in client ?

I know I can create custom handle in server and in client listen to extension response before continue room join or not but this have 2 issue, first not secure since final validation logic in client and second it is not practice need two step in client and server.

please any suggestion/clue
User avatar
Lapo
Site Admin
Posts: 22211
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to add custom validation before user join room

Postby Lapo » 05 Nov 2021, 15:13

Sorry for the late reply.
This was posted in the wrong section of the forum, under SFS1.x while it's actually SFS2X. I have now moved the topic.

The server-side event USER_JOIN_ROOM is triggered after a User has already joined a Room, so what you're trying to accomplish won't work.
To validate a User before he enters a specific Room you would need to send an ExtensionRequest from client side and validate it on the server side before joining the client also from the server side (via --> SFSApi.joinRoom())

If something is unclear let me know.
Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
hng
Posts: 2
Joined: 01 Nov 2021, 18:17

Re: How to add custom validation before user join room

Postby hng » 09 Nov 2021, 04:28

Thank you very much for you clarification
kirito
Posts: 2
Joined: 10 Jul 2021, 19:33

Re: How to add custom validation before user join room

Postby kirito » 16 Nov 2021, 04:08

Thanks for creating this thread, Pal. Saved my time :) Lapwhatsapp modo, big help..i appreciate your help. Hoping for the same support in the future.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 42 guests