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.



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

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?

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.

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

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.



I figured out the playerPrefs bug. There was a hidden Input.GetKeyDown function somewhere in one of the scripts that would delete all the playerPrefs when one would press letter "A"... so that was definitely my fault... Now I'm trying to figure out what's wrong with passwords

Okie, great that you got the issue!


Try checking the details in NO-SQL and make sure you are using the right App id.

Hi Sandro,


I hope you don't mind but I am in your game now, I've created a user GameSparksShane with a password of password in the test harness.


I am able to log in fine, I cannot replicate entering the same number of letters as the username and being authenticated, I can't see the passwords for your existing users but everything seems to be working fine...


Can you create a new user and test it again?


In the manage screen you can see your existing users, remember that you use the username to sign in, not the display name.


Shane

Hi Sandro,


Sorry for double posting! :P 


So I took a guess I tried a few of your original users with "password" as their password and I got in! The username will always be the "true" login name, much like Steam a user can change their displayName as much as they want, but the must use their original userName to log in.


Shane

Hmm, I exported the Player collection and in password fields it shows stuff like this "Sv9fFdqgvOwCm8X+QydfM+XMXCX3Gp8SlRVK1tOx43o=" which is not the real password obviously... Is there a way to see what's the password currently? Maybe that'll help me understand better why the login attempts fail

Ok, so this time:
I created a user from my game and I was able to login from both, my game and test harness
Then I created a user in testharness and again was able to login from both, my game and test harness 
I tried GameSparksShane and it tells me that it's taken so it sees it in the database but when I put "password" in password field, it doesn't let me in -_-

Unfortunately we cannot access the passwords.


As for you not being able to log into GameSparksShane, I just tried there and it is still working for me, here's the calls I sent:


 

{
 "@class": ".AuthenticationRequest",
 "password": "password",
 "userName": "GameSparksShane"
}
{
 "@class": ".AuthenticationResponse",
 "authToken": "69dd6e9a-8615-4df6-b588-d8db3a26bbac",
 "displayName": "GameSparksShane",
 "newPlayer": false,
 "scriptData": null,
 "userId": "552cea55e4b0e4d939d4ff89"
}

 

Can you copy and paste the test harness inspector?

Login to post a comment