Hi,
I’m making a game with Unity+Parse and using a user system with facebook.
Problem is, I dont want multiple devices to use the same facebook account as the same time.
The way I’m trying to go about it is i use a variable that acts as a counter- whenever someone logins an account, it saves the login as an Int, and them when someone else logs in on another device, I updates that Int again. when the first player’s counter is “outdated”, that indicates that he should be disconnected from parse/facebook.
The problem is I don’t know how to get the most updated values, because when two players are updating the same ParseObject at the same time, retrieving that value isn’t getting me the most recent one.
How can I resolve this?
thank you.
Personally, I would store the a device ID rather than an integer. It’s just more meaningful, and you don’t end up with an ever increasing value.
I think you can use FetchAsync to update the user object with data from the server. Have you tried that already?
IEnumerator CheckForOtherDeviceLogin() {
if (ParseUser.CurrentUser != null) {
var task = ParseUser.CurrentUser.FetchAsync();
while (!task.IsCompleted) {
yield return null;
}
if (task.IsFaulted || task.IsCanceled) {
Debug.LogError("Error getting user object.");
}
else {
if (ParseUser.CurrentUser.Get<string>("deviceID") != SystemInfo.deviceUniqueIdentifier) {
ParseUser.LogOut();
}
}
}
}
There might be a better way of dealing with this. Such as, sending a notification to the previously logged in device when a new login occurs. However, you may then run into issues if the device loses internet connection at some point. Perhaps someone else with experience will post a better answer.