123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- var crypto = require('crypto');
- class Admin {
- help(room, mobile, input) {
- if(input.join(" ").trim().length == 0) {
- libs.Output.toMobile(mobile.id, "Admin commands:");
- libs.Output.toMobile(mobile.id, "reload, hash, time, permission");
- return false;
- }
- var topic = input.join(" ").trim();
- switch(topic) {
- case "reload":
- libs.Output.toMobile(mobile.id, "* reload world - reloads the core processing");
- libs.Output.toMobile(mobile.id, "* reload builder - reloads the building tools");
- libs.Output.toMobile(mobile.id, "* reload libs - reloads common utilities like output");
- libs.Output.toMobile(mobile.id, "* reload admin - reloads the administration tools");
- libs.Output.toMobile(mobile.id, "* reload commands - reloads the collection of player input commands");
- return false;
- case "hash":
- libs.Output.toMobile(mobile.id, "hash [input to hash] - will generate a sha256-base64 hash");
- return true;
- case "time":
- libs.Output.toMobile(mobile.id, "time - displays the current server time tick (0-640)");
- libs.Output.toMobile(mobile.id, "time [value] - sets the server to this time tick");
- return true;
- case "permission":
- libs.Output.toMobile(mobile.id, "permission see [playerName] - lists the permissions of the player");
- libs.Output.toMobile(mobile.id, "permission add [playerName] [admin|builder] - adds the permission to a player");
- libs.Output.toMobile(mobile.id, "permission remove [playerName] [admin|builder] - removes a permission from a player");
- return true;
- }
- }
- reload(room, mobile, input) {
- switch(input[0]) {
- case "world":
- return this.reloadWorld(room, mobile, input);
- case "builder":
- return this.reloadBuilder(room, mobile, input);
- case "libs":
- return this.reloadLibs(room, mobile, input);
- case "admin":
- return this.reloadAdmin(room, mobile, input);
- case "commands":
- return this.reloadCommands(room, mobile, input);
- //default:
- //return this.help(room, mobile, ["reload"]);
- }
- }
- reloadWorld(room, mobile, input) {
- var tempTime = world.time;
- var tempSession = session;
- libs.Output.toMobile(mobile.id,"Preparing to reload world.");
- try {
- delete require.cache[require.resolve('./world')];
- world = require('./world');
- world.time = tempTime;
- session = tempSession;
- libs.Output.toMobile(mobile.id,"World reloaded");
- libs.Output.toServer("World reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload world.");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- reloadBuilder(room, mobile, input) {
- libs.Output.toMobile(mobile.id,"Preparing to reload build tools.");
- try {
- delete require.cache[require.resolve('./builder')];
- builder = require('./builder');
- libs.Output.toMobile(mobile.id,"Build tools reloaded");
- libs.Output.toServer("Build tools reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload build tools.");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- reloadLibs(room, mobile, input) {
- libs.Output.toMobile(mobile.id,"Preparing to reload common libraries.");
- try {
- delete require.cache[require.resolve('./libs')];
- libs = require('./libs');
- for(var library in libs){
- libs.Output.toMobile(mobile.id, "\t" + library);
- delete require.cache[require.resolve('./libs/'+library.toLowerCase()+".js")];
- libs[library] = require('./libs/' + library.toLowerCase() + ".js");
- }
- libs.Output.toMobile(mobile.id,"Common libraries reloaded");
- libs.Output.toServer("Common libraries reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload common libraries.");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- reloadCommands(room, mobile, input) {
- libs.Output.toMobile(mobile.id,"Preparing to reload commands.");
- try {
- delete require.cache[require.resolve('./commands')];
- commands = require('./commands');
- for(var commandClass in commands){
- libs.Output.toMobile(mobile.id, "\t" + commandClass);
- delete require.cache[require.resolve('./commands/'+commandClass.toLowerCase()+".js")];
- commands[commandClass] = require('./commands/' + commandClass.toLowerCase() + ".js");
- }
- libs.Output.toMobile(mobile.id,"Commands reloaded");
- libs.Output.toServer("Commands reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload commands.");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- reloadAdmin(room, mobile, input) {
- libs.Output.toMobile(mobile.id,"Preparing to reload admin tools.");
- try {
- delete require.cache[require.resolve('./admin')];
- admin = require('./admin');
- libs.Output.toMobile(mobile.id,"Admin tools reloaded.");
- libs.Output.toServer("Admin tools reloaded.\n");
- } catch (error) {
- libs.Output.toMobile(mobile.id, "Error when attempting to reload admin tools.");
- libs.Output.toMobile(mobile.id, error.code + " " + error.stack +"\n");
- }
- return true;
- }
- hash(room, mobile, input) {
- var hash = world.mud_generateHash(input.join(" "));
- libs.Output.toMobile(mobile.id,"hash: " + hash);
- return true;
- }
- time(room, mobile, input) {
- if(input.join(" ") == null || input.join(" ") == "") {
- libs.Output.toMobile(mobile.id,"The time is " + world.time);
- return true;
- } else {
- var newTime = parseInt(input.join(" "));
- world.time = newTime;
- libs.Output.toMobile(mobile.id,"The time is " + world.time);
- return true;
- }
- }
- permission(room, mobile, input) {
- switch(input.shift()) {
- case "add":
- this.mud_addPermission(room, mobile, input);
- return true;
- case "remove":
- this.mud_removePermission(room, mobile, input);
- return true;
- case "see":
- this.mud_seePermission(room, mobile, input);
- return true;
- default:
- return this.help(room, mobile, ["permission"]);
- }
- }
- mud_addPermission(room, mobile, input) {
- var playerIds = [];
- for(var index in session.players) {
- var player = session.players[index];
- playerIds.push(player.id);
- }
- var username = input.join(" ").trim().toLowerCase();
- var player = libs.Utilities.getSpecific(username, playerIds, session.mobiles);
- if(player != null) {
- var role = input[1].trim();
- if(player.roles.indexOf(role) == -1) {
- player.roles.push(role);
- libs.Output.toMobile(mobile.id, "Adding permission '"+ role + "' to player '"+player.name+"'");
- libs.Output.toMobile(player.id, "You now have '" + role + "' access.");
- player.save();
- world.mud_handleInput(player.roomId, player.id, ["help", role]);
- }
- libs.Output.toMobile(mobile.id, "Player '"+player.name+"' roles:");
- for(var index in player.roles) {
- libs.Output.toMobile(mobile.id, "\t"+player.roles[index]);
- }
- return true;
- }
- libs.Output.toMobile(mobile.id, "That player is not online.");
- return true;
- }
- mud_seePermission(room, mobile, input) {
- var playerIds = [];
- for(var index in session.players) {
- var player = session.players[index];
- playerIds.push(player.id);
- }
- var username = input.join(" ").trim().toLowerCase();
- var player = libs.Utilities.getSpecific(username, playerIds, session.mobiles);
- if(player != null) {
- libs.Output.toMobile(mobile.id, "Player '"+player.name+"' roles:");
- for(var index in player.roles) {
- libs.Output.toMobile(mobile.id, "\t"+player.roles[index]);
- }
- return true;
- }
- libs.Output.toMobile(mobile.id, "That player is not online.");
- return true;
- }
- mud_removePermission(room, mobile, input) {
- var playerIds = [];
- for(var index in session.players) {
- var player = session.players[index];
- playerIds.push(player.id);
- }
- var username = input.join(" ").trim().toLowerCase();
- var player = libs.Utilities.getSpecific(username, playerIds, session.mobiles);
- if(player != null) {
- var role = input[1].trim();
- if(player.roles.indexOf(role) != -1) {
- player.roles.splice(player.roles.indexOf(role), 1);
- libs.Output.toMobile(mobile.id, "Removing permission '"+ role + "' from player '"+player.name+"'");
- libs.Output.toMobile(player.id, "You no longer have '" + role + "' access.");
- player.save();
- }
- libs.Output.toMobile(mobile.id, "Player '"+player.name+"' roles:");
- for(var index in player.roles) {
- libs.Output.toMobile(mobile.id, "\t"+player.roles[index]);
- }
- return true;
- }
- libs.Output.toMobile(mobile.id, "That player is not online.");
- return true;
- }
- }
- module.exports = new Admin();
|