tripleS-Dev
commited on
Commit
โข
ef70cfd
1
Parent(s):
b3c2dfa
for linux
Browse files
main.py
CHANGED
@@ -3,50 +3,78 @@ import socket
|
|
3 |
import requests
|
4 |
import os
|
5 |
import stat
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
hostname = socket.gethostname()
|
9 |
-
local_ip = socket.gethostbyname(hostname)
|
10 |
-
print(f"Internal IP: {local_ip}")
|
11 |
-
|
12 |
-
|
13 |
-
try:
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
except requests.exceptions.RequestException as e:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
import stat
|
6 |
+
import threading
|
7 |
+
import gradio as gr
|
8 |
|
9 |
+
def get_internal_ip():
|
10 |
+
hostname = socket.gethostname()
|
11 |
+
local_ip = socket.gethostbyname(hostname)
|
12 |
+
print(f"Internal IP: {local_ip}")
|
13 |
+
|
14 |
+
def get_public_ip():
|
15 |
+
try:
|
16 |
+
response = requests.get('https://ipinfo.io/ip')
|
17 |
+
public_ip = response.text.strip()
|
18 |
+
print(f"Public IP: {public_ip}")
|
19 |
+
except requests.exceptions.RequestException as e:
|
20 |
+
print(f"Failed to get public IP: {e}")
|
21 |
+
|
22 |
+
def start_minecraft_server():
|
23 |
+
# Java ์คํ ํ์ผ ๊ฒฝ๋ก
|
24 |
+
java_executable = "./jdk-22.0.1/bin/java" # ์์ถ ํผ ์๋ฐ ํ์ผ์ ๊ฒฝ๋ก
|
25 |
+
|
26 |
+
# ํ์ผ์ ์คํ ๊ถํ ๋ถ์ฌ
|
27 |
+
os.chmod(java_executable, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
28 |
+
|
29 |
+
# Minecraft ์๋ฒ JAR ํ์ผ ๊ฒฝ๋ก
|
30 |
+
minecraft_server_jar = "./paper-1.20.6-140.jar"
|
31 |
+
|
32 |
+
# ์๋ฒ ์์ ๋ช
๋ น์ด
|
33 |
+
command = [
|
34 |
+
java_executable,
|
35 |
+
"-Xmx10240M", # ์ต๋ ํ ๋ฉ๋ชจ๋ฆฌ ์ค์ (์: 10240MB)
|
36 |
+
"-Xms10240M", # ์ด๊ธฐ ํ ๋ฉ๋ชจ๋ฆฌ ์ค์ (์: 10240MB)
|
37 |
+
"-jar",
|
38 |
+
minecraft_server_jar,
|
39 |
+
"nogui"
|
40 |
+
]
|
41 |
+
|
42 |
+
# ์๋ฒ ์์
|
43 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
44 |
+
|
45 |
+
# ์๋ฒ ์ถ๋ ฅ ์ฝ๊ธฐ
|
46 |
+
while True:
|
47 |
+
output = process.stdout.readline()
|
48 |
+
if output == b'' and process.poll() is not None:
|
49 |
+
break
|
50 |
+
if output:
|
51 |
+
print(output.strip().decode())
|
52 |
+
|
53 |
+
error = process.stderr.read().decode()
|
54 |
+
if error:
|
55 |
+
print(f"Error: {error}")
|
56 |
+
|
57 |
+
def greet(name):
|
58 |
+
return "Hello " + name + "!"
|
59 |
+
|
60 |
+
def start_gradio():
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown(
|
63 |
+
"""
|
64 |
+
# ์๋ฒ ์ํ : ON!
|
65 |
+
"""
|
66 |
+
)
|
67 |
+
demo.launch()
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
get_internal_ip()
|
71 |
+
get_public_ip()
|
72 |
+
|
73 |
+
t1 = threading.Thread(target=start_gradio)
|
74 |
+
t2 = threading.Thread(target=start_minecraft_server)
|
75 |
+
|
76 |
+
t1.start()
|
77 |
+
t2.start()
|
78 |
+
|
79 |
+
t1.join()
|
80 |
+
t2.join()
|