Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
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)
d2gsProtocol
} = require('../../index')
const protoToServer = new ProtoDef(false)
protoToServer.addProtocol(sidProtocol, ['toServer'])
/*
console.log(protoToServer.parsePacketBuffer("packet",Buffer.from(`FF 50 33 00 00 00 00 00 36 38 58 49 50 58
32 44 0D 00 00 00 53 55 6E 65 C0 A8 01 23 C4 FF
FF FF 0C 04 00 00 09 04 00 00 46 52 41 00 46 72
61 6E 63 65 00`.replace(/[ \n\r\t]/g,""),"hex")));
*/
const bnftp = new ProtoDef(false)
bnftp.addProtocol(bnftpProtocol, ['toServer'])
/*
console.log(bnftp.parsePacketBuffer("FILE_TRANSFER_PROTOCOL",Buffer.from(`2f 00 00 01 36 38 58 49 56 44 32 44 00 00 00 00
00 00 00 00 00 00 00 00 00 31 ef 00 70 5f c7 01
76 65 72 2d 49 58 38 36 2d 31 2e 6d 70 71 00`.replace(/[ \n\r\t]/g,""),"hex")));
console.log(JSON.stringify(protoToServer.parsePacketBuffer("packet",Buffer.from(`ff 33 1e 00 04 00 00 80 00 00 00 00 62 6e 73 65
72 76 65 72 2d 44 32 44 56 2e 69 6e 69 00`.replace(/[ \n\r\t]/g,""),"hex")).data,null,2));
*/
/*
console.log(JSON.stringify(protoToServer.parsePacketBuffer("packet",Buffer.from(`ff 3a 29 00 3e 1e 16 01 d7 43 54 5a d1 bf c8 8a
8a 81 11 09 e0 0f b3 b0 98 be 47 1b 5f 5f 5e 54
74 00 00`.replace(/[ \n\r\t]/g,""),"hex")).data,null,2));
*/
const d2gs = new ProtoDef(false)
d2gs.addProtocol(d2gsProtocol, ['toServer'])
/*
console.log(JSON.stringify(d2gs.parsePacketBuffer("packet",Buffer.from(`68 A5 81 60 5A 01 00 01 0D 00 00 00 50 CC
5D ED B6 19 A5 91 00 55 72 75 6B 75 62 61 6C 00
12 05 4B 00 00 00 00`.replace(/[ \n\r\t]/g,""),"hex")).data,null,2));
*/
console.log(JSON.stringify(d2gs.parsePacketBuffer('packet', Buffer.from(` 68 a1 f3 68 5a 0f 00 01 0d 00 00 00 50 cc 5d ed
b6 19 a5 91 00 55 72 75 6b 75 62 61 6c 00 af 6f
4b 00 00 00 00`.replace(/[ \n\r\t]/g, ''), 'hex')).data, null, 2))
const mcp = new ProtoDef(false)
mcp.addProtocol(mcpProtocol, ['toServer'])
/*
console.log(JSON.stringify(mcp.parsePacketBuffer("packet",Buffer.from(`ff0f870004000000000000001000000
0000000000df0adba0df0adba5461726b686e617262
2a5461726b686e61726200596f757220667269656e64205461726b686e617262
2068617320656e7465726564206120446961626c6f204949
`.replace(/[ \n\r\t]/g,""),"hex")).data,null,2));
*/
const ProtoDef = require('protodef').ProtoDef
const {
mcpProtocol,
sidProtocol,
bnftpProtocol,
d2gsProtocol
} = require('../../index')
const protoToServer = new ProtoDef(false)
protoToServer.addProtocol(sidProtocol, ['toServer'])
/*
console.log(protoToServer.parsePacketBuffer("packet",Buffer.from(`FF 50 33 00 00 00 00 00 36 38 58 49 50 58
32 44 0D 00 00 00 53 55 6E 65 C0 A8 01 23 C4 FF
FF FF 0C 04 00 00 09 04 00 00 46 52 41 00 46 72
61 6E 63 65 00`.replace(/[ \n\r\t]/g,""),"hex")));
*/
const bnftp = new ProtoDef(false)
bnftp.addProtocol(bnftpProtocol, ['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)
d2gsToClient.addTypes(bitfieldLE)
d2gsToClient.addProtocol(protocol['1.13'].d2gs, ['toClient'])
const d2gsToServer = new ProtoDef(false)
d2gsToServer.addProtocol(protocol[version].d2gs, ['toServer'])
const toClientParser = new FullPacketParser(d2gsToClient, 'packet')
const splitter = createSplitter()
splitter.sloppyMode = true
let messagesToClient = []
let messagesToServer = []
splitter.on('data', data => {
const uncompressedData = decompress(data)
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)
d2gsToClient.addTypes(bitfieldLE)
d2gsToClient.addProtocol(protocol['1.13'].d2gs, ['toClient'])
const d2gsToServer = new ProtoDef(false)
d2gsToServer.addProtocol(protocol[version].d2gs, ['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)
d2gsToClient.addTypes(bitfieldLE)
d2gsToClient.addProtocol(protocol['1.13'].d2gs, ['toClient'])
const d2gsToServer = new ProtoDef(false)
d2gsToServer.addProtocol(protocol[version].d2gs, ['toServer'])
const toClientParser = new FullPacketParser(d2gsToClient, 'packet')
const splitter = createSplitter()
splitter.sloppyMode = true
let messagesToClient = []
let messagesToServer = []
splitter.on('data', data => {
const uncompressedData = decompress(data)
toClientParser.write(uncompressedData)
})
toClientParser.on('data', ({ data, buffer }) => {
try {
function createProtocol (state, direction, version, customPackets) {
const key = state + ';' + direction + ';' + version
if (protocols[key]) { return protocols[key] }
const proto = new ProtoDef(false)
proto.addTypes(minecraft)
const mcData = require('minecraft-data')(version)
proto.addProtocol(merge(mcData.protocol, get(customPackets, [mcData.version.majorVersion])), [state, direction])
protocols[key] = proto
return proto
}
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)
d2gsToClient.addTypes(bitfieldLE)
d2gsToClient.addProtocol(protocol['1.13'].d2gs, ['toClient'])