Serverside Room Creation
Posted: 15 Nov 2010, 13:33
Hi there,
i've been talking about it in a different threads but since the problem looks getting bigger and bigger, i prefer putting all the stuff related in a unique topic.
My need is to create rooms that are owned by the server. To do so, i created an extension that does the tricks.
This is my handleClientRequest method :
So, when a user call the "roomrequest" extension request, it creates silently the needed room, and autojoin the user in it.
I also created a "roomleaving" handler which put the user out of the room to have a full custom room join/leave method.
If this looks like working, it does only with one single connexion. If i disconnect my client or if i try to connect an other client, the server throws this :
Is what im doing the good way and should i try to solve this bug OR is there an other way to do server owned rooms ?
i've been talking about it in a different threads but since the problem looks getting bigger and bigger, i prefer putting all the stuff related in a unique topic.
My need is to create rooms that are owned by the server. To do so, i created an extension that does the tricks.
This is my handleClientRequest method :
Code: Select all
SmartFoxServer server = SmartFoxServer.getInstance();
SFSZone zone = (SFSZone) server.getZoneManager().getZoneList().get(1);
trace("---------- room " + roomname + "request");
if (zone.getRoomByName(roomname) == null)
{
trace("---------- room creation required");
SFSRoom room = new SFSRoom(roomname);
room.setMaxUsers(2500);
room.setActive(true);
try
{
room.addUser(sender);
sender.addJoinedRoom(room);
}
catch (SFSJoinRoomException ex) { trace("error while joining"); }
HashSet<SFSRoomSettings> flags = new HashSet<SFSRoomSettings>();
flags.add(SFSRoomSettings.USER_COUNT_CHANGE_EVENT);
flags.add(SFSRoomSettings.USER_ENTER_EVENT);
flags.add(SFSRoomSettings.USER_EXIT_EVENT);
flags.add(SFSRoomSettings.USER_VARIABLES_UPDATE_EVENT);
room.setFlags(flags);
room.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
try { zone.addRoom(room); }
catch (SFSTooManyRoomsException ex) { trace("error while adding room"); }
}
SFSObject response = new SFSObject();
response.putUtfString("roomname", roomname);
send("roomrequest", response, sender);I also created a "roomleaving" handler which put the user out of the room to have a full custom room join/leave method.
If this looks like working, it does only with one single connexion. If i disconnect my client or if i try to connect an other client, the server throws this :
Code: Select all
15:58:22,008 WARN [com.smartfoxserver.v2.controllers.SystemController-1] protocol.SFSIoHandler -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.binEncode_UTF_STRING(DefaultSFSDataSerializer.java:1160)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:780)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.arr2bin(DefaultSFSDataSerializer.java:544)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.array2binary(DefaultSFSDataSerializer.java:530)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:817)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.arr2bin(DefaultSFSDataSerializer.java:544)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.array2binary(DefaultSFSDataSerializer.java:530)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:817)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.obj2bin(DefaultSFSDataSerializer.java:500)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.object2binary(DefaultSFSDataSerializer.java:483)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:822)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.obj2bin(DefaultSFSDataSerializer.java:500)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.object2binary(DefaultSFSDataSerializer.java:483)
com.smartfoxserver.v2.entities.data.SFSObject.toBinary(SFSObject.java:229)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handleWrite(BinaryIoHandler.java:75)
com.smartfoxserver.v2.protocol.SFSIoHandler.onDataWrite(SFSIoHandler.java:325)
com.smartfoxserver.v2.protocol.SFSProtocolCodec.onPacketWrite(SFSProtocolCodec.java:144)
com.smartfoxserver.bitswarm.io.Response.write(Response.java:76)
com.smartfoxserver.v2.api.SFSApi.login(SFSApi.java:457)
com.smartfoxserver.v2.controllers.system.Login.execute(Login.java:125)
com.smartfoxserver.v2.controllers.SystemController.processRequest(SystemController.java:127)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Is what im doing the good way and should i try to solve this bug OR is there an other way to do server owned rooms ?