Create Room from the server-side step by step

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

Moderators: Lapo, Bax

hecool108
Posts: 2
Joined: 30 Nov 2011, 07:16

Create Room from the server-side step by step

Postby hecool108 » 13 Dec 2011, 08:15

Hi every one ,I been working on Smart Fox Server for 2 weeks,I must say,this is a really cool and nice product.It is graceful and powerful.

I want to share my experience here ,and hope this is helpful.

I created room from the client side first by as3,then I found ,I can't set the auto-remove-mode from the as3 API , I don't know why, maybe there are some reason about security or what?

So I try to create room from server-side,these are the steps I did.

step 1 : Create a Extension extends BaseSFSExtension, handle the command from the client,in the override method named handleClientRequest like this:

Code: Select all

private void createRoom(User sender, ISFSObject params){
      
RoomExtensionSettings res = new RoomExtensionSettings("MainZoneExtension","sfsextension.WarRoomExtension");
      CreateRoomSettings crs = new CreateRoomSettings();
      
      crs.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
      crs.setName("gameRoom");
      crs.setGroupId("games");
      crs.setMaxVariablesAllowed(100);
      crs.setMaxUsers(1000);
      crs.setDynamic(true);
      crs.setExtension(res);
      
      ISFSObject reback = SFSObject.newInstance();
      try {
         getApi().createRoom(sender.getZone(),crs,sender);
         reback.putBool("success", true);
      } catch (SFSCreateRoomException e) {
         e.printStackTrace();
         reback.putBool("success", false);
      }finally{
         send("createRoom", reback, sender);
      }
   }

Notice here :

Code: Select all

RoomExtensionSettings res = new RoomExtensionSettings("MainZoneExtension","sfsextension.WarRoomExtension");

the class RoomExtensionSettings have 2 parameters, according to the Java Server Side Docs the first one id must correspond to the Extension's folder name under the extensions/ directory , I made a mistake here,I think that was the name of my extension class!! And I try once and once again.

step 2: deploy the jar file to your running sfs server, we can see detail info here http://docs2x.smartfoxserver.com/AdvancedTopics/server-side-extensions
Remember to restart your sfs server,even the zone config panel of the AdminTool say it will "reload automatically".In my example,it worked till I restart the server.
step 3: call the extension from client-side:

Code: Select all

private function createRoom():void
{
      sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE,
                                         onExtensionResponse);
      sfs.send(new ExtensionRequest("createRoom",roomSetting));
}
protected function onExtensionResponse(e:SFSEvent):void
{
      //handle response from server side
}

Hope this helpful and thanks to gotoAndPlay() team for your amazing product. :lol:

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 51 guests