SteamQueryNet est un C # Wrapper pour Steam Server Queries Protocol UDP. C'est;
Découvrez SteamQueryNet sur NuGet.
SteamQueryNet est livré avec un seul objet qui vous donne accès à toutes les API du protocole Steam qui sont;
Pour utiliser les API répertoriées ci-dessus, une instance de ServerQuery doit être créée.
string serverIp = "127.0.0.1" ;
int serverPort = 27015 ;
IServerQuery serverQuery = new ServerQuery ( serverIp , serverPort ) ;ou vous pouvez utiliser des résolveurs de chaînes comme ci-dessous:
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 ) ; Il est également possible de créer un objet ServerQuery sans se connecter comme ci-dessous:
IServerQuery serverQuery = new ServerQuery ( ) ;
serverQuery . Connect ( host , port ) ; Remarque : les surcharges de fonction Connect sont similaires aux constructeurs non vides ServerQuery .
Vous pouvez fournir des clients UDP personnalisés en implémentant IUdpClient dans SteamQueryNet.Interfaces Espace.
Voir l'exemple ci-dessous:
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 ) ;Une fois que ses fonctions créées ci-dessous renvoient les informations souhaitées,
ServerInfo
ServerInfo serverInfo = serverQuery . GetServerInfo ( ) ;Joueurs
List < Player > players = serverQuery . GetPlayers ( ) ;Règles
List < Rule > rules = serverQuery . GetRules ( ) ; Bien qu'il ne soit pas encouragé , vous pouvez enchaîner la fonction Connect ou des constructeurs non vides pour obtenir des informations en une seule ligne.
ServerInfo serverInfo = new ServerQuery ( )
. Connect ( host , port )
. GetServerInfo ( ) ;