++doc ++ game

This commit is contained in:
Nico Schottelius 2019-05-26 22:49:26 +02:00
parent 7272edb7d5
commit 935cf24833
2 changed files with 16 additions and 5 deletions

View File

@ -17,7 +17,7 @@ the project name might change later.
### How to play (for instance on Nico's notebook)
1. Register
1. Register: send a POST request with your username
```
curl -d user=nico http://nico.ungleich.cloud:5002/register
@ -38,7 +38,7 @@ curl http://nico.ungleich.cloud:5002/challenge/registernet
4. Solve a challenge
```
curl -d user=nico -d 2a0a:e5c0:101::/64 http://nico.ungleich.cloud:5002/challenge/registernet
curl -d user=nico -d 2a0a:e5c0:101::/64 http://nico.ungleich.cloud:5002/challenge/RegisterNet
```
5. Get high score

View File

@ -12,8 +12,6 @@ import datetime
from flask import Flask, abort, request, Response
from flask_restful import reqparse
# app = Flask(__name__)
def get_random_ip(network):
net = ipaddress.IPv6Network(network)
addr_offset = random.randrange(2**64)
@ -39,6 +37,16 @@ class Challenge(object):
self.client = etcdclient
def game(self):
# Check if preconditions are met - otherwise error out
# This might need to me moved to the Game class to
# retrieve other challenges that we can recommend
# for req in self.requires:
# path = "/ungleichgame/v1/user/{}/{}".format(user, req)
# try:
# data = self.client.read(path)
# except etcd.EtcdKeyNotFound:
# return None
if request.method == 'GET':
return self.describe()
if request.method == 'POST':
@ -155,11 +163,14 @@ class Game(object):
def list_of_challenges(self):
base = request.base_url
challenges = [ "{} ({})".format(name, "{}/{}".format(base, name)) for name in self.challenge_names ]
return """The following challenges are available on this server:
{}
""".format("\n".join(self.challenge_names))
""".format("\n".join(challenges))
def read_etcd(self, path, recursive=False):