Пример #1
0
        public bool getServerIP()
        {
            string xmlURL = GlobalVal.ServerURL + "/Config.xml";

            string retstr = m_client.DownloadString(xmlURL, string.Empty);

            string serverstr = Regex.Match(retstr, "socketServiceUrl value=\"(?<value>.*?)\"").Groups["value"].Value;

            if (string.IsNullOrEmpty(serverstr))
            {
                return(false);
            }

            string[] lst = serverstr.Split(':');
            if (lst.Length != 2)
            {
                return(false);
            }

            m_serverAddr = lst[0];
            m_serverPort = Int32.Parse(lst[1]);
            //AppSetting.SetValue(m_strServerName, m_serverPort.ToString());
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 登陆游戏
        /// </summary>
        /// <returns></returns>
        public ExcuteState LoginGame()
        {
            ExcuteState exestate = new ExcuteState();

            exestate.State = IdentityCode.Success;
            return(exestate);

            try
            {
                #region 网页登陆操作
                string URL    = GlobalVal.CenterURL + "/ssoLogin.action?jsoncallback=jsonp1503016397724&funName=getRSAkey";
                string retstr = m_client.DownloadString(URL, string.Empty);
                retstr = retstr.Replace("\r", "").Replace("\n", "");
                string     jsontext = Regex.Match(retstr, "\\((?<value>.*?)\\)").Groups["value"].Value;
                CipherCode cipher   = (CipherCode)JsonManager.JsonToObject(jsontext, typeof(CipherCode));
                if (cipher == null)
                {
                    exestate.Description = "json转化为对象失败,json=" + jsontext;
                    return(exestate);
                }

                ScriptEngine engine     = new ScriptEngine();
                string       scriptpath = AppDomain.CurrentDomain.BaseDirectory + "\\RSA_min.js";
                bool         bSuccess   = engine.LoadScriptFromFile(scriptpath);
                if (!bSuccess)
                {
                    exestate.Description = ("加载脚本失败!脚本路径=" + scriptpath);
                    return(exestate);
                }
                //object retobj = engine.Eval(ScriptLanguage.JavaScript,
                //    "RSAKeyPair(\"233AB\", \"\", \"1234566666\")", engine.Functionbody);

                List <object> lst = new List <object>();
                lst.Add(cipher.public_exponent);
                lst.Add(cipher.public_modulus);
                lst.Add(cipher.tp);
                lst.Add(m_passwd);

                object token     = engine.EvalValue("getToken", lst, engine.Functionbody);
                string stoken    = (string)token;
                long   timeticks = ConvertDateTimeToInt();
                URL = GlobalVal.CenterURL +
                      string.Format("/ssoLogin.action?jsoncallback=jsonp{2}&funName=indexLogin&username={0}&token={1}&remember=true",
                                    m_uname, stoken, timeticks);
                retstr = m_client.DownloadString(URL, string.Empty);

                jsontext = Regex.Match(retstr, "\\((?<value>.*?)\\)").Groups["value"].Value;
                webLoginInfo info = (webLoginInfo)JsonManager.JsonToObject(jsontext, typeof(webLoginInfo));
                if (info == null)
                {
                    exestate.Description = "json转化为对象失败2,json=" + jsontext;
                    return(exestate);
                }
                if (!info.success)
                {
                    return(exestate);
                }

                // 获取个人信息
                URL = GlobalVal.LgnURL + "/html/server/ssoLogin.xhtml";
                string postdata = string.Format("ts={0}&key={1}&userJson=%7B%22encryptInfo%22%3A%22{2}%22%7D&isgameLogin=true",
                                                info.ts, info.key, info.current_user.encryptInfo);

                retstr = m_client.Post(URL, string.Empty, postdata);

                webPersonalInfo gameinfo = (webPersonalInfo)JsonManager.JsonToObject(retstr, typeof(webPersonalInfo));
                m_psInfo = gameinfo;
                jsontext = Regex.Match(retstr, "\\[(?<value>.*?)\\]").Groups["value"].Value;
                List <webGameInfo> ginfo = (List <webGameInfo>)JsonManager.JsonToObject("[" + jsontext + "]", typeof(List <webGameInfo>));
                m_psInfo.phistory = ginfo[0];
                m_strServerName   = ginfo[0].serverName;

                // 快速登录
                URL = GlobalVal.LgnURL + "/quick.xhtml?gid=gcld";
                m_client.ResponseHeaderData = "Location";
                m_client.DownloadString(URL, string.Empty);
                string jumpURL = m_client.ResponseHeaderData;
                if (string.IsNullOrEmpty(jumpURL))
                {
                    exestate.Description = "获取登录服务器失败";
                    return(exestate);
                }

                retstr = m_client.DownloadString(jumpURL, string.Empty);
                if (string.IsNullOrEmpty(retstr))
                {
                    exestate.Description = "获取登录服务器失败2,URL=" + jumpURL;
                    return(exestate);
                }

                jumpURL = Regex.Match(retstr, "frame src=\"(?<value>.*?)\" name=\"gameFrame").Groups["value"].Value;
                if (string.IsNullOrEmpty(jumpURL))
                {
                    exestate.Description = "获取登录服务器失败3,Page=" + retstr;
                    return(exestate);
                }

                retstr = m_client.DownloadString(jumpURL, string.Empty);
                if (string.IsNullOrEmpty(retstr))
                {
                    exestate.Description = "获取登录服务器失败4,URL=" + jumpURL;
                    return(exestate);
                }
                jumpURL             = Regex.Match(retstr, "window.location.href = \"(?<value>.*?)\"").Groups["value"].Value;
                GlobalVal.ServerURL = jumpURL.Substring(0, jumpURL.IndexOf("/root"));
                GlobalVal.CmdURL    = GlobalVal.ServerURL + "/root/gateway.action?command=";
                if (string.IsNullOrEmpty(jumpURL))
                {
                    exestate.Description = "获取登录服务器失败5,Page=" + retstr;
                    return(exestate);
                }

                retstr = m_client.DownloadString(jumpURL, string.Empty);
                if (retstr == "{\"state\":1,\"data\":1}")
                {
                    exestate.State = IdentityCode.Success;
                }
                else
                {
                    exestate.Description = "获取登录服务器失败6,retstr=" + retstr;
                }
                //{
                //    exestate.State = IdentityCode.Success;
                //    m_lgnInfo = info;
                //}
                // = engine.Run("encryptedString", oblist, engine.Functionbody);
                #endregion
            }
            catch (Exception ex)
            {
                exestate.Description = ex.Message + "\r\n" + ex.StackTrace;
                Debug.WriteLine(exestate.Description);
            }

            return(exestate);
        }