Skip to content

Commit

Permalink
validator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyftXero committed Sep 20, 2023
1 parent c190b1b commit 4e86975
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 9 additions & 1 deletion byoctf_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
import json
import pyfiglet
import math

from typing import Union

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
13 changes: 8 additions & 5 deletions challenge_validator_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4e86975

Please sign in to comment.