示例#1
0
  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))
示例#2
0
 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)