public A2S_PLAYER PlayerListPoll() { //First, request the challenge. var client = GetConn(); byte[] req = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x55, 0xFF, 0xFF, 0xFF, 0xFF }; //Request challenge byte[] chal = ServerConnector.GetData(ref client, req); //Swap challenge results and request again req[5] = chal[5]; req[6] = chal[6]; req[7] = chal[7]; req[8] = chal[8]; byte[] results = ServerConnector.GetData(ref client, req); //Results contains the list return(A2S_PLAYER.Read(results)); }
public async Task <IActionResult> GetServerStats() { var rconStatus = await RunRCON(""); if (rconStatus == Status.ONLINE) { try { IPEndPoint ip = new IPEndPoint(Dns.GetHostAddresses("arks-zoo.xyz")[0], 27015); A2S_INFO a2S_INFO = new A2S_INFO(ip); A2S_PLAYER a2S_PLAYER = new A2S_PLAYER(ip); if (a2S_INFO.Players > 0) { ArrayList playerStats = new ArrayList(); playerStats.Add(a2S_INFO.Players); playerStats.Add(a2S_INFO.MaxPlayers); playerStats.Add(a2S_PLAYER.Players); return(Ok(playerStats)); } else { return(NoContent()); } } catch (SocketException ex) { Debug.WriteLine(ex.ToString()); return(NoContent()); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return(NoContent()); } } else { return(StatusCode(StatusCodes.Status404NotFound)); } }
public async Task GetStatus([Remainder] string args = null) { foreach (var server in servers) { var embed = new EmbedBuilder(); embed.Title = server.Name; embed.WithColor(new Color(0, 255, 0)); try { var ip = Dns.GetHostAddresses(server.Address).FirstOrDefault(); var endPoint = new IPEndPoint(ip, server.Port); var q = new A2S_INFO(endPoint); var players = new A2S_PLAYER(endPoint); var playerString = new StringBuilder(); foreach (var player in players.Players) { playerString.AppendLine(player.Name); } if (players.Players.Count() == 0) { playerString.AppendLine("There are no players."); } embed.AddField("Map", q.Map); embed.AddField("Players", $"{q.Players}/{q.MaxPlayers}"); embed.AddField("Player List", playerString.ToString()); } catch (Exception e) { embed.WithColor(new Color(255, 0, 0)); embed.Description = "Server is not responding."; } _ = ReplyAsync(null, false, embed.Build()); } }