def net_cmd_hi(self, args): """Handshake. HI#<hdid:string>#% :param args: a list containing all the arguments """ if self.client.is_checked: self.client.disconnect() return if not self.validate_net_cmd(args, self.ArgType.STR, needs_auth=False): return hdid = self.client.hdid = args[0] ipid = self.client.ipid database.add_hdid(ipid, hdid) ban = database.find_ban(ipid, hdid) if ban is not None: try: special_ban_data = json.loads(ban.ban_data) except (ValueError, TypeError): special_ban_data = None if special_ban_data is not None: try: if special_ban_data['ban_type'] == 'area_curse': self.client.area_curse = special_ban_data[ 'target_area'] self.client.area_curse_info = ban self.client.change_area( self.server.area_manager.get_area_by_id( self.client.area_curse)) except (KeyError, ValueError): pass else: if ban.unban_date is not None: unban_date = arrow.get(ban.unban_date) else: unban_date = 'N/A' msg = f'{ban.reason}\r\n' msg += f'ID: {ban.ban_id}\r\n' msg += f'Until: {unban_date.humanize()}' database.log_connect(self.client, failed=True) self.client.send_command('BD', msg) self.client.disconnect() return self.client.is_checked = True database.log_connect(self.client, failed=False) self.client.send_command('ID', self.client.id, self.server.software, self.server.version) self.client.send_command('PN', self.server.player_count, self.server.config['playerlimit'])
def net_cmd_hi(self, args): """ Handshake. HI#<hdid:string>#% :param args: a list containing all the arguments """ if not self.validate_net_cmd(args, ArgType.STR, needs_auth=False): return hdid = self.client.hdid = args[0] ipid = self.client.ipid database.add_hdid(ipid, hdid) ban = database.find_ban(ipid, hdid) if ban is not None: if ban.unban_date is not None: unban_date = arrow.get(ban.unban_date) else: unban_date = 'N/A' msg = f'{ban.reason}\r\n' msg += f'ID: {ban.ban_id}\r\n' if unban_date == 'N/A': msg += f'Until: {unban_date}' else: msg += f'Until: {unban_date.humanize()}' database.log_connect(self.client, failed=True) self.client.send_command('BD', msg) self.client.disconnect() return else: self.client.is_checked = True database.log_connect(self.client, failed=False) self.client.send_command('ID', self.client.id, self.server.software, self.server.version) self.client.send_command('PN', self.server.player_count, self.server.config['playerlimit'])
def ooc_cmd_baninfo(client, arg): """ Get information about a ban. Usage: /baninfo <id> ['ban_id'|'ipid'|'hdid'] By default, id identifies a ban_id. """ args = arg.split(' ') if len(arg) == 0: raise ArgumentError('You must specify an ID.') elif len(args) == 1: lookup_type = 'ban_id' else: lookup_type = args[1] if lookup_type not in ('ban_id', 'ipid', 'hdid'): raise ArgumentError('Incorrect lookup type.') ban = database.find_ban(**{lookup_type: args[0]}) if ban is None: client.send_ooc('No ban found for this ID.') else: msg = f'Ban ID: {ban.ban_id}\n' msg += 'Affected IPIDs: ' + ', '.join( [str(ipid) for ipid in ban.ipids]) + '\n' msg += 'Affected HDIDs: ' + ', '.join(ban.hdids) + '\n' msg += f'Reason: "{ban.reason}"\n' msg += f'Banned by: {ban.banned_by_name} ({ban.banned_by})\n' ban_date = arrow.get(ban.ban_date) msg += f'Banned on: {ban_date.format()} ({ban_date.humanize()})\n' if ban.unban_date is not None: unban_date = arrow.get(ban.unban_date) msg += f'Unban date: {unban_date.format()} ({unban_date.humanize()})' else: msg += 'Unban date: N/A' client.send_ooc(msg)
def ooc_cmd_baninfo(client, arg): """ Get information about a ban. Usage: /baninfo <id> ['ban_id'|'ipid'|'hdid'] By default, id identifies a ban_id. """ args = arg.split(" ") if len(arg) == 0: raise ArgumentError("You must specify an ID.") elif len(args) == 1: lookup_type = "ban_id" else: lookup_type = args[1] if lookup_type not in ("ban_id", "ipid", "hdid"): raise ArgumentError("Incorrect lookup type.") ban = database.find_ban(**{lookup_type: args[0]}) if ban is None: client.send_ooc("No ban found for this ID.") else: msg = f"Ban ID: {ban.ban_id}\n" msg += "Affected IPIDs: " + \ ", ".join([str(ipid) for ipid in ban.ipids]) + "\n" msg += "Affected HDIDs: " + ", ".join(ban.hdids) + "\n" msg += f'Reason: "{ban.reason}"\n' msg += f"Banned by: {ban.banned_by_name} ({ban.banned_by})\n" ban_date = arrow.get(ban.ban_date) msg += f"Banned on: {ban_date.format()} ({ban_date.humanize()})\n" if ban.unban_date is not None: unban_date = arrow.get(ban.unban_date) msg += f"Unban date: {unban_date.format()} ({unban_date.humanize()})" else: msg += "Unban date: N/A" client.send_ooc(msg)
def kickban(client, arg: str, ban_hdid): args = shlex.split(arg) ban_id = None default_ban_duration = client.server.config['default_ban_duration'] if len(args) < 2: raise ArgumentError('Not enough arguments.') elif len(args) == 2: ipid = _convert_ipid_to_int(args[0]) ban_id = args[1] reason = None ban_duration = parse(str(default_ban_duration), granularity='hours') unban_date = arrow.get().shift(hours=ban_duration).datetime elif len(args) == 3: ipid = _convert_ipid_to_int(args[0]) reason = args[1] duration = args[2] ban_duration = parse(str(duration), granularity='hours') if duration is None: raise ArgumentError('Invalid ban duration.') elif 'perma' in duration.lower(): unban_date = None else: if ban_duration is not None: unban_date = arrow.get().shift(hours=ban_duration).datetime else: raise ArgumentError(f'{duration} is an invalid ban duration') else: raise ArgumentError( f'Ambiguous input: {arg}\nPlease wrap your arguments ' 'in quotes.') try: raw_ipid = args[0] ipid = int(raw_ipid) except ValueError: raise ClientError(f'{raw_ipid} does not look like a valid IPID.') if ban_id != None: existing_ban = database.find_ban(None, None, ban_id) if existing_ban: if bool(existing_ban.unbanned) == True: raise ClientError(f'{ban_id} is already unbanned.') ban_id = database.ban(ipid, reason, ban_type='ipid', banned_by=client, ban_id=ban_id, unban_date=unban_date) targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if targets: for c in targets: if ban_hdid: database.ban(c.hdid, reason, ban_type='hdid', ban_id=ban_id) c.send_command('KB', reason) c.disconnect() database.log_misc('ban', client, target=c, data={'reason': reason}) client.send_ooc(f'{len(targets)} clients were kicked.') client.send_ooc(f'{ipid} was banned. Ban ID: {ban_id}')