mirror of
https://github.com/djhackersdev/minime.git
synced 2026-08-28 05:24:04 -05:00
Eliminate Framer
This commit is contained in:
@@ -58,21 +58,36 @@ class Encoder extends Transform {
|
||||
})
|
||||
}
|
||||
|
||||
static init(length) {
|
||||
const buf = Buffer.alloc(length)
|
||||
|
||||
buf.writeUInt16LE(0xA13E, 0x0000) // Magic?
|
||||
buf.writeUInt16LE(0x3087, 0x0002) // ???
|
||||
buf.writeUInt16LE(length, 0x0006)
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
console.log('Aimedb: Encode', chunk)
|
||||
|
||||
let payload
|
||||
let buf
|
||||
|
||||
switch (chunk.cmd) {
|
||||
case 'hello':
|
||||
payload = Buffer.alloc(24)
|
||||
payload.writeInt16LE(chunk.status)
|
||||
buf = Encoder.init(32)
|
||||
buf.writeInt16LE(0x0065, 0x0004) // cmd code
|
||||
buf.writeInt16LE(chunk.status, 0x0008)
|
||||
|
||||
return callback(null, { cmd: 0x0065, payload })
|
||||
break
|
||||
|
||||
default:
|
||||
return callback(newError(`Unimplemented response: ${cmd}`))
|
||||
}
|
||||
|
||||
console.log('Aimedb: Send', buf)
|
||||
|
||||
return callback(null, buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,35 +39,6 @@ class Deframer extends Transform {
|
||||
}
|
||||
}
|
||||
|
||||
class Framer extends Transform {
|
||||
constructor(options) {
|
||||
super({
|
||||
writableObjectMode: true,
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
const { cmd, payload } = chunk
|
||||
|
||||
// Message size must be rounded up to a multiple of 16
|
||||
|
||||
const len = 8 + payload.length
|
||||
const buf = Buffer.alloc((len + 15) & ~15)
|
||||
|
||||
buf.writeUInt16LE(0xA13E, 0) // Magic?
|
||||
buf.writeUInt16LE(0x3087, 2) // ???
|
||||
buf.writeUInt16LE(cmd, 4)
|
||||
buf.writeUInt16LE(buf.length, 6)
|
||||
payload.copy(buf, 8)
|
||||
|
||||
console.log('Aimedb: Send', buf)
|
||||
|
||||
callback(null, buf)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Deframer,
|
||||
Framer,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const crypto = require('crypto')
|
||||
const { pipeline } = require('stream')
|
||||
|
||||
const { Deframer, Framer } = require('./frame')
|
||||
const { Deframer } = require('./frame')
|
||||
const { Decoder, Encoder } = require('./cmd')
|
||||
|
||||
const K = Buffer.from('Copyright(C)SEGA', 'utf8')
|
||||
@@ -20,7 +20,6 @@ function setup(socket) {
|
||||
|
||||
pipeline(
|
||||
output,
|
||||
new Framer(),
|
||||
crypto
|
||||
.createCipheriv('aes-128-ecb', K, null)
|
||||
.setAutoPadding(false),
|
||||
|
||||
Reference in New Issue
Block a user