Esempio n. 1
0
def teleport(connection, player1, player2=None, silent=False):
    """
    Teleport yourself or a given player to another player
    /teleport [player] <target player>
    """
    # TODO: refactor this
    player1 = get_player(connection.protocol, player1)
    if player2 is not None:
        if connection.admin or connection.rights.teleport_other:
            player, target = player1, get_player(connection.protocol, player2)
            silent = silent or player.invisible
            message = ('%s ' + ('silently ' if silent else '') + 'teleported '
                       '%s to %s')
            message = message % (connection.name, player.name, target.name)
        else:
            return 'No administrator rights!'
    else:
        if connection not in connection.protocol.players:
            raise ValueError()
        player, target = connection, player1
        silent = silent or player.invisible
        message = '%s ' + \
            ('silently ' if silent else '') + 'teleported to %s'
        message = message % (player.name, target.name)
    x, y, z = target.get_location()
    player.set_location(((x - 0.5), (y - 0.5), (z + 0.5)))
    if silent:
        connection.protocol.irc_say('* ' + message)
    else:
        connection.protocol.send_chat(message, irc=True)
Esempio n. 2
0
def switch(connection, player=None, team=None):
    """
    Switch teams either for yourself or for a given player
    /switch [player]
    """
    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.team.spectator:
        player.send_chat(
            "The switch command can't be used on a spectating player.")
        return
    if team is None:
        new_team = player.team.other
    else:
        new_team = get_team(connection, team)
    if player.invisible:
        old_team = player.team
        player.team = new_team
        player.on_team_changed(old_team)
        player.spawn(player.world_object.position.get())
        player.send_chat('Switched to %s team' % player.team.name)
        if connection is not player and connection in protocol.players:
            connection.send_chat('Switched %s to %s team' %
                                 (player.name, player.team.name))
        protocol.irc_say('* %s silently switched teams' % player.name)
    else:
        player.respawn_time = protocol.respawn_time
        player.set_team(new_team)
        protocol.send_chat('%s switched teams' % player.name, irc=True)
Esempio n. 3
0
def ratio(connection, user=None):
    msg = "You have"
    if user is not None:
        connection = get_player(connection.protocol, user)
        msg = "%s has"
        if connection not in connection.protocol.players:
            raise KeyError()
        msg %= connection.name
    if connection not in connection.protocol.players:
        raise KeyError()

    kills = connection.ratio_kills
    deaths = float(max(1, connection.ratio_deaths))
    headshotkills = connection.ratio_headshotkills
    meleekills = connection.ratio_meleekills
    grenadekills = connection.ratio_grenadekills

    msg += " a kill-death ratio of %.2f" % (kills / deaths)
    if HEADSHOT_RATIO:
        msg += ", headshot-death ratio of %.2f" % (headshotkills / deaths)
    msg += " (%s kills, %s deaths" % (kills, connection.ratio_deaths)
    if EXTENDED_RATIO:
        msg += ", %s headshot, %s melee, %s grenade" % (
            headshotkills, meleekills, grenadekills)
    msg += ")."
    return msg
Esempio n. 4
0
def godsilent(connection, player=None):
    """
    Silently go into god mode
    /godsilent [player]
    """
    if player is not None:
        connection = get_player(connection.protocol, player)
    elif connection not in connection.protocol.players:
        return 'Unknown player: ' + player

    connection.god = not connection.god  # toggle godmode

    if connection.protocol.set_god_build:
        connection.god_build = connection.god
    else:
        connection.god_build = False

    if connection.god:
        if player is None:
            return 'You have silently entered god mode'
        else:
            # TODO: Do not send this if the specified player is the one who called the command
            connection.send_chat(
                'Someone has made you silently enter godmode!')
            return 'You made ' + connection.name + ' silently enter god mode'
    else:
        if player is None:
            return 'You have silently returned to being a mere human'
        else:
            # TODO: Do not send this if the specified player is the one who called the command
            connection.send_chat(
                'Someone has made you silently return to being a mere human')
            return 'You made ' + connection.name + ' silently return to being a mere human'
Esempio n. 5
0
def start_votekick(connection, *args):
    protocol = connection.protocol
    if connection not in protocol.players:
        raise KeyError()
    player = connection

    if not protocol.votekick_enabled:
        return S_VOTEKICKING_DISABLED
    if not player.votekick_enabled:
        return S_VOTEKICK_DISALLOWED

    if not args:
        if protocol.votekick:
            # player requested votekick info
            protocol.votekick.send_chat_update(player)
            return
        raise ValueError()

    value = args[0]
    victim = get_player(protocol, value)
    reason = join_arguments(args[1:])

    try:
        # attempt to start votekick
        votekick = Votekick.start(player, victim, reason)
        protocol.votekick = votekick
    except VotekickFailure as err:
        return str(err)
Esempio n. 6
0
def ban(connection, value, *arg):
    """
    Ban a given player forever or for a limited amount of time
    /ban <player> [duration] [reason]
    """
    duration, reason = get_ban_arguments(connection, arg)
    player = get_player(connection.protocol, value)
    player.ban(reason, duration)
Esempio n. 7
0
def investigate(connection, player):
    player = get_player(connection.protocol, player)
    score = score_grief(connection, player)
    kdr = round(player.ratio_kills / float(max(1, player.ratio_deaths)))
    percent = round(check_percent(player))
    message = "Results for %s: Grief Score - %s / KDR - %s / Hit Acc. - %s" % (
        player.name, score, kdr, percent)
    return message
Esempio n. 8
0
def pban(connection, value, *arg):
    """
    Ban a given player permanently
    /pban <player> [reason]
    """
    duration = 0
    reason = join_arguments(arg)
    player = get_player(connection.protocol, value)
    player.ban(reason, duration)
Esempio n. 9
0
def wban(connection, value, *arg):
    """
    Ban a given player for one week
    /wban <player> [reason]
    """
    duration = 10080
    reason = join_arguments(arg)
    player = get_player(connection.protocol, value)
    player.ban(reason, duration)
Esempio n. 10
0
def hban(connection, value, *arg):
    """
    Ban a given player for an hour
    /hban <player> [reason]
    """
    duration = 60
    reason = join_arguments(arg)
    player = get_player(connection.protocol, value)
    player.ban(reason, duration)
Esempio n. 11
0
def kick(connection, value, *arg):
    """
    Kick a given player
    /kick <player>
    Player is the #ID of the player, or an unique part of their name
    """
    reason = join_arguments(arg)
    player = get_player(connection.protocol, value)
    player.kick(reason)
Esempio n. 12
0
def give_strike(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.airstrike = True
    player.send_chat(S_READY)
Esempio n. 13
0
def pm(connection, value, *arg):
    """
    Send a private message to a given player
    /pm <player> <message>
    """
    player = get_player(connection.protocol, value)
    message = join_arguments(arg)
    if len(message) == 0:
        return "Please specify your message"
    player.send_chat('PM from %s: %s' % (connection.name, message))
    return 'PM sent to %s' % player.name
Esempio n. 14
0
def weapon(connection, value):
    """
    Tell you what weapon a given player is using
    /weapon <player>
    """
    player = get_player(connection.protocol, value)
    if player.weapon_object is None:
        name = '(unknown)'
    else:
        name = player.weapon_object.name
    return '%s has a %s' % (player.name, name)
Esempio n. 15
0
def unmute(connection, value):
    """
    Unmute a player
    /unmute <player>
    """
    player = get_player(connection.protocol, value)
    if not player.mute:
        return '%s is not muted' % player.name
    player.mute = False
    message = '%s has been unmuted by %s' % (player.name, connection.name)
    connection.protocol.send_chat(message, irc=True)
Esempio n. 16
0
def mute(connection, value):
    """
    Mute a player
    /mute <player>
    """
    player = get_player(connection.protocol, value)
    if player.mute:
        return '%s is already muted' % player.name
    player.mute = True
    message = '%s has been muted by %s' % (player.name, connection.name)
    connection.protocol.send_chat(message, irc=True)
Esempio n. 17
0
def toggle_markers(connection, player=None):
    protocol = connection.protocol
    if player is not None:
        player = get_player(protocol, player)
        player.allow_markers = not player.allow_markers
        message = S_PLAYER_ENABLED if player.allow_markers else S_PLAYER_DISABLED
        message = message.format(player=player.name)
        protocol.send_chat(message, irc=True)
    else:
        protocol.allow_markers = not protocol.allow_markers
        message = S_ENABLED if protocol.allow_markers else S_DISABLED
        connection.protocol.send_chat(message, irc=True)
Esempio n. 18
0
def ip(connection, value=None):
    """
    Get the IP of a user
    /ip [player]
    """
    if value is None:
        if connection not in connection.protocol.players:
            raise ValueError()
        player = connection
    else:
        player = get_player(connection.protocol, value)
    return 'The IP of %s is %s' % (player.name, player.address[0])
Esempio n. 19
0
def where(connection, player=None):
    """
    Tell you the coordinates of yourself or of a given player
    /where [player]
    """
    if player is not None:
        connection = get_player(connection.protocol, player)
    elif connection not in connection.protocol.players:
        raise ValueError()
    x, y, z = connection.get_location()
    return '%s is in %s (%s, %s, %s)' % (connection.name, to_coordinates(
        x, y), int(x), int(y), int(z))
Esempio n. 20
0
def togglevotekick(connection, *args):
    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. 21
0
def unstick(connection, player=None):
    """
    Unstick yourself or another player and inform everyone on the server of it
    /unstick [player]
    """
    if player is not None:
        player = get_player(connection.protocol, player)
    else:
        player = connection
    connection.protocol.send_chat("%s unstuck %s" %
                                  (connection.name, player.name),
                                  irc=True)
    player.set_location_safe(player.get_location())
Esempio n. 22
0
def client(connection, target=None):
    """
    Tell you information about your client or the client of a given player
    /client [player]
    """
    if not target:
        player = connection
        who_is = "You are"
    else:
        player = get_player(connection.protocol, target)
        who_is = player.name + " is"

    return "{} connected with {}".format(who_is, connection.client_string)
Esempio n. 23
0
def do_move(connection, args, silent=False):
    position = None
    player = None
    arg_count = len(args)

    initial_index = 1 if arg_count == 2 or arg_count == 4 else 0

    # the target position is a <sector>
    if arg_count == 1 or arg_count == 2:
        x, y = coordinates(args[initial_index])
        x += 32
        y += 32
        z = connection.protocol.map.get_height(x, y) - 2
        position = args[initial_index].upper()
    # the target position is <x> <y> <z>
    elif arg_count == 3 or arg_count == 4:
        x = min(max(0, int(args[initial_index])), 511)
        y = min(max(0, int(args[initial_index + 1])), 511)
        z = min(max(0, int(args[initial_index + 2])),
                connection.protocol.map.get_height(x, y) - 2)
        position = '%d %d %d' % (x, y, z)
    else:
        raise ValueError('Wrong number of parameters!')

    # no player specified
    if arg_count == 1 or arg_count == 3:
        if connection not in connection.protocol.players:
            raise ValueError()
        player = connection.name
    # player specified
    elif arg_count == 2 or arg_count == 4:
        player = args[0]

    player = get_player(connection.protocol, player)

    silent = connection.invisible or silent

    player.set_location((x, y, z))
    if connection is player:
        message = ('%s ' + ('silently ' if silent else '') + 'teleported to '
                   'location %s')
        message = message % (player.name, position)
    else:
        message = ('%s ' + ('silently ' if silent else '') + 'teleported %s '
                   'to location %s')
        message = message % (connection.name, player.name, position)
    if silent:
        connection.protocol.irc_say('* ' + message)
    else:
        connection.protocol.send_chat(message, irc=True)
Esempio n. 24
0
def ping(connection, value=None):
    """
    Tell your current ping (time for your actions to be received by the server)
    /ping
    """
    if value is None:
        if connection not in connection.protocol.players:
            raise ValueError()
        player = connection
    else:
        player = get_player(connection.protocol, value)
    ping = player.latency
    if value is None:
        return 'Your ping is %s ms. Lower ping is better!' % ping
    return "%s's ping is %s ms" % (player.name, ping)
Esempio n. 25
0
def heal(connection, player=None):
    """
    Heal and refill yourself or a given player and inform everyone on the server of this action
    /heal [player]
    """
    if player is not None:
        player = get_player(connection.protocol, player, False)
        message = '%s was healed by %s' % (player.name, connection.name)
    else:
        if connection not in connection.protocol.players:
            raise ValueError()
        player = connection
        message = '%s was healed' % (connection.name)
    player.refill()
    connection.protocol.send_chat(message, irc=True)
Esempio n. 26
0
def kill(connection, value=None):
    """
    Kill yourself or a given player
    /kill [target]
    """
    if value is None:
        player = connection
    else:
        if not connection.rights.kill and not connection.admin:
            raise PermissionDenied()
        player = get_player(connection.protocol, value, False)
    player.kill()
    if connection is not player:
        message = '%s killed %s' % (connection.name, player.name)
        connection.protocol.send_chat(message, irc=True)
Esempio n. 27
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. 28
0
def follow(self, playerkey=None):
    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. 29
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:
        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. 30
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