private async void kryptonTextBox2_TextChanged(object sender, EventArgs e) { kryptonDataGridView3.Rows.Clear(); await Task.Delay(500); if (filterText != kryptonTextBox2.Text) { Uri apiLOB = new Uri(@"https://aoe2.net/api/leaderboard?game=aoe2de&leaderboard_id=3&start=1&search=" + kryptonTextBox2.Text); string jsonLOBBIES = await DownloadStringAsync(apiLOB); //MessageBox.Show(jsonLOBBIES.Substring(0, 8)); var ldb = QueryPlayer.FromJson(jsonLOBBIES); int i = 1; foreach (var l in ldb.Leaderboard) { i++; LinkLabel ln = new LinkLabel(); Button btn = new Button(); ln.Text = "View"; ln.Name = "view" + i.ToString(); btn.Name = "btn" + i.ToString(); btn.Text = "Join"; kryptonDataGridView3.Rows.Add(l.Rank, l.Name, l.Rating, l.Games, "View", "View", @"https://www.ageofempires.com/stats/?profileId=" + l.ProfileId + @"&game=age2", @"http://steamcommunity.com/profiles/" + l.SteamId); } } RemoveDuplicate(kryptonDataGridView3); if (kryptonTextBox2.Text == null) { kryptonDataGridView3.Rows.Clear(); } }
/// <summary> /// Query server informations. /// </summary> /// <param name="gameServerIP">The gameserver host ip.</param> /// <param name="gameServerPort">The gameserver port.</param> /// <returns></returns> public EmbedBuilder Query(string gameServerIP, int gameServerPort) { Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); client.Connect(IPAddress.Parse(gameServerIP), gameServerPort); byte[] packet_send = new byte[16]; byte[] cmd = Encoding.ASCII.GetBytes("getstatus"); Buffer.BlockCopy(PACKET_HEADER, 0, packet_send, 0, PACKET_HEADER.Length); Buffer.BlockCopy(cmd, 0, packet_send, PACKET_HEADER.Length, cmd.Length); StringBuilder response = new StringBuilder(); byte[] bufferRecv = new byte[65565]; _ = new IPEndPoint(IPAddress.Parse(gameServerIP), 0); client.Send(packet_send, SocketFlags.None); do { int bytesReceived = client.Receive(bufferRecv); response.Append(Encoding.ASCII.GetString(bufferRecv, 0, bytesReceived)); }while (client.Available > 0); string[] raw = response.ToString().Split("\n"); string rawInfo = raw[1]; string[] temp = rawInfo.Split("\\"); for (int i = 1; i < temp.Length; i += 2) { Info.Add(temp[i], Regex.Replace(temp[i + 1], "(\\^)([0-9])", "")); } for (int i = 2; i < raw.Length; i++) { string[] rawPlayer = raw[i].Split(" "); string name = ""; if (rawPlayer.Length < 2) { continue; } for (int z = 2; z < rawPlayer.Length; z++) { if (z != rawPlayer.Length) { name += rawPlayer[z] + " "; } else { name += rawPlayer[z]; } } QueryPlayer player = new QueryPlayer(rawPlayer[1], rawPlayer[0], name.Replace("\"", "")); Players.Add(player); } EmbedBuilder em = new EmbedBuilder { Title = Info["sv_hostname"].ToString(), Color = new Color(164, 22, 248), }; em.AddField("Map", Info["mapname"].ToString(), false); string playerDetails = "No players Online"; if (Players.Count > 0) { playerDetails = ""; foreach (QueryPlayer p in Players) { playerDetails += p.nickname + "\n"; } } em.AddField("Players", playerDetails, false); em.Build(); return(em); }