Example #1
0
    def post(self):
        request_data = json.loads(self.request.body)
        logging.info(request_data)
        player = current_user_player()

        # VALIDATION
        if not validate_request_data(self.response, request_data, ['type']):
            return
        if player.doing:
            error_400(self.response, "ERROR_PLAYER_BUSY", "Player is busy.")
            return

        # JOIN QUEUE
        match_queue_key = MatchSoloQueue(
            player=player.key,
            type=request_data['type']
        ).put()

        player.doing = match_queue_key
        player.put()

        ndb.get_context().clear_cache() # If it is not cleared the following count of queued players wont count this
        match_queue = match_queue_key.get()
        self._notify_players_new_queue_size(match_queue.type)
        set_json_response(self.response, {'doing': match_queue.get_data()})