/// <summary> /// Attempts to handle an incoming packet. /// Constraints: OpCode must be valid. /// GamePackets cannot be sent if ActiveCharacter == null or Account == null. /// The packet is disposed after being handled. /// </summary> /// <param name="client">the client the packet is from</param> /// <param name="packet">the packet to be handled</param> /// <returns>true if the packet could be handled or false otherwise</returns> public override bool HandlePacket(IRealmClient client, RealmPacketIn packet) { var dispose = true; try { #if DEBUG DebugUtil.DumpPacket(client.Account, packet, PacketSender.Client); #endif if (packet.PacketId.RawId == (int)RealmServerOpCode.CMSG_PING) { // we want to instantly respond to pings, otherwise it throws off latency MiscHandler.PingRequest(client, packet); return(true); } var handlerDesc = m_handlers.Get(packet.PacketId.RawId); try { if (handlerDesc == null) { HandleUnhandledPacket(client, packet); return(true); } var context = CheckConstraints(client, handlerDesc, packet); if (context != null) { context.AddMessage(new PacketMessage(handlerDesc.Handler, client, packet)); dispose = false; return(true); } return(false); } catch (Exception e) { LogUtil.ErrorException(e, Resources.PacketHandleException, client, packet.PacketId); return(false); } } finally { if (dispose) { packet.Close(); } } }