Ejemplo n.º 1
0
        public static ArgValues Get(string[] args)
        {
            var cmdArgs = new ArgValues();

            if (args.Length <= 0)
            {
                cmdArgs.IsInvalid = true;

                return(cmdArgs);
            }

            var hasValidArgs = new List <bool>();

            // get param values
            var paramList = new List <Tuple <string, Action <string> > >
            {
                Create <string, Action <string> >("wcfServiceDir", paramValue => cmdArgs.WcfServiceDir       = paramValue),
                Create <string, Action <string> >("serviceOutputDir", paramValue => cmdArgs.ServiceOutputDir = paramValue),
                Create <string, Action <string> >("wcfClientDir", paramValue => cmdArgs.WcfClientDir         = paramValue),
                Create <string, Action <string> >("clientOutputDir", paramValue => cmdArgs.ClientOutputDir   = paramValue),
            };

            foreach (var paramItem in paramList)
            {
                var paramKey   = $"-{paramItem.Item1}:";
                var fullArg    = args.FirstOrDefault(arg => arg.ToLower().StartsWith(paramKey.ToLower()));
                var paramValue = fullArg?
                                 .Replace(paramKey, "")
                                 .Replace("\"", "");

                var setCmdArg = paramItem.Item2;
                setCmdArg(paramValue);

                hasValidArgs.Add(!string.IsNullOrEmpty(fullArg));
            }

            // help
            var helpParam = args.FirstOrDefault(arg => new[] { "-?", "/?" }.Any(arg.StartsWith));

            cmdArgs.IsHelp = !string.IsNullOrEmpty(helpParam);
            hasValidArgs.Add(cmdArgs.IsHelp);

            // invalid
            cmdArgs.IsInvalid = hasValidArgs.All(arg => arg == false);

            return(cmdArgs);
        }
Ejemplo n.º 2
0
        public APIResault UpdateAddress(string args, HttpListenerRequest request)
        {
            string remoteIP = GetIP(request);
            string blockkey = KeyHead + remoteIP;

            long curTick = (long)CommonMethods.ConvertDateTimeInt(DateTime.Now, true, true);

            APIResault res = CheckBlockIP(blockkey, remoteIP, curTick);

            if (!res.IsSuccess)
            {
                return(res);
            }


            ArgValues arg  = ApiCommon.GetArgs(args);
            long      tick = arg.GetDataValue <long>("Tick");
            string    name = arg.GetDataValue <string>("Name");
            string    sign = arg.GetDataValue <string>("Sign");

            res = CheckPacket(curTick, name, tick);
            if (!res.IsSuccess)
            {
                return(res);
            }

            FWUser user = _userMan.GetUser(name);

            if (user == null)
            {
                return(ApiCommon.GetFault("找不到用户:" + name));
            }

            string cntkey = KeyCntHead + remoteIP;

            string cursign = user.GetSign(tick);

            if (!string.Equals(cursign, sign, StringComparison.CurrentCultureIgnoreCase))
            {
                int times = _cache.GetValue <int>(cntkey);
                times++;
                string err = null;
                if (times >= BlockTimes)
                {
                    _cache.SetValue <long>(blockkey, curTick, SetValueType.Set, BlockSecond);
                    _cache.DeleteValue(cntkey);
                    err = "效验错误,IP被屏蔽:" + remoteIP;
                }
                else
                {
                    _cache.SetValue <int>(cntkey, times, SetValueType.Set, BlockSecond);
                    err = "效验错误,错误次数:" + times;
                }
                return(ApiCommon.GetFault(err));
            }
            _cache.DeleteValue(cntkey);
            if (!user.UpdateIP(remoteIP))
            {
                return(ApiCommon.GetSuccess());
            }
            _userMan.RefreashFirewall();
            _userMan.SaveConfig();
            _form.OnUserUpdate();
            if (_message != null && _message.ShowLog)
            {
                _message.Log("用户:" + name + ",的IP更新为:" + remoteIP);
            }
            return(ApiCommon.GetSuccess());
        }