Exemple #1
0
  def get_game(self, userID):
    # previously matched / player re-entering?
    player_game = _match_maker.lookup_player_game(userID)
    if player_game:
      return player_game

    # look for a new available game
    result = self._get_player_game(userID)

    # found a game?
    if result and 'game' in result:
      player_game = result
      usr = db_api.getUser(userID)
      addPlayers(player_game, userID, usr.displayName)
      return result

    # more players needed to start game?
    if result.get('players_needed_for_next_game', None) > 0:
      return result

    # start a new game
    game = startGame()
    if 'game_state' not in game:
      logging.info('RETURNING RESULT FROM startGame(): %s' % game)
      return game

    logging.info('RETURNING RESULT: %s' % result)
    return result
Exemple #2
0
  def post(self):
    self.response.headers['Access-Control-Allow-Origin'] = '*'
    userID, displayName = self.determine_user()

    usr = db_api.getUser(userID)
    if not usr:
      usr = db_api.newUser(userID, displayName)
    r = {'userID': userID, 'displayName': displayName}

    self.response.write(tojson(r) + '\n')
Exemple #3
0
  def post(self, fcn):
    logging.info('%s ...' % self.request.url)
    if not fcn:
      fcn = self.request.get('fcn')
      if fnc:
        # TODO remove once there are no more uses of ?fcn=... in our code
        logging.warning('Please use /grits/%s/?foo=... instead of /grits/?fcn=%s&foo=...' % (fnc, fnc))
    self.response.headers['Access-Control-Allow-Origin'] = '*'

    userID, displayName = self.determine_user()

    usr = db_api.getUser(userID)
    if not usr:
      if userID.startswith('bot*'):
        usr = db_api.newUser(userID, displayName)
      else:
        self.response.set_status(404)
        self.response.write('Grits userID not found: ' + userID)
        return

    if fcn == 'getProfile':
      r = {'userID': userID, 'credits': str(usr.credits), 'numWins': str(usr.numWins), 'virtualItems': usr.virtualItems}
      self.response.write(tojson(r))
    elif fcn == 'getFriends':
      self.getFriends(userID)
    elif fcn == 'buyItem':
      itemID = self.request.get('itemID')
      if not itemID:
        self.response.set_status(400)
        self.response.write('Grits itemID is required')
        return
      r = db_api.userAttemptToBuy(userID, itemID)
      self.response.write(tojson(r))
    elif fcn == 'findGame':
      self.findGame(userID)
    else:
      self.response.set_status(400)
      self.response.write('Bad grits request.')