public void handleServerEvent(ISFSEvent event) throws SFSException { User user = (User) event.getParameter(SFSEventParam.USER); trace("ClueGameExtension UserDisconnectEventHandler got user: "******"room"); if (uv == null) return; Room room = (Room) getParentExtension().getParentZone().getRoomByName(uv.getStringValue()); trace("ClueGameExtension UserDisconnectEventHandler got room: " + room); // handles both the user disconnected event and the user exit room events if (room != null) { // set the game to over if (room.getUserList().size() < 3) { room.removeVariable("isGameStarted"); } } // send the note to all other players List<User> users = room.getUserList(); ISFSObject resObj = SFSObject.newInstance(); resObj.putUtfString( "message", "Game is over because there are less than 3 players. A player has disconnected from the server."); send("gameOver", resObj, users); }
@Override public void handleClientRequest(User user, ISFSObject isfso) { trace("isplay: " + user.getVariable("isplay")); Boolean isplay = user.getVariable("isplay").getBoolValue(); if (isplay == true) { if (user.getVariable("ischuong").getBoolValue()) { ISFSObject obj = new SFSObject(); obj.putBool("status", false); obj.putUtfString("message", "Chương không có quyền đặt tiền"); send("betgame", obj, user); } else { Double bet = 0.0; bet = isfso.getDouble("betmoney"); trace(bet); SFSUserVariable money = SFSUserVariable.newInstance("bet", bet); try { user.setVariable(money); } catch (SFSVariableException ex) { } trace("Thong tin user sau bet game: " + user.getVariable("bet")); ISFSObject obj = new SFSObject(); obj.putBool("status", true); obj.putInt("betid", user.getId()); obj.putDouble("betmoney", bet); send("betgame", obj, this.getParentExtension().getParentRoom().getUserList()); } } else { ISFSObject obj = new SFSObject(); obj.putBool("status", false); obj.putUtfString("message", "Không có quyền chơi, chờ ván sau"); send("betgame", obj, user); } }