-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_.py
142 lines (113 loc) · 3.81 KB
/
_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from flask import *
from Game import *
from flask_cors import CORS, cross_origin
Gy = dict()
app = Flask(__name__)
CORS(app)
# Home page which will redirect to docs currently cause that's there
@app.route('/')
def index():
return redirect(url_for('docs'))
#404 error henadler with a template from /templates
@app.errorhandler(404)
def err(e):
return render_template('/error.html')
#Index redirects here
@app.route('/docs')
def docs():
return render_template('/index.html')
#A wrong call requese homie , So for the first one we give an error
@app.route('/api/game/', methods=['GET'])
def dummy():
ga = {"message": "Wrong request,please refer to the docs", "URL": "idk"}
return respor(ga)
# A game init call request which specifies the name and other things of taht matter
@app.route('/api/game/', methods=['POST'])
def start():
if not request.json:
abort(400)
inz = json.loads(request.data)
if inz["name"] in Gy and Gy[inz["name"]].id!=request.remote_addr:
return respor({"error": "user already here"})
try:
Gy[inz["name"]] = Game(request.remote_addr, inz["complexity"], inz["name"])
except:
abort(500, error_message="User already")
return respor({"status": "user created"})
@app.route('/api/game/<string:id>', methods=['POST'])
def begin(id):
if not request.json:
abort(400)
inz = json.loads(request.data)
Gy[id].start(inz["choices"],inz["charecters"],inz["levels"])
return respor({"status": "game created"})
# For the game config the api request[POST] data : choices<n,1> confidence
@app.route('/api/game/<string:id>/playconfig', methods=['POST'])
def iconfig(id):
if not request.json:
abort(400)
inz = json.loads(request.data)
result = Gy[id].whome(inz["choices"], inz["confidence"])
return respor(result)
@app.route('/api/game/<string:id>/disc', methods=['POST'])
def disc(id):
if not request.json:
abort(400)
inz = json.loads(request.data)
result = Gy[id].discu(inz["Name"])
return respor(result)
@app.route('/api/game/<string:id>/inf', methods=['POST'])
def inf(id):
if not request.json:
abort(400)
inz = json.loads(request.data)
result = Gy[id].pinf(inz["Name"])
return respor(result)
@app.route('/api/game/<string:id>/upday', methods=['GET'])
def upday(id):
result = Gy[id].upday()
return respor(result)
@app.route('/api/game/<string:id>/unt', methods=['GET'])
def utd(id):
result = Gy[id].utd()
return respor(result)
@app.route('/api/game/<string:id>/day', methods=['GET'])
def day(id):
result = Gy[id].daystat()
return respor(result)
@app.route('/api/game/<string:id>/me', methods=['GET'])
def me(id):
result = Gy[id].pstat()
return respor(result)
@app.route('/api/game/<string:id>/kar/<string:name>', methods=['GET'])
def du(id,name):
result = Gy[id].cstat(name)
return respor(result)
@app.route('/api/game/<string:id>/undi/<string:name>', methods=['GET'])
def undie(id,name):
result = Gy[id].undistancedu(name)
return respor(result)
@app.route('/api/game/<string:id>/di/<string:name>', methods=['GET'])
def dies(id,name):
result = Gy[id].distancedu(name)
return respor(result)
@app.route('/api/game/<string:id>/trusty/<string:name>', methods=['POST'])
def duonly(id,name):
if not request.json:
abort(400)
inz = json.loads(request.data)
result = Gy[id].trusty(name,inz["trust"])
return respor(result)
#Init callable function else will be set to random
@app.route('/api/game/<string:id>/wholetrusty/<string:name>', methods=['POST'])
def wholes(id,name):
if not request.json:
abort(400)
inz = json.loads(request.data)
result = Gy[id].doawholetrusty(inz["tmatrix"])
return respor(result)
def respor(dic):
resp = jsonify(dic)
resp.status_code = 200
return resp
app.run('0.0.0.0')