mcs / main.py
tripleS-Dev
for linux
6134d95
raw
history blame
2.2 kB
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()