Beispiel #1
0
        private async void OnJoinServerButtonPressed()
        {
            var       entry = SelectedItem.SavedServerEntry;
            var       ips   = Dns.GetHostAddresses(entry.Host).ToArray();
            IPAddress ip    = ips[Rnd.Next(0, ips.Length - 1)];

            if (ip == null)
            {
                return;
            }

            IPEndPoint target = new IPEndPoint(ip, entry.Port);

            var authenticationService = GetService <IPlayerProfileService>();
            var currentProfile        = authenticationService.CurrentProfile;

            if (Alex.ServerTypeManager.TryGet(entry.ServerType, out var typeImplementation))
            {
                if (!await typeImplementation.VerifyAuthentication(currentProfile))
                {
                    await typeImplementation.Authenticate(_skyBox, result =>
                    {
                        if (result)
                        {
                            Alex.ConnectToServer(typeImplementation, new ServerConnectionDetails(target, entry.Host), authenticationService.CurrentProfile);
                        }
                    });
                }
                else
                {
                    Alex.ConnectToServer(typeImplementation, new ServerConnectionDetails(target, entry.Host), authenticationService.CurrentProfile);
                }
            }
        }
        private async void OnJoinServerButtonPressed()
        {
            var       entry = SelectedItem.SavedServerEntry;
            var       ips   = Dns.GetHostAddresses(entry.Host).ToArray();
            IPAddress ip    = ips[Rnd.Next(0, ips.Length - 1)];

            if (ip == null)
            {
                return;
            }

            IPEndPoint target = new IPEndPoint(ip, entry.Port);

            var authenticationService = GetService <IPlayerProfileService>();
            var currentProfile        = authenticationService.CurrentProfile;

            if (entry.ServerType == ServerType.Java)
            {
                if (currentProfile == null || (currentProfile.IsBedrock))
                {
                    JavaLoginState loginState = new JavaLoginState(
                        _skyBox,
                        () =>
                    {
                        Alex.ConnectToServer(
                            target, authenticationService.CurrentProfile, false,
                            SelectedItem.SavedServerEntry.Host);
                    });


                    Alex.GameStateManager.SetActiveState(loginState, true);
                }
                else
                {
                    Alex.ConnectToServer(target, currentProfile, false, SelectedItem.SavedServerEntry.Host);
                }
            }
            else if (entry.ServerType == ServerType.Bedrock)
            {
                if (SelectedItem.ConnectionEndpoint != null)
                {
                    target = SelectedItem.ConnectionEndpoint;
                }

                if (currentProfile == null || (!currentProfile.IsBedrock))
                {
                    foreach (var profile in authenticationService.GetBedrockProfiles())
                    {
                        profile.IsBedrock = true;
                        Log.Debug($"BEDROCK PROFILE: {profile.Username}");

                        var task = await authenticationService.TryAuthenticateAsync(profile);

                        if (task)
                        {
                            currentProfile = profile;

                            break;
                        }
                        else
                        {
                            Log.Warn($"Profile auth failed.");
                        }
                    }
                }

                if ((currentProfile == null || (!currentProfile.IsBedrock)) || !currentProfile.Authenticated)
                {
                    BEDeviceCodeLoginState loginState = new BEDeviceCodeLoginState(
                        _skyBox, (profile) => { Alex.ConnectToServer(target, profile, true); });

                    Alex.GameStateManager.SetActiveState(loginState, true);
                }
                else
                {
                    Alex.ConnectToServer(target, currentProfile, true);
                }
            }
        }
        private async void OnJoinServerButtonPressed()
        {
            var overlay = new LoadingOverlay();

            Alex.GuiManager.AddScreen(overlay);

            try
            {
                var       entry = SelectedItem.SavedServerEntry;
                var       ips   = Dns.GetHostAddresses(entry.Host).ToArray();
                IPAddress ip    = ips[Rnd.Next(0, ips.Length - 1)];

                if (ip == null)
                {
                    return;
                }

                IPEndPoint target = new IPEndPoint(ip, entry.Port);

                var authenticationService = GetService <IPlayerProfileService>();
                //var currentProfile        = authenticationService.CurrentProfile;

                if (Alex.ServerTypeManager.TryGet(entry.ServerType, out var typeImplementation))
                {
                    var           profiles       = authenticationService.GetProfiles(entry.ServerType);
                    PlayerProfile currentProfile = null;

                    if (profiles.Length == 1)
                    {
                        currentProfile = profiles[0];
                    }

                    void Connect(PlayerProfile profile)
                    {
                        Alex.ConnectToServer(
                            typeImplementation, new ServerConnectionDetails(target, entry.Host),
                            profile);

                        Alex.GuiManager.RemoveScreen(overlay);
                        overlay = null;
                    }

                    if (currentProfile == null || !await typeImplementation.VerifyAuthentication(currentProfile))
                    {
                        await typeImplementation.Authenticate(
                            _skyBox, currentProfile, result =>
                        {
                            if (result)
                            {
                                Connect(authenticationService.CurrentProfile);
                            }
                        });
                    }
                    else
                    {
                        Connect(currentProfile);
                    }
                }
            }
            finally
            {
                if (overlay != null)
                {
                    Alex.GuiManager.RemoveScreen(overlay);
                }
            }
        }