예제 #1
0
def appAugmentFreestyle(environ, start_response):
    data = util.get_json_post(environ)
    user = storage.get_user_by_sessid(data.sessid)
    if user is None:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You are not logged in.")]
    logger.bigbrother("/augment/freestyle", user, environ)
    if ratelimiter.get_suspicion_counter(user.id) >= 3:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("Bot verification failed.")]
    state = augment.state(user.id)
    if data.augment_id != state.sid:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [
            util.err_json(
                "This augmentation has expired or does not exist. Did you open this page in multiple tabs? You can only do one augmentation at a time!"
            )
        ]
    token_cost = 12
    tokens = augment.get_balance(user.id)
    if tokens < token_cost:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You don't have enough augmentation tokens.")]
    tokens -= token_cost
    augment.subtract_balance(user.id, token_cost)
    augment.freestyle(user.id)
    result = {
        "success": True,
        "augment_id": state.sid,
        "type": "freestyle",
        "balance": tokens
    }
    start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
    return [util.json_bytes(result)]
예제 #2
0
def appAugmentReroll(environ, start_response):
    data = util.get_json_post(environ)
    user = storage.get_user_by_sessid(data.sessid)
    if user is None:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You are not logged in.")]
    logger.bigbrother("/augment/reroll", user, environ)
    if ratelimiter.get_suspicion_counter(user.id) >= 3:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("Bot verification failed.")]
    token_cost = 4
    tokens = augment.get_balance(user.id)
    if tokens < token_cost:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You don't have enough augmentation tokens.")]
    tokens -= token_cost
    augment.subtract_balance(user.id, token_cost)
    state = augment.reroll(user.id)
    result = {
        "success": True,
        "type": state.type,
        "max_length": state.max_length,
        "context": "",
        "augment_id": state.sid,
        "balance": tokens
    }
    start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
    return [util.json_bytes(result)]
예제 #3
0
def appAugmentInfo(environ, start_response):
    data = util.get_json_post(environ)
    user = storage.get_user_by_sessid(data.sessid)
    if user is None:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You are not logged in.")]
    logger.bigbrother("/augment/info", user, environ)
    captcha_needed = ratelimiter.get_suspicion_counter(user.id) >= 3
    q = storage.sql(
        """
        SELECT visited_kingdoms
        FROM progress
        WHERE user_id = ?
    """, (user.id, ))[0]
    result = {
        "success":
        True,
        "captcha":
        captcha_needed,
        "augmentables": [
            x for x in json.loads(q.visited_kingdoms)
            if x in config.AUGMENTABLE_KINGDOMS
        ]
    }
    start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
    return [util.json_bytes(result)]
예제 #4
0
def appAugmentBegin(environ, start_response):
    data = util.get_json_post(environ)
    user = storage.get_user_by_sessid(data.sessid)
    if user is None:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You are not logged in.")]
    logger.bigbrother("/augment/begin", user, environ)
    if ratelimiter.get_suspicion_counter(user.id) >= 3:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("Bot verification failed.")]
    if data.kingdom not in config.AUGMENTABLE_KINGDOMS and data.kingdom != '@':
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("Trying to augment an unknown kingdom.")]
    if ratelimiter.check_timeout("begin_augment", user.id,
                                 config.RATELIMIT_AUGMENT):
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You can only augment once every 30 seconds.")]
    ratelimiter.save_current_time("begin_augment", user.id)
    token_cost = 4
    if data.kingdom != '@':
        token_cost = 8
    tokens = augment.get_balance(user.id)
    if tokens < token_cost:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You don't have enough augmentation tokens.")]
    tokens -= token_cost
    augment.subtract_balance(user.id, token_cost)
    state = augment.begin(user.id, data.kingdom)
    result = {
        "success": True,
        "type": state.type,
        "max_length": state.max_length,
        "context": "",
        "augment_id": state.sid,
        "balance": tokens
    }
    start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
    return [util.json_bytes(result)]
예제 #5
0
def appAugmentFinish(environ, start_response):
    data = util.get_json_post(environ)
    user = storage.get_user_by_sessid(data.sessid)
    if user is None:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("You are not logged in.")]
    logger.bigbrother("/augment/finish", user, environ)
    if ratelimiter.get_suspicion_counter(user.id) >= 3:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json("Bot verification failed.")]
    state = augment.state(user.id)
    if data.augment_id != state.sid:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [
            util.err_json(
                "This augmentation has expired or does not exist. Did you open this page in multiple tabs? You can only do one augmentation at a time!"
            )
        ]
    try:
        augment.verify(user.id, data.word.lower())
    except augment.VerificationError as e:
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [util.err_json(str(e))]
    if checks.is_word_filtered(
            data.word.lower()) and state.type != 'freestyle':
        start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
        return [
            util.err_json(
                "Even though this is a dictionary word, we must ask you to enable freestyle mode to enter this phrase. This is to prevent users from filling the system with profanity by using cheap, cost effective random augmentations."
            )
        ]
    augment.store(user.id, data.word)
    ratelimiter.increment_suspicion_counter(user.id)
    tokens = augment.get_balance(user.id)
    result = {"success": True, "balance": tokens}
    start_response('200 OK', HEADERS_JSON + HEADERS_CORS)
    return [util.json_bytes(result)]