Code: Select all
import com.smartfoxserver.v2.api.CreateRoomSettings;
import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.exceptions.SFSCreateRoomException;
import com.smartfoxserver.v2.extensions.SFSExtension;
public class MyExtension extends SFSExtension {
@Override
public void init() {
trace("Hello, this is my first SFS2X Extension!");
// Add a new Request Handler
addRequestHandler("sum", SumReqHandler.class);
addEventHandler(SFSEventType.USER_JOIN_ZONE, ZoneEventHandler.class);
CreateRoomSettings cfg = new CreateRoomSettings();
cfg.setName("MyNewRoom");
cfg.setMaxUsers(50);
cfg.setDynamic(true);
try
{
Room myNewRoom = getApi().createRoom(getParentZone(), cfg, null);
}
catch (SFSCreateRoomException e)
{
// ... handle exception
}
}
}
Below is the server output
Code: Select all
20:39:53,866 INFO [main] managers.SFSRoomManager - Room created: { Zone: BasicExamples }, [ Room: The Lobby, Id: 0, Group: default, isGame: false ], type = SFSRoom
20:39:53,871 INFO [main] Extensions - {MyExtension}: Hello, this is my first SFS2X Extension!
20:39:53,872 INFO [main] managers.SFSRoomManager - Room created: { Zone: BasicExamples }, [ Room: MyNewRoom, Id: 1, Group: default, isGame: false ], type = SFSRoom
20:39:53,877 ERROR [main] managers.SFSExtensionManager - java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Extension initialization failed.
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.bitswarm.core.BitSwarmEngine.writeToSocket(BitSwarmEngine.java:412)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.write(BitSwarmEngine.java:406)
com.smartfoxserver.bitswarm.io.Response.write(Response.java:71)
com.smartfoxserver.v2.api.response.SFSResponseApi.notifyRoomAdded(SFSResponseApi.java:128)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:754)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:703)
MyExtension.init(MyExtension.java:25)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:426)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239)
com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292)
com.smartfoxserver.v2.Main.main(Main.java:14)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
com.exe4j.runtime.WinLauncher.main(Unknown Source)
com.install4j.runtime.launcher.WinLauncher.main(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Thank you