Delay after the login failure

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
Scarpelius
Posts: 24
Joined: 12 Mar 2011, 11:33

Delay after the login failure

Postby Scarpelius » 01 May 2011, 08:25

Hello there

I am using for my game a custom login against the MySQL DB and it works like a charm :)
The problem is if i write the username or password wrong i have to wait like 25 seconds until the right user/password can be used again and this is related to the expiry of current session

Code: Select all

01 May 2011 12:05:50,361 WARN  [pool-1-thread-1] entities.managers.SFSExtensionManager     - com.smartfoxserver.v2.exceptions.SFSLoginException: Bad user name:
01 May 2011 12:06:15,158 INFO  [Scheduler1-thread-1] bitswarm.sessions.DefaultSessionManager     - Session removed: { Id: 8, Type: DEFAULT, Logged: No, IP: 192.168.1.4:12146 }
01 May 2011 12:06:15,159 INFO  [SocketReader] bitswarm.core.SocketReader     - Socket closed: java.nio.channels.SocketChannel[closed]
01 May 2011 12:06:15,999 INFO  [SocketReader] bitswarm.core.SocketAcceptor     - Session created: { Id: 9, Type: DEFAULT, Logged: No, IP: 192.168.1.4:12147 } on Server port: 9933 <---> 12147
01 May 2011 12:06:16,000 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] v2.controllers.SystemController     - {IN}: Handshake
01 May 2011 12:06:16,014 INFO  [com.smartfoxserver.v2.controllers.SystemController-1] v2.controllers.SystemController     - {IN}: Login
01 May 2011 12:06:16,034 INFO  [pool-1-thread-2] v2.api.SFSApi     - Login in, { Zone: OperationDraco }, ( User Name: xxx, Id: 2, Priv: 0, Sess: 192.168.1.4:12147 )


Between the Bad User name and Session removed there is no event, even if i click like mad the login button on client side.

So, where to look to solve this issue? Is it sfsx2 related or mysql? Or maybe Unity3D api side? I think i saw something related but i searched for 2 hours now and i cant find that thread.

PS I use Unity3D for client side.
User avatar
Scarpelius
Posts: 24
Joined: 12 Mar 2011, 11:33

Postby Scarpelius » 01 May 2011, 08:35

This is the login code, in case it have any relevance

Code: Select all

public class LoginEventHandler extends BaseServerEventHandler
{

    @Override
    public void handleServerEvent(ISFSEvent evt) throws SFSException
    {
   // Grab parameters from client request
   String userName = (String) evt.getParameter(SFSEventParam.LOGIN_NAME);
   String cryptedPass = (String) evt.getParameter(SFSEventParam.LOGIN_PASSWORD);
   ISession session = (ISession) evt.getParameter(SFSEventParam.SESSION);
   //boolean isAuthenticated = false;
   
   // Get password from DB
   IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
   Connection connection;
   
   try
   {
       // grab connection from DBManager connection pool
       connection = dbManager.getConnection();
       String sql = "SELECT Password, Id FROM user WHERE Username=?";
       PreparedStatement statment = connection.prepareStatement(sql);
       statment.setString(1, userName);
      
       ResultSet res = statment.executeQuery();
       if(!res.first())
       {
      // This is the part that goes to the client
      SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_USERNAME);
      errData.addParameter(userName);
      
      // This is logged on the server side
      throw new SFSLoginException("Bad user name: " + userName, errData);
       }
      
       String userPass = res.getString("Password");
       int userId = res.getInt("Id");
      
       if(!getApi().checkSecurePassword(session, userPass, cryptedPass.toLowerCase()))
       {
      SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
      data.addParameter(userName);
            
      throw new SFSLoginException("Login failed for user: " + userName, data); 
       }
      
       session.setProperty(SafeLevelExtension.USER_ID, userId);
      
       connection.close();
   }
   catch(SQLException e)
   {
       SFSErrorData errData = new SFSErrorData(SFSErrorCode.GENERIC_ERROR);
       errData.addParameter("SQL Error: " + e.getMessage());
   
       throw new SFSLoginException("A SQL Error occurred: " + e.getMessage(), errData);
   }
   
   
   
    }

}
User avatar
Scarpelius
Posts: 24
Joined: 12 Mar 2011, 11:33

Postby Scarpelius » 01 May 2011, 09:39

Never mind I solved it
It was my client side code.
Cant send login requests when you do smartfox.Connect() and allready connected :oops: the login code was only in OnConnection function.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 22 guests