public final void unserialise(final byte[] data) { final ByteBuffer bb = ByteBuffer.wrap(data); this.m_id = bb.getInt(); this.m_isChallengeGoal = (bb.get() == 1); try { final byte[] targetPosition = new byte[bb.getInt()]; bb.get(targetPosition); this.m_targetPosition = new String(targetPosition, "UTF-8").intern(); this.m_isCountDownJauge = (bb.get() == 1); this.m_jaugeMaxValue = bb.getInt(); final byte[] jaugeVarName = new byte[bb.getInt()]; bb.get(jaugeVarName); this.m_jaugeVarName = new String(jaugeVarName, "UTF-8").intern(); } catch (UnsupportedEncodingException e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } }
@Override public boolean decode(final byte[] rawDatas) { final ByteBuffer bb = ByteBuffer.wrap(rawDatas); this.m_eventId = bb.getLong(); this.m_invitedId = bb.getLong(); final byte[] tInvitedName = new byte[bb.get()]; bb.get(tInvitedName); this.m_invitedName = StringUtils.fromUTF8(tInvitedName); this.m_result = bb.get(); 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(); }
public final byte[] serialize() { final byte[] cdata = StringUtils.toUTF8(this.m_criterion); final int presize = cdata.length; final ByteBuffer bb = ByteBuffer.allocate(32 + presize); bb.putInt(this.m_id); bb.put(this.m_order); bb.putInt(this.m_gfx); bb.putInt(cdata.length); bb.put(cdata); bb.put((byte) (this.m_success ? 1 : 0)); bb.putInt(this.m_itemId); bb.putShort(this.m_itemQty); bb.putInt(this.m_xp); bb.putInt(this.m_kama); bb.putInt(this.m_guildPoints); return bb.array(); }
@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"); } }
public final byte[] serialize() { ByteBuffer bb = null; try { final byte[] targetPosition = (this.m_targetPosition == null) ? new byte[0] : this.m_targetPosition.getBytes("UTF-8"); final byte[] jaugeVarName = (this.m_jaugeVarName == null) ? new byte[0] : this.m_jaugeVarName.getBytes("UTF-8"); bb = ByteBuffer.allocate(9 + targetPosition.length + 4 + 1 + 4 + jaugeVarName.length); bb.putInt(this.m_id); bb.put((byte) (this.m_isChallengeGoal ? 1 : 0)); bb.putInt(targetPosition.length); bb.put(targetPosition); bb.put((byte) (this.m_isCountDownJauge ? 1 : 0)); bb.putInt(this.m_jaugeMaxValue); bb.putInt(jaugeVarName.length); bb.put(jaugeVarName); } catch (UnsupportedEncodingException e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } return bb.array(); }
@Override public byte[] getBinaryData() { final ArrayList<byte[]> binGroups = new ArrayList<byte[]>(this.m_actionGroups.size()); final ArrayList<byte[]> binRewars = new ArrayList<byte[]>(this.m_rewards.size()); int presize = 0; presize += 4; try { for (final String var : this.m_varMapping) { presize += 4 + var.getBytes("UTF-8").length; } } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } try { presize += 8; presize += ((this.m_joinCriterion != null) ? this.m_joinCriterion.getBytes("UTF-8").length : 0); presize += ((this.m_rewardEligibilityCriterion != null) ? this.m_rewardEligibilityCriterion.getBytes("UTF-8").length : 0); } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } for (final ActionGroupStorable g : this.m_actionGroups) { final byte[] bin = g.serialize(); presize += bin.length + 4; binGroups.add(bin); } for (final RewardStorable r : this.m_rewards) { final byte[] bin = r.serialize(); presize += bin.length + 4; binRewars.add(bin); } try { presize += 4; presize += ((this.m_params != null) ? this.m_params.getBytes("UTF-8").length : 0); } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } final ByteBuffer bb = ByteBuffer.allocate(31 + presize); bb.putInt(this.m_id); bb.put(this.m_type); bb.put(this.m_userType); bb.put((byte) (this.m_autoTrigger ? 1 : 0)); bb.put((byte) (this.m_isChallenge ? 1 : 0)); bb.put((byte) (this.m_isChaos ? 1 : 0)); bb.putShort(this.m_duration); bb.putShort(this.m_minUsers); bb.putShort(this.m_maxUsers); if (this.m_expirationDate != null) { bb.putLong(this.m_expirationDate.toLong()); } else { bb.putLong(0L); } try { if (this.m_params != null) { final byte[] bytes = this.m_params.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } try { bb.putInt(this.m_varMapping.length); for (final String var2 : this.m_varMapping) { final byte[] bytes2 = var2.getBytes("UTF-8"); bb.putInt(bytes2.length); bb.put(bytes2); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } try { if (this.m_joinCriterion != null) { final byte[] bytes = this.m_joinCriterion.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } if (this.m_rewardEligibilityCriterion != null) { final byte[] bytes = this.m_rewardEligibilityCriterion.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } bb.putInt(binGroups.size()); for (final byte[] gdata : binGroups) { bb.putInt(gdata.length); bb.put(gdata); } bb.putInt(binRewars.size()); for (final byte[] rdata : binRewars) { bb.putInt(rdata.length); bb.put(rdata); } return bb.array(); }
@Override public byte[] encode() { final byte[] name = StringUtils.toUTF8(this.m_inviterName); final byte[] groupName = StringUtils.toUTF8(this.m_groupName); final int sizeDatas = 3 + name.length + 1 + groupName.length + 8; final ByteBuffer buffer = ByteBuffer.allocate(sizeDatas); buffer.put(this.m_groupType); buffer.put((byte) (this.m_invitationAccepted ? 1 : 0)); buffer.put((byte) name.length); buffer.put(name); buffer.put((byte) groupName.length); buffer.put(groupName); buffer.putLong(this.m_inviterId); if (this.m_sendToGlobalServer) { return this.addClientHeader((byte) 6, buffer.array()); } return this.addClientHeader((byte) 2, buffer.array()); }