Пример #1
0
 public static void checkHeader(ByteBuffer b, int length, int psecret, short step) {
   int l = b.getInt();
   int ps = b.getInt();
   int s = b.getShort();
   b.getShort(); // the student number, which I am not checking.
   if (l != length) {
     System.out.println("Packet length was " + l + " instead of " + length);
   }
   if (ps != psecret) {
     System.out.println("Psecret was " + ps + " instead of " + psecret);
   }
   if (s != step) {
     System.out.println("Packet length was " + s + " instead of " + step);
   }
 }
 public void unserializeResults(final ByteBuffer buffer) {
   final short resultsCount = buffer.getShort();
   for (int i = 0; i < resultsCount; ++i) {
     final DungeonLadderResult result = DungeonLadderResult.fromBuild(buffer);
     this.insertResult(result);
   }
 }
 @Override
 public boolean unserialize(final ByteBuffer buffer) {
   final int contents_size = buffer.getShort() & 0xFFFF;
   this.contents.clear();
   this.contents.ensureCapacity(contents_size);
   for (int i = 0; i < contents_size; ++i) {
     final Content contents_element = new Content();
     final boolean contents_element_ok = contents_element.unserialize(buffer);
     if (!contents_element_ok) {
       return false;
     }
     this.contents.add(contents_element);
   }
   final boolean contentsSelection_present = buffer.get() == 1;
   if (contentsSelection_present) {
     this.contentsSelection = new ContentsSelection();
     final boolean contentsSelection_ok = this.contentsSelection.unserialize(buffer);
     if (!contentsSelection_ok) {
       return false;
     }
   } else {
     this.contentsSelection = null;
   }
   final int buyableContents_size = buffer.getShort() & 0xFFFF;
   this.buyableContents.clear();
   this.buyableContents.ensureCapacity(buyableContents_size);
   for (int j = 0; j < buyableContents_size; ++j) {
     final BuyableContent buyableContents_element = new BuyableContent();
     final boolean buyableContents_element_ok = buyableContents_element.unserialize(buffer);
     if (!buyableContents_element_ok) {
       return false;
     }
     this.buyableContents.add(buyableContents_element);
   }
   return true;
 }
 private boolean unserialize_v0(final ByteBuffer buffer) {
   final int contentsSelection_size = buffer.getShort() & 0xFFFF;
   this.contentsSelection.clear();
   this.contentsSelection.ensureCapacity(contentsSelection_size);
   for (int i = 0; i < contentsSelection_size; ++i) {
     final ContentSelection contentsSelection_element = new ContentSelection();
     final boolean contentsSelection_element_ok =
         contentsSelection_element.unserializeVersion(buffer, 0);
     if (!contentsSelection_element_ok) {
       return false;
     }
     this.contentsSelection.add(contentsSelection_element);
   }
   return true;
 }
Пример #5
0
 @Override
 public boolean unserialize(final ByteBuffer buffer) {
   final int gems_size = buffer.getShort() & 0xFFFF;
   this.gems.clear();
   this.gems.ensureCapacity(gems_size);
   for (int i = 0; i < gems_size; ++i) {
     final Content gems_element = new Content();
     final boolean gems_element_ok = gems_element.unserialize(buffer);
     if (!gems_element_ok) {
       return false;
     }
     this.gems.add(gems_element);
   }
   return true;
 }
 public final void unserialise(final byte[] data) {
   final ByteBuffer bb = ByteBuffer.wrap(data);
   this.m_id = bb.getInt();
   this.m_order = bb.get();
   this.m_gfx = bb.getInt();
   final byte[] cdata = new byte[bb.getInt()];
   bb.get(cdata);
   try {
     this.m_criterion = new String(cdata, "UTF-8").intern();
   } catch (UnsupportedEncodingException e) {
     ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
   }
   this.m_success = (bb.get() == 1);
   this.m_itemId = bb.getInt();
   this.m_itemQty = bb.getShort();
   this.m_xp = bb.getInt();
   this.m_kama = bb.getInt();
   this.m_guildPoints = bb.getInt();
 }
Пример #7
0
  /**
   * Handles control packet.
   *
   * @param data raw packet data that arrived on control PPID.
   * @param sid SCTP stream id on which the data has arrived.
   */
  private synchronized void onCtrlPacket(byte[] data, int sid) throws IOException {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    int messageType = /* 1 byte unsigned integer */ 0xFF & buffer.get();

    if (messageType == MSG_CHANNEL_ACK) {
      if (logger.isDebugEnabled()) {
        logger.debug(getEndpoint().getID() + " ACK received SID: " + sid);
      }
      // Open channel ACK
      WebRtcDataStream channel = channels.get(sid);
      if (channel != null) {
        // Ack check prevents from firing multiple notifications
        // if we get more than one ACKs (by mistake/bug).
        if (!channel.isAcknowledged()) {
          channel.ackReceived();
          notifyChannelOpened(channel);
        } else {
          logger.warn("Redundant ACK received for SID: " + sid);
        }
      } else {
        logger.error("No channel exists on sid: " + sid);
      }
    } else if (messageType == MSG_OPEN_CHANNEL) {
      int channelType = /* 1 byte unsigned integer */ 0xFF & buffer.get();
      int priority = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      long reliability = /* 4 bytes unsigned integer */ 0xFFFFFFFFL & buffer.getInt();
      int labelLength = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      int protocolLength = /* 2 bytes unsigned integer */ 0xFFFF & buffer.getShort();
      String label;
      String protocol;

      if (labelLength == 0) {
        label = "";
      } else {
        byte[] labelBytes = new byte[labelLength];

        buffer.get(labelBytes);
        label = new String(labelBytes, "UTF-8");
      }
      if (protocolLength == 0) {
        protocol = "";
      } else {
        byte[] protocolBytes = new byte[protocolLength];

        buffer.get(protocolBytes);
        protocol = new String(protocolBytes, "UTF-8");
      }

      if (logger.isDebugEnabled()) {
        logger.debug(
            "!!! "
                + getEndpoint().getID()
                + " data channel open request on SID: "
                + sid
                + " type: "
                + channelType
                + " prio: "
                + priority
                + " reliab: "
                + reliability
                + " label: "
                + label
                + " proto: "
                + protocol);
      }

      if (channels.containsKey(sid)) {
        logger.error("Channel on sid: " + sid + " already exists");
      }

      WebRtcDataStream newChannel = new WebRtcDataStream(sctpSocket, sid, label, true);
      channels.put(sid, newChannel);

      sendOpenChannelAck(sid);

      notifyChannelOpened(newChannel);
    } else {
      logger.error("Unexpected ctrl msg type: " + messageType);
    }
  }
Пример #8
0
  /**
   * Parses the binary data that describes the recurrent pattern.
   *
   * @param data the binary data.
   * @param sourceTask the calendar item.
   */
  public RecurringPattern(byte[] data, CalendarItemTimerTask sourceTask) {
    this.sourceTask = sourceTask;
    dataBuffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);

    int offset = 4;
    recurFrequency = dataBuffer.getShort(offset);
    offset += 2;

    patternType = PatternType.getFromShort(dataBuffer.getShort(offset));
    offset += 2;

    calendarType = dataBuffer.getShort(offset);
    offset += 2;

    firstDateTime = dataBuffer.getInt(offset);
    offset += 4;

    period = dataBuffer.getInt(offset);
    offset += 4;

    slidingFlag = dataBuffer.getInt(offset);
    offset += 4;

    switch (patternType) {
      case Week:
      case Month:
      case MonthEnd:
      case HjMonth:
      case HjMonthEnd:
        patternSpecific1 = dataBuffer.getInt(offset);
        patternSpecific2 = 0;
        offset += 4;
        if (patternType == PatternType.Week) {
          for (int day = firstDow; day < firstDow + 7; day++) {
            if ((patternSpecific1 & (weekOfDayMask[day % 7])) != 0) {
              allowedDaysOfWeek.add((day % 7) + 1);
            }
          }
        }
        break;
      case MonthNth:
      case HjMonthNth:
        patternSpecific1 = dataBuffer.getInt(offset);
        patternSpecific2 = dataBuffer.getInt(offset + 4);
        if (patternSpecific1 == 0x7f && patternSpecific2 != 0x5) {
          patternType = PatternType.Month;
        }
        for (int day = 0; day < 7; day++) {
          if ((patternSpecific1 & (weekOfDayMask[day])) != 0) {
            allowedDaysOfWeek.add((day) + 1);
          }
        }
        offset += 8;
        break;
      default:
        break;
    }

    // endType
    endType = dataBuffer.getInt(offset);
    offset += 4;

    occurenceCount = dataBuffer.getInt(offset);
    offset += 4;

    firstDow = dataBuffer.getInt(offset);
    offset += 4;

    deletedInstanceCount = dataBuffer.getInt(offset);
    offset += 4;

    // deleted instances
    for (int i = 0; i < deletedInstanceCount; i++) {
      deletedInstances.add(windowsTimeToDateObject(dataBuffer.getInt(offset)));
      offset += 4;
    }

    modifiedInstanceCount = dataBuffer.getInt(offset);
    offset += 4;

    // modified instances
    modifiedInstances = new int[modifiedInstanceCount];

    for (int i = 0; i < modifiedInstanceCount; i++) {
      modifiedInstances[i] = dataBuffer.getInt(offset);
      offset += 4;
    }

    startDate = dataBuffer.getInt(offset);
    offset += 4;

    endDate = dataBuffer.getInt(offset);
    offset += 4;

    offset += 16;

    short exceptionCount = dataBuffer.getShort(offset);
    offset += 2;
    exceptionInfo = new ArrayList<ExceptionInfo>(exceptionCount);
    for (int i = 0; i < exceptionCount; i++) {
      ExceptionInfo tmpExceptionInfo = new ExceptionInfo(offset);
      exceptionInfo.add(tmpExceptionInfo);
      offset += tmpExceptionInfo.sizeInBytes();

      CalendarService.BusyStatusEnum status = tmpExceptionInfo.getBusyStatus();
      Date startTime = tmpExceptionInfo.getStartDate();
      Date endTime = tmpExceptionInfo.getEndDate();
      if (status == CalendarService.BusyStatusEnum.FREE || startTime == null || endTime == null)
        continue;
      Date currentTime = new Date();

      if (endTime.before(currentTime) || endTime.equals(currentTime)) return;

      boolean executeNow = false;

      if (startTime.before(currentTime) || startTime.equals(currentTime)) executeNow = true;

      CalendarItemTimerTask task =
          new CalendarItemTimerTask(
              status, startTime, endTime, sourceTask.getId(), executeNow, this);

      task.scheduleTasks();
    }
  }
 @Override
 public void build(final ByteBuffer bb, final int id, final short version) {
   this.setGlobalId(id);
   if (version == 1) {
     this.m_id = bb.getInt();
     this.m_type = bb.get();
     this.m_userType = bb.get();
     this.m_autoTrigger = (bb.get() == 1);
     this.m_isChallenge = (bb.get() == 1);
     this.m_isChaos = (bb.get() == 1);
     this.m_duration = bb.getShort();
     this.m_minUsers = bb.getShort();
     this.m_maxUsers = bb.getShort();
     final long time = bb.getLong();
     if (time != 0L) {
       this.m_expirationDate = GameDate.fromLong(time);
     } else {
       this.m_expirationDate = null;
     }
     try {
       final byte[] bytes = new byte[bb.getInt()];
       bb.get(bytes);
       this.m_params = new String(bytes, "UTF-8").intern();
     } catch (UnsupportedEncodingException e) {
       ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
     }
     try {
       final int mappingLen = bb.getInt();
       this.m_varMapping = new String[mappingLen];
       for (int i = 0; i < mappingLen; ++i) {
         final byte[] bytes2 = new byte[bb.getInt()];
         bb.get(bytes2);
         this.m_varMapping[i] = new String(bytes2, "UTF-8").intern();
       }
     } catch (UnsupportedEncodingException e) {
       ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
     }
     try {
       final byte[] bytes = new byte[bb.getInt()];
       bb.get(bytes);
       this.m_joinCriterion = new String(bytes, "UTF-8").intern();
       final byte[] rewardEligibilityCriterion = new byte[bb.getInt()];
       bb.get(rewardEligibilityCriterion);
       this.m_rewardEligibilityCriterion =
           new String(rewardEligibilityCriterion, "UTF-8").intern();
     } catch (UnsupportedEncodingException e) {
       ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e);
     }
     for (int glen = bb.getInt(), i = 0; i < glen; ++i) {
       final byte[] gdata = new byte[bb.getInt()];
       bb.get(gdata);
       final ActionGroupStorable g = new ActionGroupStorable();
       g.unserialise(gdata);
       this.m_actionGroups.add(g);
     }
     for (int rlen = bb.getInt(), j = 0; j < rlen; ++j) {
       final byte[] rdata = new byte[bb.getInt()];
       bb.get(rdata);
       final RewardStorable r = new RewardStorable();
       r.unserialise(rdata);
       this.m_rewards.add(r);
     }
   } else {
     ScenarioBinaryStorable.m_logger.error(
         (Object)
             "Tentative de d\u00e9s\u00e9rialisation d'un objet avec une version non prise en charge");
   }
 }