Beispiel #1
0
def ooc_cmd_kick(client, arg: str) -> None:
    """
	Kick a player.
	Usage: /kick <ipid|*|**> [reason]
	Special cases:
	 - "*" kicks everyone in the current area.
	 - "**" kicks everyone in the server.
	"""
    w = Webhooks(client.server)
    if len(arg) == 0:
        raise ArgumentError(
            'You must specify a target. Use /kick <ipid> [reason]')
    elif arg[0] == '*':
        targets = [c for c in client.area.clients if c != client]
    elif arg[0] == '**':
        targets = [
            c for c in client.server.client_manager.clients if c != client
        ]
    else:
        targets = None

    args = list(arg.split(' '))
    if targets is None:
        raw_ipid = args[0]
        try:
            ipid = int(raw_ipid)
        except:
            raise ClientError(f'{raw_ipid} does not look like a valid IPID.')
        targets = client.server.client_manager.get_targets(
            client, TargetType.IPID, ipid, False)

    if targets:
        reason = ' '.join(args[1:])
        if reason == '':
            reason = 'N/A'
        for c in targets:
            if c.is_admin:
                client.send_ooc(f'{c.charname} is an admin, cannot kick them.')
                continue
            database.log_misc('kick',
                              client,
                              target=c,
                              data={'reason': reason})
            w.kick(char=c.char_name, ipid=c.ipid, reason=reason)
            client.send_ooc("{} was kicked.".format(c.char_name))
            c.send_command('KK', f'Kicked: "{reason}"')
            c.disconnect()
    else:
        client.send_ooc(f'No targets with the IPID {ipid} were found.')
Beispiel #2
0
def ooc_cmd_unmod(client, arg):
    """
	Log out as a moderator.
	Usage: /unmod
	"""
    w = Webhooks(client.server)
    client.is_mod = False
    client.is_admin = False
    login_name = client.mod_profile_name
    client.mod_profile_name = None
    if client.area.evidence_mod == 'HiddenCM':
        client.area.broadcast_evidence_list()
    client.send_ooc('You\'re not a mod anymore.')
    client.send_command('AUTH', '-1')
    w.unmod(login_name=login_name)
Beispiel #3
0
def ooc_cmd_unwarn(client, arg: str) -> None:
    """
	Remove a list of warn entries from the database.
	Usage: /unwarn <warn_id ...>
	"""
    w = Webhooks(client.server)
    if len(arg) == 0:
        raise ArgumentError(
            'You must specify a target. Use /unwarn <warn_id...>')
    args = list(arg.split(' '))
    client.send_ooc(f'Attempting to revoke {len(args)} warn(s)...')
    for warn_id in args:
        if database.unwarn(warn_id):
            client.send_ooc(f'Removed warn entry with ID {warn_id}.')
            w.unwarn(client=client, warn_id=warn_id)
        else:
            client.send_ooc(f'No entry exists for warn ID {warn_id}.')
        database.log_misc('unwarn', client, data={'id': warn_id})
Beispiel #4
0
def ooc_cmd_unban(client, arg: str) -> None:
    """
	Unban a list of users.
	Usage: /unban <ban_id...>
	"""
    w = Webhooks(client.server)
    if len(arg) == 0:
        raise ArgumentError(
            'You must specify a target. Use /unban <ban_id...>')
    args = list(arg.split(' '))
    client.send_ooc(f'Attempting to lift {len(args)} ban(s)...')
    for ban_id in args:
        if database.unban(ban_id):
            client.send_ooc(f'Removed ban ID {ban_id}.')
            w.unban(client=client, ban_id=ban_id)
        else:
            client.send_ooc(f'{ban_id} is not on the ban list.')
        database.log_misc('unban', client, data={'id': ban_id})
Beispiel #5
0
def ooc_cmd_warn(client, arg: str) -> None:
    """
	Warn the given user.
	Usage: /warn <ipid> [reason]
	"""
    w = Webhooks(client.server)
    if len(arg) == 0:
        raise ArgumentError(
            'You must specify a target. Use /warn <ipid> [reason]')
    elif len(arg) == 1:
        raise ArgumentError(
            'You must specify a reason. Use /warn <ipid> [reason]')
    else:
        targets = None

    args = list(arg.split(' '))
    if targets is None:
        raw_ipid = args[0]
        try:
            ipid = int(raw_ipid)
        except:
            raise ClientError(f'{raw_ipid} does not look like a valid IPID.')
        targets = client.server.client_manager.get_targets(
            client, TargetType.IPID, ipid, False)
    warn_id = None
    if targets:
        reason = ' '.join(args[1:])
        if reason == '':
            reason = 'N/A'
        for c in targets:
            warn_id = database.warn(target=c, reason=reason, warned_by=client)
            w.warn(char=c.char_name,
                   ipid=c.ipid,
                   warn_id=warn_id,
                   reason=reason)
            client.send_ooc("{} was warned. Warn ID: {}".format(
                c.char_name, warn_id))
            c.send_ooc(
                f"You were warned by a moderator. (ID: {warn_id}) Reason: {reason}"
            )
            c.send_command('WARN', f'"{reason}" (ID: {warn_id})')
            c.send_command('BEEP')
    else:
        client.send_ooc(f'No targets with the IPID {ipid} were found.')
Beispiel #6
0
def ooc_cmd_login(client, arg: str) -> None:
    """
	Logs the user in as a moderator.

    Calls auth_mod to check whether or not the user's login attempt is 
    valid. 

	Should return a message in-client confirming login and 
	log profile in the server's internal log. 

    Will throw an error and log it if not and send an OOC message in-client
    stating that the user's login attempt was invalid. 

    Usage: /login <password> (The user might not require using a mod pass
    if their profile already exists in the moderation.yaml)

    Parameters:
    client = An instance of the class Client. 
    arg = The mod pass used in order to log in.

    Precondition: arg is a valid mod pass. 
    Otherwise, throws login_invalid error. 


	"""
    w = Webhooks(client.server)
    login_name = None
    try:
        login_name = client.auth_mod(arg)
    except ClientError:
        client.send_command('AUTH', '0')
        database.log_misc('login.invalid', client)
        raise

    client.send_ooc('Logged in as a moderator.')
    client.send_command('AUTH', '1')
    w.login(client=client)
    database.log_misc('login', client, data={'profile': login_name})
Beispiel #7
0
	def net_cmd_zz(self, args):
		"""Sent on mod call.

		"""
		from server.webhooks import Webhooks
		if not self.client.is_checked:
			return
		
		if not self.client.permission:
			self.client.send_ooc('You need permission to use a web client, please ask staff via our discord.')
			return

		if self.client.is_muted:  # Checks to see if the client has been muted by a mod
			self.client.send_ooc('You are muted by a moderator.')
			return

		if self.client.char_id == -1:
			self.client.send_ooc(
				"You cannot call a moderator while spectating.")
			return

		if not self.client.can_call_mod():
			self.client.send_ooc(
				"You must wait 30 seconds between mod calls.")
			return

		current_time = strftime("%H:%M", localtime())
		w = Webhooks(self.server)
		if len(args) < 1:
			self.server.send_all_cmd_pred(
				'ZZ',
				'[{}] {} ({}) in [{}]{} without reason (not using 2.6?)'.format(
					current_time, self.client.char_name,
					self.client.ip, self.client.area.abbreviation, self.client.area.name),
				pred=lambda c: c.is_mod)
			self.client.set_mod_call_delay()
			database.log_room('modcall', self.client, self.client.area)
			w.modcall(char=self.client.char_name, ipid=self.client.ip, area=self.client.area)
		else:
			self.server.send_all_cmd_pred(
				'ZZ',
				'[{}] {} ({}) in [{}]{} with reason: {}'.format(
					current_time, self.client.char_name,
					self.client.ip, self.client.area.abbreviation, self.client.area.name,
					args[0][:100]),
				pred=lambda c: c.is_mod)
			self.client.set_mod_call_delay()
			database.log_room('modcall', self.client, self.client.area, message=args[0])
			w.modcall(char=self.client.char_name, ipid=self.client.ip, area=self.client.area, reason=args[0][:100])
Beispiel #8
0
def kickban(client, arg, ban_hdid):
    args = shlex.split(arg)
    w = Webhooks(client.server)
    if len(args) < 2:
        raise ArgumentError('Not enough arguments.')
    elif len(args) == 2:
        reason = None
        ban_id = None
        try:
            ban_id = int(args[1])
            unban_date = None
        except ValueError:
            reason = args[1]
            unban_date = arrow.get().shift(hours=6).datetime
    elif len(args) == 3:
        ban_id = None
        reason = args[1]
        if 'perma' in args[2]:
            unban_date = None
        else:
            duration = pytimeparse.parse(args[2], granularity='hours')
            if duration is None:
                raise ArgumentError('Invalid ban duration.')
            unban_date = arrow.get().shift(seconds=duration).datetime
    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.')
    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 item in mods:
            ipids = []
            try:
                ipids = item['ipid'].split()
            except:
                ipids.append(item['ipid'])
            if ipid in ipids:
                if item['status'] == 'admin':
                    return client.send_ooc('Can\'t ban an admin.')

    ban_id = database.ban(ipid,
                          reason,
                          ban_type='ipid',
                          banned_by=client,
                          ban_id=ban_id,
                          unban_date=unban_date)

    if ipid != None:
        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)
                    w.ban(char=c.char_name,
                          ipid=c.ipid,
                          ban_id=ban_id,
                          reason=reason,
                          hdid=c.hdid)
                else:
                    w.ban(char=c.char_name,
                          ipid=c.ipid,
                          ban_id=ban_id,
                          reason=reason)
                c.send_command('KB', f'Banned: "{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}')