def get(self): """Renders the main page. When this page is shown, we create a new channel to push asynchronous updates to the client.""" player = users.get_current_user() game = None if player: game_key = player.user_id() game = Game(key_name = game_key, playerA = player, move_state = Game.MOVE_STATE_NOT_STARTED, state = ' ') game.put() game_link = 'http://localhost:8081/join?g=' + game_key token = channel.create_channel(player.user_id() + game_key) template_values = {'token': token, 'me': player.user_id(), 'mode': 2, 'game_key': game_key, 'game_link': game_link, 'initial_message': GameUpdater(game).get_game_message() } path = os.path.join(os.path.dirname(__file__), '../html/game.html') self.response.out.write(template.render(path, template_values)) else: self.redirect(users.create_login_url(self.request.uri))
def get(self): """Renders the main page. """ player = users.get_current_user() if not player: self.redirect(users.create_login_url(self.request.uri)) return all_games = Game.all().filter('last_updated > ', datetime.now() - timedelta(minutes=10)) template_values = { 'me': player, 'games': all_games, 'joinlink': 'http://localhost:8081/join?g=', }; path = os.path.join(os.path.dirname(__file__), '../html/start.html') self.response.out.write(template.render(path, template_values))
def get(self): """Renders the main page. When this page is shown, we create a new channel to push asynchronous updates to the client.""" player = users.get_current_user() game_key = self.request.get('g') game = None if not player: self.redirect(users.create_login_url(self.request.uri)) return if game_key: game = Game.get_by_key_name(game_key) if not game.playerB and game.playerA != player: game.playerB = player game.move_state = Game.MOVE_STATE_READY game.put() else: game = None if not game: self.response.out.write('No such game or cannot join game at this time') return game_link = 'http://localhost:8081/?g=' + game_key token = channel.create_channel(player.user_id() + game_key) template_values = {'token': token, 'me': player.user_id(), 'game_key': game_key, 'game_link': game_link, 'initial_message': GameUpdater(game).get_game_message() } path = os.path.join(os.path.dirname(__file__), '../html/game.html') GameUpdater(game).send_update() self.response.out.write(template.render(path, template_values))
def __init__(self, request): player = users.get_current_user() game_key = request.get('g') if player and game_key: self.game = Game.get_by_key_name(game_key)