Home > mu_trumps

mu_trumps

Mu_trumps is a project mainly written in RUBY and PYTHON, it's free.

Cannes Midem MHD project

= µTrumps

This is the web service for µTrumps, a game built at Music Hack Day, at the Midem conference in Cannes. It was built by James[http://github.com/jcoglan], Jono[http://github.com/jonocole], Ben[http://github.com/gearmonkey], Joris[http://twitter.com/joriszaalberg] and Gideon[http://twitter.com/gideonb].

To run the service, you need Ruby and these gems:

gem install faye sinatra nokogiri activerecord acts_as_list sqlite3

Initialize the database:

rake db:setup

And run the server:

rackup -s thin -E production -p 8000 config.ru

=== Tasks

rake import:lastfm:top_artists[username] rake import:echonest:hotttnesss rake import:echonest:familiarity rake import:seven_digital:ids

=== Testing

gem install rspec rack-test factory_girl fakeweb rspec -bcf nested spec/

== Service API

The service provides a RESTish interface for interacting with the game engine. This consists of several GET/POST endpoints and a Bayeux messaging service, all of which output JSON.

=== Using the messaging service

In-game events are transmitted to players through a pub/sub messaging service using the Bayeux protocol. Each client should subscribe to a channel for the current game and user, for example /games/1/alice. If you're developing a JavaScript or Ruby client, you can use Faye[http://faye.jcoglan.com] to subscribe to the channel and receive events.

If you don't have a Bayeux client available, you can set up long-polling by building the protocol messages yourself: see https://gist.github.com/795082.

Events are transmitted as the data payload of Bayeux messages, so you can get them using the Faye client:

var fayeClient = new Faye.Client('http://localhost:8000/messaging')

fayeClient.subscribe('/games/1/alice', function(event) { // handle event object })

If you're doing long-polling by hand, you can get the events out of the /meta/connect response by looking for messages with data fields, e.g.:

connect = '{"channel":"/meta/connect","clientId":"' + client_id + '","connectionType":"long-polling"}' response = Net::HTTP.post_form(endpoint, 'message' => connect)

response.body == '[{"channel":"/meta/connect",...},{"channel":"/games/1/alice","data":{"event":"start",...}},...]'

JSON.parse(response.body).each do |message| if message['data'] handle_event(message['data']) end end

Remember to unsubscribe from the game channel when the game is over. See https://gist.github.com/795082 if you need to implement this yourself.

fayeClient.unsubscribe('/games/1/alice')