Disconnection Check from server side

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

Moderators: Lapo, Bax

eiquy3
Posts: 9
Joined: 21 Oct 2021, 05:42

Disconnection Check from server side

Postby eiquy3 » 21 Oct 2021, 06:18

I am trying to maintain a state on the server for every player in the room, using a room extension that keeps a variable if the player is connected or disconnected. So is there any way to check from the server-side that if any player has disconnected, so I can update that variable accordingly?

I am new to the smartfox, so i apologize if this is a basic question.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection Check from server side

Postby Lapo » 21 Oct 2021, 08:54

Hi,
in your extension you can listen for a number of server-side events such as a User disconnection.

If you're not familiar with server-side event, just check the introductory tutorial on Extensions here:
http://docs2x.smartfoxserver.com/Extens ... uick-start

It shows an example of how to set an event listener.
The parameters passed by each server-side events are documented in the SFSEventType class in our javadoc.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
eiquy3
Posts: 9
Joined: 21 Oct 2021, 05:42

Re: Disconnection Check from server side

Postby eiquy3 » 21 Oct 2021, 15:19

Hey,
Thanks Lapo for your reply it really helped me. I have one more doubt. it's regarding storing some variables on the extension like I have made my own data structure using some classes. now I want to store values in that. I have some restrictions so I am not using room or user variables. I tried storing data in static variables and it worked but I can't go with this approach also because of their static nature.

I read something about the class model which can stay inside _lib_ folder but I can't find any resource which can explain this process better. what is the model class? where to keep it in my development environment so that I don't get any compile errors and how this could help with data storing without static variables or those files can have static variables?. I have gone through http://docs2x.smartfoxserver.com/ExtensionsJava/advanced-concepts#classLoading link.
or is there any other way where I can access these variables from other classes without making them static? I want to access these variables within the same room extension.

Code: Select all

public class mainRoom extends SFSExtension {
        public static PlayersData _playersData = new PlayersData(new ArrayList<UserData>(), 0); // set MMTime And maxGame time in Config
   public static Timer MMtimer = new Timer();
   public static Timer GameTimer = new Timer();

Thanks.
eiquy3
Posts: 9
Joined: 21 Oct 2021, 05:42

Re: Disconnection Check from server side

Postby eiquy3 » 22 Oct 2021, 09:29

I got a solution for the problem. I am passing the main class (where all variable resides) in the constructor for every class that needs a reference for variables. now I can have access to all the variables with that reference.
Thanks.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 52 guests