public IEnumerator AddAccountCoroutine(uLobby.AccountRecord account, uLobby.Request <uLobby.AccountRecord> request) { MySqlParameter[] paramsArray = new MySqlParameter[4]; paramsArray[0] = new MySqlParameter("name", account.name); paramsArray[1] = new MySqlParameter("password", account.passwordHash.passwordHash); paramsArray[2] = new MySqlParameter("salt", account.passwordHash.salt); paramsArray[3] = new MySqlParameter("data", account.data); var operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "INSERT INTO accounts (name,password,salt,data)VALUES(@name,@password,@salt,@data)", paramsArray, null, null); while (!operation.IsCompleted) { yield return(null); } ExecuteNonQueryAsync.EndInvoke(operation); operation = ExecuteDataReaderAsync.BeginInvoke(storageManager.connectionString, "SELECT id FROM accounts where name = @name and password = @password and salt = @salt LIMIT 1;", paramsArray, null, null); while (!operation.IsCompleted) { yield return(null); } var dr = ExecuteDataReaderAsync.EndInvoke(operation); dr.Read(); account.id = new AccountID(dr.GetInt32("id").ToString()); dr.Close(); StorageLayerUtility.RequestUtility.SetResult(request, account); }
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); }
public IEnumerator SetFriendListRecordCoroutine(uLobby.AccountID accountID, uLobby.FriendListRecord record, uLobby.Request request) { var operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "DELETE FROM friends WHERE owner = @id", new MySqlParameter[] { new MySqlParameter("id", int.Parse(accountID.value)) }, null, null); while (!operation.IsCompleted) { yield return(null); } ExecuteNonQueryAsync.EndInvoke(operation); operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "DELETE FROM invitations WHERE sender = @id", new MySqlParameter[] { new MySqlParameter("id", int.Parse(accountID.value)) }, null, null); while (!operation.IsCompleted) { yield return(null); } ExecuteNonQueryAsync.EndInvoke(operation); foreach (AccountID friend in StorageLayerUtility.FriendListRecordUtility.GetFriendIDs(record)) { MySqlParameter[] paramsArray = new MySqlParameter[2]; paramsArray[0] = new MySqlParameter("owner", int.Parse(accountID.value)); paramsArray[1] = new MySqlParameter("friend", int.Parse(friend.value)); operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "INSERT INTO friends (owner,friend) VALUES(@owner,@friend)", paramsArray, null, null); while (!operation.IsCompleted) { yield return(null); } ExecuteNonQueryAsync.EndInvoke(operation); } foreach (var inviter in StorageLayerUtility.FriendListRecordUtility.GetInviterIDs(record)) { MySqlParameter[] paramsArray = new MySqlParameter[2]; paramsArray[0] = new MySqlParameter("sender", int.Parse(inviter.value)); paramsArray[1] = new MySqlParameter("receiver", int.Parse(accountID.value)); operation = ExecuteNonQueryAsync.BeginInvoke(storageManager.connectionString, "INSERT INTO invitations (sender,receiver) VALUES(@sender,@receiver)", paramsArray, null, null); while (!operation.IsCompleted) { yield return(null); } ExecuteNonQueryAsync.EndInvoke(operation); } yield break; }