Skip to content

Latest commit

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SteamQueryNet

SteamQueryNet is a C# wrapper for Steam Server Queries UDP protocol. It is;

  • Light
  • Dependency free
  • Written in .net standard 2.0 so that it works with both .NET framework 4.6+ and core.

How to install ?

Check out SteamQueryNet on nuget.

How to use ?

SteamQueryNet comes with a single object that gives you access to all API's of the Steam protocol which are;

  • Server information (server name, capacity etc).
  • Concurrent players.
  • Server rules (friendlyfire, roundttime etc). Warning: currently does not work due to a protocol issue on steam server query API. Use could make use of ServerInfo.tags if the server admins are kind enough to put rules as tags in the field.

Creating an instance

To make use of the API's listed above, an instance of ServerQuery should be created.

stringserverIp="127.0.0.1";intserverPort=27015;IServerQueryserverQuery=newServerQuery(serverIp,serverPort);

or you can use string resolvers like below:

stringmyHostAndPort="127.0.0.1:27015";// ormyHostAndPort="127.0.0.1,27015";// ormyHostAndPort="localhost:27015";// ormyHostAndPort="localhost,27015";// ormyHostAndPort="steam://connect/127.0.0.1:27015";// ormyHostAndPort="steam://connect/localhost:27015";IServerQueryserverQuery=newServerQuery(myHostAndPort);

Also, it is possible to create ServerQuery object without connecting like below:

IServerQueryserverQuery=newServerQuery();serverQuery.Connect(host,port);

Note: Connect function overloads are similar to ServerQuery non-empty constructors.

Providing Custom UDPClient

You can provide custom UDP clients by implementing IUdpClient in SteamQueryNet.Interfaces namespace.

See the example below:

publicclassMyAmazingUdpClient:IUdpClient{publicboolIsConnected{get;}publicvoidClose(){// client implementation}publicvoidConnect(IPEndPointremoteIpEndpoint){// client implementation}publicvoidDispose(){// client implementation}publicTask<UdpReceiveResult>ReceiveAsync(){// client implementation}publicTask<int>SendAsync(byte[]datagram,intbytes){// client implementation}}// UsageIPEndpointremoteIpEndpoint=newIPEndPoint(IPAddress.Parse(remoteServerIp),remoteServerPort);IUdpClientmyUdpClient=newMyAmazingUdpClient();IServerQueryserverQuery=newServerQuery(myUdpClient,remoteIpEndpoint);

once its created functions below returns informations desired,

ServerInfo

ServerInfoserverInfo=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.

ServerInfoserverInfo=newServerQuery().Connect(host,port).GetServerInfo();

Todos

  • Enable CI

About

Steam Server Query API written in netstandard2.0

Topics

Resources

Stars

18 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages