Forum Multiplayer Temporarily saving guest data

Discussion and help relating to the PlayerIO Multiplayer API.

Temporarily saving guest data

Postby wgfunstorm » September 23rd, 2012, 12:43 am

When a guest connects, I want to start saving their data on the server. When a guest disconnects, I want to delete their data from the server.

How can I delete the data when the guest disconnects?

I can't use the UserLeft server method because a guest may play multiple games across different rooms.
wgfunstorm
 
Posts: 16
Joined: January 21st, 2012, 4:10 pm

Re: Temporarily saving guest data

Postby dreamora » September 23rd, 2012, 9:42 am

when you want the data to vanish when a user disconnects, never store the PlayerObject at all, just use it on the player object in your server code.
The server will then handle that for you.

If you handle the data on the client you can't do it, as the client disconnected already. But I would never 'write' data from the client anyway, only from the server, as clients aren't to be trusted.
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am

Re: Temporarily saving guest data

Postby wgfunstorm » September 23rd, 2012, 10:43 am

If I don't store the playerobject, the data is lost when the guest switches rooms. I want to save it across rooms, and only forget it upon disconnect. And yea, like you said I can't trust the client so I won't do it that way either.
wgfunstorm
 
Posts: 16
Joined: January 21st, 2012, 4:10 pm

Re: Temporarily saving guest data

Postby dreamora » September 23rd, 2012, 11:03 am

Ah you will have room switching.

In that case you will indeed need to save it and you will likely want to use a special room type to which the player connect that only does 'save the player object' upon the connecting and when disconnecting it deletes the player object again.

You will then connect the player to this room first and afterwards to the 'real rooms' you have

Using a service-room would then be best to use for this room type
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am

Re: Temporarily saving guest data

Postby wgfunstorm » September 23rd, 2012, 9:41 pm

Interesting work around... so guests would be connected to 2 rooms at once: one for storing / deleting data and another for gameplay. This appears to work, and is pretty easy for me to implement since I already secretly connect players to a service room right away so I can show info / let them shop / etc from the main menu. So I would just need to keep that connection alive and do the saving / deleting there.

But I have 1 reservation / question: does 1 player connected to 2 rooms count as 1 or 2 users when it comes to playerio pricing?

I have also been playing around with a second option: storing guest data in a custom bigdb table (not playerobject) along with a 'last message received' datetime index that I can then use to delete old entries every few days.

Can anyone think of reasons why option 2 is better / worse than option 1?
wgfunstorm
 
Posts: 16
Joined: January 21st, 2012, 4:10 pm

Re: Temporarily saving guest data

Postby Benjaminsen » September 24th, 2012, 5:51 pm

wgfunstorm wrote:....
But I have 1 reservation / question: does 1 player connected to 2 rooms count as 1 or 2 users when it comes to playerio pricing?
....


It would count as two users.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Temporarily saving guest data

Postby Benjaminsen » September 24th, 2012, 5:55 pm

As determining if a guest is switching rooms or disconnecting is practically impossible, the best way would be to have an updated timestamp on guest user types.

IE, every time a guest connects to a room you update said timestamp. Then deleting no longer used guest database objects is a simple matter og doing a simple deleteRange on the table. IE, delete all objects which have not been touched in say, 30 days.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark


Return to Multiplayer