diff --git a/byoctf_discord.py b/byoctf_discord.py index 9d33594..5fa52ce 100755 --- a/byoctf_discord.py +++ b/byoctf_discord.py @@ -10,6 +10,7 @@ import time import json import pyfiglet +import math from typing import Union @@ -205,6 +206,13 @@ def renderChallenge(result: dict, preview=False): byoc_rate = SETTINGS.get("_byoc_reward_rate", 0) break_even_solves = (result["cost"] / byoc_rate) // 100 + avg_flag_val = sum([f["flag_value"] for f in result["flags"]])/len(result["flags"]) + + break_even_solves = result["cost"] / avg_flag_val + + + # break_even_solves = result['cost'] / (avg_flag_val * byoc_rate) + msg += f"{'-'*25}\n\n" msg += "Here's a preview:\n\n" msg += f"It will cost `{result['cost']}` points to post with `!byoc_commit`\n" @@ -218,7 +226,7 @@ def renderChallenge(result: dict, preview=False): # byoc validation rendering if preview == True: - msg += f"Reward rate is currently `{byoc_rate}` of flag value which means about `{break_even_solves}` solves will be required to break even.\n\n" + msg += f"Average flag value `{avg_flag_val}`\n\nReward rate is currently `{byoc_rate}` of flag value which means about `{break_even_solves}` solves will be required to break even. _It's possible to break even or profit with enough of partial solves._\n\n" # normal rendering msg += f"**Description**:\n{result['challenge_description']}\n\n" diff --git a/challenge_validator_webapp.py b/challenge_validator_webapp.py index 8963996..d885949 100644 --- a/challenge_validator_webapp.py +++ b/challenge_validator_webapp.py @@ -30,14 +30,17 @@ def create(): @limiter.limit("2/second", override_defaults=False) def validate(): try: + # breakpoint() # print(f'{request.form}') - challenge_object = toml.loads(request.form.get("toml")) + challenge_object = toml.loads(request.form.get("challenge")) except toml.TomlDecodeError as e: - print(e) - return f"error decoding toml: {e}" + # print(request.form.get("challenge")) + print(f"error decoding toml: {e}") + return f"error decoding toml: {e}", 500 except TypeError as e: - print(e) - return f"error parsing toml: {e}" + # print(request.form.get("challenge")) + print(f"error parsing toml: {e}") + return f"error parsing toml: {e}", 500 result = database.validateChallenge(challenge_object) logger.debug(challenge_object)