def onPlayerCommands(cn, args): if args != '': sauerbomber.playerMessage(cn, error('Usage: #playercommands')) else: msg = blue('Available commands: ') for command in command_info.keys(): msg += '#' + command + ' ' sauerbomber.playerMessage(cn, orange(msg))
def onSetMaster(cn, givenhash): p = player(cn) adminhash = sauerbomber.hashPassword(cn, sauerbomber.adminPassword()) try: na = dbmanager.query(NickAccount).filter(NickAccount.nick==p.name()).one() except NoResultFound: if givenhash != adminhash: p.message(error('Your name is not assigned to any accounts')) except MultipleResultsFound: p.message(error('Multiple names linked to this account. Contact the system administrator.')) else: nickhash = sauerbomber.hashPassword(cn, na.user.password) if givenhash == nickhash: login(cn, na.user) else: if givenhash != adminhash: p.message(error('Invalid password'))
def trigger(self, cn, command, text): p = player(cn) if self.command_handlers.has_key(command): for func in self.command_handlers[command]: try: func(cn, text) except UsageError, e: try: usages = command_info[command].usages except KeyError: usages = [] p.message(error('Invalid Usage of #' + command + ' command. ' + str(e))) for usage in usages: p.message(info('Usage: ' + command + ' ' + usage)) except StateError, e: p.message(error(str(e))) except ArgumentValueError, e: p.message(error('Invalid argument. ' + str(e)))
def onLoginCommand(cn, args): '''@description Login to server account @usage email password @public''' args = args.split(' ') if len(args) != 2: raise UsageError() user = userAuth(args[0], args[1]) if user: login(cn, user) else: sauerbomber.playerMessage(cn, error('Invalid login.'))
def msgHelpText(cn, cmd): try: helpinfo = command_info[cmd] except KeyError: sauerbomber.playerMessage(cn, error('Command not found')) else: msgs = [] try: msgs.append(helpinfo.description) except AttributeError: pass for usage in helpinfo.usages: msgs.append(usage) for msg in msgs: sauerbomber.playerMessage(cn, info(msg))
def onAuthSuccess(cn, name): if currentAdmin() != None: sauerbomber.playerMessage(cn, error("Admin is present")) return sauerbomber.setMaster(cn)
p.message(info('Usage: ' + command + ' ' + usage)) except StateError, e: p.message(error(str(e))) except ArgumentValueError, e: p.message(error('Invalid argument. ' + str(e))) except ValueError: p.message(error('Value Error: Did you specify a valid cn?')) exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() logging.warn('Uncaught ValueError raised in command handler.') logging.warn(traceback.format_exc()) except: exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() logging.warn('Uncaught exception occured in command handler.') logging.warn(traceback.format_exc()) else: sauerbomber.playerMessage(cn, error('Command not found')) def onMsg(self, cn, text): if len(text) > 0 and self.prefixes.find(text[0]) != -1: cmd = text[1:].split(' ')[0] self.trigger(cn, cmd, text[len(cmd)+2:]) return False return True commandmanager = CommandManager() def registerCommandHandler(command, func): help.loadCommandInfo(command, func) commandmanager.register(command, func) class commandHandler(object): def __init__(self, name):