Exemplo n.º 1
0
def start_votekick(connection, *args):
    protocol = connection.protocol
    if connection not in protocol.players:
        raise KeyError()
    player = connection
    
    if not args:
        if protocol.votekick:
            # player requested votekick info
            protocol.votekick.send_chat_update(player)
            return
        raise ValueError()
    
    value = args[0]
    try:
        # vanilla aos behavior
        victim = get_player(protocol, '#' + value)
    except InvalidPlayer:
        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)
Exemplo n.º 2
0
def start_votekick(connection, *args):
    protocol = connection.protocol
    if connection not in protocol.players:
        raise KeyError()
    player = connection
    
    if not args:
        if protocol.votekick:
            # player requested votekick info
            protocol.votekick.send_chat_update(player)
            return
        raise ValueError()
    
    value = args[0]
    try:
        # vanilla aos behavior
        victim = get_player(protocol, '#' + value)
    except InvalidPlayer:
        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)
Exemplo n.º 3
0
def start_votekick(connection, *args):
    protocol = connection.protocol
    if connection not in protocol.players:
        raise KeyError()
    player = connection
    
    if protocol.votekick_enabled == False:
        return "Votekicking disabled"
    if player.votekick_enabled == False:
        return "You are not allowed to initiate a votekick."
    
    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)
Exemplo n.º 4
0
def timed_mute(connection, *args):
  protocol = connection.protocol
  
  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
Exemplo n.º 5
0
def timed_mute(connection, *args):
    protocol = connection.protocol

    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
Exemplo n.º 6
0
def jail_player(connection, value = None, *args):
    protocol = connection.protocol # Meh
    player = get_player(protocol, value) # Get player
    reason = join_arguments(args[0:]) # Convert reason args into one string
    if player not in protocol.players:
        raise ValueError() # If player doesn't exist, raise error
    else:
        if player.jailed:
            return 'Player ' + player.name + ' is already jailed!' # Player is already jailed!
        elif not player.jailed:
            player.jailed = True # Set player to jailed
            player.reason = reason
            player.set_location(jail_location) # Move player to jail
            connection.protocol.send_chat("%s was sent to jail by %s for reason(s): %s" % (player.name, connection.name, reason)) # Message
            connection.protocol.irc_say("* %s jailed %s for reason: %s" % (connection.name, player.name, reason)) # Message
            jail_list.append(player.name)
Exemplo n.º 7
0
def jail_player(connection, value = None, *args):
    protocol = connection.protocol # Meh
    player = get_player(protocol, value) # Get player
    reason = join_arguments(args[0:]) # Convert reason args into one string
    if player not in protocol.players:
        raise ValueError() # If player doesn't exist, raise error
    else:
        if player.jailed:
            return 'Player ' + player.name + ' is already jailed!' # Player is already jailed!
        elif not player.jailed:
            player.jailed = True # Set player to jailed
            player.reason = reason
            player.squad  = None
            player.squad_pref = None
            player.set_location(jail_location) # Move player to jail
            connection.protocol.send_chat("%s was sent to jail by %s for reason(s): %s" % (player.name, connection.name, reason)) # Message
            connection.protocol.irc_say("* %s jailed %s for reason: %s" % (connection.name, player.name, reason)) # Message
            jail_list.append(player.name)
def report(connection, value, *arg):
    #Declaration of Pysnip Constants and Variables
    player = get_player(connection.protocol, value)
    message = join_arguments(arg)
    player_name = player.name
    protocol = connection.protocol

    if LANGUAGE is "PT":

        reportmsg = "**%s** esta reportando o player: **%s**.\n**Motivo**: %s.\n**Servidor**: %s.\nIP: %s\n%s" % (
            connection.name, player_name, message, protocol.name,
            protocol.identifier, ROLE_MENTION)
        if not message:
            return "Digite a mensagem no seguinte formato: /reportar <#ID/Nickname> <Mensagem>"
        try:
            url = WEBHOOK_URL
            data = urllib.urlencode({"content": reportmsg})
            post_request = urllib2.Request(url, data)
            post_request.add_header("User-Agent", USER_AGENT)
            urllib2.urlopen(post_request).read()
        except:
            return "UMA EXCECAO OCORREU!!!"
        return 'O report foi enviado com Sucesso para a Equipe STAFF'

    elif LANGUAGE is "EN":

        reportmsg = "**%s** is reporting player: **%s**.\n**Reason**: %s.\n**Server**: %s.\nIP: %s\n%s" % (
            connection.name, player_name, message, protocol.name,
            protocol.identifier, ROLE_MENTION)
        if not message:
            return "Type the command in the following Format: Command: /report <#ID/Nickname> <Message>"
        try:
            url = WEBHOOK_URL
            data = urllib.urlencode({"content": reportmsg})
            post_request = urllib2.Request(url, data)
            post_request.add_header("User-Agent", USER_AGENT)
            urllib2.urlopen(post_request).read()
        except:
            return "A exception has occurred!"
        return 'The report has successfully sended to Staff Team'
Exemplo n.º 9
0
def machinegun_tools(connection, *args):
    protocol = connection.protocol
    usage = S_EDIT_TOOL_USAGE if EDIT_MODE else S_TOOL_USAGE
    if not args:
        return usage
    result = None
    mode = args[0].lower()
    
    if (mode == 'stats' or
        (EDIT_MODE and
            (mode == 'delete' or
            (mode == 'edit' and connection in protocol.players)))):
        if len(args) != 2:
            return usage
        
        number_arg = args[1]
        if number_arg.startswith('#'):
            number_arg = number_arg[1:]
        i = int(number_arg)
        if i >= len(protocol.machineguns):
            return S_INVALID_ID
    
    # non-edit tools that can be used outside the game
    
    if mode == 'save':
        protocol.dump_machinegun_json()
        result = S_SAVED
    elif mode == 'list':
        items = []
        for machinegun, i in izip(protocol.machineguns, count()):
            item = S_LIST_ITEM.format(label = machinegun.label, number = i)
            items.append(item)
        result = S_LIST_HEADER + ', '.join(items) if items else S_LIST_EMPTY
    elif mode == 'stats':
        machinegun = protocol.machineguns[i]
        td = machinegun.get_time_active()
        result = S_STATS.format(label = machinegun.label, number = i,
            bullets = machinegun.rounds_fired, time = td,
            kills = machinegun.kills, deaths = machinegun.deaths)
    
    # editing tools that can be used outside the game
    
    if not EDIT_MODE or result:
        return result
    if mode == 'delete':
        machinegun = protocol.machineguns.pop(i)
        machinegun.release()
        for p in protocol.players.values():
            if p.editing_machinegun is machinegun:
                message = S_EDIT_CANCEL.format(label = machinegun.label)
                p.send_chat(message)
                p.editing_machinegun = None
        return S_DELETED.format(number = i, label = machinegun.label)
    
    # editing tools that must be used ingame
    
    if connection not in protocol.players:
        raise ValueError()
    player = connection
    machinegun = player.editing_machinegun
    
    # with no previous mg selected
    
    if mode == 'edit' or mode == 'new':
        if machinegun:
            return S_ALREADY_EDITING.format(label = machinegun.label)
        
        if mode == 'edit':
            machinegun = protocol.machineguns[i]
            result = S_EDITING.format(number = i, label = machinegun.label)
        elif mode == 'new':
            if len(args) < 2:
                return S_NEW_USAGE
            value = join_arguments(args[1:]).strip()
            if not value:
                return S_NEW_USAGE
            machinegun = Machinegun(protocol, value, player.team)
            machinegun.active = False
            message = S_NEW.format(team = player.team.name, label = value,
                number = len(protocol.machineguns))
            player.send_chat(message)
            result = S_ADD_ENTRY
        
        player.editing_machinegun = machinegun
        return result
    
    # while already editing a mg
    
    if not machinegun:
        return S_EDIT_FIRST
    
    if mode == 'entry' or mode == 'nest':
        x, y, z = player.get_location()
        if player.world_object.crouch:
            z -= 0.9
        if mode == 'entry':
            x = round(x * 2.0) / 2.0
            y = round(y * 2.0) / 2.0
            z = round(z)
            xyz = (x, y, z)
            machinegun.entry_location = xyz
            message = S_ENTRY_SET.format(location = xyz)
        else:
            x = round(x) + machinegun.forward.x
            y = round(y * 2.0) / 2.0
            z = int(z) + 0.6
            xyz = (x, y, z)
            machinegun.location = xyz
            message = S_NEST_SET.format(location = xyz)
        player.send_chat(message)
        
        if machinegun.entry_location is None:
            result = S_ADD_ENTRY
        elif machinegun.location is None:
            result = S_ADD_NEST
        else:
            result = None
            if machinegun not in protocol.machineguns:
                machinegun.active = True
                protocol.machineguns.append(machinegun)
                result = S_ACTIVE.format(number = len(protocol.machineguns) - 1)
                player.editing_machinegun = None
    elif mode == 'cancel':
        result = S_EDIT_CANCEL.format(label = machinegun.label)
        if machinegun not in protocol.machineguns:
            machinegun.release()
        player.editing_machinegun = None
    elif mode == 'angles':
        result = S_ANGLES_USAGE
        if len(args) == 4:
            result = S_ANGLES
            machinegun.horizontal_fov, machinegun.up_fov, machinegun.down_fov = (
                float(args[1]), float(args[2]), float(args[3]))
            machinegun.precalc_angles()
        result = result.format(h_fov = machinegun.horizontal_fov,
            up_fov = machinegun.up_fov, down_fov = machinegun.down_fov)
    return result or usage
Exemplo n.º 10
0
def machinegun_tools(connection, *args):
    protocol = connection.protocol
    usage = S_EDIT_TOOL_USAGE if EDIT_MODE else S_TOOL_USAGE
    if not args:
        return usage
    result = None
    mode = args[0].lower()

    if (mode == 'stats' or
        (EDIT_MODE and (mode == 'delete' or
                        (mode == 'edit' and connection in protocol.players)))):
        if len(args) != 2:
            return usage

        number_arg = args[1]
        if number_arg.startswith('#'):
            number_arg = number_arg[1:]
        i = int(number_arg)
        if i >= len(protocol.machineguns):
            return S_INVALID_ID

    # non-edit tools that can be used outside the game

    if mode == 'save':
        protocol.dump_machinegun_json()
        result = S_SAVED
    elif mode == 'list':
        items = []
        for machinegun, i in izip(protocol.machineguns, count()):
            item = S_LIST_ITEM.format(label=machinegun.label, number=i)
            items.append(item)
        result = S_LIST_HEADER + ', '.join(items) if items else S_LIST_EMPTY
    elif mode == 'stats':
        machinegun = protocol.machineguns[i]
        td = machinegun.get_time_active()
        result = S_STATS.format(label=machinegun.label,
                                number=i,
                                bullets=machinegun.rounds_fired,
                                time=td,
                                kills=machinegun.kills,
                                deaths=machinegun.deaths)

    # editing tools that can be used outside the game

    if not EDIT_MODE or result:
        return result
    if mode == 'delete':
        machinegun = protocol.machineguns.pop(i)
        machinegun.release()
        for p in protocol.players.values():
            if p.editing_machinegun is machinegun:
                message = S_EDIT_CANCEL.format(label=machinegun.label)
                p.send_chat(message)
                p.editing_machinegun = None
        return S_DELETED.format(number=i, label=machinegun.label)

    # editing tools that must be used ingame

    if connection not in protocol.players:
        raise ValueError()
    player = connection
    machinegun = player.editing_machinegun

    # with no previous mg selected

    if mode == 'edit' or mode == 'new':
        if machinegun:
            return S_ALREADY_EDITING.format(label=machinegun.label)

        if mode == 'edit':
            machinegun = protocol.machineguns[i]
            result = S_EDITING.format(number=i, label=machinegun.label)
        elif mode == 'new':
            if len(args) < 2:
                return S_NEW_USAGE
            value = join_arguments(args[1:]).strip()
            if not value:
                return S_NEW_USAGE
            machinegun = Machinegun(protocol, value, player.team)
            machinegun.active = False
            message = S_NEW.format(team=player.team.name,
                                   label=value,
                                   number=len(protocol.machineguns))
            player.send_chat(message)
            result = S_ADD_ENTRY

        player.editing_machinegun = machinegun
        return result

    # while already editing a mg

    if not machinegun:
        return S_EDIT_FIRST

    if mode == 'entry' or mode == 'nest':
        x, y, z = player.get_location()
        if player.world_object.crouch:
            z -= 0.9
        if mode == 'entry':
            x = round(x * 2.0) / 2.0
            y = round(y * 2.0) / 2.0
            z = round(z)
            xyz = (x, y, z)
            machinegun.entry_location = xyz
            message = S_ENTRY_SET.format(location=xyz)
        else:
            x = round(x) + machinegun.forward.x
            y = round(y * 2.0) / 2.0
            z = int(z) + 0.6
            xyz = (x, y, z)
            machinegun.location = xyz
            message = S_NEST_SET.format(location=xyz)
        player.send_chat(message)

        if machinegun.entry_location is None:
            result = S_ADD_ENTRY
        elif machinegun.location is None:
            result = S_ADD_NEST
        else:
            result = None
            if machinegun not in protocol.machineguns:
                machinegun.active = True
                protocol.machineguns.append(machinegun)
                result = S_ACTIVE.format(number=len(protocol.machineguns) - 1)
                player.editing_machinegun = None
    elif mode == 'cancel':
        result = S_EDIT_CANCEL.format(label=machinegun.label)
        if machinegun not in protocol.machineguns:
            machinegun.release()
        player.editing_machinegun = None
    elif mode == 'angles':
        result = S_ANGLES_USAGE
        if len(args) == 4:
            result = S_ANGLES
            machinegun.horizontal_fov, machinegun.up_fov, machinegun.down_fov = (
                float(args[1]), float(args[2]), float(args[3]))
            machinegun.precalc_angles()
        result = result.format(h_fov=machinegun.horizontal_fov,
                               up_fov=machinegun.up_fov,
                               down_fov=machinegun.down_fov)
    return result or usage