Пример #1
0
        public ExcuteState getPlayerInfo(webRole role)
        {
            ExcuteState state = new ExcuteState();

            try
            {
                string URL      = GlobalVal.ServerURL + "/root/gateway.action";
                string postdata = "command=player%40getPlayerInfo&version=11%2E01%2E17%2E1&token=1&info=3391&playerId=" + role.playerId;

                string outputstr = m_client.Post_retbyte2(URL, string.Empty, postdata);
                Debug.WriteLine(outputstr);

                string        jsontest   = Regex.Match(outputstr, "player\":(?<value>.*?)\\},").Groups["value"].Value + "}";
                webDetailRole detailinfo = (webDetailRole)JsonManager.JsonToObject(jsontest, typeof(webDetailRole));
                m_roledetail = detailinfo;

                jsontest = Tool.PickupDataStr(outputstr);;
                webCurTask taskInfo = (webCurTask)JsonManager.JsonToObject(jsontest, typeof(webCurTask));
                if (taskInfo.curTask.tasks != null && taskInfo.curTask.tasks.Count() > 0)
                {
                    m_curTask = taskInfo.curTask.tasks[0];
                    // 把信息写入配置文件
                    TaskObj task = TaskObj.getCurTask(m_curTask);
                    // 把任务写入txt
                    // 再获取一次角色列表
                    if (!string.IsNullOrEmpty(TasktxtPath) && File.Exists(TasktxtPath) && task != null)
                    {
                        List <TaskObj> tasklst = null;
                        TaskObj.getTasklistFromTxt(TasktxtPath, ref tasklst);
                        // 搜索列表
                        TaskObj tobj = tasklst.Find(delegate(TaskObj user){ return(user.TaskName == task.TaskName); });
                        if (tobj == null)
                        {//写入文档
                            TaskObj.WriteData2File(TasktxtPath, task.Obj2String());
                        }
                    }
                }
                state.State = IdentityCode.Success;
            }
            catch (Exception ex)
            {
                state.Description = "发生异常=" + ex.Message + ";\r\n" + ex.StackTrace;
                return(state);
            }
            return(state);
        }
Пример #2
0
        public ExcuteState getPlayerList()
        {
            ExcuteState state = new ExcuteState();

            try
            {
                string jsontext = null;
                //byte[] arrOutput = m_client.DownloadBytearr(GlobalVal.CmdURL + "player@getPlayerList", string.Empty, false);
                //byte[] arrDescrypt = ZlibCompress.DecompressBytes(arrOutput);
                while (true)
                {
                    string outputstr = m_client.DownloadBytearr2(GlobalVal.CmdURL + "player@getPlayerList", string.Empty, false);

                    jsontext = Regex.Match(outputstr, "\\[(?<value>.*?)\\]").Groups["value"].Value;

                    if (string.IsNullOrEmpty(jsontext))
                    {// 创角
                        RoleCreate.GetForceInfo(m_client);
                    }
                    else
                    {
                        break;
                    }
                }

                // 目前只有一个角色
                webRole webrole = (webRole)JsonManager.JsonToObject(jsontext, typeof(webRole));
                if (webrole != null)
                {
                    Rolelist.Add(webrole);
                }
                else
                {
                    state.Description = "getPlayerList() 转化json为对象失败, json=" + jsontext;
                    return(state);
                }

                state.State = IdentityCode.Success;
            }
            catch (Exception ex)
            {
                state.Description = "发生异常=" + ex.Message + ";\r\n" + ex.StackTrace;
                return(state);
            }
            return(state);
        }
Пример #3
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);
        }