Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Collections.Generic;
  5.  
  6. namespace Server
  7. {
  8. public class AccountDatabase
  9. {
  10. public string path = Environment.CurrentDirectory + "/database/accounts/";
  11.  
  12. public List<Account> accounts = new List<Account>();
  13.  
  14. public static void createAccount(int accountID, string username, string password) {
  15. if (accountExists(accountID) {
  16. Debug.Log(TAG.INFO, "Account already exists");
  17. return;
  18. }
  19.  
  20. Globals.ad.accounts.Add(new Account() { Username = username, AccountID = accountID, Password = password });
  21.  
  22. using (XmlWriter w = XmlWriter.Create(path + accountID + ".xml")) {
  23. w.WriteStartElement("account");
  24. w.WriteElementString("accountID", accountID);
  25. w.WriteElementString("userName", username);
  26. w.WriteElementString("password", password);
  27. w.WriteEndElement();
  28. w.Flush();
  29. }
  30.  
  31. Debug.Log(TAG.DEBUG, "Created new account with id: " + accountID);
  32. }
  33.  
  34. public static bool accountExists(int accountID) {
  35. bool final = false;
  36.  
  37. if (File.Exists (path + accountID + ".xml")) {
  38. final = true;
  39. }
  40.  
  41. return final;
  42. }
  43.  
  44. public static void deleteAccount(int accountID) {
  45. if (!File.Exists (path + accountID + ".xml")) {
  46. Debug.Log (TAG.ERROR, "Account not found!");
  47. return;
  48. }
  49.  
  50. File.Delete(path + Account + ".xml");
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement