Page 1 of 1

Change Room Capacity Request

Posted: 21 Jan 2012, 23:59
by wildcatz
Hi all!

I have a case. I have a game room with max user = 4.

Inside of the game room, there is a start button and the game can be started with only two or three players only.

Thing that I want is that when someone in the game room press the start button, the game room "closed" to be joined for other players, but in my case, other players can still join the game room.

I have tried to use changeroomcapacityrequest after the initiation of start button, but it seems like it didn't make any changes. Even the tracing of SFSEvent roomcapacitychange and roomcapacitychangeerror didn't occured.

My friend suggest me to use reserved room variable. Is it true?

Thanks.


My friend

Posted: 22 Jan 2012, 19:25
by rjgtav
Hi.

Sorry but I'm not understanding what you want to achieve. You want to, after you press the "start button", to prevent users from joining that room? Or do you want to still let users join in?

Posted: 27 Jan 2012, 17:34
by wildcatz
Sorry for the late reply.

What I mean is that after I press the start button, it prevents other user
to join that room.

My friend has introduced me with reservedroomvariable.

I have used it in my onroomjoin function.

[code]
function onRoomJoin(evt:SFSEvent):void
{
var roomJoined:Room = evt.params.room;

if (roomJoined.isJoined)
{
trace("The user is joining the Lobby");
}

if (roomJoined.isGame)
{
trace("The user is joining the game room");
if (sfs.lastJoinedRoom.getVariable(ReservedRoomVariables.RV_GAME_STARTED) != null)
{
trace("the game is started");
gotoAndStop("chat");
}
else
{
trace("the game is not started");
gotoAndStop("game");

}
}
}
[/code]

Turns out when I test the movie, this is the output:

[quote]
ReferenceError: Error #1065: Variable com.smartfoxserver.v2.entities.variables::ReservedRoomVariables is not defined.
at BrainFreeze/onRoomJoin()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.smartfoxserver.v2.controllers::SystemController/fnJoinRoom()
at com.smartfoxserver.v2.controllers::SystemController/handleMessage()
at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()
at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()
at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()
at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()
at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()
[/quote]

Is the reservedroomvariable somehow linked with the creation of room using sfsgamesettings?

(I read the documentation and saw that reservedroomvariable is = The Room Variable with this name keeps track of the state (started or stopped) of a game created with the CreateSFSGameRequest request.)

Posted: 28 Jan 2012, 10:58
by Bax
Did you import the class ReservedRoomVariables? It seems not...

Posted: 03 Feb 2012, 18:06
by wildcatz
It seems that I import the wrong .swc.. After I change the .swc, now the reservedroomvariable is now defined.

But, the problem is not solved yet. Do you have a solution to prevent other players to join the room after the game is already started?

I have two ideas and both of them is not working :( :
1. [b]change the room capacity right after the game is started.[/b]
The trace is working, but I don't see any change happened, even the onCapacityRoomChanged function is not working at all.

[code]
if (sfs.lastJoinedRoom.getVariable(ReservedRoomVariables.RV_GAME_STARTED) != null)
{
var theRoom:Room = sfs.getRoomByName(sfs.lastJoinedRoom.name);
trace("the room is :" + theRoom);
trace("total player is :" + sfs.lastJoinedRoom.userCount);
sfs.send(new ChangeRoomCapacityRequest(theRoom, sfs.lastJoinedRoom.userCount, 0));
}

function onRoomCapacityChanged(evt:SFSEvent):void
{
trace("The capacity of Room " + evt.params.room.name + " was changed successfully");
}

function onRoomCapacityChangeError(evt:SFSEvent):void
{
trace("Room capacity change failed: " + evt.params.errorMessage);
}

[/code]


2. [b]Set the room settings into hidden.[/b]
I don't know how to do it.

I tried to do this, but it is not working.

if (sfs.lastJoinedRoom.getVariable(ReservedRoomVariables.RV_GAME_STARTED) != null)
{
sfs.lastJoinedRoom.isHidden == true;
}


Do you have any ideas or answers? Thanks..

Posted: 03 Feb 2012, 19:20
by rjgtav
Hi. You can't simply set the room's capacity to 0, as that's lower than the number of joined users.

It now depends on what you want to achieve. If you only want client-side filtering, Game Rooms have a dedicated global variable which corresponds to the state of the game: if it has started or not (one of the ReservedRoomVariables). Then, you just have to show games that haven't started yet.

If you really want to prevent users from joining that room (in case users try to join that room despite it being hidden on the client), you could set its capacity to the amount of current joined users in that room.
Another way is to do it all server-side, with an extension, where instead of sending a JoinRoomRequest, you send an EtensionRequest, asking the extension to join a specific room.