How to use protodef - 10 common examples

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 deathcap / wsmc / wsmc.js View on Github external
'use strict';

var mcversion = require('./mcversion.js');
var minecraft_protocol = require('minecraft-protocol/src');
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
var minecraft_data = require('minecraft-data')(mcversion);
var protodef = require('protodef');
var readVarInt = protodef.types.varint[0];
var writeVarInt = protodef.types.varint[1];
var sizeOfVarInt = protodef.types.varint[2];
var hex = require('hex');
var WebSocketServer = (require('ws')).Server;
var websocket_stream = require('websocket-stream');
var argv = (require('optimist'))
  .default('wshost', '')
  .default('wsport', 24444)
  .default('mchost', 'localhost')
  .default('mcport', 25565)
  .default('prefix', 'webuser-')
  .argv;

var PACKET_DEBUG = process.env.NODE_DEBUG && /wsmc/.test(process.env.NODE_DEBUG);
var FIXED_MC_VERSION = false; // either a version string, or false to auto-detect

console.log('WS('+argv.wshost+':'+argv.wsport+') <--> MC('+argv.mchost+':'+argv.mcport+')');
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 deathcap / wsmc / wsmc.js View on Github external
'use strict';

var mcversion = require('./mcversion.js');
var minecraft_protocol = require('minecraft-protocol/src');
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
var minecraft_data = require('minecraft-data')(mcversion);
var protodef = require('protodef');
var readVarInt = protodef.types.varint[0];
var writeVarInt = protodef.types.varint[1];
var sizeOfVarInt = protodef.types.varint[2];
var hex = require('hex');
var WebSocketServer = (require('ws')).Server;
var websocket_stream = require('websocket-stream');
var argv = (require('optimist'))
  .default('wshost', '')
  .default('wsport', 24444)
  .default('mchost', 'localhost')
  .default('mcport', 25565)
  .default('prefix', 'webuser-')
  .argv;

var PACKET_DEBUG = process.env.NODE_DEBUG && /wsmc/.test(process.env.NODE_DEBUG);
var FIXED_MC_VERSION = false; // either a version string, or false to auto-detect
github MephisTools / diablo2-protocol / examples / sniffer / sniffer.js View on Github external
const ProtoDef = require('protodef').ProtoDef

const express = require('express')
const app = express()
// app.use(express.static(`${__dirname}/public`))

const {
  protocol,
  createSplitter,
  decompress,
  d2gsReader,
  itemParser,
  bitfieldLE
} = require('../..')

const mcpToServer = new ProtoDef(false)
mcpToServer.addProtocol(protocol[version].mcp, ['toServer'])

const mcpToClient = new ProtoDef(false)
mcpToClient.addProtocol(protocol[version].mcp, ['toClient'])

const sidToServer = new ProtoDef(false)
sidToServer.addProtocol(protocol[version].sid, ['toServer'])

const sidToClient = new ProtoDef(false)
sidToClient.addProtocol(protocol[version].sid, ['toClient'])

const bnftpToServer = new ProtoDef(false)
bnftpToServer.addProtocol(protocol[version].bnftp, ['toServer'])

const bnftpToClient = new ProtoDef(false)
bnftpToClient.addProtocol(protocol['1.13'].bnftp, ['toClient'])
github MephisTools / diablo2-protocol / examples / sniffer / sniffer.js View on Github external
const app = express()
// app.use(express.static(`${__dirname}/public`))

const {
  protocol,
  createSplitter,
  decompress,
  d2gsReader,
  itemParser,
  bitfieldLE
} = require('../..')

const mcpToServer = new ProtoDef(false)
mcpToServer.addProtocol(protocol[version].mcp, ['toServer'])

const mcpToClient = new ProtoDef(false)
mcpToClient.addProtocol(protocol[version].mcp, ['toClient'])

const sidToServer = new ProtoDef(false)
sidToServer.addProtocol(protocol[version].sid, ['toServer'])

const sidToClient = new ProtoDef(false)
sidToClient.addProtocol(protocol[version].sid, ['toClient'])

const bnftpToServer = new ProtoDef(false)
bnftpToServer.addProtocol(protocol[version].bnftp, ['toServer'])

const bnftpToClient = new ProtoDef(false)
bnftpToClient.addProtocol(protocol['1.13'].bnftp, ['toClient'])

const d2gsToClient = new ProtoDef(false)
d2gsToClient.addTypes(d2gsReader)
github ProtoDef-io / node-protodef / test / benchmark.js View on Github external
it("bench serializing",function(done){
    var start, i, j;
    console.log('Beginning write test');
    var serializer = new Serializer(proto, "packet");
    start = Date.now();
    for(i = 0; i < ITERATIONS; i++) {
      for(j = 0; j < testDataWrite.length; j++) {
        serializer.write(testDataWrite[j]);
      }
    }
    function wait(cb) {
      var i=0;
      serializer.on("data",function(data){
        inputData.push(data);
        i++;
        if(i==size)
          cb();
      });
    }
    wait(function(){
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')
      })
    })

protodef

A simple yet powerful way to define binary protocols

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis