Exemplo n.º 1
0
    public void CreateNewAccount(string acctName, string pw)
    {
        //SERVER-SIDE ONLY | Insert a new record into the 'accounts' table
        Debug.Log("Creating New Account >> " + acctName);
        //If the account name doesn't already exist...
        if (!AccountNameExists(acctName))
        {
            //Create a connection to the database, open it, and create a command
            IDbConnection dbCon = (IDbConnection) new SqliteConnection(dbPath);
            dbCon.Open();
            IDbCommand dbCmd = dbCon.CreateCommand();

            //Set the command's text and execute it
            dbCmd.CommandText = "INSERT INTO accounts (name, password) VALUES ('" + acctName + "', '" + pw + "');";
            Debug.Log(dbCmd.CommandText);
            dbCmd.ExecuteNonQuery();
            Debug.Log("New Account Created >> " + acctName);

            //Retrieve the newly-created account's ID
            int newAcctID = GetAccountID(acctName, pw);
            //Create the new account's library
            libraryManager.CreateNewAccountLibrary(newAcctID);
            //Create blank deck templates for the new account
            deckListManager.CreateNewAccountDeckList(newAcctID);

            //Clean up
            dbCmd.Dispose();
            dbCmd = null;
            dbCon.Close();
            dbCon = null;
        }
        //Otherwise the name was taken and cannot be used
        else
        {
            Debug.Log("Account Name >> " + acctName + " Already Exists || Cannot Create New Account");
        }
    }