mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-18 19:42:27 -05:00
1740124c47
* Improve CI setup: move lint out of per version * fix * Simplify go back to all per version. * refactor cycle test to use supported versions * fix cycle packet test * Add v to version to avoid 1.19 running every 1.19 minor. * Add quotes. * Use versions from js file in ci.yml * Fix ci.yml syntax. * Fix matrix read. * fix * fix * fix gitignore
53 lines
2 KiB
JavaScript
53 lines
2 KiB
JavaScript
/* eslint-env mocha */
|
|
// Tests packet serialization/deserialization from with raw binary from minecraft-packets
|
|
const { createSerializer, createDeserializer, states, supportedVersions } = require('minecraft-protocol')
|
|
const mcPackets = require('minecraft-packets')
|
|
const assert = require('assert')
|
|
|
|
const makeClientSerializer = version => createSerializer({ state: states.PLAY, version, isServer: true })
|
|
const makeClientDeserializer = version => createDeserializer({ state: states.PLAY, version })
|
|
|
|
for (const supportedVersion of supportedVersions) {
|
|
let serializer, deserializer, data
|
|
const mcData = require('minecraft-data')(supportedVersion)
|
|
const version = mcData.version
|
|
|
|
function convertBufferToObject (buffer) {
|
|
return deserializer.parsePacketBuffer(buffer)
|
|
}
|
|
|
|
function convertObjectToBuffer (object) {
|
|
return serializer.createPacketBuffer(object)
|
|
}
|
|
|
|
function testBuffer (buffer, [packetName, packetIx]) {
|
|
const parsed = convertBufferToObject(buffer).data
|
|
const parsedBuffer = convertObjectToBuffer(parsed)
|
|
const areEq = buffer.equals(parsedBuffer)
|
|
assert.strictEqual(areEq, true, `Error when testing ${+packetIx + 1} ${packetName} packet`)
|
|
}
|
|
describe(`Test cycle packet for version ${supportedVersion}v`, () => {
|
|
before(() => {
|
|
serializer = makeClientSerializer(version.minecraftVersion)
|
|
deserializer = makeClientDeserializer(version.minecraftVersion)
|
|
})
|
|
data = mcPackets.pc[version.minecraftVersion]
|
|
it('Has packet data', () => {
|
|
if (data === undefined) {
|
|
// many version do not have data, so print a log for now
|
|
// assert when most versions have packet data
|
|
console.log(`Version ${version.minecraftVersion} has no packet dump.`)
|
|
}
|
|
})
|
|
// server -> client
|
|
if (data !== undefined) {
|
|
Object.entries(data['from-server']).forEach(([packetName, packetData]) => {
|
|
it(`${packetName} packet`, () => {
|
|
for (const i in packetData) {
|
|
testBuffer(packetData[i].raw, [packetName, i])
|
|
}
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|