-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.py
88 lines (70 loc) · 2.76 KB
/
test.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
import json
import os
from pathlib import Path
import asyncio
if __name__ == "__main__":
async def run_server_connection(reader, writer):
credentials = ""
path = Path("credentials.data")
if not path.exists():
path.touch()
with open("credentials.data", "r") as f:
data = f.read()
if data:
credentials = json.loads(data)
else:
credentials = None
credentials_rpc = json.dumps(
{
"jsonrpc": "2.0",
"id": "3",
"method": "init_authentication",
"params": {"stored_credentials": credentials},
}
).encode()
print('running_browser')
writer.write(credentials_rpc + b"\n")
await writer.drain()
tokens = await reader.readline()
print("ret", tokens)
tokens = json.loads(tokens.decode())
try:
if 'method' in tokens and tokens['method'] == 'store_credentials':
with open('credentials.data', 'w') as f:
f.write(json.dumps(tokens['params']))
print("tokens", tokens)
ret = await reader.readline()
print("ret", ret)
except Exception as e:
print(f'{str(e)}: Removing credentials')
os.remove('credentials.data')
print("owned")
writer.write(b'{"jsonrpc": "2.0", "id": "3", "method": "import_owned_games"}\n')
await writer.drain()
ret = await reader.readline()
print("ret", ret)
print("local")
writer.write(b'{"jsonrpc": "2.0", "id": "4", "method": "import_local_games"}\n')
await writer.drain()
ret = await reader.readline()
print("ret", ret)
# print("install_game")
# writer.write(b'{"jsonrpc": "2.0", "method": "install_game", "params":{"game_id": "21298"}}\n')
print("launch_game")
writer.write(b'{"jsonrpc": "2.0", "method": "launch_game", "params":{"game_id": "1465140039"}}\n')
# print("uninstall_game")
# writer.write(b'{"jsonrpc": "2.0", "method": "uninstall_game", "params":{"game_id": "GAME_ID"}}\n')
# await asyncio.sleep(5)
# print("shutdown")
# writer.write(b'{"jsonrpc": "2.0", "id": "6", "method": "shutdown"}\n')
async def wakeup():
while True:
await asyncio.sleep(1)
async def start_test():
await asyncio.start_server(run_server_connection, "127.0.0.1", "7998")
# reader, writer = await asyncio.open_connection("127.0.0.1", "7998")
# await BNetPlugin(reader, writer, "sdafsdf").run()
loop = asyncio.get_event_loop()
loop.create_task(start_test())
loop.create_task(wakeup())
loop.run_forever()