Page 1 of 1
Checking if the user is a mod
Posted: 29 Aug 2009, 18:18
by Thunder
Hello,
I am using a custom login extension, but how can I check if they are a moderator and return that they are or not. Because if I add it to the config file and run a
Code: Select all
if(smartfox.amIModerator){
trace('IM MOD');
}else{
trace('IM NOT MOD');
}
It always says I am not a mod.
Thanks
Re: Checking if the user is a mod
Posted: 29 Aug 2009, 21:28
by Thunder
Ah I fixed this with the Addmoderator on the extension. Still getting used to using extensions
Posted: 06 Nov 2009, 08:20
by sharingan
Hi Thunder (and anyone in the SFS team)!
I am also using an extension to add moderators to my zone, instead of putting them in the config file. The moderators are added after the user logs in, then I call an actionscript extension that checks the database to see if the user is a moderator. If he is, then I call these two lines in the extension:
Code: Select all
if (!user.isModerator()) {
_server.addModerator(_server.getCurrentZone().getName(), user.getName(), "");
user.setAsModerator(true);
}
Well this kinda works, except the mod user has to log in once, log out then log in again before his mod status is reflected. I'm aware I need to send something back to the user when his status is first updated on smartfox server but I'm not sure what I'm supposed to send back after I set him as moderator. Can anyone help?
Posted: 09 Nov 2009, 18:46
by Lapo
When you use AddModerator you are adding new moderator accounts... in other words you're creating mod profiles.
If you want to immediately set a User as a Mod you should simply call User.setAsModerator(true) right after having logged him in. It should do the trick.
Hope it helps
Posted: 10 Nov 2009, 10:15
by sharingan
Thanks for replying, Lapo! Hmmm now it kinda works if I put the names in the config file, then just call User.setAsModerator(true) after logging in but during loading of user data from the database.
However, what I need to do is actually get whether the user is a moderator from the database. So the order is as follows:
1. User logs in
2. User joins room
3. User loads data from database - check if user is a moderator
- if database says user is a moderator but is not registered as a user in the sfs, I addModerator for the user account, and setAsModerator(true).
Yup, so I'm back to the same problem... The user has to log in once, log out then login again before his mod status is reflected.
Posted: 10 Nov 2009, 11:19
by Lapo
1. User logs in
2. User joins room
3. User loads data from database - check if user is a moderator
- if database says user is a moderator but is not registered as a user in the sfs, I addModerator for the user account, and setAsModerator(true).
In your flow there is a problem because you set the moderator flag too late, after having joined the database data.
I would have expected that you loaded the User data immediately in the server side login event. That's the place where you can check the credentials and accept or refuse the client.
Once the User object is returned by the login call in your extension you just set it as Moderator and you should be done.
There is probably one more thing to do for the client side. Since the login response is custom created by your extension you should notify your client that he is a moderator by sending a flag.
When you receive that flag you can set the amIModerator boolean in the SmartFoxClient.
Hope it helps