예제 #1
0
  private void encodeCommand(@Nonnull AbstractCommand cmd) throws IOException {
    if (cmd.getId() != CommandList.CMD_KEEPALIVE) {
      log.debug("SND: {}", cmd);
    }

    buffer.clear();
    buffer.put((byte) cmd.getId());
    buffer.put((byte) (cmd.getId() ^ COMMAND_XOR_MASK));

    // keep some space for the length and the CRC
    int headerLenCRC = buffer.position();
    buffer.putShort((short) 0);
    buffer.putShort((short) 0);

    int startOfCmd = buffer.position();
    // encode command into net protocol
    cmd.encode(this);

    int length = buffer.position() - startOfCmd;
    buffer.flip();
    buffer.position(startOfCmd);
    int crc = NetComm.getCRC(buffer, length);
    buffer.position(headerLenCRC);
    buffer.putShort((short) length);
    buffer.putShort((short) crc);
    buffer.position(0);

    if (NetComm.isDumpingActive()) {
      NetComm.dump("snd => ", buffer);
      buffer.flip();
    }

    outChannel.write(buffer);
  }
예제 #2
0
  /**
   * Put command in send queue so its send at the next send loop.
   *
   * @param cmd the command that shall be added to the queue
   */
  @SuppressWarnings("nls")
  public void sendCommand(@Nonnull final AbstractCommand cmd) {
    if (IllaClient.isDebug(Debug.protocol)) {
      if (cmd.getId() != CommandList.CMD_KEEPALIVE) {
        LOGGER.debug("SND: " + cmd.toString());
      }
    }

    try {
      outputQueue.put(cmd);
    } catch (@Nonnull final InterruptedException e) {
      LOGGER.error("Got interrupted while trying to add a command to to the queue.");
    }
  }