tripleS-Dev commited on
Commit
ef70cfd
โ€ข
1 Parent(s): b3c2dfa
Files changed (1) hide show
  1. main.py +74 -46
main.py CHANGED
@@ -3,50 +3,78 @@ import socket
3
  import requests
4
  import os
5
  import stat
 
 
6
 
7
- # ๋‚ด๋ถ€ IP ํ™•์ธ
8
- hostname = socket.gethostname()
9
- local_ip = socket.gethostbyname(hostname)
10
- print(f"Internal IP: {local_ip}")
11
-
12
- # ๊ณต์ธ IP ํ™•์ธ (๋Œ€์ฒด API ์‚ฌ์šฉ)
13
- try:
14
- response = requests.get('https://ipinfo.io/ip')
15
- public_ip = response.text.strip()
16
- print(f"Public IP: {public_ip}")
17
- except requests.exceptions.RequestException as e:
18
- print(f"Failed to get public IP: {e}")
19
-
20
- # Java ์‹คํ–‰ ํŒŒ์ผ ๊ฒฝ๋กœ
21
- java_executable = "./jdk-22.0.1/bin/java" # ์••์ถ• ํ‘ผ ์ž๋ฐ” ํŒŒ์ผ์˜ ๊ฒฝ๋กœ
22
-
23
- # ํŒŒ์ผ์— ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ
24
- os.chmod(java_executable, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
25
-
26
- # Minecraft ์„œ๋ฒ„ JAR ํŒŒ์ผ ๊ฒฝ๋กœ
27
- minecraft_server_jar = "./paper-1.20.6-140.jar"
28
-
29
- # ์„œ๋ฒ„ ์‹œ์ž‘ ๋ช…๋ น์–ด
30
- command = [
31
- java_executable,
32
- "-Xmx10240M", # ์ตœ๋Œ€ ํž™ ๋ฉ”๋ชจ๋ฆฌ ์„ค์ • (์˜ˆ: 10240MB)
33
- "-Xms10240M", # ์ดˆ๊ธฐ ํž™ ๋ฉ”๋ชจ๋ฆฌ ์„ค์ • (์˜ˆ: 10240MB)
34
- "-jar",
35
- minecraft_server_jar,
36
- "nogui"
37
- ]
38
-
39
- # ์„œ๋ฒ„ ์‹œ์ž‘
40
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41
-
42
- # ์„œ๋ฒ„ ์ถœ๋ ฅ ์ฝ๊ธฐ
43
- while True:
44
- output = process.stdout.readline()
45
- if output == b'' and process.poll() is not None:
46
- break
47
- if output:
48
- print(output.strip().decode())
49
-
50
- error = process.stderr.read().decode()
51
- if error:
52
- print(f"Error: {error}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()