-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
67 lines (58 loc) · 2.32 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
from amstramdam import app, manager, socketio, IS_LOCAL, CONF, dataloader
import os
from argparse import ArgumentParser
certfile = "extra/certif.crt"
keyfile = "extra/certif.key"
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
"-d", "--debug", help="Enable live-reloading", action="store_true"
)
args = parser.parse_args()
kwargs = dict(host="0.0.0.0")
if IS_LOCAL and not CONF["disableSSL"]:
kwargs["certfile"] = certfile
kwargs["keyfile"] = keyfile
kwargs["port"] = int(os.environ.get("PORT", 8000))
else:
kwargs["port"] = int(os.environ.get("PORT", 80))
if args.debug:
kwargs["debug"] = True
check_loading = False
debug_game = True
message = "Live-reloading enabled"
if debug_game:
name, game = manager.create_game(
dataset_name="paris_subway",
n_runs=3,
is_permanent=True,
duration=5,
map="paris_subway",
wait_duration=4,
force_name="__debug__",
)
for _ in range(3):
game.add_player(nickname=None)
message += ", debug game created at https://localhost/game/__debug__"
if check_loading:
with open("dataset.log", "w", encoding="utf8") as f:
errors = set()
for G in dataloader.get_datasets():
print("\n", G["group"], file=f)
for m in G["maps"]:
for level in m["levels"]:
print(m["name"], level["name"], file=f)
try:
_, game = manager.create_game(
dataset_name=m["map_id"], difficulty=level["index"]
)
print(game, file=f)
except Exception as e:
print("ERROR", e, file=f)
errors.add(m["name"])
print(len(errors), "errors", file=f)
print(*errors, file=f)
message += f", {len(errors)} error(s) found when loading datasets"
print(message)
print(manager.get_public_games())
socketio.run(app, **kwargs)