import es, os, playerlib, popuplib, gamethread, services # People who can change maps options are # mani_admins - everyone in mani's clients.txt # steamid - specific steamid # if you have group auth set up, anyone with map_admin may use it admins = ['STEAM_0:0:11089864', 'mani_admins'] def load2(): if not es.exists('saycommand', '!maps'): es.regsaycmd('!maps', 'maps/show_maps') if not es.exists('saycommand', '!changemap'): es.regsaycmd('!changemap', 'maps/changemap') maps().make_menus() def unload(): if es.exists('saycommand', '!maps'): es.unregsaycmd('!maps') if es.exists('saycommand', '!changemap'): es.unregsaycmd('!changemap') popuplib.delete('Map List') popuplib.delete('Change Map') def show_maps(): userid = es.getcmduserid() popuplib.send('Map List', userid) def changemap(): userid = es.getcmduserid() if is_authed(userid): popuplib.send('Change Map', userid) def return_admins(): if os.path.is_file(es.getAddonPath('maps').replace('addons/eventscripts/maps', 'cfg/mani_admin_plugin/clients.txt')): admins = [] a = open(es.getAddonPath('maps').replace('addons/eventscripts/maps', 'cfg/mani_admin_plugin/clients.txt'), 'r') b = a.readlines() a.close() c = [] for a in b: a = a.replace('\t', '').replace(' ', '') if not a.startswith('//'): c.append(a) for a in c: if a.lower().startswith('"steam""steam_0:'): admins.append(a.lower().replace('"steam""', '').replace('"', '').replace('\n', '').upper()) return admins def is_authed(userid): if es.getplayersteamid(userid) in admins or isAuthed(userid) or (es.getplayersteamid(userid) in return_admins() and 'mani_admins' in admins): return 1 else: es.tell(userid, '#green', 'Sorry, you are not authorized to run this command') return 0 class maps: def return_maps(self): map_list = [] for map in os.listdir(es.getAddonPath('maps').replace('addons/eventscripts/', '')): if map.endswith(('.bsp', '.bz2')): map_list.append(map.replace('.bsp', '')) return map_list def make_menus(self): show_maps = popuplib.easymenu('Map List', '_popup_choice', show_all_maps) change_map = popuplib.easymenu('Change Map', '_popup_choice', change_map2) amaps = self.return_maps() amaps.sort() for map in amaps: show_maps.addoption(map, map) change_map.addoption(map, map) def show_all_maps(userid, choice, popupid): popuplib.send('Map List', userid) def change_map2(userid, choice, popupid): es.server.queuecmd('changelevel %s'%choice) gamethread.delayed(0, load2) def setup_auth(): # Thanks, SD global isAuthed if services.isRegistered('auth'): auth_service = services.use('auth') auth_service.registerCapability('map_admin', auth_service.ADMIN) isAuthed = lambda x: auth_service.isUseridAuthorized(x, 'map_admin') else: isAuthed = lambda x: False setup_auth()