Creating Dynamic Zones with an Extension and a Room in Java

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Posts: 10
Joined: 05 Feb 2010, 15:09

Creating Dynamic Zones with an Extension and a Room in Java

Postby robert » 10 Nov 2010, 17:12

Because of that lack of documentation on some Java classes in the Server Side Extensions API, I write this post to help anyone looking for this information.

Code: Select all

String zoneName = "foo";
SmartFoxServer sfs = SmartFoxServer.getInstance();
Zone z = sfs.getZone(zoneName);
if(null == z)
  z = sfs.createZone(zoneName, "true");

  // Add an extension to this zone
  ExtensionManager em = z.getExtManager();
  AbstractExtension ae = new SomeExtension();
  ae.init(); // Call init explicitly or from the Ctor of SomeExtension
  em.add("name_of_extension", ae);

  // Add a lobby room to zone
  Room rm = new Room("lobby", 20, false, zoneName);

    // Setting owner populates __zoneName
    // and __roomName in the AbstractExtension class
    ae.setOwner(zoneName, "lobby");
  catch(CreateRoomException e)

// Do something with the zone

If you add a zone in the config.xml you have to add a room or else you will recieve this error during server start up:

at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(

When dynamically creating zones you don't need to create a room but the client side will not function correctly on an empty room list. Hence you cannot log into the zone only connect to it.

Posts: 10
Joined: 05 Feb 2010, 15:09

No Events are fired for dynamically created zones.

Postby robert » 11 Nov 2010, 00:21

Although the dynamically created zones appear in the AdminTool, it seems that no events, such as EVENT_LOGIN get dispatched to them.

Looking through classes I noticed ZoneManager. I am assuming it is internal to the SmartFoxServer instance but there is no accessor method for it. If it is similar to how extensions are handled as shown above then the usage of it would be:

Code: Select all

ZoneManager zm = sfs.getZoneManager();
zm.setZone(zoneName, zone);

Currently logging in to a dynamically created zone acts as if I was trying to log into a zone name not specified. Can anyone clear this up for me? Lapo?

Thanks for any help.
User avatar
Site Admin
Posts: 21122
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 12 Nov 2010, 16:03

Hi Robert,
dynamic Zone creation is not supported by SFS. Zones should be declared in the configuration. I don't know exactly why you are attempting to create Zones dynamically but not being supported by the API makes the operation tricky and a prone to unexpected consequences.

At the moment I am not able to suggest a quick workaround. You might want to open a support ticket and get some dedicated consulting for this specific request.
...addicted to flash games
Posts: 10
Joined: 05 Feb 2010, 15:09

Postby robert » 12 Nov 2010, 20:38

Hi Lapo,

Thank you for answering. The system being built reads external configuration data and creates a zone and lobby room per game. This way new multiplayer games can be added on the fly without rebooting the server. It is tied in with a game developer upload system on the development server for testing puposes.

Although SmartFoxServer is a singleton, could I extend it in someway?
If not, is it possible to get the file so I can add it and recompile it with the needed changes?


Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 8 guests