SteamQueryNet
1.0.0
Steamquerynet是用於Steam Server查詢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 ( ) ;