several updates to ensure own restartability
This commit is contained in:
parent
9efecd807d
commit
b460d906da
@ -19,3 +19,16 @@ exporting correct SDL_VIDEO_X11_VISUALID value is important before steam login f
|
|||||||
instead of automating the steam login its done manually due to requiring x2go/VNC/nomachine clients.
|
instead of automating the steam login its done manually due to requiring x2go/VNC/nomachine clients.
|
||||||
<br/> With the virtual desktop related to the VNC/x2go/nomachine client you can log into steam using the normal GUI -> <br/>
|
<br/> With the virtual desktop related to the VNC/x2go/nomachine client you can log into steam using the normal GUI -> <br/>
|
||||||
once logged in steam can run actively for months without requiring restarts
|
once logged in steam can run actively for months without requiring restarts
|
||||||
|
|
||||||
|
## bashrc for x2go users
|
||||||
|
in the users thats running a x2go session edit the .bashrc file and add the follwing (remember SDL_VIDEO_X11_VISUALID deppends on glxinfo from xterm terminal):
|
||||||
|
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
|
||||||
|
steam
|
||||||
|
fi
|
||||||
|
|
||||||
|
#X2GO_NXAGENT_DEFAULT_OPTIONS="-options nx/nx,sleep=0" /etc/x2go/x2goagent.options
|
||||||
|
#keeps session as R instead of S which is needed for interaction with graphical components such as steam and CS:S
|
||||||
|
|
||||||
|
6
AutismBotIngame/python/config.json
Normal file
6
AutismBotIngame/python/config.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"udp_port": 48482,
|
||||||
|
"chat_external_port": 48471,
|
||||||
|
"steam_port": 29074,
|
||||||
|
"server_ip_port": "135.125.188.157:27015"
|
||||||
|
}
|
@ -8,55 +8,32 @@ import random
|
|||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import codecs
|
import codecs
|
||||||
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
who_am_i = subprocess.getoutput(["whoami"])
|
whoami = subprocess.getoutput(["whoami"])
|
||||||
looptestPath = f"""/home/{who_am_i}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"""
|
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
||||||
|
data_ports = json.load(jsonfile)
|
||||||
|
looptestPath = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
|
||||||
chatmsg = ""
|
chatmsg = ""
|
||||||
|
|
||||||
def colored(r, g, b, text):
|
|
||||||
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
|
|
||||||
|
|
||||||
def writeCfgInput(Input_user):
|
def writeCfgInput(Input_user):
|
||||||
with open(looptestPath, 'w') as f:
|
with open(looptestPath, 'w') as f:
|
||||||
colored_text = colored(255, 0, 0, ('Input: ' + Input_user))
|
|
||||||
#print(colored_text)
|
|
||||||
f.write(Input_user)
|
f.write(Input_user)
|
||||||
|
#print(Input_user)
|
||||||
|
time.sleep(0.1)
|
||||||
|
open(looptestPath, 'w').close()
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print('reached exithandler')
|
print('reached exithandler')
|
||||||
writeCfgInput('')
|
writeCfgInput('')
|
||||||
|
#securing the looptest.cfg wont be stuck accidently with commands
|
||||||
|
|
||||||
def joinTeam():
|
def joinTeam():
|
||||||
str = "jointeam 2; joinclass 3; zspawn;"
|
str = "jointeam 2; joinclass 3; zspawn;"
|
||||||
writeCfgInput(str)
|
writeCfgInput(str)
|
||||||
print('jointeam func: ')
|
print('jointeam func: ')
|
||||||
time.sleep(4.5)
|
|
||||||
writeCfgInput('')
|
|
||||||
|
|
||||||
def bot_process_surf(input_line):
|
|
||||||
bot_surf_plane = input_line[input_line.index("surfing:") + len("surfing:"):]
|
|
||||||
bot_surf_plane = bot_surf_plane.strip()
|
|
||||||
bot_surf_plane = [float(i.replace('\U00002013', '-')) for i in bot_surf_plane.split(' ')]
|
|
||||||
#X axis positive = hold A
|
|
||||||
#X axis negative = hold D
|
|
||||||
#if Y axis = 0.0 use X instead
|
|
||||||
#Y axis negative = hold A
|
|
||||||
#Y axis positive = hold D
|
|
||||||
strInput = "-forward; wait 3; "
|
|
||||||
if bot_surf_plane[1] < 0.0:
|
|
||||||
strInput += "+moveleft; wait 3; "
|
|
||||||
elif bot_surf_plane[1] > 0.0:
|
|
||||||
strInput += "+moveright; wait 3;"
|
|
||||||
elif bot_surf_plane[0] < 0.0:
|
|
||||||
strInput += "+moveleft; wait 3; "
|
|
||||||
elif bot_surf_plane[0] > 0.0:
|
|
||||||
strInput += "+moveright; wait 3; "
|
|
||||||
print('date: ', datetime.datetime.now().time(),'bot surfing bot_surf_plane: ', bot_surf_plane)
|
|
||||||
writeCfgInput(strInput)
|
|
||||||
time.sleep(0.1)
|
|
||||||
writeCfgInput("")
|
|
||||||
|
|
||||||
def bot_process_movement(input_line):
|
def bot_process_movement(input_line):
|
||||||
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("targethuman:")]
|
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("targethuman:")]
|
||||||
@ -67,9 +44,9 @@ def bot_process_movement(input_line):
|
|||||||
dist_target = float(dist_target)
|
dist_target = float(dist_target)
|
||||||
enemy_distance = float(enemy_distance)
|
enemy_distance = float(enemy_distance)
|
||||||
targeteam = int(targeteam)
|
targeteam = int(targeteam)
|
||||||
min_distance_target_human = 50.0
|
min_distance_target_human = 1.0
|
||||||
strInput = "-attack; wait 2; -use; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; +forward; wait 2; "
|
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 and targeteam == 3:
|
if dist_target > min_distance_target_human:
|
||||||
#print('dist_target: ', dist_target)
|
#print('dist_target: ', dist_target)
|
||||||
strInput += "use weapon_elite; wait 3; "
|
strInput += "use weapon_elite; wait 3; "
|
||||||
elif targeteam == 3:
|
elif targeteam == 3:
|
||||||
@ -81,8 +58,6 @@ def bot_process_movement(input_line):
|
|||||||
strInput = strinput_append(strInput, 2)
|
strInput = strinput_append(strInput, 2)
|
||||||
#print('strInput final:', strInput)
|
#print('strInput final:', strInput)
|
||||||
writeCfgInput(strInput)
|
writeCfgInput(strInput)
|
||||||
time.sleep(0.1)
|
|
||||||
writeCfgInput("")
|
|
||||||
|
|
||||||
def strinput_append(strInput, nth):
|
def strinput_append(strInput, nth):
|
||||||
for _ in range(10 * nth):
|
for _ in range(10 * nth):
|
||||||
@ -93,28 +68,63 @@ def strinput_append(strInput, nth):
|
|||||||
strInput += "+moveright; wait 15; -moveright; "
|
strInput += "+moveright; wait 15; -moveright; "
|
||||||
return strInput
|
return strInput
|
||||||
|
|
||||||
def kill_css_process():
|
def kill_user_owned_pid(pid):
|
||||||
css_pid = subprocess.getoutput(["pidof hl2_linux"])
|
print('pid: ', pid, ' killed')
|
||||||
if css_pid:
|
pid = int(pid.strip())
|
||||||
for pid in css_pid.split(" "):
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
def return_user_owned_pid(pidof):
|
||||||
|
owner_pid = subprocess.getoutput([f"{pidof}"])
|
||||||
|
if owner_pid:
|
||||||
|
for pid in owner_pid.split(" "):
|
||||||
username = subprocess.getoutput([f"""ps -o user= -p {pid}"""])
|
username = subprocess.getoutput([f"""ps -o user= -p {pid}"""])
|
||||||
if username == who_am_i:
|
if username == whoami:
|
||||||
print('pid: ', pid, 'shutting the bots game down....')
|
return pid
|
||||||
pid = int(pid.strip())
|
return None
|
||||||
os.kill(pid, signal.SIGTERM)
|
|
||||||
time.sleep(15)
|
def kill_owned_process(pidof):
|
||||||
|
pid = return_user_owned_pid(pidof)
|
||||||
|
while pid:
|
||||||
|
kill_user_owned_pid(pid)
|
||||||
|
pid = return_user_owned_pid(pidof)
|
||||||
|
|
||||||
|
def restart_sdl_and_steam():
|
||||||
|
#ending screen
|
||||||
|
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)
|
||||||
|
if not x2go_session_list:
|
||||||
|
print('no session available. establish the session manually again')
|
||||||
|
raise Exception('')
|
||||||
|
|
||||||
|
x2go_session_display = x2go_session_list.split('|unloze.com')[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}"])
|
||||||
|
print('reached .bashrc executing steam and variables')
|
||||||
|
time.sleep(360)
|
||||||
|
#we sleep here to wait for .bashrc to launch steam. It takes some minutes
|
||||||
|
|
||||||
|
def launch_css_process():
|
||||||
print('preparing to launch game....')
|
print('preparing to launch game....')
|
||||||
os.chdir(f"""/home/{who_am_i}/.steam/debian-installation/""")
|
#deleting maps
|
||||||
subprocess.check_call("./steam.sh %s" % ("-applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi -port 29073"), shell=True)
|
subprocess.getoutput([f"rm '/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/'*"])
|
||||||
|
|
||||||
|
#launching game
|
||||||
|
subprocess.getoutput([f"/home/{whoami}/.steam/debian-installation/steam.sh -applaunch 240 -textmode -novid -nosound -noipx -nojoy -noshaderapi -port {data_ports['steam_port']}"])
|
||||||
print('finished starting game')
|
print('finished starting game')
|
||||||
|
|
||||||
def bot_connect_ze():
|
def bot_connect_ze():
|
||||||
#use whatever ip you want here to connect with
|
#use whatever ip you want here to connect with
|
||||||
strdev = "connect 144.76.218.19:27019/test132;"
|
strdev = "connect 135.125.188.157:27019/test132;"
|
||||||
str1 = "connect 144.76.218.19:27015;"
|
str1 = f"connect {data_ports['server_ip_port']}"
|
||||||
writeCfgInput(str1)
|
writeCfgInput(str1)
|
||||||
time.sleep(0.2)
|
|
||||||
writeCfgInput('')
|
|
||||||
print('not yet connected')
|
print('not yet connected')
|
||||||
|
|
||||||
def pairwise(it):
|
def pairwise(it):
|
||||||
@ -128,39 +138,43 @@ def pairwise(it):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
atexit.register(exit_handler)
|
atexit.register(exit_handler)
|
||||||
hetzner_ip = "144.76.218.19"
|
ovh_ip = "135.125.188.157"
|
||||||
local_ip = "127.0.0.1"
|
local_port = data_ports['udp_port']
|
||||||
local_port = 48479
|
external_port_messages = data_ports['chat_external_port']
|
||||||
udp_external_ip = "164.132.201.173"
|
|
||||||
buffer_size = 4096 #potentially not large enough?
|
buffer_size = 4096 #potentially not large enough?
|
||||||
connection_issue_counter = 0;
|
connection_issue_counter = 0;
|
||||||
|
pid = return_user_owned_pid("pidof hl2_linux")
|
||||||
|
if not pid:
|
||||||
|
restart_sdl_and_steam()
|
||||||
|
else:
|
||||||
|
kill_owned_process("pidof hl2_linux")
|
||||||
|
launch_css_process()
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock_external = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.bind(("", local_port))
|
sock.bind(("", local_port))
|
||||||
|
sock.settimeout(5.0)
|
||||||
messager_name = ""
|
messager_name = ""
|
||||||
print('reached deadlock')
|
print('reached deadlock')
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data, addr = sock.recvfrom(buffer_size)
|
try:
|
||||||
|
data, addr = sock.recvfrom(buffer_size)
|
||||||
|
except socket.timeout:
|
||||||
|
continue
|
||||||
data = codecs.decode(data, "utf-8", "ignore")
|
data = codecs.decode(data, "utf-8", "ignore")
|
||||||
#print(data)
|
|
||||||
ip = addr[0]
|
ip = addr[0]
|
||||||
port = addr[1]
|
port = addr[1]
|
||||||
#print('port: ', port, " ip: ", ip)
|
#print('port: ', port, " ip: ", ip)
|
||||||
#print(data)
|
#print('data: ', data)
|
||||||
if not data:
|
if not data:
|
||||||
continue
|
continue
|
||||||
if ip == udp_external_ip or ip == local_ip:
|
if ip == ovh_ip and port == external_port_messages:
|
||||||
if messager_name in data:
|
if messager_name in data:
|
||||||
messager_name = ""
|
messager_name = ""
|
||||||
response_msg = f"""say {messager_name} {data}"""
|
response_msg = f"""say {messager_name} {data}"""
|
||||||
print("remote UDP packet response_msg: ", response_msg)
|
print("remote UDP packet response_msg: ", response_msg)
|
||||||
writeCfgInput(response_msg)
|
writeCfgInput(response_msg)
|
||||||
#needs mini delay to have time to write input to console
|
if ip != ovh_ip:
|
||||||
time.sleep(0.1)
|
|
||||||
writeCfgInput("")
|
|
||||||
if ip != hetzner_ip:
|
|
||||||
continue
|
continue
|
||||||
if data == "autismo connected":
|
if data == "autismo connected":
|
||||||
print('Bot connected!')
|
print('Bot connected!')
|
||||||
@ -169,15 +183,20 @@ if __name__ == '__main__':
|
|||||||
elif data == "bot kicked server full":
|
elif data == "bot kicked server full":
|
||||||
print('bot kicked server full: ', datetime.datetime.now().time())
|
print('bot kicked server full: ', datetime.datetime.now().time())
|
||||||
elif data == "connect to ze":
|
elif data == "connect to ze":
|
||||||
if connection_issue_counter == 5 or connection_issue_counter == 50:
|
if connection_issue_counter == 20:
|
||||||
kill_css_process()
|
kill_owned_process("pidof hl2_linux")
|
||||||
|
launch_css_process()
|
||||||
|
elif connection_issue_counter == 50:
|
||||||
|
restart_sdl_and_steam()
|
||||||
|
launch_css_process()
|
||||||
|
connection_issue_counter = -10
|
||||||
connection_issue_counter += 1
|
connection_issue_counter += 1
|
||||||
print('connection_issue_counter: ', connection_issue_counter)
|
print('connection_issue_counter: ', connection_issue_counter)
|
||||||
bot_connect_ze()
|
bot_connect_ze()
|
||||||
elif "clientmessage:" in data:
|
elif "clientmessage:" in data:
|
||||||
messager_name = data.split("clientmessage:", 1)[1].split(" 72DqZ84")[0]
|
messager_name = data.split("clientmessage:", 1)[1].split(" 72DqZ84")[0]
|
||||||
databyte_send_message = messager_name + data.split("72DqZ84")[1]
|
databyte_send_message = messager_name + data.split("72DqZ84")[1]
|
||||||
sock_external.sendto(databyte_send_message.encode(), (udp_external_ip, local_port))
|
sock.sendto(databyte_send_message.encode(), (ovh_ip, external_port_messages))
|
||||||
print('databyte_send_message: ', databyte_send_message)
|
print('databyte_send_message: ', databyte_send_message)
|
||||||
elif data.startswith("dist_target:"):
|
elif data.startswith("dist_target:"):
|
||||||
bot_process_movement(data)
|
bot_process_movement(data)
|
||||||
@ -185,28 +204,20 @@ if __name__ == '__main__':
|
|||||||
bot_process_surf(data)
|
bot_process_surf(data)
|
||||||
elif data.startswith("hull info:"):
|
elif data.startswith("hull info:"):
|
||||||
hull_info = data[data.index("hull info:") + len("hull info:"):]
|
hull_info = data[data.index("hull info:") + len("hull info:"):]
|
||||||
colored_text = colored(255, 0, 0, ('hull_info: ' + hull_info))
|
|
||||||
strInput = ""
|
strInput = ""
|
||||||
if hull_info == "jump":
|
if hull_info == "jump":
|
||||||
strInput += "+jump; wait 5; -jump; +duck; wait 50; -duck; wait 5; "
|
strInput += "+jump; wait 5; -jump; +duck; wait 50; -duck; wait 5; "
|
||||||
elif hull_info == "crouch":
|
elif hull_info == "crouch":
|
||||||
strInput += "+duck; wait 50; -duck; wait 5; "
|
strInput += "+duck; wait 50; -duck; wait 5; "
|
||||||
writeCfgInput(strInput)
|
writeCfgInput(strInput)
|
||||||
#print(colored_text)
|
|
||||||
time.sleep(0.1)
|
|
||||||
writeCfgInput("")
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
sock_external.close()
|
|
||||||
|
|
||||||
#/home/gameservers/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
|
#/home/gameservers/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
|
||||||
#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop;
|
#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop;
|
||||||
|
#create looptest.cfg in /cfg/ folder
|
||||||
#-condebug
|
#X2GO_NXAGENT_DEFAULT_OPTIONS="-options nx/nx,sleep=0" /etc/x2go/x2goagent.options
|
||||||
#cd /home/gameservers/.steam/debian-installation/
|
#keeps session as R instead of S which is needed for interaction with graphical components such as steam and CS:S
|
||||||
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi
|
|
||||||
|
|
||||||
#cd /home/gameservers/ze_runner_files
|
#cd /home/gameservers/ze_runner_files
|
||||||
#python3 ingamefollowct.py
|
#python3 ingamefollowct.py
|
||||||
@ -214,3 +225,13 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
#before steam login: export SDL_VIDEO_X11_VISUALID=0x074
|
#before steam login: export SDL_VIDEO_X11_VISUALID=0x074
|
||||||
#to find correct SDL_VIDEO_X11_VISUALID use glxinfo in X2GO
|
#to find correct SDL_VIDEO_X11_VISUALID use glxinfo in X2GO
|
||||||
|
|
||||||
|
"""
|
||||||
|
.bashrc requires:
|
||||||
|
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
|
||||||
|
steam
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
@ -15,7 +15,7 @@ import time
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
local_ip = "127.0.0.1"
|
local_ip = "127.0.0.1"
|
||||||
local_port = 48479
|
local_port = 48479
|
||||||
udp_external_ip = "164.132.201.173"
|
udp_external_ip = "195.154.53.196"
|
||||||
buffer_size = 4096 #potentially not large enough?
|
buffer_size = 4096 #potentially not large enough?
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock_external = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock_external = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
@ -39,4 +39,4 @@ if __name__ == '__main__':
|
|||||||
sock.close()
|
sock.close()
|
||||||
sock_external.close()
|
sock_external.close()
|
||||||
#UDP redirecter welp
|
#UDP redirecter welp
|
||||||
#screen -d -m -S udp_redirecter python3 udp_redirecter.py
|
#screen -d -m -S udp_redirecter1 python3 udp_redirecter.py
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Deleting files from places after a certain amount of days
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=autismbot1
|
|
||||||
ExecStart=find "/home/autismbot1/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps" -maxdepth 1 -mmin +179 -type f -delete
|
|
@ -1,9 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Runs the maps Cleaner once each 10 hours
|
|
||||||
Requires=clean_maps1.service
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnCalendar=00/1:00
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
Loading…
Reference in New Issue
Block a user