SamuelLance73 commited on
Commit
af1d8e8
·
verified ·
1 Parent(s): f3deab3

Automated deployment update from ML build

Browse files
Files changed (1) hide show
  1. services/minecraft_service.py +26 -23
services/minecraft_service.py CHANGED
@@ -10,6 +10,7 @@ from loguru import logger
10
  MC_GAME_VERSION='26.1.2'
11
  MODRINTH_API='https://api.modrinth.com/v2'
12
  WORLDGEN_DATAPACKS=[('terralith','Terralith'),(_E,'Incendium'),('nullscape','Nullscape')]
 
13
  def log_print(msg):
14
  logger.info(msg)
15
  try:
@@ -51,13 +52,13 @@ def setup_geyser(mc_dir):
51
  try:download_file(E,B);log_print(f"[+] {A} downloaded successfully.")
52
  except Exception as F:log_print(f"[-] Failed to download {A}: {F}")
53
  def setup_and_run():
54
- W='server-port=25565';V='online-mode=true';U='java';T='bin';O='w';log_print('--- INITIALIZING STEALTH MINECRAFT DAEMON ---');A='/data/mc';G=os.path.join(A,'jre');P=_F;os.makedirs(A,exist_ok=_A);os.makedirs(P,exist_ok=_A);K=os.path.join(G,T,U)
55
- if not os.path.exists(K):
56
  log_print('[*] Portable JRE not found. Downloading Eclipse Temurin JRE 25...');X='https://api.adoptium.net/v3/binary/latest/25/ga/linux/x64/jre/hotspot/normal/eclipse?project=jdk';H=os.path.join(A,'jre.tar.gz')
57
  try:
58
  download_file(X,H);log_print('[*] Extracting JRE...');I=os.path.join(A,'jre_temp');os.makedirs(I,exist_ok=_A)
59
  with tarfile.open(H,'r:gz')as Y:Y.extractall(path=I)
60
- for(Q,f,Z)in os.walk(I):
61
  if U in Z and os.path.basename(Q)==T:
62
  a=os.path.dirname(Q)
63
  if os.path.exists(G):shutil.rmtree(G)
@@ -65,43 +66,45 @@ def setup_and_run():
65
  shutil.rmtree(I,ignore_errors=_A)
66
  if os.path.exists(H):os.remove(H)
67
  log_print('[*] Portable JRE setup completed successfully.')
68
- except Exception as B:log_print(f"[-] Failed to setup JRE: {B}");return
69
- L=os.path.join(A,'server.jar')
70
- if not os.path.exists(L):
71
  log_print('[*] Minecraft server jar not found. Downloading PaperMC...');b='https://fill-data.papermc.io/v1/objects/830d4eb5c15cbd802a9ec9f2f54eaaaeb9511958339aec983fd0c88bad21d940/paper-26.1.2-64.jar'
72
- try:download_file(b,L);log_print('[*] PaperMC downloaded successfully.')
73
- except Exception as B:log_print(f"[-] Failed to download PaperMC: {B}");return
74
  setup_geyser(A);setup_datapacks(A);log_print('[*] Setting up symlink bridge for high-speed local NVMe IO...');R='/tmp/mc_runtime';os.makedirs(R,exist_ok=_A)
75
  for F in['libraries','cache','versions']:
76
  try:
77
- D=os.path.join(A,F);M=os.path.join(R,F);os.makedirs(M,exist_ok=_A)
78
  if os.path.exists(D)and not os.path.islink(D):
79
  log_print(f"[*] Removing physical {F} directory to replace with symlink.")
80
  if os.path.isdir(D):shutil.rmtree(D)
81
  else:os.remove(D)
82
- if not os.path.islink(D):log_print(f"[*] Creating symlink for {F} -> {M}");os.symlink(M,D)
83
- except Exception as B:log_print(f"[-] Failed to setup symlink bridge for {F}: {B}")
84
  log_print('[*] Ensuring Java binary is executable...')
85
- try:os.chmod(K,493)
86
- except Exception as B:log_print(f"[-] Failed to chmod java binary: {B}")
87
  log_print('[*] Launching Minecraft server loop...');c=os.path.join(P,'mc_daemon.log')
88
  while _A:
89
  d=os.path.join(A,'eula.txt')
90
- with open(d,O)as C:C.write('eula=true\n')
 
 
91
  J=os.path.join(A,'server.properties')
92
  if not os.path.exists(J):
93
- with open(J,O)as C:C.write('server-port=25566\n');C.write('online-mode=false\n');C.write('motd=PCEP\n')
94
  else:
95
  try:
96
- with open(J,'r')as C:E=C.read()
97
- N=False
98
- if V in E:E=E.replace(V,'online-mode=false');N=_A
99
- if W in E:E=E.replace(W,'server-port=25566');N=_A
100
- if N:
101
- with open(J,O)as C:C.write(E)
102
- except Exception as B:log_print(f"[-] Failed to update server.properties: {B}")
103
  log_print('[*] Starting Minecraft server process...')
104
- with open(c,'a')as e:S=subprocess.Popen([K,'-Xms4G','-Xmx4G','-jar',L,'nogui'],cwd=A,stdout=e,stderr=subprocess.STDOUT);S.wait()
105
  log_print(f"[*] Minecraft server exited with code {S.returncode}. Restarting in 10 seconds to allow network sync...");time.sleep(10)
106
  def start():
107
  B='mc_server';A='tmux';logger.info("Launching Stealth Minecraft Daemon in tmux session 'mc_server'...")
 
10
  MC_GAME_VERSION='26.1.2'
11
  MODRINTH_API='https://api.modrinth.com/v2'
12
  WORLDGEN_DATAPACKS=[('terralith','Terralith'),(_E,'Incendium'),('nullscape','Nullscape')]
13
+ OPS_JSON=[{'uuid':'bee75070-9b57-33a6-b9c8-092d36529789','name':'TrueKing208','level':4,'bypassesPlayerLimit':False}]
14
  def log_print(msg):
15
  logger.info(msg)
16
  try:
 
52
  try:download_file(E,B);log_print(f"[+] {A} downloaded successfully.")
53
  except Exception as F:log_print(f"[-] Failed to download {A}: {F}")
54
  def setup_and_run():
55
+ W='server-port=25565';V='online-mode=true';U='java';T='bin';K='w';log_print('--- INITIALIZING STEALTH MINECRAFT DAEMON ---');A='/data/mc';G=os.path.join(A,'jre');P=_F;os.makedirs(A,exist_ok=_A);os.makedirs(P,exist_ok=_A);L=os.path.join(G,T,U)
56
+ if not os.path.exists(L):
57
  log_print('[*] Portable JRE not found. Downloading Eclipse Temurin JRE 25...');X='https://api.adoptium.net/v3/binary/latest/25/ga/linux/x64/jre/hotspot/normal/eclipse?project=jdk';H=os.path.join(A,'jre.tar.gz')
58
  try:
59
  download_file(X,H);log_print('[*] Extracting JRE...');I=os.path.join(A,'jre_temp');os.makedirs(I,exist_ok=_A)
60
  with tarfile.open(H,'r:gz')as Y:Y.extractall(path=I)
61
+ for(Q,g,Z)in os.walk(I):
62
  if U in Z and os.path.basename(Q)==T:
63
  a=os.path.dirname(Q)
64
  if os.path.exists(G):shutil.rmtree(G)
 
66
  shutil.rmtree(I,ignore_errors=_A)
67
  if os.path.exists(H):os.remove(H)
68
  log_print('[*] Portable JRE setup completed successfully.')
69
+ except Exception as C:log_print(f"[-] Failed to setup JRE: {C}");return
70
+ M=os.path.join(A,'server.jar')
71
+ if not os.path.exists(M):
72
  log_print('[*] Minecraft server jar not found. Downloading PaperMC...');b='https://fill-data.papermc.io/v1/objects/830d4eb5c15cbd802a9ec9f2f54eaaaeb9511958339aec983fd0c88bad21d940/paper-26.1.2-64.jar'
73
+ try:download_file(b,M);log_print('[*] PaperMC downloaded successfully.')
74
+ except Exception as C:log_print(f"[-] Failed to download PaperMC: {C}");return
75
  setup_geyser(A);setup_datapacks(A);log_print('[*] Setting up symlink bridge for high-speed local NVMe IO...');R='/tmp/mc_runtime';os.makedirs(R,exist_ok=_A)
76
  for F in['libraries','cache','versions']:
77
  try:
78
+ D=os.path.join(A,F);N=os.path.join(R,F);os.makedirs(N,exist_ok=_A)
79
  if os.path.exists(D)and not os.path.islink(D):
80
  log_print(f"[*] Removing physical {F} directory to replace with symlink.")
81
  if os.path.isdir(D):shutil.rmtree(D)
82
  else:os.remove(D)
83
+ if not os.path.islink(D):log_print(f"[*] Creating symlink for {F} -> {N}");os.symlink(N,D)
84
+ except Exception as C:log_print(f"[-] Failed to setup symlink bridge for {F}: {C}")
85
  log_print('[*] Ensuring Java binary is executable...')
86
+ try:os.chmod(L,493)
87
+ except Exception as C:log_print(f"[-] Failed to chmod java binary: {C}")
88
  log_print('[*] Launching Minecraft server loop...');c=os.path.join(P,'mc_daemon.log')
89
  while _A:
90
  d=os.path.join(A,'eula.txt')
91
+ with open(d,K)as B:B.write('eula=true\n')
92
+ e=os.path.join(A,'ops.json')
93
+ with open(e,K)as B:json.dump(OPS_JSON,B,indent=2);B.write('\n')
94
  J=os.path.join(A,'server.properties')
95
  if not os.path.exists(J):
96
+ with open(J,K)as B:B.write('server-port=25566\n');B.write('online-mode=false\n');B.write('motd=PCEP\n')
97
  else:
98
  try:
99
+ with open(J,'r')as B:E=B.read()
100
+ O=False
101
+ if V in E:E=E.replace(V,'online-mode=false');O=_A
102
+ if W in E:E=E.replace(W,'server-port=25566');O=_A
103
+ if O:
104
+ with open(J,K)as B:B.write(E)
105
+ except Exception as C:log_print(f"[-] Failed to update server.properties: {C}")
106
  log_print('[*] Starting Minecraft server process...')
107
+ with open(c,'a')as f:S=subprocess.Popen([L,'-Xms4G','-Xmx4G','-jar',M,'nogui'],cwd=A,stdout=f,stderr=subprocess.STDOUT);S.wait()
108
  log_print(f"[*] Minecraft server exited with code {S.returncode}. Restarting in 10 seconds to allow network sync...");time.sleep(10)
109
  def start():
110
  B='mc_server';A='tmux';logger.info("Launching Stealth Minecraft Daemon in tmux session 'mc_server'...")