//=============================================================================== // Account management //=============================================================================== public static void SaveAccounts() { //StringBuilder output = new StringBuilder(); MemoryStream output = new MemoryStream(); bool savedToTempFile = false; StreamWriter file; if (File.Exists(Settings.playersXmlPath)) { savedToTempFile = true; file = new StreamWriter(Settings.playersTempXmlPath); } else { file = new StreamWriter(Settings.playersXmlPath); } XmlWriterSettings ws = new XmlWriterSettings(); ws.Indent = true; ws.IndentChars = "\t"; ws.Encoding = Encoding.UTF8; XmlWriter writer = XmlWriter.Create(output, ws); // Generate an XML writer.WriteStartDocument(); writer.WriteStartElement("root"); foreach (Player p in Authorization.playerList) { writer.WriteStartElement("player"); writer.WriteStartElement("username"); writer.WriteValue(p.username); writer.WriteEndElement(); writer.WriteStartElement("password"); writer.WriteValue(p.password); writer.WriteEndElement(); writer.WriteStartElement("passwordSalt"); writer.WriteValue(p.passwordSalt); writer.WriteEndElement(); writer.WriteStartElement("loginCounter"); writer.WriteValue(p.loginCounter); writer.WriteEndElement(); writer.WriteStartElement("startingShipName"); writer.WriteValue(p.startingShipName); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); output.Position = 0; //file.Write(output.Read); output.WriteTo(file.BaseStream); output.Close(); output.Dispose(); file.Close(); if (savedToTempFile) { try { File.Move(Settings.playersXmlPath, Settings.playersBackupXmlPath); File.Move(Settings.playersTempXmlPath, Settings.playersXmlPath); File.Delete(Settings.playersBackupXmlPath); } catch (Exception) { ConsoleEx.Error("Account database update failed."); return; } } ConsoleEx.Log("Account database updated successfully."); //ConsoleEx.Debug(output.ToString()); }
public static void Handle(string cmd) { bool handled = false; StringBuilder output = new StringBuilder(); // Formatting cmd = cmd.ToLower(); // Basic commands switch (cmd) { case "help": output.AppendLine("Available types:"); foreach (Type t in staticTypes) { output.AppendLine("- " + t.Name); } handled = true; break; case "event.reload": Destiny.FullReload(); break; case "exit": ConsoleWindow.CloseInstance(); handled = true; break; } // Still not handled if (!handled && cmd.Substring(0, 1) == "#") { string reflectionLine = ParseReflectionCommand(cmd.Substring(1)); if (reflectionLine != null && reflectionLine.Length > 0) { output.AppendLine(reflectionLine); handled = true; } foreach (Type t in staticTypes) { // Show all fields and properties /*if (t.Name.ToLower() == cmd.ToLower()) * { * output.AppendLine("Please note that the console functionality is still Work-In-Progress."); * var fields = t.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); * foreach (FieldInfo field in fields) * { * output.AppendLine(field.Name + " = " + Parse(field.GetValue(null), 0)); * } * var properties = t.GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); * foreach (PropertyInfo property in properties) * { * output.AppendLine(property.Name + " = " + Parse(property.GetValue(null, null), 0)); * } * handled = true; * break; * }*/ } } // Unknown if (!handled) { output.AppendLine("Unknown command"); } // Remove last line break if (output.Length > 0) { output.Remove(output.Length - 2, 2); } // Flush to console ConsoleEx.Log(output.ToString(), false); }