Initial commit

This commit is contained in:
2026-08-24 22:20:36 +02:00
commit 62f7b1278a
251 changed files with 16670 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name ActiveStatusEffects
@Packet identifier 161
@Description Sends which status effects are active
@Data pId, designId, playerId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + data.length;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 161);
view.setUint8(1, packetLength);
data.forEach((id, i) => view.setUint8(2 + i, id));
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name AdmiralSpawned
@Packet identifier 145
@Description Sends information about a spawned admiral
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 4 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { mapID, typeID, entityTypeID } = data;
view.setUint8(0, 145);
view.setUint8(1, packetLength);
view.setUint8(2, mapID);
view.setUint8(3, typeID);
view.setUint8(4, entityTypeID);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name AmmunitionChangeConfirmation
@Packet identifier 200
@Description Ammunition change confirmation
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 200);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint8(3, data.id);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name AmmunitionUsed
@Packet identifier 135
@Description unused
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 135);
view.setUint8(1, packetLength);
view.setUint8(2, data.amount);
view.setUint8(3, data.type);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name AttackAborted
@Packet identifier 141
@Description Sends the
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 11 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 141);
view.setUint8(1, packetLength);
view.setUint8(2, data.authorTypeID);
view.setUint32(3, data.authorID);
view.setUint8(7, data.targetTypeID);
view.setUint32(8, data.targetID);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name AttackInformation
@Packet identifier 139
@Description -
@Data pId, typeId, entityId
@Structure -
*/
module.exports = function (data) {
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 139);
view.setUint8(1, packetLength);
view.setUint8(2, data.authorTypeID);
view.setUint32(3, data.authorID);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name AttackerInformation
@Packet identifier 142
@Description Sends the
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 8 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 142);
view.setUint8(1, packetLength);
view.setUint8(2, data.authorTypeID);
view.setUint32(3, data.authorID);
view.setUint8(7, data.isTarget);
view.setUint8(8, data.source)
return buffer;
};
+25
View File
@@ -0,0 +1,25 @@
/*
@Packet name Attacking
@Packet identifier 140
@Description Sends the attack's data to the nearby players
@Data pId, authorTypeId, authorId, targetTypeId, targetId, damage, critical
@Structure -
*/
module.exports = function (data) {
const packetLength = 17 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 140);
view.setUint8(1, packetLength);
view.setUint8(2, data.authorTypeID);
view.setUint32(3, data.authorID);
view.setUint8(7, data.targetTypeID);
view.setUint32(8, data.targetID);
view.setUint32(12, data.damage);
view.setUint8(16, +data.critical);
view.setUint8(17, data.entityTypeID);
return buffer;
};
+30
View File
@@ -0,0 +1,30 @@
/*
@Packet name Cannonballs
@Packet identifier 153
@Description Sends the
@Data pId, (ammunitionId, damage, amount), selectedAmmunition
@Structure -
*/
module.exports = function (data) {
const { ammunition, selected } = data;
const packetLength = ammunition.length * 6 + 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 153);
view.setUint8(1, packetLength);
for (let i = 0; i < ammunition.length; i++) {
const ammo = ammunition[i];
view.setUint8(i * 6 + 2, ammo.id);
view.setUint8(i * 6 + 3, 0);
view.setUint32(i * 6 + 4, ammo.amount);
};
view.setUint8(2 + ammunition.length * 6, selected);
return buffer;
};
+40
View File
@@ -0,0 +1,40 @@
const Reward = require("../Game/Reward");
const rewardCallback = require("../Callbacks/reward");
const MAXIMUM_COUNT_MOJO = 1000;
const cauldronReward = new Reward({
distributionType: 2,
baseReward: {
3: {
5: { amountMinimum: 1500, chance: 16.5 },
6: { amountMinimum: 1500, chance: 16.5 },
7: { amountMinimum: 1500, chance: 16.5 },
8: { amountMinimum: 1500, chance: 16.5 },
9: { amountMinimum: 1500, chance: 16.5 },
10: { amountMinimum: 1500, chance: 16.5 },
}/*,
5: {
17: { amount: 1, chance: 1 }
}*/
}
});
module.exports = function (ws, message, player) {
let amount = message.getUint16(1);
if (!amount) return;
if (amount > MAXIMUM_COUNT_MOJO) amount = MAXIMUM_COUNT_MOJO;
// const usedItem = player.inventory.use(1, 3, amount);
// const economy = player.inventory.getEconomy();
const usedAmount = player.inventory.alterAmount(1, 3, amount);
if (!usedAmount) return console.log("not enough mojo");
console.log("mojo thrown | amount:", usedAmount);
const playerInventory = player.inventory.getPosessions();
cauldronReward.single(usedAmount, playerInventory, rewards => {
rewardCallback({ isRegular: false, death: { authorID: player.id }, rewards })
console.info(rewards)
});
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name DesignChanged
@Packet identifier 160
@Description Includes data about which entity changed texture
@Data pId, designId, typeId, playerId
@Structure -
*/
module.exports = function (data) {
const packetLength = 8 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { designID, typeID, id } = data;
view.setUint8(0, 160);
view.setUint8(1, packetLength);
view.setUint16(2, designID);
view.setUint8(4, typeID);
view.setUint32(5, id);
return buffer;
};
+24
View File
@@ -0,0 +1,24 @@
/*
@Packet name Economy
@Packet identifier 158
@Description Sends economy data
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + data.length * 5;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
for (let i = 0, length = data.length; i < length; i++) {
const economy = data[i];
view.setUint8(2 + i * 5, economy.id);
view.setUint32(2 + i * 5 + 1, economy.amount);
};
view.setUint8(0, 158);
view.setUint8(1, packetLength);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name EffectAdd
@Packet identifier 146
@Description Sends
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { typeID, id, effectID } = data;
view.setUint8(0, 146);
view.setUint8(1, packetLength);
view.setUint8(2, effectID)
view.setUint8(3, typeID);
view.setUint32(4, id);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name EntityDie
@Packet identifier 143
@Description Sends the death information to the nearby players
@Data pId, deadEntityTypeId, entityId, lastShotEntityTypeID, lastShotId
@Structure -
*/
module.exports = function (data) {
const packetLength = 12 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 143);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint32(3, data.targetID);
view.setUint8(7, data.lastShotTypeID);
view.setUint32(8, data.lastShotID);
view.setUint8(12, data.targetEntityTypeID);
return buffer;
};
+214
View File
@@ -0,0 +1,214 @@
/*
@Packet name EntityNew
@Packet identifier 134
@Description Holds data about the entity that a player encountered
@Data -
@Structure -
*/
module.exports.player = function (data) {
const destinationX = data.currentNode[0];
const destinationY = data.currentNode[1];
const curHP = data.hp.current;
const maxHP = data.hp.maximum;
const x = data.position.x;
const y = data.position.y;
const name = data.name;
const guild = data.guildTag;
const id = data.id;
const mapID = data.mapID;
const speed = data.speed;
const typeID = data.typeID;
const textureID = data.textureID;
const isMoving = data.isMoving;
const pirateLevel = data.pirateLevel;
const globalRank = data.globalRank;
const levelRank = data.levelRank;
let packetLength = 28 + name.length + (guild ? guild.length : 0) + 1 + 4;
if (isMoving) packetLength += 4;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 134);
view.setUint8(1, packetLength);
view.setUint8(2, typeID);
view.setUint32(3, id);
view.setUint32(7, curHP);
view.setUint32(11, maxHP);
view.setUint16(15, x);
view.setUint16(17, y);
view.setUint16(19, speed);
view.setUint8(21, pirateLevel);
view.setUint8(22, mapID);
view.setUint8(23, textureID);
view.setUint8(24, isMoving);
view.setUint8(25, globalRank);
view.setUint8(26, levelRank);
view.setUint8(27, name.length);
view.setUint8(28, guild ? guild.length : 0);
if (isMoving) {
view.setUint16(29, destinationX);
view.setUint16(31, destinationY);
};
const nameBuffer = Buffer.from(name);
for (const pair of nameBuffer.entries()) {
const index = pair[0];
view.setUint8(isMoving ? index + 33 : index + 29, pair[1]);
};
if (guild) {
const guildBuffer = Buffer.from(guild);
for (const pair of guildBuffer.entries()) {
const index = pair[0];
view.setUint8(isMoving ? index + 33 + name.length : index + 29 + name.length, pair[1]);
};
view.setUint32(isMoving ? guild.length + name.length + 33 : guild.length + name.length + 29, data.guildColor);
};
const metadata = [curHP / maxHP, x, y, typeID];
return {
buffer,
metadata
};
};
module.exports.npc = function (data) {
const destinationX = data.path[0];
const destinationY = data.path[1];
const { id, speed, size, typeID, entityTypeID, behaviourBits, activeEffectsBits, isAdmiral, isMoving, isSpeedLowered } = data;
const packetLength = (isMoving ? 31 : 27) + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const curHP = data.hp.current;
const maxHP = data.hp.maximum;
const x = data.position.x;
const y = data.position.y;
const intermediatePositionX = 0
const intermediatePositionY = 0
view.setUint8(0, 134);
view.setUint8(1, packetLength);
view.setUint8(2, typeID)
view.setUint32(3, id);
view.setUint8(7, entityTypeID)
view.setUint32(8, curHP);
view.setUint32(12, maxHP);
view.setUint16(16, x);
view.setUint16(18, y);
view.setUint16(20, speed);
view.setUint8(22, activeEffectsBits);
view.setUint8(23, +isMoving);
view.setUint8(24, +isSpeedLowered);
view.setUint8(25, +isAdmiral);
view.setUint8(26, activeEffectsBits);
view.setUint8(27, size);
if (isMoving) {
view.setUint16(28, destinationX);
view.setUint16(30, destinationY);
};
const metadata = [curHP / maxHP, x, y, typeID];
return {
buffer,
metadata
};
};
module.exports.monster = function (data) {
const packetLength = 20 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { typeID, id, position, isAdmiral, entityTypeID, hp } = data;
view.setUint8(0, 134);
view.setUint8(1, packetLength);
view.setUint8(2, typeID);
view.setUint32(3, id);
view.setUint8(7, entityTypeID);
view.setUint8(8, isAdmiral);
view.setUint32(9, hp.current);
view.setUint32(13, hp.maximum);
view.setUint16(17, position.x);
view.setUint16(19, position.y);
const metadata = [hp.current / hp.maximum, position.x, position.y, typeID];
return {
buffer,
metadata
};
};
module.exports.tower = function (data) {
const packetlength = (data.guildTag ? 23 : 20) + 1 + 4;
const buffer = new ArrayBuffer(packetlength);
const view = new DataView(buffer);
const { hp, position, guildTag, id, entityTypeID, typeID, guildColor, order } = data;
view.setUint8(0, 134);
view.setUint8(1, packetlength);
view.setUint8(2, typeID);
view.setUint32(3, id);
view.setUint16(7, position.x);
view.setUint16(9, position.y);
view.setUint32(11, hp.current);
view.setUint32(15, hp.maximum);
view.setUint8(19, entityTypeID);
view.setUint8(20, order);
if (guildTag) {
const guildBuffer = Buffer.from(guildTag);
for (const pair of guildBuffer.entries()) {
const index = pair[0];
view.setUint8(21 + index, pair[1]);
};
view.setUint32(24, guildColor);
};
const metadata = [hp.current / hp.maximum, position.x, position.y, typeID];
return {
buffer,
metadata
};
};
module.exports.collectable = function (data) {
const packetLength = 11 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { typeID, id, entityTypeID, position } = data;
view.setUint8(0, 134);
view.setUint8(1, packetLength);
view.setUint8(2, typeID);
view.setUint32(3, id);
view.setUint8(7, entityTypeID);
view.setUint16(8, position.x);
view.setUint16(10, position.y);
const metadata = [position.x, position.y, typeID];
return {
buffer,
metadata
};
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name EntityOld
@Packet identifier 133
@Description Sends the entity type and id to the player who left it
@Data pId, typeId, entityId
@Structure -
*/
module.exports = function (data) {
const { typeID, id } = data;
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 133);
view.setUint8(1, packetLength);
view.setUint8(2, typeID);
view.setUint32(3, id);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name EntitySpeedChanged
@Packet identifier 150
@Description Sends information about the new speed of NPC
@Data pId, mapId, guildName
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 150);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint32(3, data.id);
view.setUint16(7, data.speed);
return buffer;
};
+17
View File
@@ -0,0 +1,17 @@
/*
@Packet name ready
@Packet identifier 2
@Description Ready event
@Data pId, mapId
@Structure -
*/
module.exports = function (data) {
const buffer = new ArrayBuffer(2);
const view = new DataView(buffer);
view.setUint8(0, 2);
view.setUint8(1, data);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name EquiptmentCapacitiesMaximum
@Packet identifier 156
@Description -
@Data pId, cannonSlots, harpoonerSlots, sailSlots, pirateSlots
@Structure -
*/
module.exports = function (data) {
const packetLength = data.length * 2 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 156);
view.setUint8(1, packetLength);
data.forEach((e, i) => {
view.setUint16(2 + i * 2, e);
});
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name EquipmentConfirmation
@Packet identifier 148
@Description -
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 148);
view.setUint8(1, packetLength);
view.setUint8(2, data)
return buffer;
};
+36
View File
@@ -0,0 +1,36 @@
/*
@Packet name Equipments
@Packet identifier 168
@Description -
@Data pId
@Structure -
*/
module.exports = {
init: length => {
const packetLength = length * 4 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 168);
view.setUint8(1, packetLength);
let i = 0;
return {
update: d => {
const startIndex = i * 4;
view.setUint8(2 + startIndex, d.typeID);
view.setUint8(2 + startIndex + 1, d.id);
view.setUint8(2 + startIndex + 2, d.amount);
view.setUint8(2 + startIndex + 3, d.amountEquipped);
i++;
},
get: () => {
return buffer;
}
};
}
};
+27
View File
@@ -0,0 +1,27 @@
/*
@Packet name GuildDataApplicant
@Packet identifier 191
@Description Holds data about a single applicant
@Data -
@Structure -
*/
const encoder = new TextEncoder();
module.exports = function (data) {
const nameBuffer = encoder.encode(data.username);
const packetLength = 8 + 1 + nameBuffer.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 191);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
view.setUint16(6, data.pirateLevel);
view.setUint8(8, nameBuffer.byteLength);
new Uint8Array(buffer, 9).set(nameBuffer);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name GuildDataApplicantRemove
@Packet identifier 192
@Description Holds data about a single applicant who was removed
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 5 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 192);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name GuildDataCreationFeedback
@Packet identifier 230
@Description Holds data about feedback for guild creation
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 230);
view.setUint8(1, packetLength);
view.setUint8(2, data.reason);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name GuildDataEconomy
@Packet identifier 178
@Description Includes data about guild currencies
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = data.length * 4 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 178);
view.setUint8(1, packetLength);
data.forEach((d, i) => view.setUint32(2 + i * 4, d.amount));
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name GuildDataEconomy
@Packet identifier 187
@Description Includes confirmation data about donated guild economy
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 187);
view.setUint8(1, packetLength);
view.setUint8(2, data.id);
view.setUint32(3, data.amount);
return buffer;
};
+44
View File
@@ -0,0 +1,44 @@
/*
@Packet name GuildDataGeneral
@Packet identifier 175
@Description Includes data about general guild properties
@Data pId,
@Structure -
*/
const encoder = new TextEncoder();
module.exports = function (data) {
const tagBuffer = encoder.encode(data.tag);
const nameBuffer = encoder.encode(data.name);
const descriptionBuffer = encoder.encode(data.description);
const packetLength = 29 + 1 + tagBuffer.byteLength + nameBuffer.byteLength + descriptionBuffer.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 175);
view.setUint8(1, packetLength);
view.setUint8(2, data.level);
view.setUint8(3, data.size.current);
view.setUint8(4, data.size.maximum);
view.setUint8(5, data.taxRates[0]);
view.setUint8(6, data.taxRates[1]);
view.setUint32(7, data.timestamps.tagEditedAt);
view.setUint32(11, data.timestamps.nameEditedAt);
view.setUint32(15, data.timestamps.descriptionEditedAt);
view.setUint32(19, data.timestamps.taxRatesEditedAt);
view.setUint32(23, data.experience);
console.info(data, "guild general data")
view.setUint8(27, tagBuffer.byteLength);
new Uint8Array(buffer, 28).set(tagBuffer);
view.setUint8(28 + tagBuffer.byteLength, nameBuffer.byteLength);
new Uint8Array(buffer, 28 + tagBuffer.byteLength + 1).set(nameBuffer);
view.setUint8(28 + tagBuffer.byteLength + nameBuffer.byteLength + 1, descriptionBuffer.byteLength);
new Uint8Array(buffer, 28 + tagBuffer.byteLength + nameBuffer.byteLength + 1 + 1).set(descriptionBuffer);
return buffer;
};
+35
View File
@@ -0,0 +1,35 @@
/*
@Packet name GuildDataIdentityModified
@Packet identifier 186
@Description Includes data about modified guild identity (tag, name, description) and the timestamps of the end of cooldowns
@Data -
@Structure -
*/
module.exports = function (data) {
const identityLength = data.bufferTag.byteLength + 1 + data.bufferName.byteLength + 1 + data.bufferDescription.byteLength + 1;
const packetLength = 3 * (4 + 1) + identityLength + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 186);
view.setUint8(1, packetLength);
view.setUint8(2, data.r[0]);
view.setUint32(3, data.timestamps.tagEditedAt);
view.setUint8(7, data.r[1]);
view.setUint32(8, data.timestamps.nameEditedAt);
view.setUint8(12, data.r[2]);
view.setUint32(13, data.timestamps.descriptionEditedAt);
view.setUint8(17, data.bufferTag.byteLength);
new Uint8Array(buffer, 18).set(data.bufferTag);
view.setUint8(18 + data.bufferTag.byteLength, data.bufferName.byteLength);
new Uint8Array(buffer, 18 + data.bufferTag.byteLength + 1).set(data.bufferName);
view.setUint8(18 + data.bufferTag.byteLength + data.bufferName.byteLength + 1, data.bufferDescription.byteLength);
new Uint8Array(buffer, 18 + data.bufferTag.byteLength + 1 + data.bufferName.byteLength + 1).set(data.bufferDescription);
console.info("buffer", buffer)
console.info(data.timestamps)
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name GuildDataIsland
@Packet identifier 179
@Description Includes data about a guild island
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 179);
view.setUint8(1, packetLength);
view.setUint8(2, data.id);
view.setUint8(3, data.mapID)
view.setUint16(4, data.position.x);
view.setUint16(6, data.position.y);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name GuildDataIslandCaptured
@Packet identifier 184
@Description Includes data about a guild island that has been captured
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 184);
view.setUint8(1, packetLength);
view.setUint8(2, data.guildIslandID);
return buffer;
};
+24
View File
@@ -0,0 +1,24 @@
/*
@Packet name GuildDataIslandTower
@Packet identifier 180
@Description Includes data about a guild island tower
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 13 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 180);
view.setUint8(1, packetLength);
view.setUint8(2, data.entityTypeID);
view.setUint32(3, data.id);
view.setUint8(7, data.guildIslandID);
view.setUint8(8, data.order);
view.setUint32(9, data.hp.current);
view.setUint8(13, data.isRepairing);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name GuildDataIslandTowerBuilt
@Packet identifier 181
@Description Includes data about a built guild island tower
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 181);
view.setUint8(1, packetLength);
view.setUint8(2, data.entityTypeID);
view.setUint32(3, data.id);
view.setUint8(7, data.guildIslandID);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name GuildDataIslandTowerDestroyed
@Packet identifier 182
@Description Includes data about a destroyed guild island tower
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 182);
view.setUint8(1, packetLength);
view.setUint8(2, data.entityTypeID);
view.setUint32(3, data.id);
view.setUint8(7, data.guildIslandID);
return buffer;
};
@@ -0,0 +1,22 @@
/*
@Packet name GuildDataIslandTowerHealthChanged
@Packet identifier 183
@Description Includes data about a guild island tower that has its current hitpoint changed
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 11 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 183);
view.setUint8(1, packetLength);
view.setUint8(2, data.entityTypeID);
view.setUint32(3, data.id);
view.setUint8(7, data.guildIslandID);
view.setUint32(8, data.currentHitpoint)
return buffer;
};
+29
View File
@@ -0,0 +1,29 @@
/*
@Packet name GuildDataMember
@Packet identifier 176
@Description Includes data about a guild member
@Data pId,
@Structure -
*/
const encoder = new TextEncoder();
module.exports = function (data) {
const nameBuffer = encoder.encode(data.name);
const packetLength = 13 + 1 + nameBuffer.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 176);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
view.setUint32(6, data.permission)
view.setUint8(10, data.isOnline);
view.setUint16(11, data.pirateLevel);
console.info(data);
view.setUint8(13, nameBuffer.byteLength);
new Uint8Array(buffer, 14).set(nameBuffer);
return buffer;
};
+60
View File
@@ -0,0 +1,60 @@
/*
@Packet name GuildDataMemberChanged
@Packet identifier 193
@Description Holds data about a single guild member's changed properties
@Data -
@Structure -
*/
const encoder = new TextEncoder();
module.exports = function (data) {
const packetLength = 5 + 1 + 1 +
("isOnline" in data ? 1 : 0) +
("permission" in data ? 4 : 0) +
("level" in data ? 2 : 0) +
("name" in data ? 1 + data.name.length : 0);
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
let offset = 6;
let mask = 0;
console.info(packetLength, "isOnline" in data, "permission" in data, "level" in data, "name" in data)
if ("isOnline" in data) {
mask |= (1 << 0);
view.setUint8(offset + 1, data.isOnline);
offset += 1;
};
if ("permission" in data) {
mask |= (1 << 1);
view.setUint32(offset + 1, data.permission);
offset += 4;
};
if ("level" in data) {
mask |= (1 << 2);
view.setUint16(offset + 1, data.level);
offset += 2;
};
if ("name" in data) {
mask |= (1 << 3);
const nameBuffer = encoder.encode(data.name);
view.setUint8(offset + 1, nameBuffer.byteLength);
new Uint8Array(buffer, offset + 2).set(nameBuffer);
offset += 1 + nameBuffer.byteLength;
};
view.setUint8(0, 193);
view.setUint8(1, packetLength);
view.setUint8(2, mask);
view.setUint32(3, data.id);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name GuildDataMemberRemoved
@Packet identifier 185
@Description Includes data about a guild member who joined a guild
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 5 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 185);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name GuildDataTaxRatesModified
@Packet identifier 188
@Description Includes data about modified guild tax rates
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = data.length + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 188);
view.setUint8(1, packetLength);
data.forEach((d, i) => view.setUint8(2 + i, d));
console.info(data, buffer);
return buffer;
};
+11
View File
@@ -0,0 +1,11 @@
module.exports = function (data) {
const packetLength = 1 + 1 + data.tag.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 174);
view.setUint8(1, packetLength);
new Uint8Array(buffer, 2).set(data.tag);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name GuildLeaveConfirmation
@Packet identifier 177
@Description Confirms the requested resignation from guild
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 177);
view.setUint8(1, packetLength);
view.setUint8(2, data);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
this one is for accepted members
sent out to all the players that are near to the accepted player (to update the player's guild tag)
*/
module.exports = function (data) {
const packetLength = 6 + 1 + data.tag.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 45);
view.setUint8(1, packetLength);
view.setUint32(2, data.playerID);
view.setUint8(6, data.tag.byteLength);
new Uint8Array(buffer, 7).set(data.tag);
return buffer;
};
+28
View File
@@ -0,0 +1,28 @@
/*
this one is for the leaving members
sent out to all the players that are near to the leaving player (to update the player's guild tag to nothing)
*/
module.exports = function (data) {
// data: { playerID: number }
const packetLength = 5 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 46);
view.setUint8(1, packetLength);
view.setUint32(2, data.playerID);
return buffer;
};
/*
const guildMemberOld = serializeGuildMemberOld({ playerID: 7 });
const guildMemberOldView = new DataView(guildMemberOld);
const playerID = guildMemberOldView.getUint32(1);
*/
+34
View File
@@ -0,0 +1,34 @@
/*
@Packet name GuildSearchResult
@Packet identifier 189
@Description Sends the
@Data Holds data of a single result of a guild when searching guilds
@Structure -
*/
const encoder = new TextEncoder();
module.exports = function (data) {
const tagBuffer = encoder.encode(data.tag);
const nameBuffer = encoder.encode(data.name);
const packetLength = 9 + 1 + tagBuffer.byteLength + nameBuffer.byteLength;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 189);
view.setUint8(1, packetLength);
view.setUint16(2, data.id);
view.setUint8(4, data.size.current);
view.setUint8(5, data.size.maximum);
view.setUint8(6, data.hasApplied);
view.setUint8(7, data.isLastEntry);
view.setUint8(8, tagBuffer.byteLength);
new Uint8Array(buffer, 9).set(tagBuffer);
view.setUint8(7 + tagBuffer.byteLength + 1 + 1, nameBuffer.byteLength);
new Uint8Array(buffer, 7 + tagBuffer.byteLength + 1 + 1 + 1).set(nameBuffer);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name GuildSearchResultStateChanged
@Packet identifier 190
@Description Holds data of a single result's application state change
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 4 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 190);
view.setUint8(1, packetLength);
view.setUint16(2, data.id);
view.setUint8(4, data.hasApplied);
return buffer;
};
+30
View File
@@ -0,0 +1,30 @@
/*
@Packet name Harpoons
@Packet identifier 154
@Description Sends the
@Data pId, (harpoonId, damage, amount), selectedHarpoon
@Structure -
*/
module.exports = function (data) {
const { harpoon, selected } = data;
const packetLength = harpoon.length * 6 + 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 154);
view.setUint8(1, packetLength);
for (let i = 0; i < harpoon.length; i++) {
const harp = harpoon[i];
view.setUint8(i * 6 + 2, harp.id);
view.setUint8(i * 6 + 3, 0);
view.setUint32(i * 6 + 4, harp.amount);
};
view.setUint8(2 + harpoon.length * 6, selected);
return buffer;
};
+25
View File
@@ -0,0 +1,25 @@
/*
@Packet name HealthChanged
@Packet identifier 163
@Description Sends information about health modification (increase, decrease)
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 17 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 163);
view.setUint8(1, packetLength);
view.setUint8(2, data.authorTypeID);
view.setUint32(3, data.authorID);
view.setUint8(7, data.targetTypeID);
view.setUint32(8, data.targetID);
view.setUint32(12, data.amount);
view.setUint8(16, data.type);
view.setUint8(17, data.isCritical);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name HealthChangedAuthorless
@Packet identifier 162
@Description -
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 12 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 162);
view.setUint8(1, packetLength);
view.setUint8(2, data.targetTypeID);
view.setUint32(3, data.targetID);
view.setUint32(7, data.amount);
view.setUint8(11, data.type);
view.setUint8(12, data.isCritical);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name ItemBought
@Packet identifier 170
@Description Holds data about a bought item's confirmation from shop
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 170);
view.setUint8(1, packetLength);
view.setUint8(2, data.categoryID);
view.setUint8(3, data.id);
view.setUint32(4, data.amount);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name ItemUsed
@Packet identifier 164
@Description Sends information about a used item
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 5 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 164);
view.setUint8(1, packetLength);
view.setUint8(2, data.statusID);
view.setUint8(3, data.itemID);
view.setUint8(4, data.amountToRemove);
view.setUint8(5, data.isActive);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name Items
@Packet identifier 155
@Description Sends item information
@Data pId, type, amount
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + data.length * 5;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 155);
view.setUint8(1, packetLength);
data.forEach((item, i) => {
view.setUint8(2 + i * 5, item.id);
view.setUint32(3 + i * 5, item.amount);
});
return buffer;
};
+41
View File
@@ -0,0 +1,41 @@
/*
@Packet name LeaderboardPage
@Packet identifier 166
@Description -
@Data pId
@Structure -
*/
module.exports = {
init: (leaderboardID, length) => {
const packetLength = (length * 16 + length * 4) + 4 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 166);
view.setUint8(1, packetLength);
view.setUint16(2, leaderboardID);
view.setUint8(4, length);
let i = 0;
return {
update: d => {
const startIndex = i * (16 + 4);
const nameBuffer = Buffer.from(d.username);
for (const pair of nameBuffer.entries()) {
const index = pair[0];
view.setUint8(5 + startIndex + index, pair[1]);
};
view.setUint32(5 + startIndex + 16, d.amount);
i++;
},
get: () => {
return buffer;
}
};
}
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name LeaderboardPositions
@Packet identifier 165
@Description
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + 7 * (2 + 2);
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 165);
view.setUint8(1, packetLength);
for (let i = 0; i < 7; i++) {
view.setUint16(2 + i * 4, data[i].selfPosition);
view.setUint16(2 + i * 4 + 2, data[i].totalPositionsLength);
};
return buffer;
};
+18
View File
@@ -0,0 +1,18 @@
/*
@Packet name LevelIsLow
@Packet identifier 152
@Description Sends "level is low" notification
@Data pId
@Structure -
*/
module.exports = function() {
const packetLength = 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 152);
view.setUint8(1, packetLength);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name LevelUp
@Packet identifier 159
@Description -
@Data pId, level, statusLevelID, playerID
@Structure -
*/
module.exports = function (data) {
const packetLength = 8 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { level, statusLevelID, id } = data;
view.setUint8(0, 159);
view.setUint8(1, packetLength);
view.setUint16(2, level);
view.setUint8(4, statusLevelID);
view.setUint32(5, id);
return buffer;
};
+18
View File
@@ -0,0 +1,18 @@
/*
@Packet name LogoutCancelled
@Packet identifier 136
@Description Sends the player's id to the nearby players
@Data pId, playerId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 136);
view.setUint8(1, packetLength);
return buffer;
};
+52
View File
@@ -0,0 +1,52 @@
/*
@Packet name MainPlayer
@Packet identifier 128
@Description Sends the connected main player's data
@Data pId,
@Structure -
*/
module.exports = function (data) {
// const guildTag = data.guildTag;
const packetLength = 52 + 1; // (guildTag ? 51 : 48) + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 128);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
view.setUint32(6, data.hp.current);
view.setUint32(10, data.hp.maximum);
view.setUint16(14, data.position.x);
view.setUint16(16, data.position.y);
view.setUint16(18, data.speed);
view.setUint8(20, data.mapID);
view.setUint16(21, data.textureID);
view.setUint16(23, data.harpoonerRange);
view.setUint16(25, data.cannonRange)
view.setUint8(27, +data.isSpeedLowered)
view.setUint8(28, +data.isRepairing)
view.setUint16(29, data.pirateLevel);
view.setUint16(31, data.eliteLevel);
view.setUint16(33, data.fishingLevel);
view.setUint8(35, data.globalRank);
view.setUint8(36, data.levelRank);
const nameBuffer = Buffer.from(data.name);
for (const pair of nameBuffer.entries()) {
const index = pair[0];
view.setUint8(37 + index, pair[1]);
};
/*
if (guildTag) {
const guildBuffer = Buffer.from(guildTag);
for (const pair of guildBuffer.entries()) {
const index = pair[0];
view.setUint8(49 + index, pair[1]);
};
};
*/
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name MaintenanceScheduled
@Packet identifier 254
@Description Sends the
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 7 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 254);
view.setUint8(1, packetLength);
view.setUint32(2, data.timestamp);
view.setUint16(6, data.timeSeconds);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name MapChangeState
@Packet identifier 151
@Description -
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 4 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 151);
view.setUint8(1, packetLength);
view.setUint8(2, data.isAbleToJump);
view.setUint16(3, data.newMapID);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name MapChanged
@Packet identifier 169
@Description Sends the
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { mapID, x, y } = data;
view.setUint8(0, 169);
view.setUint8(1, packetLength);
view.setUint8(2, mapID);
view.setUint16(3, x);
view.setUint16(5, y);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name MaximumCannonsSize
@Packet identifier 156
@Description -
@Data pId, cannonSlots
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 156);
view.setUint8(1, packetLength);
view.setUint16(2, data);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name MiniMapEntryMove
@Packet identifier 201
@Description Includes data about a minimap entry's new position
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 9 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 201);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
view.setUint16(6, data.position.x);
view.setUint16(8, data.position.y);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name MiniMapEntryRemove
@Packet identifier 202
@Description Includes data about a removed minimap entry
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 5 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 202);
view.setUint8(1, packetLength);
view.setUint32(2, data.id);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name MojoRemoved
@Packet identifier 172
@Description Confirms how many mojo was removed.
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 172);
view.setUint8(1, packetLength)
view.setUint16(2, data);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name NewDestinationNode
@Packet identifier 167
@Description Sends the next node
@Data pId
@Structure -
*/
const packetLength = 1 + 10;
module.exports = function (data) {
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 167);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint32(3, data.id);
view.setUint16(7, data.x);
view.setUint16(9, data.y);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name ObtainedDesigns
@Packet identifier 132
@Description Contains information about the design ID's that the player is owner of
@Data pId, typeId, entityId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + data.length;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 132);
view.setUint8(1, packetLength);
data.forEach((id, i) => view.setUint8(2 + i, id));
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name PropertyChanged
@Packet identifier 137
@Description -
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 137);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint32(3, data.value);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name PropertyChangedGeneral
@Packet identifier 199
@Description -
@Data pId,
@Structure -
*/
module.exports = function (data) {
const packetLength = 11 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 199);
view.setUint8(1, packetLength);
view.setUint8(2, data.typeID);
view.setUint32(3, data.id);
view.setUint8(7, data.propertyTypeID);
view.setUint32(8, data.value);
return buffer;
};
+21
View File
@@ -0,0 +1,21 @@
/*
@Packet name QuestAdded
@Packet identifier 173
@Description Adding a quest by its ID
@Data pId, questId, isSuccessful
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 3;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { questID } = data;
view.setUint8(0, 173);
view.setUint8(1, packetLength);
view.setUint16(2, questID);
return buffer;
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name QuestRemoval
@Packet identifier 129
@Description Removing a quest by its ID
@Data pId, questId, isSuccessful
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 4;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { questID, isSuccessful } = data;
view.setUint8(0, 129);
view.setUint8(1, packetLength);
view.setUint16(2, questID);
view.setUint8(4, isSuccessful);
return buffer;
};
+35
View File
@@ -0,0 +1,35 @@
/*
@Packet name Quests
@Packet identifier 147
@Description Sends the quests' data
@Data pId
@Structure -
*/
module.exports = {
init: () => {
const buffer = new ArrayBuffer(512);
const view = new DataView(buffer);
view.setUint8(0, 147);
view.setUint8(1, 0);
let i = 0;
return {
update: d => {
const { id, progression } = d;
view.setUint16(2 + i, id);
view.setUint8(2 + i + 2, progression.length);
progression.forEach((p, j) => view.setUint32(2 + i + 3 + j * 4, p.amount));
i += 3 + progression.length * 4;
},
get: () => {
view.setUint8(1, i + 2);
return buffer.slice(0, i + 2);
}
};
}
};
+24
View File
@@ -0,0 +1,24 @@
/*
@Packet name QuestsCompletedAmount
@Packet identifier 149
@Description Sends how many times quests have been completed
@Data pId,
@Structure -
*/
module.exports = function (data) {
const keys = Object.keys(data);
const packetLength = keys.length * 3 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 149);
view.setUint8(1, packetLength);
keys.forEach((id, i) => {
view.setUint16(2 + i * 3, id);
view.setUint8(2 + i * 3 + 2, data[id]);
});
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name RankPoint
@Packet identifier 206
@Description Holds data about a value needed to calculate a specific rank
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 5 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 206);
view.setUint8(1, packetLength);
view.setUint8(2, data.rankTypeID);
view.setUint32(3, data.value);
return buffer;
};
+24
View File
@@ -0,0 +1,24 @@
/*
@Packet name RankThresholdPoints
@Packet identifier 205
@Description Holds data about needed points to be in a specific rank bracket
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = data.thresholds.length * 4 + 1 + 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 205);
view.setUint8(1, packetLength);
view.setUint8(2, data.rankTypeID);
console.info(data)
for (let i = 0, length = data.thresholds.length; i < length; i++)
view.setUint32(3 + i * 4, data.thresholds[i]);
return buffer;
};
+19
View File
@@ -0,0 +1,19 @@
/*
@Packet name RepairConfirmation
@Packet identifier 138
@Description Confirms the repair request of the packet author.
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 2 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 138);
view.setUint8(1, packetLength)
view.setUint8(2, data);
return buffer;
};
+18
View File
@@ -0,0 +1,18 @@
/*
@Packet name RespawnConfirmation
@Packet identifier 144
@Description Sends the confirmation of the respawn
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 144);
view.setUint8(1, packetLength);
return buffer;
};
+66
View File
@@ -0,0 +1,66 @@
/*
@Packet name Reward
@Packet identifier 131
@Description Contains information about rewards the player got
@Data pId
@Structure -
*/
module.exports = {
init: (isRegular, length) => {
const maxEntries = Math.floor((255 - (1 + 2)) / 6);
let submittedLength = length;
if (length > maxEntries) length = maxEntries;
submittedLength -= length;
const offset = 3;
const packetLength = length * 6 + 1 + 2;
let i = 0;
let j = 0;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 131);
view.setUint8(1, packetLength);
view.setUint8(2, isRegular ? 255 : 0);
const buffers = [buffer];
const views = [view];
return {
update: d => {
const startIndex = i * 6;
views[j].setUint8(offset + startIndex, d.categoryID);
views[j].setUint8(offset + startIndex + 1, d.id);
views[j].setInt32(offset + startIndex + 2, d.amount);
i++;
if (maxEntries === i) {
i = 0;
j++;
if (submittedLength > maxEntries) length = maxEntries;
else length = submittedLength;
submittedLength -= length
if (submittedLength < 0) length = maxEntries + submittedLength;
const packetLength = length * 6 + 1 + 2;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 131);
view.setUint8(1, packetLength);
view.setUint8(2, isRegular ? 255 : 0);
buffers.push(buffer);
views.push(view);
};
},
get: () => {
return buffers;
}
};
}
};
+24
View File
@@ -0,0 +1,24 @@
/*
@Packet name ShopEntry
@Packet identifier 215
@Description Holds data about a shop entry
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 12 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 215);
view.setUint8(1, packetLength);
view.setUint8(2, data.id);
view.setUint8(3, data.categoryID);
view.setUint16(4, data.itemID);
view.setUint8(6, data.currencyType);
view.setUint32(7, data.currencyAmount);
view.setUint16(11, data.unit);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name ShopEntryRemoved
@Packet identifier 216
@Description Holds the id of a shop entry being removed
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 216);
view.setUint8(1, packetLength);
view.setUint8(2, data.shopCategoryID);
view.setUint8(3, data.id);
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name SpyResult
@Packet identifier 130
@Description Spy event
@Data pId, mapId, positionX, positionY
@Structure -
*/
module.exports = function (data) {
const packetLength = 6 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { mapID, x, y } = data;
view.setUint8(0, 130);
view.setUint8(1, packetLength);
view.setUint8(2, mapID)
view.setUint16(3, x);
view.setUint16(5, y);
return buffer;
};
+27
View File
@@ -0,0 +1,27 @@
/*
@Packet name StatusPoints
@Packet identifier 157
@Description Sends points data (pirate, elite, fishing levels)
@Data pId, experience
@Structure -
*/
module.exports = function (data) {
const { statusPoints } = data;
const statusPointsSize = statusPoints.length * 5;
const packetLength = 1 + 1 + statusPointsSize;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 157);
view.setUint8(1, packetLength);
for (let i = 0, length = statusPoints.length; i < length; i++) {
const statusPoint = statusPoints[i];
view.setUint8(2 + i * 5, statusPoint.id);
view.setUint32(2 + i * 5 + 1, statusPoint.amount);
};
return buffer;
};
+23
View File
@@ -0,0 +1,23 @@
/*
@Packet name WorldMapGuildEntry
@Packet identifier 194
@Description -
@Data -
@Structure -
*/
module.exports = function (data) {
const packetLength = 2 + (data.bufferTag.byteLength + 1) + 1 + 1
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 194);
view.setUint8(1, packetLength);
view.setUint8(2, data.locationMapID);
view.setUint8(3, data.index);
view.setUint8(4, data.bufferTag.byteLength);
new Uint8Array(buffer, 5).set(data.bufferTag);
return buffer;
};
+55
View File
@@ -0,0 +1,55 @@
const cache = {};
const opcodesInterestedIn = {
// 200: true, // ammunition change
164: true, // item usage
163: true, // gets attacked
162: true, // authorless hp change
160: true, // design change
151: true, // map change state
148: true, // equipment change
131: true, // rewards
133: true, // entity disappears
134: true // entity appears
};
function packet(packetsToAdd, batched, id, metadataToAdd) {
if (!(packetsToAdd instanceof Array)) packetsToAdd = [packetsToAdd];
if (!cache[id]) cache[id] = new ArrayBuffer(1024, { maxByteLength: 65536 });
const playerBehaviourContext = global.actionContext.getElement(id);
const targetBuffer = cache[id];
const targetArray = new Uint8Array(targetBuffer);
let offset = batched.offset;
packetsToAdd.forEach((packet, i) => {
const newSize = offset + packet.byteLength;
if (newSize > targetBuffer.byteLength) {
const newBufferSize = Math.pow(2, Math.ceil(Math.log(newSize) / Math.log(2)));
targetBuffer.resize(newBufferSize);
};
const newArray = new Uint8Array(packet);
if (opcodesInterestedIn[newArray[0]]) {
const metadata = {
ts: new Date(),
pid: id,
metadata: metadataToAdd && metadataToAdd[i] ? metadataToAdd[i] : {}
};
playerBehaviourContext.add(metadata);
};
targetArray.set(newArray, offset);
offset += packet.byteLength;
});
return {
packet: targetBuffer,
offset
};
};
module.exports = packet;
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name confirmationPacket
@Packet identifier 255
@Description Confirms packets
@Data pId, confirmedpId
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
const { packetId, isSuccessful } = data;
view.setUint8(0, 255);
view.setUint8(1, packetLength);
view.setUint8(2, packetId);
view.setUint8(3, isSuccessful);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name shopCapReached
@Packet identifier 57
@Description Sends information about reached cap
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 57);
view.setUint8(1, packetLength);
view.setUint8(2, data.shopCategoryID);
view.setUint8(3, data.id);
return buffer;
};
+20
View File
@@ -0,0 +1,20 @@
/*
@Packet name irrelevantShopEntries
@Packet identifier 58
@Description Sends information about reached cap
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + 1 + data.length;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 58);
view.setUint8(1, packetLength);
data.forEach((id, i) => view.setUint8(2 + i, id));
return buffer;
};
+40
View File
@@ -0,0 +1,40 @@
/*
@Packet name -
@Packet identifier 61
@Description
@Data pId
@Structure -
*/
module.exports = {
init: startPosition => {
const packetLength = (10 * 16 + 10 * 4) + 3 + 1;
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 61);
view.setUint8(1, packetLength);
view.setUint16(2, startPosition);
let i = 0;
return {
update: d => {
const startIndex = i * (16 + 4);
const nameBuffer = Buffer.from(d.username);
for (const pair of nameBuffer.entries()) {
const index = pair[0];
view.setUint8(4 + startIndex + index, pair[1]);
};
view.setUint32(4 + startIndex + 16, d.amount);
i++;
},
get: () => {
return buffer;
}
};
}
};
+22
View File
@@ -0,0 +1,22 @@
/*
@Packet name leaderboardPosition
@Packet identifier 62
@Description
@Data pId
@Structure -
*/
module.exports = function (data) {
const packetLength = 1 + + 1 + 7 * (2 + 2);
const buffer = new ArrayBuffer(packetLength);
const view = new DataView(buffer);
view.setUint8(0, 62);
view.setUint8(1, packetLength);
for (let i = 0; i < 7; i++) {
view.setUint16(2 + i * 4, data[i].selfPosition);
view.setUint16(2 + i * 4 + 2, data[i].totalPositionsLength);
};
return buffer;
};
+65
View File
@@ -0,0 +1,65 @@
const ReadyMessage = require("../Messages/ReadyMessage");
const QuestMessage = require("../Messages/QuestMessage");
const SpyMessage = require("../Messages/SpyMessage");
const CauldronMessage = require("../Messages/CauldronMessage");
const MovementMessage = require("../Messages/MovementMessage");
const CloseMessage = require("../Messages/CloseMessage");
const RepairMessage = require("../Messages/RepairMessage");
const AttackStartMessage = require("../Messages/AttackStartMessage");
const AttackAbortMessage = require("../Messages/AttackAbortMessage");
const RespawnMessage = require("../Messages/RespawnMessage");
const EquipmentChangeMessage = require("../Messages/EquipmentChangeMessage");
const MapChangeMessage = require("../Messages/MapChangeMessage");
const AmmunitionChangeMessage = require("../Messages/AmmunitionChangeMessage");
const DesignChangeMessage = require("../Messages/DesignChangeMessage");
const ItemUseMessage = require("../Messages/ItemUseMessage");
const ItemBuyMessage = require("../Messages/ItemBuyMessage");
const LeaderboardPageMessage = require("../Messages/LeaderboardPageMessage");
const GuildMemberLeaveMessage = require("../Messages/GuildMemberLeaveMessage");
const GuildMemberJoinMessage = require("../Messages/GuildMemberJoinMessage");
const GuildJoinRequestSubmitMessage = require("../Messages/GuildJoinRequestSubmitMessage");
const GuildDataMessage = require("../Messages/GuildDataMessage");
const GuildDonateMessage = require("../Messages/GuildDonateMessage");
const GuildDetailsTaxEditMessage = require("../Messages/GuildDetailsTaxEditMessage");
const GuildDetailsIdentityEditMessage = require("../Messages/GuildDetailsIdentityEditMessage");
const GuildIslandTowerRepairMessage = require("../Messages/GuildIslandTowerRepairMessage");
const GuildIslandTowerBuildMessage = require("../Messages/GuildIslandTowerBuildMessage");
const TopicInterestedMessage = require("../Messages/TopicInterestedMessage");
const packetTable = {
1: { handler: ReadyMessage, expectedSize: 1, isAvailable: true },
2: { handler: QuestMessage, expectedSize: 3, isAvailable: true },
3: { handler: SpyMessage, expectedSize: 5, isAvailable: true },
4: { handler: CauldronMessage, expectedSize: 3, isAvailable: true },
5: { handler: MovementMessage, expectedSize: 5, isAvailable: true },
6: { handler: CloseMessage, expectedSize: 1, isAvailable: true },
7: { handler: RepairMessage, expectedSize: 1, isAvailable: true },
8: { handler: AttackStartMessage, expectedSize: 6, isAvailable: true },
9: { handler: AttackAbortMessage, expectedSize: 6, isAvailable: true },
10: { handler: RespawnMessage, expectedSize: 1, isAvailable: true },
11: { handler: EquipmentChangeMessage, expectedSize: 5, isAvailable: true },
12: { handler: MapChangeMessage, expectedSize: 1, isAvailable: true },
13: { handler: AmmunitionChangeMessage, expectedSize: 3, isAvailable: true },
14: { handler: DesignChangeMessage, expectedSize: 3, isAvailable: true },
15: { handler: ItemUseMessage, expectedSize: 7, isAvailable: true },
16: { handler: ItemBuyMessage, expectedSize: 7, isAvailable: true },
17: { handler: LeaderboardPageMessage, expectedSize: 4, isAvailable: true },
18: { handler: GuildMemberLeaveMessage, expectedSize: 5, isAvailable: true },
19: { handler: GuildMemberJoinMessage, expectedSize: 5, isAvailable: true },
20: { handler: GuildJoinRequestSubmitMessage, expectedSize: 0, isAvailable: true },
21: { handler: GuildDataMessage, expectedSize: 1, isAvailable: true },
22: { handler: GuildDonateMessage, expectedSize: 6, isAvailable: true },
23: { handler: GuildDetailsTaxEditMessage, expectedSize: 3, isAvailable: true },
24: { handler: GuildDetailsIdentityEditMessage, expectedSize: 0, isAvailable: true },
25: { handler: GuildIslandTowerRepairMessage, expectedSize: 6, isAvailable: true },
26: { handler: GuildIslandTowerBuildMessage, expectedSize: 7, isAvailable: true },
27: { handler: TopicInterestedMessage, expectedSize: 1, isAvailable: true }
};
module.exports = packetTable;
/*
handler: the function that runs when packet is received
expectedSize: size of the packet
isAvailable: whether the server accepts this packet
*/