Custom login extension doesnt work!

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Custom login extension doesnt work!

Postby antuan » 03 May 2012, 13:02

Hello,

I am trying to create a custom login extension. Everything works fine. When I send wrong login parameters, the socket throw an error, but user login successfully. The client side doesnt receive any error. I see the error on the system logs. My codes and logs is here:

Client :

Code: Select all


public function login():void
      {
         addEventListener(SFSEvent.LOGIN, onLogin);
         addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
               
         send(new LoginRequest(username, password, zone));
      }

      private function onLoginError(event:SFSEvent):void
      {
         dispatchEvent(new Event(CustomEvent.LOGIN_ERROR));
      }

      private function onLogin(event:SFSEvent):void
      {
         dispatchEvent(new Event(CustomEvent.LOGIN_SUCCESS));
      }




Server :

Code: Select all


package sfs2x.extensions.coolgames.poker.src;

import com.smartfoxserver.bitswarm.sessions.ISession;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.SFSArray;
import com.smartfoxserver.v2.exceptions.SFSErrorCode;
import com.smartfoxserver.v2.exceptions.SFSErrorData;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.exceptions.SFSLoginException;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;

public class Login {
   
    Database database;   
    String username;
    String password;
    User user;
    ISession session;
    Room gameRoom;

   public Login(ISFSEvent event, Game game) throws SFSException
   {       
       username = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
       password = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);       
       user = (User)event.getParameter(SFSEventParam.USER);
       session = (ISession)event.getParameter(SFSEventParam.SESSION);       
       gameRoom = game.getGameRoom();
             
       SFSErrorData data;
       
       database = new Database();
           
        try {
           
            SFSArray row = database.login(game, session, username, password);
           
            if(row.size() == 0){

                SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
                errData.addParameter(username);             
               
                throw new SFSLoginException(username +" is not allowed in this Zone!", errData);
            }
                   
            if (password.equals(""))
            {
                data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
                data.addParameter(username);
                throw new SFSLoginException("You must enter a password.", data);
            }
           
           if (!username.equals("admin") && !password.equals("admin") &&
                   !game.getApi().checkSecurePassword(session, row.getSFSObject(0).getUtfString("user_password"), password))
           {
                data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);

                data.addParameter(username);

                throw new SFSLoginException("Login failed for user: "  + username, data);
           }

            game.trace("Login successfully!");

        } catch (Exception e) {
            game.trace(ExtensionLogLevel.WARN, " SQL Failed: " + e.toString());
        }
       
   }
   
}






logs :


03 May 2012 | 14:44:01,609 | WARN | pool-1-thread-2 | Extensions | {Game}: SQL Failed: com.smartfoxserver.v2.exceptions.SFSLoginException: asdfasdfwer is not allowed in this Zone!

03 May 2012 | 14:44:01,611 | INFO | pool-1-thread-2 | v2.api.SFSApi | Login in, { Zone: Game }, ( User Name: asdfasdfwer, Id: 1, Priv: 0, Sess: 192.168.110.1:54162 )




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

Re: Custom login extension doesnt work!

Postby rjgtav » 03 May 2012, 19:27

Hi.
Are you using the latest SFS2X Final Release (2.0.1) alongside with the latest Java client API at http://www.smartfoxserver.com/download/sfs2x#p=updates?
And what socket error are you getting on the client-side?
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.
itsmylifesoham
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: Custom login extension doesnt work!

Postby itsmylifesoham » 04 May 2012, 04:15

on your client you must be having a sfs = new SmartFox(); object right?

do sfs.addEventListener(SFSEvent.login_error,handler);

make sure that in your admin tool the use custom login is set to true for the zone configuration.
antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Re: Custom login extension doesnt work!

Postby antuan » 04 May 2012, 07:27

rjgtav wrote:Hi.
Are you using the latest SFS2X Final Release (2.0.1) alongside with the latest Java client API at http://www.smartfoxserver.com/download/sfs2x#p=updates?
And what socket error are you getting on the client-side?



The server version is SFS2X-PatchRC3 and there is no any error on the client side. I activated the custom login from the admin tools.
antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Re: Custom login extension doesnt work!

Postby antuan » 04 May 2012, 07:36

itsmylifesoham wrote:on your client you must be having a sfs = new SmartFox(); object right?

do sfs.addEventListener(SFSEvent.login_error,handler);

make sure that in your admin tool the use custom login is set to true for the zone configuration.


Sfs can connect socket, get the room list or join a room. Everything works fine. Also the socket throw an error when user send wrong login parameters, but I cant get the error on the client side. The custom login is active on the admin tool. MY server version is SFS2X-PatchRC3.

My client side code :

Code: Select all


public class SFSWrapper extends SmartFox
{

           ......

public function login():void
      {
         addEventListener(SFSEvent.LOGIN, onLogin);
         addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
               
         send(new LoginRequest(username, password, zone));
      }

      private function onLoginError(event:SFSEvent):void
      {
             trace("Login error");
      }

      private function onLogin(event:SFSEvent):void
      {
             trace("Login success");
      }

          .....

}

User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Custom login extension doesnt work!

Postby Bax » 04 May 2012, 08:53

Before reporting possible errors, please make sure you install the latest server version, patches and API updates.
Pleas update and retest. Thanks.
Paolo Bax
The SmartFoxServer Team
antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Re: Custom login extension doesnt work!

Postby antuan » 04 May 2012, 12:38

Bax wrote:Before reporting possible errors, please make sure you install the latest server version, patches and API updates.
Pleas update and retest. Thanks.



I installed the patch version 2.1.0, but the error still exist.


The logs :

04 May 2012 | 14:34:28,033 | INFO | SocketReader | bitswarm.core.SocketAcceptor | Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 192.168.110.1:51100 } on Server port: 9933 <---> 51100
04 May 2012 | 14:34:44,429 | WARN | pool-1-thread-3 | Extensions | {Games}: SQL Failed: com.smartfoxserver.v2.exceptions.SFSLoginException: user is not allowed in this Zone!
04 May 2012 | 14:34:44,430 | INFO | pool-1-thread-3 | v2.api.SFSApi | Login in, { Zone: Game }, ( User Name: user, Id: 1, Priv: 0, Sess: 192.168.110.1:51100 ) , Type: FlashPlayer:Desktop:WIN 10,2,153,1, CCU: 1/2




my server boot logs :
04 May 2012 | 14:24:47,223 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | Scheduler stopped. Unprocessed tasks: 0
04 May 2012 | 14:24:47,223 | WARN | Scheduler1-thread-1 | bootLogger | | Scheduler: scheduler interrupted.
04 May 2012 | 14:24:47,223 | INFO | SocketWriter-1 | bootLogger | | SocketWriter threadpool shutting down.
04 May 2012 | 14:24:47,224 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | SocketWriter stopped. Unprocessed tasks: 0
04 May 2012 | 14:24:47,224 | INFO | SocketReader | bootLogger | | SocketWriter threadpool shutting down.
04 May 2012 | 14:24:47,725 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | SocketReader stopped. Unprocessed tasks: 0
04 May 2012 | 14:24:49,728 | INFO | com.smartfoxserver.v2.controllers.SystemController-1 | bootLogger | | Controller worker threads stopped: com.smartfoxserver.v2.controllers.SystemController
04 May 2012 | 14:24:49,729 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | Security Manager stopped
04 May 2012 | 14:24:49,730 | WARN | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | Error when shutting down Accept selector: sleep interrupted
04 May 2012 | 14:24:49,730 | INFO | SocketAcceptor-1 | bootLogger | | SocketAcceptor threadpool shutting down.
04 May 2012 | 14:24:49,730 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-2 | bootLogger | | Controller worker threads stopped: com.smartfoxserver.v2.controllers.ExtensionController
04 May 2012 | 14:24:49,730 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | SocketAcceptor stopped. Unprocessed tasks: 0
04 May 2012 | 14:24:49,731 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-1 | bootLogger | | Controller worker threads stopped: com.smartfoxserver.v2.controllers.ExtensionController
04 May 2012 | 14:24:49,731 | INFO | com.smartfoxserver.v2.controllers.ExtensionController-3 | bootLogger | | Controller worker threads stopped: com.smartfoxserver.v2.controllers.ExtensionController
04 May 2012 | 14:24:51,701 | INFO | main | bootLogger | | SmartFoxServer 2X
04 May 2012 | 14:24:51,702 | INFO | main | bootLogger | | BitSwarmEngine version: 3.4.5-Gold { main }
04 May 2012 | 14:24:51,703 | INFO | main | bootLogger | | System Info:
Processor(s): 4
VM Max. memory: 469MB
os.name: Linux
os.arch: amd64
os.version: 2.6.32-5-amd64
java.version: 1.6.0_21
java.vendor: Sun Microsystems Inc.
java.vendor.url: http://java.sun.com/
java.vm.specification.version: 1.0
java.vm.version: 17.0-b16
java.vm.vendor: Sun Microsystems Inc.
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.io.tmpdir: /tmp
Default charset: UTF-8

04 May 2012 | 14:24:51,704 | INFO | main | bootLogger | | Network Info:
Card: eth0
->fe80:0:0:0:20c:29ff:feff:a62d%2
->192.168.110.130
Card: lo
->0:0:0:0:0:0:0:1%1
->127.0.0.1

04 May 2012 | 14:24:51,709 | INFO | main | bootLogger | | Session manager ready: com.smartfoxserver.bitswarm.sessions.DefaultSessionManager@552cf9bd
04 May 2012 | 14:24:51,713 | INFO | main | bootLogger | | ReaderSelector opened
04 May 2012 | 14:24:51,719 | INFO | main | bootLogger | | AcceptSelector opened
04 May 2012 | 14:24:51,721 | INFO | main | bootLogger | | Added bound tcp socket --> 192.168.110.130:9933
04 May 2012 | 14:24:51,723 | INFO | main | bootLogger | | Added bound udp socket --> 192.168.110.130:9933
04 May 2012 | 14:24:51,724 | INFO | main | bootLogger | | Controller started: com.smartfoxserver.v2.controllers.SystemController -- Queue: 0/20000
04 May 2012 | 14:24:51,724 | INFO | main | bootLogger | | Controller started: com.smartfoxserver.v2.controllers.ExtensionController -- Queue: 0/20000
04 May 2012 | 14:24:51,725 | INFO | main | bootLogger | | IOHandler: com.smartfoxserver.v2.protocol.SFSIoHandler@6e18e546
04 May 2012 | 14:24:51,725 | INFO | main | bootLogger | | SocketReader started
04 May 2012 | 14:24:51,725 | INFO | main | bootLogger | | SocketAcceptor initialized
04 May 2012 | 14:24:51,725 | INFO | main | bootLogger | | Socket Writer started (pool size:1)
04 May 2012 | 14:24:51,725 | INFO | Scheduler1-thread-1 | bootLogger | | Scheduler started: scheduler
04 May 2012 | 14:24:51,726 | INFO | main | bootLogger | | Security Manager started
04 May 2012 | 14:24:51,728 | INFO | main | bootLogger | | [[[ ===--- Boot sequence complete ---=== ]]]
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Custom login extension doesnt work!

Postby Bax » 04 May 2012, 13:18

If you installed the 2.1.0 patch on your previous RC3 version.. you made a mess!
As reported in the requirements, the patch requires the final version, not the release candidate.
Please install SFS2X from scratch getting it from the website, the patch it.
Paolo Bax
The SmartFoxServer Team
antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Re: Custom login extension doesnt work!

Postby antuan » 04 May 2012, 13:57

Bax wrote:If you installed the 2.1.0 patch on your previous RC3 version.. you made a mess!
As reported in the requirements, the patch requires the final version, not the release candidate.
Please install SFS2X from scratch getting it from the website, the patch it.


I installed already the final release and patched it. The error still exist.
antuan
Posts: 10
Joined: 06 Dec 2010, 11:49

Re: Custom login extension doesnt work!

Postby antuan » 04 May 2012, 16:01

antuan wrote:
Bax wrote:If you installed the 2.1.0 patch on your previous RC3 version.. you made a mess!
As reported in the requirements, the patch requires the final version, not the release candidate.
Please install SFS2X from scratch getting it from the website, the patch it.


I installed already the final release and patched it. The error still exist.



The problem solved! The reason is that I forgot to add the code "new throw".

Thank you for your all help!

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 28 guests