Esempio n. 1
0
        public List<ServerInformation> EnumerateServers(float discoveryTime)
        {
            List<ServerInformation> serverList = new List<ServerInformation>();

            // Discover local servers.
            propertyBag.netClient.DiscoverLocalServers(5565);
            NetBuffer msgBuffer = propertyBag.netClient.CreateBuffer();
            NetMessageType msgType;
            float timeTaken = 0;
            while (timeTaken < discoveryTime)
            {
                while (propertyBag.netClient.ReadMessage(msgBuffer, out msgType))
                {
                    if (msgType == NetMessageType.ServerDiscovered)
                    {
                        bool serverFound = false;
                        ServerInformation serverInfo = new ServerInformation(msgBuffer);
                        foreach (ServerInformation si in serverList)
                            if (si.Equals(serverInfo))
                                serverFound = true;
                        if (!serverFound)
                            serverList.Add(serverInfo);
                    }
                }

                timeTaken += 0.1f;
                Thread.Sleep(100);
            }

            // Discover remote servers.
            try
            {
                string publicList = HttpRequest.Get("http://apps.keithholman.net/plain", null);
                foreach (string s in publicList.Split("\r\n".ToCharArray()))
                {
                    string[] args = s.Split(";".ToCharArray());
                    if (args.Length == 6)
                    {
                        IPAddress serverIp;
                        if (IPAddress.TryParse(args[1], out serverIp) && args[2] == "INFINIMINER")
                        {
                            ServerInformation serverInfo = new ServerInformation(serverIp, args[0], args[5], args[3], args[4]);
                            serverList.Add(serverInfo);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return serverList;
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            ServerInformation serverInfo = obj as ServerInformation;

            if (!ipEndPoint.Equals(serverInfo.ipEndPoint))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        public List <ServerInformation> EnumerateServers(float discoveryTime)
        {
            List <ServerInformation> serverList = new List <ServerInformation>();

            // Discover local servers.
            propertyBag.netClient.DiscoverLocalPeers(5565);
            //propertyBag.netClient.Connect(serverEndPoint, connectBuffer); //TO DO
            NetOutgoingMessage msgBuffer = propertyBag.netClient.CreateMessage();
            NetIncomingMessage msgType;
            float timeTaken = 0;

            while (timeTaken < discoveryTime)
            {
                while ((msgType = propertyBag.netClient.ReadMessage()) != null)
                {
                    if (msgType.MessageType == NetIncomingMessageType.DiscoveryResponse)
                    {
                        bool serverFound             = false;
                        ServerInformation serverInfo = new ServerInformation(msgBuffer);
                        foreach (ServerInformation si in serverList)
                        {
                            if (si.Equals(serverInfo))
                            {
                                serverFound = true;
                            }
                        }
                        if (!serverFound)
                        {
                            serverList.Add(serverInfo);
                        }
                    }
                }

                timeTaken += 0.1f;
                Thread.Sleep(100);
            }

            // Discover remote servers.
            try
            {
                string publicList = HttpRequest.Get("http://apps.keithholman.net/plain", null);
                foreach (string s in publicList.Split("\r\n".ToCharArray()))
                {
                    string[] args = s.Split(";".ToCharArray());
                    if (args.Length == 6)
                    {
                        IPAddress serverIp;
                        if (IPAddress.TryParse(args[1], out serverIp) && args[2] == "INFINIMINER")
                        {
                            ServerInformation serverInfo = new ServerInformation(serverIp, args[0], args[5], args[3], args[4]);
                            serverList.Add(serverInfo);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(serverList);
        }