def func(self): """Implementing the function""" caller = self.caller args = self.args if not args: caller.msg("Usage: @boot[/switches] <account> [:reason]") return if ':' in args: args, reason = [a.strip() for a in args.split(':', 1)] else: args, reason = args, "" boot_list = [] if 'sid' in self.switches: # Boot a particular session id. sessions = SESSIONS.get_sessions(True) for sess in sessions: # Find the session with the matching session id. if sess.sessid == int(args): boot_list.append(sess) break else: # Boot by account object pobj = search.account_search(args) if not pobj: caller.msg("Account %s was not found." % args) return pobj = pobj[0] if not pobj.access(caller, 'boot'): string = "You don't have the permission to boot %s." % ( pobj.key, ) caller.msg(string) return # we have a bootable object with a connected user matches = SESSIONS.sessions_from_account(pobj) for match in matches: boot_list.append(match) if not boot_list: caller.msg( "No matching sessions found. The Account does not seem to be online." ) return # Carry out the booting of the sessions in the boot list. feedback = None if 'quiet' not in self.switches: feedback = "You have been disconnected by %s.\n" % caller.name if reason: feedback += "\nReason given: %s" % reason for session in boot_list: session.msg(feedback) session.account.disconnect_session_from_account(session)
def func(self): """Implementing the function""" caller = self.caller args = self.args if not args: caller.msg("Usage: @boot[/switches] <account> [:reason]") return if ':' in args: args, reason = [a.strip() for a in args.split(':', 1)] else: args, reason = args, "" boot_list = [] if 'sid' in self.switches: # Boot a particular session id. sessions = SESSIONS.get_sessions(True) for sess in sessions: # Find the session with the matching session id. if sess.sessid == int(args): boot_list.append(sess) break else: # Boot by account object pobj = search.account_search(args) if not pobj: caller.msg("Account %s was not found." % args) return pobj = pobj[0] if not pobj.access(caller, 'boot'): string = "You don't have the permission to boot %s." % (pobj.key, ) caller.msg(string) return # we have a bootable object with a connected user matches = SESSIONS.sessions_from_account(pobj) for match in matches: boot_list.append(match) if not boot_list: caller.msg("No matching sessions found. The Account does not seem to be online.") return # Carry out the booting of the sessions in the boot list. feedback = None if 'quiet' not in self.switches: feedback = "You have been disconnected by %s.\n" % caller.name if reason: feedback += "\nReason given: %s" % reason for session in boot_list: session.msg(feedback) session.account.disconnect_session_from_account(session)
def func(self): """Implements the command.""" caller = self.caller args = self.args if hasattr(caller, 'account'): caller = caller.account if not args: self.msg( "Usage: @delaccount <account/user name or #id> [: reason]") return reason = "" if ':' in args: args, reason = [arg.strip() for arg in args.split(':', 1)] # We use account_search since we want to be sure to find also accounts # that lack characters. accounts = search.account_search(args) if not accounts: self.msg('Could not find an account by that name.') return if len(accounts) > 1: string = "There were multiple matches:\n" string += "\n".join(" %s %s" % (account.id, account.key) for account in accounts) self.msg(string) return # one single match account = accounts.first() if not account.access(caller, 'delete'): string = "You don't have the permissions to delete that account." self.msg(string) return uname = account.username # boot the account then delete self.msg("Informing and disconnecting account ...") string = "\nYour account '%s' is being *permanently* deleted.\n" % uname if reason: string += " Reason given:\n '%s'" % reason account.msg(string) account.delete() self.msg("Account %s was successfully deleted." % uname)
def func(self): """Implements the command.""" caller = self.caller args = self.args if hasattr(caller, 'account'): caller = caller.account if not args: self.msg("Usage: @delaccount <account/user name or #id> [: reason]") return reason = "" if ':' in args: args, reason = [arg.strip() for arg in args.split(':', 1)] # We use account_search since we want to be sure to find also accounts # that lack characters. accounts = search.account_search(args) if not accounts: self.msg('Could not find an account by that name.') return if len(accounts) > 1: string = "There were multiple matches:\n" string += "\n".join(" %s %s" % (account.id, account.key) for account in accounts) self.msg(string) return # one single match account = accounts.pop() if not account.access(caller, 'delete'): string = "You don't have the permissions to delete that account." self.msg(string) return uname = account.username # boot the account then delete self.msg("Informing and disconnecting account ...") string = "\nYour account '%s' is being *permanently* deleted.\n" % uname if reason: string += " Reason given:\n '%s'" % reason account.msg(string) account.delete() self.msg("Account %s was successfully deleted." % uname)
def func(self): """List the accounts""" caller = self.caller args = self.args if "delete" in self.switches: account = getattr(caller, "account") if not account or not account.check_permstring("Developer"): caller.msg("You are not allowed to delete accounts.") return if not args: caller.msg("Usage: accounts/delete <name or #id> [: reason]") return reason = "" if ":" in args: args, reason = [arg.strip() for arg in args.split(":", 1)] # We use account_search since we want to be sure to find also accounts # that lack characters. accounts = search.account_search(args) if not accounts: self.msg("Could not find an account by that name.") return if len(accounts) > 1: string = "There were multiple matches:\n" string += "\n".join(" %s %s" % (account.id, account.key) for account in accounts) self.msg(string) return account = accounts.first() if not account.access(caller, "delete"): self.msg("You don't have the permissions to delete that account.") return username = account.username # ask for confirmation confirm = ( "It is often better to block access to an account rather than to delete it. " "|yAre you sure you want to permanently delete " "account '|n{}|y'|n yes/[no]?".format(username) ) answer = yield (confirm) if answer.lower() not in ("y", "yes"): caller.msg("Canceled deletion.") return # Boot the account then delete it. self.msg("Informing and disconnecting account ...") string = "\nYour account '%s' is being *permanently* deleted.\n" % username if reason: string += " Reason given:\n '%s'" % reason account.msg(string) logger.log_sec( "Account Deleted: %s (Reason: %s, Caller: %s, IP: %s)." % (account, reason, caller, self.session.address) ) account.delete() self.msg("Account %s was successfully deleted." % username) return # No switches, default to displaying a list of accounts. if self.args and self.args.isdigit(): nlim = int(self.args) else: nlim = 10 naccounts = AccountDB.objects.count() # typeclass table dbtotals = AccountDB.objects.object_totals() typetable = self.styled_table( "|wtypeclass|n", "|wcount|n", "|w%%|n", border="cells", align="l" ) for path, count in dbtotals.items(): typetable.add_row(path, count, "%.2f" % ((float(count) / naccounts) * 100)) # last N table plyrs = AccountDB.objects.all().order_by("db_date_created")[max(0, naccounts - nlim) :] latesttable = self.styled_table( "|wcreated|n", "|wdbref|n", "|wname|n", "|wtypeclass|n", border="cells", align="l" ) for ply in plyrs: latesttable.add_row( utils.datetime_format(ply.date_created), ply.dbref, ply.key, ply.path ) string = "\n|wAccount typeclass distribution:|n\n%s" % typetable string += "\n|wLast %s Accounts created:|n\n%s" % (min(naccounts, nlim), latesttable) caller.msg(string)