srcds-log-receiver
Version:
A simple too to receive srcds logs
55 lines • 2.19 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var dgram = require("dgram");
var events = require("events");
var parser = require("./PacketParser");
var LogReceiver = (function (_super) {
__extends(LogReceiver, _super);
function LogReceiver(opts) {
var _this = _super.call(this) || this;
opts = opts || {};
opts.address = opts.address || "0.0.0.0";
opts.port = opts.port || 9871;
opts.definedSources = opts.definedSources || [];
opts.requirePassword = opts.requirePassword || false;
_this.opts = opts;
_this.parser = new parser.LogMessageConstructor(opts);
_this.createSocket();
return _this;
}
LogReceiver.prototype.createSocket = function () {
this.socket = dgram.createSocket('udp4', this.handleMessage.bind(this));
this.socket.bind(this.opts.port, this.opts.address);
};
LogReceiver.prototype.handleMessage = function (message, senderInfo) {
var logMessage = this.parser.GetLogMessage(message, senderInfo);
if (logMessage.isValid) {
this.emit("data", logMessage);
}
else {
this.emit("invalid", logMessage);
}
};
return LogReceiver;
}(events.EventEmitter));
exports.LogReceiver = LogReceiver;
var magicBytePassword = 0x53, magicByteNoPassword = 0x52;
var LogType;
(function (LogType) {
LogType[LogType["NoPassword"] = magicByteNoPassword] = "NoPassword";
LogType[LogType["Password"] = magicBytePassword] = "Password";
})(LogType = exports.LogType || (exports.LogType = {}));
//# sourceMappingURL=index.js.map