Example #1
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());
        }