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 { + 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 channelId = game.getChannelKey(userId); + String token = FirebaseAuth.getInstance().createCustomToken(channelId); + req.setAttribute("token", token); + + // 4. More general template values + req.setAttribute("game_key", gameKey); + req.setAttribute("me", userId); + req.setAttribute("channel_id", channelId); + req.setAttribute("initial_message", game.getMessageString()); + req.setAttribute("game_link", getGameUriWithGameParam(req, gameKey)); + req.setAttribute("firebase_snippet", game.sFirebaseSnippet); + getServletContext().getRequestDispatcher("/WEB-INF/view/index.jsp").forward(req, resp); + } +} 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..cb581be56c4 --- /dev/null +++ b/appengine/firebase-tictactoe/src/main/webapp/WEB-INF/appengine-web.xml @@ -0,0 +1,35 @@ + + +