Sign In Register

How can we help you today?

Start a new topic
Answered

Re-Login deletes my PlayerPrefs

Hi, 


I'm new to gamesparks and am trying to integrate its login without any social network (GameSparks' own username/password that is). So far I've more or less managed to get the result I want, however I have couple of problems. 


The system I currently have works in the following way:
When a player presses a leaderboards button for the first time, two textInputFields appear where the username and password must be written. The window also has three buttons - "REGISTER", "LOGIN" and "CANCEL". When the username/password fields are filled in, if the register button is pressed the username is registered (unless it's taken) and if login is pressed, the player logs in (if the password matches the username). After that the same button opens up the leadboards but has an extra button which enables players to relogin as someone else. 

My first problem is, if I log in as Player1, then play the game for a while, and re-login as Player2, all the PlayerPrefs get deleted. 

Below is the code for Register and Login methods

Register:  

	public void Register()
	{
		SetInput ();
		new GameSparks.Api.Requests.RegistrationRequest().SetDisplayName(gsUsername).SetUserName(gsUsername).SetPassword (gsPassword).Send((response) =>
		{
			if (response.HasErrors)
			{
				print (response.Errors);
				// if usename is already taken the do
                                // feedbackText.text = "username already in use,\nplease choose another one";
			}
			else
			{
				feedbackText.text = "Registration Successful!";
				Invoke ("CancelButton", 1.5f);
			}
		});
	}

Login:

public void Login()
	{
		SetInput ();
		new GameSparks.Api.Requests.AuthenticationRequest().SetUserName (gsUsername).SetPassword (gsPassword).Send((response) =>
		                                                                                                                                   {
			if (response.HasErrors)
			{
				print (response.Errors);
				//if username and password don't match, say that they don't match
			}
			else
			{
				feedbackText.text = "Login Successful!";
				Invoke ("CancelButton", 1.5f);
			}
		});
	}

My second problem is, how do I check which error was returned in the response?

In "Register" code for example I want to be able to know if the error returns "username taken" and if it does then print out the feedback text, while if error is something else, handle it differently.

Same in the "Login" code. If the username and password don't match, I want to know it. 
I tried printing `response.Errors` but it doesn't show anything special.


Thanks in advance


Best Answer

Hi Sandro,


If you want to remove entries from a leaderboard first select the Manage tab in the portal.



In the next column select the "Dynamic Leaderboards" tab and you should have a list of leaderboards for that project.



Click the button to the right of the leaderboard to edit the entries.



Here you can either select an entry to delete or delete them all.


Thanks,


Oisin.



while we're at it, should I manually save player's login and username credentials so that on the next game boot up they are logged in automatically in the background or does GameSparks handle that itself somehow? 
Right now it seems that in Unity Editor (I don't have the device with me at this moment), when I start the game, it sends the "AuthenticatedConnectRequest" which makes the "GameSparks.GameSparksApi.isAuthenticated()" return true. But I think it is not logged in as any user right?


I need to check if the user is already logged in or not, to then either present the login screen or show the leaderboards, and I think in this case "isAuthenticated()" won't do. How do I check for this?


Also, how do I check for the event when GS is Available? I need this so that as soon as GS is available I can login the player automatically


Lastly, are there any restrictions I should keep in mind for usernames? I mean should I only allow alphanumeric values, or is "Standard" setting ok? (which lets you put pretty much anything you want).
I limit both, the username and password, to 10 characters max.

I removed it from the player collection but it still shows up in the leaderboard...

Thanks!
I caught the specific errors I needed but the player pref problem remains...
When I relogin as another user, it nullifies my Player Prefs (yes, I mean unity PlayerPrefs).

oh and I just noticed another problem.
For some reason, Log In works if you enter the same number of characters as in the password. Even if my password is "lion" and I enter "lama" it logs me in... how do I fix this?

Answer

Hi Sandro,


If you want to remove entries from a leaderboard first select the Manage tab in the portal.



In the next column select the "Dynamic Leaderboards" tab and you should have a list of leaderboards for that project.



Click the button to the right of the leaderboard to edit the entries.



Here you can either select an entry to delete or delete them all.


Thanks,


Oisin.


Done, thanks Oisin!


I still can't login to all the old users I created, not that's it's a huge problem anymore since so far all the new registered users seem to not have any issues with passwords but do you guys have any update on what may have caused the password related problem?

Removing leaderboard data seems to be intentionally restricted from No-SQL.

However,

       You can delete them easily with well designed new "Manage" tab section.




Good luck!


I think you may have had a mix up between the usernames and the display names.

The display names you defined had conventional seeming names but the usernames were more randomized.


Shane posted above that he was able to log in those users in your project using their "true" usernames.


If you go to the manage tab again you can see all existing usernames and display names in the "players" section.


Thanks.


Oisin.

Hmm, strange.

I just checked and the ones that I can't login with have identical userNames/displayNames. It couldn't be otherwise since when I register from the game, the one and the same variable is passed for both, display and usernames, and thus they cannot be different.

Anyway, it doesn't matter at this point, I won't bother you again unless something stops working or I fail to find relevant documentation for a given task : )

Thanks a lot for support!

Now that I'm trying to replicate this in the test harness, I can't login with any usernames that i've registered before... The response always returns as "UNRECOGNIZED"... In my game, I don't really have any other GameSparks code besides the Login() and Register() mentioned above so I figure this can't be my fault... or can it?. I created a new user in test harness and it works fine but all the old ones that I have are unable to login. 

And regarding playerPrefs, as you can see from the code posted above, it has no reference to playerPrefs so I don't really know what I can do to debug this at this point

Hi Sandro, 

I haven't been able to recreate your problem here.
Have you been able to replicate it in the test harness?


Thanks,


Oisin.

Hi Sandro,


First Problem:

I assume you mean the Unity PlayerPrefs? This should definitely not be happening but I've been unable to replicate myself as of yet, I will keep testing though and get back to you if I can replicate it.


Second Problem:

To figure out what errors are being returned you can do the following:

 

public void CreateNewUser()
{
new RegistrationRequest().SetUserName("userName").SetPassword("password").SetDisplayName("userName").Send((response) =>
        {
                        if(repsone.Errors.GetString("USERNAME") == "TAKEN"){
                            Debug.Log("Username already in use, please choose a different one");
                        }
});
}

 

You can see what errors to look out for on our Documentation site:

https://docs.gamesparks.net/documentation/request-api/authentication-request-api/registrationrequest

https://docs.gamesparks.net/documentation/request-api/authentication-request-api/authenticationrequest


Shane

So... whatever I register from the game is unable to log in from test harness and whatever i register from test harness is unable to log in from the game apparently. But both see that the username is taken, just passwords don't seem to work

I was thinking on this from quite some time how playerPrefs is linked here and that too with GameSparks.

Can you try logging in with GS in a fresh project and let me know if its still the same case?

Make sure you are check the same Application from TestHarness and from Unity project regarding the user details.


Further, you can do this. Go to No-SQL tab and check the available players and cross check with the results.

I would be interested in knowing more details on this, but this forum lacks PM so only this is the only place I can communicate.



Login to post a comment