Guest User

Untitled

a guest
Nov 11th, 2012
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. package org.solace.network.packet;
  2.  
  3. import org.solace.network.RSChannelContext;
  4. import org.solace.network.packet.impl.ActionButtonPacket;
  5. import org.solace.network.packet.impl.AppearanceChangePacket;
  6. import org.solace.network.packet.impl.ClickingIngamePacket;
  7. import org.solace.network.packet.impl.CommandPacket;
  8. import org.solace.network.packet.impl.DialoguePacket;
  9. import org.solace.network.packet.impl.DropItemPacket;
  10. import org.solace.network.packet.impl.EquipPacketHandler;
  11. import org.solace.network.packet.impl.IncomingChatPacket;
  12. import org.solace.network.packet.impl.ItemActionPacket;
  13. import org.solace.network.packet.impl.NPCInteractionPacket;
  14. import org.solace.network.packet.impl.ObjectInteractionPacket;
  15. import org.solace.network.packet.impl.PickupGroundItemPacket;
  16. import org.solace.network.packet.impl.PlayerInteractionPacket;
  17. import org.solace.network.packet.impl.PrivateMessagingPacket;
  18. import org.solace.network.packet.impl.RegionChangePacket;
  19. import org.solace.network.packet.impl.UseItemPacketHandler;
  20. import org.solace.network.packet.impl.WalkingUpdatePacket;
  21. import org.solace.network.packet.impl.xInterfacePacket2;
  22.  
  23. /**
  24. * Packet handlers manager.
  25. *
  26. * @author Faris
  27. * @author Arithium
  28. */
  29. public class PacketType {
  30.  
  31. public static final int SIZE = 256;
  32.  
  33. private static PacketHandler[] packets = new PacketHandler[SIZE];
  34.  
  35. /**
  36. * Handles an incoming packet.
  37. *
  38. * @param channelContext
  39. * the channel socket context
  40. *
  41. * @param packet
  42. * the packet
  43. */
  44. public static void handlePacket(RSChannelContext channelContext,
  45. Packet packet) {
  46. PacketHandler packetHandler = packets[packet.opcode()];
  47. if (packetHandler == null) {
  48. System.out.println("Unhandled Packet Type: " + packet.opcode());
  49. return;
  50. }
  51. if (packet.opcode() < 0 || packet.opcode() > 256)
  52. return;
  53. try {
  54. packetHandler.handlePacket(channelContext.player(), packet);
  55. System.out.println(packet.opcode());
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. channelContext.player().setLogoutRequired(true);
  59. }
  60. }
  61.  
  62. /**
  63. * Static constructor for packet handlers initializing.
  64. */
  65. static {
  66. ObjectInteractionPacket objectInteraction = new ObjectInteractionPacket();
  67. PickupGroundItemPacket pickup = new PickupGroundItemPacket();
  68. DialoguePacket dialogue = new DialoguePacket();
  69. PrivateMessagingPacket privateMessage = new PrivateMessagingPacket();
  70. EquipPacketHandler equip = new EquipPacketHandler();
  71. DropItemPacket drop = new DropItemPacket();
  72. ItemActionPacket itemAction = new ItemActionPacket();
  73. NPCInteractionPacket npcInteraction = new NPCInteractionPacket();
  74. xInterfacePacket2 xInterface = new xInterfacePacket2();
  75. ClickingIngamePacket clickingInGame = new ClickingIngamePacket();
  76. PlayerInteractionPacket playerInteraction = new PlayerInteractionPacket();
  77. ActionButtonPacket actionButton = new ActionButtonPacket();
  78. CommandPacket command = new CommandPacket();
  79. AppearanceChangePacket appearance = new AppearanceChangePacket();
  80. IncomingChatPacket chat = new IncomingChatPacket();
  81. RegionChangePacket region = new RegionChangePacket();
  82. WalkingUpdatePacket walking = new WalkingUpdatePacket();
  83. UseItemPacketHandler useItem = new UseItemPacketHandler();
  84.  
  85. packets[ObjectInteractionPacket.FIRST_CLICK_OBJECT_OPCODE] = objectInteraction;
  86. packets[ObjectInteractionPacket.SECOND_CLICK_OBJECT_OPCODE] = objectInteraction;
  87. packets[ObjectInteractionPacket.THIRD_CLICK_OBJECT_OPCODE] = objectInteraction;
  88. packets[132] = objectInteraction;
  89. packets[252] = objectInteraction;
  90. packets[70] = objectInteraction;
  91. packets[236] = pickup;
  92. packets[DialoguePacket.DIALOGUE_OPCODE] = dialogue;
  93. packets[PrivateMessagingPacket.ADD_FRIEND_OPCODE] = privateMessage;
  94. packets[PrivateMessagingPacket.ADD_IGNORE_OPCODE] = privateMessage;
  95. packets[PrivateMessagingPacket.REMOVE_FRIEND_OPCODE] = privateMessage;
  96. packets[PrivateMessagingPacket.REMOVE_IGNORE_OPCODE] = privateMessage;
  97. packets[PrivateMessagingPacket.SEND_PM_OPCODE] = privateMessage;
  98. packets[41] = equip;
  99. packets[DropItemPacket.DROP_ITEM_OPCODE] = drop;
  100. packets[ItemActionPacket.FIRST_ITEM_ACTION_OPCODE] = itemAction;
  101. packets[ItemActionPacket.SECOND_ITEM_ACTION_OPCODE] = itemAction;
  102. packets[ItemActionPacket.THIRD_ITEM_ACTION_OPCODE] = itemAction;
  103. packets[ItemActionPacket.FOURTH_ITEM_ACTION_OPCODE] = itemAction;
  104. packets[NPCInteractionPacket.FIRST_CLICK] = npcInteraction;
  105. packets[NPCInteractionPacket.SECOND_CLICK] = npcInteraction;
  106. packets[NPCInteractionPacket.THIRD_CLICK] = npcInteraction;
  107. packets[NPCInteractionPacket.FOURTH_CLICK] = npcInteraction;
  108. packets[NPCInteractionPacket.ATTACK] = npcInteraction;
  109. packets[NPCInteractionPacket.MAGIC_ON_NPC] = npcInteraction;
  110. packets[208] = xInterface;
  111. packets[241] = clickingInGame;
  112. packets[PlayerInteractionPacket.ATTACK] = playerInteraction;
  113. packets[PlayerInteractionPacket.FOLLOW] = playerInteraction;
  114. packets[PlayerInteractionPacket.MAGIC_ON_PLAYER] = playerInteraction;
  115. packets[185] = actionButton;
  116. packets[103] = command;
  117. packets[101] = appearance;
  118. packets[4] = chat;
  119. packets[121] = region;
  120. packets[WalkingUpdatePacket.COMMAND_MOVEMENT_OPCODE] = walking;
  121. packets[WalkingUpdatePacket.GAME_MOVEMENT_OPCODE] = walking;
  122. packets[WalkingUpdatePacket.MINIMAP_MOVEMENT_OPCODE] = walking;
  123. packets[UseItemPacketHandler.USE_ITEM] = useItem;
  124. packets[UseItemPacketHandler.ITEM_ON_OBJECT] = useItem;
  125. //packets[UseItemPacketHandler.ITEM_ON_NPC] = useItem;
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment