SFSEventType USER_DISCONNECT

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

Moderators: Lapo, Bax

Post Reply
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

when USER_DISCONNECT event is called, this custom handler-- zone and room . why zone handler first ,then room handler ? can change the order of these two ? thx
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Zone events are usually fired first, because the Zone has control over the Rooms not the other way around.
And no it's not possible to change it.

BTW: there should be no dependency between events in a Zone and its Rooms, if so you might consider rethinking your code to avoid that.
Events are asynchronous and wanting to synchronize them via code dependencies is not a good a idea. My 2C
Lapo
--
gotoAndPlay()
...addicted to flash games
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

Lapo wrote:Zone events are usually fired first, because the Zone has control over the Rooms not the other way around.
And no it's not possible to change it.

BTW: there should be no dependency between events in a Zone and its Rooms, if so you might consider rethinking your code to avoid that.
Events are asynchronous and wanting to synchronize them via code dependencies is not a good a idea. My 2C
thanks a lot,Lapo.I see it now.

I have another question:when users leave the sfs2x server,and i will save user's info to database,but I don't kown how and when to do it! beacause,server trigger these events ,maybe USER_LOGOUT,USER_LEAVE_ROOM,or USER_DISCONNECT...
i Confused。

Many thanks for your help and i look forward to your reply.
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

when gaming is running if user close browser the room,what will happend?

Event USER_LEAVE_ROOM must can be called?

and after then call USER_DISCONNECT event?

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

Post by Lapo »

Are you talking about server side events?
You will get the disconnection event. On the client nothing
Lapo
--
gotoAndPlay()
...addicted to flash games
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

Lapo wrote:Are you talking about server side events?
You will get the disconnection event. On the client nothing
hi Lapo ,yes i'm talking about server side event.

I wrote some codes like these.

/**
* a Room-level Extension can only listen to the events in that Room and manage
* the Users contained in it. A typical use of Room-level Extension is to manage
* the logic of a game running in the Room.
*/
public class GameExtention extends SFSExtension {
....
init(){
....
addEventHandler(SFSEventType.USER_LEAVE_ROOM,
UserLeaveRoomHandler.class);
addEventHandler(SFSEventType.USER_DISCONNECT,
UserDisconnectHandler.class);
....
}

}


/**
* A Zone-level Extension can listen to any event in the Zone and control all
* the Rooms and Users in that it manages.
*/
public class AppExtension extends SFSExtension {
............
init(){
..........
addEventHandler(SFSEventType.USER_DISCONNECT,
UserDisconnectHandler.class);
.............
}
..........
}


now,when SFSEventType.USER_DISCONNECT event called,

UserDisconnectHandler be invoked twice.

public class UserDisconnectHandler extends BaseServerEventHandler {
....................
handleServerEvent(ISFSEvent event(){
....
saveUserInfo();//save user's data to database...
....
}
................
}

and so same code in UserLeaveRoomHandler.

where should i save user's data to database,and how?

because ,if user left in room ,game status changed,and some data.

it different from in zone....logic.

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

Post by Lapo »

As I said, and you can check the docs for all the details, you get the DISCONNECT event. The event will then give you all the details about which rooms the User had joined etc...
Lapo
--
gotoAndPlay()
...addicted to flash games
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

Lapo wrote:As I said, and you can check the docs for all the details, you get the DISCONNECT event. The event will then give you all the details about which rooms the User had joined etc...

OK,some questions is ,

1) when SFSEventType.USER_LOGOUT event was called, SFSEventType.USER_DISCONNECT event must be called?

2) in zone level , i can get DISCONNECT event and kown which rooms the User had joined,how i can get the room-level Extension? my game logic in the room Extension.

thank you very much for your help.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

1) No, logout simply means you leave the current zone but you don't drop the connection

2) Check the javadoc, a Room object exposes a getExtension() method
http://docs2x.smartfoxserver.com/api-do ... oc/server/
Lapo
--
gotoAndPlay()
...addicted to flash games
yysct2005
Posts: 21
Joined: 28 Apr 2011, 06:39

SFSEventType USER_DISCONNECT

Post by yysct2005 »

Lapo wrote:1) No, logout simply means you leave the current zone but you don't drop the connection

2) Check the javadoc, a Room object exposes a getExtension() method
http://docs2x.smartfoxserver.com/api-do ... oc/server/

OK,I see it now.

Lapo,thank you!
Post Reply