Ghost User Problem

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
mete2221
Posts: 53
Joined: 30 Aug 2017, 17:01

Ghost User Problem

Postby mete2221 » 31 Jan 2023, 10:47

Some users are never deleted from the room even though ghost hunter is turned on.
Could it be that the players are stuck because the User Logout handler somehow throws an exception?
Also, could this be happening because I keep the user object (http://docs2x.smartfoxserver.com/api-do ... /User.html) in another object? (Maybe it can't collect garbage?)

Example:

Code: Select all

package com.arcade.entity;

import com.smartfoxserver.v2.entities.User;

public final class ArcadePlayer
{
  private final User user;
 
  private int turnIndex;

  public ArcadePlayer(User user)
  {
    this.user = user;
  }

  public ArcadePlayer(boolean online)
  {
    this.user = null;
  }
 
  public int getTurnIndex()
  {
   return turnIndex;
  }
 
  public void setTurnIndex(int value)
  {
   turnIndex = value;
  }

  public User getUser()
  {
    return this.user;
  }

  public boolean isOnline()
  {
    if(this.user == null)
      return false;

   //if user is not online, skip turn of user.
    return this.user.isConnected();
  }
}


If the problem is about keeping the user object in another object, I think keeping the user object using weak reference will solve the problem.

Weak Reference Example:

Code: Select all

package com.arcade.entity;

import com.smartfoxserver.v2.entities.User;
import java.lang.ref.WeakReference;
import javax.annotation.Nullable;

public final class ArcadePlayer
{
  private final WeakReference<User> user;
 
  private int turnIndex;

  public ArcadePlayer(User user)
  {
    this.user = new WeakReference<User>(user);
  }

  public ArcadePlayer()
  {
    this.user = null;
  }
 
  public int getTurnIndex()
  {
   return turnIndex;
  }
 
  public void setTurnIndex(int value)
  {
   turnIndex = value;
  }

  public @Nullable User user()
  {
   if(this.user == null)
      return null;
    
    return this.user.get();
  }

  public boolean isOnline()
  {
    User user = this.user();

    if(user == null)
      return false;

    return user.isConnected();
  }
}


userlist.png
(40.37 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Ghost User Problem

Postby Lapo » 31 Jan 2023, 15:17

Hi, what version of SFS2X are you using exactly?

As regards keeping a reference to the User object it's not important, at least as regards the User showing up in the AdminTool. That depend exclusively on the state of the User's session, which is usually half-closed. So the server doesn't know the client has disconnected from its end.

Could it be that the players are stuck because the User Logout handler somehow throws an exception?

Maybe. Have you checked the logs and found excpetions occurring in the LOGOUT event handler?
If so can you give us the details of the exception?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
mete2221
Posts: 53
Joined: 30 Aug 2017, 17:01

Re: Ghost User Problem

Postby mete2221 » 24 Feb 2023, 06:14

Lapo wrote:Hi, what version of SFS2X are you using exactly?

As regards keeping a reference to the User object it's not important, at least as regards the User showing up in the AdminTool. That depend exclusively on the state of the User's session, which is usually half-closed. So the server doesn't know the client has disconnected from its end.

Could it be that the players are stuck because the User Logout handler somehow throws an exception?

Maybe. Have you checked the logs and found excpetions occurring in the LOGOUT event handler?
If so can you give us the details of the exception?

Thanks

Using WeakReference seems to have fixed the issue.
User avatar
mete2221
Posts: 53
Joined: 30 Aug 2017, 17:01

Re: Ghost User Problem

Postby mete2221 » 24 Feb 2023, 06:14

Lapo wrote:Hi, what version of SFS2X are you using exactly?

As regards keeping a reference to the User object it's not important, at least as regards the User showing up in the AdminTool. That depend exclusively on the state of the User's session, which is usually half-closed. So the server doesn't know the client has disconnected from its end.

Could it be that the players are stuck because the User Logout handler somehow throws an exception?

Maybe. Have you checked the logs and found excpetions occurring in the LOGOUT event handler?
If so can you give us the details of the exception?

Thanks


is it possible to close topic?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Ghost User Problem

Postby Lapo » 24 Feb 2023, 16:26

Hi,
the forum doesn't have a specific user function to close a topic.
Admins can do it, as far as I can remember.
If you want to mark this thread as closed you can edit the title and put a [CLOSED] in front of the topic.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 42 guests