Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.solace.network.packet;
- import org.solace.network.RSChannelContext;
- import org.solace.network.packet.impl.ActionButtonPacket;
- import org.solace.network.packet.impl.AppearanceChangePacket;
- import org.solace.network.packet.impl.ClickingIngamePacket;
- import org.solace.network.packet.impl.CommandPacket;
- import org.solace.network.packet.impl.DialoguePacket;
- import org.solace.network.packet.impl.DropItemPacket;
- import org.solace.network.packet.impl.EquipPacketHandler;
- import org.solace.network.packet.impl.IncomingChatPacket;
- import org.solace.network.packet.impl.ItemActionPacket;
- import org.solace.network.packet.impl.NPCInteractionPacket;
- import org.solace.network.packet.impl.ObjectInteractionPacket;
- import org.solace.network.packet.impl.PickupGroundItemPacket;
- import org.solace.network.packet.impl.PlayerInteractionPacket;
- import org.solace.network.packet.impl.PrivateMessagingPacket;
- import org.solace.network.packet.impl.RegionChangePacket;
- import org.solace.network.packet.impl.UseItemPacketHandler;
- import org.solace.network.packet.impl.WalkingUpdatePacket;
- import org.solace.network.packet.impl.xInterfacePacket2;
- /**
- * Packet handlers manager.
- *
- * @author Faris
- * @author Arithium
- */
- public class PacketType {
- public static final int SIZE = 256;
- private static PacketHandler[] packets = new PacketHandler[SIZE];
- /**
- * Handles an incoming packet.
- *
- * @param channelContext
- * the channel socket context
- *
- * @param packet
- * the packet
- */
- public static void handlePacket(RSChannelContext channelContext,
- Packet packet) {
- PacketHandler packetHandler = packets[packet.opcode()];
- if (packetHandler == null) {
- System.out.println("Unhandled Packet Type: " + packet.opcode());
- return;
- }
- if (packet.opcode() < 0 || packet.opcode() > 256)
- return;
- try {
- packetHandler.handlePacket(channelContext.player(), packet);
- System.out.println(packet.opcode());
- } catch (Exception e) {
- e.printStackTrace();
- channelContext.player().setLogoutRequired(true);
- }
- }
- /**
- * Static constructor for packet handlers initializing.
- */
- static {
- ObjectInteractionPacket objectInteraction = new ObjectInteractionPacket();
- PickupGroundItemPacket pickup = new PickupGroundItemPacket();
- DialoguePacket dialogue = new DialoguePacket();
- PrivateMessagingPacket privateMessage = new PrivateMessagingPacket();
- EquipPacketHandler equip = new EquipPacketHandler();
- DropItemPacket drop = new DropItemPacket();
- ItemActionPacket itemAction = new ItemActionPacket();
- NPCInteractionPacket npcInteraction = new NPCInteractionPacket();
- xInterfacePacket2 xInterface = new xInterfacePacket2();
- ClickingIngamePacket clickingInGame = new ClickingIngamePacket();
- PlayerInteractionPacket playerInteraction = new PlayerInteractionPacket();
- ActionButtonPacket actionButton = new ActionButtonPacket();
- CommandPacket command = new CommandPacket();
- AppearanceChangePacket appearance = new AppearanceChangePacket();
- IncomingChatPacket chat = new IncomingChatPacket();
- RegionChangePacket region = new RegionChangePacket();
- WalkingUpdatePacket walking = new WalkingUpdatePacket();
- UseItemPacketHandler useItem = new UseItemPacketHandler();
- packets[ObjectInteractionPacket.FIRST_CLICK_OBJECT_OPCODE] = objectInteraction;
- packets[ObjectInteractionPacket.SECOND_CLICK_OBJECT_OPCODE] = objectInteraction;
- packets[ObjectInteractionPacket.THIRD_CLICK_OBJECT_OPCODE] = objectInteraction;
- packets[132] = objectInteraction;
- packets[252] = objectInteraction;
- packets[70] = objectInteraction;
- packets[236] = pickup;
- packets[DialoguePacket.DIALOGUE_OPCODE] = dialogue;
- packets[PrivateMessagingPacket.ADD_FRIEND_OPCODE] = privateMessage;
- packets[PrivateMessagingPacket.ADD_IGNORE_OPCODE] = privateMessage;
- packets[PrivateMessagingPacket.REMOVE_FRIEND_OPCODE] = privateMessage;
- packets[PrivateMessagingPacket.REMOVE_IGNORE_OPCODE] = privateMessage;
- packets[PrivateMessagingPacket.SEND_PM_OPCODE] = privateMessage;
- packets[41] = equip;
- packets[DropItemPacket.DROP_ITEM_OPCODE] = drop;
- packets[ItemActionPacket.FIRST_ITEM_ACTION_OPCODE] = itemAction;
- packets[ItemActionPacket.SECOND_ITEM_ACTION_OPCODE] = itemAction;
- packets[ItemActionPacket.THIRD_ITEM_ACTION_OPCODE] = itemAction;
- packets[ItemActionPacket.FOURTH_ITEM_ACTION_OPCODE] = itemAction;
- packets[NPCInteractionPacket.FIRST_CLICK] = npcInteraction;
- packets[NPCInteractionPacket.SECOND_CLICK] = npcInteraction;
- packets[NPCInteractionPacket.THIRD_CLICK] = npcInteraction;
- packets[NPCInteractionPacket.FOURTH_CLICK] = npcInteraction;
- packets[NPCInteractionPacket.ATTACK] = npcInteraction;
- packets[NPCInteractionPacket.MAGIC_ON_NPC] = npcInteraction;
- packets[208] = xInterface;
- packets[241] = clickingInGame;
- packets[PlayerInteractionPacket.ATTACK] = playerInteraction;
- packets[PlayerInteractionPacket.FOLLOW] = playerInteraction;
- packets[PlayerInteractionPacket.MAGIC_ON_PLAYER] = playerInteraction;
- packets[185] = actionButton;
- packets[103] = command;
- packets[101] = appearance;
- packets[4] = chat;
- packets[121] = region;
- packets[WalkingUpdatePacket.COMMAND_MOVEMENT_OPCODE] = walking;
- packets[WalkingUpdatePacket.GAME_MOVEMENT_OPCODE] = walking;
- packets[WalkingUpdatePacket.MINIMAP_MOVEMENT_OPCODE] = walking;
- packets[UseItemPacketHandler.USE_ITEM] = useItem;
- packets[UseItemPacketHandler.ITEM_ON_OBJECT] = useItem;
- //packets[UseItemPacketHandler.ITEM_ON_NPC] = useItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment