public HandleParseErrArgs(MsgCmdHelperBase <TWithUi> sender, MsgDetail msgDetail, MsgCmd msgCmd, Exception exception = null)
 {
     Sender    = sender;
     MsgDetail = msgDetail;
     MsgCmd    = msgCmd;
     Exception = exception;
 }
Exemple #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MsgCmd != 0)
            {
                hash ^= MsgCmd.GetHashCode();
            }
            if (Uuid.Length != 0)
            {
                hash ^= Uuid.GetHashCode();
            }
            if (TimeStart.Length != 0)
            {
                hash ^= TimeStart.GetHashCode();
            }
            if (TimeEnd.Length != 0)
            {
                hash ^= TimeEnd.GetHashCode();
            }
            if (ImageBase64.Length != 0)
            {
                hash ^= ImageBase64.GetHashCode();
            }
            if (Processed != 0)
            {
                hash ^= Processed.GetHashCode();
            }
            hash ^= targetFeatureList_.GetHashCode();
            hash ^= targetResultList_.GetHashCode();
            return(hash);
        }
        public static MsgCmd GetCmd(this int value)
        {
            MsgCmd cmd = MsgCmd.None;

            if (Enum.IsDefined(typeof(MsgCmd), value))
            {
                cmd = (MsgCmd)value;
            }

            return(cmd);
        }
        public virtual bool Request <TData>(MsgCmd cmd, TData data)
        {
            bool result = false;
            var  msg    = this.msgClient.Send(cmd.GetValue(), data);

            if (msg.Status == MsgStatus.Succeed.GetValue())
            {
                result = true;
            }
            else
            {
                string s = !string.IsNullOrEmpty(msg.Msg) ? msg.Msg : ((MsgStatus)msg.Status).GetDescription();
                LogUtils.Error($"【Request】cmd:{cmd}, Status: {msg.Status}, Msg: {s}");
            }
            return(result);
        }
        public virtual TResult Request <TResult, TData>(MsgCmd cmd, TData data, bool isThrow = false)
        {
            TResult result = default(TResult);
            var     msg    = this.msgClient.Send(cmd.GetValue(), data);

            if (msg.Status == MsgStatus.Succeed.GetValue())
            {
                result = msg.GetData <TResult>();
            }
            else
            {
                string s = !string.IsNullOrEmpty(msg.Msg) ? msg.Msg : ((MsgStatus)msg.Status).GetDescription();
                LogUtils.Error($"【Request】cmd:{cmd}, Status: {msg.Status}, Msg: {s}");
                if (isThrow)
                {
                    throw new MsgStatusException(msg.Status, s);
                }
            }
            return(result);
        }
        public virtual TResult Request <TResult, TData>(MsgCmd cmd, TData data, out int status, out string error)
        {
            TResult result = default(TResult);

            status = MsgStatus.None.GetValue();
            error  = null;
            var msg = this.msgClient.Send(cmd.GetValue(), data);

            if (msg.Status == MsgStatus.Succeed.GetValue())
            {
                result = msg.GetData <TResult>();
            }
            else
            {
                string s = !string.IsNullOrEmpty(msg.Msg) ? msg.Msg : ((MsgStatus)msg.Status).GetDescription();
                LogUtils.Error($"【Request】cmd:{cmd}, Status: {msg.Status}, Msg: {s}");
            }
            status = msg.Status;
            error  = !string.IsNullOrEmpty(msg.Msg) ? msg.Msg : ((MsgStatus)msg.Status).GetDescription();

            return(result);
        }
 /// <summary>
 /// 解析一个
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public virtual TWithUi Parse(MsgCmd item)
 {
     return(DetailProcess[item.Id][item.Type](new MsgCmdParseArgs <TWithUi>(this, item, GetUi())));
 }
 public static string GetName(this MsgCmd cmd)
 {
     return(cmd.ToString());
 }
 public static int GetValue(this MsgCmd cmd)
 {
     return((int)cmd);
 }
    public void Parse(string name, string msg)
    {
        var commands = msg.ToLower().Substring(1).Split();

        if (commands.Length > 3)
        {
            return;
        }

        MsgCmd cmd = MsgCmd.none;

        if (!(System.Enum.TryParse(commands[0], out cmd)))
        {
            return;
        }

        TEAM team = TEAM.BOTH;

        if (GameLogic.State == GameState.Playing)
        {
            if (_goodPlayers.Contains(name))
            {
                team = TEAM.GOOD;
            }
            else if (_evilPlayers.Contains(name))
            {
                team = TEAM.BAD;
            }
        }

        switch (cmd)
        {
        case MsgCmd.move:
            if (GameLogic.State == GameState.Playing)
            {
                if (team == TEAM.BOTH)
                {
                    return;
                }

                Cmd subcmd;
                if (!(Enum.TryParse(commands[2], out subcmd)))
                {
                    return;
                }

                if (IsPlayerBlockedByCooldown(name, subcmd))
                {
                    return;
                }

                SetPlayerCmdCooldown(name, subcmd);

                InteractableManager.instance.DistributeCommand(subcmd, commands[1].ToUpper(), team);
            }
            break;

        case MsgCmd.arm:
            if (GameLogic.State == GameState.Playing)
            {
                if (team == TEAM.BOTH)
                {
                    return;
                }

                if (IsPlayerBlockedByCooldown(name, Cmd.arm))
                {
                    return;
                }

                SetPlayerCmdCooldown(name, Cmd.arm);

                InteractableManager.instance.DistributeCommand(Cmd.arm, commands[1].ToUpper(), team);
            }
            break;

        case MsgCmd.disarm:
            if (GameLogic.State == GameState.Playing)
            {
                if (team == TEAM.BOTH)
                {
                    return;
                }

                if (IsPlayerBlockedByCooldown(name, Cmd.disarm))
                {
                    return;
                }

                SetPlayerCmdCooldown(name, Cmd.disarm);

                InteractableManager.instance.DistributeCommand(Cmd.disarm, commands[1].ToUpper(), team);
            }
            break;

        case MsgCmd.join:
            if (GameLogic.State == GameState.Perperation && !_joinedPlayers.Contains(name) && _joinedPlayers.Count < Config.MaxPlayers)
            {
                _joinedPlayers.Add(name);
                Debug.Log($"{name} joined");
            }
            break;

        case MsgCmd.pause:
            if (GameLogic.State == GameState.Playing)
            {
                if (team != TEAM.GOOD)
                {
                    return;
                }

                if (IsPlayerBlockedByCooldown(name, Cmd.pause))
                {
                    return;
                }

                SetPlayerCmdCooldown(name, Cmd.pause);

                InteractableManager.instance.DistributeCommand(Cmd.pause, "", team);
            }
            break;

        case MsgCmd.help:
            if (_helpTimer <= 0)
            {
                _helpTimer = _helpCooldown;
                twitchClient.SendMessage(twitchClient.JoinedChannels[0], "This should be helpful huh?");
            }
            break;
        }
    }
 public MsgCmdParseArgs(MsgCmdHelperBase <TWithUi> sender, MsgCmd parseObject, TWithUi uiElement)
 {
     Sender      = sender;
     ParseObject = parseObject;
     UiElement   = uiElement;
 }