From 88091ecaf1c0b8646659b9fe6cadf660e84ce2e9 Mon Sep 17 00:00:00 2001 From: DryByte <93609026+DryByte@users.noreply.github.com> Date: Sun, 12 Mar 2023 08:31:59 -0300 Subject: [PATCH] Document all packets --- src/extraPackets/VersionGet.js | 9 +++++++++ src/extraPackets/VersionHandshakeInit.js | 14 +++++++++++++ src/extraPackets/VersionHandshakeRes.js | 5 +++++ src/extraPackets/VersionSend.js | 18 +++++++++++++++++ src/packets/BlockAction.js | 3 +-- src/packets/BlockLine.js | 3 +-- src/packets/ChangeTeam.js | 14 +++++++++++++ src/packets/ChangeWeapon.js | 14 +++++++++++++ src/packets/ChatMessage.js | 15 ++++++++++++++ src/packets/CreatePlayer.js | 19 ++++++++++++++++++ src/packets/ExistingPlayer.js | 21 ++++++++++++++++++++ src/packets/InputData.js | 22 +++++++++++++++++++++ src/packets/IntelCapture.js | 14 +++++++++++++ src/packets/IntelDrop.js | 16 +++++++++++++++ src/packets/IntelPickup.js | 13 ++++++++++++ src/packets/KillAction.js | 16 +++++++++++++++ src/packets/MapChunk.js | 13 ++++++++++++ src/packets/MapStart.js | 13 ++++++++++++ src/packets/OrientationData.js | 15 ++++++++++++++ src/packets/PlayerLeft.js | 13 ++++++++++++ src/packets/PositionData.js | 15 ++++++++++++++ src/packets/SetColor.js | 16 +++++++++++++++ src/packets/SetTool.js | 14 +++++++++++++ src/packets/StateData.js | 25 ++++++++++++++++++++++++ src/packets/WeaponInput.js | 19 ++++++++++++++++++ src/packets/WeaponReload.js | 15 ++++++++++++++ src/packets/WorldUpdate.js | 13 ++++++++++++ 27 files changed, 383 insertions(+), 4 deletions(-) diff --git a/src/extraPackets/VersionGet.js b/src/extraPackets/VersionGet.js index 4836280..4f7f899 100644 --- a/src/extraPackets/VersionGet.js +++ b/src/extraPackets/VersionGet.js @@ -1,9 +1,18 @@ const BasePacket = require("../packets/BasePacket.js"); +/** + * Tells the client to send version info + * @category Ext Packets + * @extends {BasePacket} + */ class VersionGet extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 33; this.fields = {}; diff --git a/src/extraPackets/VersionHandshakeInit.js b/src/extraPackets/VersionHandshakeInit.js index 71cf55b..435a888 100644 --- a/src/extraPackets/VersionHandshakeInit.js +++ b/src/extraPackets/VersionHandshakeInit.js @@ -1,11 +1,25 @@ const BasePacket = require("../packets/BasePacket.js"); const { LEIntType } = require("../types"); +/** + * Server starts handshake for version info + * @category Ext Packets + * @extends {BasePacket} + */ class VersionHandshakeInit extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 31; + + /** + * Fields Object + * @property {LEIntType} challenge Number sent to validate handshake + */ this.fields = { challenge: new LEIntType(), }; diff --git a/src/extraPackets/VersionHandshakeRes.js b/src/extraPackets/VersionHandshakeRes.js index 3f3dd3d..815e579 100644 --- a/src/extraPackets/VersionHandshakeRes.js +++ b/src/extraPackets/VersionHandshakeRes.js @@ -1,6 +1,11 @@ const BasePacket = require("../packets/BasePacket.js"); const { LEIntType } = require("../types"); +/** + * Response for a VersionHandshakeInit + * @category Ext Packets + * @extends {BasePacket} + */ class VersionHandshakeRes extends BasePacket { constructor(packet) { super(); diff --git a/src/extraPackets/VersionSend.js b/src/extraPackets/VersionSend.js index 2023378..11c0e22 100644 --- a/src/extraPackets/VersionSend.js +++ b/src/extraPackets/VersionSend.js @@ -1,11 +1,29 @@ const BasePacket = require("../packets/BasePacket.js"); const { ByteType, StringType } = require("../types"); +/** + * Send version infos + * @category Ext Packets + * @extends {BasePacket} + */ class VersionSend extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 34; + + /** + * Fields Object + * @property {ByteType} client_identifier ASCII Client Identifier + * @property {ByteType} version_major Major Version + * @property {ByteType} version_minor Minor Version + * @property {ByteType} version_revision Revision Version + * @property {StringType} os Operational System Infos + */ this.fields = { client_identifier: new ByteType(), version_major: new ByteType(), diff --git a/src/packets/BlockAction.js b/src/packets/BlockAction.js index 4cac303..2b6c6ee 100644 --- a/src/packets/BlockAction.js +++ b/src/packets/BlockAction.js @@ -2,9 +2,8 @@ const BasePacket = require("./BasePacket.js"); const { UByteType, LEIntType } = require("../types"); /** - * Block Action Packet * @category Packets - * @extends BasePacket + * @extends {BasePacket} */ class BlockAction extends BasePacket { constructor(packet) { diff --git a/src/packets/BlockLine.js b/src/packets/BlockLine.js index 2f8c9f8..9689859 100644 --- a/src/packets/BlockLine.js +++ b/src/packets/BlockLine.js @@ -2,9 +2,8 @@ const BasePacket = require("./BasePacket.js"); const { UByteType, LEIntType } = require("../types"); /** - * Block Line Packet * @category Packets - * @extends BasePacket + * @extends {BasePacket} */ class BlockLine extends BasePacket { constructor(packet) { diff --git a/src/packets/ChangeTeam.js b/src/packets/ChangeTeam.js index 932acb7..9bf1348 100644 --- a/src/packets/ChangeTeam.js +++ b/src/packets/ChangeTeam.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType, ByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class ChangeTeam extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 29; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {ByteType} team_id Team ID to change + */ this.fields = { player_id: new UByteType(), team_id: new ByteType(), diff --git a/src/packets/ChangeWeapon.js b/src/packets/ChangeWeapon.js index 2387cdf..93121bb 100644 --- a/src/packets/ChangeWeapon.js +++ b/src/packets/ChangeWeapon.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class ChangeWeapon extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 30; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} weapon_id Weapon ID to change + */ this.fields = { player_id: new UByteType(), weapon_id: new UByteType(), diff --git a/src/packets/ChatMessage.js b/src/packets/ChatMessage.js index eee30bc..756a3df 100644 --- a/src/packets/ChatMessage.js +++ b/src/packets/ChatMessage.js @@ -1,11 +1,26 @@ const BasePacket = require("./BasePacket.js"); const { UByteType, StringType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class ChatMessage extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 17; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} chat_type Chat Type to send the message + * @property {StringType} chat_message Chat Message to send + */ this.fields = { player_id: new UByteType(), chat_type: new UByteType(), diff --git a/src/packets/CreatePlayer.js b/src/packets/CreatePlayer.js index 52d7d85..cff3fde 100644 --- a/src/packets/CreatePlayer.js +++ b/src/packets/CreatePlayer.js @@ -2,11 +2,30 @@ const BasePacket = require("./BasePacket.js"); const Player = require("../game/Player.js"); const { ByteType, UByteType, LEFloatType, StringType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class CreatePlayer extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 12; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} weapon Weapon id + * @property {ByteType} team Team id + * @property {LEFloatType} x Spawn X coordinate + * @property {LEFloatType} y Spawn Y coordinate + * @property {LEFloatType} z Spawn Z coordinate + * @property {StringType} name Player's name + */ this.fields = { player_id: new UByteType(), weapon: new UByteType(), diff --git a/src/packets/ExistingPlayer.js b/src/packets/ExistingPlayer.js index bb5c734..9e77ee2 100644 --- a/src/packets/ExistingPlayer.js +++ b/src/packets/ExistingPlayer.js @@ -2,11 +2,32 @@ const BasePacket = require("./BasePacket.js"); const Player = require("../game/Player.js"); const { ByteType, UByteType, StringType, UInt32Type } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class ExistingPlayer extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 9; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {ByteType} team Team id + * @property {UByteType} weapon Weapon id + * @property {UByteType} held_item Which tool player is holding + * @property {UInt32Type} kills Kill count + * @property {UByteType} block_blue Player's block blue color + * @property {UByteType} block_green Player's block green color + * @property {UByteType} block_red Player's block red color + * @property {StringType} name Player's name + */ this.fields = { player_id: new UByteType(), team: new ByteType(), diff --git a/src/packets/InputData.js b/src/packets/InputData.js index 7e27c42..4e58b17 100644 --- a/src/packets/InputData.js +++ b/src/packets/InputData.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class InputData extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 3; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} key_states A byte that each bit is a key state + */ this.fields = { player_id: new UByteType(), key_states: new UByteType() @@ -19,6 +33,10 @@ class InputData extends BasePacket { game.players[this.getValue("player_id")].inputs = this.getKeyStates(); } + /** + * Set key states field using object + * @param {WalkInputs} KeyStates Object with key states. + */ setKeyStates(state_obj) { let bits = 0; let current_state = 0; @@ -31,6 +49,10 @@ class InputData extends BasePacket { this.fields.key_states.value = bits; } + /** + * Get the an object with the key_states fields + * @returns {WalkInputs} + */ getKeyStates() { let r_obj = {up: false, down: false, left: false, right: false, jump: false, crouch: false, sneak: false, sprint: false}; let current_state = 0; diff --git a/src/packets/IntelCapture.js b/src/packets/IntelCapture.js index 510889d..a4dcdf9 100644 --- a/src/packets/IntelCapture.js +++ b/src/packets/IntelCapture.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class IntelCapture extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 23; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} winning Boolean if thats the winning intel + */ this.fields = { player_id: new UByteType(), winning: new UByteType(), diff --git a/src/packets/IntelDrop.js b/src/packets/IntelDrop.js index e977685..5185b9c 100644 --- a/src/packets/IntelDrop.js +++ b/src/packets/IntelDrop.js @@ -1,11 +1,27 @@ const BasePacket = require("./BasePacket.js"); const { UByteType, LEFloatType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class IntelDrop extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 25; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {LEFloatType} x Drop X coordinate + * @property {LEFloatType} y Drop Y coordinate + * @property {LEFloatType} z Drop Z coordinate + */ this.fields = { player_id: new UByteType(), x: new LEFloatType(), diff --git a/src/packets/IntelPickup.js b/src/packets/IntelPickup.js index 67f4f42..522ab07 100644 --- a/src/packets/IntelPickup.js +++ b/src/packets/IntelPickup.js @@ -1,11 +1,24 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class IntelPickup extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 24; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + */ this.fields = { player_id: new UByteType() }; diff --git a/src/packets/KillAction.js b/src/packets/KillAction.js index 74586b9..186a83a 100644 --- a/src/packets/KillAction.js +++ b/src/packets/KillAction.js @@ -1,11 +1,27 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class KillAction extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 16; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} killer_id Killer player's id + * @property {UByteType} kill_type Kill type + * @property {UByteType} respawn_time Time until respawn + */ this.fields = { player_id: new UByteType(), killer_id: new UByteType(), diff --git a/src/packets/MapChunk.js b/src/packets/MapChunk.js index bf24110..1269f79 100644 --- a/src/packets/MapChunk.js +++ b/src/packets/MapChunk.js @@ -1,10 +1,23 @@ const BasePacket = require("./BasePacket.js"); +/** + * @category Packets + * @extends {BasePacket} + */ class MapChunk extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 19; + + /** + * Fields Object + * @property {Buffer} map_data Buffer with chunk data + */ this.fields = { map_data: packet }; diff --git a/src/packets/MapStart.js b/src/packets/MapStart.js index 46d1c47..cf2a1d1 100644 --- a/src/packets/MapStart.js +++ b/src/packets/MapStart.js @@ -2,11 +2,24 @@ const BasePacket = require("./BasePacket.js"); const VXL = require("../vxl/VXL.js"); const { UInt32Type } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class MapStart extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 18; + + /** + * Fields Object + * @property {UInt32Type} map_size The map size + */ this.fields = { map_size: new UInt32Type() }; diff --git a/src/packets/OrientationData.js b/src/packets/OrientationData.js index 91e825b..5c2b202 100644 --- a/src/packets/OrientationData.js +++ b/src/packets/OrientationData.js @@ -1,11 +1,26 @@ const BasePacket = require("./BasePacket.js"); const { LEFloatType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class OrientationData extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 1; + + /** + * Fields Object + * @property {LEFloatType} x Orientation X + * @property {LEFloatType} y Orientation Y + * @property {LEFloatType} z Orientation Z + */ this.fields = { x: new LEFloatType(), y: new LEFloatType(), diff --git a/src/packets/PlayerLeft.js b/src/packets/PlayerLeft.js index 09a7c01..d0d9c93 100644 --- a/src/packets/PlayerLeft.js +++ b/src/packets/PlayerLeft.js @@ -1,11 +1,24 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class PlayerLeft extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 20; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + */ this.fields = { player_id: new UByteType() }; diff --git a/src/packets/PositionData.js b/src/packets/PositionData.js index 8c2a252..7c14637 100644 --- a/src/packets/PositionData.js +++ b/src/packets/PositionData.js @@ -1,11 +1,26 @@ const BasePacket = require("./BasePacket.js"); const { LEFloatType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class PositionData extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 0; + + /** + * Fields Object + * @property {LEFloatType} x X coordinate + * @property {LEFloatType} y Y coordinate + * @property {LEFloatType} z Z coordinate + */ this.fields = { x: new LEFloatType(), y: new LEFloatType(), diff --git a/src/packets/SetColor.js b/src/packets/SetColor.js index 3c5fd3a..40af144 100644 --- a/src/packets/SetColor.js +++ b/src/packets/SetColor.js @@ -1,11 +1,27 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class SetColor extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 8; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} blue Block blue color + * @property {UByteType} green Block green color + * @property {UByteType} red Block red color + */ this.fields = { player_id: new UByteType(), blue: new UByteType(), diff --git a/src/packets/SetTool.js b/src/packets/SetTool.js index 2cf66ef..4065e09 100644 --- a/src/packets/SetTool.js +++ b/src/packets/SetTool.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class SetTool extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 7; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} tool Tool id + */ this.fields = { player_id: new UByteType(), tool: new UByteType(), diff --git a/src/packets/StateData.js b/src/packets/StateData.js index 8cd5df1..7126ca1 100644 --- a/src/packets/StateData.js +++ b/src/packets/StateData.js @@ -3,11 +3,36 @@ const { mergeObj } = require("../utils.js"); const { UByteType, StringType, LEFloatType } = require("../types"); const Player = require("../game/Player.js"); +/** + * @category Packets + * @extends {BasePacket} + */ class StateData extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 15; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} fog_blue Fog blue color + * @property {UByteType} fog_green Fog green color + * @property {UByteType} fog_red Fog red color + * @property {UByteType} team_1_blue Team 1 blue color + * @property {UByteType} team_1_green Team 1 green color + * @property {UByteType} team_1_red Team 1 red color + * @property {UByteType} team_2_blue Team 2 blue color + * @property {UByteType} team_2_green Team 2 green color + * @property {UByteType} team_2_red Team 2 red color + * @property {StringType} team_1_name Team 1 name with max length of 10 + * @property {StringType} team_2_name Team 2 name with max length of 10 + * @property {UByteType} gamemode_id Gamemode id, 0 for ctf and 1 for tc + */ this.fields = { player_id: new UByteType(), diff --git a/src/packets/WeaponInput.js b/src/packets/WeaponInput.js index ca7eb47..8f0d9dd 100644 --- a/src/packets/WeaponInput.js +++ b/src/packets/WeaponInput.js @@ -1,11 +1,25 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class WeaponInput extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 4; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} weapon_input The lowest bit represents the primary fire, the second lowest represents the secondary fire. + */ this.fields = { player_id: new UByteType(), weapon_input: new UByteType() @@ -20,6 +34,11 @@ class WeaponInput extends BasePacket { player.firing = this.getValue("weapon_input")&1; } + /** + * Enable/disable weapon inputs + * @param {boolean} Primary Primary fire + * @param {boolean} Secondary Secondary fire + */ setWeaponInput(primary, secondary){ this.setValue("weapon_input", primary | (secondary<<1)); } diff --git a/src/packets/WeaponReload.js b/src/packets/WeaponReload.js index 59ea306..3de20e1 100644 --- a/src/packets/WeaponReload.js +++ b/src/packets/WeaponReload.js @@ -1,11 +1,26 @@ const BasePacket = require("./BasePacket.js"); const { UByteType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class WeaponReload extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 28; + + /** + * Fields Object + * @property {UByteType} player_id Player's id + * @property {UByteType} clip AMMO in clip + * @property {UByteType} reserve AMMO in reserve + */ this.fields = { player_id: new UByteType(), clip: new UByteType(), diff --git a/src/packets/WorldUpdate.js b/src/packets/WorldUpdate.js index 9bb7aee..f0dfbd3 100644 --- a/src/packets/WorldUpdate.js +++ b/src/packets/WorldUpdate.js @@ -1,11 +1,24 @@ const BasePacket = require("./BasePacket.js"); const { LEFloatType } = require("../types"); +/** + * @category Packets + * @extends {BasePacket} + */ class WorldUpdate extends BasePacket { constructor(packet) { super(); + /** + * Packet Id + * @type Integer + */ this.id = 2; + + /** + * Fields Object + * @see {@link https://github.com/DryByte/AoS.js/blob/main/src/packets/WorldUpdate.js|Check for more information} + */ this.fields = {}; for (let i = 0; i < Math.floor(packet.length/(6*4)); i++) { this.fields[`player_${i}_pos_x`] = new LEFloatType();