Code Monkey home page Code Monkey logo

steamquerynet's Introduction

SteamQueryNet

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

  • Light
  • Dependency free
  • Written in .NET 6

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.

IServerQuery serverQuery = new ServerQuery();
serverQuery.Connect(host, port);

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);

Providing Custom UDPClient

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();

Todos

  • Enable CI

steamquerynet's People

Contributors

cyilcode avatar razaqq avatar asche00 avatar restoremonarchy avatar shanejs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.