Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Xml;
- using System.Collections.Generic;
- namespace Server
- {
- public class AccountDatabase
- {
- public string path = Environment.CurrentDirectory + "/database/accounts/";
- public List<Account> accounts = new List<Account>();
- public static void createAccount(int accountID, string username, string password) {
- if (accountExists(accountID) {
- Debug.Log(TAG.INFO, "Account already exists");
- return;
- }
- Globals.ad.accounts.Add(new Account() { Username = username, AccountID = accountID, Password = password });
- using (XmlWriter w = XmlWriter.Create(path + accountID + ".xml")) {
- w.WriteStartElement("account");
- w.WriteElementString("accountID", accountID);
- w.WriteElementString("userName", username);
- w.WriteElementString("password", password);
- w.WriteEndElement();
- w.Flush();
- }
- Debug.Log(TAG.DEBUG, "Created new account with id: " + accountID);
- }
- public static bool accountExists(int accountID) {
- bool final = false;
- if (File.Exists (path + accountID + ".xml")) {
- final = true;
- }
- return final;
- }
- public static void deleteAccount(int accountID) {
- if (!File.Exists (path + accountID + ".xml")) {
- Debug.Log (TAG.ERROR, "Account not found!");
- return;
- }
- File.Delete(path + Account + ".xml");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement