Custom Login Extension. So close! Need your help! :)

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

Moderators: Lapo, Bax

Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Custom Login Extension. So close! Need your help! :)

Postby Sparticus » 31 Jan 2011, 19:11

Hey all,

I am making a custom login extension. I already have it so the extension is successfully passed in a username and password, and it successfully checks to see if that is a valid user in my database.

That all works.

I do see when the extension ends it automatically fires off the "SFSEvent.LOGIN" event assuming there was no exceptions thrown.

In my "onLogin" function (whens gets called by the extension when it completes) I am passed in an "evt:SFSEvent" object. Can I add parameters to that objects somehow?

What I really want to do in the end is pass values from the database back to the client (like their current player level, etc).

I have been doing a ton of reading today and I think I might need to use the "send" method... but wouldn't that mean when tehy log in 2 responses are sent back to the client? (1 for the login successful, and 1 to tell the user their current player level).

Thanks in advance for any help you can give!
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 31 Jan 2011, 19:16

hi. u can use the setProperty method. check this topic => viewtopic.php?t=8843&highlight=
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.
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 31 Jan 2011, 19:58

Thank you so much! I can't believe 6 hours on google today couldn't find that forum post you linked me.


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

Postby rjgtav » 31 Jan 2011, 20:01

you welcome. maybe the search function in the forums would have found that post ;-)
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.
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 31 Jan 2011, 20:35

lol, ya. I did try the search on the forums but I always get tons of post that don't seem to apply.

Anyways, 1 more quick follow up question. I am now doing the following :

Code: Select all

ISFSObject sfso = new SFSObject();
sfso.putUtfString("level", "5");
sfso.putUtfString("rating", "1500");
ISFSObject responseObj = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
responseObj.putSFSObject("userData", sfso);


The above code successfully sends the users level and rating to them.

However, when someone joins a room "onUserEnterRoom" gets called. I tried to do this :

Code: Select all

trace("rating:"+user.getVariable("rating"));


and it returns null. I am guessing what I did in the first section of code was not tied to that user object?

What I need is a way for each user to be able to tell what level and rating each other player is.

Can you point me in the right direction?

Thanks


[/code]
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 31 Jan 2011, 20:54

the Object your sending to the client in the LOGIN_OUT_DATA is not stored as a userVariable, so yes, it's not tied to the user - it's just one time sent data.

You should set the userVariables on the Server during the USER_JOIN_ZONE event, possibly with something like this:

Code: Select all

else if(eventType.equals(SFSEventType.USER_JOIN_ZONE))
{
                UserVariable uv_rating = new SFSUserVariable("rating", 5);
                List<UserVariable> vars = new ArrayList<UserVariable>();
                vars.add(uv_rating);
                getApi().setUserVariables(user, vars, true, false);
}
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 31 Jan 2011, 21:04

Doesn't that mean all the users will get 1 notification that a user joined their room... and then another notification that that users userVariables have been updated?

Assuming I understood you correctly, that would be 2 messages spammed to all users for every new user that joins a room. Maybe that's just the way it has to work... but I thought I'd make sure before implementing it.

Thanks for your reply.
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 31 Jan 2011, 21:23

You can either suppress the events via "fireClientEvent, fireServerEvent"
http://docs2x.smartfoxserver.com/api-docs/javadoc/com/smartfoxserver/v2/api/ISFSApi.html#setUserVariables(com.smartfoxserver.v2.entities.User,%20java.util.List,%20boolean,%20boolean)

But in this situation the user isn't yet in a room, so nobody should get notified anyway.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 57 guests