Problem with user disconnection

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

Moderators: Lapo, Bax

set_a
Posts: 16
Joined: 23 Feb 2012, 13:24

Problem with user disconnection

Postby set_a » 18 May 2012, 14:43

Hello,

Situation:

1. Enter with two users into ther room from two different browsers on the same PC.
2. Unplug ethernet cable from this PC -->> got connect lost in few seconds on client.
3. From third clinet using another PC it could be seen that two disconnected users are still in the room.
4. Plug ethernet cable back.
5. Reload disconnected clients.
6. On the server side handle login event as follows: check if user already exisit in zone:

Code: Select all

 User checkUser = getParentExtension().getApi().getUserByName(providedName);

    if(checkUser != null) {
      getParentExtension().getApi().disconnectUser(checkUser, ClientDisconnectionReason.KICK);
      log.warn("UserLoginHandler: kick ".concat(providedName));
      log.warn("UserLoginHandler: User already exist in zone - disconnect user | ip address".concat(session.getFullIpAddress()));
    }

    checkUser = getParentExtension().getParentZone().getUserByName(providedName);
    if (checkUser != null) {
      getParentExtension().getParentZone().getUserManager().disconnectUser(checkUser);
      log.warn("UserLoginHandler: disconnect ".concat(providedName));
      log.warn("UserLoginHandler: User already exist in zone - disconnect user | ip address".concat(session.getFullIpAddress()));
    }


In server log we see:

Code: Select all

 ===== LOGIN =======
- UserLoginHandler: kick 100002909477108
- UserLoginHandler: User already exist in zone - disconnect user | ip address192.168.11.174:49271
- UserLoginHandler: disconnect 100002909477108
- UserLoginHandler: User already exist in zone - disconnect user | ip address192.168.11.174:49271


The user was removed by disconnect, not by kick. Why is it posiible?

----------------------

Enter into the room using one of the previously disconnected users. Check if user is in room using function SFSRoom.:

Code: Select all

 if (room.containsUser(user.getName())) {
        log.warn("USER EXIST IN ROOM");
        extension.getApi().leaveRoom(user, room);
      } else {
        log.warn("USER NOT EXIST IN ROOM");
      }



By some unknown reason user is not in the room. But I printed out array of users in the room and !!! it exists there:

Code: Select all

iter = room.getUserList().iterator();
     
      while(iter.hasNext()) {
        log.warn("user name1 = ".concat(iter.next().getName()));
      }



And in the logs we see:

Code: Select all

- USER UID = 100002909477108
- USER NOT EXIST IN ROOM

- user name1 = 100002909477108
- user name1 = 100002850443247


Manually try to remove user from the room:

Code: Select all

 Iterator<User> iter = room.getUserList().iterator();
     
      User temp = null;
      while(iter.hasNext()) {
        temp = iter.next();
       
        if (temp.getName().equalsIgnoreCase(user.getName())) {
          extension.getApi().leaveRoom(temp, room);
          log.warn("user remove = ".concat(temp.getName()));
        } else {
          log.warn("user name = ".concat(temp.getName()));
        }
      }



See in logs:

Code: Select all

- USER UID = 100002909477108
- USER NOT EXIST IN ROOM

- user name1 = 100002909477108
- user name1 = 100002850443247

- user name = 100002850443247
- user remove = 100002909477108

- user name1 = 100002850443247



From AS client side we see that user 100002909477108 is not disconnected. Why AS clinet has not received leave room event (it is subscribed on this event)? Why the situation when user is able to enter in room multiple times is possible?

Why after deletion user from parent zone of the room user was not deleted from the room? May be we lost something? Is there any way to remove/disconnect user completely from all rooms of the zone.

Is there a way (by API) to allow entering into the room only that users who is not already in the room?

How to receive rooms to which user was joined before reconnect in tha way that other connected clients receive this information?

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

Re: Problem with user disconnection

Postby rjgtav » 18 May 2012, 20:52

Hello.
First of all, are you using the latest server patch (2.1.0)?

From AS client side we see that user 100002909477108 is not disconnected. Why AS clinet has not received leave room event (it is subscribed on this event)? Why the situation when user is able to enter in room multiple times is possible?

From which client do you see this, the third one? How are you joining the user in the room? Via SFSApi.joinRoom()?

Why after deletion user from parent zone of the room user was not deleted from the room? May be we lost something? Is there any way to remove/disconnect user completely from all rooms of the zone.

Yes, when you remove an user from a Zone it isn't automatically removed from the joined rooms. The way to go is to use the SFSApi.disconnectUser() method, which disconnects the user and removes him from the Zone and every room he has joined.

Is there a way (by API) to allow entering into the room only that users who is not already in the room?

If you use the SFSApi.joinRoom() method, an user will never be able to join a room multiple times.

How to receive rooms to which user was joined before reconnect in tha way that other connected clients receive this information?

You get those rooms from the User.getJoinedRooms() method.

By the way, why don't you use the forceLogout method? It will automatically disconnect the previous user for you.
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.
set_a
Posts: 16
Joined: 23 Feb 2012, 13:24

Re: Problem with user disconnection

Postby set_a » 21 May 2012, 08:28

First of all, are you using the latest server patch (2.1.0)?


version 2.0.1

From which client do you see this, the third one?


I see this from clinet which stands in the room


How are you joining the user in the room? Via SFSApi.joinRoom()?


Yeah, we use SFSApi.joinRoom

Code: Select all

 extension.getApi().joinRoom(user, room);


If you use the SFSApi.joinRoom() method, an user will never be able to join a room multiple times


Yes, we use SFSAPi.joinRoom(), but we see duplicate users in room.

You get those rooms from the User.getJoinedRooms() method.


After flash client reloading User.getJoinedRooms() list is empty

By the way, why don't you use the forceLogout method? It will automatically disconnect the previous user for you.


forceLogout is enabled, but we have to use that code in order to disconnect duplicated users:

Code: Select all

User checkUser = getParentExtension().getApi().getUserByName(providedName);

if(checkUser != null) {
  getParentExtension().getApi().disconnectUser(checkUser, ClientDisconnectionReason.KICK);
  log.warn("UserLoginHandler: kick ".concat(providedName));
  log.warn("UserLoginHandler: User already exist in zone - disconnect user | ip address".concat(session.getFullIpAddress()));
}

checkUser = getParentExtension().getParentZone().getUserByName(providedName);
if (checkUser != null) {
  getParentExtension().getParentZone().getUserManager().disconnectUser(checkUser);
  log.warn("UserLoginHandler: disconnect ".concat(providedName));
  log.warn("UserLoginHandler: User already exist in zone - disconnect user | ip address".concat(session.getFullIpAddress()));




We try to use code you have posted, but it works with delay: after duplicate user removal we check list of users joined to the zone and find that he is still there. After USER_LOGIN event handling duplicate user disappear at last.

I see from the AS clinet side that LEAVE_ROOM event hasn't been received. It comes approx after 5 seconds after removal code execution.

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

Re: Problem with user disconnection

Postby rjgtav » 21 May 2012, 20:10

Please update to the latest server version (2.1.0) and use also the latest AS3 Client API (2.0.3).
If you just use forceLogout without running the "manual disconnect" code on your extension, does it corretly remove the other users, even if it takes a little more time?
Can you please test this procedure by using smartfox.killConnection() on the client instead of unplugging the internet cable?
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.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 139 guests