Esempio n. 1
0
def paint(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()

    player.painting = not player.painting

    message = 'now painting' if player.painting else 'no longer painting'
    player.send_chat("You're %s" % message)
    if connection is not player and connection in protocol.players:
        connection.send_chat('%s is %s' % (player.name, message))
    protocol.irc_say('* %s is %s' % (player.name, message))
Esempio n. 2
0
def timed_mute(connection, *args):
    protocol = connection.protocol
    if len(args) < 3:
        return '/tm <nick> <time> <reason>'

    nick = args[0]
    time = int(args[1])
    reason = join_arguments(args[2:])
    player = get_player(protocol, nick)

    if time < 0:
        raise ValueError()

    if not player.mute:
        TimedMute(player, time, reason)
    else:
        return '%s is already muted!' % nick
Esempio n. 3
0
def togglevotekick(connection, *args):
    """
    Toggles votekicking for a player or the whole server
    /tvk <player> or /tvk
    """
    protocol = connection.protocol
    if len(args) == 0:
        protocol.votekick_enabled = not protocol.votekick_enabled
        return S_VOTEKICKING_SET.format(
            set=('enabled' if protocol.votekick_enabled else 'disabled'))
    try:
        player = get_player(protocol, args[0])
    except CommandError:
        return 'Invalid Player'
    player.votekick_enabled = not player.votekick_enabled
    return S_VOTEKICK_USER_SET.format(user=player.name, set=(
        'enabled' if player.votekick_enabled else 'disabled'))
Esempio n. 4
0
def god(connection, player=None):
    """
    Go into god mode and inform everyone on the server of it
    /god [player]
    """
    if player:
        connection = get_player(connection.protocol, player)
    elif connection not in connection.protocol.players.values():
        return 'Unknown player'

    connection.god = not connection.god  # toggle godmode

    if connection.god:
        message = '%s entered GOD MODE!' % connection.name
    else:
        message = '%s returned to being a mere human' % connection.name
    connection.protocol.send_chat(message, irc=True)
Esempio n. 5
0
def give_fly(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()
    if player in protocol.flying:
        protocol.flying.remove(player)
        player.send_chat("You are no longer flying")
    else:
        protocol.flying.append(player)
        player.send_chat("You are now flying")
        player.send_chat("Press ctrl(crouch) to move down")
        player.send_chat("Press V(sneak) to move up")
        player.send_chat("Press 4(grenade) for accelerate")
Esempio n. 6
0
def deaf(connection, value=None):
    """
    Make you or a given player no longer receive chat messages
    /deaf [player]
    """
    if value is not None:
        if not connection.admin and not connection.rights.deaf:
            return 'No administrator rights!'
        connection = get_player(connection.protocol, value)
    message = '%s deaf' % ('now' if not connection.deaf else 'no longer')
    connection.protocol.irc_say('%s is %s' % (connection.name, message))
    message = "You're " + message
    if connection.deaf:
        connection.deaf = False
        connection.send_chat(message)
    else:
        connection.send_chat(message)
        connection.deaf = True
Esempio n. 7
0
def fly(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        if connection.admin:
            player = get_player(connection.protocol, player)
        else:
            return 'No administrator rights!'
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError('Invalid player')
    player.fly = not player.fly

    message = 'now flying' if player.fly else 'no longer flying'
    player.send_chat("You're {}".format(message))
    if connection is not player and connection in protocol.players:
        connection.send_chat('{} is {}'.format(player.name, message))
    protocol.send_chat('{} is {}'.format(player.name, message), irc=True)
Esempio n. 8
0
def unlink(connection, player=None):
    protocol = connection.protocol
    if not protocol.running_man:
        return S_NOT_ENABLED

    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()

    player.drop_link()
    player.linkable = not player.linkable
    player.send_chat(S_LINKABLE_SELF if player.linkable else S_UNLINKABLE_SELF)
    message = S_LINKABLE if player.linkable else S_UNLINKABLE
    message.format(player=player.name)
    if connection is not player:
        return message
Esempio n. 9
0
def god(connection, name=None):
    if name is not None:
        if not connection.admin:
            return 'No administrator rights!'
        player = get_player(connection.protocol, name)
    else:
        player = connection
    if player not in player.protocol.players:
        raise ValueError()
    player.infinite_blocks = False
    player.god = not player.god
    if player.god:
        message = '{} entered BUILD MODE!'
        player.set_team(player.protocol.blue_team)
        player.respawn_time = 0
    else:
        message = '{} returned to being a mere sightseer'
        player.set_team(player.protocol.green_team)
        player.respawn_time = player.protocol.respawn_time
    player.protocol.send_chat(message.format(connection.name), irc=True)
Esempio n. 10
0
def follow(self, playerkey=None):
    """
    Lets you spawn near a specific player in your squad
    /follow <player>
    """
    if playerkey is None:
        squad_pref = None
        squad = self.squad
    else:
        squad_pref = get_player(self.protocol, playerkey)
        squad = squad_pref.squad
        if squad_pref.team is not self.team:
            return '%s is not on your team!' % (squad_pref.name)
        if squad_pref is self:
            return "You can't follow yourself!"
        if squad_pref.squad is None:
            return ('%s is not in a squad and cannot be followed.' %
                    squad_pref.name)

    return self.join_squad(squad, squad_pref)
Esempio n. 11
0
def fly(connection, player=None):
    """
    Enable flight
    /fly [player]
    Hold control and press space ;)
    """
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()
    player.fly = not player.fly

    message = 'now flying' if player.fly else 'no longer flying'
    player.send_chat("You're %s" % message)
    if connection is not player and connection in protocol.players:
        connection.send_chat('%s is %s' % (player.name, message))
    protocol.irc_say('* %s is %s' % (player.name, message))
Esempio n. 12
0
 def on_hit(self, hit_amount, hit_player, type, grenade):
     if self.name in list(self.protocol.analyzers.values()):
         if type == HEADSHOT_KILL or hit_amount in body_damage_values or hit_amount in limb_damage_values:
             if not grenade:
                 dist = int(distance_3d_vector(
                     self.world_object.position, hit_player.world_object.position))
                 weap = self.weapon_object.name
                 self.pres_time = time.monotonic()
                 if self.prev_time is None:
                     dt = None
                 else:
                     dt = (self.pres_time - self.prev_time) * 1000
                 self.prev_time = time.monotonic()
                 if type == HEADSHOT_KILL:
                     body_part = "HEADSHOT"
                 elif hit_amount in body_damage_values:
                     body_part = "Body"
                 elif hit_amount in limb_damage_values:
                     body_part = "Limb"
                 for name in list(self.protocol.analyzers.keys()):
                     if self.protocol.analyzers[name] == self.name:
                         analyzer = get_player(self.protocol, name)
                         if analyzer not in self.protocol.players:
                             raise ValueError()
                         else:
                             if body_part == "HEADSHOT":
                                 analyzer.hs += 1
                                 counter = analyzer.hs
                             elif body_part == "Body":
                                 analyzer.bs += 1
                                 counter = analyzer.bs
                             elif body_part == "Limb":
                                 analyzer.ls += 1
                                 counter = analyzer.ls
                             if dt is not None:
                                 analyzer.send_chat('%s shot %s dist: %d blocks dT: %.0f ms %s %s(%d)' % (
                                     self.name, hit_player.name, dist, dt, weap, body_part, counter))
                             else:
                                 analyzer.send_chat('%s shot %s dist: %d blocks dT: NA %s %s(%d)' % (
                                     self.name, hit_player.name, dist, weap, body_part, counter))
     return connection.on_hit(self, hit_amount, hit_player, type, grenade)
Esempio n. 13
0
def god_build(connection, player=None):
    """
    Place blocks that can be destroyed only by players with godmode activated
    /godbuild [player]
    """
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()

    player.god_build = not player.god_build

    message = ('now placing god blocks'
               if player.god_build else 'no longer placing god blocks')
    player.send_chat("You're %s" % message)
    if connection is not player and connection in protocol.players:
        connection.send_chat('%s is %s' % (player.name, message))
    protocol.irc_say('* %s is %s' % (player.name, message))
Esempio n. 14
0
def toggle_kill(connection, player=None):
    """
    Toggle killing for everyone in the server or for a given player
    /togglekill [player]
    """
    if player is not None:
        player = get_player(connection.protocol, player)
        value = not player.killing
        player.killing = value
        msg = '%s can kill again' if value else '%s is disabled from killing'
        connection.protocol.send_chat(msg % player.name)
        connection.protocol.irc_say(
            '* %s %s killing for %s' %
            (connection.name, ['disabled', 'enabled'
                               ][int(value)], player.name))
    else:
        value = not connection.protocol.killing
        connection.protocol.killing = value
        on_off = ['OFF', 'ON'][int(value)]
        connection.protocol.send_chat('Killing has been toggled %s!' % on_off)
        connection.protocol.irc_say('* %s toggled killing %s' %
                                    (connection.name, on_off))
Esempio n. 15
0
    def where_from(connection, value=None):
        # Get player IP address
        if value is None:
            if connection not in connection.protocol.players:
                raise ValueError()
            player = connection
        else:
            player = get_player(connection.protocol, value)

        # Query database
        try:
            record = database.city(player.address[0])
        except geoip2.errors.GeoIP2Error:
            return 'Player location could not be determined.'

        # Extract info
        raw_items = (record.city, *reversed(record.subdivisions), record.country)

        items = (raw_item.name for raw_item in raw_items if raw_item.name is not None)

        return '%s is from %s (%s)' % (player.name, ', '.join(items),
                                       record.country.iso_code)
Esempio n. 16
0
def sculpt(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()
    
    player.sculpting = sculpting = not player.sculpting
    if sculpting:
        player.sculpt_loop = HandyLoopingCall(sculpt_ray, player)
    else:
        if player.sculpt_loop and player.sculpt_loop.running:
            player.sculpt_loop.stop()
        player.sculpt_loop = None
    
    message = 'now sculpting' if sculpting else 'no longer sculpting'
    player.send_chat("You're %s" % message)
    if connection is not player and connection in protocol.players:
        connection.send_chat('%s is %s' % (player.name, message))
    protocol.irc_say('* %s is %s' % (player.name, message))
Esempio n. 17
0
def build(connection, player, area=None):
    """
    Give temporary build permission to a player
    /build <#id> <area>
    """
    if player is None:
        raise ValueError()
    player = get_player(connection.protocol, player)
    if area is None:
        if len(player.allowed_areas) < 1:
            raise ValueError()
        else:
            player.allowed_areas.clear()
            connection.protocol.broadcast_chat(
                player.name + " can no longer build at protected areas")
    else:
        area_coord = coordinates(area)
        player.allowed_areas.symmetric_difference_update([area_coord])
        message = ("%s can %s build at %s" %
                   (player.name, "temporary" if area_coord
                    in player.allowed_areas else "no longer", area.upper()))
        connection.protocol.broadcast_chat(message)
Esempio n. 18
0
def toggle_rapid(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()

    player.rapid = rapid = not player.rapid
    player.rapid_hack_detect = not rapid
    if rapid:
        player.rapid_loop = LoopingCall(resend_tool, player)
    else:
        if player.rapid_loop and player.rapid_loop.running:
            player.rapid_loop.stop()
        player.rapid_loop = None

    message = 'now rapid' if rapid else 'no longer rapid'
    player.send_chat("You're %s" % message)
    if connection is not player and connection in protocol.players:
        connection.send_chat('%s is %s' % (player.name, message))
    protocol.irc_say('* %s is %s' % (player.name, message))
Esempio n. 19
0
def invisible(connection, player=None):
    """
    Turn invisible
    /invisible [player]
    """
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
    elif connection in protocol.players:
        player = connection
    else:
        raise ValueError()
    # TODO: move this logic to a more suitable place
    player.invisible = not player.invisible
    player.filter_visibility_data = player.invisible
    player.god = player.invisible
    player.god_build = False
    player.killing = not player.invisible
    if player.invisible:
        player.send_chat("You're now invisible")
        protocol.irc_say('* %s became invisible' % player.name)
        kill_action = KillAction()
        kill_action.kill_type = choice([GRENADE_KILL, FALL_KILL])
        kill_action.player_id = kill_action.killer_id = player.player_id
        reactor.callLater(1.0 / NETWORK_FPS,
                          protocol.broadcast_contained,
                          kill_action,
                          sender=player)
    else:
        player.send_chat("You return to visibility")
        protocol.irc_say('* %s became visible' % player.name)
        x, y, z = player.world_object.position.get()
        create_player = CreatePlayer()
        create_player.player_id = player.player_id
        create_player.name = player.name
        create_player.x = x
        create_player.y = y
        create_player.z = z
        create_player.weapon = player.weapon
        create_player.team = player.team.id
        world_object = player.world_object
        input_data = InputData()
        input_data.player_id = player.player_id
        input_data.up = world_object.up
        input_data.down = world_object.down
        input_data.left = world_object.left
        input_data.right = world_object.right
        input_data.jump = world_object.jump
        input_data.crouch = world_object.crouch
        input_data.sneak = world_object.sneak
        input_data.sprint = world_object.sprint
        set_tool = SetTool()
        set_tool.player_id = player.player_id
        set_tool.value = player.tool
        set_color = SetColor()
        set_color.player_id = player.player_id
        set_color.value = make_color(*player.color)
        weapon_input = WeaponInput()
        weapon_input.primary = world_object.primary_fire
        weapon_input.secondary = world_object.secondary_fire
        protocol.broadcast_contained(create_player, sender=player, save=True)
        protocol.broadcast_contained(set_tool, sender=player)
        protocol.broadcast_contained(set_color, sender=player, save=True)
        protocol.broadcast_contained(input_data, sender=player)
        protocol.broadcast_contained(weapon_input, sender=player)
    if connection is not player and connection in protocol.players:
        if player.invisible:
            return '%s is now invisible' % player.name
        else:
            return '%s is now visible' % player.name
Esempio n. 20
0
def hackinfo(connection, name):
    player = get_player(connection.protocol, name)
    return hackinfo_player(player)
Esempio n. 21
0
def accuracy(connection, name=None):
    if name is None:
        player = connection
    else:
        player = get_player(connection.protocol, name)
    return accuracy_player(player)
Esempio n. 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)
Esempio n. 23
0
def trust(connection, player):
    player = get_player(connection.protocol, player)
    player.on_user_login('trusted', False)
    player.send_chat(S_GRANTED_SELF)
    return S_GRANTED.format(player=player.name)
Esempio n. 24
0
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])
        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
Esempio n. 25
0
def give_rocket(connection, player):
    player = get_player(connection.protocol, player)
    player.give_rocket()