public IEnumerator UpdateAccountCoroutine(uLobby.IAccount account, uLobby.AccountUpdate update, uLobby.Request <uLobby.Account> request)
    {
        Request <AccountRecord> getAccountRequest;

        getAccountRequest = StorageLayerUtility.GetAccountRecord(account.id);
        yield return(getAccountRequest.WaitUntilDone()); if (StorageLayerUtility.RequestUtility.PropagateException(getAccountRequest, request))
        {
            yield break;
        }
        AccountRecord record = getAccountRequest.result;

        if (StorageLayerUtility.AccountUpdateUtility.isPasswordChanged(update))
        {
            record.passwordHash = SaltedPasswordHash.GenerateSaltedPasswordHash(SaltedPasswordHash.GeneratePasswordHash(StorageLayerUtility.AccountUpdateUtility.GetPassword(update) + record.name));
        }
        if (StorageLayerUtility.AccountUpdateUtility.IsDataChanged(update))
        {
            record.data = StorageLayerUtility.AccountUpdateUtility.GetData(update);
        }
        MySqlParameter[] paramsArray = new MySqlParameter[4];
        paramsArray[0] = new MySqlParameter("password", record.passwordHash.passwordHash);
        paramsArray[1] = new MySqlParameter("salt", record.passwordHash.salt);
        paramsArray[2] = new MySqlParameter("data", record.data);
        paramsArray[3] = new MySqlParameter("id", int.Parse(record.id.value));
        var operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "UPDATE accounts SET password=@password,salt=@salt,data=@data WHERE id = @id", paramsArray, null, null);

        while (!operation.IsCompleted)
        {
            yield return(null);
        }
        Account updatedAccount = StorageLayerUtility.CreateAccount(record);

        StorageLayerUtility.RequestUtility.SetResult(request, updatedAccount);
    }
Exemplo n.º 2
0
    // UpdateAccountCoroutine
    IEnumerator IAccountOperations.UpdateAccountCoroutine(IAccount account, AccountUpdate update, Request <Account> request)
    {
        Request <AccountRecord> getAccountRequest;

        getAccountRequest = StorageLayerUtility.GetAccountRecord(account.id);
        yield return(getAccountRequest.WaitUntilDone()); if (StorageLayerUtility.RequestUtility.PropagateException(getAccountRequest, request))
        {
            yield break;
        }
        AccountRecord record = getAccountRequest.result;

        if (StorageLayerUtility.AccountUpdateUtility.isPasswordChanged(update))
        {
            record.passwordHash = SaltedPasswordHash.GenerateSaltedPasswordHash(SaltedPasswordHash.GeneratePasswordHash(StorageLayerUtility.AccountUpdateUtility.GetPassword(update) + record.name));
        }

        if (StorageLayerUtility.AccountUpdateUtility.IsDataChanged(update))
        {
            record.data = StorageLayerUtility.AccountUpdateUtility.GetData(update);
        }

        Account updatedAccount = StorageLayerUtility.CreateAccount(record);

        StorageLayerUtility.RequestUtility.SetResult(request, updatedAccount);
        yield break;
    }
    // CreateAccount
    public static IEnumerator CreateAccount(string accountId, string email, string password)
    {
        // Test accounts
        if (GameDB.IsTestAccount(email))
        {
            password = email;
        }

        // Log
        LogManager.General.Log(accountId + ", " + email + ", " + password);

        // SHA 512 encryption
        password = GameDB.EncryptPasswordString(password);

        // AccountNameToID
        yield return(GameDB.instance.StartCoroutine(GameDB.Set <string>(
                                                        "AccountNameToID",
                                                        email,
                                                        accountId,
                                                        null
                                                        )));

        // Create password hash
        LogManager.General.Log("Generating password hash");
        var saltedPasswordHash = SaltedPasswordHash.GenerateSaltedPasswordHash(SaltedPasswordHash.GeneratePasswordHash(password + email));

        // Create game account
        var gameAccount = new GameAccount(
            accountId,
            email,
            saltedPasswordHash.passwordHash,
            saltedPasswordHash.salt
            );

        // Save game account
        LogManager.General.Log("Saving game account: " + accountId);
        yield return(GameDB.instance.StartCoroutine(GameDB.Set <GameAccount>(
                                                        "Accounts",
                                                        accountId,
                                                        gameAccount,
                                                        null
                                                        )));
    }
Exemplo n.º 4
0
    // UpdateAccountCoroutine
    IEnumerator IAccountOperations.UpdateAccountCoroutine(IAccount account, AccountUpdate update, Request <Account> request)
    {
        // Get account record
        Request <AccountRecord> getAccountRequest;

        getAccountRequest = StorageLayerUtility.GetAccountRecord(account.id);
        yield return(getAccountRequest.WaitUntilDone());

        // Did it cause an exception?
        if (StorageLayerUtility.RequestUtility.PropagateException(getAccountRequest, request))
        {
            yield break;
        }

        AccountRecord record = getAccountRequest.result;

        // Password change
        if (StorageLayerUtility.AccountUpdateUtility.isPasswordChanged(update))
        {
            record.passwordHash = SaltedPasswordHash.GenerateSaltedPasswordHash(SaltedPasswordHash.GeneratePasswordHash(StorageLayerUtility.AccountUpdateUtility.GetPassword(update) + record.name));
        }

        Account updatedAccount = StorageLayerUtility.CreateAccount(record);

        // Save in accounts database
        yield return(GameDB.instance.StartCoroutine(GameDB.Set <GameAccount>(
                                                        "Accounts",
                                                        updatedAccount.id.value,
                                                        new GameAccount(record),
                                                        data => {
            if (data != null)
            {
                StorageLayerUtility.RequestUtility.SetResult(request, updatedAccount);
            }
        }
                                                        )));
    }