-
Notifications
You must be signed in to change notification settings - Fork 1
Server Queries
Yunus Emre edited this page May 1, 2025
·
2 revisions
All properties and methods are XML documented.
All asynchronous methods accept the cancellationToken parameter.
Provide an IP address via either constructor parameters or assign manually.
Once you change the IpEndPoint property, the connection will be reestablished automatically. It's not required for you to call Initialize(), Reestablish() or Close() method manually;
using var server = new GameServer("localhost:27015");
using var server = new GameServer();
server.IpEndPoint = IpHelper.CreateIpEndPoint("localhost", 27015);Changes to SendTimeout and ReceiveTimeout take effect immediately. Likewise, you are not required to manually reestablish the connection.
Default timeout is both 30 seconds for sending and receiving.
using var server = new GameServer("localhost:27015")
{
SendTimeout = TimeSpan.FromSeconds(5.0d),
ReceiveTimeout = TimeSpan.FromSeconds(5.0d)
};using var server = new GameServer("localhost:27015");
var players = await server.GetPlayersAsync();
foreach (var player in players)
{
Console.WriteLine($"[{player.Index}] [{player.Duration}] {player.Score} - {player.Name}");
}Default value of the parameter is SteamQueryA2SQuery.All.
using var server = new GameServer("127.0.0.1:27015");
await server.PerformQueryAsync(SteamQueryA2SQuery.Information | SteamQueryA2SQuery.Rules);
Console.WriteLine($"Server Name: {server.Information.ServerName}"); // Server Name: [TR] AnneTokatlayan Pro Public
Console.WriteLine($"Players: {server.Players.Count}/{server.Information.MaxPlayers}"); // Output will be like "Players: 0/31" because you did not perform the Players query.
Console.WriteLine($"Rule Count: {server.Rules.Count}"); // Rule Count: 420using var server = new GameServer("localhost:27015");
var information = server.GetInformation();
Console.WriteLine($"Server Name: {information.ServerName}"); // Server Name: [TR] AnneTokatlayan Pro PublicConsole.OutputEncoding = Encoding.UTF8;
// Pick a server from: https://www.gametracker.com/search/cs/
using var server = new GameServer("localhost", 27015);
await server.PerformQueryAsync();
var information = server.Information;
Console.WriteLine($"Protocol: {information.ProtocolVersion}");
Console.WriteLine($"Server Name: {information.ServerName}");
Console.WriteLine($"Folder: {information.Folder}");
Console.WriteLine($"Game Name: {information.GameName}");
Console.WriteLine($"Players: {information.OnlinePlayers}/{information.MaxPlayers}");
Console.WriteLine($"Bots: {information.Bots}");
Console.WriteLine($"Server Type: {information.ServerType}");
Console.WriteLine($"Environment: {information.Environment}");
Console.WriteLine($"Visible: {information.Visible}");
Console.WriteLine($"VAC Secured: {information.VacSecured}");
Console.WriteLine($"Version: {information.Version}");
if (information.IsHalfLifeMod.HasValue)
{
Console.WriteLine();
Console.WriteLine($"Is Half-Life Mod: {information.IsHalfLifeMod}");
if (information.IsHalfLifeMod == true)
{
Console.WriteLine($"Mod Link: {information.HalfLifeMod.Link}");
Console.WriteLine($"Mod Download Link: {information.HalfLifeMod.DownloadLink}");
Console.WriteLine($"Mod Version: {information.HalfLifeMod.Version}");
Console.WriteLine($"Size in Bytes: {information.HalfLifeMod.SizeInBytes}");
Console.WriteLine($"Is Multiplayer Only: {information.HalfLifeMod.IsMultiplayerOnly}");
Console.WriteLine($"Has Own DLL: {information.HalfLifeMod.HasOwnDll}");
}
}
if (information.ExtraDataFlag.HasValue)
{
Console.WriteLine();
if (information.Port.HasValue)
{
Console.WriteLine($"Port: {information.Port.Value}");
}
if (information.SteamId.HasValue)
{
Console.WriteLine($"SteamID: {information.SteamId.Value}");
}
if (information.GameId.HasValue)
{
Console.WriteLine($"Game ID: {information.GameId.Value}");
}
if (information.SourceTvPort.HasValue)
{
Console.WriteLine($"SourceTV Port: {information.SourceTvPort.Value}");
}
if (!string.IsNullOrEmpty(information.SourceTvName))
{
Console.WriteLine($"SourceTV Name: {information.SourceTvName}");
}
if (!string.IsNullOrEmpty(information.Keywords))
{
Console.WriteLine($"Keywords: {information.Keywords}");
}
}
Console.WriteLine();
foreach (var player in server.Players)
{
Console.WriteLine($"[{player.Index}] [{player.Duration}] {player.Score} - {player.Name}");
}
Console.WriteLine();
foreach (var rule in server.Rules)
{
Console.WriteLine($"{rule.Name} = {rule.Value}");
}