-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_handler.py
More file actions
33 lines (28 loc) · 789 Bytes
/
server_handler.py
File metadata and controls
33 lines (28 loc) · 789 Bytes
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
import os
import asyncio
import subprocess
import json
class ServerHandler:
async def start(self):
server_argv = [
os.path.join("server", "srcds.exe"),
"-game",
"cstrike",
"+map",
"de_dust2",
"-console",
]
self.server_process = await asyncio.subprocess.create_subprocess_exec(
*server_argv,
cwd="server",
stdout=subprocess.PIPE,
)
async def read(self):
while True:
line = await self.server_process.stdout.readline()
line = line.decode("utf-8")
if not line.startswith("[HIT]"):
continue
line = line[5:]
event = json.loads(line)
return event