ColdCore/utils/flag.py

31 lines
1.3 KiB
Python
Raw Normal View History

from database import Challenge, ChallengeSolve, ChallengeFailure
from flask import g
from ctferror import *
from datetime import datetime
import config
def submit_flag(team, challenge, flag):
if g.redis.get("rl{}".format(team.id)):
2016-05-22 20:09:57 +00:00
delta = config.competition_end - datetime.now()
2016-05-27 01:29:08 +00:00
if delta.total_seconds() > (config.flag_rl * 6):
2016-05-22 20:09:57 +00:00
return FLAG_SUBMISSION_TOO_FAST
if team.solved(challenge):
return FLAG_SUBMITTED_ALREADY
2015-12-03 23:18:00 +00:00
elif not challenge.enabled:
return FLAG_CANNOT_SUBMIT_WHILE_DISABLED
2016-05-15 20:14:11 +00:00
elif flag.strip().lower() != challenge.flag.strip().lower():
g.redis.set("rl{}".format(team.id), str(datetime.now()), config.flag_rl)
ChallengeFailure.create(team=team, challenge=challenge, attempt=flag, time=datetime.now())
return FLAG_INCORRECT
else:
2015-12-03 23:18:00 +00:00
if int(g.redis.hget("solves", challenge.id).decode()) == 0:
if challenge.breakthrough_bonus:
ScoreAdjustment.create(team=team, value=challenge.breakthrough_bonus, reason="First solve for {}".format(challenge.name))
g.redis.hincrby("solves", challenge.id, 1)
2016-03-14 02:54:30 +00:00
g.redis.delete("scoreboard")
g.redis.delete("graph")
ChallengeSolve.create(team=team, challenge=challenge, time=datetime.now())
return SUCCESS