import subprocess import socket import requests import os import stat import threading import gradio as gr def get_internal_ip(): hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) print(f"Internal IP: {local_ip}") def get_public_ip(): try: response = requests.get('https://ipinfo.io/ip') public_ip = response.text.strip() print(f"Public IP: {public_ip}") except requests.exceptions.RequestException as e: print(f"Failed to get public IP: {e}") def start_minecraft_server(): # Java 실행 파일 경로 java_executable = "./jdk-22.0.1/bin/java" # 압축 푼 자바 파일의 경로 # 파일에 실행 권한 부여 os.chmod(java_executable, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) # Minecraft 서버 JAR 파일 경로 minecraft_server_jar = "./paper-1.20.6-140.jar" # 서버 시작 명령어 command = [ java_executable, "-Xmx10240M", # 최대 힙 메모리 설정 (예: 10240MB) "-Xms10240M", # 초기 힙 메모리 설정 (예: 10240MB) "-jar", minecraft_server_jar, "nogui" ] # 서버 시작 process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # 서버 출력 읽기 while True: output = process.stdout.readline() if output == b'' and process.poll() is not None: break if output: print(output.strip().decode()) error = process.stderr.read().decode() if error: print(f"Error: {error}") def greet(name): return "Hello " + name + "!" def start_gradio(): with gr.Blocks() as demo: gr.Markdown( """ # 서버 상태 : ON! ## 서버 주소 : triples.kro.kr ## pc, 모바일 최신 릴리즈 ### (gerser 플러그인으로 모바일과 pc 호환) """ ) demo.launch(server_port='7861') if __name__ == "__main__": get_internal_ip() get_public_ip() t1 = threading.Thread(target=start_gradio) t2 = threading.Thread(target=start_minecraft_server) t1.start() t2.start() t1.join() t2.join()