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

游戏

开发平台:

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.net.InetAddress;
  20. import net.sf.odinms.client.MapleCharacter;
  21. import net.sf.odinms.client.MapleClient;
  22. import net.sf.odinms.net.AbstractMaplePacketHandler;
  23. import net.sf.odinms.net.MaplePacket;
  24. import net.sf.odinms.net.channel.ChannelServer;
  25. import net.sf.odinms.server.MaplePortal;
  26. import net.sf.odinms.server.maps.MapleMap;
  27. import net.sf.odinms.tools.MaplePacketCreator;
  28. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. public class ChangeMapHandler extends AbstractMaplePacketHandler {
  32.     private static Logger log = LoggerFactory.getLogger(ChangeMapHandler.class);
  33.     @Override
  34.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  35.         c.getPlayer().resetAfkTime();
  36.         if (slea.available() == 0) {
  37.             int channel = c.getChannel();
  38.             String ip = ChannelServer.getInstance(c.getChannel()).getIP(channel);
  39.             String[] socket = ip.split(":");
  40.             c.getPlayer().saveToDB(true, true);
  41.             c.getPlayer().setInCS(false);
  42.             c.getPlayer().setInMTS(false);
  43.             ChannelServer.getInstance(c.getChannel()).removePlayer(c.getPlayer());
  44.             c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
  45.             try {
  46.                 MaplePacket packet = MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]));
  47.                 c.getSession().write(packet);
  48.                 c.getSession().close();
  49.             } catch (Exception e) {
  50.                 throw new RuntimeException(e);
  51.             }
  52.         } else {
  53.             byte type = slea.readByte(); // 1 = from dying 2 = regular portals
  54.             int targetid = slea.readInt(); // FF FF FF FF
  55.             String startwp = slea.readMapleAsciiString();
  56.             MaplePortal portal = c.getPlayer().getMap().getPortal(startwp);
  57.             MapleCharacter player = c.getPlayer();
  58.             if (targetid != -1 && !c.getPlayer().isAlive()) {
  59.                 boolean executeStandardPath = true;
  60.                 if (player.getEventInstance() != null) {
  61.                     executeStandardPath = player.getEventInstance().revivePlayer(player);
  62.                 }
  63.                 if (executeStandardPath) {
  64.                     player.cancelAllBuffs();
  65.                     player.setHp(50);
  66.                     MapleMap to = player.getMap().getReturnMap();
  67.                     MaplePortal pto = to.getPortal(0);
  68.                     player.setStance(0);
  69.                     player.changeMap(to, pto);
  70.                 }
  71.             } else if (targetid != -1 && player.isGM()) {
  72.                 MapleMap to = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(targetid);
  73.                 MaplePortal pto = to.getPortal(0);
  74.                 player.changeMap(to, pto);
  75.             } else if (targetid != -1 && !player.isGM()) {
  76.                 System.err.println("玩家 {} attempted Map jumping without being a GM"+ c.getPlayer().getName());
  77.             } else {
  78.                 if (portal != null) {
  79.                     portal.enterPortal(c);
  80. /*
  81.                     if (player.getClan() == -1 && !c.isGuest()) {
  82.                         for (int i = 0; i < 3; i++) {
  83.                             player.dropMessage(6, "You have yet to join a clan ! Type @clan to join a clan..");
  84.                         }
  85.                     }*/
  86.                 } else {
  87.                     c.getSession().write(MaplePacketCreator.enableActions());
  88.                     log.warn("传送点 {} 不存在该地图: {}", startwp, player.getMap().getId());
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }