Category Archives: Uncategorized

Fair Dice in Google+ Hangouts

I’ve been using Google+ Hangouts a lot, to keep up with friends and do business, so I decided to try my hand at creating a game for their API.  Because the act of rolling dice seems like a common thing to want to do, I thought I would share my approach and a library that implements it.

In the game I’m working on, I require people to be able to make dice rolls.  A naive implementation would have the users’ clients perform the random number generation, and then update the shared state object with the result.  However, since the game runs fully in the browser and is Javascript, a simple random number generator for each player would be very easy to “cheat” by simply using the browser’s developer tools to override the function to always return, say, a 20.

My implementation works a differently in order to prevent tampering. Every time an update is made to the shared state, the key that was changed is timestamped with a millisecond resolution by the server. This is recorded in the metadata for the update.  Because this has millisecond resolution, it is sufficiently indeterminate enough to act as a random seed.  To actually roll the dice, I send a submitDelta request to the hangouts API with a common key (in this case “HangoutDice.roll”) and a value containing the information on the number and type of dice requested. This will then call the onStateChanged handler with notification of the key’s change. All of the clients can then take the timestamp from the metadata of the key, use it to seed a pure JS RNG, and determine what the roll was.  The seeded RNG allows all clients to independently determine the roll with the same results.  This results in a very cheat-resistant, distributed dice roller.

The javascript library can be found here: https://github.com/jaswope/hangout-dice

You can start a hangout using the library here: http://dice.finalmeasure.com/dice-game/

Please note that at this time there is no good way to share a Hangouts app with other people. The only way for anyone to install it is to create a hangout with the link above, and then click on the app’s button in the hangout. There is no way to share it with other people in a hangout, even if you start it with the above link and then invite others to it.  The other participants will have to use the link at least once before it is available.

Chrome Campfire Notifications

I ended up getting one of those nifty Cr-48 laptops that Google has been giving out. I haven’t written anything about it because, well, it’s like using Chrome. If you’ve used the browser (and especially if you’re a power user) you won’t find much new. There’s very little that I do outside of the context of a browser, and if I consider the Chrome OS laptop my portable machine (to be used in conjunction with a desktop), there’s really nothing that can’t be done online.

The one thing I do miss from the desktop world is desktop notification systems (like Growl, or the native Windows/Linux ones) that I could use with my native Campfire clients. Luckily Chrome (and by extension Chrome OS) supports desktop notifications natively as well, so I created an extension that will take care of this in the browser-only world of Chrome.

Chrome Campfire Notifications is very bare bones at the moment, but I plan to release updates to allow for some amount of configuration. It does work as advertised, though, giving you notifications when Campfire messages come through.