Пример #1
0
        public static void Info()
        {
            IClientTarget target = UIManager.Target();

            if (target.Serial != 0)
            {
                Info(target.Serial);
            }
            else
            {
                string name = null;
                if (target.Graphic != 0 && target.Graphic < DataFiles.Tiledata.Count)
                {
                    name = DataFiles.Tiledata.GetArt(target.Graphic).Name;
                }

                string format = "Tile X={0} Y={1} Z={2} Graphic=0x{3:X4}";
                if (name != null && name.Length > 0)
                {
                    format += " Name={4}";
                }

                Notepad.WriteLine(format, target.X, target.Y, target.Z, target.Graphic, name);
                Notepad.WriteLine();
            }
        }
Пример #2
0
        public static IRequestResult WaitForTarget(IClientTarget target)
        {
            if (!Core.LoggedIn)
            {
                return(UIManager.FailedResult);
            }

            IClientTarget info = (IClientTarget)target.Clone();

            lock (syncRoot) {
                if ((CurrentState != State.WaitMenu && CurrentState != State.WaitTarget) ||
                    waitQueue == null || waitQueue.Count == 0 ||
                    waitQueue.Peek().ThreadId != Thread.CurrentThread.ManagedThreadId)
                {
                    Reset();

                    waitQueue    = new Queue <WaitQuery>();
                    CurrentState = State.WaitTarget;
                }

                Debug.Assert(waitQueue != null, "waitQueue == null");

                WaitQuery query = new WaitQuery(info);
                waitQueue.Enqueue(query);

                Debug.WriteLine("Target enqueued.", "UIManager");

                BeginTimeout(WaitTargetTimeout);

                query.State = RequestState.Pending;
                return(query);
            }
        }
Пример #3
0
        private static CallbackResult OnServerTarget(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                if (CurrentState == State.WaitTarget)
                {
                    Debug.Assert(waitQueue != null && waitQueue.Count > 0, "Empty waitQueue.");
                    Debug.Assert(!waitQueue.Peek().IsMenu, "Menu is in the top of the queue instead of Target.");

                    TargetData    target     = TargetData.FromData(data);
                    WaitQuery     query      = waitQueue.Dequeue();
                    IClientTarget waitTarget = query.Target;

                    if ((byte)waitTarget.Type > target.Type)
                    {
                        Trace.WriteLine("Unexpected Server target type received. Target passed to client.", "UIManager");
                        query.Finish(RequestState.Failed);
                    }
                    else
                    {
                        Core.SendToServer(TargetData.ToData(waitTarget, target.TargetId));

                        FinishWork();
                        Trace.WriteLine("Processed expected Server target.", "UIManager");

                        query.Finish(RequestState.Completed);
                        return(CallbackResult.Eat);
                    }
                }

                if (CurrentState == State.ServerTarget)
                {
                    TargetData target = TargetData.FromData(data);

                    if (target.Flags == 0x03)
                    {
                        Trace.WriteLine("Cancel-target packet passed to client.", "UIManager");
                        return(CallbackResult.Normal);
                    }
                    else
                    {
                        Trace.WriteLine("Warning: Server target updated without previous cancellation.", "UIManager");
                        clientTarget = target;
                        return(CallbackResult.Normal);
                    }
                }

                if (CurrentState != State.Ready)
                {
                    Reset();
                }

                Debug.Assert(CurrentState == State.Ready, "CurrentState is not Ready. Internal error.");

                clientTarget = TargetData.FromData(data);
                CurrentState = State.ServerTarget;
            }
            return(CallbackResult.Normal);
        }
Пример #4
0
 public WaitQuery(IClientTarget target)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target   = target;
     Menu     = new MenuSelection();
 }
Пример #5
0
 internal static byte[] ToData(IClientTarget target, uint targetId)
 {
     return(PacketBuilder.Target((byte)target.Type, targetId, target.Flags, target.Serial, target.X, target.Y, target.Z, target.Graphic));
 }
Пример #6
0
 public WaitQuery(MenuSelection menu)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target = null;
     Menu = menu;
 }
Пример #7
0
 public WaitQuery(IClientTarget target)
 {
     ThreadId = Thread.CurrentThread.ManagedThreadId;
     Target = target;
     Menu = new MenuSelection();
 }
Пример #8
0
        public static IRequestResult WaitForTarget(IClientTarget target)
        {
            if (!Core.LoggedIn)
                return UIManager.FailedResult;

            IClientTarget info = (IClientTarget)target.Clone();

            lock (syncRoot) {
                if ((CurrentState != State.WaitMenu && CurrentState != State.WaitTarget) ||
                    waitQueue == null || waitQueue.Count == 0 ||
                    waitQueue.Peek().ThreadId != Thread.CurrentThread.ManagedThreadId) {
                    Reset();

                    waitQueue = new Queue<WaitQuery>();
                    CurrentState = State.WaitTarget;
                }

                Debug.Assert(waitQueue != null, "waitQueue == null");

                WaitQuery query = new WaitQuery(info);
                waitQueue.Enqueue(query);

                Debug.WriteLine("Target enqueued.", "UIManager");

                BeginTimeout(WaitTargetTimeout);

                query.State = RequestState.Pending;
                return query;
            }
        }
Пример #9
0
 internal static byte[] ToData(IClientTarget target, uint targetId)
 {
     return PacketBuilder.Target((byte)target.Type, targetId, target.Flags, target.Serial, target.X, target.Y, target.Z, target.Graphic);
 }