+ Reply to Thread
Results 1 to 9 of 9

Thread: extend loginEventHandler

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post

    extend loginEventHandler

    Hey,

    i just want to extend the loginEventHandler, which is already working fine and everything is invoked as expected. But i am missing the option to send a custom Message to the client with ChainAction.Fail
    How does that work?

    lets say in this snippet:

    Code:
    String query = "SELECT password FROM users WHERE username = '"+c.getUserName()+"';";
                    EsObject msg = activeRecord.doQuery(query);
                    if(msg.toString().equals(c.getPassword())) {
                        return ChainAction.OkAndContinue;
                    } else {
                        // message client about wrong password
                        return ChainAction.Fail;
                    }
    How do i send a custom message to the client like: "Hey your password is shit." ?

    Thanks,

    seb

  2. #2
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,212
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    You can't, because the user isn't logged in. If you need to be able to do this, then you will have to use a two stage login process. That's likely a good idea when you need to do a database access during login anyway. See Threading in Plugins for info on a two stage login process.

    If you don't want to use the two stage login process, have the client check the error message on the failed login. If the ErrorType is LoginEventHandlerFailure, then that means that your custom LoginEventHandler returned a Fail. If it's ES5 that failed the login, there will be a different ErrorType, such as UserNameExists.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    ah okay, thought since the client is already connected to the server But in this case i will just go with the second solution and use the ErrorType, saves some pain

    Thank you

  4. #4
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,212
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    As of ES5.1 "LoginEventHandlers can now set the response parameters on the LoginContext, which can be read by clients from the LoginResponse using getEsObject()." but I'm pretty sure that doesn't work if the login fails. You could try it and see if it works.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  5. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    this is working as well, how do i get the saved string on the client? My es object: {EsObject:
    pw:String = false
    }

    but how do i access the string?

  6. #6
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,212
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    If you have an EsObject named obj that is tracing out as
    {EsObject:
    pw:String = false
    }

    then you get that string by using:
    var temp:String = obj.getString("pw");

    If you just want to send true or false, I would suggest using a boolean to conserve bandwidth.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  7. #7
    Junior Member
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    yeah but i am on the client, is there also a method getString? if so in which namespace? because right now i get the error:

    error CS1061: Type `Electrotank.Electroserver5.Api.EsObjectRO' does not contain a definition for `getString' and no extension method `getString' of type `Electrotank.Electroserver5.Api.EsObjectRO' could be found (are you missing a using directive or an assembly reference?)

  8. #8
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,212
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    That's weird. The AS3 api clearly gives EsObjectRO as having a getString method. Looking at the C# docs, that might be the problem. Try creating a new variable of type EsObject, then using the EsObject.addAll method to suck in everything from your EsObjectRO.

    One of the TODOs for a future release is to remove all the EsObjectRO stuff from the client apis, so that there's just EsObject, which will cause less confusion.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  9. #9
    Junior Member
    Join Date
    Jan 2011
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    that actually did it, thank you teresa. The Read Only EsObject is really confusing sometimes, so might be worse removing it.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts