node-insim
Version:
An InSim library for NodeJS with TypeScript support
67 lines (66 loc) • 1.85 kB
JavaScript
import { __decorate } from "tslib";
import { byte, getFormat, stringNull } from '../decorators';
import { InSimError } from '../errors';
import { unpack } from '../lfspack';
import { Packet } from './base';
import { PacketType } from './enums';
/**
* InsIm Info - /i message from user to host's InSim - variable size
*/
export class IS_III extends Packet {
constructor() {
super(...arguments);
this.Size = IS_III.FIXED_DATA_SIZE;
this.Type = PacketType.ISP_III;
this.ReqI = 0;
this.Zero = 0;
/** Connection's unique id (0 = host) */
this.UCID = 0;
/** Player's unique id (if zero, use UCID) */
this.PLID = 0;
this.Sp2 = 0;
this.Sp3 = 0;
/** 4, 8, 12... 64 characters - last byte is zero */
this.Msg = '';
}
unpack(buffer) {
const data = unpack(`<${getFormat(this, 'Size')}`, buffer.buffer);
if (!data || data.length === 0) {
throw new InSimError('IS_III - Unpacked no data from buffer');
}
const size = data[0] * this.SIZE_MULTIPLIER;
const msgLength = size - IS_III.FIXED_DATA_SIZE;
super.unpack(buffer, {
Msg: `${msgLength}s`,
});
return this;
}
}
IS_III.FIXED_DATA_SIZE = 8;
__decorate([
byte()
], IS_III.prototype, "Size", void 0);
__decorate([
byte()
], IS_III.prototype, "Type", void 0);
__decorate([
byte()
], IS_III.prototype, "ReqI", void 0);
__decorate([
byte()
], IS_III.prototype, "Zero", void 0);
__decorate([
byte()
], IS_III.prototype, "UCID", void 0);
__decorate([
byte()
], IS_III.prototype, "PLID", void 0);
__decorate([
byte()
], IS_III.prototype, "Sp2", void 0);
__decorate([
byte()
], IS_III.prototype, "Sp3", void 0);
__decorate([
stringNull(64)
], IS_III.prototype, "Msg", void 0);