private void LoadInfo() { if (Request.QueryString.Count > 0) { Table1.Rows[1].Cells[0].Width = 265; #region Steam Profile Data Int64 CID = GetCommunityID(Request.QueryString[0]); //bool first = false; XDocument doc = XDocument.Load(string.Format("http://steamcommunity.com/profiles/{0}/?xml=1", CID.ToString())); //TODO: do something if the player hasn't set up his or her profile. //TODO: figure out what (if anything) we can still get info on if someone hasn't set up their profile. try { if (doc.Descendants("profile").Elements("avatarFull").Single().Value == "http://media.steampowered.com/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_full.jpg") { SteamPic.ImageUrl = "question_mark.png"; } else { SteamPic.ImageUrl = doc.Descendants("profile").Elements("avatarFull").Single().Value; } Page.Header.Title = string.Format("{0}'s Statistics :: Ch1ckensCoop", doc.Descendants("profile").Elements("steamID").Single().Value); Table1.Rows[0].Cells[2].Text = doc.Descendants("profile").Elements("steamID").Single().Value; if (doc.Descendants("profile").Elements("onlineState").Single().Value.Contains("in-game")) { HyperLink link1 = new HyperLink(); link1.NavigateUrl = doc.Descendants("profile").Descendants("inGameInfo").Elements("gameLink").Single().Value; link1.Text = doc.Descendants("profile").Descendants("inGameInfo").Elements("gameName").Single().Value; Label PlayingLable = new Label(); PlayingLable.Text = "Playing "; Table1.Rows[1].Cells[1].Controls.Add(PlayingLable); Table1.Rows[1].Cells[1].Controls.Add(link1); if (doc.Descendants("profile").Elements("inGameServerIP").Single().Value.Length > 1) { HyperLink link2 = new HyperLink(); link2.Text = "Join Game"; link2.NavigateUrl = string.Format("steam://connect/{0}", doc.Descendants("profile").Elements("inGameServerIP").Single().Value); Table1.Rows[2].Cells[1].Text = string.Format("<a href='steam://connect/{0}'>Join Game</a>", doc.Descendants("profile").Elements("inGameServerIP").Single().Value); } else { Table1.Rows[2].Cells[1].Text = "Not in joinable game."; } } else if (doc.Descendants("profile").Elements("onlineState").Single().Value.Contains("online")) { Table1.Rows[1].Cells[1].Text = "Online"; Table1.Rows[2].Cells[1].Text = "Not in a game."; } else { Table1.Rows[2].Cells[1].Text = "Not in a game."; } //Get playtime for Alien Swarm XDocument asw_time = XDocument.Load(string.Format("http://steamcommunity.com/profiles/{0}/games?xml=1", CID.ToString())); foreach (XElement game in asw_time.Descendants("gamesList").Descendants("games").Descendants("game")) { //Table1.Rows[4].Cells[1].Text = "Made it this farther..."; string value = game.Element("appID").Value.ToString(); if (value == "630") { Table1.Rows[4].Cells[1].Text = game.Element("hoursLast2Weeks").Value.ToString() + " Hours "; Table1.Rows[3].Cells[1].Text = game.Element("hoursOnRecord").Value.ToString() + " Hours "; Table1.Rows[4].Visible = true; Table1.Rows[3].Visible = true; } } //asw_time.Descendants("gamesList").Descendants("games").Descendants("game").Elements("appID"); } catch { //Image Qm = new Image(); //Qm.ImageUrl = "questionmark.png"; //Response.Write(Qm); Response.Write(@"<img src='question_mark.png'; /> This player has not set up their Steam profile."); Response.End(); } #endregion #region Recorded Statistics using (StreamReader sr = new StreamReader(@"E:\Ch1ckensCoop_Server\swarm\addons\sourcemod\SwarmStats\players.swarmstats")) { string line; while ((line = sr.ReadLine()) != null) { if (line.Contains(Request.QueryString[0])) { while (line.Contains('}') == false) { line = sr.ReadLine(); string newline; if (line.Contains(@"""kills""")) { newline = line.Replace(@"""kills""", ""); newline = newline.Remove(0, newline.IndexOf('"') + 1); Table1.Rows[5].Cells[1].Text = newline.Remove(newline.Length - 1, 1); } else if (line.Contains(@"""points""")) { newline = line.Replace(@"""points""", ""); newline = newline.Remove(0, newline.IndexOf('"') + 1); Table1.Rows[6].Cells[1].Text = newline.Remove(newline.Length - 1, 1); } } } } } #endregion #region Wins and Losses using (StreamReader sr = new StreamReader(@"E:\Ch1ckensCoop_Server\swarm\addons\sourcemod\SwarmStats\maps.swarmstats")) { int level = 0; int skill = 0; string mapname = ""; int wins = -1; int linenume = 0; int plays = -1; string line; while ((line = sr.ReadLine()) != null) { linenume++; if (line.Contains('{')) { level++; } if (level == 1) { if (line.Contains("Easy")) { skill = 1; } else if (line.Contains("Normal")) { skill = 2; } else if (line.Contains("Hard")) { skill = 3; } else if (line.Contains("Insane")) { skill = 4; } else if (line.Contains("Brutal")) { skill = 5; } } else if (line.Contains('}')) { level--; } if (line.Contains(Request.QueryString[0]) && level == 3) { while ((line = sr.ReadLine()).Contains('}') == false) { linenume++; string[] data; if (line.Contains(@"""plays""")) { data = line.Split('"'); plays = Convert.ToInt32(data[3]); } else if (line.Contains(@"""wins""")) { data = line.Split('"'); wins = Convert.ToInt32(data[3]); } } if (wins == -1) { wins = 0; } //level--; } if (level == 2) { string[] data = line.Split('"'); if (data.Length == 3) { mapname = data[1]; } } if (mapname != null && wins != -1 && plays != -1) { if (skill == 1) { TableCell mapCell = new TableCell(); mapCell.Text = FriendlyNames.GetMapName(mapname); TableCell playsCell = new TableCell(); playsCell.Text = (plays - wins).ToString(); TableCell winsCell = new TableCell(); winsCell.Text = wins.ToString(); TableRow row1 = new TableRow(); row1.Cells.Add(mapCell); row1.Cells.Add(winsCell); row1.Cells.Add(playsCell); row1.BackColor = System.Drawing.ColorTranslator.FromHtml("#D9F7FF"); Easy.Rows.Add(row1); Easy.Visible = true; mapname = ""; wins = -1; plays = -1; } else if (skill == 2) { TableCell mapCell = new TableCell(); mapCell.Text = FriendlyNames.GetMapName(mapname); TableCell playsCell = new TableCell(); playsCell.Text = (plays - wins).ToString(); TableCell winsCell = new TableCell(); winsCell.Text = wins.ToString(); TableRow row1 = new TableRow(); row1.Cells.Add(mapCell); row1.Cells.Add(winsCell); row1.Cells.Add(playsCell); row1.BackColor = System.Drawing.ColorTranslator.FromHtml("#D9F7FF"); Normal.Rows.Add(row1); Normal.Visible = true; mapname = ""; wins = -1; plays = -1; } else if (skill == 3) { TableCell mapCell = new TableCell(); mapCell.Text = FriendlyNames.GetMapName(mapname); TableCell playsCell = new TableCell(); playsCell.Text = (plays - wins).ToString(); TableCell winsCell = new TableCell(); winsCell.Text = wins.ToString(); TableRow row1 = new TableRow(); row1.Cells.Add(mapCell); row1.Cells.Add(winsCell); row1.Cells.Add(playsCell); row1.BackColor = System.Drawing.ColorTranslator.FromHtml("#D9F7FF"); Hard.Rows.Add(row1); Hard.Visible = true; mapname = ""; wins = -1; plays = -1; } else if (skill == 4) { TableCell mapCell = new TableCell(); mapCell.Text = FriendlyNames.GetMapName(mapname); TableCell playsCell = new TableCell(); playsCell.Text = (plays - wins).ToString(); TableCell winsCell = new TableCell(); winsCell.Text = wins.ToString(); TableRow row1 = new TableRow(); row1.Cells.Add(mapCell); row1.Cells.Add(winsCell); row1.Cells.Add(playsCell); row1.BackColor = System.Drawing.ColorTranslator.FromHtml("#D9F7FF"); Insane.Rows.Add(row1); Insane.Visible = true; mapname = ""; wins = -1; plays = -1; } else if (skill == 5) { TableCell mapCell = new TableCell(); mapCell.Text = FriendlyNames.GetMapName(mapname); TableCell playsCell = new TableCell(); playsCell.Text = (plays - wins).ToString(); TableCell winsCell = new TableCell(); winsCell.Text = wins.ToString(); TableRow row1 = new TableRow(); row1.Cells.Add(mapCell); row1.Cells.Add(winsCell); row1.Cells.Add(playsCell); row1.BackColor = System.Drawing.ColorTranslator.FromHtml("#D9F7FF"); Brutal.Rows.Add(row1); Brutal.Visible = true; mapname = ""; wins = -1; plays = -1; } } } } #endregion } else { Response.WriteFile("errors/no_steamid.htm"); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { #region Map Statistics ArrayList playCountArray = new ArrayList(); using (StreamReader sr = new StreamReader(@"E:\Ch1ckensCoop_Server\swarm\addons\sourcemod\SwarmStats\maps.swarmstats")) { int level = 0; int skill = 0; string mapname = ""; int playcountint = 0; string line; while ((line = sr.ReadLine()) != null) { if (line.Contains("{")) { level++; if (level == 1) { line = sr.ReadLine(); if (line.Contains("Easy")) { skill = 1; } else if (line.Contains("Normal")) { skill = 2; } else if (line.Contains("Hard")) { skill = 3; } else if (line.Contains("Insane")) { skill = 4; } else if (line.Contains("Brutal")) { skill = 5; } } } else if (line.Contains("}")) { level--; if (playcountint != 0 && mapname != "" && level == 2) { PlayCount pc1 = new PlayCount(); pc1.PlayCountInt = playcountint; pc1.MapName = FriendlyNames.GetCampaignName(mapname); if (pc1.MapName != "cancel_now") { playCountArray.Add(pc1); } playcountint = 0; } } if (level == 2) { string[] data = line.Split('"'); if (data.Length > 1) { mapname = data[1]; } } if (level == 4 && line.Contains("plays")) { string[] data = line.Split('"'); playcountint += Convert.ToInt32(data[3]); } } playCountArray.Add(new PlayCount(1, "z_null_map")); IComparer sortByMapNameComparer = new sortByMapNameClass(); playCountArray.Sort(sortByMapNameComparer); string previousmapname = ""; int playcount = 0; bool firstTime = true; ArrayList dupe = new ArrayList(playCountArray); playCountArray.Clear(); foreach (PlayCount pc in dupe) { if (firstTime) { previousmapname = pc.MapName; firstTime = false; } if (previousmapname != pc.MapName) { PlayCount pc2 = new PlayCount(); pc2.PlayCountInt = playcount; pc2.MapName = previousmapname; if (pc2.PlayCountInt != 0 && pc2.MapName != "" && pc2.MapName != "Jacob's Rest") { playCountArray.Add(pc2); } playcount = 0; previousmapname = pc.MapName; } playcount += pc.PlayCountInt; } ArrayList labels = new ArrayList(); ArrayList values = new ArrayList(); foreach (PlayCount pc in playCountArray) { labels.Add(pc.MapName); values.Add(pc.PlayCountInt); } float total = 0; foreach (int value in values) { total += value; } total -= 1; ArrayList valuesDupe = new ArrayList(values); values.Clear(); foreach (int value in valuesDupe) { values.Add(value / total); } string[] labelsArray = (string[])labels.ToArray(typeof(string)); float[] valuesArray = (float[])values.ToArray(typeof(float)); PieChart chart = new PieChart(600, 300); chart.SetData(valuesArray); chart.SetPieChartLabels(labelsArray); chart.SetTitle("Custom Map Statistics"); chart.SetDatasetColors(new string[] { "00B3E4" }); Image12.ImageUrl = chart.GetUrl() + "&chf=bg,s,65432100"; } #endregion #region Player Statistics string name = ""; int kills = 0; int points = 0; dtbl1 = new DataTable(); dtbl1.Columns.Add(" "); dtbl1.Columns.Add("Total Kills", Type.GetType("System.Int32")); dtbl1.Columns.Add("Points", Type.GetType("System.Int32")); dtbl1.Columns.Add(" "); //TODO: Highlight admins in red. try { using (StreamReader sr = new StreamReader(@"E:\Ch1ckensCoop_Server\swarm\addons\sourcemod\SwarmStats\players.swarmstats")) { int level = 0; string steamid = ""; String line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { string[] steamid_temp; if (!line.Contains("Players")) { if (line.Contains("{")) { level++; } else if (line.Contains("}")) { level--; if (name.Length > 0) { //HyperLink link1 = new HyperLink(); //link1.Text = name; string url = string.Format("Player.aspx?={0}", steamid); dtbl1.Rows.Add(name, kills, points, url); } name = ""; kills = 0; points = 0; } else if (line.Contains("STEAM_")) { //TableRow row1 = new TableRow(); steamid_temp = line.Split('"'); steamid = steamid_temp[1]; //Response.Write("'" + steamid_temp[1] + "'"); } else { string newline; if (line.Contains(@"""name""")) { newline = line.Replace(@"""name""", ""); newline = newline.Remove(0, newline.IndexOf('"') + 1); newline = newline.Remove(newline.Length - 1, 1); name = newline; } else if (line.Contains(@"""kills""")) { newline = line.Replace(@"""kills""", ""); newline = newline.Remove(0, newline.IndexOf('"') + 1); newline = newline.Remove(newline.Length - 1, 1); kills = Convert.ToInt32(float.Parse(newline)); } else if (line.Contains(@"""points""")) { newline = line.Replace(@"""points""", ""); newline = newline.Remove(0, newline.IndexOf('"') + 1); newline = newline.Remove(newline.Length - 1, 1); points = Convert.ToInt32(float.Parse(newline)); } } } } } Session["dtbl"] = dtbl1; dtbl1.DefaultView.Sort = "Points DESC"; GridView1.DataSource = dtbl1; GridView1.DataBind(); //GridView1.Sort("Points", SortDirection.Descending); /*DataTable ranktable = new DataTable(); * ranktable.Columns.Add("Rank", Type.GetType("System.Int32")); * foreach (DataRow row in dtbl1.Rows) * { * ranktable.Rows.Add(rank++); * } * GridView2.DataSource = ranktable; * GridView2.DataBind();*/ } catch { } #endregion /*#region Current Players * rcon = new SourceRcon(); * IPEndPoint point = new IPEndPoint(IPAddress.Parse("192.168.1.120"), 27015); * rcon.ConnectionSuccess += new BoolInfo(rcon_ConnectionSuccess); * rcon.Connect(point, "pwnappleftwlol"); #endregion*/ }