Page 1 of 1

quickJoinGame

Posted: 01 Dec 2010, 20:53
by vandelpal
Why function quickJoinGame in GameApi fire Exception, when I try call it on empty server zone? In my opinion if the zone does not have any room it should return null and not exception.

Code: Select all

findRoomsMathExpression = new MatchExpression(RoomProperties.IS_GAME, BoolMatch.EQUALS, true).and
                                           (RoomProperties.HAS_FREE_PLAYER_SLOTS, BoolMatch.EQUALS, true);

 getGameApi().quickJoinGame(user, findRoomsMathExpression, getZone(), "battle");

Code: Select all


ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1] v2.controllers.ExtensionController     - 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.IllegalArgumentException
Message: No Room provided for searching.
Description: Error while handling client request in extension: { Ext: XCOMExtension, Type: JAVA, Lev: ZONE, { Zone: XCOMExtension }, {} }
Extension Cmd: MSG_JOINT_TO_BATTLE
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.api.SFSGameApi.quickJoinGame(SFSGameApi.java:252)
com.smartfoxserver.v2.api.SFSGameApi.quickJoinGame(SFSGameApi.java:196)
com.smartfoxserver.v2.api.SFSGameApi.quickJoinGame(SFSGameApi.java:190)
com.smartfoxserver.v2.api.SFSGameApi.quickJoinGame(SFSGameApi.java:184)
sfs2extensions.games.xcom.gamezone.model.proxy.BattleRoomsProxy.jointBattle(BattleRoomsProxy.java:101)
sfs2extensions.games.xcom.gamezone.view.handlers.JointToBattleHandler.handleClientRequest(JointToBattleHandler.java:31)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:187)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionController.java:137)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

Posted: 02 Dec 2010, 15:32
by Lapo
The API expect at least one Room to search, otherwise it doesn't make sense searching for anything. If you don't want to catch the exception (which is actually a RuntimeException, so not mandatory) you could just make a little check.

Code: Select all

if (zone.getRoomCount() == 0) 
// avoid searching...
which is the same as testing if the returned Room is null.

Posted: 02 Dec 2010, 21:34
by vandelpal
This IF should be inside a function quickJoinGame, that function does not fall under the correct parameters. I handed her a MatchExpression and search location(Zone), it should not fall if it did not find any room. Otherwise it seems unreliable.