Ejemplo n.º 1
0
 internal void OnCast(PacketReader p)
 {
     Cast();
     Assistant.Client.Instance.SendToServer(p);
 }
Ejemplo n.º 2
0
 public abstract void SendToServer(PacketReader pr);
Ejemplo n.º 3
0
 public override void SendToServer(PacketReader pr)
 {
     SendToServer(MakePacketFrom(pr));
 }
Ejemplo n.º 4
0
 public void OnCast(PacketReader p)
 {
     Cast();
     Client.Instance.SendToServer(p);
 }
Ejemplo n.º 5
0
 public void ReadPropertyList(PacketReader p)
 {
     m_ObjPropList.Read(p);
 }
Ejemplo n.º 6
0
 public Packet MakePacketFrom(PacketReader pr)
 {
     byte[] data = pr.CopyBytes(0, pr.Length);
     return(new Packet(data, pr.Length, pr.DynamicLength));
 }
Ejemplo n.º 7
0
        private static void NewTarget(PacketReader p, PacketHandlerEventArgs args)
        {
            bool prevAllowGround  = m_AllowGround;
            uint prevID           = m_CurrentID;
            byte prevFlags        = m_CurFlags;
            bool prevClientTarget = m_ClientTarget;

            m_AllowGround = p.ReadBoolean(); // allow ground
            m_CurrentID   = p.ReadUInt32();  // target uid
            m_CurFlags    = p.ReadByte();    // flags
            // the rest of the packet is 0s

            // check for a server cancel command
            if (!m_AllowGround && m_CurrentID == 0 && m_CurFlags == 3)
            {
                m_HasTarget      = false;
                m_FromGrabHotKey = false;

                m_ClientTarget = false;
                if (m_Intercept)
                {
                    EndIntercept();
                    World.Player.SendMessage(MsgLevel.Error, LocString.OTTCancel);
                }

                return;
            }

            if (Spell.LastCastTime + TimeSpan.FromSeconds(3.0) > DateTime.UtcNow &&
                Spell.LastCastTime + TimeSpan.FromSeconds(0.5) <= DateTime.UtcNow && m_SpellTargID == 0)
            {
                m_SpellTargID = m_CurrentID;
            }

            m_HasTarget    = true;
            m_ClientTarget = false;

            if (m_QueueTarget == null && Macros.MacroManager.AcceptActions &&
                MacroManager.Action(new WaitForTargetAction()))
            {
                args.Block = true;
            }
            else if (m_QueueTarget == null && ScriptManager.AddToScript("waitfortarget"))
            {
                //args.Block = true;
            }
            else if (m_QueueTarget != null && m_QueueTarget())
            {
                ClearQueue();
                args.Block = true;
            }

            if (args.Block)
            {
                if (prevClientTarget)
                {
                    m_AllowGround = prevAllowGround;
                    m_CurrentID   = prevID;
                    m_CurFlags    = prevFlags;

                    m_ClientTarget = true;

                    if (!m_Intercept)
                    {
                        CancelClientTarget();
                    }
                }
            }
            else
            {
                m_ClientTarget = true;

                if (m_Intercept)
                {
                    if (m_OnCancel != null)
                    {
                        m_OnCancel();
                    }
                    EndIntercept();
                    World.Player.SendMessage(MsgLevel.Error, LocString.OTTCancel);

                    m_FilterCancel.Add((uint)prevID);
                }
            }
        }
Ejemplo n.º 8
0
        private static void TargetResponse(PacketReader p, PacketHandlerEventArgs args)
        {
            if (World.Player == null)
            {
                return;
            }

            TargetInfo info = new TargetInfo
            {
                Type   = p.ReadByte(),
                TargID = p.ReadUInt32(),
                Flags  = p.ReadByte(),
                Serial = p.ReadUInt32(),
                X      = p.ReadUInt16(),
                Y      = p.ReadUInt16(),
                Z      = p.ReadInt16(),
                Gfx    = p.ReadUInt16()
            };

            m_ClientTarget = false;

            OverheadTargetMessage(info);

            // check for cancel
            if (info.X == 0xFFFF && info.X == 0xFFFF && (info.Serial <= 0 || info.Serial >= 0x80000000))
            {
                m_HasTarget      = false;
                m_FromGrabHotKey = false;

                if (m_Intercept)
                {
                    args.Block = true;
                    Timer.DelayedCallbackState(TimeSpan.Zero, m_OneTimeRespCallback, info).Start();
                    EndIntercept();

                    if (m_PreviousID != 0)
                    {
                        m_CurrentID   = m_PreviousID;
                        m_AllowGround = m_PreviousGround;
                        m_CurFlags    = m_PrevFlags;

                        m_PreviousID = 0;

                        ResendTarget();
                    }
                }
                else if (m_FilterCancel.Contains((uint)info.TargID) || info.TargID == LocalTargID)
                {
                    args.Block = true;
                }

                m_FilterCancel.Clear();
                return;
            }

            ClearQueue();

            if (m_Intercept)
            {
                if (info.TargID == LocalTargID)
                {
                    Timer.DelayedCallbackState(TimeSpan.Zero, m_OneTimeRespCallback, info).Start();

                    m_HasTarget      = false;
                    m_FromGrabHotKey = false;
                    args.Block       = true;

                    if (m_PreviousID != 0)
                    {
                        m_CurrentID   = m_PreviousID;
                        m_AllowGround = m_PreviousGround;
                        m_CurFlags    = m_PrevFlags;

                        m_PreviousID = 0;

                        ResendTarget();
                    }

                    m_FilterCancel.Clear();

                    return;
                }
                else
                {
                    EndIntercept();
                }
            }

            m_HasTarget = false;

            if (CheckHealPoisonTarg(m_CurrentID, info.Serial))
            {
                ResendTarget();
                args.Block = true;
            }

            if (info.Serial != World.Player.Serial)
            {
                if (info.Serial.IsValid)
                {
                    // only let lasttarget be a non-ground target

                    m_LastTarget = info;
                    if (info.Flags == 1)
                    {
                        m_LastHarmTarg = info;
                    }
                    else if (info.Flags == 2)
                    {
                        m_LastBeneTarg = info;
                    }

                    LastTargetChanged();
                    LastBeneficialTargetChanged();
                    LastHarmfulTargetChanged();
                }

                m_LastGroundTarg = info; // ground target is the true last target

                if (Macros.MacroManager.AcceptActions)
                {
                    MacroManager.Action(new AbsoluteTargetAction(info));
                }

                ScriptManager.AddToScript(info.Serial == Serial.Zero
                    ? $"target 0x0 {info.X} {info.Y} {info.Z}"
                    : $"target {info.Serial}");


                if (ScriptManager.Recording)
                {
                    if (info.Serial == Serial.Zero)
                    {
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                if (Macros.MacroManager.AcceptActions)
                {
                    KeyData hk = HotKey.Get((int)LocString.TargetSelf);
                    if (hk != null)
                    {
                        MacroManager.Action(new HotKeyAction(hk));

                        ScriptManager.AddToScript($"hotkey '{hk.DispName}'");
                    }
                    else
                    {
                        MacroManager.Action(new AbsoluteTargetAction(info));

                        ScriptManager.AddToScript($"target {info.Serial}");
                    }
                }
            }

            if (World.Player.LastSpell == 52 && !GateTimer.Running)
            {
                GateTimer.Start();
            }

            m_FilterCancel.Clear();
        }
Ejemplo n.º 9
0
        private void HandleComm(Buffer *inBuff, Buffer *outBuff, Queue <Packet> queue, PacketPath path)
        {
            CommMutex.WaitOne();
            while (inBuff->Length > 0)
            {
                byte *buff = (&inBuff->Buff0) + inBuff->Start;

                short len = PacketsTable.GetPacketLength(buff, inBuff->Length);
                if (len > inBuff->Length || len <= 0)
                {
                    break;
                }

                inBuff->Start  += len;
                inBuff->Length -= len;

                bool viewer = false;
                bool filter = false;

                switch (path)
                {
                case PacketPath.ClientToServer:
                    viewer = PacketHandler.HasClientViewer(buff[0]);
                    filter = PacketHandler.HasClientFilter(buff[0]);
                    break;

                case PacketPath.ServerToClient:
                    viewer = PacketHandler.HasServerViewer(buff[0]);
                    filter = PacketHandler.HasServerFilter(buff[0]);
                    break;
                }

                Packet       p  = null;
                PacketReader pr = null;
                if (viewer)
                {
                    pr = new PacketReader(buff, len, PacketsTable.IsDynLength(buff[0]));
                    if (filter)
                    {
                        p = MakePacketFrom(pr);
                    }
                }
                else if (filter)
                {
                    byte[] temp = new byte[len];

                    fixed(byte *ptr = temp)
                    Platform.memcpy(ptr, buff, len);

                    p = new Packet(temp, len, PacketsTable.IsDynLength(buff[0]));
                }

                bool blocked = false;
                switch (path)
                {
                // yes it should be this way
                case PacketPath.ClientToServer:
                {
                    blocked = PacketHandler.OnClientPacket(buff[0], pr, p);
                    break;
                }

                case PacketPath.ServerToClient:
                {
                    blocked = PacketHandler.OnServerPacket(buff[0], pr, p);
                    break;
                }
                }

                if (filter)
                {
                    byte[] data = p.Compile();
                    fixed(byte *ptr = data)
                    {
                        Packet.Log(path, ptr, data.Length, blocked);
                        if (!blocked)
                        {
                            CopyToBuffer(outBuff, ptr, data.Length);
                        }
                    }
                }
                else
                {
                    Packet.Log(path, buff, len, blocked);
                    if (!blocked)
                    {
                        CopyToBuffer(outBuff, buff, len);
                    }
                }

                while (queue.Count > 0)
                {
                    p = (Packet)queue.Dequeue();
                    byte[] data = p.Compile();
                    fixed(byte *ptr = data)
                    {
                        CopyToBuffer(outBuff, ptr, data.Length);
                        Packet.Log((PacketPath)(((int)path) + 1), ptr, data.Length);
                    }
                }
            }
            CommMutex.ReleaseMutex();
        }