def net_cmd_ct(self, args: List[str]): """ OOC Message CT#<name:string>#<message:string>#% """ pargs = self.process_arguments('CT', args) username, message = pargs['username'], pargs['message'] # Trim out any leading/trailing whitespace characters up to a chain of spaces username = Constants.trim_extra_whitespace(username) message = Constants.trim_extra_whitespace(message) if self.client.is_ooc_muted: # Checks to see if the client has been muted by a mod self.client.send_ooc("You have been muted by a moderator.") return if username == '' or not self.client.is_valid_name(username): self.client.send_ooc('You must insert a name with at least one letter.') return if username.startswith(' '): self.client.send_ooc('You must insert a name that starts with a letter.') return if Constants.contains_illegal_characters(username): self.client.send_ooc('Your name contains an illegal character.') return if (Constants.decode_ao_packet([self.server.config['hostname']])[0] in username or '$G' in username): self.client.send_ooc('That name is reserved.') return # After this the name is validated self.client.publish_inbound_command('CT', pargs) self.client.name = username if message.startswith('/'): spl = message[1:].split(' ', 1) cmd = spl[0] arg = '' if len(spl) == 2: arg = spl[1][:1024] arg = Constants.trim_extra_whitespace(arg) # Do it again because args may be weird try: called_function = 'ooc_cmd_{}'.format(cmd) function = None # Double assignment to check if it matched to a function later function = getattr(self.server.commands, called_function) except AttributeError: try: function = getattr(self.server.commands_alt, called_function) except AttributeError: self.client.send_ooc(f'Invalid command `{cmd}`.') if function: try: function(self.client, arg) except TsuserverException as ex: if ex.message: self.client.send_ooc(ex) else: self.client.send_ooc(type(ex).__name__) else: # Censor passwords if accidentally said without a slash in OOC for password in self.server.all_passwords: for login in ['login ', 'logincm ', 'loginrp ', 'logingm ']: if login + password in args[1]: message = message.replace(password, '[CENSORED]') if self.client.disemvowel: # If you are disemvoweled, replace string. message = Constants.disemvowel_message(message) if self.client.disemconsonant: # If you are disemconsonanted, replace string. message = Constants.disemconsonant_message(message) if self.client.remove_h: # If h is removed, replace string. message = Constants.remove_h_message(message) for client in self.client.area.clients: client.send_ooc(message, username=self.client.name) self.client.last_ooc_message = args[1] logger.log_server('[OOC][{}][{}][{}]{}' .format(self.client.area.id, self.client.get_char_name(), self.client.name, message), self.client) self.client.last_active = Constants.get_time()
def net_cmd_ct(self, args): """ OOC Message CT#<name:string>#<message:string>#% """ if self.client.is_ooc_muted: # Checks to see if the client has been muted by a mod self.client.send_ooc("You have been muted by a moderator.") return if not self.validate_net_cmd( args, ArgType.STR, ArgType.STR, needs_auth=False): return if args[0] == '' or not self.client.is_valid_name(args[0]): self.client.send_ooc( 'You must insert a name with at least one letter.') return if args[0].startswith(' '): self.client.send_ooc( 'You must insert a name that starts with a letter.') return if Constants.contains_illegal_characters(args[0]): self.client.send_ooc('Your name contains an illegal character.') return if self.server.config['hostname'] in args[0] or '<dollar>G' in args[0]: self.client.send_ooc('That name is reserved.') return # After this the name is validated if self.client.name != args[0] and self.client.fake_name != args[0]: if self.client.is_valid_name(args[0]): self.client.name = args[0] self.client.fake_name = args[0] else: self.client.fake_name = args[0] self.client.name = '' if args[1].startswith('/'): spl = args[1][1:].split(' ', 1) cmd = spl[0] arg = '' if len(spl) == 2: arg = spl[1][:1024] try: called_function = 'ooc_cmd_{}'.format(cmd) function = None # Double assignment to check if it matched to a function later function = getattr(self.server.commands, called_function) except AttributeError: try: function = getattr(self.server.commands_alt, called_function) except AttributeError: logger.log_print('Attribute error with ' + called_function) self.client.send_ooc('Invalid command.') if function: try: function(self.client, arg) except TsuserverException as ex: self.client.send_ooc(ex) else: # Censor passwords if accidentally said without a slash in OOC for password in self.server.all_passwords: for login in ['login ', 'logincm ', 'loginrp ', 'logingm ']: if login + password in args[1]: args[1] = args[1].replace(password, '[CENSORED]') if self.client.disemvowel: #If you are disemvoweled, replace string. args[1] = Constants.disemvowel_message(args[1]) if self.client.disemconsonant: #If you are disemconsonanted, replace string. args[1] = Constants.disemconsonant_message(args[1]) if self.client.remove_h: #If h is removed, replace string. args[1] = Constants.remove_h_message(args[1]) self.client.area.send_command('CT', self.client.name, args[1]) self.client.last_ooc_message = args[1] logger.log_server( '[OOC][{}][{}][{}]{}'.format(self.client.area.id, self.client.get_char_name(), self.client.name, args[1]), self.client) self.client.last_active = Constants.get_time()