-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
66 lines (56 loc) · 1.61 KB
/
run.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
import rcon
import pickle
import stdiomask
import json
import sys
import time
import socket
from socket import gaierror
foundData = -1
try:
with open(".\data\svr.dat","rb") as f:
pickle.load(f)
foundData = 1
except EOFError as ex:
foundData = 0
loadData = 'n'
if foundData == 1:
loadData = input("Load server connection from previous session? (y/n): ").lower()
elif foundData == 0:
ip = input("Enter IP: ")
port = int(input("Enter Port: "))
pswd = stdiomask.getpass(prompt = "Enter RCON Password: ", mask = '*')
conn = rcon.RCON(ip,port,pswd)
if loadData == 'y':
with open('.\data\svr.dat','rb') as f:
conn = pickle.load(f)
with open('.\data\serverparams.json','r') as f:
params = json.load(f)
conn.__init__(params["ip"],params["port"],params["rcon"])
if loadData == 'n' and foundData != 0:
ip = input("Enter IP: ")
port = int(input("Enter Port: "))
pswd = stdiomask.getpass(prompt = "Enter RCON Password: ", mask = '*')
conn = rcon.RCON(ip,port,pswd)
with open(".\data\svr.dat","wb") as f:
pickle.dump(conn,f)
if loadData == 'n':
with open(".\data\serverparams.json","w") as f:
params = {"ip":ip,"port":port,"rcon":pswd}
json.dump(params,f,indent=4)
try:
while True:
cmd = input(r"\rcon ")
conn.send(cmd)
except gaierror:
print("ERROR : Host not found!")
time.sleep(2)
sys.exit()
except ConnectionResetError:
print("ERROR : Check host and port combination!")
time.sleep(2)
sys.exit()
except socket.timeout:
print("Server Connection timed out!")
time.sleep(2)
sys.exit()