@Override
  public void handleServerEvent(ISFSEvent event) throws SFSException {
    trace("--------------------------------------------------------");
    // Grab parameters from client request
    userName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
    cryptedPass = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
    session = (ISession) event.getParameter(SFSEventParam.SESSION);

    customData = (SFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);

    String joinRoom = AuthorizeExtension.LOBBY;

    if (customData == null || customData.getUtfString("session") == null) {
      lobbyLoginAsGuestOrRegistered(event);
    } else {
      joinRoom = customData.getUtfString("room");
      generateSession = customData.getUtfString("session");
      customRoomLogin(event);
    }

    trace("Session loggin in: ", generateSession);

    session.setProperty("room", joinRoom);
    session.setProperty("isRegistered", isRegistered);
    session.setProperty("session", generateSession);
  }
  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);
  }
  private void customRoomLogin(ISFSEvent event) throws SFSLoginException {
    trace("Game Login by session");

    DBCollection users = AuthorizeExtension.users;

    BasicDBObject query = new BasicDBObject();
    query.put("session", generateSession);

    DBCursor cursor = users.find(query);

    if (!cursor.hasNext()) {
      trace("Game Login User not found!", generateSession);
      SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
      data.addParameter(userName);

      throw new SFSLoginException("Login failed for user: "******"Game Login User logged in!", generateSession);
      document = cursor.next();

      ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
      outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, document.get("nickname").toString());

      Boolean isGuest = (Boolean) document.get("is_guest");
      if (isGuest == null) {
        isRegistered = true;
      } else {
        isRegistered = false;
      }
    }
  }
  private void handleGuest(ISFSEvent event) throws NoSuchElementException {
    trace("Guest is loggin in", userName);

    DBCollection users = AuthorizeExtension.users;

    // Create random num 0..99
    Random randomGenerator = new Random();
    userName = userName + randomGenerator.nextInt(100);

    // Set new Name
    ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
    outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, userName);

    // Insert DB
    BasicDBObject newUser = new BasicDBObject();
    newUser.put("nickname", userName);
    newUser.put("session", generateSession);
    newUser.put("is_guest", true);

    users.insert(newUser);

    isRegistered = false;
  }