Page 1 of 1

Problem with joining and creating rooms

Posted: 28 Oct 2015, 19:33
by noFault
Hi,
We are starting up an online turn based game project by using smart fox as our back end, but there are some strange behaviors in different parts of the platform which makes it difficult to develop at this phase, now i decided to discuss some of these problem here, starting with this scenario:

UserA joins MyZone, at first he is not subscribed to any group because i have configured no default group in AdminTool to subscribe after login.
Then he subscribes to MyGroup, (here MyGroup is empty since no room is created yet)
Then he sends a custom message called "createRoom" via ExtensionRequest, At server side i will capture this message and create a room named MyRoom with my preferred room settings. Of course i do this with SFSApi so client will be notified about MyRoom.

MyRoom has the following settings :
isDynamic = true
isGame = true
groupId = "MyGroup"
autoRemoveMode = SFSRoomRemoveMode.WHEN_EMPTY

Now UserB joins MyZone, subscribes to MyGroup and then joins MyRoom.
at this point UserA leaves MyRoom. MyRoom should remain in room list because of autoRemoveMode settings and the fact that UserB is still in MyRoom.

Everything works fine with noFault, except when i query room list in client side with RoomManager.GetRoomList(), UserA gets an empty list. but he is still subscribed to MyGroup and MyRoom belongs to MyGroup and it's not destroyed yet. So UserA should see MyRoom in its RoomList but he don't.


I tried to figure this out, and after digging into client source code api for some hours, i found that MyRoom at client side has a flag called isManaged (which is used by api only) set to false, and that forces room manager to remove room from it's list when user leaves the room. isManaged flag is set false because room manager doesn't have MyGroup in it's "groups" variable ("groups" is a private list inside room manager) and this happens because at subscription time MyGroup is empty.

so what's the problem. Is this a bug or I'm doing things wrong way.

thanks for your patience

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 08:14
by Lapo
Hi,
can you show me the code used on the server side to create the Room?
Also please specify the C# API version (see SmartFox.Version property) and the SFS2X version in use.

As a side note there's no need to specify the WHEN_EMPTY mode for a Room that is set as game, that's because game Rooms already employ that modality by default.

Thanks

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 10:14
by noFault
This is the code for MyZone extension:

Code: Select all

public class ZoneExtension extends SFSExtension {
	
    @Override
    public void init() {

        addRequestHandler("createRoom", new BaseClientRequestHandler() {
            @Override
            public void handleClientRequest(User user, ISFSObject isfsObject) {

		CreateRoomSettings settings = new CreateRoomSettings();
                settings.setName("MyRoom");
                settings.setGroupId("MyGroup");
                settings.setGame(true);
                settings.setDynamic(true);
                settings.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);

                try {
                    Room room = getParentZone().createRoom(settings);
                    getApi().joinRoom(user, room);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
	}
}

I have removed login code because i think it has nothing to do with this problem, it's just about configuring LoginAssistantComponent.

I have used both c# client versions available at download section (1.5.7 and 1.6.2) and get the same result.

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 10:45
by Lapo
Ok,
the problem is how the Room is created.
You are calling Zone.createRoom(...) which will create the Room but won't tell anyone (i.e. the clients).

You must use the API instead:
getApi().createRoom( settings ...)
The simple rule is that every operation that requires updating the clients is found in the SFSApi object, obtained via getApi()

We talked about this in our recent blog posts on "common pitfalls to avoid" and it's at number 1 in the list :)
See here: http://smartfoxserver.com/blog/?p=329

cheers

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 11:40
by noFault
Yes, it did the job
I don't know why i thought Zone.createRoom(...) will do the same as SFSApi :D

But problem still occurs this way : if UserA first create room then subscribe to MyGroup, and UserB follow the same order as before, this way UserA will lose MyRoom after leaving.

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 12:08
by Lapo
Seems a bit of a convoluted logic.
Why creating a Room in an "area" of the server that won't send you any updates?

This makes sense only if you don't want the client to receive any Room related events and then you manage Rooms manually, by creating it and joining it without subscribing to a Group.
It's a rare use case, but it may be required.

What doesn't make sense to me is the idea of creating and joining Rooms outside of any Groups and then joining the Group later.
It's pretty clear that you're doing things backwards. So first join the group, then deal with the Room related operations (create, join etc...)

To be honest, I am not even sure why you need to create the Room from server side if you don't apply any additional logic, wouldn't it be simpler to do all from client side?

Cheers

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 14:11
by noFault
OK, let's assume that we have 3 games within a zone : poker, backgammon, chess

Each game has its own lobby, when a player joins the zone he won't subscribe to any lobby, he just see home page which contains introduction, news, game icons, friend list, etc. I don't want to force user to subscribe to any lobby, because maybe he just want to remain in home page and chat with his friends, why forcing him to receive extra traffic?

Lapo wrote:To be honest, I am not even sure why you need to create the Room from server side if you don't apply any additional logic, wouldn't it be simpler to do all from client side?
I have two reasons for creating games on server side : simplicity and security
there is always a join after any create, and there is always a bunch of room settings for any create (room parameters, room variables, extension setup), and since we have multiple client developers for different platform, it's much more simpler to integrate these parts into server and have a cleaner client code.
and indeed i think it's not safe to have such freedom at client side, all room settings are related to each other, for example there is no chess room with four players, chess is always a two player game, or all games which belong to Chess group should use ChessExtension as their extension.

i have used this method for other parts of the server, for example user can not subscribe to multiple groups, he should unsubscribe from current group then subscribe to new one, for this to happen i placed a filter on SystemRequest.SubscribeRoomGroup which provides the required logic.
Lapo wrote:Why creating a Room in an "area" of the server that won't send you any updates?
there are situations in which user joins/creates a room without subscribing to its group. for example a user is chatting with his friend in home page and his friends invites him to a game, this way he will join without subscribing. another case is "Play Now!" shortcut in home page, user will create without subscribing.
After joining the room, user still has access to home window and can subscribe to group.
even he can subscribe to a different group: he joins a chess game and then subscribes to backgammon lobby :D

actually we have written our server with java from scratch and it's up and running now and works fine with all these scenarios, but there are lots of scaling problems for our new version so we decided to switch to SFS. Now i'm trying to find out what is possible with SFS and of course we need to align our requirements with new platform.

thanks

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 15:02
by Lapo
noFault wrote:OK, let's assume that we have 3 games within a zone : poker, backgammon, chess

Each game has its own lobby, when a player joins the zone he won't subscribe to any lobby, he just see home page which contains introduction, news, game icons, friend list, etc. I don't want to force user to subscribe to any lobby, because maybe he just want to remain in home page and chat with his friends, why forcing him to receive extra traffic?
Right, I agree.
I have two reasons for creating games on server side : simplicity and security
there is always a join after any create, and there is always a bunch of room settings for any create (room parameters, room variables, extension setup), and since we have multiple client developers for different platform, it's much more simpler to integrate these parts into server and have a cleaner client code.
and indeed i think it's not safe to have such freedom at client side, all room settings are related to each other, for example there is no chess room with four players, chess is always a two player game, or all games which belong to Chess group should use ChessExtension as their extension.
Thanks for the clarification, makes sense.
there are situations in which user joins/creates a room without subscribing to its group. for example a user is chatting with his friend in home page and his friends invites him to a game, this way he will join without subscribing. another case is "Play Now!" shortcut in home page, user will create without subscribing.
After joining the room, user still has access to home window and can subscribe to group.
even he can subscribe to a different group: he joins a chess game and then subscribes to backgammon lobby :D
Is this use case really necessary?

-> User joins a chess game Room (unmanaged Room)
-> User plays...
-> User subscribes to the chess Room Group (can this be done while in game?)
-> User leaves the chess Room

Why not simply subscribing after the game has finished? When the user has returned to the Lobby...

In any case, if the answer is yes (the use case is necessary) I think you could manually convert the Room from unmanaged to managed by setting the relative property.

cheers

Re: Problem with joining and creating rooms

Posted: 29 Oct 2015, 16:46
by noFault
Thanks a lot for your great support

As i said my goal was to find out whether it is SFS normal behavior or i'm treating it the wrong way.
About the necessity of this use case, no it's not required in mobile clients (android, IOS), but in desktop version everything is inside a window and user can have multiple windows open, such as lobby window and room window

So with your guide, here is my conclusion :

1- i can limit user access to lobby while he is in a game room. Actually our current users are not used to this structure and we prefer not to change user habits, but as i said maybe we need to align our requirements with platform limitations

2- if we want to keep our traditional structure, we have to listen on "SFSEvent.ROOM_GROUP_SUBSCRIBE" and if user JoinedRoom has the same group id as subscribed group, then make it managed

Again thanks for your great support