示例#1
0
        public Task<CommandResult> SendAsync(ICommand command, CommandReplyType commandReplyType)
        {
            var task = commandResultManager.RegisterCommand(command, commandReplyType);

            this.Send(command);

            return task;
        }
示例#2
0
        /// <summary>
        /// 注册一个命令
        /// </summary>
        public Task<CommandResult> RegisterCommand(ICommand command, CommandReplyType commandReplyType, Action<ICommand> commandAction)
        {
            var commandTaskCompletionSource = _commandTaskDict.GetOrAdd(command.Id, key => new CommandTaskCompletionSource(commandReplyType));

            commandAction(command);

            return commandTaskCompletionSource.TaskCompletionSource.Task;
        }
示例#3
0
        /// <summary>
        /// Construct a new TorReply instance based on the sourceReply instance. Should be used on extended TorReply classes.
        /// </summary>
        /// <param name="sourceReply">Source reply. Cannot be null.</param>
        /// <param name="extraReplies">(Optional) List of extra replies (if it is a set). Could include the sourceReply (filter it out manually)</param>
        /// <remarks>Create a class extending on TorReply that acceps a specific TorReply type and parse it.</remarks>
        public TorReply( params TorReply[] replies)
        {
            if (replies == null || replies.FirstOrDefault() == null)
            {
                return;
            }

            TorReply sourceReply = replies.First();

            Code = sourceReply.Code;
            Arguments = sourceReply.Arguments;
            Type = sourceReply.Type;
            Raw = sourceReply.Raw;
        }
示例#4
0
 public CommandTaskCompletionSource(CommandReplyType commandReplyType)
 {
     this.CommandReplyType = commandReplyType;
     this.TaskCompletionSource = new TaskCompletionSource<CommandResult>();
 }
示例#5
0
        /// <summary>
        /// Construct a new TorReply instance.
        /// </summary>
        /// <param name="input">Input string.</param>
        /// <param name="isMultiReply">Is part of a multi-reply or not.</param>
        internal TorReply(string input, bool isMultiReply)
        {
            // Store the raw input
            Raw = input;

            if (isMultiReply && input == ".")
            {
                Type = CommandReplyType.EndOfMultiline;
                return;
            }

            if (isMultiReply)
            {
                Type = CommandReplyType.LineValue;
                return;
            }

            string code = string.Empty;

            // Go over the input
            foreach (var chr in input)
            {
                if ((chr != ' ') && (chr != '+') && (chr != '-'))
                {
                    code += chr;
                    continue;
                }

                if (chr == '+' && code == "250")
                {
                    Type = CommandReplyType.MultiLineValue;
                    Code = 250;
                }
                else if (chr == '-' && code == "250")
                {
                    Type = CommandReplyType.SingleLineValue;
                    Code = 250;

                }
                else if (int.TryParse(code, out Code))
                {
                    Type = CommandReplyType.Status;
                }

                break;
            }

            if (code.Length + 1 < input.Length)
            {
                Arguments = input.Substring(code.Length + 1);
            }

            // Basic sanity check
            if (Code >= 1000 || Code < 250)
            {
                throw new Exception("Invalid reply.");
            }

            // 650 - Notifications
            if (Code == 650)
            {
                Type = CommandReplyType.Notification;
            }
        }
示例#6
0
 /// <summary>
 /// 注册一个命令
 /// </summary>
 public Task<CommandResult> RegisterCommand(ICommand command, CommandReplyType commandReplyType)
 {
     return this.RegisterCommand(command, commandReplyType, _commandBus.Send);
 }
 public ProtocolException(string message, CommandReplyType errorCode, Exception inner = null) : base(message, inner)
 {
     this.ErrorCode = errorCode;
 }
 public ProtocolException(CommandReplyType errorCode = CommandReplyType.GeneralFailure) : this(
         $"SOCKS error: {errorCode}",
         errorCode)
 {
 }
示例#9
0
 public CommandReply(CommandReplyType replyType, EndPoint bindEndPoint)
 {
     this.ReplyType    = replyType;
     this.BindEndPoint = bindEndPoint ?? throw new ArgumentNullException(nameof(bindEndPoint));
 }
示例#10
0
        public void AddBuff(int id, ActorBase caster)
        {
            if (m_Owner.IsDead)
            {
                return;
            }

            DRBuff db = GameEntry.DataTable.GetDataTable <DRBuff>()?.GetDataRow(id);

            if (db == null)
            {
                return;
            }

            BuffBase commonBuff = FindBuff(id);

            if (commonBuff != null)
            {
                switch ((BuffOverlayType)commonBuff.Data.OverlayType)
                {
                case BuffOverlayType.Overlay:
                    commonBuff.Overlay();
                    break;

                case BuffOverlayType.Reset:
                    commonBuff.Refresh();
                    break;

                case BuffOverlayType.Cancle:
                    m_DelBuffList.Add(commonBuff.Id);
                    break;
                }
                return;
            }
            CommandReplyType reply = CommandReplyType.NO;

            switch ((BattleActType)db.Result)
            {
            case BattleActType.Addattr:
            case BattleActType.Subattr:
            case BattleActType.Lddattr:
            case BattleActType.Lubattr:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Super:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Variation:
            {
                reply = m_Owner.ExecuteCommand(new VariationCommand(db.LifeTime, db.ChangeModelID));
            }
            break;

            case BattleActType.Hitfly:
            {
                reply = m_Owner.ExecuteCommand(new BeatFlyCommand());
            }
            break;

            case BattleActType.Hitdown:
            {
                reply = m_Owner.ExecuteCommand(new BeatDownCommand());
            }
            break;

            case BattleActType.Hitback:
            {
                reply = m_Owner.ExecuteCommand(new BeatBackCommand());
            }
            break;

            case BattleActType.Stun:
            {
                reply = m_Owner.ExecuteCommand(new StunCommand(db.LifeTime));
            }
            break;

            case BattleActType.Fixbody:
            {
                reply = m_Owner.ExecuteCommand(new FixBodyCommand(db.LifeTime));
            }
            break;

            case BattleActType.Stealth:
            {
                reply = m_Owner.ExecuteCommand(new StealthCommand(db.LifeTime));
            }
            break;

            case BattleActType.Frozen:
            {
                reply = m_Owner.ExecuteCommand(new FrostCommand(db.LifeTime));
            }
            break;

            case BattleActType.Blind:
            {
                reply = m_Owner.ExecuteCommand(new BlindCommand(db.LifeTime));
            }
            break;

            case BattleActType.Silent:
            {
                reply = m_Owner.ExecuteCommand(new SilentCommand(db.LifeTime));
            }
            break;

            case BattleActType.Sleep:
            {
                reply = m_Owner.ExecuteCommand(new SleepCommand(db.LifeTime));
            }
            break;

            case BattleActType.Absorb:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Wild:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Divive:
            {
                RemoveAllDebuff();
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Paraly:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Fear:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Reflex:
            {
                reply = CommandReplyType.YES;
            }
            break;

            case BattleActType.Dead:
            {
                reply = CommandReplyType.YES;
            }
            break;
            }

            if (reply == CommandReplyType.YES)
            {
                BuffBase buff = new BuffBase(id, m_Owner, caster);
                m_BuffMap.Add(id, buff);
            }

            m_Owner.UpdateCurAttribute();
        }