Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setSocket (socket) {
this.socket = socket
this.socket.on('data', (data) => {
// console.log('received that hex bnftp', data.toString('hex'))
})
const proto = this.isServer ? bnftpToClient : bnftpToServer
const parser = new Parser(proto, 'FILE_TRANSFER_PROTOCOL')
parser.on('data', (parsed) => {
this.emit('FILE_TRANSFER_PROTOCOL', parsed)
console.info('received packet FILE_TRANSFER_PROTOCOL', JSON.stringify(parsed))
this.socket.unpipe(parser)
const challengeParser = new Parser(proto, 'CHALLENGE')
challengeParser.on('data', (parsed) => {
this.emit('CHALLENGE', parsed)
console.info('received packet CHALLENGE', JSON.stringify(parsed))
})
challengeParser.on('error', err => console.log('CHALLENGE bnftp error : ', err.message))
this.socket.pipe(challengeParser)
this.socket.on('end', () => {
console.log('disconnected from server bnftp')
})
setSocket (socket) {
this.socket = socket
this.socket.on('data', (data) => {
// console.log('received that hex bnftp', data.toString('hex'))
})
const proto = this.isServer ? bnftpToClient : bnftpToServer
const parser = new Parser(proto, 'FILE_TRANSFER_PROTOCOL')
parser.on('data', (parsed) => {
this.emit('FILE_TRANSFER_PROTOCOL', parsed)
// console.info('received packet FILE_TRANSFER_PROTOCOL', JSON.stringify(parsed.data))
})
parser.on('error', err => console.log('bnftp error : ', err.message))
this.socket.pipe(parser)
this.socket.on('end', () => {
console.log('disconnected from server bnftp')
})
}
try {
protocolParserClient.write('FILE_TRANSFER_PROTOCOL')
// console.log('bnftpToClient protocol: ', JSON.stringify(bnftpToClient.parsePacketBuffer('FILE_TRANSFER_PROTOCOL', data).data))
} catch (error) {
console.log('bnftpToClient error: ', error)
console.log('bnftpToClient protocol: ', data)
// challengeParserClient.write(data)
}
}
const challengeParserServer = new Parser(bnftpToServer, 'CHALLENGE')
challengeParserServer.on('error', err => console.log('bnftpToServer bnftp error : ', err.message))
challengeParserServer.on('data', (parsed) => {
console.info('bnftpToServer challenge : ', JSON.stringify(parsed))
})
const protocolParserServer = new Parser(bnftpToServer, 'FILE_TRANSFER_PROTOCOL')
protocolParserServer.on('error', err => console.log('bnftpToServer bnftp error : ', err.message))
protocolParserServer.on('data', (parsed) => {
console.info('bnftpToServer protocol : ', JSON.stringify(parsed))
})
function displayBnftpToServer (data) {
try {
protocolParserServer.write('FILE_TRANSFER_PROTOCOL')
// console.log('bnftpToServer protocol: ', JSON.stringify(bnftpToServer.parsePacketBuffer('FILE_TRANSFER_PROTOCOL', data).data))
// console.log('bnftpToServer protocol: ', data)
} catch (error) {
console.log('bnftpToServer error: ', error)
console.log('bnftpToServer write challenge', data)
// challengeParserServer.write(data)
}
}
const parsed = displayParsed(sidToClient, 'sidToClient', data)
if (parsed.name === 'SID_LOGONREALMEX') {
const IP = parsed.params.IP
mcpIp = IP[0] + '.' + IP[1] + '.' + IP[2] + '.' + IP[3]
mcpPort = parsed.params.port + ''
console.log(`received SID_LOGONREALMEX ${JSON.stringify({ mcpIp, mcpPort })}`)
}
}
const challengeParserClient = new Parser(bnftpToClient, 'CHALLENGE')
challengeParserClient.on('error', err => console.log('bnftpToClient challenge error : ', err.message))
challengeParserClient.on('data', (parsed) => {
console.info('bnftpToClient challenge : ', JSON.stringify(parsed))
})
const protocolParserClient = new Parser(bnftpToClient, 'FILE_TRANSFER_PROTOCOL')
protocolParserClient.on('error', err => console.log('bnftpToClient protocol error : ', err.message))
protocolParserClient.on('data', (parsed) => {
console.info('bnftpToClient protocol : ', JSON.stringify(parsed))
})
function displayBnftpToClient (data) {
try {
protocolParserClient.write('FILE_TRANSFER_PROTOCOL')
// console.log('bnftpToClient protocol: ', JSON.stringify(bnftpToClient.parsePacketBuffer('FILE_TRANSFER_PROTOCOL', data).data))
} catch (error) {
console.log('bnftpToClient error: ', error)
console.log('bnftpToClient protocol: ', data)
// challengeParserClient.write(data)
}
}
parser.on('data', (parsed) => {
this.emit('FILE_TRANSFER_PROTOCOL', parsed)
console.info('received packet FILE_TRANSFER_PROTOCOL', JSON.stringify(parsed))
this.socket.unpipe(parser)
const challengeParser = new Parser(proto, 'CHALLENGE')
challengeParser.on('data', (parsed) => {
this.emit('CHALLENGE', parsed)
console.info('received packet CHALLENGE', JSON.stringify(parsed))
})
challengeParser.on('error', err => console.log('CHALLENGE bnftp error : ', err.message))
this.socket.pipe(challengeParser)
this.socket.on('end', () => {
console.log('disconnected from server bnftp')
})
})
'switch',
{
'compareTo': 'name',
'fields': {
'entity_look': 'entity_look'
}
}
]
}
]
]
}
const proto = new ProtoDef()
proto.addTypes(exampleProtocol)
const parser = new Parser(proto, 'packet')
const serializer = new Serializer(proto, 'packet')
serializer.write({
name: 'entity_look',
params: {
'entityId': 1,
'yaw': 1,
'pitch': 1,
'onGround': true
}
})
serializer.pipe(parser)
parser.on('data', function (chunk) {
console.log(JSON.stringify(chunk, null, 2))
})
const ProtoDef = require('protodef').ProtoDef
const Serializer = require('protodef').Serializer
const Parser = require('protodef').Parser
const exampleProtocol = require('./example_protocol.json')
const proto = new ProtoDef()
proto.addTypes(exampleProtocol)
const parser = new Parser(proto, 'packet')
const serializer = new Serializer(proto, 'packet')
serializer.write({
name: 'entity_look',
params: {
'entityId': 1,
'yaw': 1,
'pitch': 1,
'onGround': true
}
})
parser.on('error', function (err) {
console.log(err.stack)
console.log(err.buffer)
})
const ProtoDef = require('protodef').ProtoDef
const Serializer = require('protodef').Serializer
const Parser = require('protodef').Parser
const exampleProtocol = require('./full_protocol_example.json')
const proto = new ProtoDef()
proto.addProtocol(exampleProtocol, ['login', 'toClient'])
const parser = new Parser(proto, 'packet')
const serializer = new Serializer(proto, 'packet')
serializer.write({
name: 'success',
params: {
'uuid': 'some uuid',
'username': 'some name'
}
})
parser.on('error', function (err) {
console.log(err.stack)
console.log(err.buffer)
})
serializer.pipe(parser)
constructor (version, isServer = false) {
super()
this.compression = false
this.isServer = isServer
const protocol = require(`../../data/${version}/d2gs`)
this.protoToServer = new ProtoDef(false)
this.protoToServer.addTypes(d2gsReader)
this.protoToServer.addTypes(bitfieldLE)
this.protoToServer.addProtocol(protocol, ['toServer'])
this.protoToClient = new ProtoDef(false)
this.protoToClient.addTypes(d2gsReader)
this.protoToClient.addTypes(bitfieldLE)
this.protoToClient.addProtocol(protocol, ['toClient'])
this.toClientParser = new FullPacketParser(this.protoToClient, 'packet')
}