pro_LoginExample bug and related question

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

watersdm
Posts: 13
Joined: 24 Apr 2006, 09:52

pro_LoginExample bug and related question

Postby watersdm » 24 Apr 2006, 10:06

Hi

I'm trying to follow your example of the proLoginExample (SmartFox Pro 1.4) and believe there is a bug in it. The client code includes the following:

Code: Select all

smartfox.onExtensionResponse = function(resObj:Object)
{
   if (resObj._cmd == "logOK")
   {
      // Login Successfull
      _global.myName = resObj.name
      gotoAndStop("chat")
   }
   else if (resObj._cmd == "logKO")
   {
      // Login Failed
      _gloabl.isBusy = true
      
      // Show an error window
      var win = showWindow("errorWindow")
      win.errorMsg.text = resObj.err
   }
}


but the server side does not return a name property in resObject on success. If you run the example you will see that after logging in successfully the chat is displayed but the username in the top right of the page says 'undefined'.

This leads me to my question... what I was trying to do was trap the logon, validate the user against my database and then set some properties for the user based on the database response e.g. cankick, canbemuted, etc etc. The intention is to have all the user properties held on the server so that it doesn't matter if the client is hacked but also have them available on the client so they can be used to alter the options displayed to the user (e.g. if cankick is false then the menu won't show that option).

My question then : is the 'handleInternalEvent' for 'loginRequest' the right place to put this code (permissions are by user not room so I really only want to do this once per 'session') and if it is (1) how can I get access to the client object on the server in this event and (2) how can I get the permissions on the client side if they are set this way as the client object doesn't seem to be passed back here.

Thanks a lot for your help! :-)

David
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 24 Apr 2006, 10:41

I don't know about the bug you are talking. Didn't ran into it, but I can answer you questions.
is the 'handleInternalEvent' for 'loginRequest' the right place to put this code (permissions are by user not room so I really only want to do this once per 'session')

Yep. The login requests can be handled inside the handleInternalEvent function inside the Zone Level extension IF the zone has customLogin set to true in the config.xml.
(1) how can I get access to the client object on the server in this event

This function is called before a client object is created on server. This allows you to reject a login attempt based on a provided password for example or based on a query of your database (for example if the user is banned or hasn't payed for entry).
When a loginRequest is handled, a user is identified only by his communication channel. There is not yet a user object created. All the data you have about the user is: evt.nick, evt.pass and evt.chan (his communication channel).
After you login a user using _server.loginUser(evt.nick, evt.pass, evt.chan) you can get the user Object using
var userObj = _server.getUserByChannel(evt.chan)
or you can also handle the "userJoin" internal event where you will recieve the user object as a parameter of the evt object.
how can I get the permissions on the client side if they are set this way as the client object doesn't seem to be passed back here.

I'm not sure if I understand this question. I hope the above is clear enough. Permisions are given by users to speciffic zones.. not by rooms. If you don't use the _server.loginUser() method then the user doesn't have access to the server. Even if a connection is estabilished with the server, the user can't login inside the Zone.
You can have zones with permisions based on user paying a certain fee for example, and zones where everybody is allowed to join (customLogin is set to false).

Cheers.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Xelius
Posts: 70
Joined: 06 Apr 2006, 15:16
Location: Sweden
Contact:

Postby Xelius » 24 Apr 2006, 11:45

Hi and welcome aboard! :D

I noticed Virusescu beat me to it with a reply, and I think he covered the most of your questions. But I already typed this up, so I might as well post it. :)

I'm trying to follow your example of the proLoginExample (SmartFox Pro 1.4) and believe there is a bug in it.

I noticed the bug aswell, but it's simply solved. All you need to do is pass the name with the response.

Code: Select all

var nick = evt["nick"]
response.name = nick

is the 'handleInternalEvent' for 'loginRequest' the right place to put this code

Yes. After you validated against your database you grab the properties for that user from the database and assaign them to the userVariables.

(1) how can I get access to the client object on the server in this event

You use the getUserByChannel method

Code: Select all

var u = _server.instance.getUserByChannel(chan)
_server.setUserVariables(u, { someVar:100, anotherVar:200 } )

(2) how can I get the permissions on the client side if they are set this way as the client object doesn't seem to be passed back here.

You can use the smartfox.onUserVariablesUpdate event to grab changes in the userVariables. But where you initialy find them is in the smartfox.onJoinRoom event.
watersdm
Posts: 13
Joined: 24 Apr 2006, 09:52

Perfect

Postby watersdm » 24 Apr 2006, 16:58

Thanks to you both for your extremely fast and detailed response. Your examples made it all very clear and I have it working now.

David
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 24 Apr 2006, 17:33

to Virusescu and Xelious: you guys are getting real SFS experts! :D
Thanks for your help :)

to watersdm: thanks for spotting the issue. We'll update the tutorial in the next release.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 35 guests