diff --git a/server/client_manager.py b/server/client_manager.py index cec5739e..ff319a1b 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -18,7 +18,6 @@ import datetime import time -import warnings from server import client_changearea from server import fantacrypt @@ -164,8 +163,8 @@ def send_ooc_others(self, msg, username=None, allow_empty=False, self.server.make_all_clients_do("send_ooc", msg, pred=cond, allow_empty=allow_empty, username=username) - def send_ic(self, ic_params=None, params=None, sender=None, pred=None, not_to=None, - gag_replaced=False, is_staff=None, in_area=None, to_blind=None, to_deaf=None, + def send_ic(self, params=None, sender=None, pred=None, not_to=None, gag_replaced=False, + is_staff=None, in_area=None, to_blind=None, to_deaf=None, bypass_replace=False, bypass_deafened_starters=False, msg=None, pos=None, cid=None, ding=None, color=None, showname=None): @@ -173,24 +172,16 @@ def send_ic(self, ic_params=None, params=None, sender=None, pred=None, not_to=No # self is who is receiving the IC message at this particular moment # Assert correct call to the function - if ic_params is None and params is None and msg is None: + if params is None and msg is None: raise ValueError('Expected message.') - if ic_params is not None and params is not None: - raise ValueError('Conflicting ic_params and params') - - if ic_params is not None: - self.ic_params_deprecation_warning() - params = {self.packet_handler.MS_OUTBOUND.value[i][0]: ic_params[i] - for i in range(len(ic_params))} - # Fill in defaults # Expected behavior is as follows: - # If ic_params is None, then the sent IC message will only include custom details + # If params is None, then the sent IC message will only include custom details # about the ding and the message, everything else is fixed. However, sender details # are considered when replacing the parameters based on sender/receiver's properties - # If ic_params is not None, then the sent IC message will use the parameters given in - # ic_params, and use the properties of sender to replace the parameters if needed. + # If params is not None, then the sent IC message will use the parameters given in + # params, and use the properties of sender to replace the parameters if needed. pargs = {x: y for (x, y) in self.packet_handler.MS_OUTBOUND.value} if params is None: @@ -308,20 +299,19 @@ def pop_if_there(dictionary, argument): self.send_command('MS', *to_send) - def send_ic_others(self, ic_params=None, params=None, sender=None, bypass_replace=False, - pred=None, not_to=None, gag_replaced=False, is_staff=None, in_area=None, + def send_ic_others(self, params=None, sender=None, bypass_replace=False, pred=None, + not_to=None, gag_replaced=False, is_staff=None, in_area=None, to_blind=None, to_deaf=None, msg=None, pos=None, cid=None, ding=None, color=None, showname=None): - if ic_params is not None: - self.ic_params_deprecation_warning() + if not_to is None: not_to = {self} else: not_to = not_to.union({self}) for c in self.server.client_manager.clients: - c.send_ic(ic_params=None, params=None, sender=sender, bypass_replace=bypass_replace, - pred=pred, not_to=not_to, gag_replaced=gag_replaced, is_staff=is_staff, + c.send_ic(params=None, sender=sender, bypass_replace=bypass_replace, pred=pred, + not_to=not_to, gag_replaced=gag_replaced, is_staff=is_staff, in_area=in_area, to_blind=to_blind, to_deaf=to_deaf, msg=msg, pos=pos, cid=cid, ding=ding, color=color, showname=showname) @@ -1054,12 +1044,6 @@ def __repr__(self): .format(self.id, self.ipid, self.name, self.get_char_name(), self.showname, self.is_staff(), self.area.id)) - def ic_params_deprecation_warning(self): - message = ('Code is using old IC params syntax (using ic_params as an argument). ' - 'Please change it (or ask your server developer) so that it uses ' - 'params instead (pending removal in 4.2).') - warnings.warn(message, category=UserWarning, stacklevel=3) - def __init__(self, server, client_obj=None): if client_obj is None: self.client_obj = self.Client @@ -1231,7 +1215,7 @@ def get_target_public(self, client, identifier, only_in_area=False): """ split_identifier = identifier.split(' ') - multiple_match_message = '' + multiple_match_mes = '' valid_targets = list() def _discard_sneaked_if_needed(targets): @@ -1278,10 +1262,10 @@ def _discard_sneaked_if_needed(targets): # Otherwise, other identifiers may not be unique, so consider all possibilities # Pretend the identity is a character name, iniswapped to folder, a showname or OOC name possibilities = [ - (TargetType.CHAR_NAME, lambda target: target.get_char_name()), - (TargetType.CHAR_FOLDER, lambda target: target.char_folder), - (TargetType.SHOWNAME, lambda target: target.showname), - (TargetType.OOC_NAME, lambda target: target.name)] + (TargetType.CHAR_NAME, lambda target: target.get_char_name()), + (TargetType.CHAR_FOLDER, lambda target: target.char_folder), + (TargetType.SHOWNAME, lambda target: target.showname), + (TargetType.OOC_NAME, lambda target: target.name)] targets = set() # Match against everything @@ -1307,19 +1291,19 @@ def _discard_sneaked_if_needed(targets): else: # Otherwise, our identity guess was not precise enough, so keep track of that # for later and continue with the for loop - multiple_match_message = 'Multiple targets match identifier `{}`'.format(identity) + multiple_match_mes = 'Multiple targets match identifier `{}`'.format(identity) for target in sorted(list(targets), key=lambda c: c.id): char = target.get_char_name() if target.char_folder and target.char_folder != char: # Show iniswap if needed char = '{}/{}'.format(char, target.char_folder) - multiple_match_message += ('\r\n*[{}] {} ({}) (OOC: {})' - .format(target.id, char, target.showname, target.name)) + multiple_match_mes += ('\r\n*[{}] {} ({}) (OOC: {})' + .format(target.id, char, target.showname, target.name)) if not valid_targets or len(valid_targets) > 1: # If was able to match more than one at some point, return that - if multiple_match_message: - raise ClientError(multiple_match_message) + if multiple_match_mes: + raise ClientError(multiple_match_mes) # Otherwise, show that no match was ever found raise ClientError('No targets with identifier `{}` found.'.format(identifier)) diff --git a/server/commands_alt.py b/server/commands_alt.py index abe0146b..478b9d7d 100644 --- a/server/commands_alt.py +++ b/server/commands_alt.py @@ -38,79 +38,16 @@ def do_command_deprecated(command, client, arg): 'Please use /{} next time.'.format(command)) do_command(command, client, arg) -def ooc_cmd_zg(client, arg): - """ - Alias for /zone_global. - """ - - do_command('zone_global', client, arg) - -def ooc_cmd_allow_iniswap(client, arg): - """ - Deprecated for /can_iniswap. - """ - - do_command_deprecated('can_iniswap', client, arg) - -def ooc_cmd_delete_areareachlock(client, arg): - """ - Deprecated for /passage_clear. - """ - - do_command_deprecated('passage_clear', client, arg) - -def ooc_cmd_mutepm(client, arg): - """ - Deprecated for /toggle_pm. - """ - - do_command_deprecated('toggle_pm', client, arg) - -def ooc_cmd_restore_areareachlock(client, arg): - """ - Deprecated for /passage_restore. - """ - - do_command_deprecated('passage_restore', client, arg) - def ooc_cmd_showname_list(client, arg): """ - Deprecated for /showname_areas. - """ - - do_command_deprecated('showname_areas', client, arg) - -def ooc_cmd_toggle_areareachlock(client, arg): - """ - Deprecated for /can_passagelock. + Alias for /showname_areas. """ - do_command_deprecated('can_passagelock', client, arg) + do_command('showname_areas', client, arg) -def ooc_cmd_toggleglobal(client, arg): - """ - Deprecated for /toggle_global. - """ - - do_command_deprecated('toggle_global', client, arg) - -def ooc_cmd_toggle_rollp(client, arg): - """ - Deprecated for /can_rollp. - """ - - do_command_deprecated('can_rollp', client, arg) - -def ooc_cmd_toggle_rpgetarea(client, arg): - """ - Deprecated for /can_rpgetarea. - """ - - do_command_deprecated('can_rpgetarea', client, arg) - -def ooc_cmd_toggle_rpgetareas(client, arg): +def ooc_cmd_zg(client, arg): """ - Deprecated for /can_rpgetareas. + Alias for /zone_global. """ - do_command_deprecated('can_rpgetareas', client, arg) + do_command('zone_global', client, arg) diff --git a/server/tsuserver.py b/server/tsuserver.py index e74bf941..923b3a87 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -24,9 +24,6 @@ import sys import traceback import urllib.request -import warnings -import yaml - from server import logger from server.aoprotocol import AOProtocol from server.area_manager import AreaManager @@ -45,8 +42,8 @@ def __init__(self, protocol=None, client_manager=None, in_test=False): self.release = 4 self.major_version = 3 self.minor_version = 0 - self.segment_version = 'a3' - self.internal_version = '200115a' + self.segment_version = 'a4' + self.internal_version = '200115b' version_string = self.get_version_string() self.software = 'TsuserverDR {}'.format(version_string) self.version = 'TsuserverDR {} ({})'.format(version_string, self.internal_version) @@ -88,7 +85,6 @@ def __init__(self, protocol=None, client_manager=None, in_test=False): self.ipid_list = {} self.hdid_list = {} self.music_list = None - self._music_list_ao2 = None # Pending deprecation in 4.3 self.music_pages_ao1 = None self.backgrounds = None self.load_music() @@ -98,8 +94,6 @@ def __init__(self, protocol=None, client_manager=None, in_test=False): self.ms_client = None self.rp_mode = False self.user_auth_req = False - # self.client_tasks = dict() # KEPT FOR BACKWARDS COMPATIBILITY - # self.active_timers = dict() # KEPT FOR BACKWARDS COMPATIBILITY self.showname_freeze = False self.commands = importlib.import_module('server.commands') self.commands_alt = importlib.import_module('server.commands_alt') @@ -123,15 +117,16 @@ def start(self): server_name = self.config['masterserver_name'] logger.log_print('Starting a nonlocal server...') - ao_server_crt = self.loop.create_server(lambda: self.protocol(self), bound_ip, self.config['port']) - ao_server = self.loop.run_until_complete(ao_server_crt) + server = self.loop.create_server(lambda: self.protocol(self), bound_ip, self.config['port']) + ao_server = self.loop.run_until_complete(server) logger.log_pserver('Server started successfully!') if self.config['local']: host_ip = '127.0.0.1' else: - host_ip = urllib.request.urlopen('https://api.ipify.org', context=ssl.SSLContext()).read().decode('utf8') + request = urllib.request.urlopen('https://api.ipify.org', context=ssl.SSLContext()) + host_ip = request.read().decode('utf8') logger.log_pdebug('Server should be now accessible from {}:{}:{}' .format(host_ip, self.config['port'], server_name)) @@ -141,14 +136,16 @@ def start(self): if self.config['use_district']: self.district_client = DistrictClient(self) - self.district_connection = asyncio.ensure_future(self.district_client.connect(), loop=self.loop) + self.district_connection = asyncio.ensure_future(self.district_client.connect(), + loop=self.loop) print(' ') logger.log_print('Attempting to connect to district at {}:{}.' .format(self.config['district_ip'], self.config['district_port'])) if self.config['use_masterserver']: self.ms_client = MasterServerClient(self) - self.masterserver_connection = asyncio.ensure_future(self.ms_client.connect(), loop=self.loop) + self.masterserver_connection = asyncio.ensure_future(self.ms_client.connect(), + loop=self.loop) print(' ') logger.log_print('Attempting to connect to the master server at {}:{} with the ' 'following details:'.format(self.config['masterserver_ip'], @@ -482,7 +479,6 @@ def build_music_list_ao2(self, from_area=None, c=None, music_list=None, include_ if include_music: built_music_list.extend(self.prepare_music_list(c=c, specific_music_list=music_list)) - self._music_list_ao2 = built_music_list # Backwards compatibility return built_music_list def prepare_area_list(self, c=None, from_area=None): @@ -643,7 +639,7 @@ def send_error_report(self, client, cmd, args, ex): logger.log_error(info, server=self, errortype='C') if self.in_test: - raise + raise ex def broadcast_global(self, client, msg, as_mod=False, mtype="G", condition=lambda x: not x.muted_global): @@ -653,8 +649,8 @@ def broadcast_global(self, client, msg, as_mod=False, ooc_name += '[M]' self.send_all_cmd_pred('CT', ooc_name, msg, pred=condition) if self.config['use_district']: - self.district_client.send_raw_message( - 'GLOBAL#{}#{}#{}#{}'.format(int(as_mod), client.area.id, username, msg)) + msg = 'GLOBAL#{}#{}#{}#{}'.format(int(as_mod), client.area.id, username, msg) + self.district_client.send_raw_message(msg) def broadcast_need(self, client, msg): char_name = client.displayname @@ -662,88 +658,8 @@ def broadcast_need(self, client, msg): area_id = client.area.id self.send_all_cmd_pred('CT', '{}'.format(self.config['hostname']), '=== Advert ===\r\n{} in {} [{}] needs {}\r\n===============' - .format(char_name, area_name, area_id, msg), pred=lambda x: not x.muted_adverts) + .format(char_name, area_name, area_id, msg), + pred=lambda x: not x.muted_adverts) if self.config['use_district']: - self.district_client.send_raw_message('NEED#{}#{}#{}#{}'.format(char_name, area_name, area_id, msg)) - - """ - OLD CODE. - KEPT FOR BACKWARDS COMPATIBILITY WITH PRE 4.2 TSUSERVERDR. - """ - - def create_task(self, client, args): - self.task_deprecation_warning() - self.tasker.create_task(client, args) - - def cancel_task(self, task): - """ Cancels current task and sends order to await cancellation """ - self.task_deprecation_warning() - self.tasker.cancel_task(task) - - def remove_task(self, client, args): - """ Given client and task name, removes task from server.client_tasks, and cancels it """ - self.task_deprecation_warning() - self.tasker.remove_task(client, args) - - def get_task(self, client, args): - """ Returns actual task instance """ - self.task_deprecation_warning() - return self.tasker.get_task(client, args) - - def get_task_args(self, client, args): - """ Returns input arguments of task """ - self.task_deprecation_warning() - return self.tasker.get_task_args(client, args) - - def get_task_attr(self, client, args, attr): - """ Returns task attribute """ - self.task_deprecation_warning() - return self.tasker.get_task_attr(client, args, attr) - - def set_task_attr(self, client, args, attr, value): - """ Sets task attribute """ - self.task_deprecation_warning() - self.tasker.set_task_attr(client, args, attr, value) - - @property - def active_timers(self): - self.task_deprecation_warning() - return self.tasker.active_timers - - @property - def client_tasks(self): - self.task_deprecation_warning() - return self.tasker.client_tasks - - @active_timers.setter - def active_timers(self, value): - self.task_deprecation_warning() - self.tasker.active_timers = value - - @client_tasks.setter - def client_tasks(self, value): - self.task_deprecation_warning() - self.tasker.client_tasks = value - - @property - def music_list_ao2(self): - self.music_list_ao2_deprecation_warning() - return self._music_list_ao2 - - @music_list_ao2.setter - def music_list_ao2(self, value): - self.music_list_ao2_deprecation_warning() - self._music_list_ao2 = value - - def task_deprecation_warning(self): - message = ('Code is using old task syntax (assuming it is a server property/method). ' - 'Please change it (or ask your server developer) so that it uses ' - 'server.tasker instead (pending removal in 4.3).') - warnings.warn(message, category=UserWarning, stacklevel=3) - - def music_list_ao2_deprecation_warning(self): - message = ('Code is currently using old music_list_ao2_syntax (assuming it is a server ' - 'property/method). Please change it (or ask your server develop) so that it ' - 'uses the return value of self.build_music_list_ao2() instead (pending removal ' - 'in 4.3).') - warnings.warn(message, category=UserWarning, stacklevel=3) + msg = 'NEED#{}#{}#{}#{}'.format(char_name, area_name, area_id, msg) + self.district_client.send_raw_message(msg) diff --git a/tests/test_global.py b/tests/test_global.py index cac1effa..41135d72 100644 --- a/tests/test_global.py +++ b/tests/test_global.py @@ -42,35 +42,6 @@ def test_02_muteglobal(self): self.assertFalse(self.c2.muted_global) self.assertFalse(self.c3.muted_global) - def test_03_deprecatedname(self): - """ - Situation: Client uses /toggleglobal (deprecated name). It works... for now. - """ - - self.c0.ooc('/toggleglobal') - self.c0.assert_ooc('This command is deprecated and pending removal in 4.3. Please use ' - '/toggle_global next time.') - self.c0.assert_ooc('You will no longer receive global messages.', over=True) - self.c1.assert_no_ooc() - self.c2.assert_no_ooc() - self.c3.assert_no_ooc() - self.assertTrue(self.c0.muted_global) - self.assertFalse(self.c1.muted_global) - self.assertFalse(self.c2.muted_global) - self.assertFalse(self.c3.muted_global) - - self.c0.ooc('/toggleglobal') - self.c0.assert_ooc('This command is deprecated and pending removal in 4.3. Please use ' - '/toggle_global next time.') - self.c0.assert_ooc('You will now receive global messages.', over=True) - self.c1.assert_no_ooc() - self.c2.assert_no_ooc() - self.c3.assert_no_ooc() - self.assertFalse(self.c0.muted_global) - self.assertFalse(self.c1.muted_global) - self.assertFalse(self.c2.muted_global) - self.assertFalse(self.c3.muted_global) - class TestGlobal_02_Announce(_TestOOC): def test_01_wrongarguments(self): """