Exemple #1
0
 def on_input_data_recieved(self, contained: loaders.InputData) -> None:
     if not self.hp:
         return
     world_object = self.world_object
     returned = self.on_walk_update(contained.up, contained.down,
                                    contained.left, contained.right)
     if returned is not None:
         up, down, left, right = returned
         if (up != contained.up or down != contained.down or
                 left != contained.left or right != contained.right):
             (contained.up, contained.down, contained.left,
                 contained.right) = returned
             # XXX unsupported
             # self.send_contained(contained)
     if not self.freeze_animation:
         world_object.set_walk(contained.up, contained.down,
                               contained.left, contained.right)
     contained.player_id = self.player_id
     z_vel = world_object.velocity.z
     if contained.jump and not (z_vel >= 0 and z_vel < 0.017):
         contained.jump = False
     # XXX unsupported for now
     # returned = self.on_animation_update(contained.primary_fire,
         # contained.secondary_fire, contained.jump,
         # contained.crouch)
     # if returned is not None:
         # fire1, fire2, jump, crouch = returned
         # if (fire1 != contained.primary_fire or
         # fire2 != contained.secondary_fire or
         # jump != contained.jump or
         # crouch != contained.crouch):
         # (contained.primary_fire, contained.secondary_fire,
         # contained.jump, contained.crouch) = returned
         # self.send_contained(contained)
     returned = self.on_animation_update(
         contained.jump, contained.crouch, contained.sneak,
         contained.sprint)
     if returned is not None:
         jump, crouch, sneak, sprint = returned
         if (jump != contained.jump or crouch != contained.crouch or
                 sneak != contained.sneak or sprint != contained.sprint):
             (contained.jump, contained.crouch, contained.sneak,
                 contained.sprint) = returned
             self.send_contained(contained)
     if not self.freeze_animation:
         world_object.set_animation(
             contained.jump, contained.crouch, contained.sneak,
             contained.sprint)
     if self.filter_visibility_data or self.filter_animation_data:
         return
     self.protocol.send_contained(contained, sender=self)
Exemple #2
0
def invisible(connection, player):
    """
    Turn invisible
    /invisible [player]
    """
    protocol = connection.protocol
    # 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.values():
        if player.invisible:
            return '%s is now invisible' % player.name
        else:
            return '%s is now visible' % player.name
Exemple #3
0
from random import choice
from twisted.internet import reactor
from pyspades.contained import KillAction, InputData, SetColor, WeaponInput
from pyspades.player import create_player, set_tool
from pyspades.constants import (GRENADE_KILL, FALL_KILL, NETWORK_FPS)
from pyspades.common import (prettify_timespan, make_color)
from piqueserver.commands import command, CommandError, get_player, join_arguments

# aparently, we need to send packets in this file. For now, I give in.
kill_action = KillAction()
input_data = InputData()
set_color = SetColor()
weapon_input = WeaponInput()


def get_ban_arguments(connection, arg):
    duration = None
    if len(arg):
        try:
            duration = int(arg[0])
            arg = arg[1:]
        except (IndexError, ValueError):
            pass
    if duration is None:
        if len(arg) > 0 and arg[0] == "perma":
            arg = arg[1:]
        else:
            duration = connection.protocol.default_ban_time
    reason = join_arguments(arg)
    return duration, reason
 def flush_input(self):
     input = self.input
     world_object = self.world_object
     z_vel = world_object.velocity.z
     if "jump" in input and not (z_vel >= 0.0 and z_vel < 0.017):
         input.discard("jump")
     input_changed = not (("up" in input) == world_object.up and
                          ("down" in input) == world_object.down and
                          ("left" in input) == world_object.left and
                          ("right" in input) == world_object.right and
                          ("jump" in input) == world_object.jump and
                          ("crouch" in input) == world_object.crouch and
                          ("sneak" in input) == world_object.sneak and
                          ("sprint" in input) == world_object.sprint)
     if input_changed:
         if not self.freeze_animation:
             world_object.set_walk(
                 "up" in input,
                 "down" in input,
                 "left" in input,
                 "right" in input,
             )
             world_object.set_animation(
                 "jump" in input,
                 "crouch" in input,
                 "sneak" in input,
                 "sprint" in input,
             )
         if not self.filter_visibility_data and not self.filter_animation_data:
             input_data = InputData()
             input_data.player_id = self.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
             self.protocol.send_contained(input_data)
     primary = "primary_fire" in input
     secondary = "secondary_fire" in input
     shoot_changed = not (primary == world_object.primary_fire
                          and secondary == world_object.secondary_fire)
     if shoot_changed:
         if primary != world_object.primary_fire:
             if self.tool == WEAPON_TOOL:
                 self.weapon_object.set_shoot(primary)
             if self.tool == WEAPON_TOOL or self.tool == SPADE_TOOL:
                 self.on_shoot_set(primary)
         world_object.primary_fire = primary
         world_object.secondary_fire = secondary
         if not self.filter_visibility_data:
             weapon_input = WeaponInput()
             weapon_input.player_id = self.player_id
             weapon_input.primary = primary
             weapon_input.secondary = secondary
             self.protocol.send_contained(weapon_input)
     input.clear()