Page 1 of 1

Create room from Serverside in SFS2x

Posted: 04 Jan 2012, 17:16
by krishsalt
Hi,

I am a new in Java.

I want to create Room from Serverside with below properties.

// Flex Code bellow

var settings:SFSGameSettings = new SFSGameSettings("gameRoom1");
settings.maxUsers = 2;
settings.maxSpectators = 10;
settings.isPublic = true;
settings.minPlayersToStartGame = 2;
settings.notifyGameStarted = true;
settings.leaveLastJoinedRoom = false;
settings.extension = new RoomExtension("sfsGame", "sfs2x.extensions.games.pingPong.SFSPingPong");

// Create some Room Variables
var roomVars:Array = [];
roomVars.push(new SFSRoomVariable("gameStarted", false));
roomVars.push(new SFSRoomVariable("gameType", "Ping"));
roomVars.push(new SFSRoomVariable("minRank", 10));
roomVars.push(new SFSRoomVariable("type", "fun"));
roomVars.push(new SFSRoomVariable("desc", " game, public, bestScore > 100"));

settings.variables = roomVars;
sfs.send(new CreateSFSGameRequest(settings));


I am trying to create Room in server side(Java).

Please help how to create Room with Extenstion and RoomVariables with Global Flag set to true in Java.

Thanks in Advance
Krishsalt.

Posted: 05 Jan 2012, 10:09
by ThomasLund
Hi,

I just need to ask. Are you client side or server side? Because this part of the forum is about client side Java API. The server side stuff is at this part:

http://forums.smartfoxserver.com/viewforum.php?f=18

Anyways - client side code snippet:

Code: Select all

		RoomSettings roomSettings = new RoomSettings(roomName);
		CreateRoomRequest req = new CreateRoomRequest(roomSettings, false);
		sfs1.send(req);
/Thomas

creating dynamic rooms and joining the user in that room

Posted: 10 Feb 2012, 06:53
by arunkumar624
As i am new to SmartFoxServer I need help in the server side coding.I hope you will help

The below is my scenario

1.There is one zone and one default room(manually i created) in that zone in Admin panel.
2.The users from client side(Action script) want to play the game when he loads the game I need to do below steps
a)I want handle login request from the client
b)After handling login request i want to check the default room is full or not which i created in Admin panel, if it is full i need to create a new dynamic room and join the new user to the newly created room and have to send response to the client(tell me what response i have to send to client). 3)I need the server side (i.e:java) coding for the above scenario and what are the necessary steps to be followed by the client.

Re: creating dynamic rooms and joining the user in that room

Posted: 21 Feb 2012, 10:51
by itsmylifesoham
arunkumar624 wrote:As i am new to SmartFoxServer I need help in the server side coding.I hope you will help

The below is my scenario

1.There is one zone and one default room(manually i created) in that zone in Admin panel.
2.The users from client side(Action script) want to play the game when he loads the game I need to do below steps
a)I want handle login request from the client
b)After handling login request i want to check the default room is full or not which i created in Admin panel, if it is full i need to create a new dynamic room and join the new user to the newly created room and have to send response to the client(tell me what response i have to send to client). 3)I need the server side (i.e:java) coding for the above scenario and what are the necessary steps to be followed by the client.
step 1 : send login request to the zone from client.
step 2 : lets say the one default room that already is there has name "MyFirstRoom". in the zone login handler if the user is successfully authenticated, then at the end of this handler you have to make a check if the "MyFirstRoom" is full or not.
so do

Code: Select all

 Room myfirstroom = getParentExtension().getParentZone().getRoomByName("MyFirstRoom");
if(!myfirstroom.isfull()) 
    getApi().joinRoom(((SFSUser) event.getParameter(SFSEventParam.USER)), myfirstroom ) 
else
{
    Room newRoom = getApi().createroom(<please see how to pass the roomsettings parameters in the api documentation>);
 getApi().joinRoom(((SFSUser) event.getParameter(SFSEventParam.USER)), newRoom ) ;

   
}
once the user joins the room, on client side he will get a event called Room_JOIN which has parameters as the room which just got joined. so he can now send public /private messages to this room and extension messages if the room has its own extension.

hope it gives some idea.

Re: Create room from Serverside in SFS2x

Posted: 28 Feb 2012, 10:14
by set_a
Multiple users sent a request to join the room. We need to create a room and join all the users in new room

How should I limit the access for the room creation not to get a several rooms instead of single?

I use for name room = "room_"+count rooms in group rooms

Re: Create room from Serverside in SFS2x

Posted: 28 Feb 2012, 10:59
by Lapo
It is not clear. Can you please explain exactly what you need to do?
Give us a step by step description please

Re: Create room from Serverside in SFS2x

Posted: 28 Feb 2012, 11:56
by set_a
1. 4 users want to enter the room that belongs to a group of rooms "group_1"
2. Each user sends request to the server with the parameter "group_1"
3. The server is trying to get the room (not private and the number of users is less than maximum) from the group "group_1"
4. If there's no such room in the group "group_1", the server calls the method that creates a new room in the group "group_1".
5. After the room creation, server should connect all the users who have sent a request to the new room
6. Also I need to pick up the part of users from the full room and in 5 seconds move them into the new one. (I use sfs.getTaskScheduler().schedule(new Task(), ), but I don't get extension in class Task for getApi().joinRoom()

How can I avoid the execute of 4th paragraph? The server should set up only one room instead of four.

From 3rd till 6 paragraph all actions must be thread-safe because otherwise may be the unpredictable result.

Re: Create room from Serverside in SFS2x

Posted: 29 Feb 2012, 05:06
by itsmylifesoham
set_a wrote:1. 4 users want to enter the room that belongs to a group of rooms "group_1"
2. Each user sends request to the server with the parameter "group_1"
3. The server is trying to get the room (not private and the number of users is less than maximum) from the group "group_1"
4. If there's no such room in the group "group_1", the server calls the method that creates a new room in the group "group_1".
5. After the room creation, server should connect all the users who have sent a request to the new room
6. Also I need to pick up the part of users from the full room and in 5 seconds move them into the new one. (I use sfs.getTaskScheduler().schedule(new Task(), ), but I don't get extension in class Task for getApi().joinRoom()

How can I avoid the execute of 4th paragraph? The server should set up only one room instead of four.

From 3rd till 6 paragraph all actions must be thread-safe because otherwise may be the unpredictable result.

hi set_a,

maybe this post from before can help regarding your thread-safety requirement query :
http://forums.smartfoxserver.com/viewto ... afe#p52465

Also to access extension from the Task class you could do one of the two that i use :

1. declare the Task class as an inner private class inside an extension. you can see it in action here :
http://docs2x.smartfoxserver.com/Advanc ... hreadModel
just go to the part where they show how to write a scheduler.
from an inner class you can access all the methods and properies of your extension which includes getapi().joinroom etc.

2. if you are having your task class declared separately elsewhere, just put "getapi()" as the constructor argument for that task.

eg:
taskHandle = sfs.getTaskScheduler().scheduleAtFixedRate(new TaskRunner(getapi()), 0, 1, TimeUnit.SECONDS);
now in your task class you can utilise the api.

Re: Create room from Serverside in SFS2x

Posted: 29 Feb 2012, 12:06
by set_a
Thanks you very much for your answer :D