public LoginViewModel() { WhenLogin = ReactiveCommand.CreateFromTask(async v => { Visibility = Visibility.Hidden; var auth = new OldAuthenticator(UserName, Password, App.Config.ClientToken); try { var result = await auth.Authenticate(); var account = new MinecraftAccount { Name = result["auth_player_name"], AccessToken = result["auth_access_token"], AccountGuid = Guid.Parse(result["auth_uuid"]), Type = result["user_type"] }; App.Config.Accounts[account.Name] = account; App.Config.DefaultAccount = account.Name; App.Config = App.Config; var version = Directory.CreateDirectory("versions").FullName; var asset = Directory.CreateDirectory("assets").FullName; var lib = Directory.CreateDirectory("libraries").FullName; var games = Directory.CreateDirectory("games").FullName; //Start game var defaultGame = App.Config.Instances[App.Config.DefaultGame]; var game = await defaultGame .GetMinecraftGame(version, Array.Empty <string>()); var assetList = JsonConvert.DeserializeObject <MinecraftAssetCollection>( await File.ReadAllTextAsync(Path.Combine(asset, "indexes", $"{game.AssetIndex}.json"))); var launcher = new Launcher(auth, game, assetList, asset, lib, Path.Combine(games, App.Config.DefaultGame), defaultGame.CustomJava ?? App.Config.DefaultJava); launcher.ArgBuilder.Append(new JvmArgProvider(o => { o.MaxMemoryInMegaBytes = defaultGame.Ram; })); await launcher.Run(); Environment.Exit(0); } catch (AuthenticationException e) { MessageBox.Show(e.Message, "错误", MessageBoxButtons.OKCancel); Visibility = Visibility.Visible; } }); }
private async ValueTask <string> MojangLogin() { var userName = GetStringNotEmpty("user name"); var password = GetPasswordNotEmpty(); var auth = new OldAuthenticator(userName, password, Config.ClientToken); var result = await auth.Authenticate(); var name = result["auth_player_name"]; var guid = Guid.Parse(result["auth_uuid"]); var accessToken = result["auth_access_token"]; Config.Accounts[name] = new() { Name = name, AccessToken = accessToken, AccountGuid = guid, Type = "Mojang" }; if (string.IsNullOrEmpty(Config.DefaultAccount)) { Config.DefaultAccount = name; } return(name); }