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

游戏

开发平台:

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;
  19. import net.sf.odinms.net.handler.KeepAliveHandler;
  20. import net.sf.odinms.net.handler.LoginRequiringNoOpHandler;
  21. import net.sf.odinms.net.channel.handler.*;
  22. import net.sf.odinms.net.login.handler.*;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. public final class PacketProcessor {
  26.     private static Logger log = LoggerFactory.getLogger(PacketProcessor.class);
  27.     public enum Mode {
  28.         LOGINSERVER,
  29.         CHANNELSERVER
  30.     };
  31.     private static PacketProcessor instance;
  32.     private MaplePacketHandler[] handlers;
  33.     private PacketProcessor() {
  34.         int maxRecvOp = 0;
  35.         for (RecvPacketOpcode op : RecvPacketOpcode.values()) {
  36.             if (op.getValue() > maxRecvOp) {
  37.                 maxRecvOp = op.getValue();
  38.             }
  39.         }
  40.         handlers = new MaplePacketHandler[maxRecvOp + 1];
  41.     }
  42.     public MaplePacketHandler getHandler(short packetId) {
  43.         if (packetId > handlers.length) {
  44.             return null;
  45.         }
  46.         MaplePacketHandler handler = handlers[packetId];
  47.         if (handler != null) {
  48.             return handler;
  49.         }
  50.         return null;
  51.     }
  52.     public void registerHandler(RecvPacketOpcode code, MaplePacketHandler handler) {
  53.         try {
  54.             handlers[code.getValue()] = handler;
  55.         } catch (ArrayIndexOutOfBoundsException aiobe) {
  56.             log.error("Check your Recv Packet Opcodes - Something is wrong");
  57.         }
  58.     }
  59.     public synchronized static PacketProcessor getProcessor(Mode mode) {
  60.         if (instance == null) {
  61.             instance = new PacketProcessor();
  62.             instance.reset(mode);
  63.         }
  64.         return instance;
  65.     }
  66.     public void reset(Mode mode) {
  67.         handlers = new MaplePacketHandler[handlers.length];
  68.         registerHandler(RecvPacketOpcode.PONG, new KeepAliveHandler());
  69.         if (mode == Mode.LOGINSERVER) {
  70.             registerHandler(RecvPacketOpcode.AFTER_LOGIN, new AfterLoginHandler());
  71.             registerHandler(RecvPacketOpcode.SERVERLIST_REREQUEST, new ServerlistRequestHandler());
  72.             registerHandler(RecvPacketOpcode.CHARLIST_REQUEST, new CharlistRequestHandler());
  73.             registerHandler(RecvPacketOpcode.CHAR_SELECT, new CharSelectedHandler());
  74.             registerHandler(RecvPacketOpcode.LOGIN_PASSWORD, new LoginPasswordHandler());
  75.             registerHandler(RecvPacketOpcode.RELOG, new RelogRequestHandler());
  76.             registerHandler(RecvPacketOpcode.GUEST_LOGIN, new GuestLoginHandler());
  77.             registerHandler(RecvPacketOpcode.SERVERLIST_REQUEST, new ServerlistRequestHandler());
  78.             registerHandler(RecvPacketOpcode.PLAYER_DC, new PlayerDCHandler());
  79.             registerHandler(RecvPacketOpcode.SERVERSTATUS_REQUEST, new ServerStatusRequestHandler());
  80.             registerHandler(RecvPacketOpcode.CHECK_CHAR_NAME, new CheckCharNameHandler());
  81.             registerHandler(RecvPacketOpcode.CREATE_CHAR, new CreateCharHandler());
  82.             registerHandler(RecvPacketOpcode.DELETE_CHAR, new DeleteCharHandler());
  83.             registerHandler(RecvPacketOpcode.VIEW_ALL_CHAR, new ViewCharHandler());
  84.             registerHandler(RecvPacketOpcode.PICK_ALL_CHAR, new PickCharHandler());
  85.         } else if (mode == Mode.CHANNELSERVER) {
  86.             registerHandler(RecvPacketOpcode.CHANGE_CHANNEL, new ChangeChannelHandler());
  87.             registerHandler(RecvPacketOpcode.STRANGE_DATA, LoginRequiringNoOpHandler.getInstance());
  88.             registerHandler(RecvPacketOpcode.GENERAL_CHAT, new GeneralchatHandler());
  89.             registerHandler(RecvPacketOpcode.WHISPER, new WhisperHandler());
  90.             registerHandler(RecvPacketOpcode.NPC_TALK, new NPCTalkHandler());
  91.             registerHandler(RecvPacketOpcode.NPC_TALK_MORE, new NPCMoreTalkHandler());
  92.             registerHandler(RecvPacketOpcode.QUEST_ACTION, new QuestActionHandler());
  93.             registerHandler(RecvPacketOpcode.NPC_SHOP, new NPCShopHandler());
  94.             registerHandler(RecvPacketOpcode.ITEM_SORT, new ItemSortHandler());
  95.             registerHandler(RecvPacketOpcode.ITEM_SORT2, new ItemSortHandler2());
  96.             registerHandler(RecvPacketOpcode.ITEM_MOVE, new ItemMoveHandler());
  97.             registerHandler(RecvPacketOpcode.MESO_DROP, new MesoDropHandler());
  98.             registerHandler(RecvPacketOpcode.PLAYER_LOGGEDIN, new PlayerLoggedinHandler());
  99.             registerHandler(RecvPacketOpcode.CHANGE_MAP, new ChangeMapHandler());
  100.             registerHandler(RecvPacketOpcode.MOVE_LIFE, new MoveLifeHandler());
  101.             registerHandler(RecvPacketOpcode.CLOSE_RANGE_ATTACK, new CloseRangeDamageHandler());
  102.             registerHandler(RecvPacketOpcode.RANGED_ATTACK, new RangedAttackHandler());
  103.             registerHandler(RecvPacketOpcode.MAGIC_ATTACK, new MagicDamageHandler());
  104.             registerHandler(RecvPacketOpcode.TAKE_DAMAGE, new TakeDamageHandler());
  105.             registerHandler(RecvPacketOpcode.MOVE_PLAYER, new MovePlayerHandler());
  106.             registerHandler(RecvPacketOpcode.USE_CASH_ITEM, new UseCashItemHandler());
  107.             registerHandler(RecvPacketOpcode.USE_ITEM, new UseItemHandler());
  108.             registerHandler(RecvPacketOpcode.USE_RETURN_SCROLL, new UseItemHandler());
  109.             registerHandler(RecvPacketOpcode.USE_UPGRADE_SCROLL, new ScrollHandler());
  110.             registerHandler(RecvPacketOpcode.USE_SUMMON_BAG, new UseSummonBag());
  111.             registerHandler(RecvPacketOpcode.FACE_EXPRESSION, new FaceExpressionHandler());
  112.             registerHandler(RecvPacketOpcode.HEAL_OVER_TIME, new HealOvertimeHandler());
  113.             registerHandler(RecvPacketOpcode.ITEM_PICKUP, new ItemPickupHandler());
  114.             registerHandler(RecvPacketOpcode.CHAR_INFO_REQUEST, new CharInfoRequestHandler());
  115.             registerHandler(RecvPacketOpcode.SPECIAL_MOVE, new SpecialMoveHandler());
  116.             registerHandler(RecvPacketOpcode.USE_INNER_PORTAL, new InnerPortalHandler());
  117.             registerHandler(RecvPacketOpcode.CANCEL_BUFF, new CancelBuffHandler());
  118.             registerHandler(RecvPacketOpcode.CANCEL_ITEM_EFFECT, new CancelItemEffectHandler());
  119.             registerHandler(RecvPacketOpcode.PLAYER_INTERACTION, new PlayerInteractionHandler());
  120.             registerHandler(RecvPacketOpcode.DISTRIBUTE_AP, new DistributeAPHandler());
  121.             registerHandler(RecvPacketOpcode.DISTRIBUTE_SP, new DistributeSPHandler());
  122.             registerHandler(RecvPacketOpcode.CHANGE_KEYMAP, new KeymapChangeHandler());
  123.             registerHandler(RecvPacketOpcode.CHANGE_MAP_SPECIAL, new ChangeMapSpecialHandler());
  124.             registerHandler(RecvPacketOpcode.STORAGE, new StorageHandler());
  125.             registerHandler(RecvPacketOpcode.GIVE_FAME, new GiveFameHandler());
  126.             registerHandler(RecvPacketOpcode.PARTY_OPERATION, new PartyOperationHandler());
  127.             registerHandler(RecvPacketOpcode.DENY_PARTY_REQUEST, new DenyPartyRequestHandler());
  128.             registerHandler(RecvPacketOpcode.PARTYCHAT, new PartychatHandler());
  129.             registerHandler(RecvPacketOpcode.USE_DOOR, new DoorHandler());
  130.             registerHandler(RecvPacketOpcode.ENTER_MTS, new EnterMTSHandler());
  131.             registerHandler(RecvPacketOpcode.ENTER_CASH_SHOP, new EnterCashShopHandler());
  132.             registerHandler(RecvPacketOpcode.DAMAGE_SUMMON, new DamageSummonHandler());
  133.             registerHandler(RecvPacketOpcode.MOVE_SUMMON, new MoveSummonHandler());
  134.             registerHandler(RecvPacketOpcode.SUMMON_ATTACK, new SummonDamageHandler());
  135.             registerHandler(RecvPacketOpcode.BUDDYLIST_MODIFY, new BuddylistModifyHandler());
  136.             registerHandler(RecvPacketOpcode.USE_ITEMEFFECT, new UseItemEffectHandler());
  137.             registerHandler(RecvPacketOpcode.USE_CHAIR, new UseChairHandler());
  138.             registerHandler(RecvPacketOpcode.CANCEL_CHAIR, new CancelChairHandler());
  139.             registerHandler(RecvPacketOpcode.DAMAGE_REACTOR, new ReactorHitHandler());
  140.             registerHandler(RecvPacketOpcode.GUILD_OPERATION, new GuildOperationHandler());
  141.             registerHandler(RecvPacketOpcode.DENY_GUILD_REQUEST, new DenyGuildRequestHandler());
  142.             registerHandler(RecvPacketOpcode.BBS_OPERATION, new BBSOperationHandler());
  143.             registerHandler(RecvPacketOpcode.SKILL_EFFECT, new SkillEffectHandler());
  144.             registerHandler(RecvPacketOpcode.MESSENGER, new MessengerHandler());
  145.             registerHandler(RecvPacketOpcode.NPC_ACTION, new NPCAnimation());
  146.             registerHandler(RecvPacketOpcode.TOUCHING_CS, new TouchingCashShopHandler());
  147.             registerHandler(RecvPacketOpcode.BUY_CS_ITEM, new BuyCSItemHandler());
  148.             registerHandler(RecvPacketOpcode.COUPON_CODE, new CouponCodeHandler());
  149.             registerHandler(RecvPacketOpcode.SPAWN_PET, new SpawnPetHandler());
  150.             registerHandler(RecvPacketOpcode.MOVE_PET, new MovePetHandler());
  151.             registerHandler(RecvPacketOpcode.PET_CHAT, new PetChatHandler());
  152.             registerHandler(RecvPacketOpcode.PET_COMMAND, new PetCommandHandler());
  153.             registerHandler(RecvPacketOpcode.PET_FOOD, new PetFoodHandler());
  154.             registerHandler(RecvPacketOpcode.PET_LOOT, new PetLootHandler());
  155.             registerHandler(RecvPacketOpcode.AUTO_AGGRO, new AutoAggroHandler());
  156.             registerHandler(RecvPacketOpcode.MONSTER_BOMB, new MonsterBombHandler());
  157.             registerHandler(RecvPacketOpcode.CANCEL_DEBUFF, new CancelDebuffHandler());
  158.             registerHandler(RecvPacketOpcode.USE_SKILL_BOOK, new SkillBookHandler());
  159.             registerHandler(RecvPacketOpcode.SKILL_MACRO, new SkillMacroHandler());
  160.             registerHandler(RecvPacketOpcode.NOTE_ACTION, new NoteActionHandler());
  161.             registerHandler(RecvPacketOpcode.MAPLETV, new MapleTVHandler());
  162.             registerHandler(RecvPacketOpcode.PLAYER_UPDATE, new PlayerUpdateHandler());
  163.             registerHandler(RecvPacketOpcode.USE_CATCH_ITEM, new UseCatchItemHandler());
  164.             registerHandler(RecvPacketOpcode.CLOSE_CHALKBOARD, new CloseChalkboardHandler());
  165.             registerHandler(RecvPacketOpcode.MONSTER_CARNIVAL, new MonsterCarnivalHandler());
  166.             registerHandler(RecvPacketOpcode.USE_MOUNT_FOOD, new UseMountFoodHandler());
  167.             registerHandler(RecvPacketOpcode.VIP_ADD_MAP, new VIPAddMapHandler());
  168.             registerHandler(RecvPacketOpcode.RING_ACTION, new RingActionHandler());
  169.             registerHandler(RecvPacketOpcode.MOB_DAMAGE_MOB, new MobDamageMobHandler());
  170.             registerHandler(RecvPacketOpcode.REPORT_PLAYER, new ReportHandler());
  171.             registerHandler(RecvPacketOpcode.PARTY_SEARCH_REGISTER, new PartySearchHandler());
  172.             registerHandler(RecvPacketOpcode.DUEY_ACTION, new DueyHandler());
  173.             registerHandler(RecvPacketOpcode.PET_AUTO_POT, new PetAutoPotHandler());
  174.             registerHandler(RecvPacketOpcode.MTS_OP, new MTSHandler());
  175.             registerHandler(RecvPacketOpcode.ENERGY_ORB_ATTACK, new EnergyOrbDamageHandler());
  176.             registerHandler(RecvPacketOpcode.USE_SOLOMAN_ITEM, new useSolomonHandler());
  177.             registerHandler(RecvPacketOpcode.ALLIANCE_OPERATION, new AllianceOperationHandler());
  178.             registerHandler(RecvPacketOpcode.HIRED_MERCHANT_REQUEST, new HiredMerchantRequest());
  179.         } else {
  180.             throw new RuntimeException("Unknown packet processor mode");
  181.         }
  182.     }
  183. }