示例#1
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);
        }
示例#2
0
        private static CallbackResult OnClientTarget(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                switch (CurrentState)
                {
                case State.ServerTarget:
                    clientTarget = null;
                    FinishWork();
                    return(CallbackResult.Normal);

                case State.Target:
                    TargetData target = TargetData.FromData(data);

                    if (target.TargetId == clientTarget.TargetId && target.Type <= clientTarget.Type)
                    {
                        clientTarget.Serial  = target.Serial;
                        clientTarget.X       = target.X;
                        clientTarget.Y       = target.Y;
                        clientTarget.Z       = target.Z;
                        clientTarget.Graphic = target.Graphic;
                    }
                    else
                    {
                        Trace.WriteLine("Incorrect target received from client.", "UIManager");
                    }

                    operationResult.Event.Set();
                    operationResult = null;
                    clientTarget    = null;
                    FinishWork();
                    return(CallbackResult.Eat);

                default:
                    Trace.WriteLine("Dropped unexpected client target.", "UIManager");
                    return(CallbackResult.Eat);
                }
            }
        }
示例#3
0
        private static IMacroCommand OnTarget(byte[] data)
        {
            TargetData ti = TargetData.FromData(data);

            return(new WaitTargetCommand(ti));
        }