Skip to content

Commit

Permalink
feat: Add coins field to Problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mradigen committed Dec 24, 2023
1 parent 8ed2f75 commit d3a7494
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/pwncore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class Config:
config = Config(
development=True,
db_url="sqlite://:memory:",
# docker_url=None, # None for default system docker
docker_url=None, # None for default system docker
# Or set it to an arbitrary URL for testing without Docker
docker_url="http://google.com",
# docker_url="http://google.com",
flag="C0D",
max_containers_per_team=3,
jwt_secret="mysecret",
Expand Down
2 changes: 2 additions & 0 deletions src/pwncore/models/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Problem(Model):
points = fields.IntField()
author = fields.TextField()

coins = fields.IntField(default=0)

image_name = fields.TextField()
image_config: fields.Field[dict[str, list]] = fields.JSONField() # type: ignore[assignment]

Expand Down
8 changes: 7 additions & 1 deletion src/pwncore/routes/ctf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ async def ctf_list():
return problems


@atomic()
@router.post("/{ctf_id}/flag")
async def flag_post(ctf_id: int, flag: Flag, response: Response, jwt: RequireJwt):
team_id = jwt["team_id"]
problem = await Problem.exists(id=ctf_id)
problem = await Problem.get_or_none(id=ctf_id)
if not problem:
response.status_code = 404
return {"msg_code": config.msg_codes["ctf_not_found"]}
Expand All @@ -57,6 +58,11 @@ async def flag_post(ctf_id: int, flag: Flag, response: Response, jwt: RequireJwt
)
if check_solved:
await SolvedProblem.create(team_id=team_id, problem_id=ctf_id)

team = await Team.get(id=team_id)
team.coins += problem.coins
await team.save()

return {"status": True}
return {"status": False}

Expand Down
14 changes: 1 addition & 13 deletions src/pwncore/routes/ctf/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import uuid
from tortoise.transactions import atomic

from pwncore.models import Problem, Container, Ports, Team
from pwncore.models import Problem, Container, Ports
from pwncore.container import docker_client
from pwncore.config import config
from pwncore.routes.auth import RequireJwt
Expand All @@ -25,18 +25,6 @@ async def start_docker_container(ctf_id: int, response: Response, jwt: RequireJw
}
}
"""
if config.development:
await Problem.create(
name="Invisible-Incursion",
description="Chod de tujhe se na ho paye",
author="Meetesh Saini",
points=300,
image_name="key:latest",
image_config={"PortBindings": {"22/tcp": [{}]}},
)
await Team.create(
name="CID Squad" + uuid.uuid4().hex, secret_hash="veryverysecret"
)

ctf = await Problem.get_or_none(id=ctf_id)
if not ctf:
Expand Down

0 comments on commit d3a7494

Please sign in to comment.