-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.py
72 lines (57 loc) · 1.63 KB
/
server.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
from fastapi import FastAPI
import uvicorn
import os
import base64
import random
import string
curdir = os.path.abspath(os.path.dirname(__file__))
def read_file(path: str) -> str:
with open(path) as f:
return f.read()
ROUND = 1
DEFAULT_CHOOSER = read_file(os.path.join(curdir, "bot", "default_chooser.lua"))
DEFAULT_ACTION = read_file(os.path.join(curdir, "bot", "default_action.lua"))
app = FastAPI()
print("init success")
@app.get("/api/ct/admin/xgame/game/init/")
def init():
req = {
"code": "AD-000000",
"data": {
"teams": [{
"team_id": str(i + 1),
"team_name": f"r{i + 1}kapig",
"score": 500,
"rank": 1
} for i in range(16)]
}
}
return req
@app.get("/api/ct/admin/xgame/game/service/")
def service():
global ROUND
req = {
"code": "AD-000000",
"data": {
"task_id": ''.join(random.sample(string.ascii_letters + string.digits, 32)),
"turn": ROUND,
"teams": [{
"team_id": str(i + 1),
"score": 500,
"select": base64.b64encode(DEFAULT_CHOOSER.encode()).decode(),
"act": base64.b64encode(DEFAULT_ACTION.encode()).decode(),
"rank": 1
} for i in range(16)]
}
}
return req
@app.post("/api/ct/admin/xgame/game/service/")
def service():
global ROUND
ROUND += 1
req = {
"code": "AD-000000",
}
return req
if __name__ == "__main__":
uvicorn.run("server:app")