Creating Dynamic Lobbies in Extension

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

Moderators: Lapo, Bax

msaygi
Posts: 11
Joined: 06 Jan 2017, 09:21

Creating Dynamic Lobbies in Extension

Postby msaygi » 17 Apr 2017, 13:57

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.
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Creating Dynamic Lobbies in Extension

Postby meanvel » 18 Apr 2017, 08:36

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.
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Creating Dynamic Lobbies in Extension

Postby meanvel » 18 Apr 2017, 08:39

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...

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() {
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating Dynamic Lobbies in Extension

Postby Lapo » 18 Apr 2017, 09:36

Sure, it is possible.
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
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Creating Dynamic Lobbies in Extension

Postby Lapo » 18 Apr 2017, 09:37

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.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Creating Dynamic Lobbies in Extension

Postby meanvel » 18 Apr 2017, 09:44

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...

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Thomasea and 50 guests