Esempio n. 1
0
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns></returns>
        public static UserTicketInfo GetUserCookie()
        {
            string plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);

            // 大厅cookie处理
            object pfCookieUserName = HttpContext.Current.Request.Cookies["Accounts"];
            object pfCookieUserID   = HttpContext.Current.Request.Cookies["UserID"];

            if (string.IsNullOrEmpty(plaintext))
            {
                // 大厅Cookie存在
                if (pfCookieUserName != null && pfCookieUserID != null)
                {
                    plaintext = PalaformWriteCookie();
                }
            }
            else
            {
                // 如果网页与大厅cookie都存在,验证是否一致
                string tempStr = Utils.AES.Decrypt(plaintext, CookieEncryptKey);
                if (!string.IsNullOrEmpty(tempStr) && pfCookieUserName != null && pfCookieUserID != null)
                {
                    UserTicketInfo tempModel = UserTicketInfo.DeserializeObject(tempStr);
                    if (tempModel.UserID.ToString() != pfCookieUserID.ToString() || tempModel.Accounts != pfCookieUserName.ToString())
                    {
                        Fetch.DeleteCookie(Fetch.UC_COOKIE_LOGON_TOKEN);
                        plaintext = PalaformWriteCookie();
                    }
                }
            }

            //cookie为空
            if (TextUtility.EmptyTrimOrNull(plaintext))
            {
                return(null);
            }

            //验证cookie格式
            string jsonText = Utils.AES.Decrypt(plaintext, CookieEncryptKey);

            if (TextUtility.EmptyTrimOrNull(jsonText))
            {
                return(null);
            }

            return(UserTicketInfo.DeserializeObject(jsonText));
        }
Esempio n. 2
0
 /// <summary>
 /// 大厅登陆写入cookie
 /// </summary>
 public static string PalaformWriteCookie()
 {
     if (HttpContext.Current.Request.Cookies["Accounts"] != null && HttpContext.Current.Request.Cookies["Password"] != null)
     {
         string accounts = HttpContext.Current.Request.Cookies["Accounts"].Value.ToString();
         string password = HttpContext.Current.Request.Cookies["Password"].Value.ToString();
         password = password.Trim();
         accounts = accounts.Trim();
         UserInfo suInfo = new UserInfo(0, accounts, 0, password.Trim());
         suInfo.LastLogonIP = GameRequest.GetUserIP();
         AccountsFacade accountsFacade = new AccountsFacade();
         Message        umsg           = accountsFacade.Logon(suInfo, true);
         if (umsg.Success)
         {
             UserInfo ui = umsg.EntityList[0] as UserInfo;
             ui.LogonPass = password.Trim();
             Fetch.SetUserCookie(ui.ToUserTicketInfo());
             return(Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN));
         }
     }
     return("");
 }
Esempio n. 3
0
        /// <summary>
        /// 获取用户对象
        /// </summary>
        /// <returns></returns>
        public static UserTicketInfo GetUserCookie()
        {
            string plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);

            //平台跳转判断是否登录
            if (HttpContext.Current.Request.Cookies["Accounts"] != null && HttpContext.Current.Request.Cookies["Password"] != null && TextUtility.EmptyTrimOrNull(plaintext))
            {
                string accounts = HttpContext.Current.Request.Cookies["Accounts"].Value.ToString();
                string password = HttpContext.Current.Request.Cookies["Password"].Value.ToString();
                password = password.Trim();
                accounts = accounts.Trim();
                UserInfo suInfo = new UserInfo(0, accounts, 0, password.Trim());
                suInfo.LastLogonIP = GameRequest.GetUserIP();
                AccountsFacade accountsFacade = new AccountsFacade();
                Message        umsg           = accountsFacade.Logon(suInfo, true);
                if (umsg.Success)
                {
                    UserInfo ui = umsg.EntityList[0] as UserInfo;
                    ui.LogonPass = password.Trim();
                    Fetch.SetUserCookie(ui.ToUserTicketInfo());
                    plaintext = Fetch.GetCookie(Fetch.UC_COOKIE_LOGON_TOKEN);
                }
            }

            if (TextUtility.EmptyTrimOrNull(plaintext))
            {
                return(null);
            }

            string jsonText = Utils.AES.Decrypt(plaintext, CookieEncryptKey);

            if (TextUtility.EmptyTrimOrNull(jsonText))
            {
                return(null);
            }

            return(UserTicketInfo.DeserializeObject(jsonText));
        }