@ohd-tools/rcon
Version:
An RCON Interface for Operation: Harsh Doorstop
93 lines (92 loc) • 2.7 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Player = void 0;
const events_1 = __importDefault(require("events"));
/**
* Generic Player Object
*/
class Player {
id;
steam64;
name;
created;
_events;
_controller;
constructor(controller = null, $b = {}) {
// Want to do instanceof, but circular dependency :(
if (controller != null &&
controller._onResponse == null) {
$b = controller;
controller = null;
}
Object.defineProperty(this, '_controller', {
value: controller,
enumerable: false,
});
Object.defineProperty(this, '_events', {
value: new events_1.default(),
enumerable: false,
});
this.id = $b.id;
this.steam64 = $b.steam64;
this.name = $b.name;
this.created = $b.created ?? new Date();
}
on(event, cb) {
return this._events.on(event, cb);
}
removeListener(event, cb) {
return this._events.removeListener(event, cb);
}
/**Is the player a Bot */
get isBot() {
return this.steam64 == null;
}
get hasController() {
return this._controller != undefined;
}
controllerReject() {
return Promise.reject({
success: false,
reason: `Object for Player ${this.id} does not have an RCON Controller.`,
});
}
/**Kick the current `Player` */
kick(reason = 'You have been Kicked!') {
if (!this.hasController)
return this.controllerReject();
return this._controller.kickId(this.id, reason);
}
/**Ban the current `Player` */
ban(duration = 0, reason) {
if (!this.hasController)
return this.controllerReject();
return this._controller.banId(this.id, duration, reason);
}
/**Set the team of the current `Player` */
setTeam(teamId) {
if (!this.hasController)
return this.controllerReject();
return this._controller.forceTeamId(this.id, teamId);
}
/**
* Give the user Admin Access
*/
addAdmin() {
if (!this.hasController)
return this.controllerReject();
return this._controller.addAdminById(this.id);
}
/**
* Revoke the users Admin Access
*/
removeAdmin() {
if (!this.hasController)
return this.controllerReject();
return this._controller.removeAdminById(this.id);
}
}
exports.Player = Player;