SteamQueryNet is a C# wrapper for Steam Server Queries UDP protocol. It is;
Check out SteamQueryNet on nuget.
SteamQueryNet comes with a single object that gives you access to all API's of the Steam protocol which are;
To make use of the API's listed above, an instance of ServerQuery should be created.
string serverIp = "127.0.0.1";
int serverPort = 27015;
IServerQuery serverQuery = new ServerQuery(serverIp, serverPort);or you can use string resolvers like below:
string myHostAndPort = "127.0.0.1:27015";
// or
myHostAndPort = "127.0.0.1,27015";
// or
myHostAndPort = "localhost:27015";
// or
myHostAndPort = "localhost,27015";
// or
myHostAndPort = "steam://connect/127.0.0.1:27015";
// or
myHostAndPort = "steam://connect/localhost:27015";
IServerQuery serverQuery = new ServerQuery(myHostAndPort);Also, it is possible to create ServerQuery object without connecting like below:
IServerQuery serverQuery = new ServerQuery();
serverQuery.Connect(host, port);Note: Connect function overloads are similar to ServerQuery non-empty constructors.
You can provide custom UDP clients by implementing IUdpClient in SteamQueryNet.Interfaces namespace.
See the example below:
public class MyAmazingUdpClient : IUdpClient
{
public bool IsConnected { get; }
public void Close()
{
// client implementation
}
public void Connect(IPEndPoint remoteIpEndpoint)
{
// client implementation
}
public void Dispose()
{
// client implementation
}
public Task<UdpReceiveResult> ReceiveAsync()
{
// client implementation
}
public Task<int> SendAsync(byte[] datagram, int bytes)
{
// client implementation
}
}
// Usage
IPEndpoint remoteIpEndpoint = new IPEndPoint(IPAddress.Parse(remoteServerIp), remoteServerPort);
IUdpClient myUdpClient = new MyAmazingUdpClient();
IServerQuery serverQuery = new ServerQuery(myUdpClient, remoteIpEndpoint);once its created functions below returns informations desired,
ServerInfo
ServerInfo serverInfo = serverQuery.GetServerInfo();Players
List<Player> players = serverQuery.GetPlayers();Rules
List<Rule> rules = serverQuery.GetRules();While it is not encouraged, you can chain Connect function or Non-empty Constructors to get information in a single line.
ServerInfo serverInfo = new ServerQuery()
.Connect(host, port)
.GetServerInfo();