-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpyBE_rawFile.py
More file actions
81 lines (72 loc) · 2.5 KB
/
pyBE_rawFile.py
File metadata and controls
81 lines (72 loc) · 2.5 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
# Filename: pyBE_rawFile.py
# This file is part of pyBE.
#
# pyBEscanner is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyBEscanner is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyBEscanner. If not, see <http://www.gnu.org/licenses/>.
import argparse
import os
import sys
import time
from modules import settings
from modules import rcon
def close_battleye_connection(serverConnection):
try:
serverConnection.stop()
except Exception:
pass
parser = argparse.ArgumentParser(description='pyBE_rawFile Usage: pyBE_rawFile <serverid> <filename>')
parser.add_argument("serverid")
parser.add_argument("filename")
args = parser.parse_args()
settings, vac_bans_file = settings.Settings().load_rcon_bot_config()
for server in settings:
if server["Server ID"] == args.serverid:
serverConnection = None
try:
if os.path.isfile(args.filename) is True:
serverConnection = rcon.BattleyeServer(server["ServerIP"], server["ServerPort"], server["RconPassword"])
timeout = 60 + time.time()
while (time.time() < timeout) and not (serverConnection.connected):
print ("Retrying to connect to " + server["ServerName"])
time.sleep(5)
close_battleye_connection(serverConnection)
serverConnection = rcon.BattleyeServer(server["ServerIP"], server["ServerPort"], server["RconPassword"])
if serverConnection.connected:
try:
with open(args.filename) as f:
for line in f:
command = line.strip()
data = serverConnection.command(command)
time.sleep(0.5)
time.sleep(5)
finally:
close_battleye_connection(serverConnection)
sys.exit()
else:
print "File not found"
except KeyboardInterrupt:
print
print("Stopping pyBE....")
print
close_battleye_connection(serverConnection)
sys.exit()
except IOError, err:
print("IOError %s"% err)
sys.exit()
except Exception, err:
print("\n")
print("Unexpected error")
print("Error %s"% err)
# unexpected exception, better close the battleye connection
close_battleye_connection(serverConnection)
sys.exit()