check_eula function

This commit is contained in:
espeon65536 2021-08-08 15:36:12 -05:00 committed by Fabian Dill
parent 527a9b49e2
commit 9e1748bf67
1 changed files with 27 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import atexit
from subprocess import Popen from subprocess import Popen
from shutil import copyfile from shutil import copyfile
from base64 import b64decode from base64 import b64decode
from json import loads from time import strftime
import requests import requests
@ -106,7 +106,31 @@ def update_mod(forge_dir):
print(f"Error checking for randomizer mod updates (status code {resp.status_code}).") print(f"Error checking for randomizer mod updates (status code {resp.status_code}).")
print(f"If this was not expected, please report this issue on the Archipelago Discord server.") print(f"If this was not expected, please report this issue on the Archipelago Discord server.")
if not prompt_yes_no("Continue anyways?"): if not prompt_yes_no("Continue anyways?"):
sys.exit(1) sys.exit(0)
# Check if the EULA is agreed to, and prompt the user to read and agree if necessary.
def check_eula(forge_dir):
eula_path = os.path.join(forge_dir, "eula.txt")
if not os.path.isfile(eula_path):
# Create eula.txt
with open(eula_path, 'w') as f:
f.write("#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).\n")
f.write(f"#{strftime('%a %b %d %X %Z %Y')}\n")
f.write("eula=false\n")
with open(eula_path, 'r+') as f:
text = f.read()
if 'false' in text:
# Prompt user to agree to the EULA
print("You need to agree to the Minecraft EULA in order to run the server.")
print("The EULA can be found at https://account.mojang.com/documents/minecraft_eula")
if prompt_yes_no("Do you agree to the EULA?"):
f.seek(0)
f.write(text.replace('false', 'true'))
f.truncate()
print(f"Set {eula_path} to true")
else:
sys.exit(0)
# Run the Forge server. Return process object # Run the Forge server. Return process object
@ -151,5 +175,6 @@ if __name__ == '__main__':
update_mod(forge_dir) update_mod(forge_dir)
replace_apmc_files(forge_dir, apmc_file) replace_apmc_files(forge_dir, apmc_file)
check_eula(forge_dir)
server_process = run_forge_server(forge_dir, max_heap) server_process = run_forge_server(forge_dir, max_heap)
server_process.wait() server_process.wait()