-
Notifications
You must be signed in to change notification settings - Fork 1
/
backend.py
executable file
·44 lines (41 loc) · 1.65 KB
/
backend.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
import websocket
from os.path import exists
import json
def writefile():
global websocket
try:
recv = irun(lambda: websocket.recv())
transfer = open("TRANSFER","w")
transfer.write(recv)
transfer.close()
except Exception as e:
if e == "socket is already closed.":
websocket = websocket.WebSocket()
irun(lambda: websocket.connect(cfg["servers"][cfg["lastsession"]["server"]]["websocket"]))
irun(lambda: websocket.send('{"cmd": "direct", "val": {"cmd": "authpswd", "val": {"username": "' + cfg["lastsession"]["user"] + '", "pswd": "' + cfg["servers"][cfg["lastsession"]["server"]]["logins"][cfg["lastsession"]["user"]] + '"}}}'))
print(e)
def irun(com):
while True:
try:
return com()
except Exception as e:
if str(e) in ("[Errno -3] Temporary failure in name resolution","[Errno 101] Network is unreachable"):
pass
else:
raise e
cf = open("meower95.conf","r")
cfg = json.load(cf)
cf.close()
websocket = websocket.WebSocket()
irun(lambda: websocket.connect(cfg["servers"][cfg["lastsession"]["server"]]["websocket"]))
irun(lambda: websocket.send('{"cmd": "direct", "val": {"cmd": "authpswd", "val": {"username": "' + cfg["lastsession"]["user"] + '", "pswd": "' + cfg["servers"][cfg["lastsession"]["server"]]["logins"][cfg["lastsession"]["user"]] + '"}}}'))
while True:
try:
while True:
transfer = open("TRANSFER","r")
if transfer.read() == "":
break
transfer.close()
writefile()
except FileNotFoundError:
writefile()