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.