def getDescription(command, acl): if command not in commands: command=getRealCommand(command) acl=int(acl) paramstr="" desc=commandvalues[command][4] brief=desc[0] params=desc[1] ident_param=2 ident_param_desc=10 for param in params: acl_needed=float("inf") if AccessLevel.accessLevelSet(command.lower()+"_param_"+param[0].lower()): acl_needed=AccessLevel.getAccessLevel(command.lower()+"_param_"+param[0].lower()) if not acl_needed>=acl: continue paramstr=paramstr+"\n"+" "*ident_param paramstr=paramstr+"0x0088ff"+param[0]+":" paramdesc=textwrap.wrap(param[1], width=80-ident_param_desc) paramstr=paramstr+(ident_param_desc-ident_param-len(param[0]))*" "+" 0xffffff" paramstr=paramstr+paramdesc[0] paramdesc=paramdesc[1:] for desc in paramdesc: paramstr=paramstr+"\n"+" "+" "*ident_param_desc+" 0xffffff"+desc+"\n" if len(paramstr)==0: paramstr="None" return brief, paramstr
def getArgs(command,acl): if command not in commands: command=getRealCommand(command) minargcount, maxargcount, defaultvalues, names=commandvalues[command][:4] allowed=lambda i: not AccessLevel.accessLevelSet(command.lower()+"_param_"+i.lower()) or AccessLevel.isAllowed(command.lower()+"_param_"+i, acl) optionalargs=names[minargcount:] newnames=[] for name in names: if not allowed(name): if name not in optionalargs: minargcount-=1 elif name in optionalargs and optionalargs.index(name)==len(optionalargs)-1 and maxargcount==float("inf"): maxargcount=minargcount+len(optionalargs) continue maxargcount-=1 else: newnames.append(name) return minargcount, maxargcount, defaultvalues, newnames
def mode(acl, player, modename, when=None): if when!=None: ctype="set" else: ctype="vote" if locked: Armagetronad.PrintPlayerMessage(player, Messages.ModeLocked) return if modename.lower() not in SimpleMode.modes: Armagetronad.PrintPlayerMessage(player, Messages.ModeNotExist.format(mode=modename)) return if SimpleMode.current_mode: if SimpleMode.current_mode.name.lower()==modename.lower() and ctype=="vote": #@UndefinedVariable Armagetronad.PrintPlayerMessage(player, Messages.ModeAlreadyPlaying) return def removeActivateMethods(l, name="activate", cls=SimpleMode.Mode): ret=[] for i in l: if not inspect.ismethod(i): ret.append(i) continue if not (i.__name__==name and i.__self__.__class__==cls): ret.append(i) return ret def activator(w="roundend"): w=w.lower() if w=="now": SimpleMode.modes[modename.lower()].activate(kill=True) elif w in ("roundend","matchend"): w=w.capitalize() handler_list=getattr(LadderLogHandlers, "at"+w) handler_list=removeActivateMethods(handler_list) handler_list.append(SimpleMode.modes[modename.lower()].activate) #UndefiniedVariable setattr(LadderLogHandlers, "at"+w, handler_list) if ctype=="vote": try: target="Mode '"+modename+"'" act=lambda: activator("roundend") if SimpleMode.current_mode and SimpleMode.current_mode.lives>10: act=lambda: activator("now") Poll.Add(target, act, player) Poll.current_poll.SetPlayerVote(player, True) Poll.current_poll.CheckResult(only_sure=True) except RuntimeError as r: if r.args[1]==1: Armagetronad.PrintPlayerMessage(player, Messages.PollAlreadyActive) elif r.args[1]==2: Armagetronad.PrintPlayerMessage(player, Messages.SpecNotAllowed) Poll.Cancel() return elif ctype=="set": when=when.lower() access_name="mode_set_"+when if AccessLevel.accessLevelSet(access_name) and not AccessLevel.isAllowed(access_name, acl): Armagetronad.PrintPlayerMessage(player, "0xff0000You're not allowed to do that. ") return activator(when) if when=="roundend": Armagetronad.PrintMessage(Messages.NextRoundMode.format(mode=modename.lower(), player=Player.players[player].name)) elif when=="matchend": Armagetronad.PrintMessage(Messages.NextMatchMode.format(mode=modename.lower(), player=Player.players[player].name)) elif when=="now": Armagetronad.PrintMessage(Messages.ModeChanged.format(mode=modename.lower(), player=Player.players[player].name))