def refresh(self): """ Refresh as many parts of the server as possible: - MOTD - Mod credentials (unmodding users if necessary) - Characters - Music - Backgrounds - Gimp lines - Prompts - Commands - Banlists - Misc Data """ with open('config/config.yaml', 'r') as cfg: cfg_yaml = yaml.safe_load(cfg) self.config['motd'] = cfg_yaml['motd'].replace('\\n', ' \n') # Reload moderator passwords list and unmod any moderator affected by # credential changes or removals if isinstance(self.config['modpass'], str): self.config['modpass'] = { 'default': { 'password': self.config['modpass'] } } if isinstance(cfg_yaml['modpass'], str): cfg_yaml['modpass'] = { 'default': { 'password': cfg_yaml['modpass'] } } for profile in self.config['modpass']: if profile not in cfg_yaml['modpass'] or \ self.config['modpass'][profile] != cfg_yaml['modpass'][profile]: for client in filter( lambda c: c.mod_profile_name == profile, self.client_manager.clients): client.is_mod = False client.mod_profile_name = None database.log_misc('unmod.modpass', client) client.send_ooc( 'Your moderator credentials have been revoked.') self.config['modpass'] = cfg_yaml['modpass'] self.load_characters() self.load_iniswaps() self.load_music() self.load_backgrounds() self.load_gimps() self.load_prompts() self.load_ipranges() self.load_miscdata() import server.commands importlib.reload(server.commands) server.commands.reload()
def start(self): """Start the server.""" loop = asyncio.get_event_loop() bound_ip = '0.0.0.0' if self.config['local']: bound_ip = '127.0.0.1' ao_server_crt = loop.create_server(lambda: AOProtocol(self), bound_ip, self.config['port']) ao_server = loop.run_until_complete(ao_server_crt) if self.config['use_websockets']: ao_server_ws = websockets.serve(new_websocket_client(self), bound_ip, self.config['websocket_port']) asyncio.ensure_future(ao_server_ws) if self.config['use_masterserver']: self.ms_client = MasterServerClient(self) asyncio.ensure_future(self.ms_client.connect(), loop=loop) if self.config['zalgo_tolerance']: self.zalgo_tolerance = self.config['zalgo_tolerance'] if 'bridgebot' in self.config and self.config['bridgebot']['enabled']: self.bridgebot = Bridgebot(self, self.config['bridgebot']['channel'], self.config['bridgebot']['hub_id'], self.config['bridgebot']['area_id']) asyncio.ensure_future(self.bridgebot.init( self.config['bridgebot']['token']), loop=loop) asyncio.ensure_future(self.schedule_unbans()) database.log_misc('start') print('Server started and is listening on port {}'.format( self.config['port'])) try: loop.run_forever() except KeyboardInterrupt: pass database.log_misc('stop') ao_server.close() loop.run_until_complete(ao_server.wait_closed()) loop.close()
def refresh(self): """ Refresh as many parts of the server as possible: - MOTD - Mod credentials (unmodding users if necessary) - Characters - Music - Backgrounds - Commands - Banlists """ with open('config/config.yaml', 'r') as cfg: cfg_yaml = yaml.safe_load(cfg) self.config['motd'] = cfg_yaml['motd'].replace('\\n', ' \n') # Reload moderator passwords list and unmod any moderator affected by # credential changes or removals modfile = 'config/moderation.yaml' new = not os.path.exists(modfile) if not new: with open(modfile, 'r') as chars: mods = yaml.safe_load(chars) for client in self.client_manager.clients: if client.is_mod: check = False for item in mods: if item['name'] == client.mod_profile_name: check = True if check == False: client.is_mod = False client.mod_profile_name = None database.log_misc('unmod.modpass', client) client.send_ooc( 'Your moderator credentials have been revoked.') client.send_command('AUTH', '-1') if isinstance(self.config['modpass'], str): self.config['modpass'] = { 'default': { 'password': self.config['modpass'] } } if isinstance(cfg_yaml['modpass'], str): cfg_yaml['modpass'] = { 'default': { 'password': cfg_yaml['modpass'] } } for profile in self.config['modpass']: if profile not in cfg_yaml['modpass'] or \ self.config['modpass'][profile] != cfg_yaml['modpass'][profile]: for client in filter( lambda c: c.mod_profile_name == profile, self.client_manager.clients): client.is_mod = False client.mod_profile_name = None database.log_misc('unmod.modpass', client) client.send_ooc( 'Your moderator credentials have been revoked.') client.send_command('AUTH', '-1') self.config['modpass'] = cfg_yaml['modpass'] self.load_characters() self.load_iniswaps() self.load_music() self.load_backgrounds() self.load_ipranges() import server.commands importlib.reload(server.commands) server.commands.reload()