Stop the login process

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

Moderators: Lapo, Bax

User avatar
Wei
Posts: 50
Joined: 13 Jun 2017, 08:16

Stop the login process

Postby Wei » 17 Jun 2017, 18:20

The login process will be stopped and user will trigger LOGIN_ERROR event if I use the following code, right?

SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);

throw new SFSLoginException("User login error", errData);
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Stop the login process

Postby Lapo » 19 Jun 2017, 07:01

Yes,
on the server side, if you throw a LoginException it will cause a LOGIN_ERROR on the client.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Wei
Posts: 50
Joined: 13 Jun 2017, 08:16

Re: Stop the login process

Postby Wei » 19 Jun 2017, 13:41

thanks man, you rock!
User avatar
Wei
Posts: 50
Joined: 13 Jun 2017, 08:16

Re: Stop the login process

Postby Wei » 08 Jul 2017, 14:35

HI Lapo, below is my code, regardless of what user name or password I've used, I could login, client does not receive LOGIN_ERROE, but there was a error message on server console. What did I miss?

Code: Select all

public class OnLogin extends BaseServerEventHandler {
   
    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
   
        ISFSObject userdata = new SFSObject();
        String uName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
        String uPasswd = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
       
        ISession session = (ISession) event.getParameter(SFSEventParam.SESSION);
       
        if(!Objects.equals(uName, "Mazing"))
        {
            SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
            errData.addParameter(uName);
           
            throw new SFSLoginException("Bad user name", errData);
        }
       
        if(!getApi().checkSecurePassword(session, "123876", uPasswd))
        {
            SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
            errData.addParameter(uPasswd);
   
            throw new SFSLoginException("Bad password", errData);
        }
       
        userdata.putUtfString("name", uName);
        userdata.putUtfString("id", "100001");
        userdata.putInt("cards", 9);
        session.setProperty("userdata", userdata);
       
    }
   
}

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

Re: Stop the login process

Postby Lapo » 09 Jul 2017, 16:59

Make sure you have turned on the "Custom login" flag in your zone config.
This tells the server to send all login requests to your Extension.

Cheers
p.s. = if you had an error post the stack trace here.
Lapo

--

gotoAndPlay()

...addicted to flash games
croftie
Posts: 49
Joined: 24 Jul 2013, 08:35
Location: Algarve Portugal
Contact:

Re: Stop the login process

Postby croftie » 09 May 2019, 05:41

Bit of an old thread but I am seeing the same behaviour

To test I have set the login handler to always throw a simple login exception with no additional code

Code: Select all

      SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
      try {
         throw new SFSLoginException("authentication failed", errData);         
      } catch (SFSLoginException e) {
         ext.trace(e);
      }


I can see the error in the server console followed by a user login

05:32:21,453 INFO [SFSWorker:Ext:1] Extensions - {CasinoFloorStage}: com.smartfoxserver.v2.exceptions.SFSLoginException: authentication failed
05:32:21,464 INFO [SFSWorker:Ext:1] api.SFSApi - User login: { Zone: CasinoFloorStage }, ( User Name: appUser, Id: 0, Priv: 0, Sess: 90.255.234.203:65277 ) , Type: IOS version: 12.2


The client always fires the onLogin and never the onLoginError.

I don't think I am missing anything but the behaviour does not seem to be correct
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Stop the login process

Postby Lapo » 09 May 2019, 07:45

Hi,
the problem with your code is that you're catching the Exception. By doing so you're not allowing the Exception to travel up the call chain and stop the login process.
Simply remove the try/catch block.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 56 guests