node-insim
Version:
An InSim library for NodeJS with TypeScript support
48 lines (47 loc) • 1.48 kB
JavaScript
import { __decorate } from "tslib";
import { byte } from '../decorators';
import { copyBuffer } from '../lfspack';
import { Packet } from './base';
import { PacketType } from './enums';
import { HInfo } from './structs';
/**
* Hostlist (hosts connected to the Relay)
*/
export class IR_HOS extends Packet {
constructor() {
super(...arguments);
this.SIZE_MULTIPLIER = 1;
/** 4 + NumHosts * 40 */
this.Size = 4;
this.Type = PacketType.IRP_HOS;
/** As given in {@link IR_HLR} */
this.ReqI = 0;
/** Number of hosts described in this packet */
this.NumHosts = 0;
/** Host info for every host in the Relay. 1 to 6 of these in a {@link IR_HOS} */
this.Info = [];
}
unpack(buffer) {
super.unpack(buffer);
const hostInfoOffset = this.getFormatSize();
const hostInfoLength = new HInfo().getFormatSize();
for (let i = 0; i < this.NumHosts; i++) {
const start = hostInfoOffset + hostInfoLength * i;
const hostInfoBuffer = copyBuffer(buffer.slice(start, start + hostInfoLength));
this.Info.push(new HInfo().unpack(hostInfoBuffer));
}
return this;
}
}
__decorate([
byte()
], IR_HOS.prototype, "Size", void 0);
__decorate([
byte()
], IR_HOS.prototype, "Type", void 0);
__decorate([
byte()
], IR_HOS.prototype, "ReqI", void 0);
__decorate([
byte()
], IR_HOS.prototype, "NumHosts", void 0);