++doc ++ game
This commit is contained in:
parent
7272edb7d5
commit
935cf24833
2 changed files with 16 additions and 5 deletions
|
@ -17,7 +17,7 @@ the project name might change later.
|
||||||
|
|
||||||
### How to play (for instance on Nico's notebook)
|
### 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
|
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
|
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
|
5. Get high score
|
||||||
|
|
17
server.py
17
server.py
|
@ -12,8 +12,6 @@ import datetime
|
||||||
from flask import Flask, abort, request, Response
|
from flask import Flask, abort, request, Response
|
||||||
from flask_restful import reqparse
|
from flask_restful import reqparse
|
||||||
|
|
||||||
# app = Flask(__name__)
|
|
||||||
|
|
||||||
def get_random_ip(network):
|
def get_random_ip(network):
|
||||||
net = ipaddress.IPv6Network(network)
|
net = ipaddress.IPv6Network(network)
|
||||||
addr_offset = random.randrange(2**64)
|
addr_offset = random.randrange(2**64)
|
||||||
|
@ -39,6 +37,16 @@ class Challenge(object):
|
||||||
self.client = etcdclient
|
self.client = etcdclient
|
||||||
|
|
||||||
def game(self):
|
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':
|
if request.method == 'GET':
|
||||||
return self.describe()
|
return self.describe()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -155,11 +163,14 @@ class Game(object):
|
||||||
|
|
||||||
|
|
||||||
def list_of_challenges(self):
|
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:
|
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):
|
def read_etcd(self, path, recursive=False):
|
||||||
|
|
Loading…
Reference in a new issue