Issue Assigning Custom Permission Profile "Vip"

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

Moderators: Lapo, Bax

Post Reply
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

Issue Assigning Custom Permission Profile "Vip"

Post by ciaoamigos »

Hi,
I've created a new permission profile on SmartFoxServer called "Vip" following thishttps://docs2x.smartfoxserver.com/A ... ge-manager. However, I receive an error when trying to assign it using session.setProperty("$permission", "Vip");.

Here’s the relevant code:

Code: Select all

switch (result.privilege) {
    case "Vip":
        session.setProperty("$permission", "Vip"); // Custom profile "Vip"
        break;
    // Other cases...
}

Issues:
An error occurs when assigning the "Vip" profile.
I have verified that the "Vip" profile is correctly created.
Questions:

What could be causing this error?
Is there something specific I should check in the configuration?
Thanks in advance!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue Assigning Custom Permission Profile "Vip"

Post by Lapo »

Hi,
custom permissions need to implement the IPermissionProfile interface.
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 custom Permissions using values > 3 (0..3 are reserved by the class above)
For example:

Code: Select all

public enum EliteUser implements IPermissionProfile {

    VIP(4),
    PRESIDENT(5);

    private short id;
    private UserPermission(int id) { this.id = (short) id; }
    public short getId() { return this.id; }
}


Finally you can assign the User permission with:

Code: Select all

session.setProperty("$permission", EliteUser.VIP);


Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

Re: Issue Assigning Custom Permission Profile "Vip"

Post by ciaoamigos »

my server-side extension is in JavaScript.
ciaoamigos
Posts: 70
Joined: 05 Sep 2021, 16:57

Re: Issue Assigning Custom Permission Profile "Vip"

Post by ciaoamigos »

News?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue Assigning Custom Permission Profile "Vip"

Post by Lapo »

Well, the user privilege id system is based on Java enums, and can be easily extended by Java Extensions.
In Javascript you'll need some hacking:

Code: Select all

var IPermProfile = Java.type("com.smartfoxserver.v2.security.IPermissionProfile")

var VipProfileClass = Java.extend(IPermProfile)
var vipProfile = new VipProfileClass() {
    getId: function() { return 4 }
}

this basically extends the IPermissionProfile interface from the SFS2X API.
You will need to create a different implementation for every new profile you need, each with its unique numeric value > 3

Then in your login handler you can assign like this:

Code: Select all

session.setProperty("$permission", vipProfile);


Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply