2015-11-10 16:23:58 +00:00
|
|
|
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
|
2015-11-10 16:23:58 +00:00
|
|
|
|
|
|
|
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():
|
2015-11-10 16:23:58 +00:00
|
|
|
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
|
|
|
g.redis.hincrby("solves", challenge.id, 1)
|
2016-05-27 01:58:31 +00:00
|
|
|
if config.immediate_scoreboard:
|
|
|
|
g.redis.delete("scoreboard")
|
|
|
|
g.redis.delete("graph")
|
2015-11-10 16:23:58 +00:00
|
|
|
ChallengeSolve.create(team=team, challenge=challenge, time=datetime.now())
|
|
|
|
return SUCCESS
|