def message(self, message): """ This is a substitute for the player.message() that plugins and the command interface expect for player objects. It translates chat type messages intended for a minecraft client into printed colorized console lines. """ displaycode, displaycolor = "5", "magenta" display = str(message) if type(message) is dict: jsondisplay = message else: jsondisplay = False # format "&c" type color (roughly) to console formatters color if display[0:1] == "&": displaycode = display[1:1] display = display[2:] if displaycode in self.message_number_coders: displaycolor = self.message_number_coders[displaycode] if jsondisplay: # or use json formatting, if available if "text" in jsondisplay: display = jsondisplay["text"] if "color" in jsondisplay: displaycolor = jsondisplay["color"] if displaycolor in self.messsage_color_coders: displaycolor = self.messsage_color_coders[displaycolor] readout(display, "", "", pad=15, command_text_fg=displaycolor, usereadline=self.wrapper.use_readline)
def command_entities(self, player, payload): if not player.isOp() > 2: player.message("&cPermission Denied") return False if not self.wrapper.proxymode: player.message( "&cProxy mode is off - Entity control is not enabled.") entitycontrol = self.wrapper.javaserver.entity_control if not entitycontrol: # only console could be the source: readout("ERROR - ", "No entity code found. (no proxy/server started?)", separator="", pad=10, usereadline=self.wrapper.use_readline) return commargs = payload["args"] if len(commargs) < 1: pass elif commargs[0].lower() in ("c", "count", "s", "sum", "summ", "summary"): player.message("Entities loaded: %d" % entitycontrol.countActiveEntities()) return elif commargs[0].lower() in ("k", "kill"): eid = getargs(commargs, 1) count = getargs(commargs, 2) if count < 1: count = 1 entitycontrol.killEntityByEID(eid, dropitems=False, finishstateof_domobloot=True, count=count) return elif commargs[0].lower() in ("l", "list", "sh", "show" "all"): nice_list = {} for ent in entitycontrol.entities: nice_list[entitycontrol.entities[ent]. eid] = entitycontrol.entities[ent].entityname player.message("Entities: \n%s" % nice_list) return elif commargs[0].lower() in ("p", "player", "name"): if len(commargs) < 3: player.message("&c/entity player <name> count/list") return them = entitycontrol.countEntitiesInPlayer(commargs[1]) if commargs[2].lower() in ("l", "list", "sh", "show" "all"): player.message("Entities: \n%s" % json.dumps(them, indent=2)) else: player.message("%d entities exist in %s's client." % (len(them), commargs[1])) return player.message("&cUsage: /entity count") player.message("&c /entity list") player.message("&c /entity player <name> count") player.message("&c /entity player <name> list") player.message("&c /entity kill <EIDofEntity> [count]")
def command_entities(self, player, payload): if not self._superop(player, 5): player.message("&cPermission Denied") return False if not self.wrapper.proxymode: player.message( "&cProxy mode is off - Entity control is not enabled.") entitycontrol = self.wrapper.proxy.entity_control if not entitycontrol: # only console could be the source: readout("ERROR - ", "No entity code found. (no proxy/server started?)", separator="", pad=10, usereadline=self.wrapper.use_readline) return commargs = payload["args"] if len(commargs) < 1: pass elif commargs[0].lower() in ( "c", "count", "s", "sum", "summ", "summary"): player.message( "Entities loaded: %d" % entitycontrol.countActiveEntities()) return elif commargs[0].lower() in ("k", "kill"): eid = get_int(getargs(commargs, 1)) count = get_int(getargs(commargs, 2)) if count < 1: count = 1 entitycontrol.killEntityByEID( eid, dropitems=False, count=count) return elif commargs[0].lower() in ("l", "list", "sh", "show" "all"): nice_list = {} for ent in entitycontrol.entities: nice_list[entitycontrol.entities[ ent].eid] = entitycontrol.entities[ent].entityname player.message("Entities: \n%s" % nice_list) return elif commargs[0].lower() in ("p", "player", "name"): if len(commargs) < 3: player.message("&c/entity player <name> count/list") return them = entitycontrol.countEntitiesInPlayer(commargs[1]) if commargs[2].lower() in ("l", "list", "sh", "show" "all"): player.message("Entities: \n%s" % json.dumps(them, indent=2)) else: player.message("%d entities exist in %s's client." % (len(them), commargs[1])) return player.message("&cUsage: /entity count") player.message("&c /entity list") player.message("&c /entity player <name> count") player.message("&c /entity player <name> list") player.message("&c /entity kill <EIDofEntity> [count]")
def listplugins(self): readout("", "List of Wrapper.py plugins installed:", separator="", pad=4, usereadline=self.use_readline) for plid in self.plugins: plugin = self.plugins[plid] if plugin["good"]: name = plugin["name"] summary = plugin["summary"] if summary is None: summary = "No description available for this plugin" version = plugin["version"] readout(name, summary, separator=(" - v%s - " % ".".join([str(_) for _ in version])), usereadline=self.use_readline) else: readout("failed to load plugin", plugin, pad=25, usereadline=self.use_readline)
def _pause_console(self, pause_time): if not self.javaserver: readout("ERROR - ", "There is no running server instance to mute.", separator="", pad=10, usereadline=self.use_readline) return self.javaserver.server_muted = True readout("Server is now muted for %d seconds." % pause_time, "", separator="", command_text_fg="yellow", usereadline=self.use_readline) time.sleep(pause_time) readout("Server now unmuted.", "", separator="", usereadline=self.use_readline) self.javaserver.server_muted = False for lines in self.javaserver.queued_lines: readout("Q\\", "", lines, pad=3, usereadline=self.use_readline) time.sleep(.1) self.javaserver.queued_lines = []
def listplugins(self): readout("", "List of Wrapper.py plugins installed:", separator="", pad=4, usereadline=self.use_readline) for plid in self.plugins: plugin = self.plugins[plid] if plugin["good"]: name = plugin["name"] summary = plugin["summary"] if summary is None: summary = "No description available for this plugin" version = plugin["version"] readout(name, summary, separator=( " - v%s - " % ".".join([str(_) for _ in version])), usereadline=self.use_readline) else: readout("failed to load plugin", plugin, pad=25, usereadline=self.use_readline)
def parseconsoleinput(self): while not self.halt.halt: consoleinput = self.getconsoleinput() # No command (perhaps just a line feed or spaces?) if len(consoleinput) < 1: continue # for use with runwrapperconsolecommand() command wholecommandline = consoleinput[0:].split(" ") command = str(getargs(wholecommandline, 0)).lower() # this can be passed to runwrapperconsolecommand() command for args allargs = wholecommandline[1:] # Console only commands (not accessible in-game) if command in ("/halt", "halt"): self._halt() elif command in ("/stop", "stop"): self.javaserver.stop_server_command() # "kill" (with no slash) is a server command. elif command == "/kill": self.javaserver.kill("Server killed at Console...") elif command in ("/start", "start"): self.javaserver.start() elif command in ("/restart", "restart"): self.javaserver.restart() elif command in ("/update-wrapper", "update-wrapper"): self._checkforupdate(True) # "plugins" command (with no slash) reserved for server commands elif command == "/plugins": self.listplugins() elif command in ("/mem", "/memory", "mem", "memory"): self._memory() elif command in ("/raw", "raw"): self._raw(consoleinput) elif command in ("/freeze", "freeze"): self._freeze() elif command in ("/unfreeze", "unfreeze"): self._unfreeze() elif command == "/version": readout("/version", self.getbuildstring(), usereadline=self.use_readline) elif command in ("/mute", "/pause", "/cm", "/m", "/p"): self._mute_console(allargs) # Commands that share the commands.py in-game interface # "reload" (with no slash) may be used by bukkit servers elif command == "/reload": self.runwrapperconsolecommand("reload", []) # proxy mode ban system elif self.proxymode and command == "/ban": self.runwrapperconsolecommand("ban", allargs) elif self.proxymode and command == "/ban-ip": self.runwrapperconsolecommand("ban-ip", allargs) elif self.proxymode and command == "/pardon-ip": self.runwrapperconsolecommand("pardon-ip", allargs) elif self.proxymode and command == "/pardon": self.runwrapperconsolecommand("pardon", allargs) elif command in ("/perm", "/perms", "/super", "/permissions", "perm", "perms", "super", "permissions"): self.runwrapperconsolecommand("perms", allargs) elif command in ("/playerstats", "/stats", "playerstats", "stats"): self.runwrapperconsolecommand("playerstats", allargs) elif command in ("/ent", "/entity", "/entities", "ent", "entity", "entities"): self.runwrapperconsolecommand("ent", allargs) elif command in ("/config", "/con", "/prop", "/property", "/properties"): self.runwrapperconsolecommand("config", allargs) elif command in ("op", "/op"): self.runwrapperconsolecommand("op", allargs) elif command in ("deop", "/deop"): self.runwrapperconsolecommand("deop", allargs) elif command in ("pass", "/pass", "pw", "/pw", "password", "/password"): self.runwrapperconsolecommand("password", allargs) # TODO Add more commands below here, below the original items: # TODO __________________ # more commands here... # TODO __________________ # TODO add more commands above here, above the help-related items: # minecraft help command elif command == "help": readout("/help", "Get wrapper.py help.", separator=" (with a slash) - ", usereadline=self.use_readline) self.javaserver.console(consoleinput) # wrapper's help (console version) elif command == "/help": self._show_help_console() # wrapper ban help elif command == "/bans": self._show_help_bans() # Commmand not recognized by wrapper else: try: self.javaserver.console(consoleinput) except Exception as e: self.log.error("[BREAK] Console input exception" " (nothing passed to server) \n%s" % e) break continue
def _show_help_bans(self): # ban commands help. if not self.proxymode: readout("ERROR - ", "Wrapper proxy-mode bans are not enabled " "(proxy mode is not on).", separator="", pad=10, usereadline=self.use_readline) return readout("", "Bans - To use the server's versions, do not type a slash.", separator="", pad=5, usereadline=self.use_readline) readout("", "", separator="-----1.7.6 and later ban commands-----", pad=10, usereadline=self.use_readline) readout("/ban", " - Ban a player. Specifying h:<hours> or d:<days>" " creates a temp ban.", separator="<name> [reason..] [d:<days>/h:<hours>] ", pad=12, usereadline=self.use_readline) readout("/ban-ip", " - Ban an IP address. Reason and days (d:) are optional.", separator="<ip> [<reason..> <d:<number of days>] ", pad=12, usereadline=self.use_readline) readout("/pardon", " - pardon a player. Default is byuuidonly. To unban a" "specific name (without checking uuid), use" " `pardon <player> False`", separator="<player> [byuuidonly(true/false)]", pad=12, usereadline=self.use_readline) readout("/pardon-ip", " - Pardon an IP address.", separator="<address> ", pad=12, usereadline=self.use_readline) readout("/banlist", " - search and display the banlist (warning -" " displays on single page!)", separator="[players|ips] [searchtext] ", pad=12, usereadline=self.use_readline)
def _show_help_console(self): # This is the console help command display. readout("", "Get Minecraft help.", separator="help (no slash) - ", pad=0, usereadline=self.use_readline) readout("/reload", "Reload Wrapper.py plugins.", usereadline=self.use_readline) readout("/plugins", "Lists Wrapper.py plugins.", usereadline=self.use_readline) readout("/update-wrapper", "Checks for new Wrapper.py updates, and will install\n" "them automatically if one is available.", usereadline=self.use_readline) readout("/stop", "Stop the minecraft server without" " auto-restarting and without\n" " shuttingdown Wrapper.py.", usereadline=self.use_readline) readout("/start", "Start the minecraft server.", usereadline=self.use_readline) readout("/restart", "Restarts the minecraft server.", usereadline=self.use_readline) readout("/halt", "Shutdown Wrapper.py completely.", usereadline=self.use_readline) readout("/cm [seconds]", "Mute server output (Wrapper console" " logging still happens)", usereadline=self.use_readline) readout("/kill", "Force kill the server without saving.", usereadline=self.use_readline) readout("/freeze", "Temporarily locks the server up" " until /unfreeze is executed\n" " (Only works on *NIX servers).", usereadline=self.use_readline) readout("/unfreeze", "Unlocks a frozen state server" " (Only works on *NIX servers).", usereadline=self.use_readline) readout("/mem", "Get memory usage of the server" " (Only works on *NIX servers).", usereadline=self.use_readline) readout("/raw [command]", "Send command to the Minecraft" " Server. Useful for Forge\n" " commands like '/fml confirm'.", usereadline=self.use_readline) readout("/password", "run `/password help` for more...)", usereadline=self.use_readline) readout("/perms", "/perms for more...)", usereadline=self.use_readline) readout("/config", "Change wrapper.properties (type" " /config help for more..)", usereadline=self.use_readline) readout("/version", self.getbuildstring(), usereadline=self.use_readline) readout("/entity", "Work with entities (run /entity for more...)", usereadline=self.use_readline) readout("/bans", "Display the ban help page.", usereadline=self.use_readline)
def _show_help_bans(self): # ban commands help. if not self.proxymode: readout( "ERROR - ", "Wrapper proxy-mode bans are not enabled " "(proxy mode is not on).", separator="", pad=10, usereadline=self.use_readline) return readout( "", "Bans - To use the server's versions, do not type a slash.", separator="", pad=5, usereadline=self.use_readline) readout( "", "", separator="-----1.7.6 and later ban commands-----", pad=10, usereadline=self.use_readline) readout( "/ban", " - Ban a player. Specifying h:<hours> or d:<days>" " creates a temp ban.", separator="<name> [reason..] [d:<days>/h:<hours>] ", pad=12, usereadline=self.use_readline) readout( "/ban-ip", " - Ban an IP address. Reason and days (d:) are optional.", separator="<ip> [<reason..> <d:<number of days>] ", pad=12, usereadline=self.use_readline) readout( "/pardon", " - pardon a player. Default is byuuidonly. To unban a" "specific name (without checking uuid), use" " `pardon <player> False`", separator="<player> [byuuidonly(true/false)]", pad=12, usereadline=self.use_readline) readout( "/pardon-ip", " - Pardon an IP address.", separator="<address> ", pad=12, usereadline=self.use_readline) readout( "/banlist", " - search and display the banlist (warning -" " displays on single page!)", separator="[players|ips] [searchtext] ", pad=12, usereadline=self.use_readline)