MovePlayerHandler.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:6k
源码类别:

游戏

开发平台:

Java

  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. package net.sf.odinms.net.channel.handler;
  19. import java.util.List;
  20. import net.sf.odinms.client.MapleCharacter;
  21. import net.sf.odinms.client.MapleClient;
  22. import net.sf.odinms.client.anticheat.CheatingOffense;
  23. import net.sf.odinms.net.MaplePacket;
  24. import net.sf.odinms.server.maps.FakeCharacter;
  25. import net.sf.odinms.server.movement.AbsoluteLifeMovement;
  26. import net.sf.odinms.server.TimerManager;
  27. import net.sf.odinms.server.movement.LifeMovementFragment;
  28. import net.sf.odinms.tools.MaplePacketCreator;
  29. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  30. import org.slf4j.Logger;
  31. import org.slf4j.LoggerFactory;
  32. public class MovePlayerHandler extends AbstractMovementPacketHandler {
  33.     private static Logger log = LoggerFactory.getLogger(MovePlayerHandler.class);
  34.     @Override
  35.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  36.         c.getPlayer().resetAfkTime();
  37.         slea.readByte();
  38.         slea.readInt();
  39.         // log.trace("Movement command received: unk1 {} unk2 {}", new Object[] { unk1, unk2 });
  40.         final List<LifeMovementFragment> res = parseMovement(slea);
  41.         // TODO more validation of input data
  42.         if (res != null) {
  43.             if (slea.available() != 18) {
  44.                 return;
  45.             }
  46.             MapleCharacter player = c.getPlayer();
  47.             MaplePacket packet = MaplePacketCreator.movePlayer(player.getId(), res);
  48.             if (!player.isHidden()) {
  49.                 c.getPlayer().getMap().broadcastMessage(player, packet, false);
  50.             } else {
  51.                 c.getPlayer().getMap().broadcastGMMessage(player, packet, false);
  52.             }
  53.             // c.getSession().write(MaplePacketCreator.movePlayer(30000, res));
  54.             if (CheatingOffense.FAST_MOVE.isEnabled() || CheatingOffense.HIGH_JUMP.isEnabled()) {
  55.                 checkMovementSpeed(c.getPlayer(), res);
  56.             }
  57.             updatePosition(res, c.getPlayer(), 0);
  58.             c.getPlayer().getMap().movePlayer(c.getPlayer(), c.getPlayer().getPosition());
  59.             if (c.getPlayer().hasFakeChar()) {
  60.                 int i = 1;
  61.                 for (final FakeCharacter ch : c.getPlayer().getFakeChars()) {
  62.                     if (ch.follow() && ch.getFakeChar().getMap() == player.getMap()) {
  63.                         TimerManager.getInstance().schedule(new Runnable() {
  64.                             @Override
  65.                             public void run() {
  66.                                 ch.getFakeChar().getMap().broadcastMessage(ch.getFakeChar(), MaplePacketCreator.movePlayer(ch.getFakeChar().getId(), res), false);
  67.                                 updatePosition(res, ch.getFakeChar(), 0);
  68.                                 ch.getFakeChar().getMap().movePlayer(ch.getFakeChar(), ch.getFakeChar().getPosition());
  69.                             }
  70.                         }, i * 300);
  71.                         i++;
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.     }
  77.     private static void checkMovementSpeed(MapleCharacter chr, List<LifeMovementFragment> moves) {
  78.         // boolean wasALM = true;
  79.         // Point oldPosition = new Point (c.getPlayer().getPosition());
  80.         double playerSpeedMod = chr.getSpeedMod() + 0.005;
  81.         // double playerJumpMod = c.getPlayer().getJumpMod() + 0.005;
  82.         boolean encounteredUnk0 = false;
  83.         for (LifeMovementFragment lmf : moves) {
  84.             if (lmf.getClass() == AbsoluteLifeMovement.class) {
  85.                 final AbsoluteLifeMovement alm = (AbsoluteLifeMovement) lmf;
  86.                 double speedMod = Math.abs(alm.getPixelsPerSecond().x) / 125.0;
  87.                 // int distancePerSec = Math.abs(alm.getPixelsPerSecond().x);
  88.                 // double jumpMod = Math.abs(alm.getPixelsPerSecond().y) / 525.0;
  89.                 // double normalSpeed = distancePerSec / playerSpeedMod;
  90.                 // System.out.println(speedMod + "(" + playerSpeedMod + ") " + alm.getUnk());
  91.                 if (speedMod > playerSpeedMod) {
  92.                     if (alm.getUnk() == 0) { // to prevent FJ fucking us
  93.                         encounteredUnk0 = true;
  94.                     }
  95.                     if (!encounteredUnk0) {
  96.                         if (speedMod > playerSpeedMod) {
  97.                             chr.getCheatTracker().registerOffense(CheatingOffense.FAST_MOVE);
  98.                         }
  99.                     }
  100.                 }
  101.             // if (wasALM && (oldPosition.y == newPosition.y)) {
  102.             // int distance = Math.abs(oldPosition.x - newPosition.x);
  103.             // if (alm.getDuration() > 60) { // short durations are strange and show too fast movement
  104.             // double distancePerSec = (distance / (double) ((LifeMovement) move).getDuration()) * 1000.0;
  105.             // double speedMod = distancePerSec / 125.0;
  106.             // double normalSpeed = distancePerSec / playerSpeedMod;
  107.             // System.out.println(speedMod + " " + normalSpeed + " " + distancePerSec + " " + distance + " "
  108.             // + alm.getWobble());
  109.             // }
  110.             // }
  111.             // oldPosition = newPosition;
  112.             // wasALM = true;
  113.             // } else {
  114.             // wasALM = false;
  115.             }
  116.         }
  117.     }
  118. }