import os CONFIG_FILE = "server_cfg.ini" CONTENT_FOLDER = "/home/sem/assetto-corsa/content" CONFIG_PATH = "/home/sem/assetto-corsa/cfg" # CONTENT_FOLDER = "./content" # CONFIG_PATH = "./cfg" def get_gamemodes() -> list: gamemodes = [0,0,0] # practice, qualify, race index = 0 config_path = os.path.join(CONFIG_PATH, CONFIG_FILE) with open(config_path,'r') as file: for line in file: line = line.strip() if line.startswith("[PRACTICE]"): index = 0 elif line.startswith("[QUALIFY]"): index = 1 elif line.startswith("[RACE]"): index = 2 elif line.startswith("TIME="): gamemodes[index] = int(line.replace("TIME=","").strip()) elif line.startswith("LAPS="): gamemodes[index] = int(line.replace("LAPS=","").strip()) print(f"loaded gamemodes: {gamemodes}") return gamemodes def update_gamemodes(practice: int, qualify: int, race: int) -> tuple[bool, str]: print(f"updating gamemodes to practice: {practice}, qualify: {qualify}, race: {race}") new_content = "" config_path = os.path.join(CONFIG_PATH, CONFIG_FILE) with open(config_path,'r') as file: in_practice = False in_qualify = False for line in file: line = line.strip() if line.startswith("[PRACTICE]"): in_practice = True in_qualify = False if line.startswith("[QUALIFY]"): in_practice = False in_qualify = True if line.startswith("TIME="): if in_practice: new_content += f"TIME={practice}" print(f"changing line to TIME={practice}") elif in_qualify: new_content += f"TIME={qualify}" print(f"changing line to TIME={qualify}") elif line.startswith("LAPS="): new_content += f"LAPS={race}" print(f"changing line to LAPS={race}") else: new_content += line new_content += "\n" with open(config_path,'w') as file: file.write(new_content) return True, "Gamemodes updated successfully."