hopefully now deleting only bz2 files when they are left over and not still being downloaded. hopefully the client now has a better chance at connecting than before

This commit is contained in:
jenz 2023-10-01 21:05:47 +02:00
parent 5b356c37ec
commit d5833f09cd

View File

@ -12,11 +12,15 @@ import codecs
import json
import datetime
import time
import glob
connection_issue_counter = 0;
call_bot_connect = True
whoami = subprocess.getoutput(["whoami"])
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
data_ports = json.load(jsonfile)
looptestPath = f"/home/{whoami}/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
data_ports = json.load(jsonfile)
looptestPath = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
chatmsg = ""
def writeCfgInput(Input_user):
@ -60,7 +64,7 @@ def bot_process_movement(input_line):
elif state == 8:
strInput += "use weapon_knife; wait 5; +forward; wait 2;"
print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance, ' targeteam: ', targeteam, ' state:', state)
#print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance, ' targeteam: ', targeteam, ' state:', state)
if state not in [0, 2, 5, 7, 8]:
strInput = strinput_append(strInput, 2)
#print('strInput final:', strInput)
@ -120,7 +124,7 @@ def restart_sdl_and_steam():
print(f'xterm_cmd: {xterm_cmd}')
subprocess.getoutput([xterm_cmd])
print('reached .bashrc executing steam and variables')
time.sleep(90)
time.sleep(40)
#we sleep here to wait for .bashrc to launch steam. It takes some time
def bot_connect(data):
@ -129,32 +133,55 @@ def bot_connect(data):
if "connect to ze" == data:
str1 = f"connect {data_ports['server_ip_port_ze']}"
elif "connect to ze2" == data:
str1 = f"connect {data_ports['server_ip_port_ze2']}"
str1 = f"connect {data_ports['server_ip_port_ze2']}; wait 15000;"
writeCfgInput(str1)
time.sleep(0.5)
time.sleep(1)
writeCfgInput("")
print('not yet connected')
t = Timer(60, attempt_bot_connect)
t.start()
def attempt_bot_connect():
global connection_issue_counter
global call_bot_connect
connection_issue_counter += 1
call_bot_connect = True
print('finished timer callback')
if __name__ == '__main__':
atexit.register(exit_handler)
local_port = data_ports['udp_port']
external_port_messages = data_ports['chat_external_port']
buffer_size = 4096 #potentially not large enough?
connection_issue_counter = 0;
#deleting left over bz2 files because they give missing map issue
subprocess.run([f"rm /home/{whoami}/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common/Counter-Strike\ Source/cstrike/download/maps/*.bz2"], shell=True)
#deleting maps
maps_folder_size = subprocess.Popen(["du", "-sh", f"/home/{whoami}/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common/Counter-Strike Source/cstrike/download/maps"], stdout=subprocess.PIPE).communicate()[0].decode().split("\t")[0]
#if downloading maps we give it 10 seconds delay to see if the size changed, if not its probably safe to delete the .bz2 file as no download in progress
bz2_maps = {}
while True:
found = False
for f in glob.glob(f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/*.bz2"):
found = True
fsize = subprocess.Popen(["du", "-sh", f], stdout=subprocess.PIPE).communicate()[0].decode().split("\t")[0]
#deleting left over bz2 files because they give missing map issue
if f in bz2_maps:
#if the size is still the same it should be abandoned bz2 file that we can delete
if bz2_maps[f] == fsize:
subprocess.Popen(["rm", f], stdout=subprocess.PIPE).communicate()[0]
bz2_maps[f] = fsize
#no bz2 maps left to be concerned about
if not found:
break
time.sleep(10)
maps_folder_size = subprocess.Popen(["du", "-sh", f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps"], stdout=subprocess.PIPE).communicate()[0].decode().split("\t")[0]
#deleting when maps folder larger than 150GB
if maps_folder_size.endswith("G"):
maps_folder_size = float(maps_folder_size[:-1])
if maps_folder_size > 150.0:
subprocess.getoutput([f"rm '/home/{whoami}/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/common/Counter-Strike Source/cstrike/download/maps/'*"])
if maps_folder_size > 40.0:
for f in glob.glob(f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/*"):
subprocess.Popen(["rm", f], stdout=subprocess.PIPE).communicate()[0]
#deleting POSIX shared memory objects, as long as one process has them open they exist. so probably until steam gets turned off. THis is to prevent /dev/shm from being full
subprocess.getoutput([f"rm /dev/shm/u1001-Shm_*"])
subprocess.getoutput([f"rm /dev/shm/u1002-Shm_*"])
#subprocess.getoutput([f"rm /dev/shm/u1001-Shm_*"])
#subprocess.getoutput([f"rm /dev/shm/u1002-Shm_*"])
#NOTE since not running vm's anymore i quit doing this. instead just restarting the service every 10 hours.
restart_sdl_and_steam()
is_bot_connected_to_ze2 = False
@ -164,6 +191,7 @@ if __name__ == '__main__':
sock.bind(("", local_port))
sock.settimeout(5.0)
messager_name = ""
try:
while True:
try:
@ -177,6 +205,7 @@ if __name__ == '__main__':
#print('data: ', data)
if not data:
continue
#print("ip: ", ip, " port: ", port)
if ip == data_ports['discord_bot_ip'] and port == external_port_messages:
if messager_name in data:
messager_name = ""
@ -201,20 +230,21 @@ if __name__ == '__main__':
connection_issue_counter = 0
is_bot_connected_to_ze2 = True
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
if connection_issue_counter == 20:
if connection_issue_counter == 5:
kill_owned_process("pidof hl2_linux")
print('exiting')
sys.exit(1)
else:
print('data: ', data)
connection_issue_counter += 1
print('connection_issue_counter: ', connection_issue_counter)
bot_connect(data)
if call_bot_connect:
call_bot_connect = False
print('data: ', data)
print("connection_issue_counter: ", connection_issue_counter)
bot_connect(data)
elif "clientmessage:" in data:
messager_name = data.split("clientmessage:", 1)[1].split(" 72DqZ84")[0]
databyte_send_message = messager_name + data.split("72DqZ84")[1]
sock.sendto(databyte_send_message.encode(), (data_ports["discord_bot_ip"], external_port_messages))
print('databyte_send_message: ', databyte_send_message)
#print('databyte_send_message: ', databyte_send_message)
elif data.startswith("dist_target:"):
bot_process_movement(data)
elif data.startswith("surfing:"):