disconnect users

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

Moderators: Lapo, Bax

hebatarek
Posts: 21
Joined: 16 May 2016, 08:50

disconnect users

Postby hebatarek » 29 Mar 2017, 09:29

Hello

I hope anyone could help me in my problem

server version: 2.12.0

the problem happens when user disconnect for any reason, the following exception appeared

Code: Select all

10:17:47,645 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 192.168.1.1:65074 }
10:17:47,655 WARN  [SFSWorker:Sys:1] v2.SmartFoxServer     - java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
+--- --- ---+
Stack Trace:
+--- --- ---+
java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
com.smartfoxserver.v2.entities.managers.SFSUserManager.removeUser(SFSUserManager.java:118)
com.smartfoxserver.v2.entities.managers.SFSUserManager.disconnectUser(SFSUserManager.java:257)
com.smartfoxserver.v2.entities.SFSZone.removeUser(SFSZone.java:1270)
com.smartfoxserver.v2.api.SFSApi.disconnectUser(SFSApi.java:305)
com.smartfoxserver.v2.api.SFSApi.disconnect(SFSApi.java:214)
com.smartfoxserver.v2.SmartFoxServer.onSessionClosed(SmartFoxServer.java:1002)
com.smartfoxserver.v2.SmartFoxServer.access$2(SmartFoxServer.java:1000)
com.smartfoxserver.v2.SmartFoxServer$EventDelegate.run(SmartFoxServer.java:1109)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


and when user login again, the following exception appeared

Code: Select all

10:17:52,320 INFO  [SFSWorker:Ext:4] scala.DefLI     - User already logged in. Disconnecting previous instance : ( User Name: null, Id: 0, Priv: 0, Sess: 192.168.1.1:65074 )
10:17:52,321 WARN  [SFSWorker:Ext:4] managers.SFSExtensionManager     - java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error during event handling: java.lang.NullPointerException, Listener: { Ext: __lib__, Type: JAVA, Lev: ZONE, { Zone: saudi }, {} }
+--- --- ---+
Stack Trace:
+--- --- ---+
java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
com.smartfoxserver.v2.entities.managers.SFSUserManager.removeUser(SFSUserManager.java:118)
com.smartfoxserver.v2.entities.managers.SFSUserManager.disconnectUser(SFSUserManager.java:257)
com.smartfoxserver.v2.entities.SFSZone.removeUser(SFSZone.java:1270)
com.smartfoxserver.v2.api.SFSApi.disconnectUser(SFSApi.java:305)
com.smartfoxserver.v2.scala.DefLI.applyForceLogin(w:516)
com.smartfoxserver.v2.scala.DefLI.doLogin(w:118)
com.smartfoxserver.v2.entities.SFSZone.login(SFSZone.java:1358)
com.smartfoxserver.v2.api.SFSApi.login(SFSApi.java:486)
com.smartfoxserver.v2.controllers.system.Login.execute(Login.java:244)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.executeEventCommand(SFSExtensionManager.java:1035)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:776)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchZoneLevelEvent(SFSExtensionManager.java:689)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:886)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:65)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: disconnect users

Postby Lapo » 29 Mar 2017, 10:16

The error points to an extension:

Code: Select all

 Listener: { Ext: __lib__, Type: JAVA, Lev: ZONE, { Zone: saudi }, {} }

I think there may be something strange going on in your Extension that is causing the problem, especially if this happens for every login/disconnection.

Can you show what your code does?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
hebatarek
Posts: 21
Joined: 16 May 2016, 08:50

Re: disconnect users

Postby hebatarek » 29 Mar 2017, 10:57

it's just login using username
when user login for first time everything is going right
after that user disconnect or logout--> the first exception happened
when user login again using same username ---> second exception happened
and it gave me ghost report
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: disconnect users

Postby Lapo » 29 Mar 2017, 13:06

Can we see the code?
Lapo

--

gotoAndPlay()

...addicted to flash games
hebatarek
Posts: 21
Joined: 16 May 2016, 08:50

Re: disconnect users

Postby hebatarek » 29 Mar 2017, 14:14

this is the following login code

Code: Select all

package com.maugames.serverhandlers;

import java.util.Map;

import com.maugames.controllers.UserController;
import com.maugames.database.DAL;
import com.maugames.database.DataDAO;
import com.maugames.database.UserObject;
import com.maugames.enums.API;
import com.maugames.enums.ClientRequestID;
import com.maugames.general.GeneralResponses;
import com.maugames.general.SFSHelper;
import com.maugames.util.Helper;
import com.smartfoxserver.bitswarm.sessions.ISession;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
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.BaseServerEventHandler;

public class OnUserLogin extends BaseServerEventHandler{
   
   @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
       
        ISFSObject parameters = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);
        SFSHelper.showLog("Login Data: "+parameters.getDump());
        ISession session = (ISession) event.getParameter(SFSEventParam.SESSION);   
      User sender = (User) event.getParameter(SFSEventParam.USER);
      String username=(String)event.getParameter(SFSEventParam.LOGIN_NAME);
   
      String[] requiredParams = new String[] { API.PWD.value()};
      
      
      if(!Helper.isSufficientParameters(parameters, requiredParams)){
         
         GeneralResponses.insufficientParameters(sender,ClientRequestID.USER_Login.value());
         return;
         
      }
      
      String sql="select * from players where username='"+username+"' and password='"+parameters.getUtfString(API.PWD.value())+"'";
      
      Map<String,String>[] users=DAL.getData(sql);
      
      if(users!=null && users.length > 0){
         
         Map<String,String> temp=users[0];
         
         for (Map.Entry<String, String> entry : temp.entrySet())
         {
            
            session.setProperty(entry.getKey(),entry.getValue());               
            
         }
         
      }else{
         SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
         
         throw new SFSLoginException("", data);
         
      }
      
   }


}

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

Re: disconnect users

Postby Lapo » 29 Mar 2017, 15:08

I am not sure what you're doing but the error suggests that you're injecting a null value somewhere, which later causes a runtime error.
Can this be reproduced every time?

The SFS2X code that is causing the problem is this:

Code: Select all

usersByName.remove(user.getName());


Where a ConcurrentMap.remove(...) is called with a null value. However there is no reason a User object has a "null" name unless some other code injected it at some point, so the only suggestion I have is to double check your server side code.

In particular search for any instance of User.setName() in your code and remove it. User name must be set a login time and never changed again, or it will mess up lots of data structures that depend on it.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 109 guests