import os import sys import subprocess import atexit from threading import Timer import string import random import time import socket import codecs looptestPath = '/home/gameservers/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg' chatmsg = "" def writeCfgInput(Input): with open(looptestPath, 'w') as f: f.write(Input) def resetCfgInputShortWait(): str = "wait 5; " with open(looptestPath, 'w') as f: f.write(str) time.sleep(0.5) def exit_handler(): print('reached exithandler') resetCfgInputShortWait() def joinTeam(): str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5;" writeCfgInput(str) time.sleep(4.5) print('jointeam func: ') def bot_process_movement(input_lines): movement_list = [1, 0] strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; " for input_line in input_lines.splitlines(): movement_input = input_line[input_line.index("keyinput:") + len("keyinput:"):input_line.index("clientangles:")] client_angles = input_line[input_line.index("clientangles:") + len("clientangles:"):input_line.index("xyz:")] xyz = input_line[input_line.index("xyz:") + len("xyz:"):input_line.index("hunt_or_mimic:")] hunt_or_mimic = input_line[input_line.index("hunt_or_mimic:") + len("hunt_or_mimic:"):input_line.index("stuckX:")] stuckx = input_line[input_line.index("stuckX:") + len("stuckX:"):input_line.index("stuckY:")] stucky = input_line[input_line.index("stuckY:") + len("stuckY:"):] if not hunt_or_mimic: axis_distance = 50 if stuckX: print('stuckX enabled') if movement_list[0] == 0: movement_list[0] = 1 elif movement_list[0] == 1: movement_list[0] = 0 strInput += " +jump; wait 3; +duck; wait 5;" if stuckY: print('stuckY enabled') if movement_list[1] == 0: movement_list[1] = 1 elif movement_list[1] == 1: movement_list[1] = 0 strInput += " +jump; wait 3; +duck; wait 5;" print('hunt mode enabled') if not stuckX and not stuckY: if xyz_difference[0] > axis_distance: movement_list[0] = 1 elif xyz_difference[0] < -axis_distance: movement_list[0] = 0 if xyz_difference[1] < -axis_distance: movement_list[1] = 1 elif xyz_difference[1] > axis_distance: movement_list[1] = 0 if movement_list[0] == 1: strInput += " -back; wait 5; +forward; wait 5;" elif movement_list[0] == 0: strInput += " -forward; wait 5; +back; wait 5;" if movement_list[1] == 1: strInput += " -moveleft; wait 5; +moveright; wait 5;" elif movement_list[1] == 0: strInput += " -moveright; wait 5; +moveleft; wait 5;" print('xyz_difference[0]: ', xyz_difference[0]) print('xyz_difference[1]: ', xyz_difference[1]) print('movement_list[0]: ', movement_list[0], '0 = back. 1 = forward.') print('movement_list[1]: ', movement_list[1], '0 = moveleft. 1 = moveright') strInput += f""" setang 0 180 0; wait 5; """ else: strInput += f"""setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input}; wait 5; """ #print('strInput final:', strInput) writeCfgInput(strInput) time.sleep(0.4) writeCfgInput("wait 5;") def bot_connect_ze(): #use whatever ip you want here to connect with strdev = "connect 151.80.230.149:27019/test132;" str1 = "connect 151.80.230.149:27015;" writeCfgInput(strdev) time.sleep(0.2) writeCfgInput("wait 5;") time.sleep(15.50) print('not yet connected') if __name__ == '__main__': atexit.register(exit_handler) resetCfgInputShortWait() local_ip = "127.0.0.1" local_port = 48477 udp_external_ip = "62.210.110.245" buffer_size = 4096 #potentially not large enough? with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock_external: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("", local_port)) print('reached deadlock') try: while True: data, addr = sock.recvfrom(buffer_size) databyte = data data = codecs.decode(data, "utf-8", "ignore") ip = addr[0] port = addr[1] print('port: ', port, " ip: ", ip) if not data: continue if ip not in [local_ip, udp_external_ip]: continue if ip == udp_external_ip: print("enabled remote UDP packet") response_msg = f"""say {data}""" writeCfgInput(response_msg) time.sleep(0.5) resetCfgInputShortWait() time.sleep(0.2) print('data: ', data) if data == "autismo connected": print('Bot connected!') time.sleep(2) joinTeam() elif data == "connect to ze": bot_connect_ze() elif "clientmessage:" in data: sock_external.sendto(databyte, (udp_external_ip, local_port)) print('sent databyte: ', databyte) elif data.startswith("keyinput:"): bot_process_movement(data) except KeyboardInterrupt: pass #/home/gameservers/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg: #/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg: #alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop; #-condebug #cd /home/nonroot/.steam/ #cd /home/gameservers/.steam/debian-installation/ #./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg #cd /home/gameservers/ze_runner_files #./play.sh #screen -A -d -m -S ze_runner ./play.sh