Exemple #1
0
 public object Clone()
 {
     TargetData td = new TargetData();
     td.Type = Type;
     td.TargetId = TargetId;
     td.Flags = Flags;
     td.Serial = Serial;
     td.X = X;
     td.Y = Y;
     td.Z = Z;
     td.Graphic = Graphic;
     return td;
 }
Exemple #2
0
        public object Clone()
        {
            TargetData td = new TargetData();

            td.Type     = Type;
            td.TargetId = TargetId;
            td.Flags    = Flags;
            td.Serial   = Serial;
            td.X        = X;
            td.Y        = Y;
            td.Z        = Z;
            td.Graphic  = Graphic;
            return(td);
        }
Exemple #3
0
        internal static TargetData FromData(byte[] data)
        {
            if (data[0] != 0x6C) throw new ArgumentException("Invalid packet.");

            TargetData targetData = new TargetData();
            targetData.Type = data[1];
            targetData.TargetId = ByteConverter.BigEndian.ToUInt32(data, 2);
            targetData.Flags = data[6];
            targetData.Serial = ByteConverter.BigEndian.ToUInt32(data, 7);
            targetData.X = ByteConverter.BigEndian.ToUInt16(data, 11);
            targetData.Y = ByteConverter.BigEndian.ToUInt16(data, 13);
            targetData.Z = ByteConverter.BigEndian.ToSByte(data, 16);
            targetData.Graphic = ByteConverter.BigEndian.ToUInt16(data, 17);

            return targetData;
        }
Exemple #4
0
        internal static TargetData FromData(byte[] data)
        {
            if (data[0] != 0x6C)
            {
                throw new ArgumentException("Invalid packet.");
            }

            TargetData targetData = new TargetData();

            targetData.Type     = data[1];
            targetData.TargetId = ByteConverter.BigEndian.ToUInt32(data, 2);
            targetData.Flags    = data[6];
            targetData.Serial   = ByteConverter.BigEndian.ToUInt32(data, 7);
            targetData.X        = ByteConverter.BigEndian.ToUInt16(data, 11);
            targetData.Y        = ByteConverter.BigEndian.ToUInt16(data, 13);
            targetData.Z        = ByteConverter.BigEndian.ToSByte(data, 16);
            targetData.Graphic  = ByteConverter.BigEndian.ToUInt16(data, 17);

            return(targetData);
        }
Exemple #5
0
        private static CallbackResult OnServerTargetMulti(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                TargetData td = new TargetData();
                td.Type = data[1];
                td.TargetId = ByteConverter.BigEndian.ToUInt32(data, 2);
                ushort multi = ByteConverter.BigEndian.ToUInt16(data, 18);

                Trace.WriteLine("Server target \"Place Multi 0x" + multi.ToString("X4") + "\" received.", "UIManager");

                // Simulate standart target packet so i don't have to handle it specially :)
                return OnServerTarget(td.ToData(), prevResult);
            }
        }
Exemple #6
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;
        }
Exemple #7
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;
                }
            }
        }
Exemple #8
0
        internal static void ResetInternal(bool timeout)
        {
            lock (syncRoot) {
                switch (CurrentState) {
                    case State.Ready:
                        return;

                    case State.ClientPickedUpItem:
                    case State.ClientHoldingItem:
                        Core.SendToClient(PacketBuilder.PickupItemFailed(6));
                        Core.SendToServer(PacketBuilder.ItemDropRequest(PickedUpItem, 0xFFFF, 0xFFFF, 0, 0));

                        pickedUpItemName = null;
                        PickedUpItem = 0;
                        break;

                    case State.ClientDroppedItem:
                        pickedUpItemName = null;
                        PickedUpItem = 0;
                        break;

                    case State.ServerTarget:
                        Debug.Assert(clientTarget != null, "clientTarget != null");
                        clientTarget.X = 0xFFFF;
                        clientTarget.Y = 0xFFFF;
                        clientTarget.Z = 0;
                        clientTarget.Serial = 0;
                        clientTarget.Graphic = 0;
                        Core.SendToServer(clientTarget.ToData());
                        clientTarget.Flags = 0x03;
                        Core.SendToClient(clientTarget.ToData());
                        clientTarget = null;
                        break;

                    case State.MoveItem:
                        Debug.Assert(operationResult != null, "operationResult != null", CurrentState.ToString());
                        operationResult.Success = false;
                        operationResult.Event.Set();
                        operationResult = null;
                        PickedUpItem = 0;
                        break;

                    case State.Target:
                        Debug.Assert(operationResult != null, "operationResult != null", CurrentState.ToString());
                        operationResult.Event.Set();
                        operationResult = null;
                        clientTarget = null;
                        break;

                    case State.WaitTarget:
                        DeleteWaitQueue(timeout);
                        break;

                    case State.WaitMenu:
                        DeleteWaitQueue(timeout);
                        break;

                    default:
                        Trace.WriteLine("Unhandled state in UIManager.Cancel()!!! Please report this error.", "UIManager");
                        return;
                }

                if (timeout)
                    timeoutThread = null;
                else
                    StopTimeout();

                Debug.Assert(PickedUpItem == 0, "PickedUpItem == 0");
                Debug.Assert(pickedUpItemName == null, "pickedUpItemName == null");
                Debug.Assert(clientTarget == null, "clientTarget == null");
                Debug.Assert(operationResult == null, "operationResult == null");

                CurrentState = State.Ready;
                readySignal.Set();
            }
        }
Exemple #9
0
        public static Serial TargetObject()
        {
            if (!Core.LoggedIn)
                return Serial.Invalid;

            TargetData info = new TargetData();
            info.TargetId = (uint)new Random().Next();

            OperationResult result = new OperationResult();

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

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

                clientTarget = info;
                operationResult = result;
                CurrentState = State.Target;
                BeginTimeout(PhoenixTargetTimeout);

                Core.SendToClient(info.ToData());
            }

            result.Event.WaitOne();

            if (info.Serial == 0)
                info.Serial = Serial.Invalid;

            Debug.WriteLine("Client returned object target. Serial=0x" + info.Serial.ToString("X8"), "UIManager");
            return info.Serial;
        }
Exemple #10
0
        public static StaticTarget Target()
        {
            if (!Core.LoggedIn)
                return null;

            TargetData info = new TargetData();
            info.Type = 1;
            info.TargetId = (uint)new Random().Next();
            info.X = 0xFFFF;
            info.Y = 0xFFFF;

            OperationResult result = new OperationResult();

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

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

                Core.SendToClient(info.ToData());

                clientTarget = info;
                operationResult = result;
                CurrentState = State.Target;
                BeginTimeout(PhoenixTargetTimeout);
            }

            result.Event.WaitOne();

            Debug.WriteLine(String.Format("Client returned target: Serial=0x{0:X8} X={1} Y={2} Z={3} Graphic=0x{4:X4}",
                                          info.Serial, info.X, info.Y, info.Z, info.Graphic), "UIManager");

            return new StaticTarget(info.Serial, info.X, info.Y, info.Z, info.Graphic);
        }