/// <summary> /// Got a response to a UDP server query /// </summary> /// <param name="data"></param> protected virtual void QueryResponseSuccess(UDPServerQueryClient.UDPServerQueryType queryType, UDPPacket data) { // The packet type should be the first byte byte packetType = data.PopByte(); // Try to update this server with data from the query response Update(packetType, data); // Notify the connection that the query was successful if (Connection != null) { Connection.HandleQueryResponse((UDPServerQueryClient.UDPServerQueryType)packetType); } switch ((UDPServerQueryClient.UDPServerQueryType)packetType) { case UDPServerQueryClient.UDPServerQueryType.Basic: queryClient.BeginQuery(Protocol.SERVERQUERY_TIMEOUT, UDPServerQueryClient.UDPServerQueryType.GameInfo, Address, QueryPort); break; case UDPServerQueryClient.UDPServerQueryType.GameInfo: queryClient.BeginQuery(Protocol.SERVERQUERY_TIMEOUT, UDPServerQueryClient.UDPServerQueryType.PlayerInfo, Address, QueryPort); break; case UDPServerQueryClient.UDPServerQueryType.PlayerInfo: break; } }
/// <summary> /// Create a new query state /// </summary> /// <param name="queryThreadProc">Query thread procedure to call</param> /// <param name="queryTimeoutCallback">Query timeout callback procedure</param> /// <param name="queryType">Type of query to execute</param> internal UDPServerQueryState(ParameterizedThreadStart queryThreadProc, TimerCallback queryTimeoutCallback, UDPServerQueryClient.UDPServerQueryType queryType) { QueryType = queryType; QueryThread = new Thread(queryThreadProc); QueryClient = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); QueryTimer = new Timer(queryTimeoutCallback, this, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// The query response timed out, close the connection since non-queryable servers are probably not accessible /// </summary> /// <param name="queryType">Query Type which timed out</param> protected virtual void QueryResponseTimeout(UDPServerQueryClient.UDPServerQueryType queryType) { if (queryType == UDPServerQueryClient.UDPServerQueryType.Basic) { MasterServer.Log("[{0}] Timeout contacting queryport on {1}. Type={2}", DisplayAddress, QueryPort, queryType); Shutdown(); OnConnectionError(); } }
/// <summary> /// Handler function for when the udp server query returns a response /// </summary> /// <param name="sender">Server query object</param> /// <param name="response">Response type</param> /// <param name="payload">Response packet (if successful)</param> void HandleQueryFinished(UDPServerQueryClient sender, UDPServerQueryClient.UDPServerQueryResponse response, UDPServerQueryClient.UDPServerQueryType queryType, UDPPacket payload) { switch (response) { case UDPServerQueryClient.UDPServerQueryResponse.Success: QueryResponseSuccess(queryType, payload); break; case UDPServerQueryClient.UDPServerQueryResponse.Error: QueryResponseError(queryType); break; case UDPServerQueryClient.UDPServerQueryResponse.Timeout: QueryResponseTimeout(queryType); break; default: break; } }
/// <summary> /// Callback from the Server object when a query response was received /// </summary> /// <param name="queryType">Type of query that was received</param> public virtual void HandleQueryResponse(UDPServerQueryClient.UDPServerQueryType queryType) { State = ConnectionState.Established; }