diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index 5eefc84..2e92c71 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -28,13 +28,14 @@ def writeCfgInput(Input_user): with open(looptestPath, 'w') as f: f.write(Input_user) #print("wrote to file: ", Input_user) - if "connect to" in Input_user: + if "connect " in Input_user: time.sleep(1.0) + open(looptestPath, 'w').close() #clearing file. elif "wait" in Input_user: - time.sleep(0.1) + time.sleep(0.35) else: time.sleep(0.5) - open(looptestPath, 'w').close() #clearing file. + open(looptestPath, 'w').close() #clearing file. def clean_up_files(): #deleting POSIX shared memory objects, as long as one process has them open they exist. THis is to prevent /dev/shm from being full @@ -148,15 +149,7 @@ def bot_connect(data): writeCfgInput(str1) time.sleep(1) - while True: - still_downloading_map = False - for f in glob.glob(f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/*.bz2"): - print('found f in bot_connect, so downloadig map?: ', f) - still_downloading_map = True - break - if not still_downloading_map: - break - time.sleep(10) + handle_bz2_map_files() t = Timer(30, attempt_bot_connect) t.start() @@ -177,14 +170,7 @@ def attempt_bot_connect(): 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? - - clean_up_files() - delete_lock_file() +def handle_bz2_map_files(): #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: @@ -203,6 +189,16 @@ if __name__ == '__main__': break time.sleep(10) +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? + + clean_up_files() + delete_lock_file() + handle_bz2_map_files() + 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"): @@ -221,12 +217,9 @@ if __name__ == '__main__': sock.settimeout(5.0) messager_name = "" - t = Timer(10, delete_lock_file) - t.start() - - #limit the cpu allowed to be used by the game instance. - t = Timer(11, cpulimit_pid_of_game) - t.start() + #limit the cpu allowed to be used by the game instance. + time.sleep(11) + cpulimit_pid_of_game() try: while True: @@ -242,6 +235,7 @@ if __name__ == '__main__': #print('data: ', data) if not data: continue + delete_lock_file() #print("ip: ", ip, " port: ", port) if ip == data_ports['discord_bot_ip'] and port == external_port_messages: if messager_name in data: @@ -296,4 +290,4 @@ if __name__ == '__main__': strInput += "+duck; wait 50; -duck; wait 5; " writeCfgInput(strInput) finally: - sock.close( + sock.close()