-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver.py
More file actions
85 lines (71 loc) · 2.38 KB
/
server.py
File metadata and controls
85 lines (71 loc) · 2.38 KB
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
import argparse
import asyncio
import importlib
from championship import championship, matchAwaiter, rescuer
from inscription import inscription
from logs import getLogger
from state import dumpState
from ui import ui
from utils import get_ip
log = getLogger("server")
async def main(gameName: str, port: int, tempo: float, parall: bool):
log.info("Game Server For {}".format(gameName.capitalize()))
IPAddr = get_ip()
Game = importlib.import_module("games.{}.game".format(gameName)).Game
render = importlib.import_module("games.{}.render".format(gameName)).render
inscriptionTask = asyncio.create_task(inscription(port))
championshipTask = asyncio.create_task(championship(Game, tempo, parall))
stateDumperTask = asyncio.create_task(dumpState())
rescuerTask = asyncio.create_task(rescuer())
matchAwaiterTask = asyncio.create_task(matchAwaiter())
await ui(gameName, render, IPAddr, port)
inscriptionTask.cancel()
try:
await inscriptionTask
except asyncio.CancelledError:
log.info("Inscription Task Stopped")
championshipTask.cancel()
try:
await championshipTask
except asyncio.CancelledError:
log.info("Championship Task Stopped")
stateDumperTask.cancel()
try:
await stateDumperTask
except asyncio.CancelledError:
log.info("State Dumper Task Stopped")
rescuerTask.cancel()
try:
await rescuerTask
except asyncio.CancelledError:
log.info("Rescuer Task Stopped")
matchAwaiterTask.cancel()
try:
await matchAwaiterTask
except asyncio.CancelledError:
log.info("Match awaiter Task Stopped")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("gameName", help="The name of the game")
parser.add_argument(
"-p",
"--port",
type=int,
help="The port the server use to listen for subscription",
default=3000,
)
parser.add_argument(
"-t",
"--tempo",
type=float,
help="value in second. Each move will be, at least, visible during this time.",
default=0.3,
)
parser.add_argument(
"--parall",
action=argparse.BooleanOptionalAction,
help="Don't run match in parallele",
default=True,
)
args = parser.parse_args()
asyncio.run(main(args.gameName, args.port, args.tempo, args.parall))