Exemple #1
0
        public DynamicService()
        {
            InitializeComponent();

            try {
                var doc = new XmlDocument();
                doc.Load(string.Format("{0}DynamicDNS.exe.config", AppDomain.CurrentDomain.BaseDirectory));
                var appSettings = doc.GetElementsByTagName("add").OfType <XmlNode>().ToDictionary(t => t.Attributes["key"].Value.ToLower(), (t) => t.Attributes["value"].Value);

                if (appSettings.ContainsKey("email"))
                {
                    email = CryptHelper.AESDecrypt(appSettings["email"]);
                }

                if (appSettings.ContainsKey("password"))
                {
                    password = CryptHelper.AESDecrypt(appSettings["password"]);
                }

                if (appSettings.ContainsKey("domain"))
                {
                    domain = CryptHelper.AESDecrypt(appSettings["domain"]);
                }

                if (appSettings.ContainsKey("subdomain"))
                {
                    subDomain = CryptHelper.AESDecrypt(appSettings["subdomain"]);
                }

                if (appSettings.ContainsKey("updateinterval"))
                {
                    var _updateInterval = appSettings["updateinterval"];
                    int.TryParse(_updateInterval, out updateInterval);
                    updateInterval = Math.Max(updateInterval, 5);
                }
            }
            catch (Exception ex) {
                Logger.Write("配置文件不存在或配置不正确:{0}", ex.Message);
            }

            timer          = new Timer();
            timer.Elapsed += timer_Elapsed;
        }
Exemple #2
0
    /// <summary>
    /// Reads the config file.
    /// </summary>
    public static void ReadConfigFile()
    {
        try{
            using (FileStream t_file = new FileStream(Application.persistentDataPath + ConfigFilename, FileMode.Open, FileAccess.Read)){
                using (StreamReader t_sr = new StreamReader(t_file)){
                    int t_version = int.Parse(t_sr.ReadLine());

                    Setting_IsAutoLogin      = bool.Parse(t_sr.ReadLine());
                    Setting_IsAutoLogin      = false;
                    Setting_IsGuest          = bool.Parse(t_sr.ReadLine());
                    Setting_IsRemberPassword = bool.Parse(t_sr.ReadLine());
                    Setting_LoginName        = t_sr.ReadLine();
                    Debug.Log(Setting_LoginName);
                    Setting_LoginPass = CryptHelper.AESDecrypt(t_sr.ReadLine());
                    Debug.Log(Setting_LoginPass);
                    Setting_LogingServer = t_sr.ReadLine();

                    Setting_ScreenQuality = bool.Parse(t_sr.ReadLine());
                    Setting_Gravity       = bool.Parse(t_sr.ReadLine());
                    Setting_UserDefined   = bool.Parse(t_sr.ReadLine());
                    Setting_MusicVol      = int.Parse(t_sr.ReadLine());
                    Setting_SoundVol      = int.Parse(t_sr.ReadLine());

                    Setting_Language = int.Parse(t_sr.ReadLine());

                    if (ConfigFileVersion >= 2)
                    {
                        Setting_SkipCopyCameraTrack = bool.Parse(t_sr.ReadLine());
                    }

                    if (ConfigFileVersion >= 3)
                    {
                        Setting_ShakeEnable = bool.Parse(t_sr.ReadLine());
                    }
                }
            }
        }catch (System.Exception ex) {
            Debug.LogWarning("Open config file failed, Exception:" + ex.Message);
        }
    }
Exemple #3
0
        /// <summary>
        /// 校验Token
        /// </summary>
        /// <param name="token">待校验的Token字符串</param>
        /// <param name="userId">输出型参数,若校验通过值为userId,否则值为null</param>
        /// <returns>Token校验结果。Valid:校验通过; Invalid:不合法的Token,校验失败; Expired:过期的Token,校验失败</returns>
        public string CheckToken(string token, out string userId)
        {
            userId = null;
            //base64编码后4的倍数长度,AES加密长度大于24位
            if (token.Length % 4 != 0 || token.Length < 24)
            {
                return(TokenState.Invalid.ToString());
            }
            string realData = CryptHelper.AESDecrypt(token);

            //验证解密非空,否则token不合法
            if (string.IsNullOrEmpty(realData))
            {
                return(TokenState.Invalid.ToString());
            }

            string[] splitData = realData.Split('&');
            //如果按照&拆分后不是4个部分,肯定被篡改了
            if (splitData.Length != 4)
            {
                return(TokenState.Invalid.ToString());
            }
            //验证数字签名
            if (HashBuilder.GetHMACMD5Hash(splitData[0] + splitData[1] + splitData[2]).Equals(splitData[3]) == false)
            {
                return(TokenState.Invalid.ToString());
            }

            //验证是否过期
            if (Convert.ToInt32((DateTime.Now - Convert.ToDateTime(splitData[1])).TotalMinutes) > Convert.ToInt32(splitData[2]))
            {
                return(TokenState.Expired.ToString());
            }
            //到此验证通过
            userId = splitData[0];
            return(TokenState.Valid.ToString());
        }