|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 12 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 13 | +}; |
| 14 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 15 | +exports.Console = void 0; |
| 16 | +const events_1 = __importDefault(require("events")); |
| 17 | +const Socket_js_1 = require("./Socket.js"); |
| 18 | +/** |
| 19 | + * Object for managing, sending, and receiving messages from the server's console. |
| 20 | + * |
| 21 | + * Accessable from a `Server` object via `Server.console`. |
| 22 | + * |
| 23 | + * @class |
| 24 | + * @property {object} Server - The Server object this belongs to. |
| 25 | + */ |
| 26 | +class Console extends events_1.default { |
| 27 | + /** |
| 28 | + * @constructor |
| 29 | + * @param {object} server - The server this belongs to. |
| 30 | + */ |
| 31 | + constructor(server) { |
| 32 | + super(); |
| 33 | + this.server = server; |
| 34 | + } |
| 35 | + /** |
| 36 | + * Prints a message to the server's console. |
| 37 | + * [SourceMod API Reference](https://sm.alliedmods.net/new-api/console/PrintToServer) |
| 38 | + * |
| 39 | + * @function |
| 40 | + * @param {string} message - The message to be printed. |
| 41 | + */ |
| 42 | + print(message) { |
| 43 | + var _a; |
| 44 | + return __awaiter(this, void 0, void 0, function* () { |
| 45 | + return yield ((_a = this.server.socket) === null || _a === void 0 ? void 0 : _a.send(Socket_js_1.Messages.PrintToServer, message)); |
| 46 | + }); |
| 47 | + } |
| 48 | + /** |
| 49 | + * Runs a command as if it were executed on the server console (or RCON). |
| 50 | + * [SourceMod API Reference](https://sm.alliedmods.net/new-api/console/ServerCommand) |
| 51 | + * |
| 52 | + * @function |
| 53 | + * @param {string} command - The command to be ran. |
| 54 | + */ |
| 55 | + command(command) { |
| 56 | + var _a; |
| 57 | + return __awaiter(this, void 0, void 0, function* () { |
| 58 | + return yield ((_a = this.server.socket) === null || _a === void 0 ? void 0 : _a.send(Socket_js_1.Messages.ServerCommand, command)); |
| 59 | + }); |
| 60 | + } |
| 61 | +} |
| 62 | +exports.Console = Console; |
0 commit comments