Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package l2s.gameserver.network.l2.c2s;
- import l2s.gameserver.data.BoatHolder;
- import l2s.gameserver.geodata.GeoEngine;
- import l2s.gameserver.model.Player;
- import l2s.gameserver.model.entity.boat.Boat;
- import l2s.gameserver.utils.Location;
- public class ValidatePosition extends L2GameClientPacket
- {
- private final Location _loc = new Location();
- private int _boatId;
- private Location _lastClientPosition;
- private Location _lastServerPosition;
- /**
- * packet type id 0x48
- * format: cddddd
- */
- @Override
- protected void readImpl()
- {
- _loc.x = readD();
- _loc.y = readD();
- _loc.z = readD();
- _loc.h = readD();
- _boatId = readD();
- }
- @Override
- protected void runImpl()
- {
- Player activeChar = getClient().getActiveChar();
- if(activeChar == null)
- return;
- if(activeChar.isTeleporting() || activeChar.isInObserverMode())
- return;
- _lastClientPosition = activeChar.getLastClientPosition();
- _lastServerPosition = activeChar.getLastServerPosition();
- if(_lastClientPosition == null)
- _lastClientPosition = activeChar.getLoc();
- if(_lastServerPosition == null)
- _lastServerPosition = activeChar.getLoc();
- if(activeChar.getX() == 0 && activeChar.getY() == 0 && activeChar.getZ() == 0)
- {
- correctPosition(activeChar);
- return;
- }
- if(activeChar.isInFlyingTransform())
- {
- // Π’ Π»ΠµΡ‚Π°Ρ�Ρ‰ΠµΠΉ Ρ‚Ρ€Π°Π½Ρ�Ρ„ΠΎΡ€ΠΌΠµ Π½ΠµΠ»Ρ�Π·Ρ� Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚Ρ�Ρ�Ρ� Π½Π° Ρ‚ΠµΡ€Ρ€ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Aden
- if(_loc.x > -166168)
- {
- activeChar.setTransform(null);
- return;
- }
- // Π’ Π»ΠµΡ‚Π°Ρ�Ρ‰ΠµΠΉ Ρ‚Ρ€Π°Π½Ρ�Ρ„ΠΎΡ€ΠΌΠµ Π½ΠµΠ»Ρ�Π·Ρ� Π»ΠµΡ‚Π°Ρ‚Ρ� Π½ΠΈΠ¶Πµ, Ρ‡ΠµΠΌ 0, ΠΈ Π²Ρ‹Ρ�Πµ, Ρ‡ΠµΠΌ 6000
- if(_loc.z <= 0 || _loc.z >= 6000)
- {
- activeChar.teleToLocation(activeChar.getLoc().setZ(Math.min(5950, Math.max(50, _loc.z))));
- return;
- }
- }
- double diff = activeChar.getDistance(_loc.x, _loc.y);
- int dz = Math.abs(_loc.z - activeChar.getZ());
- int h = _lastServerPosition.z - activeChar.getZ();
- if(_boatId > 0)
- {
- Boat boat = BoatHolder.getInstance().getBoat(_boatId);
- if(boat != null && activeChar.getBoat() == boat)
- {
- activeChar.setHeading(_loc.h);
- boat.validateLocationPacket(activeChar);
- }
- activeChar.setLastClientPosition(_loc.setH(activeChar.getHeading()));
- activeChar.setLastServerPosition(activeChar.getLoc());
- return;
- }
- // Π•Ρ�Π»ΠΈ ΠΌΡ‹ ΡƒΠ¶Πµ ΠΏΠ°Π΄Π°ΠµΠΌ, Ρ‚ΠΎ ΠΎΡ‚ΠΊΠ»Ρ�Ρ‡Π°ΠµΠΌ Π²Ρ�Πµ Π²Π°Π»ΠΈΠ΄ΠµΠΉΡ‚Ρ‹
- if(activeChar.isFalling())
- {
- diff = 0;
- dz = 0;
- h = 0;
- }
- if(h > activeChar.getBaseStats().getSafeFallHeight()) // Π�ΠΎΠΊΠ° ΠΏΠ°Π΄Π°ΠµΠΌ, Π²Ρ‹Ρ�ΠΎΡ‚Ρƒ Π½Πµ ΠΊΠΎΡ€Ρ€ΠµΠΊΡ‚ΠΈΡ€ΡƒΠµΠΌ
- {
- activeChar.falling(h);
- }
- else if(dz >= (activeChar.isFlying() ? 1024 : 512))
- {
- if(activeChar.getIncorrectValidateCount() >= 3)
- activeChar.teleToClosestTown();
- else
- {
- activeChar.teleToLocation(activeChar.getLoc());
- activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
- }
- }
- else if(dz >= 256)
- {
- activeChar.validateLocation(0);
- }
- else if(_loc.z < -30000 || _loc.z > 30000)
- {
- if(activeChar.getIncorrectValidateCount() >= 3)
- activeChar.teleToClosestTown();
- else
- {
- correctPosition(activeChar);
- activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
- }
- }
- else if(diff > 1024)
- {
- if(activeChar.getIncorrectValidateCount() >= 3)
- activeChar.teleToClosestTown();
- else
- {
- activeChar.teleToLocation(activeChar.getLoc());
- activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
- }
- }
- else if(diff > 256)
- {
- //TODO Ρ€ΠµΠ°Π»ΠΈΠ·ΠΎΠ²Π°Ρ‚Ρ� NetPing ΠΈ Π²Ρ‹Ρ‡ΠΈΡ�Π»Ρ�Ρ‚Ρ� ΠΏΡ€ΠµΠ΄ΠµΠ»Ρ�Π½ΠΎΠµ ΠΎΡ‚ΠΊΠ»ΠΎΠ½ΠµΠ½ΠΈΠµ ΠΈΡ�Ρ…ΠΎΠ΄Ρ� ΠΈΠ· ΠΏΠΈΠ½Π³Π° ΠΏΠΎ Ρ„ΠΎΡ€ΠΌΡƒΠ»Πµ: 16 + (ping * activeChar.getMoveSpeed()) / 1000
- activeChar.validateLocation(1);
- }
- else
- activeChar.setIncorrectValidateCount(0);
- activeChar.setLastClientPosition(_loc.setH(activeChar.getHeading()));
- activeChar.setLastServerPosition(activeChar.getLoc());
- }
- private void correctPosition(Player activeChar)
- {
- if(activeChar.isGM())
- {
- activeChar.sendMessage("Server loc: " + activeChar.getLoc());
- activeChar.sendMessage("Correcting position...");
- }
- if(_lastServerPosition.x != 0 && _lastServerPosition.y != 0 && _lastServerPosition.z != 0)
- {
- if(GeoEngine.getNSWE(_lastServerPosition.x, _lastServerPosition.y, _lastServerPosition.z, activeChar.getGeoIndex()) == GeoEngine.NSWE_ALL)
- activeChar.teleToLocation(_lastServerPosition);
- else
- activeChar.teleToClosestTown();
- }
- else if(_lastClientPosition.x != 0 && _lastClientPosition.y != 0 && _lastClientPosition.z != 0)
- {
- if(GeoEngine.getNSWE(_lastClientPosition.x, _lastClientPosition.y, _lastClientPosition.z, activeChar.getGeoIndex()) == GeoEngine.NSWE_ALL)
- activeChar.teleToLocation(_lastClientPosition);
- else
- activeChar.teleToClosestTown();
- }
- else
- activeChar.teleToClosestTown();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement