From a8a2efe64f571192c5ec1d76146ccbdf9a0e5eee Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 25 Mar 2022 19:59:42 +0100 Subject: [PATCH] updated readme and config settings being applied --- AutismBotIngame/python/config.json | 5 +- AutismBotIngame/python/ingamefollowct.py | 59 +++++++++++++++--------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/AutismBotIngame/python/config.json b/AutismBotIngame/python/config.json index c0ebeb07..41019133 100644 --- a/AutismBotIngame/python/config.json +++ b/AutismBotIngame/python/config.json @@ -2,7 +2,10 @@ "udp_port": 48470, "chat_external_port": 48475, "steam_port": 29074, + "discord_bot_ip": "5.104.107.39", "server_ip_port_ze": "135.125.188.157:27015", - "server_ip_port_ze2": "135.125.188.157:27035" + "server_ip_port_ze2": "135.125.188.157:27035", + "ovh_ip": "135.125.188.157" } + diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index b8ee0a39..c75a59d0 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -21,7 +21,6 @@ chatmsg = "" def writeCfgInput(Input_user): with open(looptestPath, 'w') as f: f.write(Input_user) - #print(Input_user) time.sleep(0.1) open(looptestPath, 'w').close() @@ -39,17 +38,15 @@ def bot_process_movement(input_line): dist_target = float(dist_target) enemy_distance = float(enemy_distance) targeteam = int(targeteam) - min_distance_target_human = 1.0 + min_distance_target_human = 10.0 strInput = "-attack; wait 2; -use; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; +forward; wait 2; " if dist_target > min_distance_target_human: - #print('dist_target: ', dist_target) strInput += "use weapon_elite; wait 3; " elif targeteam == 3: strInput += "use weapon_p90; wait 3; " elif targeteam == 2: strInput += "use weapon_knife; wait 5; " - print('date: ', datetime.datetime.now().time(), ' target_enemy: ', target_enemy, ' enemy distance: ', enemy_distance, ' target human: ', targethuman, - ' dist_target: ', dist_target) + print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance) strInput = strinput_append(strInput, 2) #print('strInput final:', strInput) writeCfgInput(strInput) @@ -85,25 +82,45 @@ def kill_owned_process(pidof): pid = return_user_owned_pid(pidof) def restart_sdl_and_steam(): - #ending screen - subprocess.getoutput(["screen -XS XTERM quit"]) + #subprocess.getoutput(["screen -XS XTERM quit"]) kill_owned_process("pidof hl2_linux") kill_owned_process("pidof xterm") x2go_session_list = subprocess.getoutput(["x2golistsessions"]) - print('x2go_session_list: ', x2go_session_list) + print('x2golistsessions: ', x2go_session_list) if not x2go_session_list: - print('no session available. establish the session manually again') + print('creating new session') raise Exception('') + #TODO https://pypi.org/project/PyVirtualDisplay/ + subprocess.getoutput(["x2gostartagent 20x20 wan 2m-png-jpeg unix-kde-depth_24 dk pc105/dk 1 R xterm"]) + restart_sdl_and_steam() - x2go_session_display = x2go_session_list.split('|unloze.com')[0].rsplit('|', 1)[1] + hostname = subprocess.getoutput(['hostname']) + x2go_session_display = x2go_session_list.split(f'|{hostname}')[0].rsplit('|', 1)[1] x2go_session_pid = x2go_session_list.split('|')[0] x2go_session_id = x2go_session_list.split('|')[1].split('|')[0] x2go_session_command = 'TERMINAL xterm' - - subprocess.getoutput([f"screen -d -m -S XTERM x2goruncommand {x2go_session_display} {x2go_session_pid} {x2go_session_id} {x2go_session_command}"]) + xterm_cmd = f'screen -d -m -S XTERM x2goruncommand {x2go_session_display} {x2go_session_pid} {x2go_session_id} {x2go_session_command}' + print(xterm_cmd) + subprocess.getoutput([xterm_cmd]) print('reached .bashrc executing steam and variables') time.sleep(60) + """ + steampid = None + while steampid is None: + time.sleep(1) + print(subprocess.getoutput(["pidof steam"])) + steampids = subprocess.getoutput(["pidof steam"]) + found_steam = False + while not found_steam: + for spid in steampids.split(' '): + owner = subprocess.getoutput([f"ps -o user={spids}"]) + if whoami == owner: + print('steam finished loading!') + found_steam = True + time.sleep(10) + steampids = subprocess.getoutput(["pidof steam"]) + """ #we sleep here to wait for .bashrc to launch steam. It takes some minutes def launch_css_process(): @@ -137,7 +154,6 @@ def pairwise(it): if __name__ == '__main__': atexit.register(exit_handler) - ovh_ip = "135.125.188.157" local_port = data_ports['udp_port'] external_port_messages = data_ports['chat_external_port'] buffer_size = 4096 #potentially not large enough? @@ -154,7 +170,6 @@ if __name__ == '__main__': sock.bind(("", local_port)) sock.settimeout(5.0) messager_name = "" - print('reached deadlock') try: while True: try: @@ -168,15 +183,14 @@ if __name__ == '__main__': #print('data: ', data) if not data: continue - if ip == ovh_ip and port == external_port_messages: + if ip == data_ports['discord_bot_ip'] and port == external_port_messages: if messager_name in data: messager_name = "" response_msg = f"""say {messager_name} {data}""" print("remote UDP packet response_msg: ", response_msg) writeCfgInput(response_msg) - if ip != ovh_ip: + if ip != data_ports['ovh_ip']: continue - #print("data: ", data) if data == "autismo connected": print('Bot connected!') connection_issue_counter = 0 @@ -207,7 +221,7 @@ if __name__ == '__main__': 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(), (ovh_ip, external_port_messages)) + sock.sendto(databyte_send_message.encode(), (data_ports["discord_bot_ip"], external_port_messages)) print('databyte_send_message: ', databyte_send_message) elif data.startswith("dist_target:"): bot_process_movement(data) @@ -232,7 +246,6 @@ if __name__ == '__main__': #cd /home/gameservers/ze_runner_files #python3 ingamefollowct.py -#screen -d -m -S ze_runner python3 ingamefollowct.py #before steam login: export SDL_VIDEO_X11_VISUALID=0x074 #to find correct SDL_VIDEO_X11_VISUALID use glxinfo in X2GO @@ -243,7 +256,11 @@ if [[ $DISPLAY ]]; then echo 'SDL_VIDEO_X11_VISUALID: ' $SDL_VIDEO_X11_VISUALID export SDL_VIDEO_X11_VISUALID=0x205 echo 'SDL_VIDEO_X11_VISUALID: ' $SDL_VIDEO_X11_VISUALID - #native libraries being prefered over runtime here - STEAM_RUNTIME=0 steam no-browser -console + steam fi """ + +#apt-get install tmux -> tmux -> cd /home/autismbot1/ze_runner -> python3 ingamefollowct.py + +#https://pypi.org/project/PyVirtualDisplay/ +