def func(self): """ Get all connected players by polling session. """ player = self.player session_list = SESSIONS.get_sessions() session_list = sorted(session_list, key=lambda o: o.player.key) if self.cmdstring == "doing": show_session_data = False else: show_session_data = player.check_permstring( "Immortals") or player.check_permstring("Wizards") nplayers = (SESSIONS.player_count()) if show_session_data: # privileged info table = prettytable.PrettyTable([ "{wPlayer Name", "{wOn for", "{wIdle", "{wPuppeting", "{wRoom", "{wCmds", "{wProtocol", "{wHost" ]) for session in session_list: if not session.logged_in: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time player = session.get_player() puppet = session.get_puppet() location = puppet.location.key if puppet else "None" table.add_row([ utils.crop(player.name, width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1), utils.crop(puppet.key if puppet else "None", width=25), utils.crop(location, width=25), session.cmd_total, session.protocol_key, isinstance(session.address, tuple) and session.address[0] or session.address ]) else: # unprivileged table = prettytable.PrettyTable( ["{wPlayer name", "{wOn for", "{wIdle"]) for session in session_list: if not session.logged_in: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time player = session.get_player() table.add_row([ utils.crop(player.key, width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1) ]) isone = nplayers == 1 string = "{wPlayers:{n\n%s\n%s unique account%s logged in." % ( table, "One" if isone else nplayers, "" if isone else "s") self.msg(string)
def func(self): "Create the nickname" caller = self.caller switches = self.switches nicks = caller.nicks.get(return_obj=True) if 'list' in switches: table = prettytable.PrettyTable( ["{wNickType", "{wNickname", "{wTranslates-to"]) for nick in utils.make_iter(nicks): table.add_row( [nick.db_category, nick.db_key, nick.db_strvalue]) string = "{wDefined Nicks:{n\n%s" % table caller.msg(string) return if 'clearall' in switches: caller.nicks.clear() caller.msg("Cleared all aliases.") return if not self.args or not self.lhs: caller.msg("Usage: nick[/switches] nickname = [realname]") return nick = self.lhs real = self.rhs if real == nick: caller.msg( "No point in setting nick same as the string to replace...") return # check so we have a suitable nick type if not any(True for switch in switches if switch in ("object", "player", "inputline")): switches = ["inputline"] string = "" for switch in switches: oldnick = caller.nicks.get(key=nick, category=switch) if not real: # removal of nick if oldnick: # clear the alias string += "\nNick '%s' (= '%s') was cleared." % (nick, oldnick) caller.nicks.delete(nick, category=switch) else: string += "\nNo nick '%s' found, so it could not be removed." % nick else: # creating new nick if oldnick: string += "\nNick %s changed from '%s' to '%s'." % ( nick, oldnick, real) else: string += "\nNick set: '%s' = '%s'." % (nick, real) caller.nicks.add(nick, real, category=switch) caller.msg(string)
def list_bans(banlist): """ Helper function to display a list of active bans. Input argument is the banlist read into the two commands @ban and @unban below. """ if not banlist: return "No active bans were found." table = prettytable.PrettyTable(["{wid", "{wname/ip", "{wdate", "{wreason"]) for inum, ban in enumerate(banlist): table.add_row([str(inum + 1), ban[0] and ban[0] or ban[1], ban[3], ban[4]]) string = "{wActive bans:{n\n%s" % table return string
def func(self): "check inventory" items = self.caller.contents if not items: string = "You are not carrying anything." else: table = prettytable.PrettyTable(["name", "desc"]) table.header = False table.border = False for item in items: table.add_row([ "{C%s{n" % item.name, item.db.desc and item.db.desc or "" ]) string = "{wYou are carrying:\n%s" % table self.caller.msg(string)
def func(self): "Show server time data in a table." table = prettytable.PrettyTable(["{wserver time statistic", "{wtime"]) table.align = 'l' table.add_row( ["Current server uptime", utils.time_format(gametime.uptime(), 3)]) table.add_row([ "Total server running time", utils.time_format(gametime.runtime(), 2) ]) table.add_row([ "Total in-game time (realtime x %g)" % (gametime.TIMEFACTOR), utils.time_format(gametime.gametime(), 2) ]) table.add_row(["Server time stamp", datetime.datetime.now()]) self.caller.msg(str(table))
def func(self): "Implement function" player = self.player sessions = player.sessions.all() table = prettytable.PrettyTable(["{wsessid", "{wprotocol", "{whost", "{wpuppet/character", "{wlocation"]) for sess in sorted(sessions, key=lambda x: x.sessid): char = player.get_puppet(sess) table.add_row([str(sess.sessid), str(sess.protocol_key), type(sess.address) == tuple and sess.address[0] or sess.address, char and str(char) or "None", char and str(char.location) or "N/A"]) string = "{wYour current session(s):{n\n%s" % table self.msg(string)
def func(self): """check inventory""" you = self.caller items = you.contents if not items: string = 'You are not carrying anything.' else: table = prettytable.PrettyTable(['name', 'desc_brief']) table.header = False table.border = False for item in items: imass = mass_unit(item.get_mass()) if hasattr( item, 'get_mass') else '- unknown -' second = imass if 'weight' in self.switches else item.db.desc_brief table.add_row([ '%s' % item.mxp_name(you.sessions, '@verb #%s' % item.id) if hasattr(item, 'mxp_name') else item.get_display_name( you.sessions), second and second or '' ]) imass = you.get_mass() if hasattr(item, 'get_mass') else '- unknown -' string = "|wYou and what you carry total |y%s|n:\n%s" % ( mass_unit(imass), table) you.msg(string)
def func(self): "Implement command" caller = self.caller switches = self.switches if switches and switches[0] not in ("list", "start", "stop", "delete"): caller.msg( "Usage: @service/<list|start|stop|delete> [servicename]") return # get all services service_collection = SESSIONS.server.services if not switches or switches[0] == "list": # Just display the list of installed services and their # status, then exit. table = prettytable.PrettyTable( ["{wService{n (use @services/start|stop|delete)", "{wstatus"]) table.align = 'l' for service in service_collection.services: table.add_row([ service.name, service.running and "{gRunning" or "{rNot Running" ]) caller.msg(str(table)) return # Get the service to start / stop try: service = service_collection.getServiceNamed(self.args) except Exception: string = 'Invalid service name. This command is case-sensitive. ' string += 'See @service/list for valid service name (enter the full name exactly).' caller.msg(string) return if switches[0] in ("stop", "delete"): # Stopping/killing a service gracefully closes it and disconnects # any connections (if applicable). delmode = switches[0] == "delete" if not service.running: caller.msg('That service is not currently running.') return if service.name[:7] == 'Evennia': if delmode: caller.msg( "You cannot remove a core Evennia service (named 'Evennia***')." ) return string = "You seem to be shutting down a core Evennia service (named 'Evennia***'). Note that" string += "stopping some TCP port services will *not* disconnect users *already*" string += "connected on those ports, but *may* instead cause spurious errors for them. To " string += "safely and permanently remove ports, change settings file and restart the server." caller.msg(string) if delmode: service.stopService() service_collection.removeService(service) caller.msg("Stopped and removed service '%s'." % self.args) else: service.stopService() caller.msg("Stopped service '%s'." % self.args) return if switches[0] == "start": #Starts a service. if service.running: caller.msg('That service is already running.') return caller.msg("Starting service '%s'." % self.args) service.startService()
def func(self): """Get all connected players by polling session.""" player = self.player session_list = SESSIONS.get_sessions() session_list = sorted(session_list, key=lambda o: o.player.key) show_session_data = player.check_permstring( 'Immortals') if 'f' in self.switches else False nplayers = (SESSIONS.player_count()) if 'f' in self.switches or 'full' in self.switches: if show_session_data: # privileged info - who/f by wizard or immortal table = prettytable.PrettyTable([ "|wPlayer Name", "|wOn for", "|wIdle", "|wCharacter", "|wRoom", "|wCmds", "|wProtocol", "|wHost" ]) for session in session_list: if not session.logged_in: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time player = session.get_player() puppet = session.get_puppet() location = puppet.location.key if puppet else 'None' table.add_row([ utils.crop(player.name, width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1), utils.crop(puppet.key if puppet else 'None', width=25), utils.crop(location, width=25), session.cmd_total, session.protocol_key, isinstance(session.address, tuple) and session.address[0] or session.address ]) else: # unprivileged info - who/f by player table = prettytable.PrettyTable( ["|wCharacter", "|wOn for", "|wIdle", "|wLocation"]) for session in session_list: if not session.logged_in: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time character = session.get_puppet() location = character.location.key if character and character.location else 'None' table.add_row([ utils.crop( character.key if character else '- Unknown -', width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1), utils.crop(location, width=25) ]) else: if 's' in self.switches or 'species' in self.switches or self.cmdstring == 'ws': my_character = self.caller.get_puppet(self.session) if not (my_character and my_character.location): self.msg("You can't see anyone here.") return table = prettytable.PrettyTable( ["|wCharacter", "|wOn for", "|wIdle", "|wSpecies"]) for session in session_list: character = session.get_puppet() # my_character = self.caller.get_puppet(self.session) if not session.logged_in or character.location != my_character.location: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time character = session.get_puppet() species = character.attributes.get('species', default='- None -') table.add_row([ utils.crop( character.key if character else '- Unknown -', width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1), utils.crop(species, width=25) ]) else: # unprivileged info - who table = prettytable.PrettyTable( ["|wCharacter", "|wOn for", "|wIdle"]) for session in session_list: if not session.logged_in: continue delta_cmd = time.time() - session.cmd_last_visible delta_conn = time.time() - session.conn_time character = session.get_puppet() table.add_row([ utils.crop( character.key if character else '- Unknown -', width=25), utils.time_format(delta_conn, 0), utils.time_format(delta_cmd, 1) ]) isone = nplayers == 1 string = "%s\n%s " % (table, 'A' if isone else nplayers) string += 'single' if isone else 'unique' plural = '' if isone else 's' string += " account%s logged in." % plural self.msg(string)