Hi There,
Maybe my question is bullshit but i just wonder. I want to create lobby rooms dynamically in an extension instead of zone.xml and need to add or remove lobbies dynamically without restart SmartfoxServer. I also do not want to use SmartfoxServer Admin Interface. Is this possible? If possible, what is the efficient way of doing this issue? In first look, i thought create room objects in extension init function. Is there an easy way instead of this?
Thanks in advance.
Creating Dynamic Lobbies in Extension
Re: Creating Dynamic Lobbies in Extension
msaygi wrote:Hi There,
Maybe my question is bullshit but i just wonder. I want to create lobby rooms dynamically in an extension instead of zone.xml and need to add or remove lobbies dynamically without restart SmartfoxServer. I also do not want to use SmartfoxServer Admin Interface. Is this possible? If possible, what is the efficient way of doing this issue? In first look, i thought create room objects in extension init function. Is there an easy way instead of this?
Thanks in advance.
LoL... Funny way of asking. I create and remove all my rooms dynamically.
Code: Select all
private void createRoom(gameMap targetMap) {
trace("Create room instance for " + targetMap.mapName + ".");
CreateMMORoomSettings Cfg = new CreateMMORoomSettings();
Cfg.setDefaultAOI(new Vec3D(targetMap.mapAoiX,targetMap.mapAoiY,0));
/** Set all your config stuff here... Cfg.setMaxUsers,setMaxSpectators, etc...**/
Cfg.setExtension(new RoomExtensionSettings(gameName,targetMap.mapExtension));
//Add custom data to new extension, available on extension init!
Map<Object, Object> extensionData = new HashMap<Object, Object>();
extensionData.put("pathMap",pathMaps.getMap(targetMap.mapName));
Cfg.setRoomProperties(extensionData);
try {
targetMap.roomAdded(getApi().createRoom(getParentZone(),Cfg,null));
} catch (SFSCreateRoomException e) {
trace(ExtensionLogLevel.WARN,"Could not create room.");
}
}
Last edited by meanvel on 18 Apr 2017, 08:55, edited 2 times in total.
Re: Creating Dynamic Lobbies in Extension
Oh, also... You cannot create rooms on init()... smartFox isn't fully booted up yet.
Instead you need to add this to your zone init()...
addEventHandler(SFSEventType.SERVER_READY,serverReadyHandler.class);
Then, that needs to go back to your main zone extension...
Then, you just handle the internal message... Create rooms, viola...
I dynamically instance all my maps based upon number of users. When the last instance of a room for a map is more than half full, another instance is prepared for users.
You will need to schedule a timer to monitor your rooms and handle instancing/removal... Add to init, or when the server is ready.
sfsApi.getSystemScheduler().scheduleAtFixedRate(new roomInstantiator(),10,10,TimeUnit.SECONDS);
Instead you need to add this to your zone init()...
addEventHandler(SFSEventType.SERVER_READY,serverReadyHandler.class);
Then, that needs to go back to your main zone extension...
Code: Select all
public class serverReadyHandler extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException {
getParentExtension().handleInternalMessage(extensionConstants.SERVER_READY,null);
}
}
Then, you just handle the internal message... Create rooms, viola...
I dynamically instance all my maps based upon number of users. When the last instance of a room for a map is more than half full, another instance is prepared for users.
You will need to schedule a timer to monitor your rooms and handle instancing/removal... Add to init, or when the server is ready.
sfsApi.getSystemScheduler().scheduleAtFixedRate(new roomInstantiator(),10,10,TimeUnit.SECONDS);
Code: Select all
private class roomInstantiator implements Runnable {
@Override
public void run() {
Re: Creating Dynamic Lobbies in Extension
Sure, it is possible.
You can create a Room from either client side or server side.
From client side you send a CreateRoomRequest and from server side you call the SFSApi.createRoom(...) method
I'd recommend this starting point:
http://docs2x.smartfoxserver.com/Develo ... ension-api
cheers
If possible, what is the efficient way of doing this issue?
You can create a Room from either client side or server side.
From client side you send a CreateRoomRequest and from server side you call the SFSApi.createRoom(...) method
I'd recommend this starting point:
http://docs2x.smartfoxserver.com/Develo ... ension-api
cheers
Re: Creating Dynamic Lobbies in Extension
meanvel wrote:Oh, also... You cannot create rooms on init()... smartFox isn't fully booted up yet.
Sure you can!
You just need to pass the fireClientEvent parameter as false.
Re: Creating Dynamic Lobbies in Extension
Lapo wrote:meanvel wrote:Oh, also... You cannot create rooms on init()... smartFox isn't fully booted up yet.
Sure you can!
You just need to pass the fireClientEvent parameter as false.
Ah, didn't know that. Thanks! Probably don't need fireServerEvent either...
Who is online
Users browsing this forum: Thomasea and 50 guests