Moderator, Admin, Standard, etc.

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

Moderators: Lapo, Bax

User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Moderator, Admin, Standard, etc.

Post by rjgtav »

Hi. Today i was trying the isModerator, isAdmin and isStandardUser methods and realized that all returned false, even loggin with admin's username and password. And curiously the only one that returned true was isGuest, but i'm not loging in as a guest... Am i doing something wrong during the login phase or this feature isnt implemented yet?

BTW i can't find where to define the moderators, only the admin.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Post by appels »

you need to look at the privilige manager in the docs, when you logged in a user you will need to assign the group in the onjoinzone handler.
you need to store the permission profile Id in the Session properties but i got stuck on the retrieval of the group id when i needed to assign the group.
i have not had a chance yet to work more on it.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Thanks ;-)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

So... I have already configured the privilege manager, before joining the lobby I set the user's privilege id to the one given from the database (via server extension). In the AdminTool it shows the correct privilegeID/profileID (in this case is 2 that means the user is a Moderator). But when i check with user.isModerator(), it still returns false and saying that the user is a Guest... What am I missing?

BTW, the privilege Manager is working. For example if i deny the moderator to send public messages, it doesnt let it send.

[UPDATE]

For some reason, the other players can see that this user is moderator when they join into the lobby or when the moderator joins in...
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ethereal
Posts: 54
Joined: 02 Nov 2005, 18:26
Location: netherlands

Post by ethereal »

rjgtav wrote:
For some reason, the other players can see that this user is moderator when they join into the lobby or when the moderator joins in...
I have exactly the same problem.
Every client gets the right privilege ID except the user where the privilige id is assigned to, and set the ID manually doesn't work clientside either :(

doesn't make any difference if the users are allready logged in, or logged in after the "moderator". only the holder off the privilege id doesnt get it right.
Flex, Smartfoxserver, red5. and Linux Why does microsoft still exist?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Can you explain how the profiles where configured?
The first four ids (0,1,2,3) are reserved. They represent: guest, regular, moderator and admin

If you want to add more types you can do it by adding more values after the initial 4.

Is the login handled by Extension code?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Hi. My profiles are the default ones. 0-Guest, 1-Standard, 2-Moderator and 3-Administrator. And yes, the login is handled by Extension code. and it successfully sets the correct privilegeId, retrieved from the database.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

In which server event do you set the privilegeId? USER_JOIN_ZONE?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Yup.

here's the code BTW:

Code: Select all

public class JoinEventHandler extends BaseServerEventHandler
{
   @Override
    public void handleServerEvent(ISFSEvent event) throws SFSJoinRoomException
   {
       trace("<-JOIN ZONE EVENT->");
       trace("joining room");
       Zone zone =  SmartFoxServer.getInstance().getZoneManager().getZoneByName(Main.ZONE);
       Room room = zone.getRoomByName("Lobby");
       User user = (User) event.getParameter(SFSEventParam.USER);
       ISFSApi smartfox = SmartFoxServer.getInstance().getAPIManager().getSFSApi();
       ISession session = user.getSession();
       
       SFSObject userInfo = (SFSObject) session.getProperty("userInfo");

       trace("privlegeID: "+(Short.parseShort((userInfo.getUtfString("privilege")).trim())));
       user.setPrivilegeId(Short.parseShort((userInfo.getUtfString("privilege")).trim()));

       List<UserVariable> vars = new ArrayList<UserVariable>();
       vars.add(new SFSUserVariable("lv",userInfo.getUtfString("lv")));
       vars.add(new SFSUserVariable("country",userInfo.getUtfString("country")));

       smartfox.setUserVariables(user, vars);

       trace("room: "+room);
       trace("user: "+user);
       smartfox.joinRoom(user, room);
   }
}
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Ok, gotcha.
The problem is that the USER_JOIN_ZONE is "too late". The login response has already been sent to the User and that one contains the privilegeID for the client API.

There's a trick for this, and I am sorry to say we haven't documented this yet, because it's quite advanced. I will make sure that a note is added in the Login tutorials about this.

You need to set the profileID in the USER_LOGIN event, by storing it as a property in the Session object. The convention requires that the property key is called --> $permission.
This is the code:

Code: Select all

session.setProperty("$permission", DefaultPermissionProfile.MODERATOR);
Of course, if you are working with privilege ID other than the default ones you will first need to create a Class/Enum that implements the IPermissionProfile interface and that describe the new permission id(s);

Example:

Code: Select all

public enum JediPermissionProfile implements IPermissionProfile
{
	JEDI_INITIATE(4),
	JEDI_PADAWAN(5),
	JEDI_KNIGHT(6),
	JEDI_MASTER(7);
	
	private JediPermissionProfile(int id)
   {
		this.id = (short) id;
   }
	
	private short id;
	
	public short getId()
	{
		return id;
	}
}
Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

K. BTW, i'm working with the default ones, i only store them in a database. I'll try that later. Thanks
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Can i use session.setProperty("$permission", theIdOfThePermissionProfile); instead?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes but theIdOfThePermissionProfile must be anyways an instance of IPermissionProfile :)
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Ok thanks again. That turns this much easier

[EDIT]

Ups. i thought that i could use session.setProperty("$permission", 2) instead of session.setProperty("$permission", DefaultPermissionProfile.MODERATOR) but i've already seen that i can't :-(
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

is there a better way than using this?

Code: Select all

Short privilegeId = Short.parseShort((userData.getUtfString("PRIVILEGE")).trim());

if(privilegeId == 0){
        session.setProperty("$permission", DefaultPermissionProfile.GUEST);
}else if(privilegeId == 1){
        session.setProperty("$permission", DefaultPermissionProfile.STANDARD);
}else if(privilegeId == 2){
        session.setProperty("$permission", DefaultPermissionProfile.MODERATOR);
}else if(privilegeId == 3){
        session.setProperty("$permission", DefaultPermissionProfile.ADMINISTRATOR);
}
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Post Reply