node-insim
Version:
An InSim library for NodeJS with TypeScript support
141 lines (140 loc) • 5.87 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 __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserType = exports.IS_MSO = void 0;
var decorators_1 = require("../decorators");
var errors_1 = require("../errors");
var lfspack_1 = require("../lfspack");
var base_1 = require("./base");
var enums_1 = require("./enums");
/**
* MSg Out - system messages and user messages - variable size
*
* NOTE: Typing "/o MESSAGE" into LFS will send an IS_MSO with {@link UserType} = {@link MSO_O}
*/
var IS_MSO = /** @class */ (function (_super) {
__extends(IS_MSO, _super);
function IS_MSO() {
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
_this.Size = IS_MSO.FIXED_DATA_SIZE;
_this.Type = enums_1.PacketType.ISP_MSO;
_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;
/** Set if typed by a user (see {@link UserType}) */
_this.UserType = 0;
/** First character of the actual text (after player name) */
_this.TextStart = 0;
/** 4, 8, 12... 128 characters - last byte is zero */
_this.Msg = '';
return _this;
}
IS_MSO.prototype.unpack = function (buffer) {
var data = (0, lfspack_1.unpack)("<".concat((0, decorators_1.getFormat)(this, 'Size')), buffer.buffer);
if (!data || data.length === 0) {
throw new errors_1.InSimError('IS_MSO - Unpacked no data from buffer');
}
var size = data[0] * this.SIZE_MULTIPLIER;
var msgLength = size - IS_MSO.FIXED_DATA_SIZE;
_super.prototype.unpack.call(this, buffer, {
Msg: "".concat(msgLength, "s"),
});
var playerNameUnpacked = (0, lfspack_1.unpack)("<".concat(this.TextStart, "s"), buffer.buffer, IS_MSO.FIXED_DATA_SIZE);
if (playerNameUnpacked !== null &&
Array.isArray(playerNameUnpacked[0]) &&
playerNameUnpacked[0].length === 2) {
var _a = __read(playerNameUnpacked[0], 2), playerName = _a[1];
this.TextStart = playerName.length;
}
return this;
};
IS_MSO.FIXED_DATA_SIZE = 8;
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "Size", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "Type", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "ReqI", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "Zero", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "UCID", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "PLID", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "UserType", void 0);
__decorate([
(0, decorators_1.byte)()
], IS_MSO.prototype, "TextStart", void 0);
__decorate([
(0, decorators_1.stringNull)(128)
], IS_MSO.prototype, "Msg", void 0);
return IS_MSO;
}(base_1.Packet));
exports.IS_MSO = IS_MSO;
var UserType;
(function (UserType) {
/** System message */
UserType[UserType["MSO_SYSTEM"] = 0] = "MSO_SYSTEM";
/** Normal visible user message */
UserType[UserType["MSO_USER"] = 1] = "MSO_USER";
/** hidden message starting with special prefix (see {@link IS_ISI}) */
UserType[UserType["MSO_PREFIX"] = 2] = "MSO_PREFIX";
/** Hidden message typed on local pc with /o command */
UserType[UserType["MSO_O"] = 3] = "MSO_O";
})(UserType || (exports.UserType = UserType = {}));