Room Join Problem in SFS2X

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

Moderators: Lapo, Bax

sankarganesh86
Posts: 108
Joined: 06 Jan 2010, 09:50
Location: chennai
Contact:

Room Join Problem in SFS2X

Postby sankarganesh86 » 13 May 2017, 11:19

Hi,

We developed a game using our SFS2X with client is AS3.0 , This is a turn based playing cards game
Actually in this game max 5 players will play in one room, If a users joined the room with in 10 sec other real user will not come we will create a Autobots and play with the users in that room itself

And if 2 users join the room we will start timer from server side with in 10 sec game will start, If other user need to join the game with in that 10 sec otherwise we will show a pop-up "game is running,Please wait for the next round"

But some time server and client synchronization may get some problem, Will u provide some idea ?
Sankar.G
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Join Problem in SFS2X

Postby Lapo » 15 May 2017, 08:27

Hi,
it sounds like you have a bug in your code that is causing the sync issues, but I am not able to guess what it might be, since I don't know the details.

For starters it would help to know what exactly are these "problems" that you have mentioned.
Can you be more specific?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
sankarganesh86
Posts: 108
Joined: 06 Jan 2010, 09:50
Location: chennai
Contact:

Re: Room Join Problem in SFS2X

Postby sankarganesh86 » 15 May 2017, 11:39

Hi Lapo,

Actually we are maintain a ArrayList in the server side, If a user login to the game we will put the user in that arraylist
At the time of user disconnect or user leave room event triggered but it take some time to captured in server what to do for this scenario ?

And we wrote 2 extension in Sever
1) Create Room Extension
2) Game Logic Extension

We maintain user array list in the Game Logic Extension but We can able to capture User disconnect event in Create Room Extension only because it is merged with config.xml
How to capture user disconnect event in Game logic extension itself ?

I will explain how we are using the SFS2X below

1) User will make a click on the Join Button in client side
2) We will make a request to PHP to generate Room name with unique id and update in DB and return to Client
3) Client will get the room name and call SFS2X to create a Room
4) Then user will join in that room

In the above scenario more than 3 users will make a click on the join button, PHP will generate 2 Room ids so users will separated and join 2 different Rooms, Do u have any other idea to handle this problems ?
Sankar.G
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Join Problem in SFS2X

Postby Lapo » 15 May 2017, 14:45

sankarganesh86 wrote:Hi Lapo,

Actually we are maintain a ArrayList in the server side, If a user login to the game we will put the user in that arraylist
At the time of user disconnect or user leave room event triggered but it take some time to captured in server what to do for this scenario ?

Is this necessary?
The list of Users is already maintained by the server itself at multiple levels. At Zone level you have the full list of all users, and at Room level where you have the players joined in that Room.

Also, ArrayLists don't support concurrency so you will need to keep that in mind... If I were you I wouldn't replicate something that already is done for you. But maybe I am missing parts of the picture.

We maintain user array list in the Game Logic Extension but We can able to capture User disconnect event in Create Room Extension only because it is merged with config.xml

I don't understand.
To listen for the disconnection event you simply have to add a listener in your init() method. I have no idea what you're referring to with "config.xml" ...

How to capture user disconnect event in Game logic extension itself ?

As I said, add a listener for SFSEventType.USER_DISCONNECT.

I will explain how we are using the SFS2X below
1) User will make a click on the Join Button in client side
2) We will make a request to PHP to generate Room name with unique id and update in DB and return to Client

Why do you need to call a PHP server to generate a name?
Can't you do it in Java?
Also you can talk to the database in Java

How do you handle concurrency between Java and PHP and how do you ensure atomicity? It seems like an overly complicated way to create a unique Room ID. Additionally each Room already provides a unique numeric ID after its creation.

I think this flow has a lot of potential to cause issues.

In the above scenario more than 3 users will make a click on the join button, PHP will generate 2 Room ids so users will separated and join 2 different Rooms, Do u have any other idea to handle this problems ?

Avoid to call the external PHP server and manage the logic in Java.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
sankarganesh86
Posts: 108
Joined: 06 Jan 2010, 09:50
Location: chennai
Contact:

Re: Room Join Problem in SFS2X

Postby sankarganesh86 » 16 May 2017, 08:24

Hi Lapo,

Ok we will try the Room Unique Id generation in Java itself, And we create Room with Game Logic extension
Room Creation login we wrote as a Zone Level extension using that extension we create room with Game Login extension

We wrote separate Game Login at the time of creating the Room we call that extension,
We set Auto remove Mode (True) if there is no users in the Room , It will remove Automatically

So at the time of last user get out of the room, User disconnect event and Room Removed event will trigger in Zone level extension only , Is there any possible to trigger in Room level extension ?

And we created the game logic using Array list, It is used in many places in game logic so it is very tough to change the logic now
Maintain the array list will reduce the game performance ? What about Hash Map ?
Sankar.G
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room Join Problem in SFS2X

Postby Lapo » 16 May 2017, 08:56

sankarganesh86 wrote:
So at the time of last user get out of the room, User disconnect event and Room Removed event will trigger in Zone level extension only , Is there any possible to trigger in Room level extension ?

No, the USER_DISCONNECT event is sent to both Zone and Room.
Only the ROOM_REMOVED is sent to the Zone. This is because only the ZONE is supposed to manage and listen to Room events.

When the room is removed by the Zone the Extension destroy() method is going to be called.

And we created the game logic using Array list, It is used in many places in game logic so it is very tough to change the logic now
Maintain the array list will reduce the game performance ? What about Hash Map ?

You can keep the ArrayList, no problem. Just be aware that it doesn't handle concurrency, so you will have to either make it synchronized or synchronize manually where needed.

More on the former option here:
http://www.avajava.com/tutorials/lesson ... -java.html

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 66 guests