removed unused files related to x2go, switched from x2go to tigervnc (GLX 1.3 issue?), had to give up on headless textmode, instead now limiting cpu usage simply since it cant be headless any longer.

This commit is contained in:
2025-04-11 01:27:38 +02:00
parent 3de3e69510
commit a2eb7ade88
5 changed files with 47 additions and 80 deletions
+1 -2
View File
@@ -5,6 +5,5 @@
"discord_bot_ip": "****",
"server_ip_port_ze": "****:****",
"server_ip_port_ze2": "****:****",
"ovh_ip": "*******",
"x2go_pw": "**********"
"ovh_ip": "*******"
}
+39 -29
View File
@@ -7,6 +7,7 @@ from threading import Timer
import string
import random
import signal
import traceback
import socket
import codecs
import json
@@ -26,19 +27,21 @@ chatmsg = ""
def writeCfgInput(Input_user):
with open(looptestPath, 'w') as f:
f.write(Input_user)
#print("wrote to file: ", Input_user)
#time.sleep(10.0)
time.sleep(0.1)
open(looptestPath, 'w').close()
def exit_handler():
print('reached exithandler')
writeCfgInput('')
#securing the looptest.cfg wont be stuck accidently with commands
kill_owned_process("pidof hl2_linux")
kill_owned_process("pidof cstrike_linux64")
kill_owned_process("pidof xterm")
#deleting POSIX shared memory objects, as long as one process has them open they exist. THis is to prevent /dev/shm from being full
#due to steam child processes.
#even with steam turned offline might there be chromium web browsers left over from steam who still hold processes open.
#only kind of potential issues from this is steam cloud being out of sync, which is really fucking irrelevant.
#only kind of potential issues from this is steam cloud being out of sync, which is really fucking irrelevant.
subprocess.getoutput([f"pkill -9 -u {whoami}"])
def bot_process_movement(input_line):
@@ -54,7 +57,7 @@ def bot_process_movement(input_line):
#request by bane that bots should simply not infect people shrug
strInput = "-attack; wait 2; -use; wait 5; -attack; wait 5; cl_minmodels 1; wait 2; +use; wait 5; "
if targeteam == 3:
strInput = "-attack; wait 2; -use; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; wait 5; "
strInput = "-attack; wait 2; -use; wait 5; -attack; wait 5; cl_minmodels 1; wait 2; +use; wait 5; "
#python has no switches and such
if state in [5, 7]:
strInput += "-forward; wait 2; use weapon_knife; wait 5;"
@@ -107,29 +110,17 @@ def kill_owned_process(pidof):
def restart_sdl_and_steam():
#subprocess.getoutput(["screen -XS XTERM quit"])
kill_owned_process("pidof hl2_linux")
kill_owned_process("pidof cstrike_linux64")
kill_owned_process("pidof xterm")
x2go_session_list = subprocess.getoutput(["x2golistsessions"])
print('x2golistsessions: ', x2go_session_list)
if not x2go_session_list:
print('no session. creating Display to make idle session')
subprocess.getoutput([f"screen -d -m -S pyhoca_display ./run_follow.sh"])
while not x2go_session_list or len(x2go_session_list.split('|')[0].replace(" ", "")) == 0:
time.sleep(5)
x2go_session_list = subprocess.getoutput(["x2golistsessions"])
print(f'finally found x2go_session_list: {x2go_session_list}')
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'
xterm_cmd = f'screen -d -m -S XTERM x2goruncommand {x2go_session_display} {x2go_session_pid} {x2go_session_id} {x2go_session_command}'
print(f'xterm_cmd: {xterm_cmd}')
subprocess.getoutput([xterm_cmd])
subprocess.getoutput([f'vncserver -kill']) #only displays vncservers for the specific user.
time.sleep(5)
cmd = f'vncserver -localhost no -geometry 1x1 -depth 24'
print(f'cmd: {cmd}')
subprocess.getoutput([cmd])
print('reached .bashrc executing steam and variables')
time.sleep(40)
time.sleep(10)
#we sleep here to wait for .bashrc to launch steam. It takes some time
def bot_connect(data):
@@ -142,9 +133,19 @@ def bot_connect(data):
writeCfgInput(str1)
time.sleep(1)
writeCfgInput("")
t = Timer(150, attempt_bot_connect)
t = Timer(30, attempt_bot_connect)
t.start()
def cpulimit_pid_of_game():
pid = return_user_owned_pid("pidof cstrike_linux64")
cmd = f"cpulimit --pid={pid} --limit=5 --background"
#print('the command is: ', cmd)
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE).communicate()[0]
def delete_tmp_leftovers():
#just delete the tmp source_engine .lock file here so multiple instances can run at same time.
subprocess.Popen(["rm -f /tmp/source_engine*.lock"], shell=True, stdout=subprocess.PIPE).communicate()[0]
def attempt_bot_connect():
global connection_issue_counter
global call_bot_connect
@@ -183,6 +184,7 @@ if __name__ == '__main__':
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/*"):
subprocess.Popen(["rm", f], stdout=subprocess.PIPE).communicate()[0]
restart_sdl_and_steam()
is_bot_connected_to_ze2 = False
@@ -193,9 +195,17 @@ if __name__ == '__main__':
sock.settimeout(5.0)
messager_name = ""
t = Timer(10, delete_tmp_leftovers)
t.start()
#limit the cpu allowed to be used by the game instance.
t = Timer(11, cpulimit_pid_of_game)
t.start()
try:
while True:
try:
#print("socket waiting for recvfrom")
data, addr = sock.recvfrom(buffer_size)
except socket.timeout:
continue
@@ -232,9 +242,9 @@ if __name__ == '__main__':
is_bot_connected_to_ze2 = True
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
if connection_issue_counter == 5:
kill_owned_process("pidof hl2_linux")
print('exiting')
kill_owned_process("pidof cstrike_linux64")
sock.close()
print('exiting')
sys.exit(1)
else:
if call_bot_connect:
@@ -243,8 +253,8 @@ if __name__ == '__main__':
print("connection_issue_counter: ", connection_issue_counter)
bot_connect(data)
elif "clientmessage:" in data:
messager_name = data.split("clientmessage:", 1)[1].split(" put your magic code here.")[0]
databyte_send_message = messager_name + data.split("put your magic code here.")[1]
messager_name = data.split("clientmessage:", 1)[1].split(" secret_code_here")[0]
databyte_send_message = messager_name + data.split("secret_code_here")[1]
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:"):
-17
View File
@@ -1,17 +0,0 @@
from pyvirtualdisplay import Display
import json
import subprocess
whoami = subprocess.getoutput(["whoami"])
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
data_ports = json.load(jsonfile)
#enter screen to enter password
def main():
with Display() as disp:
d = subprocess.getoutput(["echo $DISPLAY"])
print(d)
subprocess.getoutput([f"pyhoca-cli --server localhost -N --password {data_ports['x2go_pw']}"])
if __name__ == '__main__':
main()
-4
View File
@@ -1,4 +0,0 @@
#!/bin/bash
cd "$(dirname "$0")"
source venv/bin/activate
python3 pyhoca_display.py