node-insim
Version:
An InSim library for NodeJS with TypeScript support
97 lines (96 loc) • 3.94 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IS_MTC = void 0;
var unicode_to_lfs_1 = __importDefault(require("unicode-to-lfs"));
var decorators_1 = require("../decorators");
var base_1 = require("./base");
var enums_1 = require("./enums");
var TEXT_MAX_LENGTH = 128;
/**
* Msg To Connection - hosts only - send to a connection / a player / all
*/
var IS_MTC = /** @class */ (function (_super) {
__extends(IS_MTC, _super);
function IS_MTC(data) {
var _this = _super.call(this) || this;
_this.Size = IS_MTC.FIXED_DATA_SIZE;
_this.Type = enums_1.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);
return _this;
}
IS_MTC.prototype.pack = function () {
var multiple = 4;
var encodedText = (0, unicode_to_lfs_1.default)(this.Text);
var length = encodedText.length;
var textSize = Math.min(length + (multiple - (length % multiple)), TEXT_MAX_LENGTH);
this.Size = IS_MTC.FIXED_DATA_SIZE + textSize;
return _super.prototype.pack.call(this, {
Text: "".concat(textSize, "S"),
});
};
IS_MTC.FIXED_DATA_SIZE = 8;
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "Size", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "Type", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "ReqI", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "Sound", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "UCID", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "PLID", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "Sp2", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MTC.prototype, "Sp3", void 0);
__decorate([
(0, decorators_1.stringNull)(TEXT_MAX_LENGTH)
], IS_MTC.prototype, "Text", void 0);
return IS_MTC;
}(base_1.SendablePacket));
exports.IS_MTC = IS_MTC;