Example #1
0
        public bool ConnectToServer(List <ServerListEntry> publicServers, string hash)
        {
            if (String.IsNullOrEmpty(hash))
            {
                return(false);
            }

            ClientStartData data = null;

            for (int i = 0; i < publicServers.Count; i++)
            {
                ServerListEntry entry = publicServers[i];
                if (entry.Hash != hash)
                {
                    continue;
                }

                data = new ClientStartData(Session.Username, entry.Mppass,
                                           entry.IPAddress, entry.Port, entry.Name);
                Client.Start(data, true, ref ShouldExit);
                return(true);
            }

            // Fallback to private server handling
            try {
                data = Session.GetConnectInfo(hash);
            } catch (WebException ex) {
                ErrorHandler.LogError("retrieving server information", ex);
                return(false);
            } catch (ArgumentOutOfRangeException) {
                return(false);
            }
            Client.Start(data, true, ref ShouldExit);
            return(true);
        }
Example #2
0
        public bool ConnectToServer(List <ServerListEntry> publicServers, string hash)
        {
            if (String.IsNullOrEmpty(hash))
            {
                return(false);
            }

            ClientStartData data = null;

            for (int i = 0; i < publicServers.Count; i++)
            {
                ServerListEntry entry = publicServers[i];
                if (entry.Hash != hash)
                {
                    continue;
                }

                data = new ClientStartData(Username, entry.Mppass,
                                           entry.IPAddress, entry.Port, entry.Name);
                Client.Start(data, true, ref ShouldExit);
                return(true);
            }

            // Fallback to private server handling
            try {
                // TODO: Rewrite to be async
                FetchServerTask task = new FetchServerTask(Username, hash);
                task.RunAsync(this);

                while (!task.Completed)
                {
                    task.Tick(); Thread.Sleep(10);
                }
                if (task.WebEx != null)
                {
                    throw task.WebEx;
                }

                data = task.Info;
            } catch (WebException ex) {
                ErrorHandler.LogError("retrieving server information", ex);
                return(false);
            } catch (ArgumentOutOfRangeException) {
                return(false);
            }
            Client.Start(data, true, ref ShouldExit);
            return(true);
        }