UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

67 lines (66 loc) 1.87 kB
import { __decorate } from "tslib"; import unicodeToLfs from 'unicode-to-lfs'; import { byte, stringNull } from '../decorators'; import { SendablePacket } from './base'; import { PacketType } from './enums'; const TEXT_MAX_LENGTH = 128; /** * Msg To Connection - hosts only - send to a connection / a player / all */ export class IS_MTC extends SendablePacket { constructor(data) { super(); this.Size = IS_MTC.FIXED_DATA_SIZE; this.Type = PacketType.ISP_MTC; this.ReqI = 0; /** Sound effect */ this.Sound = 0; /** Connection's unique id (0 = host / 255 = all) */ this.UCID = 0; /** Player's unique id (if zero, use UCID) */ this.PLID = 0; this.Sp2 = 0; this.Sp3 = 0; /** Up to 128 characters of text - last byte must be zero */ this.Text = ''; this.initialize(data); } pack() { const multiple = 4; const encodedText = unicodeToLfs(this.Text); const length = encodedText.length; const textSize = Math.min(length + (multiple - (length % multiple)), TEXT_MAX_LENGTH); this.Size = IS_MTC.FIXED_DATA_SIZE + textSize; return super.pack({ Text: `${textSize}S`, }); } } IS_MTC.FIXED_DATA_SIZE = 8; __decorate([ byte() ], IS_MTC.prototype, "Size", void 0); __decorate([ byte() ], IS_MTC.prototype, "Type", void 0); __decorate([ byte() ], IS_MTC.prototype, "ReqI", void 0); __decorate([ byte() ], IS_MTC.prototype, "Sound", void 0); __decorate([ byte() ], IS_MTC.prototype, "UCID", void 0); __decorate([ byte() ], IS_MTC.prototype, "PLID", void 0); __decorate([ byte() ], IS_MTC.prototype, "Sp2", void 0); __decorate([ byte() ], IS_MTC.prototype, "Sp3", void 0); __decorate([ stringNull(TEXT_MAX_LENGTH) ], IS_MTC.prototype, "Text", void 0);