Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/client/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CustomPayloadParseError extends Error {
constructor (message, cause, data) {
super(message)
this.name = 'CustomPayloadParseError'
this.cause = cause
this.data = data
this.message = `Custom channel: ${data.channel} - ${message}`
}
}

module.exports = {
CustomPayloadParseError
}
4 changes: 3 additions & 1 deletion src/client/pluginChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const ProtoDef = require('protodef').ProtoDef
const minecraft = require('../datatypes/minecraft')
const debug = require('debug')('minecraft-protocol')
const nbt = require('prismarine-nbt')
const { CustomPayloadParseError } = require('./errors')

module.exports = function (client, options) {
const mcdata = require('minecraft-data')(options.version || require('../version').defaultVersion)
Expand Down Expand Up @@ -57,7 +58,8 @@ module.exports = function (client, options) {
try {
packet.data = proto.parsePacketBuffer(channel, packet.data).data
} catch (error) {
client.emit('error', error)
const customError = new CustomPayloadParseError(error.message, error, packet)
client.emit('error', customError)
return
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Transform } from "readable-stream";
import { BinaryLike, KeyObject } from 'crypto';
import { Realm } from "prismarine-realms"
import NodeRSA from 'node-rsa';
import { CustomPayloadParseError } from './client/errors';

type PromiseLike = Promise<void> | void

Expand Down Expand Up @@ -41,7 +42,7 @@ declare module 'minecraft-protocol' {
verifyMessage(publicKey: Buffer | KeyObject, packet: object): boolean
reportPlayer(uuid: string, reason: 'FALSE_REPORTING' | 'HATE_SPEECH' | 'TERRORISM_OR_VIOLENT_EXTREMISM' | 'CHILD_SEXUAL_EXPLOITATION_OR_ABUSE' | 'IMMINENT_HARM' | 'NON_CONSENSUAL_INTIMATE_IMAGERY' | 'HARASSMENT_OR_BULLYING' | 'DEFAMATION_IMPERSONATION_FALSE_INFORMATION' | 'SELF_HARM_OR_SUICIDE' | 'ALCOHOL_TOBACCO_DRUGS', signatures: Buffer[], comment?: string): Promise<true>
chat(message: string, options?: { timestamp?: BigInt, salt?: BigInt, preview?: BinaryLike, didPreview?: boolean }): void
on(event: 'error', listener: (error: Error) => PromiseLike): this
on(event: 'error', listener: (error: Error | CustomPayloadParseError) => PromiseLike): this
on(event: 'packet', handler: (data: any, packetMeta: PacketMeta, buffer: Buffer, fullBuffer: Buffer) => PromiseLike): this
on(event: 'raw', handler: (buffer: Buffer, packetMeta: PacketMeta) => PromiseLike): this
on(event: 'session', handler: (session: SessionObject) => PromiseLike): this
Expand Down
Loading