Documentation

Today's Goals

Today's code: https://bitbucket.org/magicchicken/webgameserver/src

  • Create user profiles in our database.
  • Connect users authenticated by a third-party to database profiles
  • Update Server Application to let users play the game
  • Game updates the score for the current user

Updates to Server Application

  • We're updating our mongodb module to version 1.2.13 (Because it's where I found good documentation).
  • This has some API changes (of course). Updates to our MongoDB module
  • npm install (to update version)
  • Removed login page. Authentication is done on the home page now (index.ejs)
  • Removed top-ten page. It is now displayed on the home page as well.

Managing Player Profiles

  • connect "users" collection
  • Update authentication methods: find or create local user
    • Previously we would just return the profile given to us by Google or Facebook.
    • We now try to find an existing user in our database that has been mapped to one of these profiles
      • With Google, we map using .openId
      • With Facebook, we map using .facebookId
    • if none exists then we create a new user in our database
    • MongoDB takes care of creating unique Ids for each user under ._id
  • Now we can log in through Google/Facebook, create a new account, log out, log back in through existing account!

Serving your game

  • Wait for user to be logged in before creating canvas and loading the game
  • Required to have game states now: Main Menu, Gameplay, and Game Over (to post our scores)
  • Game needs to be able to post data to the server (to update player scores)

Leaderboards

  • Displaying top-ten scores (basically same as before - updated code taken from mikey).
  • Submitting a new score through our game by using JQuery.
  • BUG - Updating the score causes us to create a new entry!

Updating for Heroku

Setting up environment variables - https://devcenter.heroku.com/articles/config-vars

Update your Facebook App and Google variables to use your Heroku app URL.

If you're just using Local then you should already be done!

Homework

  • Have a collection for storing user accounts in your database.
  • Have at least one form of authentication method working (Facebook, Google, Local, whatever).
  • Have authenticated users get mapped to a user profile in your database.
  • Have your webserver serving your game (up to you if your user has to be authenticated to play it).
  • Have server application running on Heroku
  • Send me an email with a link to the git repository to your server application (if it's different) and to your Heroku app (once it's up)!

Optional exercises / think about

  • Could we have a better sign-in flow?
  • Option to delete a single account (instead of clearing all users)
  • Say someone created an account with Google. Then support connecting their's existing account with facebook.
  • Alternative database layouts? Should we have game data in a separate collecton from profile data? What about for anticipating achievements?