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);
  }
  @Override
  public void handle(Session client, MessageEvent msg) throws Exception {
    int itemId = msg.readInt();

    RoomItemWall item = client.getPlayer().getEntity().getRoom().getItems().getWallItem(itemId);

    if (item == null) {
      return;
    }

    if (!client.getPlayer().getEntity().isVisible()) {
      return;
    }

    item.onInteract(client.getPlayer().getEntity(), 0, false);
  }
  public void handle(Session client, MessageEvent msg) {
    int danceId = msg.readInt();

    if (client.getPlayer().getEntity().getDanceId() == danceId) {
      return;
    }

    client.getPlayer().getEntity().unIdle();

    if (!client.getPlayer().getEntity().isVisible()) {
      return;
    }

    client.getPlayer().getEntity().setDanceId(danceId);
    client
        .getPlayer()
        .getEntity()
        .getRoom()
        .getEntities()
        .broadcastMessage(
            new DanceMessageComposer(client.getPlayer().getEntity().getId(), danceId));

    client.getPlayer().getQuests().progressQuest(QuestType.SOCIAL_DANCE);
  }
예제 #4
0
  public void handle(MessageEvent message, Session client) {
    final Short header = message.getId();

    if (Comet.isDebugging) {
      log.debug(message.toString());
    }

    if (!Comet.isRunning) return;

    if (this.getMessages().containsKey(header)) {
      try {
        final Event event = this.getMessages().get(header);

        if (event != null) {
          if (this.asyncEventExecution) {
            this.eventExecutor.submit(new MessageEventTask(event, client, message));
          } else {
            final long start = System.currentTimeMillis();
            log.debug(
                "Started packet process for packet: ["
                    + event.getClass().getSimpleName()
                    + "]["
                    + header
                    + "]");

            event.handle(client, message);

            long timeTakenSinceCreation = ((System.currentTimeMillis() - start));

            // If the packet took more than 100ms to be handled, red flag!
            if (timeTakenSinceCreation >= 100) {
              if (client.getPlayer() != null && client.getPlayer().getData() != null)
                log.trace(
                    "["
                        + event.getClass().getSimpleName()
                        + "]["
                        + message.getId()
                        + "]["
                        + client.getPlayer().getId()
                        + "]["
                        + client.getPlayer().getData().getUsername()
                        + "] Packet took "
                        + timeTakenSinceCreation
                        + "ms to execute");
              else
                log.trace(
                    "["
                        + event.getClass().getSimpleName()
                        + "]["
                        + message.getId()
                        + "] Packet took "
                        + timeTakenSinceCreation
                        + "ms to execute");
            }

            log.debug(
                "Finished packet process for packet: ["
                    + event.getClass().getSimpleName()
                    + "]["
                    + header
                    + "] in "
                    + ((System.currentTimeMillis() - start))
                    + "ms");
          }
        }
      } catch (Exception e) {
        if (client.getLogger() != null)
          client
              .getLogger()
              .error(
                  "Error while handling event: "
                      + this.getMessages().get(header).getClass().getSimpleName(),
                  e);
        else
          log.error(
              "Error while handling event: "
                  + this.getMessages().get(header).getClass().getSimpleName(),
              e);
      }
    } else if (Comet.isDebugging) {
      log.debug("Unhandled message: " + Events.valueOfId(header) + " / " + header);
    }
  }
  public void handle(Session client, MessageEvent msg) {
    String text = msg.readString();

    String user = text.split(" ")[0];
    String message = text.replace(user + " ", "");

    if (client.getPlayer().getEntity() == null
        || client.getPlayer().getEntity().getRoom() == null) {
      return;
    }

    if (!client.getPlayer().getEntity().isVisible()) {
      return;
    }

    final Room room = client.getPlayer().getEntity().getRoom();

    RoomEntity userTo = room.getEntities().getEntityByName(user, RoomEntityType.PLAYER);

    if (userTo == null || user.equals(client.getPlayer().getData().getUsername())) return;

    String filteredMessage = TalkMessageEvent.filterMessage(message);

    if (!client.getPlayer().getPermissions().getRank().roomFilterBypass()) {
      FilterResult filterResult = RoomManager.getInstance().getFilter().filter(message);

      if (filterResult.isBlocked()) {
        client.send(
            new AdvancedAlertMessageComposer(
                Locale.get("game.message.blocked").replace("%s", filterResult.getMessage())));
        return;
      } else if (filterResult.wasModified()) {
        filteredMessage = filterResult.getMessage();
      }
    }

    if (!client.getPlayer().getEntity().onChat(filteredMessage)) return;

    try {
      if (LogManager.ENABLED)
        LogManager.getInstance()
            .getStore()
            .getLogEntryContainer()
            .put(
                new RoomChatLogEntry(
                    room.getId(),
                    client.getPlayer().getId(),
                    Locale.getOrDefault("game.logging.whisper", "<Whisper to %username%>")
                            .replace("%username%", user)
                        + " "
                        + message));
    } catch (Exception ignored) {

    }

    client.send(
        new WhisperMessageComposer(client.getPlayer().getEntity().getId(), filteredMessage));

    if (!((PlayerEntity) userTo).getPlayer().ignores(client.getPlayer().getId()))
      ((PlayerEntity) userTo)
          .getPlayer()
          .getSession()
          .send(
              new WhisperMessageComposer(client.getPlayer().getEntity().getId(), filteredMessage));

    for (PlayerEntity entity :
        client.getPlayer().getEntity().getRoom().getEntities().getWhisperSeers()) {
      if (entity.getPlayer().getId() != client.getPlayer().getId()
          && !user.equals(entity.getUsername()))
        entity
            .getPlayer()
            .getSession()
            .send(
                new WhisperMessageComposer(
                    client.getPlayer().getEntity().getId(),
                    "Whisper to " + user + ": " + filteredMessage));
    }
  }