Page 1 of 2

Moderator, Admin, Standard, etc.

Posted: 20 Dec 2010, 13:32
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.

Posted: 20 Dec 2010, 14:06
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.

Posted: 20 Dec 2010, 17:54
by rjgtav
Thanks ;-)

Posted: 20 Dec 2010, 19:09
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...

Posted: 21 Dec 2010, 13:33
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.

Posted: 21 Dec 2010, 14:12
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?

Posted: 21 Dec 2010, 14:15
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.

Posted: 21 Dec 2010, 14:19
by Lapo
In which server event do you set the privilegeId? USER_JOIN_ZONE?

Posted: 21 Dec 2010, 14:22
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);
   }
}

Posted: 21 Dec 2010, 14:40
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

Posted: 21 Dec 2010, 14:43
by rjgtav
K. BTW, i'm working with the default ones, i only store them in a database. I'll try that later. Thanks

Posted: 21 Dec 2010, 14:48
by rjgtav
Can i use session.setProperty("$permission", theIdOfThePermissionProfile); instead?

Posted: 21 Dec 2010, 14:59
by Lapo
Yes but theIdOfThePermissionProfile must be anyways an instance of IPermissionProfile :)

Posted: 21 Dec 2010, 15:10
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 :-(

Posted: 21 Dec 2010, 15:31
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);
}