Forum Showroom Presence server example

Show your interesting finds or creations off here.

Presence server example

Postby Benjaminsen » July 12th, 2010, 5:55 pm

I wrote a presence server as an example.

What does it do?
The system allows you to send messages to any online user without having to worry about the 45 online players, in one room limit. The system works by connecting all users to special "presence rooms". When a user then wishes to send a message to [userid] the user ask BigDB where the user is connected, connect to that specific server and parses the message.

If you send a message to a user that is not online. The message will just be lost.

I want it!
Download project here.

How do I use it?
The client is written using Flash Builder 4; but PresenceExample.as can be used as the base class for a traditional Adobe Flash project.

Getting started
Before you start you want to open presence/Presence.as and change client.multiplayer.developmentServer = "n.c:8184" to use your local development server. Although the game has a declared gameid, I did not upload the DLL to Player.IO so trying to use this example on prod without uploading your own server and changing the gameid will result in an error.

Some details
All Presence related code is isolated into a single class called Presence and the system can be used as is - without any code modifications. The only thing you will have to do is compile and upload the DLL using servertype presence and change the gameid to one of your own.

Known Limitations
You could use this system to send all your online friends an "I am online" message when you connect. You can however not use it to send an "I am offline" message if the user just closes their browser. For that single feature you will have to wait for a real presence system.

Peace out
/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Presence server example

Postby markloika » July 12th, 2010, 7:44 pm

This looks awesome Chris, thanks for posting it.

Mark
markloika
 
Posts: 76
Joined: July 8th, 2010, 3:46 am

Re: Presence server example

Postby antfarmglobal » February 11th, 2011, 12:46 am

Any developments on the Global Presense System being integrated into PlayerIO?
antfarmglobal
 
Posts: 1
Joined: February 9th, 2011, 2:17 am

Re: Presence server example

Postby Oliver » February 18th, 2011, 3:21 pm

Any developments on the Global Presense System being integrated into PlayerIO?


No :-)
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Presence server example

Postby itsmylifesoham » August 16th, 2011, 7:28 am

Hi benjaminsen,

first of all thanks for writing this nice example project.
You mentioned :

"Known Limitations
You could use this system to send all your online friends an "I am online" message when you connect. You can however not use it to send an "I am offline" message if the user just closes their browser."

So can we do something like this :

When a user just closes his browser, in the server side code the userleft() gets called right?
So in this userleft() apart from the code that you have added to remove the online status, we could send a message from the userleft() to any other player who is online in this room instance(say "notifyAllAboutTheLeftUserOnMyBehalf , player.connectuserId ") now the user who receives this message will notify all the room instances by joining them recursively(the hacky hacky method that you have mentioned) and notify all the clients about the user who has left.

The only problem will come when the last user in the room leaves.

I was thinking i could persist an admin (my webserver will be a client in one of the service rooms) in one of the presencerooms. Whenever new rooms come up, and a user joins in them, they will notify the user with id "admin" the count of players in the new room, if the admin finds that the count is say 1 , he will join that room also, to transmit the message on behalf of the last person if he leave, after that action admin will disconnect.

Does this sound okay, or is there any problem with this scheme?

Regards
Soham
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Presence server example

Postby Benjaminsen » August 16th, 2011, 5:45 pm

Hey Soham

The method you have come up with have a few issues on it's own. As you point out yourself, when the last user leaves a room all persistence is lost. Even worse you are suddenly trusting users to correctly reporting status of other users, something that would be very open to abuse. It would also be unreliable at best, as you have no guraentee that the message would propagate to all servers. Lastly, the traffic volume grows exponentially as your user base does, putting a very real limit to how many people you can have online at any one time.

Personally I use a much updated version of the above code, sadly I have not had time to isolate the code in a neat example but the basics are as follows:

1: Each user connects to a room with their userid as room id. This allows you to always know where a user is without doing a BigDB lookup first. IE if you want to talk to the user fb1234 you simply connect to fb1234 where the specific user will be if online.

2: Although the above system does not allow you to broadcast an "user went offline" message, it does not mean it cannot be used for such. The property onlineStatus is removed from the user when the user leaves the room. Thus you could do a 30 second BigDB lookup to see if all your friends are still online. Thus in worst case it would be 30 secs before users would be told that their friends have left the game.

3: As an extension to point 2: You could do quicker lookups for users the player have shown an interest in. IE if I click you in my user list, the system could either connect to my service room to see if I where online or do a BigDB lookup to the same effect.

Best
Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Presence server example

Postby itsmylifesoham » August 16th, 2011, 6:02 pm

Thats even better, i liked these methods.

However the number of "presence" rooms = number of players online. Is it inefficient to have so many rooms open?

Also looking up in bigdb every30 sec, does it create extra load?

Thanks :D
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Presence server example

Postby Benjaminsen » August 16th, 2011, 6:16 pm

It's not the most efficient way of setting up a presence system, thus it might not be cost effective for you, depending on your revenue per player. For my games its a negligible cost.

Likewise, yes constantly reloading BigDB will take up quite some traffic. It's worth considering having a separate BigDB table just with online statuses. Again, if your game generates reasonable revenue, this will not be a huge cost factor.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Presence server example

Postby itsmylifesoham » August 17th, 2011, 10:34 am

One more thing, in relation to point number 2 that you mentioned, about reloading bigdb objects every 30 sec. Now lets say each user joins his own personal presence room which has a name as his <userid> as you mentioned in point 1. So when a user leave there is no presence room by his name right.

I was thinking would reloading the BIGdb every 30 sec be a better option for all the users registered in my game, or just doing a client.multiplayer.listrooms(<type "presence">) and updating my online players list in my UI with the names of these rooms(which is same as names of userids) be a better option.

thanks
Soham
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Presence server example

Postby Benjaminsen » August 18th, 2011, 5:52 pm

itsmylifesoham wrote:One more thing, in relation to point number 2 that you mentioned, about reloading bigdb objects every 30 sec. Now lets say each user joins his own personal presence room which has a name as his <userid> as you mentioned in point 1. So when a user leave there is no presence room by his name right.

I was thinking would reloading the BIGdb every 30 sec be a better option for all the users registered in my game, or just doing a client.multiplayer.listrooms(<type "presence">) and updating my online players list in my UI with the names of these rooms(which is same as names of userids) be a better option.

thanks
Soham


This will work for small games. But what happens when you have 10.000 people online?
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Presence server example

Postby jasonMcIntosh » September 4th, 2011, 10:13 pm

Oliver wrote:
Any developments on the Global Presense System being integrated into PlayerIO?


No :-)


Bummer. This is a pretty important piece of functionality since friends are a huge factor in what games you play. I hope you guys will consider it, and put it on the todo list since we don't have a way to robustly provide it ourselves. Even just giving us access to infrastructure to code it ourselves would be great.
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: Presence server example

Postby aseemgarg321 » August 8th, 2015, 9:49 pm

The Download link doesn't seem to work any more.. Will it be possible to upload it again?

Thanks,
Aseem
aseemgarg321
 
Posts: 104
Joined: March 28th, 2015, 9:54 am


Return to Showroom



cron