コード例 #1
0
ファイル: RoleSel.cs プロジェクト: lwfwhuhan/gongchengluedi
        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);
                ConsoleLog.Instance.writeInformationLog(outputstr);

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

                jsontest = TestApp.fire.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 Task RefreshCurTask(bool bDelete = true)
        {
            KeyValuePair <string, string>         pair;
            List <KeyValuePair <string, string> > pairLst = m_rcvpackagelst.FindAll(x => x.Key == "push@task");

            if (pairLst == null || pairLst.Count == 0)
            {
                return(null);
            }
            if (pairLst.Count > 1)
            {
                for (int i = 0; i < pairLst.Count; i++)
                {
                    lock (m_lock)
                    {
                        m_rcvpackagelst.Remove(pairLst[i]);
                    }
                }
                pair = pairLst[pairLst.Count - 1];
            }
            else
            {
                pair = pairLst[0];
            }

            if (default(KeyValuePair <string, string>).Equals(pair))
            {
                return(null);
            }
            string jsonstr = TestApp.fire.Tool.PickupDataStr(pair.Value);

            if (bDelete)
            {
                lock (m_lock)
                {
                    m_rcvpackagelst.Remove(pair);
                }
            }

            if (string.IsNullOrEmpty(jsonstr))
            {
                ConsoleLog.Instance.writeInformationLog("提取json字符串失败,jsonstr=" + jsonstr);
                return(null);
            }
            else
            {
                webCurTask t = null;
                try
                {
                    if (jsonstr.Contains("refreshTask"))
                    {
                        jsonstr = jsonstr.Replace("refreshTask", "tasks");
                    }
                    t = (webCurTask)JsonManager.JsonToObject(jsonstr, typeof(webCurTask));
                }
                catch (Exception ex1)
                {
                    ConsoleLog.Instance.writeSuccessLog("json转对象失败,str=" + jsonstr);
                }
                if (t == null)
                {
                    ConsoleLog.Instance.writeInformationLog("json转对象失败,jsonstr=" + jsonstr);
                }

                if (t.curTask != null && t.curTask.tasks != null && t.curTask.tasks.Count() > 0)
                {
                    return(t.curTask.tasks[0]);
                }
                else
                {
                    ConsoleLog.Instance.writeInformationLog("获取当前任务失败,jsonstr=" + jsonstr);
                    return(null);
                }
            }
        }