Пример #1
0
        /// <inheritdoc />
        public override Task Authenticate(GuiPanoramaSkyBox skyBox, PlayerProfile activeProfile, Action <bool> callBack)
        {
            JavaLoginState loginState = new JavaLoginState(
                skyBox,
                () =>
            {
                callBack(true);
            }, activeProfile);


            Alex.GameStateManager.SetActiveState(loginState, true);

            return(Task.CompletedTask);
        }
        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);
                }
            }
        }