|
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_executable = "./jdk-22.0.1/bin/java" |
|
|
|
|
|
os.chmod(java_executable, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) |
|
|
|
|
|
minecraft_server_jar = "./paper-1.20.6-140.jar" |
|
|
|
|
|
command = [ |
|
java_executable, |
|
"-Xmx10240M", |
|
"-Xms10240M", |
|
"-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() |
|
|