ChangeChannelHandler.java
资源名称:src.rar [点击查看]
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:6k
源码类别:
游戏
开发平台:
Java
- /*
- This file is part of the OdinMS Maple Story Server
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License version 3
- as published by the Free Software Foundation. You may not use, modify
- or distribute this program under any other version of the
- GNU Affero General Public License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.odinms.net.channel.handler;
- import java.net.InetAddress;
- import java.rmi.RemoteException;
- import net.sf.odinms.client.IItem;
- import net.sf.odinms.server.MapleInventoryManipulator;
- import net.sf.odinms.client.MapleBuffStat;
- import net.sf.odinms.client.MapleCharacter;
- import net.sf.odinms.client.MapleClient;
- import net.sf.odinms.net.AbstractMaplePacketHandler;
- import net.sf.odinms.net.channel.ChannelServer;
- import net.sf.odinms.net.world.MapleMessengerCharacter;
- import net.sf.odinms.net.world.remote.WorldChannelInterface;
- import net.sf.odinms.server.MapleTrade;
- import net.sf.odinms.server.PlayerInteraction.HiredMerchant;
- import net.sf.odinms.server.PlayerInteraction.IPlayerInteractionManager;
- import net.sf.odinms.server.PlayerInteraction.MaplePlayerShop;
- import net.sf.odinms.server.PlayerInteraction.MaplePlayerShopItem;
- import net.sf.odinms.server.PublicChatHandler;
- import net.sf.odinms.tools.MaplePacketCreator;
- import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
- /**
- *
- * @author Matze
- */
- public class ChangeChannelHandler extends AbstractMaplePacketHandler {
- public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
- int channel = slea.readByte() + 1; // there is some int after it...but...wtf?
- changeChannel(channel, c);
- }
- public static void changeChannel(int channel, MapleClient c) {
- MapleCharacter player = c.getPlayer();
- if (!player.isAlive()) {
- c.getSession().write(MaplePacketCreator.enableActions());
- return;
- }
- if (PublicChatHandler.getPublicChatHolder().containsKey(player.getId())) { // eww.
- PublicChatHandler.getPublicChatHolder().remove(player.getId());
- PublicChatHandler.getPublicChatHolder().put(player.getId(), channel);
- }
- String ip = ChannelServer.getInstance(c.getChannel()).getIP(channel);
- String[] socket = ip.split(":");
- if (player.getTrade() != null) {
- MapleTrade.cancelTrade(player);
- }
- player.cancelMagicDoor();
- if (player.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
- player.cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
- }
- IPlayerInteractionManager playershop = player.getInteraction(); // just for safety.
- if (playershop != null) {
- if (playershop.isOwner(player)) {
- if (playershop instanceof HiredMerchant) {
- HiredMerchant hm = (HiredMerchant) playershop;
- hm.setOpen(true);
- } else if (playershop instanceof MaplePlayerShop) {
- for (MaplePlayerShopItem items : playershop.getItems()) {
- if (items.getBundles() > 0) {
- IItem item = items.getItem();
- item.setQuantity(items.getBundles());
- MapleInventoryManipulator.addFromDrop(c, item);
- }
- }
- playershop.closeShop(false); // wont happen unless some idiot hacks, hopefully ?
- }
- } else {
- playershop.removeVisitor(player);
- }
- }
- if (!player.getDiseases().isEmpty()) {
- player.cancelAllDebuffs();
- }
- if (player.getBuffedValue(MapleBuffStat.SUMMON) != null) {
- player.cancelEffectFromBuffStat(MapleBuffStat.SUMMON);
- }
- if (player.getBuffedValue(MapleBuffStat.PUPPET) != null) {
- player.cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
- }
- try {
- WorldChannelInterface wci = c.getChannelServer().getWorldInterface();
- wci.addBuffsToStorage(player.getId(), player.getAllBuffs());
- wci.addCooldownsToStorage(player.getId(), player.getAllCooldowns());
- if (player.getMessenger() != null) {
- MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player);
- wci.silentLeaveMessenger(player.getMessenger().getId(), messengerplayer);
- }
- } catch (RemoteException e) {
- c.getChannelServer().reconnectWorld();
- }
- player.saveToDB(true, true);
- if (player.getCheatTracker() != null) {
- player.getCheatTracker().dispose();
- }
- player.getMap().removePlayer(player);
- c.getChannelServer().removePlayer(player);
- c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
- try {
- c.getSession().write(MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }