further updates, added back shitty exit if game gets stuck
This commit is contained in:
parent
6b7b78f9f5
commit
b0feb898e3
@ -89,3 +89,4 @@ limiting cpu can throttle the download speed as well. if bots cant connect and a
|
|||||||
|
|
||||||
pip3 install watchdog
|
pip3 install watchdog
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ import time
|
|||||||
import glob
|
import glob
|
||||||
|
|
||||||
restart_time = datetime.datetime.now() + datetime.timedelta(hours=3)
|
restart_time = datetime.datetime.now() + datetime.timedelta(hours=3)
|
||||||
|
block_connection = False
|
||||||
|
the_undesired_crash_counter = 0 #hate this monkey solution
|
||||||
|
|
||||||
whoami = subprocess.getoutput(["whoami"])
|
whoami = subprocess.getoutput(["whoami"])
|
||||||
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
||||||
@ -30,7 +32,8 @@ def writeCfgInput(Input_user):
|
|||||||
with open(looptestPath, 'w') as f:
|
with open(looptestPath, 'w') as f:
|
||||||
f.write(Input_user)
|
f.write(Input_user)
|
||||||
#print("wrote to file: ", Input_user)
|
#print("wrote to file: ", Input_user)
|
||||||
if "connect " in Input_user:
|
if "connect" in Input_user or "retry;" in Input_user:
|
||||||
|
#give extra time for disconnect, retry and connect commands
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
else:
|
else:
|
||||||
time.sleep(0.35)
|
time.sleep(0.35)
|
||||||
@ -64,14 +67,16 @@ def clean_up_files():
|
|||||||
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
||||||
if file_size == cur_file_size:
|
if file_size == cur_file_size:
|
||||||
#delete the bz2 file if its not progressing downloading
|
#delete the bz2 file if its not progressing downloading
|
||||||
subprocess.Popen(["rm", f], stdout=subprocess.DEVNULL).communicate()[0]
|
#print("deleting file: ", f)
|
||||||
|
subprocess.Popen(["rm", "-rf", f], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||||
break
|
break
|
||||||
file_size = cur_file_size
|
file_size = cur_file_size
|
||||||
|
|
||||||
|
#clean up the game cache as it otherwise just keeps growing in gigabyte size
|
||||||
|
subprocess.Popen(["rm", "-rf", f"/home/{whoami}/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cache"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print('reached exithandler')
|
print('reached exithandler')
|
||||||
writeCfgInput('')
|
|
||||||
#securing the looptest.cfg wont be stuck accidently with commands
|
#securing the looptest.cfg wont be stuck accidently with commands
|
||||||
kill_owned_process("pidof cstrike_linux64")
|
kill_owned_process("pidof cstrike_linux64")
|
||||||
kill_owned_process("pidof xterm")
|
kill_owned_process("pidof xterm")
|
||||||
@ -171,46 +176,49 @@ def cpulimit_pid_of_game():
|
|||||||
# ' > /dev/null' redirects stdout to /dev/null
|
# ' > /dev/null' redirects stdout to /dev/null
|
||||||
# '2>&1' redirects stderr to the same place as stdout
|
# '2>&1' redirects stderr to the same place as stdout
|
||||||
pid = return_user_owned_pid("pidof cstrike_linux64")
|
pid = return_user_owned_pid("pidof cstrike_linux64")
|
||||||
cmd = f"cpulimit --pid={pid} --limit=35 --background > /dev/null 2>&1"
|
cmd = f"cpulimit --pid={pid} --limit=25 --background > /dev/null 2>&1"
|
||||||
|
#cmd = f"cpulimit --pid={pid} --limit=55 --background > /dev/null 2>&1"
|
||||||
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE).communicate()[0]
|
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
def my_file_created_function(event_path):
|
def my_file_created_function(event_path):
|
||||||
#print(f"New file created: {event_path}")
|
#print(f"New file created: {event_path}")
|
||||||
if event_path.startswith("/tmp/source_engine") and event_path.endswith(".lock"):
|
if event_path.startswith("/tmp/source_engine") and event_path.endswith(".lock"):
|
||||||
subprocess.Popen([f"rm -f {event_path}"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()[0]
|
subprocess.Popen([f"rm -rf {event_path}"], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||||
return
|
return
|
||||||
|
if not event_path.lower().endswith(".bsp.bz2"):
|
||||||
if not event_path.lower().endswith(".bsp.bz2") or event_path.lower().startswith("/tmp/"): #dont do anything with /tmp/ files except the .lock file
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
global block_connection
|
||||||
|
block_connection = True
|
||||||
|
overwrite_file_access() #set chmod once for the bsp bz2 file.
|
||||||
file_size = None
|
file_size = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
stdout, stderr = subprocess.Popen(["ls", "-l", event_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
stdout, stderr = subprocess.Popen(["ls", "-l", event_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||||
#print('stdout: ', stdout)
|
|
||||||
#print('stderr: ', stderr)
|
|
||||||
if stderr:
|
if stderr:
|
||||||
print('finished downloading the bz2 file')
|
#print('stderr: ', stderr)
|
||||||
|
print(f'finished the bz2 file {event_path}')
|
||||||
break
|
break
|
||||||
|
|
||||||
|
#print('stdout: ', stdout)
|
||||||
user = stdout.decode().split("autismbots")[0]
|
user = stdout.decode().split("autismbots")[0]
|
||||||
if whoami not in user:
|
if whoami in user: #we are the user that owns the file on disk
|
||||||
print("disconnected from server until other user finished downloading bz2 file")
|
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
||||||
|
if file_size == cur_file_size:
|
||||||
|
#print('cur_file_size: ', cur_file_size, ' stdout decode: ', stdout.decode())
|
||||||
|
print(f"Deleting {event_path} due to being stuck on download.")
|
||||||
|
subprocess.Popen(["rm", "-rf", event_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||||
|
continue
|
||||||
|
file_size = cur_file_size
|
||||||
|
else:
|
||||||
writeCfgInput("disconnect;")
|
writeCfgInput("disconnect;")
|
||||||
time.sleep(5)
|
|
||||||
continue
|
|
||||||
|
|
||||||
#in case the bz2 download is not progressing just delete the file and disconnect.
|
|
||||||
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
|
|
||||||
print('cur_file_size: ', cur_file_size, ' stdout decode: ', stdout.decode())
|
|
||||||
if file_size == cur_file_size:
|
|
||||||
print("Aborting connection. file download is stuck.")
|
|
||||||
subprocess.Popen(["rm", event_path], stdout=subprocess.DEVNULL).communicate()[0]
|
|
||||||
time.sleep(2)
|
|
||||||
writeCfgInput("disconnect;")
|
|
||||||
break
|
|
||||||
file_size = cur_file_size
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
overwrite_file_access() #set chmod for the actual bsp file
|
||||||
|
global the_undesired_crash_counter
|
||||||
|
the_undesired_crash_counter = 0
|
||||||
|
block_connection = False
|
||||||
|
|
||||||
class NewFileHandler(FileSystemEventHandler):
|
class NewFileHandler(FileSystemEventHandler):
|
||||||
def on_created(self, event):
|
def on_created(self, event):
|
||||||
my_file_created_function(event.src_path)
|
my_file_created_function(event.src_path)
|
||||||
@ -251,7 +259,7 @@ if __name__ == '__main__':
|
|||||||
maps_folder_size = float(maps_folder_size[:-1])
|
maps_folder_size = float(maps_folder_size[:-1])
|
||||||
if maps_folder_size > 40.0:
|
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/*"):
|
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]
|
subprocess.Popen(["rm", "-rf", f], stdout=subprocess.PIPE).communicate()
|
||||||
|
|
||||||
restart_sdl_and_steam()
|
restart_sdl_and_steam()
|
||||||
is_bot_connected_to_ze2 = False
|
is_bot_connected_to_ze2 = False
|
||||||
@ -307,23 +315,25 @@ if __name__ == '__main__':
|
|||||||
elif "autismo connected to ze" == data:
|
elif "autismo connected to ze" == data:
|
||||||
print('Bot connected to ze!')
|
print('Bot connected to ze!')
|
||||||
is_bot_connected_to_ze2 = False
|
is_bot_connected_to_ze2 = False
|
||||||
overwrite_file_access()
|
the_undesired_crash_counter = 0
|
||||||
elif "not connected to ze2" == data:
|
elif "not connected to ze2" == data:
|
||||||
is_bot_connected_to_ze2 = False
|
is_bot_connected_to_ze2 = False
|
||||||
elif "autismo connected to ze2" == data:
|
elif "autismo connected to ze2" == data:
|
||||||
print('Bot connected to ze2!')
|
print('Bot connected to ze2!')
|
||||||
|
the_undesired_crash_counter = 0
|
||||||
is_bot_connected_to_ze2 = True
|
is_bot_connected_to_ze2 = True
|
||||||
overwrite_file_access()
|
|
||||||
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
|
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
|
||||||
if datetime.datetime.now() >= restart_time or return_user_owned_pid("pidof cstrike_linux64") is None: #the game died
|
if datetime.datetime.now() >= restart_time or return_user_owned_pid("pidof cstrike_linux64") is None or the_undesired_crash_counter >= 5:
|
||||||
|
#it already finished downloading the contnet, it just cant connect. probably stuck. shitty solution welp
|
||||||
kill_owned_process("pidof cstrike_linux64")
|
kill_owned_process("pidof cstrike_linux64")
|
||||||
sock.close()
|
sock.close()
|
||||||
close_observer(observer)
|
close_observer(observer)
|
||||||
close_observer(observer1)
|
close_observer(observer1)
|
||||||
print('exiting after running the game for several hours.')
|
print('exiting after running the game for several hours or game being stuck on map change.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
elif not block_connection: #need this check to prevent connection spam during content downloading.
|
||||||
print('data: ', data)
|
print('data: ', data, ' the_undesired_crash_counter: ', the_undesired_crash_counter)
|
||||||
|
the_undesired_crash_counter += 1
|
||||||
bot_connect(data)
|
bot_connect(data)
|
||||||
elif "clientmessage:" in data:
|
elif "clientmessage:" in data:
|
||||||
messager_name = data.split("clientmessage:", 1)[1].split(f" {data_ports['magic_secret']}")[0]
|
messager_name = data.split("clientmessage:", 1)[1].split(f" {data_ports['magic_secret']}")[0]
|
||||||
|
@ -537,14 +537,6 @@ public Action bot_check_connect(Handle timer, any data)
|
|||||||
if (!bot4_connected)
|
if (!bot4_connected)
|
||||||
send_socket_msg(msg, strlen(msg), ports[3]);
|
send_socket_msg(msg, strlen(msg), ports[3]);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Format(msg, sizeof(msg), "connect to ze2");
|
|
||||||
send_socket_msg(msg, strlen(msg), ports[0]);
|
|
||||||
send_socket_msg(msg, strlen(msg), ports[1]);
|
|
||||||
send_socket_msg(msg, strlen(msg), ports[2]);
|
|
||||||
send_socket_msg(msg, strlen(msg), ports[3]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user