SteamQueryNet
1.0.0
SteamQueryNetは、SteamサーバークエリUDPプロトコルのC#ラッパーです。それは;
NugetでSteamQueryNetをご覧ください。
SteamQueryNetには、SteamプロトコルのすべてのAPIにアクセスできる単一のオブジェクトが付属しています。
上記のAPIを使用するには、 ServerQueryのインスタンスを作成する必要があります。
string serverIp = "127.0.0.1" ;
int serverPort = 27015 ;
IServerQuery serverQuery = new ServerQuery ( serverIp , serverPort ) ;または、以下のような文字列リゾルバーを使用できます。
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 ) ;また、以下のように接続せずにServerQueryオブジェクトを作成することも可能です。
IServerQuery serverQuery = new ServerQuery ( ) ;
serverQuery . Connect ( host , port ) ;注: Connect関数の過負荷は、 ServerQuery非空白のコンストラクターに似ています。
SteamQueryNet.Interfacesの名前空間にIUdpClientを実装することにより、カスタムUDPクライアントを提供できます。
以下の例を参照してください。
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 ) ;以下に作成された関数が必要な情報を返すと、
serverInfo
ServerInfo serverInfo = serverQuery . GetServerInfo ( ) ;プレイヤー
List < Player > players = serverQuery . GetPlayers ( ) ;ルール
List < Rule > rules = serverQuery . GetRules ( ) ;奨励されていませんが、 Connect関数または空でないコンストラクターをチェーンして、単一の行で情報を取得できます。
ServerInfo serverInfo = new ServerQuery ( )
. Connect ( host , port )
. GetServerInfo ( ) ;