/// <summary> /// Call AcquireToken - to acquire a token requiring user to sign-in /// </summary> private async void CallGraphButton_Click(object sender, RoutedEventArgs e) { try { ResultText.Text = "Authentication process started..."; TokenInfoText.Text = ""; var msacc = await App.MSAuth.SignIn(); var xbaut = new XboxAuthentication(App.AuthSettings, msacc); var mcaut = new MinecraftAuthentication(App.AuthSettings, xbaut); ResultText.Text = "Authentication finished!"; TokenInfoText.Text += $"XBL Token:\r\n{xbaut.XboxLive.Token}\r\n\r\n"; TokenInfoText.Text += $"XSTS token:\r\n{xbaut.XboxSecurityTokenService.Token}\r\n\r\n"; TokenInfoText.Text += $"Minecraft:\r\n{JsonSerializer.Serialize(mcaut.Minecraft, new JsonSerializerOptions { WriteIndented = true })}\r\n\r\n"; CallGraphButton.IsEnabled = false; SignOutButton.IsEnabled = true; } catch (Exception ex) { ResultText.Text = $"Authentication falied!"; TokenInfoText.Text = $"{ex}"; } }
public void ReloadConfiguration() { try { using (StreamReader reader = new StreamReader("server.config")) { while (!reader.EndOfStream) { string[] splitted = reader.ReadLine().Trim().Split('='); if (splitted.Length == 2) { //special options if (splitted[0].ToLower() == "port") { Port = int.Parse(splitted[1]); } else if (splitted[0].ToLower() == "display") { Logger.Display = bool.Parse(splitted[1]); } else if (splitted[0].ToLower() == "auth" || splitted[0].ToLower() == "authentication") { _Authentication = (MinecraftAuthentication)Enum.Parse(typeof(MinecraftAuthentication), splitted[1], true); } else if (splitted[0].ToLower() == "version") { _Version = int.Parse(splitted[1]); } else if (splitted[0].ToLower() == "path") { _Path = splitted[1]; } else if (splitted[0].ToLower() == "commanddirectory") { CommandManager.CommandDirectory = splitted[1]; } else { //store data for future references.... Configuration.Add(splitted[0].ToLower(), splitted[1]); } } } } } catch (FileNotFoundException) { Log.Warning("Unable to locate server.config."); } catch (Exception e) { Log.Error(e, "Unable to reload configuration."); } }
public void Login() { LoginDialog login = new LoginDialog (); var saved = GetSavedCredentials(); try { if (saved != null) { login.Username = saved.AutoLoginUser; var savedCreds = saved.Credentials.Where(x => x.UserName == saved.AutoLoginUser).FirstOrDefault(); if (savedCreds != null) { login.Password = savedCreds.Password; login.RememberCredentials = true; } } while (true) { int response = login.Run (); if (response == (int)Gtk.ResponseType.Ok) { var auth = new MinecraftAuthentication (); string message = "Invalid login!"; try { Session = auth.Login (login.Username, login.Password); } catch (Exception e) { Session = null; message = e.Message; } if (Session == null || Session.AccessToken == null) { DedicatedLauncher.MessageBox (message); continue; } break; } else if (response == (int)Gtk.ResponseType.Cancel) { throw new CancelException(); } } saved = new SavedCredentials() { AutoLoginUser = login.Username, Credentials = new List<SavedCredential>() }; if (login.RememberCredentials) { saved.Credentials = new List<SavedCredential>() { new SavedCredential() { UserName = login.Username, Password = login.Password } }; } Directory.CreateDirectory(System.IO.Path.GetDirectoryName(SavedCredentialsFile)); using (StreamWriter sw = new StreamWriter(SavedCredentialsFile)) sw.Write(saved.ToJson()); login.Hide (); login.Destroy(); usernameLabel.Markup = string.Format ("Playing as <b>{0}</b>", Session.Username); } finally { login.Destroy(); } }
public bool LaunchMinecraft(string MinecraftVersion, MinecraftAuthentication MinecraftAuthData) { Assembly _assembly = Assembly.GetExecutingAssembly(); string _assemblydir = Path.GetDirectoryName(_assembly.Location); string MinecraftJar; if(MinecraftVersion == "Minecraft in %appdata%") MinecraftJar = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\\bin\\minecraft.jar"); else MinecraftJar = _assemblydir + "\\versions\\" + MinecraftVersion + "\\minecraft.jar"; if (!File.Exists(MinecraftJar)) return false; Debug.WriteLine("[MinecraftLauncher] Reloading configuration"); System.Configuration.ConfigurationManager.RefreshSection("userSettings"); Process launchProcess = new Process(); launchProcess.StartInfo.FileName = this.JavaLocation; launchProcess.StartInfo.Arguments = "-Xms" + launcher2.Properties.Settings.Default.JavaMinHeap + " -Xmx" + launcher2.Properties.Settings.Default.JavaMaxHeap + " -Xincgc "; launchProcess.StartInfo.Arguments += "-cp \"" + MinecraftJar + ";"; launchProcess.StartInfo.Arguments += LWJGLLocation + "jinput.jar" + ";"; launchProcess.StartInfo.Arguments += LWJGLLocation + "lwjgl.jar" + ";"; launchProcess.StartInfo.Arguments += LWJGLLocation + "lwjgl_util.jar" + "\" "; launchProcess.StartInfo.Arguments += "-Dorg.lwjgl.librarypath=\"" + LWJGLLocation + "natives" + "\" "; launchProcess.StartInfo.Arguments += "-Dnet.java.games.input.librarypath=\"" + LWJGLLocation + "natives" + "\" "; launchProcess.StartInfo.Arguments += "net.minecraft.client.Minecraft "; launchProcess.StartInfo.Arguments += MinecraftAuthData.MinecraftAuthToken; Debug.WriteLine("[LaunchMinecraft] Launching java with arguments: " + launchProcess.StartInfo.Arguments); launchProcess.Start(); return true; }
private void MainForm_Load(object sender, EventArgs e) { try { Debug.WriteLine("[MainForm] Creating new MinecraftLauncher instance"); mcLauncher = new MinecraftLauncher(); Debug.WriteLine("[MainForm] Populating comboMinecraftVersion"); comboMinecraftVersion.Items.AddRange(mcLauncher.GetMinecraftVersions()); comboMinecraftVersion.SelectedIndex = 0; Debug.WriteLine("[MainForm] Checking for authentication data"); if (Properties.Settings.Default.MinecraftUsername == "") { Debug.WriteLine("[MainForm] Creating new AuthDetailForm."); AuthDetailForm authForm = new AuthDetailForm(); Debug.WriteLine("[MainForm] Showing AuthDetailForm."); authForm.ShowDialog(); Debug.WriteLine("[MainForm] Disposing of created AuthDetailForm."); authForm.Dispose(); } Debug.WriteLine("[MainForm] Attempting to authenticate with minecraft.net"); AuthData = new MinecraftAuthentication(Properties.Settings.Default.MinecraftUsername, Properties.Settings.Default.MinecraftPassword); if (AuthData.DoAuthentication() != MinecraftAuthentication.AuthenticationStatus.Success) { MessageBox.Show("There was an error logging you into minecraft.net. Please check your login details."); } menuOptionsItemAuthDetails.Text = "Authenticated as " + AuthData.MinecraftUsername; } catch (MinecraftLauncher.JavaNotFoundException) { Debug.WriteLine("[MainForm] JavaNotFoundException encountered, closing app."); Application.Exit(); } catch (Exception ex) { Debug.WriteLine("[MainForm] Exception encountered: " + ex.Message); Debug.Indent(); Debug.WriteLine(ex.StackTrace); Debug.Unindent(); MessageBox.Show("Oops, something went wrong and launcher² has to close.\n\nIf you would like to help us fix what caused this crash, please send the log file located at the path below to [email protected] :\n" + launcher2.Program.logPath, "launcher²", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }