replacing reliance on alias for connecting with steam native connect command. downloading maps through sourcemod saying the nextmap. should assure that bots are connected much faster from now on in almost all cases.
This commit is contained in:
@@ -7,16 +7,18 @@ import pwd
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
import random
|
||||
import bz2
|
||||
import signal
|
||||
import socket
|
||||
import codecs
|
||||
import json
|
||||
import requests
|
||||
import datetime
|
||||
import time
|
||||
import glob
|
||||
import pwd
|
||||
|
||||
restart_time = datetime.datetime.now() + datetime.timedelta(hours=3)
|
||||
restart_time = datetime.datetime.now() + datetime.timedelta(hours=6)
|
||||
|
||||
whoami = subprocess.getoutput("whoami")
|
||||
with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
||||
@@ -24,10 +26,6 @@ with open(f'/home/{whoami}/ze_runner/config.json') as jsonfile:
|
||||
looptestPath = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg"
|
||||
chatmsg = ""
|
||||
|
||||
def overwrite_file_access():
|
||||
#setting defaults with setfacl for the download directory does not work seemingly
|
||||
subprocess.Popen(["chmod", "-R", "g+rwx", f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||
|
||||
def writeCfgInput(Input_user):
|
||||
with open(looptestPath, 'w') as f:
|
||||
f.write(Input_user)
|
||||
@@ -39,6 +37,36 @@ def writeCfgInput(Input_user):
|
||||
time.sleep(0.35)
|
||||
open(looptestPath, 'w').close() #clearing file.
|
||||
|
||||
def get_display_env_from_file():
|
||||
display_path = f"/home/{whoami}/ze_runner/display.txt"
|
||||
env = {}
|
||||
try:
|
||||
with open(display_path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if "=" in line:
|
||||
key, _, value = line.partition("=")
|
||||
env[key] = value
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
return env
|
||||
|
||||
def check_instance_conflict_dialog():
|
||||
display_env = get_display_env_from_file() or {}
|
||||
env = os.environ.copy()
|
||||
env["DISPLAY"] = display_env.get("DISPLAY")
|
||||
result = subprocess.run(
|
||||
["xdotool", "search", "--name", "Source - Warning"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
if result.returncode == 0:
|
||||
return 0
|
||||
return None
|
||||
|
||||
def overwrite_file_access():
|
||||
#setting defaults with setfacl for the download directory does not work seemingly
|
||||
subprocess.Popen(["chmod", "-R", "g+rwx", f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).communicate()
|
||||
|
||||
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
|
||||
#due to steam child processes.
|
||||
@@ -78,7 +106,6 @@ def delete_bsp_files():
|
||||
|
||||
def exit_handler():
|
||||
print('reached exithandler')
|
||||
#securing the looptest.cfg wont be stuck accidently with commands
|
||||
kill_owned_process("pidof cstrike_linux64")
|
||||
kill_owned_process("pidof xterm")
|
||||
|
||||
@@ -126,12 +153,19 @@ def restart_sdl_and_steam():
|
||||
|
||||
def bot_connect(data):
|
||||
#use whatever ip you want here to connect with
|
||||
str1 = ""
|
||||
server = ""
|
||||
if "connect to ze" == data:
|
||||
str1 = f"connect {data_ports['server_ip_port_ze']};"
|
||||
server = f"{data_ports['server_ip_port_ze']};"
|
||||
elif "connect to ze2" == data:
|
||||
str1 = f"connect {data_ports['server_ip_port_ze2']};" #wait 15000;
|
||||
writeCfgInput(str1)
|
||||
server = f"{data_ports['server_ip_port_ze2']};"
|
||||
|
||||
display_env = get_display_env_from_file() or {}
|
||||
env = os.environ.copy()
|
||||
env["DISPLAY"] = display_env.get("DISPLAY")
|
||||
subprocess.run(
|
||||
["/usr/games/steam", f"steam://connect/{server}"],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def cpulimit_pid_of_game():
|
||||
# ' > /dev/null' redirects stdout to /dev/null
|
||||
@@ -179,9 +213,9 @@ if __name__ == '__main__':
|
||||
sock.bind(("", local_port))
|
||||
sock.settimeout(5.0)
|
||||
messager_name = ""
|
||||
|
||||
failed_connect_count = 0
|
||||
|
||||
fail_safe_counter = 0
|
||||
|
||||
launch_game()
|
||||
try:
|
||||
while True:
|
||||
@@ -212,24 +246,51 @@ if __name__ == '__main__':
|
||||
elif "autismo connected to ze" == data:
|
||||
print('Bot connected to ze!')
|
||||
is_bot_connected_to_ze2 = False
|
||||
failed_connect_count = 0
|
||||
fail_safe_counter = 0
|
||||
elif "not connected to ze2" == data:
|
||||
is_bot_connected_to_ze2 = False
|
||||
elif "autismo connected to ze2" == data:
|
||||
print('Bot connected to ze2!')
|
||||
is_bot_connected_to_ze2 = True
|
||||
failed_connect_count = 0
|
||||
fail_safe_counter = 0
|
||||
elif data.startswith("download map:"):
|
||||
map_to_download = data.split("download map:")[1].strip()
|
||||
map_to_download_url = "https://uk-fastdl.unloze.com/css_ze/maps/" + map_to_download + ".bsp.bz2"
|
||||
map_folder = f"/home/{whoami}/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/download/maps/"
|
||||
bz2_path = map_folder + map_to_download + ".bsp.bz2"
|
||||
bsp_path = map_folder + map_to_download + ".bsp"
|
||||
|
||||
if os.path.exists(bsp_path):
|
||||
continue
|
||||
elif os.path.exists(bz2_path):
|
||||
continue
|
||||
else:
|
||||
with requests.get(map_to_download_url, stream=True, timeout=30) as r:
|
||||
r.raise_for_status()
|
||||
with open(bz2_path, "wb") as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
with open(bz2_path, "rb") as f:
|
||||
compressed_data = f.read()
|
||||
decompressed_data = bz2.decompress(compressed_data)
|
||||
with open(bsp_path, "wb") as f:
|
||||
f.write(decompressed_data)
|
||||
os.remove(bz2_path)
|
||||
print(f"downloaded and extracted map: {bsp_path}")
|
||||
overwrite_file_access()
|
||||
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
|
||||
if datetime.datetime.now() >= restart_time or return_user_owned_pid("pidof cstrike_linux64") is None:
|
||||
if datetime.datetime.now() >= restart_time or return_user_owned_pid("pidof cstrike_linux64") is None or check_instance_conflict_dialog() is not None:
|
||||
kill_owned_process("pidof cstrike_linux64")
|
||||
sock.close()
|
||||
print('exiting after running for several hours.')
|
||||
sys.exit(1)
|
||||
print('data: ', data)
|
||||
overwrite_file_access()
|
||||
check_if_bz2_downloading()
|
||||
bot_connect(data)
|
||||
failed_connect_count += 1
|
||||
if failed_connect_count >= 2:
|
||||
|
||||
fail_safe_counter += 1
|
||||
if fail_safe_counter >= 3:
|
||||
kill_owned_process("pidof cstrike_linux64")
|
||||
sock.close()
|
||||
print('exiting after running for several hours.')
|
||||
|
||||
Reference in New Issue
Block a user