コード例 #1
0
  public void handle(Session client, MessageEvent msg) {
    String username = msg.readString();

    if (username.equals(client.getPlayer().getData().getUsername())) return;

    Session request = NetworkManager.getInstance().getSessions().getByPlayerUsername(username);

    if (request == null
        || request.getPlayer() == null
        || request.getPlayer().getMessenger() == null) return;

    if (!request.getPlayer().getSettings().getAllowFriendRequests()) {
      client.send(
          new AdvancedAlertMessageComposer(Locale.get("game.messenger.friendrequests.disabled")));
      return;
    }

    if (request.getPlayer().getMessenger().hasRequestFrom(client.getPlayer().getId())) return;

    request.getPlayer().getMessenger().addRequest(client.getPlayer().getId());
    request.send(new FriendRequestMessageComposer(client.getPlayer().getData()));

    int userId = PlayerDao.getIdByUsername(username);

    if (userId == 0) return;

    client.getPlayer().getQuests().progressQuest(QuestType.SOCIAL_FRIEND);
    MessengerDao.createRequest(client.getPlayer().getId(), userId);
  }
コード例 #2
0
  @Override
  public void compose(IComposer msg) {
    msg.writeInt(roomId);
    msg.writeInt(playersWithRights.size());

    for (Integer id : playersWithRights) {
      msg.writeInt(id);

      String username = PlayerDao.getUsernameByPlayerId(id);
      msg.writeString(username != null ? username : "******");
    }
  }
コード例 #3
0
  @Override
  public void run() {
    if (playerData.size() == 0) {
      // No data to be saved!
      return;
    }

    log.debug("Saving " + this.playerData.size() + " player data instances");

    PlayerDao.saveBatch(this.playerData);

    this.playerData.clear();
  }