cardstories part 8 : invitations

The invitations were implemented, server and client side. They can be sent immediately after the author of the game defined it. A skin gallery was introduced to facilitate further integration works.

server

The invite function was added to the webservice with action=invite followed by multiple player_id. For instance:

action=invite&owner_id=myself&game_id=5&player_id=firstfriend&player_id=secondfriend

The server was modified to add a new table that stores the pending invitations for a given game:

            c.execute(
                "CREATE TABLE invitations ( "
                "  player_id INTEGER, "
                "  game_id INTEGER"
                "); ")

The authentication module has been updated to translate multiple player ids (i.e. multiple player_id parameters).
A pending invitation is canceled when a user chose to participate in the game. All pending invitations are canceled when the game goes to the vote state.

client

The invitation page has been integrated and the corresponding function added to /jquery.cardstories.js:

        advertise: function(owner_id, game_id, root) {
            var $this = this;
            var element = $('.cardstories_advertise', root);
            this.set_active(root, element);
            $('.cardstories_submit', element).unbind('click').click(function() {
                var text = $('.cardstories_text', element).val();
                var invites = text.split(/\s+/).
                              filter(function(s) { return s !== ''; }).
                              map(function(s) {
                                  return 'player_id=' + encodeURIComponent(s);
                                });

                $this.send(owner_id, game_id, element, 'action=invite&owner_id=' + owner_id + '&game_id=' + game_id + '&' + invites.join('&'));
              });
        },

The previous workflow was modified so that it is called after the sentence for the game is validated by the game author.

skin gallery

In order to make it easier to check the layout of a specific state in the game, the skin=XXX argument has been added. When provided, instead of running the game, the function XXXX from skin.js is called. The purpose of these functions are merely to mockup a state of the game and call the relevant display function to reveal the desired layout.