Exemple #1
0
    def update(self):
        # Prevent updates while teleporting
        if self.is_teleporting:
            return

        now = time.time()
        if now > self.last_tick > 0:
            elapsed = now - self.last_tick

            # Update played time
            self.player.totaltime += elapsed
            self.player.leveltime += elapsed

            # Regeneration
            self.regenerate(now)
            # Attack update
            self.attack_update(elapsed)

            # Release spirit timer
            if not self.is_alive:
                if self.spirit_release_timer < 300:  # 5 min
                    self.spirit_release_timer += elapsed
                else:
                    self.repop()
        self.last_tick = now

        if self.dirty:
            self.send_update_self()
            self.send_update_surrounding(self.generate_proper_update_packet())
            GridManager.update_object(self)
            self.reset_fields()

            self.set_dirty(is_dirty=False, dirty_inventory=False)
Exemple #2
0
    def update(self):
        now = time.time()

        if now > self.last_tick > 0:
            elapsed = now - self.last_tick
            self.player.totaltime += elapsed
            self.player.leveltime += elapsed
        self.last_tick = now

        if self.flagged_for_update:
            self.session.request.sendall(
                PacketWriter.get_packet(
                    OpCode.SMSG_UPDATE_OBJECT,
                    self.get_update_packet(update_type=UpdateTypes.UPDATE_FULL,
                                           is_self=True)))

            GridManager.send_surrounding(PacketWriter.get_packet(
                OpCode.SMSG_UPDATE_OBJECT,
                self.get_update_packet(update_type=UpdateTypes.UPDATE_FULL,
                                       is_self=False)),
                                         self,
                                         include_self=False)

            GridManager.update_object(self)

            self.flagged_for_update = False
Exemple #3
0
    def complete_login(self):
        self.is_online = True

        GridManager.update_object(self)
        self.send_update_surrounding(
            self.generate_proper_update_packet(create=True),
            include_self=False,
            create=True)
Exemple #4
0
    def handle_ack(world_session, socket, reader):
        world_session.player_mgr.send_update_self()
        world_session.player_mgr.send_update_surrounding()
        GridManager.update_object(world_session.player_mgr)

        world_session.player_mgr.is_teleporting = False

        return 0
Exemple #5
0
    def handle_ack(world_session, socket, reader):
        world_session.player_mgr.send_update_self(create=True)
        world_session.player_mgr.send_update_surrounding(world_session.player_mgr.generate_proper_update_packet(
            create=True), include_self=False, create=True)
        GridManager.update_object(world_session.player_mgr)

        world_session.player_mgr.is_teleporting = False

        return 0
Exemple #6
0
    def update(self):
        now = time.time()

        if now > self.last_tick > 0:
            elapsed = now - self.last_tick
            self.player.totaltime += elapsed
            self.player.leveltime += elapsed
        self.last_tick = now

        if self.flagged_for_update:
            self.send_update_self()
            self.send_update_surrounding()
            GridManager.update_object(self)

            self.flagged_for_update = False
    def update_pending_waypoints(self, elapsed):
        if not self.should_update_waypoints:
            return

        self.total_waypoint_timer += elapsed
        self.waypoint_timer += elapsed
        # Set elapsed time to the current movement spline data
        if self.unit.movement_spline:
            if self.unit.movement_spline.elapsed < self.unit.movement_spline.total_time:
                self.unit.movement_spline.elapsed += elapsed * 1000
                if self.unit.movement_spline.elapsed > self.unit.movement_spline.total_time:
                    self.unit.movement_spline.elapsed = self.unit.movement_spline.total_time

        waypoint_length = len(self.pending_waypoints)
        if waypoint_length > 0:
            current_waypoint = self.pending_waypoints[0]
            if self.total_waypoint_timer > current_waypoint.expected_timestamp:
                new_position = current_waypoint.location
                self.last_position = new_position
                self.waypoint_timer = 0

                self.pending_waypoints.pop(0)
            # Guess current position based on speed and time
            else:
                guessed_distance = self.speed * self.waypoint_timer
                new_position = self.last_position.get_point_in_between(
                    guessed_distance, current_waypoint.location)

            if new_position:
                self.unit.location.x = new_position.x
                self.unit.location.y = new_position.y
                self.unit.location.z = new_position.z

                GridManager.update_object(self.unit)
        else:
            # Path finished
            if self.total_waypoint_timer > self.total_waypoint_time:
                if self.is_player and self.unit.pending_taxi_destination:
                    self.unit.unit_flags &= ~(UnitFlags.UNIT_FLAG_FROZEN |
                                              UnitFlags.UNIT_FLAG_TAXI_FLIGHT)
                    self.unit.set_uint32(UnitFields.UNIT_FIELD_FLAGS,
                                         self.unit.unit_flags)
                    self.unit.unmount()
                    self.unit.teleport(self.unit.map_,
                                       self.unit.pending_taxi_destination)
                    self.unit.pending_taxi_destination = None
                self.reset()
    def handle_movement_status(world_session, socket, reader):
        movement_fmt = '<QfffffffffI'

        if not world_session.player_mgr.is_teleporting and len(
                reader.data
        ) >= 48:  # Avoid handling malformed movement packets
            try:
                transport_guid, transport_x, transport_y, transport_z, transport_o, x, y, z, o, pitch, flags = \
                    unpack(movement_fmt, reader.data[:48])

                world_session.player_mgr.transport_id = transport_guid

                world_session.player_mgr.transport_x = transport_x
                world_session.player_mgr.transport_y = transport_y
                world_session.player_mgr.transport_z = transport_z
                world_session.player_mgr.transport_orientation = transport_o

                world_session.player_mgr.location.x = x
                world_session.player_mgr.location.y = y
                world_session.player_mgr.location.z = z
                world_session.player_mgr.location.o = o

                world_session.player_mgr.pitch = pitch
                world_session.player_mgr.movement_flags = flags

                movement_data = pack('<Q%us' % len(reader.data),
                                     world_session.player_mgr.guid,
                                     reader.data)

                GridManager.send_surrounding(PacketWriter.get_packet(
                    OpCode(reader.opcode), movement_data),
                                             world_session.player_mgr,
                                             include_self=False)
                GridManager.update_object(world_session.player_mgr)
                world_session.player_mgr.sync_player()

                if reader.opcode == OpCode.MSG_MOVE_JUMP and \
                        world_session.player_mgr.stand_state != StandState.UNIT_DEAD and \
                        world_session.player_mgr.stand_state != StandState.UNIT_STANDING:
                    world_session.player_mgr.stand_state = StandState.UNIT_STANDING
                    world_session.player_mgr.flagged_for_update = True

            except (AttributeError, error):
                Logger.error('Error while handling %s, skipping. Data: %s' %
                             (OpCode(reader.opcode), reader.data))

        return 0
    def update(self):
        now = time.time()
        if now > self.last_tick > 0:
            elapsed = now - self.last_tick

            if self.is_alive:
                # Spell/aura updates
                self.spell_manager.update(now)
                self.aura_manager.update(elapsed)
                # Movement Updates
                self.movement_manager.update_pending_waypoints(elapsed)
                # Random Movement
                if not self.in_combat and self.creature_instance.movement_type == MovementTypes.WANDER:
                    if len(self.movement_manager.pending_waypoints) == 0:
                        if now > self.last_random_movement + self.random_movement_wait_time:
                            self.movement_manager.move_random(
                                self.spawn_position,
                                self.creature_instance.wander_distance)
                            self.random_movement_wait_time = randint(1, 12)
                            self.last_random_movement = now
            # Dead
            else:
                self.respawn_timer += elapsed
                if self.respawn_timer >= self.respawn_time:
                    self.respawn()
                # Destroy body when creature is about to respawn
                elif self.is_spawned and self.respawn_timer >= self.respawn_time * 0.8:
                    self.is_spawned = False
                    GridManager.send_surrounding(self.get_destroy_packet(),
                                                 self,
                                                 include_self=False)
        self.last_tick = now

        if self.dirty:
            GridManager.send_surrounding(
                self.generate_proper_update_packet(create=False),
                self,
                include_self=False)
            GridManager.update_object(self)
            self.reset_fields()

            self.set_dirty(is_dirty=False)
Exemple #10
0
    def handle_ack(world_session, socket, reader):
        world_session.player_mgr.send_update_self(create=True,
                                                  force_inventory_update=True,
                                                  reset_fields=False)
        world_session.player_mgr.send_update_surrounding(
            world_session.player_mgr.generate_proper_update_packet(
                create=True),
            include_self=False,
            create=True,
            force_inventory_update=True)
        GridManager.update_object(world_session.player_mgr)
        world_session.player_mgr.reset_fields()

        world_session.player_mgr.is_teleporting = False

        # Update group info after a teleport
        if world_session.player_mgr.group_manager:
            world_session.player_mgr.group_manager.send_update()

        return 0
    def handle_movement_status(world_session, socket, reader):
        # Avoid handling malformed movement packets, or handling them while no player or player teleporting
        if world_session.player_mgr and len(reader.data) >= 48:
            try:
                transport_guid, transport_x, transport_y, transport_z, transport_o, x, y, z, o, pitch, flags = \
                    unpack('<Q9fI', reader.data[:48])

                # Hacky way to prevent random teleports when colliding with elevators
                # Also acts as a rudimentary teleport cheat detection
                if not world_session.player_mgr.pending_taxi_destination and world_session.player_mgr.location.distance(
                        x=x, y=y, z=z) > 64:
                    Logger.anticheat(
                        f'Preventing coordinate desync from player {world_session.player_mgr.player.name} ({world_session.player_mgr.guid}).'
                    )
                    world_session.player_mgr.teleport(
                        world_session.player_mgr.map_,
                        world_session.player_mgr.location)

                    return 0

                # Send movement info to SpellManager until movement handling is merged to update system
                if flags & 0xF != 0:  # MoveFlags.MOVEFLAG_MOVE_MASK | MoveFlags.MOVEFLAG_STRAFE_MASK
                    world_session.player_mgr.spell_manager.flag_as_moved()

                world_session.player_mgr.transport_id = transport_guid

                world_session.player_mgr.transport.x = transport_x
                world_session.player_mgr.transport.y = transport_y
                world_session.player_mgr.transport.z = transport_z
                world_session.player_mgr.transport.o = transport_o

                world_session.player_mgr.location.x = x
                world_session.player_mgr.location.y = y
                world_session.player_mgr.location.z = z
                world_session.player_mgr.location.o = o

                world_session.player_mgr.pitch = pitch
                world_session.player_mgr.movement_flags = flags

                if flags & MoveFlags.MOVEFLAG_SPLINE_MOVER:
                    world_session.player_mgr.movement_spline = MovementManager.MovementSpline.from_bytes(
                        reader.data[48:])

                movement_data = pack(f'<Q{len(reader.data)}s',
                                     world_session.player_mgr.guid,
                                     reader.data)

                GridManager.send_surrounding(PacketWriter.get_packet(
                    OpCode(reader.opcode), movement_data),
                                             world_session.player_mgr,
                                             include_self=False)
                GridManager.update_object(world_session.player_mgr)
                world_session.player_mgr.sync_player()

                # Get up if you jump while not standing
                if reader.opcode == OpCode.MSG_MOVE_JUMP and \
                        world_session.player_mgr.stand_state != StandState.UNIT_DEAD and \
                        world_session.player_mgr.stand_state != StandState.UNIT_STANDING:
                    world_session.player_mgr.stand_state = StandState.UNIT_STANDING
                    world_session.player_mgr.set_dirty()

            except (AttributeError, error):
                Logger.error(
                    f'Error while handling {OpCode(reader.opcode).name}, skipping. Data: {reader.data}'
                )

        return 0
Exemple #12
0
 def complete_login(self):
     self.is_online = True
     GridManager.update_object(self)
     self.update_surrounding()
Exemple #13
0
    def handle_movement_status(world_session, socket, reader):
        # Avoid handling malformed movement packets, or handling them while no player or player teleporting
        if world_session.player_mgr and not world_session.player_mgr.is_teleporting and len(reader.data) >= 48:
            try:
                transport_guid, transport_x, transport_y, transport_z, transport_o, x, y, z, o, pitch, flags = \
                    unpack('<Q9fI', reader.data[:48])

                # Hacky way to prevent random teleports when colliding with elevators
                # Also acts as a rudimentary teleport cheat detection
                if not world_session.player_mgr.pending_taxi_destination and world_session.player_mgr.location.distance(
                        x=x, y=y, z=z) > 64:
                    Logger.anticheat("Preventing coordinate desync from player %s (%s)." %
                                     (world_session.player_mgr.player.name, world_session.player_mgr.guid))
                    world_session.player_mgr.teleport(world_session.player_mgr.map_,
                                                      world_session.player_mgr.location)

                    return 0

                world_session.player_mgr.transport_id = transport_guid

                world_session.player_mgr.transport.x = transport_x
                world_session.player_mgr.transport.y = transport_y
                world_session.player_mgr.transport.z = transport_z
                world_session.player_mgr.transport.o = transport_o

                world_session.player_mgr.location.x = x
                world_session.player_mgr.location.y = y
                world_session.player_mgr.location.z = z
                world_session.player_mgr.location.o = o

                world_session.player_mgr.pitch = pitch
                world_session.player_mgr.movement_flags = flags

                if flags & MoveFlags.MOVEFLAG_SPLINE_MOVER:
                    world_session.player_mgr.movement_spline = MovementManager.MovementSpline.from_bytes(
                        reader.data[48:])

                movement_data = pack('<Q%us' % len(reader.data),
                                     world_session.player_mgr.guid,
                                     reader.data)

                GridManager.send_surrounding(PacketWriter.get_packet(OpCode(reader.opcode), movement_data),
                                             world_session.player_mgr, include_self=False)
                GridManager.update_object(world_session.player_mgr)
                world_session.player_mgr.sync_player()

                # Hackfix for client not sending CMSG_ATTACKSWING.
                # m_combat.m_attackSent getting stuck in true: https://i.imgur.com/LLasM8i.png
                # if reader.opcode == OpCode.MSG_MOVE_STOP or \
                #        reader.opcode == OpCode.MSG_MOVE_STOP_PITCH or \
                #        reader.opcode == OpCode.MSG_MOVE_STOP_STRAFE or \
                #        reader.opcode == OpCode.MSG_MOVE_STOP_TURN:
                #    data = pack('<2QI', world_session.player_mgr.guid, 0, 0)
                #    socket.sendall(PacketWriter.get_packet(OpCode.SMSG_ATTACKSTOP, data))

                # Get up if you jump while not standing
                if reader.opcode == OpCode.MSG_MOVE_JUMP and \
                        world_session.player_mgr.stand_state != StandState.UNIT_DEAD and \
                        world_session.player_mgr.stand_state != StandState.UNIT_STANDING:
                    world_session.player_mgr.stand_state = StandState.UNIT_STANDING
                    world_session.player_mgr.set_dirty()

            except (AttributeError, error):
                Logger.error('Error while handling %s, skipping. Data: %s' % (OpCode(reader.opcode), reader.data))

        return 0
    def handle_movement_status(world_session, socket, reader):
        movement_fmt = '<QfffffffffI'

        if not world_session.player_mgr.is_teleporting and len(
                reader.data
        ) >= 48:  # Avoid handling malformed movement packets
            try:
                transport_guid, transport_x, transport_y, transport_z, transport_o, x, y, z, o, pitch, flags = \
                    unpack(movement_fmt, reader.data[:48])

                # Hacky way to prevent random teleports when colliding with elevators
                # Also acts as a rudimentary teleport cheat detection
                if world_session.player_mgr.location.distance(x=x, y=y,
                                                              z=z) > 64:
                    Logger.anticheat(
                        "Preventing coordinate desync from player %s (%s)." %
                        (world_session.player_mgr.player.name,
                         world_session.player_mgr.guid))
                    world_session.player_mgr.teleport(
                        world_session.player_mgr.map_,
                        world_session.player_mgr.location)

                    return 0

                world_session.player_mgr.transport_id = transport_guid

                world_session.player_mgr.transport.x = transport_x
                world_session.player_mgr.transport.y = transport_y
                world_session.player_mgr.transport.z = transport_z
                world_session.player_mgr.transport.o = transport_o

                world_session.player_mgr.location.x = x
                world_session.player_mgr.location.y = y
                world_session.player_mgr.location.z = z
                world_session.player_mgr.location.o = o

                world_session.player_mgr.pitch = pitch
                world_session.player_mgr.movement_flags = flags

                movement_data = pack('<Q%us' % len(reader.data),
                                     world_session.player_mgr.guid,
                                     reader.data)

                GridManager.send_surrounding(PacketWriter.get_packet(
                    OpCode(reader.opcode), movement_data),
                                             world_session.player_mgr,
                                             include_self=False)
                GridManager.update_object(world_session.player_mgr)
                world_session.player_mgr.sync_player()

                if reader.opcode == OpCode.MSG_MOVE_JUMP and \
                        world_session.player_mgr.stand_state != StandState.UNIT_DEAD and \
                        world_session.player_mgr.stand_state != StandState.UNIT_STANDING:
                    world_session.player_mgr.stand_state = StandState.UNIT_STANDING
                    world_session.player_mgr.flagged_for_update = True

            except (AttributeError, error):
                Logger.error('Error while handling %s, skipping. Data: %s' %
                             (OpCode(reader.opcode), reader.data))

        return 0