Waiting on join room transaction

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

Moderators: Lapo, Bax

AliAlbarrak
Posts: 2
Joined: 02 Dec 2020, 07:27

Waiting on join room transaction

Postby AliAlbarrak » 02 Dec 2020, 08:10

Hello,
I have a use case where I'd like to join a user to a room (B) if he joined room (A) and specific conditions were met
So the scenario is:
1. User is in any room (X)
2. User send request to join room (A)
3. User is joined to room (A)
4. If condition is satisfied, join user to room (B)

I listen to USER_JOIN_ROOM event on room (A) extension

Code: Select all

addEventHandler(SFSEventType.USER_JOIN_ROOM, UserJoinedRoomEventHandler())

Code: Select all

class UserJoinedTournamentRoomEventHandler : BaseServerEventHandler() {

    override fun handleServerEvent(event: ISFSEvent) {
        val user = event.getParameter(SFSEventParam.USER) as User
        if (conditionIsMet(user))
            JoinRoomB(user)
    }

    // More code omitted for simplicity ...
}

But sometimes exception "SFSRuntimeException: Join request discarded. User is already in a join transaction" is thrown
I suspect that when server event is fired, user is still joining.
I can schedule JoinRoomB() to happen after a delay but that seems more of a hack and less of a solution

Is there a proper way to listen to USER_JOIN_ROOM then wait for user to finish joining then call another join room?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Waiting on join room transaction

Postby Lapo » 02 Dec 2020, 10:12

Hi,
you need to listen for the JOIN event if the client is requesting the Join, because you have no control over when this will happen.

However if you're joining from server Extension you don't need to use the event mechanism.
Just execute the two joins one after the other.

Example:

Code: Select all

try
{
   // Join Room A
   getApi().joinRoom(...);
   
   // Join Room B
   getApi().joinRoom(...);
}

catch(SFSJoinRoomException ex)
{
   // ... handle error
}

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Rob
Posts: 53
Joined: 01 Jul 2017, 07:33

Re: Waiting on join room transaction

Postby Rob » 02 Dec 2020, 12:35

Make your own custom message handler instead of using the standard ROOM_JOIN message.

Code: Select all

handleJoinRequest(event) {
if (conditionIsMet(user))
    joinRoomB(user))
else
   joinRoomA(user)
}

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 82 guests