UNPKG

tsinsim

Version:

An InSim library for Node.js (JavaScript runtime environment) with TypeScript support.

96 lines (95 loc) 3.15 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Sendable } from "../../utilities/index.js"; import { define, byte } from "../../utilities/decorators.js"; import { PacketType } from "../../types/PacketType.js"; let IS_IPB = class IS_IPB extends Sendable { constructor(options = {}) { super(); Object.assign(this, options); } Size = 8; Type = PacketType.ISP_IPB; ReqI = 0; NumB = 0; Sp0 = 0; Sp1 = 0; Sp2 = 0; Sp3 = 0; BanIPs = []; pack() { this.BanIPs = this.BanIPs.filter((ip) => { if (ip.split('.').length != 4) return false; var valid = true; for (const v of ip.split('.')) { if (v.length < 1 || parseInt(v) < 0 || parseInt(v) > 255) { valid = false; } } return valid; }); this.NumB = this.BanIPs.length; var buffer = super.pack(this.Size + this.NumB * 4); for (const ip of this.BanIPs) { const bufferIpAdress = Buffer.alloc(4); ip.split('.').map((v, i) => { bufferIpAdress.writeUint8(parseInt(v), i); return v; }); buffer = Buffer.concat([buffer, bufferIpAdress]); } return buffer; } unpack(data) { super.unpack(data); for (var i = 8; i < 8 + this.NumB * 4; i += 4) { this.BanIPs.push(data.subarray(i, i + 4).join('.')); } return this; } }; __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Size", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Type", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "ReqI", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "NumB", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Sp0", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Sp1", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Sp2", void 0); __decorate([ byte(), __metadata("design:type", Object) ], IS_IPB.prototype, "Sp3", void 0); IS_IPB = __decorate([ define, __metadata("design:paramtypes", [Object]) ], IS_IPB); export { IS_IPB };