Example #1
0
        /// <summary>
        /// Release resources being used by this object
        /// </summary>
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;

                Properties.Clear();
                Properties = null;

                Players.Clear();
                Players = null;

                Connection = null;

                if (queryClient != null)
                {
                    queryClient.Shutdown();
                    queryClient.QueryFinished -= new UDPServerQueryResponseHandler(HandleQueryFinished);
                    queryClient = null;
                }
            }
            else
            {
                throw new ObjectDisposedException("Server " + DisplayAddress);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new server instance
        /// </summary>
        /// <param name="endpoint"></param>
        public Server(ServerConnection connection, int version, IPAddress address, string cdKey, GeoIP geoip, int heartbeatCode, bool enableStatLogging, XMPMS.Net.OperatingSystem operatingSystem, string locale, int matchId)
        {
            this.Connection        = connection;
            this.Local             = connection != null;
            this.Version           = version;
            this.Address           = address;
            this.CDKey             = cdKey;
            this.HeartbeatCode     = heartbeatCode;
            this.EnableStatLogging = enableStatLogging;
            this.OperatingSystem   = EnumInfo.Description(operatingSystem);
            this.Locale            = locale;
            this.matchId           = matchId;

            this.Name = "< Waiting gamestate... >";
            this.Port = 0;

            this.LastUpdate = DateTime.Now;
            this.Country    = geoip.Match(address).Country;

            this.queryClient = new UDPServerQueryClient();
            this.queryClient.QueryFinished += new UDPServerQueryResponseHandler(HandleQueryFinished);

            Properties = new Dictionary <string, string>();
            Properties.Add("servermode", "dedicated");

            Players = new List <Player>();
        }
Example #3
0
        /// <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;
            }
        }