GameStat.NET Reference

ServerInfo.Query Method (GameType, String, UInt16)

[This is preliminary documentation and subject to change.]

Creates a new instance of the ServerInfo class and queries a server.

public static ServerInfo Query(
   GameType type,
   string host,
   ushort port
);

Parameters

type
One of the GameType values.
host
The hostname/ip to query.
port
The game server's query port. This will likely be different from the game port.

Return Value

A new ServerInfo class initialized with server information, or null if the server didn't return any information.

Remarks

If port is set to 0, GameStat will try to guess it. If type is a generic protocol and port can not be guessed, an ArgumentException will be thrown.

Exceptions

Exception TypeCondition
SocketExceptionAn error occurred when attempting to access the server.
ArgumentOutOfRangeExceptionThe given type is not recognized by GameStat.
ArgumentExceptionAn invalid argument was given.
NotImplementedExceptionSupport for the given type is not implemented yet.
CorruptPacketExceptionA currupt or unknown packet was recieved from the server.

Example

This example queries a QuakeWorld server and writes the resulting information to the console.

[C#]
try {
   ServerInfo info=ServerInfo.Query(GameType.QuakeWorld, "quake.sol.net", 27511);
   if(info!=null) {
      Console.WriteLine("Host: "+info.Host);
      Console.WriteLine("Mod: "+info.Mod);
      Console.WriteLine("Map: "+info.Map);
      Console.WriteLine("Players: {0}/{1}", info.NumPlayers, info.MaxPlayers);
   }
   else Console.WriteLine("Server didn't return any info.");
}
catch(Exception ex) {
   Console.Error.WriteLine("An Exception Occured!");
   Console.Error.WriteLine(ex.ToString());
}

See Also

ServerInfo Class | GameStat Namespace | ServerInfo.Query Overload List