Beispiel #1
0
 def html_grief_check(ignore, player, time):
     color = False
     minutes = float(time or 2)
     if minutes < 0.0:
         raise ValueError()
     time = reactor.seconds() - minutes * 60.0
     blocks_removed = player.blocks_removed or []
     blocks = [b[1] for b in blocks_removed if b[0] >= time]
     player_name = player.name
     if color:
         player_name = (('\x0303' if player.team.id else '\x0302') +
             player_name + '\x0f')
     message = '%s removed %s block%s in the last ' % (player_name,
         len(blocks) or 'no', '' if len(blocks) == 1 else 's')
     if minutes == 1.0:
         minutes_s = 'minute'
     else:
         minutes_s = '%s minutes' % ('%f' % minutes).rstrip('0').rstrip('.')
     message += minutes_s + '.'
     if len(blocks):
         infos = set(blocks)
         infos.discard(None)
         if color:
             names = [('\x0303' if team else '\x0302') + name for name, team in
                 infos]
         else:
             names = set([name for name, team in infos])
         if len(names) > 0:
             message += (' Some of them were placed by ' +
                 ('\x0f, ' if color else ', ').join(names))
             message += '\x0f.' if color else '.'
         else:
             message += ' All of them were map blocks.'
         last = blocks_removed[-1]
         time_s = prettify_timespan(reactor.seconds() - last[0], get_seconds = True)
         message += ' Last one was destroyed %s ago' % time_s
         whom = last[1]
         if whom is None and len(names) > 0:
             message += ', and was part of the map'
         elif whom is not None:
             name, team = whom
             if color:
                 name = ('\x0303' if team else '\x0302') + name + '\x0f'
             message += ', and belonged to %s' % name
         message += '.'
     switch_sentence = False
     if player.last_switch is not None and player.last_switch >= time:
         time_s = prettify_timespan(reactor.seconds() - player.last_switch,
             get_seconds = True)
         message += ' %s joined %s team %s ago' % (player_name,
             player.team.name, time_s)
         switch_sentence = True
     teamkills = len([t for t in player.teamkill_times or [] if t >= time])
     if teamkills > 0:
         s = ', and killed' if switch_sentence else ' %s killed' % player_name
         message += s + ' %s teammates in the last %s' % (teamkills, minutes_s)
     if switch_sentence or teamkills > 0:
         message += '.'
     return message
Beispiel #2
0
def kick_afk(connection, minutes, amount=None):
    protocol = connection.protocol
    minutes = int(minutes)
    if minutes < 1:
        raise ValueError("Minutes cannot be < 1")
    to_kick = []
    seconds = minutes * 60.0
    minutes_s = prettify_timespan(seconds)
    lower_bound = reactor.seconds() - seconds
    for conn in list(protocol.connections.values()):
        if not conn.admin and conn.last_activity < lower_bound:
            to_kick.append(conn)
    if not to_kick:
        return S_NO_PLAYERS_INACTIVE.format(time=minutes_s)
    to_kick.sort(key=attrgetter('last_activity'))
    to_kick.sort(key=lambda conn: conn.name is None)
    amount = amount or len(to_kick)
    kicks = 0
    for conn in to_kick[:amount]:
        if conn.name:
            conn.afk_kick()
            kicks += 1
        else:
            conn.disconnect()
    message = S_AFK_KICKED.format(num_players=kicks,
                                  num_connections=amount - kicks,
                                  time=minutes_s)
    protocol.irc_say('* ' + message)
    if connection in protocol.players.values():
        return message
Beispiel #3
0
def check_for_ban(connection, value):
    ban = connection.protocol.check_ban(value)
    if ban is not None:
        name, reason, time = None, None, None
        try:
            name, reason, time = ban
        except ValueError:
            reason = ban

        ip = value
        #IP found in local ban list
        if name is not None:
            if time is not None:
                time = prettify_timespan(time - reactor.seconds())
                ban_time = "Banned for %s" % (time)
            else:
                ban_time = "Permabanned"
            message = "%s found. %s for %s under the name %s" % (ip, ban_time,
                                                                 reason, name)
        #IP found in external
        else:
            message = "%s found on external ban list. Banned for %s" % (ip,
                                                                        reason)
        return message
    else:
        return "%s not found" % (value)
Beispiel #4
0
def kick_afk(connection, minutes, amount = None):
    protocol = connection.protocol
    minutes = int(minutes)
    if minutes < 1:
        raise ValueError()
    to_kick = []
    no_kick = False
    seconds = minutes * 60.0
    minutes_s = prettify_timespan(seconds)
    lower_bound = reactor.seconds() - seconds
    for conn in protocol.connections.values():
        for t in ('admin', 'moderator', 'guard', 'trusted'):
            if t in conn.user_types:
                no_kick = True
        if not no_kick and conn.last_activity < lower_bound:
            to_kick.append(conn)
    if not to_kick:
        return S_NO_PLAYERS_INACTIVE.format(time = minutes_s)
    to_kick.sort(key = attrgetter('last_activity'))
    to_kick.sort(key = lambda conn: conn.name is None)
    amount = amount or len(to_kick)
    kicks = 0
    for conn in to_kick[:amount]:
        if conn.name:
            conn.afk_kick()
            kicks += 1
        else:
            conn.disconnect()
    message = S_AFK_KICKED.format(num_players = kicks,
        num_connections = amount - kicks, time = minutes_s)
    protocol.irc_say('* ' + message)
    if connection in protocol.players:
        return message
Beispiel #5
0
def kick_afk(connection, minutes, amount=None):
    protocol = connection.protocol
    minutes = int(minutes)
    if minutes < 1:
        raise ValueError()
    to_kick = []
    no_kick = False
    seconds = minutes * 60.0
    minutes_s = prettify_timespan(seconds)
    lower_bound = reactor.seconds() - seconds
    for conn in protocol.connections.values():
        for t in ('admin', 'moderator', 'guard', 'trusted'):
            if t in conn.user_types:
                no_kick = True
        if not no_kick and conn.last_activity < lower_bound:
            to_kick.append(conn)
    if not to_kick:
        return S_NO_PLAYERS_INACTIVE.format(time=minutes_s)
    to_kick.sort(key=attrgetter('last_activity'))
    to_kick.sort(key=lambda conn: conn.name is None)
    amount = amount or len(to_kick)
    kicks = 0
    for conn in to_kick[:amount]:
        if conn.name:
            conn.afk_kick()
            kicks += 1
        else:
            conn.disconnect()
    message = S_AFK_KICKED.format(num_players=kicks,
                                  num_connections=amount - kicks,
                                  time=minutes_s)
    protocol.irc_say('* ' + message)
    if connection in protocol.players:
        return message
Beispiel #6
0
 def afk_kick(self):
     if self.name:
         time_inactive = reactor.seconds() - self.last_activity
         time_inactive = max(1.0, round(time_inactive / 60.0)) * 60.0
         elapsed = prettify_timespan(time_inactive)
         self.kick(S_AFK_KICK_REASON.format(time=elapsed))
     else:
         self.disconnect()
Beispiel #7
0
 def afk_kick(self):
     if self.name:
         time_inactive = reactor.seconds() - self.last_activity
         time_inactive = max(1.0, round(time_inactive / 60.0)) * 60.0
         elapsed = prettify_timespan(time_inactive)
         self.kick(S_AFK_KICK_REASON.format(time = elapsed))
     else:
         self.disconnect()
Beispiel #8
0
 def on_hit(self, hit_amount, player, type, grenade):
     cur_timestamp = reactor.seconds() - spawn_protect_time
     if cur_timestamp < hit_player.spawn_timestamp:
         timespan = -(cur_timestamp - hit_player.spawn_timestamp)
         self.send_chat(
             "%s is spawn-protected for %s." %
             (player.name, prettify_timespan(timespan, True)))
         return False
     return connection.on_hit(self, hit_amount, player, type, grenade)
Beispiel #9
0
 def on_hit(self, hit_amount, player, type, grenade):
     cur_timestamp = reactor.seconds() - spawn_protect_time
     if cur_timestamp < hit_player.spawn_timestamp:
         timespan = -(cur_timestamp - hit_player.spawn_timestamp)
         self.send_chat(
         "%s is spawn-protected for %s." %
             (player.name,
              prettify_timespan(timespan, True)))
         return False
     return connection.on_hit(self, hit_amount, player, type, grenade)
Beispiel #10
0
def ban(connection, value, *arg):
    import time
    duration, reason = get_ban_arguments(connection, arg)
    ntime = time.ctime(time.time())
    expires = time.ctime(time.time() + duration * 60)
    player = get_player(connection.protocol, value)
    reason = '[IGN: %s] [By: %s] [Time: %s] [Duration: %s] [Expires: %s] [Offense: %s]' % (
        player.name, connection.forum_name if hasattr(connection, 'forum_name')
        else connection.name, ntime, prettify_timespan(
            duration * 60), expires, reason)
    player.ban(reason, duration)
Beispiel #11
0
def ban(connection, value, *arg):
	import time
	duration, reason = get_ban_arguments(connection, arg)
	ntime = time.ctime( time.time() )
	expires = time.ctime( time.time() + duration * 60 )
	player = get_player(connection.protocol, value)
	reason = '[IGN: %s] [By: %s] [Time: %s] [Duration: %s] [Expires: %s] [Offense: %s]' % (
		player.name, connection.forum_name if hasattr(connection, 'forum_name') else connection.name,
		ntime, prettify_timespan(duration * 60), expires, reason
	)
	player.ban(reason, duration)
Beispiel #12
0
def set_time_limit(connection, duration):
    """
    Set this game time limit
    /timelimit <duration>
    """
    limit = cast_duration(duration)
    span = prettify_timespan(limit)
    protocol = connection.protocol
    # takes time in minutes
    protocol.set_time_limit(limit / 60)
    protocol.send_chat('Time limit set to {}'.format(span), irc=True)
Beispiel #13
0
def banip(connection, ip, *arg):
	import time
	duration, reason = get_ban_arguments(connection, arg)
	ntime = time.ctime( time.time() )
	expires = time.ctime( time.time() + duration * 60 )
	reason = '[By: %s] [Time: %s] [Duration: %s] [Expires: %s] [Offense: %s]' % (
		connection.forum_name if hasattr(connection, 'forum_name') else connection.name,
		ntime, prettify_timespan(duration * 60), expires, reason
	)

	try:
		connection.protocol.add_ban(ip, reason, duration)
	except ValueError:
		return 'Invalid IP address/network'
	reason = ': ' + reason if reason is not None else ''
	duration = duration or None

	if duration is None:
		return 'IP/network %s permabanned%s' % (ip, reason)
	else:
		return 'IP/network %s banned for %s%s' % (ip,
			prettify_timespan(duration * 60), reason)
Beispiel #14
0
def banip(connection, ip, *arg):
    duration, reason = get_ban_arguments(connection, arg)
    try:
        connection.protocol.add_ban(ip, reason, duration)
    except ValueError:
        return 'Invalid IP address/network'
    reason = ': ' + reason if reason is not None else ''
    duration = duration or None
    if duration is None:
        return 'IP/network %s permabanned%s' % (ip, reason)
    else:
        return 'IP/network %s banned for %s%s' % (
            ip, prettify_timespan(duration * 60), reason)
Beispiel #15
0
def banip(connection, ip, *arg):
    import time
    duration, reason = get_ban_arguments(connection, arg)
    ntime = time.ctime(time.time())
    expires = time.ctime(time.time() + duration * 60)
    reason = '[By: %s] [Time: %s] [Duration: %s] [Expires: %s] [Offense: %s]' % (
        connection.forum_name if hasattr(connection, 'forum_name') else
        connection.name, ntime, prettify_timespan(
            duration * 60), expires, reason)

    try:
        connection.protocol.add_ban(ip, reason, duration)
    except ValueError:
        return 'Invalid IP address/network'
    reason = ': ' + reason if reason is not None else ''
    duration = duration or None

    if duration is None:
        return 'IP/network %s permabanned%s' % (ip, reason)
    else:
        return 'IP/network %s banned for %s%s' % (
            ip, prettify_timespan(duration * 60), reason)
Beispiel #16
0
def banip(connection, ip, *arg):
    duration, reason = get_ban_arguments(connection, arg)
    try:
        connection.protocol.add_ban(ip, reason, duration)
    except ValueError:
        return 'Invalid IP address/network'
    reason = ': ' + reason if reason is not None else ''
    duration = duration or None
    if duration is None:
        return 'IP/network %s permabanned%s' % (ip, reason)
    else:
        return 'IP/network %s banned for %s%s' % (ip,
            prettify_timespan(duration * 60), reason)
Beispiel #17
0
 def show_result(self):
     result = self.votes_left()['name']
     if result == "extend":
         tl = self.protocol.set_time_limit(self.extension_time, True)
         span = prettify_timespan(tl * 60.0)
         self.protocol.send_chat('Mapvote ended. Current map will '
             'continue for %s.' % span, irc = True)
         self.protocol.autoschedule_votemap()
     else:
         self.protocol.send_chat('Mapvote ended. Next map will be: %s.' % 
             result, irc = True)
         self.protocol.planned_map = check_rotation([result])[0]
     self.set_cooldown()
Beispiel #18
0
 def ban(self, reason = None, duration = None):
     reason = ': ' + reason if reason is not None else ''
     duration = duration or None
     if duration is None:
         message = '%s permabanned%s' % (self.name, reason)
     else:
         message = '%s banned for %s%s' % (self.name,
             prettify_timespan(duration * 60), reason)
     if self.protocol.on_ban_attempt(self, reason, duration):
         self.protocol.send_chat(message, irc = True)
         self.protocol.on_ban(self, reason, duration)
         if self.address[0]=="127.0.0.1":
             self.protocol.send_chat("Ban ignored: localhost")
         else:
             self.protocol.add_ban(self.address[0], reason, duration,
                                   self.name)
Beispiel #19
0
 def ban(self, reason=None, duration=None):
     reason = ': ' + reason if reason is not None else ''
     duration = duration or None
     if duration is None:
         message = '%s permabanned%s' % (self.name, reason)
     else:
         message = '%s banned for %s%s' % (
             self.name, prettify_timespan(duration * 60), reason)
     if self.protocol.on_ban_attempt(self, reason, duration):
         self.protocol.send_chat(message, irc=True)
         self.protocol.on_ban(self, reason, duration)
         if self.address[0] == "127.0.0.1":
             self.protocol.send_chat("Ban ignored: localhost")
         else:
             self.protocol.add_ban(self.address[0], reason, duration,
                                   self.name)
Beispiel #20
0
def check_for_ban(connection, value):
    ban = connection.protocol.check_ban(value)
    if ban is not None:
        name, reason, time = None, None, None
        try:
            name, reason, time = ban
        except ValueError:
            reason = ban    
            
        ip = value
        #IP found in local ban list
        if name is not None:
            if time is not None:
                time =  prettify_timespan(time - reactor.seconds())
                ban_time = "Banned for %s" %(time)
            else:
                ban_time = "Permabanned"
            message = "%s found. %s for %s under the name %s" %(ip, ban_time, reason, name)
        #IP found in external
        else:
            message = "%s found on external ban list. Banned for %s" %(ip, reason)
        return message
    else:
        return "%s not found" %(value)
Beispiel #21
0
 def html_get_afk(ignore, player):
     return prettify_timespan(reactor.seconds() - player.last_activity, True)
Beispiel #22
0
def afk(connection, player):
    player = get_player(connection.protocol, player)
    elapsed = prettify_timespan(reactor.seconds() - player.last_activity, True)
    return S_AFK_CHECK.format(player = player.name, time = elapsed)
def grief_check(connection, player, time = None):
    player = get_player(connection.protocol, player)
    protocol = connection.protocol
    color = connection not in protocol.players and connection.colors
    minutes = float(time or 2)
    if minutes < 0.0:
        raise ValueError()
    time = seconds() - minutes * 60.0
    blocks_removed = player.blocks_removed or []
    blocks = [b[1] for b in blocks_removed if b[0] >= time]
    player_name = player.name
    if color:
        player_name = (('\x0303' if player.team.id else '\x0302') +
            player_name + '\x0f')
    message = '%s removed %s block%s in the last ' % (player_name,
        len(blocks) or 'no', '' if len(blocks) == 1 else 's')
    if minutes == 1.0:
        minutes_s = 'minute'
    else:
        minutes_s = '%s minutes' % ('%f' % minutes).rstrip('0').rstrip('.')
    message += minutes_s + '.'
    if len(blocks):
        infos = set(blocks)
        infos.discard(None)
        if color:
            names = [('\x0303' if team else '\x0302') + name for name, team in
                infos]
        else:
            names = set([name for name, team in infos])
        namecheck = [[name, team, 0] for name, team in infos]
        if len(names) > 0:
            for f in range(len(namecheck)):
                for i in range(len(blocks_removed)):
                    if blocks_removed[i][1] is not None:
                        if namecheck[f][0] == blocks_removed[i][1][0] and namecheck[f][1] == blocks_removed[i][1][1] and blocks_removed[i][0] >= time:
                            namecheck[f][2] += 1
             
            message += (' Some of them were placed by ')
            for i in range(len(names)):
                message += ('\x0f, ' if color else ', ') + names[i] + "(" + str(namecheck[i][2]) + ")"
            userblocks = 0
            for i in range(len(namecheck)):
                userblocks = userblocks + namecheck[i][2]
            if userblocks == len(blocks):
                pass
            else:
                message += ('\x0f. ' if color else '. ') + str(len(blocks) - userblocks) + " were map blocks"
            message += '\x0f.' if color else '.'
        else:
            message += ' All of them were map blocks.'
        last = blocks_removed[-1]
        time_s = prettify_timespan(seconds() - last[0], get_seconds = True)
        message += ' Last one was destroyed %s ago' % time_s
        whom = last[1]
        if whom is None and len(names) > 0:
            message += ', and was part of the map'
        elif whom is not None:
            name, team = whom
            if color:
                name = ('\x0303' if team else '\x0302') + name + '\x0f'
            message += ', and belonged to %s' % name
        message += '.'
    switch_sentence = False
    if player.last_switch is not None and player.last_switch >= time:
        time_s = prettify_timespan(seconds() - player.last_switch,
            get_seconds = True)
        message += ' %s joined %s team %s ago' % (player_name,
            player.team.name, time_s)
        switch_sentence = True
    teamkills = len([t for t in player.teamkill_times or [] if t >= time])
    if teamkills > 0:
        s = ', and killed' if switch_sentence else ' %s killed' % player_name
        message += s + ' %s teammates in the last %s' % (teamkills, minutes_s)
    if switch_sentence or teamkills > 0:
        message += '.'
    votekick = getattr(protocol, 'votekick', None)
    if (votekick and votekick.victim is player and
        votekick.victim.world_object and votekick.instigator.world_object):
        instigator = votekick.instigator
        tiles = int(distance_3d_vector(player.world_object.position,
            instigator.world_object.position))
        instigator_name = (('\x0303' if instigator.team.id else '\x0302') +
            instigator.name + '\x0f')
        message += (' %s is %d tiles away from %s, who started the votekick.' %
            (player_name, tiles, instigator_name))
    return message
Beispiel #24
0
def afk(connection, player):
    player = get_player(connection.protocol, player)
    elapsed = prettify_timespan(reactor.seconds() - player.last_activity, True)
    return S_AFK_CHECK.format(player=player.name, time=elapsed)
Beispiel #25
0
def grief_check(connection, player, minutes=2):
    player = get_player(connection.protocol, player)
    protocol = connection.protocol
    color = connection not in protocol.players and connection.colors
    minutes = float(minutes)
    if minutes <= 0.0:
        raise ValueError('minutes must be number greater than 0')
    time = seconds() - minutes * 60.0
    blocks_removed = player.blocks_removed or []
    blocks = [b[1] for b in blocks_removed if b[0] >= time]
    player_name = player.name
    if color:
        player_name = (('\x0303' if player.team.id else '\x0302') +
                       player_name + '\x0f')
    message = '%s removed %s block%s in the last ' % (
        player_name, len(blocks) or 'no', '' if len(blocks) == 1 else 's')
    if minutes == 1.0:
        minutes_s = 'minute'
    else:
        minutes_s = '{:.1f} minutes'.format(minutes)
    message += minutes_s + '.'
    if len(blocks):
        infos = set(blocks)
        infos.discard(None)
        if color:
            names = [('\x0303' if team else '\x0302') + name
                     for name, team in infos]
        else:
            names = set([name for name, team in infos])
        if len(names) > 0:
            message += (' Some of them were placed by ' +
                        ('\x0f, ' if color else ', ').join(names))
            message += '\x0f.' if color else '.'
        else:
            message += ' All of them were map blocks.'
        last = blocks_removed[-1]
        time_s = prettify_timespan(seconds() - last[0], get_seconds=True)
        message += ' Last one was destroyed %s ago' % time_s
        whom = last[1]
        if whom is None and len(names) > 0:
            message += ', and was part of the map'
        elif whom is not None:
            name, team = whom
            if color:
                name = ('\x0303' if team else '\x0302') + name + '\x0f'
            message += ', and belonged to %s' % name
        message += '.'
    switch_sentence = False
    if player.last_switch is not None and player.last_switch >= time:
        time_s = prettify_timespan(seconds() - player.last_switch,
                                   get_seconds=True)
        message += ' %s joined %s team %s ago' % (player_name,
                                                  player.team.name, time_s)
        switch_sentence = True
    teamkills = len([t for t in player.teamkill_times or [] if t >= time])
    if teamkills > 0:
        s = ', and killed' if switch_sentence else ' %s killed' % player_name
        message += s + ' %s teammates in the last %s' % (teamkills, minutes_s)
    if switch_sentence or teamkills > 0:
        message += '.'
    votekick = getattr(protocol, 'votekick', None)
    if (votekick and votekick.victim is player and votekick.victim.world_object
            and votekick.instigator.world_object):
        instigator = votekick.instigator
        tiles = int(
            distance_3d_vector(player.world_object.position,
                               instigator.world_object.position))
        instigator_name = (('\x0303' if instigator.team.id else '\x0302') +
                           instigator.name + '\x0f')
        message += (' %s is %d tiles away from %s, who started the votekick.' %
                    (player_name, tiles, instigator_name))
    return message