def _validateAuthCapability(name, auth_capability, auth_recommendedlevel, command_type): """ Raises an error if only one auth argument is provided or both arguments are provided but there is no available authorization service """ if auth_capability is None and not auth_recommendedlevel is None: raise ValueError, 'auth_capability is required when auth_recommendedlevel is provided' elif not auth_capability is None and auth_recommendedlevel is None: raise ValueError, 'auth_recommendedlevel is required when auth_capability is provided' elif not auth_capability is None and not auth_recommendedlevel is None: if not services.isRegistered('auth'): raise KeyError, "Cannot register " + command_type + " command '%s' as no authorization service is loaded" % name
def _validateAuthCapability(name, auth_capability, auth_recommendedlevel, command_type): """ Raises an error if only one auth argument is provided or both arguments are provided but there is no available authorization service """ if auth_capability is None and not auth_recommendedlevel is None: raise ValueError('auth_capability is required when auth_recommendedlevel is provided') elif not auth_capability is None and auth_recommendedlevel is None: raise ValueError('auth_recommendedlevel is required when auth_capability is provided') elif not auth_capability is None and not auth_recommendedlevel is None: if not services.isRegistered('auth'): raise KeyError(f"Cannot register {command_type} command '{name}' as no authorization service is loaded")
text = lambda identifier, options = {}, lang = "en" : "No strings.ini found in ../addons/eventscripts/%(basename)s/%(basename)s.py" % {"basename" : info.basename} """ Load the dictionary """ dictPath = os.path.join( es.getAddonPath( info.basename ), "data.db" ) if os.path.isfile(dictPath): fileStream = open(dictPath, 'r') mapDicts = cPickle.load(fileStream) fileStream.close() """ Load the languages """ langPath = os.path.join( es.getAddonPath( info.basename ), "strings.ini" ) if os.path.isfile(langPath): text = langlib.Strings(langPath) """ Set up an auth check service, to return whether or not the user is authed. """ if services.isRegistered('auth'): auth_service = services.use('auth') auth_service.registerCapability('surftimer', auth_service.ADMIN) isAuthed = lambda x: auth_service.isUseridAuthorized(x, 'surftimer') else: isAuthed = lambda x: False def load(): """ If the script is loaded halfway through a load, ensure the delays start """ if str(currentMap): es_map_start({'mapname':str(currentMap)}) es.regsaycmd('!restart', 'surftimer/restart', 'Teleport back to start') def unload(): del started[:] players.clear()
cfg = cfglib.AddonCFG(CFG_CONFIG_PATH) cfg.text("*****************************************************************") cfg.text("*** %s Config" %info.name) cfg.text("*****************************************************************") cfg.text(' ') SA_DURATION = cfg.cvar('sa_duration', 11, 'Duration of one advert to stay. Minimum is 11!') SA_DEFAULT_COLOR = cfg.cvar('sa_default_color', '#red', 'Default color if none was specified for an advert. List of colors below.') SA_REFRESH_ON_ROUND = cfg.cvar('sa_refresh_on_round', 0, 'Refresh advert list every round') cfg.text(' ') cfg.text('List of available colors:') for color in sorted(COLORS): cfg.text(" -" + color) cfg.write() cfg.execute() if services.isRegistered('auth'): auth_service = services.use('auth') auth_service.registerCapability('add_ad_permission', auth_service.ADMIN) isAuthed = lambda x: auth_service.isUseridAuthorized(x, 'add_ad_permission') else: isAuthed = lambda x: False def load(): global adverts adverts = getAdverts() printAdverts() def unload(): gamethread.cancelDelayed('adverts_delay') cmdlib.unregisterClientCommand('add_advert') cmdlib.unregisterClientCommand('delete_advert')