Forum QuickConnect How to get the player name on the server

Discussion and help relating to PlayerIO's QuickConnect feature, including Facebook Connect and Kongregate Connect.

How to get the player name on the server

Postby sidwoo » December 9th, 2010, 5:38 pm

hi,

i really want to get the player name on the server side.
Can i retrieve it from the PlayerObject?

If yes, how?
:?
sidwoo
 
Posts: 13
Joined: November 23rd, 2010, 5:45 pm

Re: How to get the player name on the server

Postby Henrik » December 9th, 2010, 5:54 pm

Yes, that's the best way to do it, but you have to save the name in the PlayerObject yourself. When you've done a simpleConnect and got a client back, do something like this:

Code: Select all
client.bigDB.loadMyPlayerObject(function(playerobject:DatabaseObject):void{
   if (!playerobject.Contains("Username")) {
      playerobject.Set("Username", "the value of the username here...");
      playerobject.Save();
   }
})


...and then on the server-side you should be able to do something like this:

Code: Select all
var username = player.PlayerObject.GetString("Username");
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: How to get the player name on the server

Postby sidwoo » December 9th, 2010, 6:22 pm

ah ok, so save the name to the DB from the client ... it´s a bit weird that you have to do it this way instead of just having access to the player name on the server.

I´ll try it this way, thx!
sidwoo
 
Posts: 13
Joined: November 23rd, 2010, 5:45 pm

Re: How to get the player name on the server

Postby Benjaminsen » December 9th, 2010, 7:33 pm

sidwoo wrote:ah ok, so save the name to the DB from the client ... it´s a bit weird that you have to do it this way instead of just having access to the player name on the server.

I´ll try it this way, thx!


If you use QuickConnect with simple users, you can simply read connectUserId and substring simple from it.
The rest being the username.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: How to get the player name on the server

Postby HAnz » February 25th, 2011, 6:02 pm

I used the code in Henriks example but since it was a mix of AS3 and C# it didn't work. So I fixed it and thought I'd post the proper as3 code in case someone wanted to use the code from this thread in the future. :)

Code: Select all
client.bigDB.loadMyPlayerObject(function(playerobject:DatabaseObject):void{
   if (playerobject.Username == null) {
       playerobject.Username = "the value of the username here...";
       playerobject.save();
   }
})
I make games and stuff.
User avatar
HAnz
 
Posts: 46
Joined: August 7th, 2010, 2:59 pm


Return to QuickConnect



cron