Code: Select all
String zoneName = "foo";
SmartFoxServer sfs = SmartFoxServer.getInstance();
Zone z = sfs.getZone(zoneName);
if(null == z)
{
z = sfs.createZone(zoneName, "true");
z.setEmptyNames(false);
// 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);
try
{
z.addRoom(rm);
// Setting owner populates __zoneName
// and __roomName in the AbstractExtension class
ae.setOwner(zoneName, "lobby");
}
catch(CreateRoomException e)
{
e.printStackTrace();
}
}
// 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:
java.lang.NullPointerException
at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(SmartFoxServer.java:1972)
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.
HTH,
R.