Example #1
0
        public async Task <ArgumentHandleResult> ProgressRaceOnlineJoin(NameValueCollection p)
        {
            /* required arguments */
            var ip                = p.Get(@"ip");
            var httpPort          = FlexibleParser.TryParseInt(p.Get(@"httpPort"));
            var password          = p.Get(@"plainPassword");
            var encryptedPassword = p.Get(@"password");

            if (string.IsNullOrWhiteSpace(ip))
            {
                throw new InformativeException("IP is missing");
            }

            if (!httpPort.HasValue)
            {
                throw new InformativeException("HTTP port is missing or is in invalid format");
            }

            OnlineManager.EnsureInitialized();

            if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword))
            {
                password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword);
            }

            var list    = OnlineManager.Instance.List;
            var source  = new FakeSource(ip, httpPort.Value);
            var wrapper = new OnlineSourceWrapper(list, source);

            ServerEntry server;

            using (var waiting = new WaitingDialog()) {
                waiting.Report(ControlsStrings.Common_Loading);

                await wrapper.EnsureLoadedAsync();

                server = list.GetByIdOrDefault(source.Id);
                if (server == null)
                {
                    throw new Exception(@"Unexpected");
                }
            }

            if (password != null)
            {
                server.Password = password;
            }

            var content = new OnlineServer(server)
            {
                Margin  = new Thickness(0, 0, 0, -43),
                ToolBar = { FitWidth = true },

                // Values taken from ModernDialog.xaml
                // TODO: Extract them to some style?
                Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) }
            };

            content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);

            var dlg = new ModernDialog {
                ShowTitle          = false,
                Content            = content,
                MinHeight          = 400,
                MinWidth           = 450,
                MaxHeight          = 99999,
                MaxWidth           = 700,
                Padding            = new Thickness(0),
                ButtonsMargin      = new Thickness(8),
                SizeToContent      = SizeToContent.Manual,
                ResizeMode         = ResizeMode.CanResizeWithGrip,
                LocationAndSizeKey = @".OnlineServerDialog"
            };

            dlg.SetBinding(Window.TitleProperty, new Binding {
                Path   = new PropertyPath(nameof(server.DisplayName)),
                Source = server
            });

            dlg.ShowDialog();
            await wrapper.ReloadAsync(true);

            return(ArgumentHandleResult.Successful);
        }
Example #2
0
        public static async Task JoinInvitation([NotNull] string ip, int port, [CanBeNull] string password)
        {
            OnlineManager.EnsureInitialized();

            var list    = OnlineManager.Instance.List;
            var source  = new FakeSource(ip, port);
            var wrapper = new OnlineSourceWrapper(list, source);

            ServerEntry server;

            using (var waiting = new WaitingDialog()) {
                waiting.Report(ControlsStrings.Common_Loading);

                await wrapper.EnsureLoadedAsync();

                server = list.GetByIdOrDefault(source.Id);
                if (server == null)
                {
                    throw new Exception(@"Unexpected");
                }
            }

            if (password != null)
            {
                server.Password = password;
            }

            var content = new OnlineServer(server)
            {
                Margin  = new Thickness(0, 0, 0, -38),
                ToolBar = { FitWidth = true },

                // Values taken from ModernDialog.xaml
                // TODO: Extract them to some style?
                Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) }
            };

            content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);

            var dlg = new ModernDialog {
                ShowTitle          = false,
                Content            = content,
                MinHeight          = 400,
                MinWidth           = 450,
                MaxHeight          = 99999,
                MaxWidth           = 700,
                Padding            = new Thickness(0),
                ButtonsMargin      = new Thickness(8),
                SizeToContent      = SizeToContent.Manual,
                ResizeMode         = ResizeMode.CanResizeWithGrip,
                LocationAndSizeKey = @".OnlineServerDialog"
            };

            dlg.SetBinding(Window.TitleProperty, new Binding {
                Path   = new PropertyPath(nameof(server.DisplayName)),
                Source = server
            });

            dlg.ShowDialog();
            await wrapper.ReloadAsync(true);
        }
Example #3
0
        public static async Task JoinInvitationNoUI([NotNull] string ip, int port, [CanBeNull] string password)
        {
            OnlineManager.EnsureInitialized();

            var list       = OnlineManager.Instance.List;
            var source     = new FakeSource(ip, port);
            var wrapper    = new OnlineSourceWrapper(list, source);
            var drive_opts = SettingsHolder.Drive;

            ServerEntry server;

            Logging.Write("Going through server list ...");
            using (var waiting = new WaitingDialog())
            {
                waiting.Report(ControlsStrings.Common_Loading);

                await wrapper.EnsureLoadedAsync();

                server = list.GetByIdOrDefault(source.Id);
                if (server == null)
                {
                    throw new Exception(@"Unexpected");
                }
            }

            Logging.Write("Updating server infos ...");
            await server.Update(ServerEntry.UpdateMode.Full, false, true);

            if (password != null)
            {
                server.Password = password;
            }

            //Change name here
            //We are going to use the server entry team name to match client local name.
            //Then we change the client online name to match the name required by the server.
            IReadOnlyList <ServerEntry.CurrentDriver> drivers = server.CurrentDrivers;

            Logging.Write("Going through all drivers ...");

            if (drivers == null)
            {
                throw new Exception(@"Unexpected");
            }
            foreach (var driver in drivers)
            {
                if (driver.Team == drive_opts.PlayerName)
                {
                    drive_opts.PlayerNameOnline = driver.Name;
                    break;
                }
            }

            Logging.Write("Joining server ....");
            await server.JoinCommand.ExecuteAsync(null);

            Logging.Write("Checking booking time ...");
            while (server.BookingTimeLeft > TimeSpan.Zero)
            {
                await Task.Delay(2000);
            }

            Logging.Write("Joining ...");
            await server.JoinCommand.ExecuteAsync(ServerEntry.ActualJoin);

            await wrapper.ReloadAsync(true);
        }