Server-side JoinRoom handling

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

Moderators: Lapo, Bax

amateur
Posts: 29
Joined: 07 Jun 2017, 07:18

Server-side JoinRoom handling

Postby amateur » 22 Jan 2021, 10:44

Hi, a couple of quick questions on the server-side handling of the login and joinRoom process.

1. I have started to pass parameters during login, which I can retrieve using:
ISFSObject params = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
but earlier game versions didn't use this. Is there a way to detect whether the parameters are supplied or not? As a workaround, I am wrapping the code in a try, catch block but wanted to know if there's a better way.

2. Is it possible to use roomJoin without triggering the UserJoinedRoomEventHandler? Workaround here is to set a session property during login and skip code here depending on the setting in the session

3. I'm trying to set the permission level during sign-in, using a custom value (say, 8 ). The session.setProperty ("$permission" only allows the default permissions to be set, so I'm using user.setPrivilegeId(short(8)) in the UserJoineZoneHandler instead. Can setPrivilegeId be set during login? Do I need to use both session.setProperty(@$permission and also setPrivilegeID or can I use just one method?

4. The LoginHandler can be stopped using
throw new SFSLoginException("Login failed for user: " + username, data);
and this stops login altogether. I'd like to be able to do the same for the UserJoinedRoomEventHandler as well. I suspect you are already joined when this is triggered, so I can't prevent someone joining a room in this way - for now the workaround is to kick them out if not allowed. Is there a better way to prevent a user from being able to join a room?

Thanks
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Server-side JoinRoom handling

Postby Lapo » 25 Jan 2021, 11:34

Hi,
the thread was moved from the SFS1.x section to the SFS2X Questions section.

1. I have started to pass parameters during login, which I can retrieve using:
ISFSObject params = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
but earlier game versions didn't use this. Is there a way to detect whether the parameters are supplied or not? As a workaround, I am wrapping the code in a try, catch block but wanted to know if there's a better way.

You don't need a try/catch block to check if a parameter exists.
Just check if the parameter is not null.
I.e.:

Code: Select all

ISFSObject params = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
if (params =! null)
{
  // etc...
}


2. Is it possible to use roomJoin without triggering the UserJoinedRoomEventHandler? Workaround here is to set a session property during login and skip code here depending on the setting in the session

If we're talking about the server-side API, yes.
Check the SFSApi.joinRoom() method. It has a fireServerEvent parameter which you can set to false to avoid triggering the event.

If you're referring to a client side JoinRoomRequest, and you don't want to receive server side events I'd suggest not to add a listener for such event.

3. I'm trying to set the permission level during sign-in, using a custom value (say, 8 ). The session.setProperty ("$permission" only allows the default permissions to be set, so I'm using user.setPrivilegeId(short(8)) in the UserJoineZoneHandler instead. Can setPrivilegeId be set during login? Do I need to use both session.setProperty(@$permission and also setPrivilegeID or can I use just one method?

You should use the session.setProperty() call at login time, as explained here:
http://docs2x.smartfoxserver.com/Advanc ... ge-manager
bottom of the document.

4. The LoginHandler can be stopped using
throw new SFSLoginException("Login failed for user: " + username, data);
and this stops login altogether. I'd like to be able to do the same for the UserJoinedRoomEventHandler as well. I suspect you are already joined when this is triggered, so I can't prevent someone joining a room in this way - for now the workaround is to kick them out if not allowed. Is there a better way to prevent a user from being able to join a room?

The proper way to filter users from joining certain Rooms is to perform a server side join via Extension, rather than sending a JoinRoomRequest from client side.

In other words:
- Client send custom request to Extension asking to join Room X
- Extension runs custom logic and decides whether the client can join or not

This way your Extension can implement all the necessary checks before joining a User and refuse the join when necessary.
Also, you can configure your Zone to refuse client side Join requests, so that custom-made clients don't succeed in joining a certain Room via a client side request.

You can do that by disabling system events under the AdminTool > Zone Configurator > Advanced

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
amateur
Posts: 29
Joined: 07 Jun 2017, 07:18

Re: Server-side JoinRoom handling

Postby amateur » 26 Jan 2021, 10:41

What a terrific and thorough response!

I think I just need to clarify one thing: when I use
session.setProperty("$permission", DefaultPermissionProfile.MODERATOR);

how do I use, say, 8 instead of 2? It won't accept a (short) but I want to set it to something other than the default profiles.

Thanks.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Server-side JoinRoom handling

Postby Lapo » 27 Jan 2021, 08:49

Hi,
this is what the DefaultPermissionProfile class looks like.

Code: Select all

public enum DefaultPermissionProfile implements IPermissionProfile
{
   GUEST(0),
   STANDARD(1),
   MODERATOR(2),
   ADMINISTRATOR(3);
   
   private DefaultPermissionProfile(int id)
    {
      this.id = (short) id;
    }
   
   private short id;
   
   public short getId()
   {
      return id;
   }   
   
   public static DefaultPermissionProfile fromId(short id)
   {
      for (DefaultPermissionProfile dpp : values())
      {
         if (dpp.id == id)
            return dpp;
      }
      
      return null;
   }
}


You can create your own custom Permission profile implementing the same IPermissionProfile interface and just making sure not use any short int ID > 3

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
amateur
Posts: 29
Joined: 07 Jun 2017, 07:18

Re: Server-side JoinRoom handling

Postby amateur » 04 Feb 2021, 18:14

Thanks Lapo, I did get it all working with a custom permission profile. This keeps all the logic on the server and it is brilliant.

Many thanks

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 40 guests