O SteamQueryNet é um wrapper C# para consultas de servidor Steam Protocolo UDP. Isso é;
Confira SteamQueryNet no NUGET.
O SteamQueryNet vem com um único objeto que fornece acesso a todas as APIs do protocolo Steam que são;
Para fazer uso da API listada acima, uma instância do ServerQuery deve ser criada.
string serverIp = "127.0.0.1" ;
int serverPort = 27015 ;
IServerQuery serverQuery = new ServerQuery ( serverIp , serverPort ) ;Ou você pode usar resolvedores de string como abaixo:
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 ) ; Além disso, é possível criar um objeto ServerQuery sem se conectar como abaixo:
IServerQuery serverQuery = new ServerQuery ( ) ;
serverQuery . Connect ( host , port ) ; Nota : As sobrecargas de função Connect são semelhantes aos construtores não vazios ServerQuery .
Você pode fornecer clientes UDP personalizados implementando IUdpClient no espaço de nome SteamQueryNet.Interfaces .
Veja o exemplo abaixo:
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 ) ;Uma vez criado, as funções abaixo retornam as informações desejadas,
ServerInfo
ServerInfo serverInfo = serverQuery . GetServerInfo ( ) ;Jogadores
List < Player > players = serverQuery . GetPlayers ( ) ;Regras
List < Rule > rules = serverQuery . GetRules ( ) ; Embora não seja incentivado , você pode encadear funções Connect ou construtores não vazios para obter informações em uma única linha.
ServerInfo serverInfo = new ServerQuery ( )
. Connect ( host , port )
. GetServerInfo ( ) ;