GameStat.NET Reference

ServerInfo.QueryMaster Method (MasterType, MasterFilter, String, UInt16)

[This is preliminary documentation and subject to change.]

Creates a new instance of the ServerCollection class and queries a master server.

public static ServerCollection QueryMaster(
   MasterType type,
   MasterFilter filter,
   string host,
   ushort port
);

Parameters

type
One of the MasterType values.
filter
One or more of the MasterFilter values.
host
The hostname/ip to query.
port
The master server's query port.

Return Value

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

Remarks

If host is set to null, GameStat will try to guess it. If host can not be guessed, an ArgumentException will be thrown. If port is set to 0, GameStat will try to guess it. If port can not be guessed, an ArgumentException will be thrown.

Exceptions

Exception TypeCondition
SocketExceptionAn error occurred when attempting to access the master 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 master server.

Example

This example queries the Counter-Strike master server and writes the resulting information to the console.

[C#]
try {
   ServerCollection servers=ServerInfo.QueryMaster(MasterType.Counter-Strike,
      MasterFilter.NotFull|MasterFilter.NotEmpty|MasterFilter.NoPassword, null, 0);
   
   if(servers!=null) {
      foreach(Server s in servers)
         Console.WriteLine(s.Host+":"+s.Port.ToString());
   }
   else Console.WriteLine("Master server didn't return any servers.");
}
catch(Exception ex) {
   Console.Error.WriteLine("An Exception Occured!");
   Console.Error.WriteLine(ex.ToString());
}

See Also

ServerInfo Class | GameStat Namespace | ServerInfo.QueryMaster Overload List