Page 1 of 1

SFSEventType USER_DISCONNECT

Posted: 07 Jun 2011, 02:30
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

Posted: 08 Jun 2011, 09:18
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

SFSEventType USER_DISCONNECT

Posted: 15 Jun 2011, 07:24
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.

SFSEventType USER_DISCONNECT

Posted: 15 Jun 2011, 08:12
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

Posted: 15 Jun 2011, 14:03
by Lapo
Are you talking about server side events?
You will get the disconnection event. On the client nothing

SFSEventType USER_DISCONNECT

Posted: 16 Jun 2011, 13:17
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

Posted: 16 Jun 2011, 14:41
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...

SFSEventType USER_DISCONNECT

Posted: 17 Jun 2011, 04:10
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.

Posted: 17 Jun 2011, 09:12
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/

SFSEventType USER_DISCONNECT

Posted: 17 Jun 2011, 09:34
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!