/ban, /kick, /mute, /unmute, /unban now allow for multiple people.

Their IPIDs should be appended after one another with a space inbetween,
so: `/ban 45123 42130 39212` for example.
Further, they now all lead through the user as to what they're doing.
This commit is contained in:
Cerapter 2018-08-29 00:40:43 +02:00
parent 712b683fd5
commit 46e64d6077

View File

@ -330,22 +330,34 @@ def ooc_cmd_kick(client, arg):
raise ClientError('You must be authorized to do that.') raise ClientError('You must be authorized to do that.')
if len(arg) == 0: if len(arg) == 0:
raise ArgumentError('You must specify a target. Use /kick <ipid>.') raise ArgumentError('You must specify a target. Use /kick <ipid>.')
targets = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False) args = list(arg.split(' '))
client.send_host_message('Attempting to ban {} IPIDs.'.format(len(args)))
for raw_ipid in args:
try:
ipid = int(raw_ipid)
except:
raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid))
targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False)
if targets: if targets:
for c in targets: for c in targets:
logger.log_server('Kicked {}.'.format(c.ipid), client) logger.log_server('Kicked {}.'.format(c.ipid), client)
client.send_host_message("{} was kicked.".format(c.get_char_name())) client.send_host_message("{} was kicked.".format(c.get_char_name()))
c.disconnect() c.disconnect()
else: else:
client.send_host_message("No targets found.") client.send_host_message("No targets with the IPID {} were found.".format(ipid))
def ooc_cmd_ban(client, arg): def ooc_cmd_ban(client, arg):
if not client.is_mod: if not client.is_mod:
raise ClientError('You must be authorized to do that.') raise ClientError('You must be authorized to do that.')
if len(arg) == 0:
raise ArgumentError('You must specify a target. Use /ban <ipid>.')
args = list(arg.split(' '))
client.send_host_message('Attempting to ban {} IPIDs.'.format(len(args)))
for raw_ipid in args:
try: try:
ipid = int(arg.strip()) ipid = int(raw_ipid)
except: except:
raise ClientError('You must specify ipid') raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid))
try: try:
client.server.ban_manager.add_ban(ipid) client.server.ban_manager.add_ban(ipid)
except ServerError: except ServerError:
@ -362,12 +374,17 @@ def ooc_cmd_ban(client, arg):
def ooc_cmd_unban(client, arg): def ooc_cmd_unban(client, arg):
if not client.is_mod: if not client.is_mod:
raise ClientError('You must be authorized to do that.') raise ClientError('You must be authorized to do that.')
if len(arg) == 0:
raise ArgumentError('You must specify a target. Use /unban <ipid>.')
args = list(arg.split(' '))
client.send_host_message('Attempting to unban {} IPIDs.'.format(len(args)))
for raw_ipid in args:
try: try:
client.server.ban_manager.remove_ban(int(arg.strip())) client.server.ban_manager.remove_ban(int(raw_ipid))
except: except:
raise ClientError('You must specify ipid') raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid))
logger.log_server('Unbanned {}.'.format(arg), client) logger.log_server('Unbanned {}.'.format(raw_ipid), client)
client.send_host_message('Unbanned {}'.format(arg)) client.send_host_message('Unbanned {}'.format(raw_ipid))
def ooc_cmd_play(client, arg): def ooc_cmd_play(client, arg):
if not client.is_mod: if not client.is_mod:
@ -382,25 +399,49 @@ def ooc_cmd_mute(client, arg):
if not client.is_mod: if not client.is_mod:
raise ClientError('You must be authorized to do that.') raise ClientError('You must be authorized to do that.')
if len(arg) == 0: if len(arg) == 0:
raise ArgumentError('You must specify a target.') raise ArgumentError('You must specify a target. Use /mute <ipid>.')
args = list(arg.split(' '))
client.send_host_message('Attempting to mute {} IPIDs.'.format(len(args)))
for raw_ipid in args:
try: try:
c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] ipid = int(raw_ipid)
c.is_muted = True
client.send_host_message('{} existing client(s).'.format(c.get_char_name()))
except: except:
client.send_host_message("No targets found. Use /mute <id> for mute") raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid))
try:
clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False)
msg = 'Muted ' + str(ipid) + ' clients'
for c in clients:
c.is_muted = True
msg += ' ' + c.get_char_name() + ' [' + c.id + '],'
msg = msg[:-1]
msg += '.'
client.send_host_message('{}'.format(msg))
except:
client.send_host_message("No targets found. Use /mute <ipid> for mute.")
def ooc_cmd_unmute(client, arg): def ooc_cmd_unmute(client, arg):
if not client.is_mod: if not client.is_mod:
raise ClientError('You must be authorized to do that.') raise ClientError('You must be authorized to do that.')
if len(arg) == 0: if len(arg) == 0:
raise ArgumentError('You must specify a target.') raise ArgumentError('You must specify a target.')
args = list(arg.split(' '))
client.send_host_message('Attempting to unmute {} IPIDs.'.format(len(args)))
for raw_ipid in args:
try: try:
c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] ipid = int(raw_ipid)
c.is_muted = False
client.send_host_message('{} existing client(s).'.format(c.get_char_name()))
except: except:
client.send_host_message("No targets found. Use /mute <id> for mute") raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid))
try:
clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False)
msg = 'Unmuted ' + str(ipid) + ' clients'
for c in clients:
c.is_muted = True
msg += ' ' + c.get_char_name() + ' [' + c.id + '],'
msg = msg[:-1]
msg += '.'
client.send_host_message('{}'.format(msg))
except:
client.send_host_message("No targets found. Use /unmute <ipid> for unmute.")
def ooc_cmd_login(client, arg): def ooc_cmd_login(client, arg):
if len(arg) == 0: if len(arg) == 0: