Exemplo n.º 1
0
 def check_for_block_removal(self, x, y, z, team_blocks_only=False):
     if self.blocks_removed is not None:
         time = seconds() - (BLOCK_TEAM_REMOVAL_MINS if team_blocks_only
                             else BLOCK_REMOVAL_MINS) * 60.0
         block_time = 0
         amount = 0
         for b in reversed(self.blocks_removed):
             if (team_blocks_only and b[1] is not None
                     and b[1][0] != self.name
                     and b[1][1] == self.team.id) or (
                         not team_blocks_only and
                         (b[1] is None or b[1][0] != self.name)):
                 if block_time == 0:
                     block_time = b[0]
                 if b[0] < time:
                     break
                 amount += 1
         if (amount > 1 and block_time > self.last_block_time + 30
                 and not amount %
             (BLOCK_TEAM_REMOVAL_MAX
              if team_blocks_only else BLOCK_REMOVAL_MAX)):
             send_warning(
                 self.protocol,
                 "Warning: %s #%s removed %s%s blocks (%s)" %
                 (self.name, self.player_id, amount, " team"
                  if team_blocks_only else "", to_coordinates(x, y)))
             self.last_block_time = block_time
Exemplo n.º 2
0
def buildpw(connection, password=None, area=None):
    """
    Quick way of giving a player a password for a protected area
    /buildpw <password> <area>
    """
    if password is None and area is None:
        pws_str = ""
        for pw in connection.protocol.password_areas:
            pws_str += pw + " "
        if pws_str == "":
            pws_str = "none"
        return "Passwords: " + pws_str
    elif area is None:
        areas_str = ""
        for pw_coord in connection.protocol.password_areas.get(password):
            areas_str += to_coordinates(pw_coord[0], pw_coord[1]) + " "
        if areas_str == "":
            areas_str = "none"
        return "Areas for " + password + ": " + areas_str
    else:
        if connection.protocol.password_areas.get(password) is None:
            connection.protocol.password_areas[password] = set()
        areas = connection.protocol.password_areas[password]
        area_coord = coordinates(area)
        areas.symmetric_difference_update([area_coord])
        message = ("%s now %s with %s" %
                   (area.upper(), "allowed"
                    if area_coord in areas else "disallowed", password))
        if len(areas) < 1:
            connection.protocol.password_areas.pop(password, None)
        return message
Exemplo n.º 3
0
def where(connection, value=None):
    if value is not None:
        connection = get_player(connection.protocol, value)
    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))
Exemplo n.º 4
0
def where(connection, value = None):
    if value is not None:
        connection = get_player(connection.protocol, value)
    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))
Exemplo n.º 5
0
def where(connection, player):
    """
    Tell you the coordinates of yourself or of a given player
    /where [player]
    """
    x, y, z = player.get_location()
    return '%s is in %s (%s, %s, %s)' % (player.name, to_coordinates(
        x, y), int(x), int(y), int(z))
Exemplo n.º 6
0
 def on_block_destroy(self, x, y, z, mode):
     x, y, z = self.get_location()
     coord = to_coordinates(x, y)
     if self.jailed:
         self.send_chat("You can't destroy blocks when you're in jail! You were jailed for: %s" % (self.reason))
         return False
     elif coord in jail_coords and not self.user_types.admin:
         self.send_chat("Stop trying to destroy the jail, %s!" % self.name)
         return False
     return connection.on_block_destroy(self, x, y, z, mode)
Exemplo n.º 7
0
 def on_line_build_attempt(self, points):
     x, y, z = self.get_location()
     coord = to_coordinates(x, y)
     if self.jailed:
         self.send_chat("You can't build when you're jailed! You were jailed for: %s" % (self.reason))
         return False
     elif coord == in jail_coords and not self.user_types.admin:
         self.send_chat("You can't build near the jail, %s!" % self.name)
         return False
     return connection.on_line_build_attempt(self, points)
Exemplo n.º 8
0
        def start_airstrike(self, x, y, z):
            coords = to_coordinates(x, y)
            message = S_ALLIED.format(player=self.name, coords=coords)
            self.protocol.send_chat(message, global_message=False,
                                    team=self.team)
            message = S_ENEMY.format(coords=coords)
            self.protocol.send_chat(message, global_message=False,
                                    team=self.team.other)
            self.team.last_airstrike = reactor.seconds()

            reactor.callLater(ARRIVAL_DELAY, self.do_airstrike, x, y, z)
Exemplo n.º 9
0
def selectChunk(connection):
    position = connection.get_location()
    position = (floor(position[0]), floor(position[1]), floor(position[2]))
    x = (position[0] // 64) * 64
    y = (position[1] // 64) * 64
    pos1 = (x, y, 0)
    pos2 = (x + 64, y + 64, 63)
    connection.pos1 = pos1
    connection.pos2 = pos2
    connection.send_chat("Selected current chunk ({})".format(
        to_coordinates(x, y)))
Exemplo n.º 10
0
 def check_for_located_on_enemy_side(self):
     area = self.team.other.build_area
     if (area is not None and self.world_object is not None and
             is_in_area(self.world_object.position.x,
                        self.world_object.position.y,
                        *area)):
         if not self.located_on_enemy_side:
             x, y, z = self.get_location()
             send_warning(self.protocol, "Warning: %s #%s is on enemy side (%s)"
                          % (self.name, self.player_id, to_coordinates(x, y)))
         self.located_on_enemy_side = True
Exemplo n.º 11
0
 def start_airstrike(self, coord_x, coord_y):
     coords = to_coordinates(coord_x, coord_y)
     message = S_ALLIED.format(player = self.name, coords = coords)
     self.protocol.send_chat(message, global_message = False,
         team = self.team)
     message = S_ENEMY.format(coords = coords)
     self.protocol.send_chat(message, global_message = False,
         team = self.team.other)
     
     self.team.last_airstrike = seconds()
     self.airstrike = False
     callLater(2.5, self.do_airstrike, coord_x, coord_y)
Exemplo n.º 12
0
 def on_block_build_attempt(self, x, y, z):
     coord = to_coordinates(x, y)
     if self.jailed:
         self.send_chat("You can't build when you're jailed! You were jailed for %s" % (self.reason))
         return False
     elif coord == "B8" and not self.user_types.admin: # Stuff
         self.send_chat("You can't build near the jail, %s!" % self.name)
         return False
     elif coord == "C8" and not self.user_types.admin:
         self.send_chat("You can't build near the jail, %s!" % self.name)
         return False
     return connection.on_block_build_attempt(self, x, y, z)
Exemplo n.º 13
0
 def start_airstrike(self, coord_x, coord_y):
     coords = to_coordinates(coord_x, coord_y)
     message = S_ALLIED.format(player = self.name, coords = coords)
     self.protocol.send_chat(message, global_message = False,
         team = self.team)
     message = S_ENEMY.format(coords = coords)
     self.protocol.send_chat(message, global_message = False,
         team = self.team.other)
     
     self.team.last_airstrike = seconds()
     self.airstrike = False
     callLater(2.5, self.do_airstrike, coord_x, coord_y)
Exemplo n.º 14
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))
Exemplo n.º 15
0
def allow(connection, password):
    """
    Using a password to get permission for areas
    /allow <password>
    """
    areas = connection.protocol.password_areas.get(password)
    if areas is None or len(areas) < 1:
        return "Invalid key"
    else:
        connection.allowed_areas.update(areas)
        areas_str = ""
        for a in areas:
            areas_str += to_coordinates(a[0], a[1]) + " "
        connection.protocol.irc_say("%s got permission for %s" %
                                    (connection.name, areas_str))
        return "Permission allowed for " + areas_str
Exemplo n.º 16
0
 def on_block_build_attempt(self, x, y, z):
     coord = to_coordinates(x, y)
     if self.jailed:
         self.send_chat(
             "You can't build when you're jailed! You were jailed for %s"
             % (self.reason))
         return False
     elif coord == "B8" and not self.user_types.admin:  # Stuff
         self.send_chat("You can't build near the jail, %s!" %
                        self.name)
         return False
     elif coord == "C8" and not self.user_types.admin:
         self.send_chat("You can't build near the jail, %s!" %
                        self.name)
         return False
     return connection.on_block_build_attempt(self, x, y, z)
Exemplo n.º 17
0
        def start_dangerzone(self, coord_x, coord_y):
            print "start_dangerzone"
            coords = to_coordinates(coord_x, coord_y)
            message = S_DZ_START.format(player=self.name, coords=coords)
            self.protocol.send_chat(message)
            message = S_DZ_GETOUT.format(seconds=EVAC_TIME)
            self.protocol.send_chat(message)

            self.team.last_dangerzone = seconds()
            self.dangerzone = False

            self.protocol.dz_x = coord_x
            self.protocol.dz_y = coord_y
            if self.name is None:
                return
            self.protocol.dangerzone_on = True
            callLater(EVAC_TIME, self.do_dangerzone)
            callLater(DANGERZONE_DURATION, self.end_dangerzone)
Exemplo n.º 18
0
 def start_dangerzone(self, coord_x, coord_y):
     print "start_dangerzone"
     coords = to_coordinates(coord_x, coord_y)
     message = S_DZ_START.format(player = self.name, coords = coords)
     self.protocol.send_chat(message)
     message = S_DZ_GETOUT.format(seconds = EVAC_TIME)
     self.protocol.send_chat(message)
     
     self.team.last_dangerzone = seconds()
     self.dangerzone = False
     
     self.protocol.dz_x = coord_x
     self.protocol.dz_y = coord_y
     if self.name is None:
         return
     self.protocol.dangerzone_on = True
     callLater(EVAC_TIME, self.do_dangerzone)
     callLater(DANGERZONE_DURATION, self.end_dangerzone)
Exemplo n.º 19
0
def protect(connection, area=None):
    """
    Protect an area inside the public build region
    /protect <area>
    """
    if area is None:
        areas_str = ""
        for protected_coord in connection.protocol.protected_areas:
            areas_str += to_coordinates(protected_coord[0],
                                        protected_coord[1]) + " "
        if areas_str == "":
            areas_str = "none"
        return "Protected areas: " + areas_str
    else:
        area_coord = coordinates(area)
        connection.protocol.protected_areas.symmetric_difference_update(
            [area_coord])
        message = ("The area at %s is now %s" %
                   (area.upper(), "protected" if area_coord
                    in connection.protocol.protected_areas else "unprotected"))
        connection.protocol.broadcast_chat(message)
Exemplo n.º 20
0
 def on_animation_update(self, jump, crouch, sneak, sprint):
     markers_allowed = (VV_ENABLED and self.allow_markers and
         self.protocol.allow_markers)
     if markers_allowed and sneak and self.world_object.sneak != sneak:
         now = seconds()
         if self.last_marker is None or now - self.last_marker > COOLDOWN:
             presses = self.sneak_presses
             presses.append(now)
             if len(presses) == 2 and presses[0] >= now - VV_TIMEFRAME:
                 location = self.get_there_location()
                 if location:
                     coords = to_coordinates(*location)
                     chat_message.chat_type = CHAT_TEAM
                     chat_message.player_id = self.player_id
                     chat_message.value = S_SPOTTED.format(coords = coords)
                     self.protocol.send_contained(chat_message, team =
                         self.team)
                     self.make_marker(Enemy, location)
                     presses.clear()
     return connection.on_animation_update(self, jump, crouch, sneak,
         sprint)
Exemplo n.º 21
0
 def on_animation_update(self, jump, crouch, sneak, sprint):
     markers_allowed = (VV_ENABLED and self.allow_markers
                        and self.protocol.allow_markers)
     if markers_allowed and sneak and self.world_object.sneak != sneak:
         now = seconds()
         if self.last_marker is None or now - self.last_marker > COOLDOWN:
             presses = self.sneak_presses
             presses.append(now)
             if len(presses) == 2 and presses[0] >= now - VV_TIMEFRAME:
                 location = self.get_there_location()
                 if location:
                     coords = to_coordinates(*location)
                     chat_message.chat_type = CHAT_TEAM
                     chat_message.player_id = self.player_id
                     chat_message.value = S_SPOTTED.format(
                         coords=coords)
                     self.protocol.send_contained(chat_message,
                                                  team=self.team)
                     self.make_marker(Enemy, location)
                     presses.clear()
     return connection.on_animation_update(self, jump, crouch, sneak,
                                           sprint)
Exemplo n.º 22
0
 def do_dangerzone(self):
     print("do_dangerzone")
     coords = to_coordinates(self.protocol.dz_x, self.protocol.dz_y)
     message = S_DZ_NOWDZ.format(coords = coords)
     self.protocol.send_chat(message)
     callLater(0.5, self.dangerzone_damage)
Exemplo n.º 23
0
 def test_to_coords(self):
     self.assertEqual(to_coordinates(511, 511), "H8")
Exemplo n.º 24
0
 def do_dangerzone(self):
     print("do_dangerzone")
     coords = to_coordinates(self.protocol.dz_x, self.protocol.dz_y)
     message = S_DZ_NOWDZ.format(coords=coords)
     self.protocol.send_chat(message)
     callLater(0.5, self.dangerzone_damage)
Exemplo n.º 25
0
 def end_dangerzone(self):
     coords = to_coordinates(self.protocol.dz_x, self.protocol.dz_y)
     message = S_DZ_END.format(coords=coords)
     self.protocol.send_chat(message)
     self.protocol.dangerzone_on = False
Exemplo n.º 26
0
 def end_dangerzone(self):
     coords = to_coordinates(self.protocol.dz_x, self.protocol.dz_y)
     message = S_DZ_END.format(coords = coords)
     self.protocol.send_chat(message)
     self.protocol.dangerzone_on = False