Please sign in.
"); + return; + } + + // 1. Create or fetch a Game object from the datastore + Objectify ofy = ObjectifyService.ofy(); + Game game = null; + String userId = userService.getCurrentUser().getUserId(); + if (gameKey != null) { + game = ofy.load().type(Game.class).id(gameKey).safe(); + if (game.getUserO() == null && !userId.equals(game.getUserX())) { + game.setUserO(userId); + } + ofy.save().entity(game).now(); + } else { + // Initialize a new board. The board is represented as a String of 9 spaces, one for each + // blank spot on the tic-tac-toe board. + game = new Game(userId, null, " ", true); + ofy.save().entity(game).now(); + gameKey = game.getId(); + } + + // 2. Create this Game in the firebase db + game.sendUpdateToClients(); + + // 3. Inject a secure token into the client, so it can get game updates + + // The 'Game' object exposes a method which creates a unique string based on the game's key + // and the user's id. + String token = FirebaseChannel.getInstance().createFirebaseToken(game, userId); + request.setAttribute("token", token); + + // 4. More general template values + request.setAttribute("game_key", gameKey); + request.setAttribute("me", userId); + request.setAttribute("channel_id", game.getChannelKey(userId)); + request.setAttribute("initial_message", new Gson().toJson(game)); + request.setAttribute("game_link", getGameUriWithGameParam(request, gameKey)); + getServletContext().getRequestDispatcher("/WEB-INF/view/index.jsp").forward(request, response); + } +} diff --git a/appengine/firebase-tictactoe/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/firebase-tictactoe/src/main/webapp/WEB-INF/appengine-web.xml new file mode 100644 index 00000000000..60505d89c7a --- /dev/null +++ b/appengine/firebase-tictactoe/src/main/webapp/WEB-INF/appengine-web.xml @@ -0,0 +1,34 @@ + + +