How to use the protodef.Parser function in protodef

To help you get started, we’ve selected a few protodef examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MephisTools / diablo2-protocol / lib / client / clientBnftpv2.js View on Github external
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')
      })
github MephisTools / diablo2-protocol / lib / client / clientBnftpv1.js View on Github external
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')
    })
  }
github MephisTools / diablo2-protocol / examples / sniffer / sniffer.js View on Github external
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)
  }
}
github MephisTools / diablo2-protocol / examples / sniffer / sniffer.js View on Github external
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)
  }
}
github MephisTools / diablo2-protocol / lib / client / clientBnftpv2.js View on Github external
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')
      })
    })
github ProtoDef-io / node-protodef / example.js View on Github external
'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))
})
github ProtoDef-io / node-protodef / examples / error_handling.js View on Github external
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)
})
github ProtoDef-io / node-protodef / examples / full_protocol.js View on Github external
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)
github MephisTools / diablo2-protocol / lib / client / clientD2gs.js View on Github external
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')
  }

protodef

A simple yet powerful way to define binary protocols

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis