SteamQuerynet es un envoltorio C# para el protocolo UDP de consultas de servidor Steam. Es;
Echa un vistazo a SteamQuerynet en Nuget.
SteamQuerynet viene con un solo objeto que le brinda acceso a todas las API del Protocolo de Steam que son;
Para utilizar la API enumerada anteriormente, se debe crear una instancia de ServerQuery .
string serverIp = "127.0.0.1" ;
int serverPort = 27015 ;
IServerQuery serverQuery = new ServerQuery ( serverIp , serverPort ) ;O puede usar resolvers de cadena como a continuación:
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 ) ; Además, es posible crear un objeto ServerQuery sin conectarse como a continuación:
IServerQuery serverQuery = new ServerQuery ( ) ;
serverQuery . Connect ( host , port ) ; Nota : Las sobrecargas de la función Connect son similares a los constructores no vacíos ServerQuery .
Puede proporcionar clientes UDP personalizados implementando IUdpClient en el espacio de nombres de SteamQueryNet.Interfaces .
Vea el ejemplo a continuación:
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 ) ;Una vez que sus funciones creadas a continuación devuelven la información deseada,
Servidor
ServerInfo serverInfo = serverQuery . GetServerInfo ( ) ;Jugadores
List < Player > players = serverQuery . GetPlayers ( ) ;Normas
List < Rule > rules = serverQuery . GetRules ( ) ; Si bien no se recomienda , puede encadenar la función Connect o constructores no vacíos para obtener información en una sola línea.
ServerInfo serverInfo = new ServerQuery ( )
. Connect ( host , port )
. GetServerInfo ( ) ;