I am working on a login system on Unity, but I encountered a problem that two people could enter the same account and play in it, so I used the LockAccount method, but I encountered errors such as Error CS0117 'UpdateUserDataRequest' does not contain a definition for 'PlayFabId' and Error CS0103 The name 'OnGetUserDataError' does not exist in the current context , and this is the code that contains revision errors.
using PlayFab;
using PlayFab.ClientModels;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public InputField EmailInputFeild;
public InputField PasswordInputFeild;
public InputField email;
public Text Mess;
public class PlayFabManager : MonoBehaviour
{
public void Login()
{
string username = EmailInputFeild.text;
string password = PasswordInputFeild.text;
var request = new LoginWithEmailAddressRequest
{
Email = username,
Password = password
};
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginError);
}
private void OnLoginSuccess(LoginResult result)
{
string playerId = result.PlayFabId;
Debug.Log("Login successful! Player ID: " + playerId);
CheckAccountStatus(playerId);
}
private void OnLoginError(PlayFabError error)
{
Debug.LogError("Login failed: " + error.GenerateErrorReport());
}
private void CheckAccountStatus(string playerId)
{
PlayFabClientAPI.GetUserData(new GetUserDataRequest
{
PlayFabId = playerId,
Keys = new List<string> { "AccountStatus" }
}, result =>
{
if (result.Data.TryGetValue("AccountStatus", out UserDataRecord userDataRecord))
{
string accountStatus = userDataRecord.Value;
if (accountStatus == "locked")
{
Debug.Log("Account is already locked. Cannot log in from another device.");
Mess.text = "Account is already locked. Cannot log in from another device.";
}
else
{
Debug.Log("Account is not locked. Proceed with login.");
LockAccount(playerId);
Mess.text = "Login successful!";
}
}
else
{
Debug.Log("AccountStatus not found in player's data. Proceed with login.");
LockAccount(playerId);
Mess.text = "Login successful!";
}
}, OnGetUserDataError /*error 2 : Error CS0103*/);
}
private void LockAccount(string playerId)
{
var updatedData = new Dictionary<string, string>
{
{ "AccountStatus", "locked" }
};
var request = new UpdateUserDataRequest
{
PlayFabId = playerId, /*error 1 : ErrorCS0117 */
Data = updatedData
};
PlayFabClientAPI.UpdateUserData(request, OnUpdateUserDataSuccess, OnUpdateUserDataError);
}
private void OnUpdateUserDataSuccess(UpdateUserDataResult result)
{
Debug.Log("Account locked successfully!");
}
private void OnUpdateUserDataError(PlayFabError error)
{
Debug.LogError("Failed to lock account: " + error.GenerateErrorReport());
Mess.text = "Failed to lock account. Please try again.";
}
}