@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);
  }
  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;
  }