Ejemplo n.º 1
0
 private void UpdateOnlinePlayerNumber(object sender, EventArgs e)
 {
     try
     {
         //更新在线玩家数字
         string str = NetworkTools.GetUrlReturn("http://139.199.127.51:23233/?Qgetnum");
         //示例:document.write("在线人数:1:Qiaoyiiii6;")
         string onlinenum = str.Substring(21, 1);
         OnlinePlayerNumber = int.Parse(onlinenum);
     }
     catch
     {
         OnlinePlayerNumber = 0;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取指定日期各时段玩家数。
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public List <TimePointPlayerNumber> GetPlayerNumbersOfDay(DateTime date)
        {
            try
            {
                List <TimePointPlayerNumber> ret = new List <TimePointPlayerNumber>();
                string _date = date.Year.ToString() + (date.Month.ToString().Length == 2 ? date.Month.ToString() : "0" + date.Month.ToString()) +
                               (date.Day.ToString().Length == 2 ? date.Day.ToString() : "0" + date.Day.ToString());
                string   playersOnTime = NetworkTools.GetUrlReturn("http://139.199.127.51/Qnum/" + _date + ".txt");
                char[]   spchar        = { '\\', '\\' };
                string[] lines         = Regex.Split(playersOnTime, "\\\\", RegexOptions.IgnoreCase);
                foreach (string s in lines)
                {
                    if (s == "")
                    {
                        continue;
                    }
                    string time = s.Split(':')[0];
                    string num  = s.Split(':')[1];

                    //*** 判断最接近的时间点并将数据填充到PlayerNumberDuringDay的合适位置 ***
                    //以下算法极为烧脑,请酌情修改
                    //可联系时间轴帮助理解算法
                    int year  = int.Parse(time.Substring(0, 4));  //取得年
                    int month = int.Parse(time.Substring(4, 2));  //取得月
                    int day   = int.Parse(time.Substring(6, 2));  //取得日
                    int hour  = int.Parse(time.Substring(8, 2));  //取得小时
                    int min   = int.Parse(time.Substring(10, 2)); //取得分钟
                    ret.Add(new TimePointPlayerNumber(new DateTime(year, month, day, hour, min, 0), int.Parse(num)));
                }
                return(ret);
            }
            catch (Exception e)
            {
                throw e;
            }
        }