|
|
|
@ -3,6 +3,7 @@ import asyncio
|
|
|
|
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
|
|
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, MessageHandler, filters, ContextTypes
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import psutil
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import subprocess
|
|
|
|
@ -27,6 +28,7 @@ gaming_server_profiles = {
|
|
|
|
|
# Minecraft
|
|
|
|
|
"mc_vanilla" : {
|
|
|
|
|
'profile_id': 'vanilla',
|
|
|
|
|
'exec_type': 'java',
|
|
|
|
|
'server_name': 'Vanilla 1.21',
|
|
|
|
|
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/Vanilla_1-21/',
|
|
|
|
|
'command': ['C:/Program Files/Java/jdk-22/bin/java.exe', '-Xmx1024M', '-Xms1024M', '-jar', 'minecraft_server.1.21.jar', '--nogui', '--bonusChest'],
|
|
|
|
@ -34,6 +36,7 @@ gaming_server_profiles = {
|
|
|
|
|
},
|
|
|
|
|
"mc_sanderpack" : {
|
|
|
|
|
'profile_id': 'sanderpack',
|
|
|
|
|
'exec_type': 'java',
|
|
|
|
|
'server_name': 'The 1.12.2 Pack 1.6.3(SanderPack)',
|
|
|
|
|
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/1-12-2-Pack/',
|
|
|
|
|
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx16G', '-XX:+UseG1GC','-Xms4G', '-Dsun.rmi.dgc.server.gcInterval=2147483646', '-XX:+UnlockExperimentalVMOptions', '-XX:G1NewSizePercent=20', '-XX:G1ReservePercent=20', '-XX:MaxGCPauseMillis=50', '-XX:G1HeapRegionSize=32M', '-Dfml.queryResult=confirm', '-Duser.language=en', '-jar', 'forge-1.12.2-14.23.5.2860.jar', '--nogui', '--bonusChest'],
|
|
|
|
@ -41,6 +44,7 @@ gaming_server_profiles = {
|
|
|
|
|
},
|
|
|
|
|
"mc_sanderhorizons" : {
|
|
|
|
|
'profile_id': 'sanderhorizons',
|
|
|
|
|
'exec_type': 'java',
|
|
|
|
|
'server_name': 'GT New Horizons 2.6.0 (SanderHorizons)',
|
|
|
|
|
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/gt_new_horizons_2.6.0/',
|
|
|
|
|
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx12G', '-Xms4G', '-XX:+UseStringDeduplication', '-XX:+UseCompressedOops', '-XX:+UseCodeCacheFlushing', '-Dfml.readTimeout=180', '-jar', 'forge-1.7.10-10.13.4.1614-1.7.10-universal.jar', '--nogui', '--bonusChest'],
|
|
|
|
@ -48,6 +52,7 @@ gaming_server_profiles = {
|
|
|
|
|
},
|
|
|
|
|
"mc_sanderhardcore" : {
|
|
|
|
|
'profile_id': 'sanderhardcore',
|
|
|
|
|
'exec_type': 'java',
|
|
|
|
|
'server_name': 'RLCraft 2.9.3 (SanderHardcore)',
|
|
|
|
|
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/rlcraft/',
|
|
|
|
|
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Xmx16G', '-Xms4G', '-jar', 'forge-1.12.2-14.23.5.2860.jar', '--nogui', '--bonusChest'],
|
|
|
|
@ -55,12 +60,22 @@ gaming_server_profiles = {
|
|
|
|
|
},
|
|
|
|
|
"mc_sandervalley" : {
|
|
|
|
|
'profile_id': 'sandervalley',
|
|
|
|
|
'exec_type': 'java',
|
|
|
|
|
'server_name': 'Farming Valley (SanderValley)',
|
|
|
|
|
'directory': 'C:/Users/4lexK/Desktop/GameServers/Minecraft/farming_valley_1-1-2/',
|
|
|
|
|
'command': ['C:/Program Files/OpenLogic/jdk-8.0.412.08-hotspot/bin/java.exe', '-Dlog4j2.formatMsgNoLookups=true', '-Dlog4j.configurationFile=log4j2.xml', '-Xmx8G', '-Xms2G', '-jar', 'forge-1.10.2-12.18.3.2511-universal.jar', '--nogui', '--bonusChest'],
|
|
|
|
|
'wait_time': 30
|
|
|
|
|
},
|
|
|
|
|
# Dont Starve Together
|
|
|
|
|
"dst_vanilla": {
|
|
|
|
|
'profile_id': 'dst_sanders',
|
|
|
|
|
'exec_type': 'exe_dst',
|
|
|
|
|
'server_name': 'Dont Starve at Sanders',
|
|
|
|
|
'directory': "C:/Users/4lexK/Desktop/GameServers/Dont Starve/Dont Starve at Sanders (Vanilla)",
|
|
|
|
|
'command_DontStarveAtSandersOverworld': ["C:/Program Files (x86)/Steam/steamapps/common/Don't Starve Together Dedicated Server/bin/dontstarve_dedicated_server_nullrenderer.exe", '-persistent_storage_root', "C:/Users/4lexK/Desktop/GameServers/Dont Starve/Dont Starve at Sanders (Vanilla)", '-conf_dir', 'DontStarveAtSandersOverworld', '-console'],
|
|
|
|
|
'command_DontStarveAtSandersCaves': ["C:/Program Files (x86)/Steam/steamapps/common/Don't Starve Together Dedicated Server/bin/dontstarve_dedicated_server_nullrenderer.exe", '-persistent_storage_root', "C:/Users/4lexK/Desktop/GameServers/Dont Starve/Dont Starve at Sanders (Vanilla)", '-conf_dir', 'DontStarveAtSandersCave', '-console'],
|
|
|
|
|
'wait_time': 30
|
|
|
|
|
}
|
|
|
|
|
# Ragnarok Online
|
|
|
|
|
# World of Warcraft
|
|
|
|
|
}
|
|
|
|
@ -282,38 +297,77 @@ async def verify_password(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
|
|
|
|
|
####
|
|
|
|
|
def start_gameserver(profile: str) -> str:
|
|
|
|
|
response_msg = ""
|
|
|
|
|
if profile in gaming_server_profiles:
|
|
|
|
|
if profile in gaming_server_profiles:
|
|
|
|
|
server = gaming_server_profiles[profile]
|
|
|
|
|
os.chdir(server['directory'])
|
|
|
|
|
pid_file = os.path.join(server['directory'], 'server.pid')
|
|
|
|
|
log_file = os.path.join(server['directory'], 'logs', f'server_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log')
|
|
|
|
|
#wait_time = server['wait_time']
|
|
|
|
|
|
|
|
|
|
# Create logs directory if it doesn't exist
|
|
|
|
|
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
if os.path.exists(pid_file):
|
|
|
|
|
with open(pid_file, 'r') as file:
|
|
|
|
|
pid = int(file.read().strip())
|
|
|
|
|
if psutil.pid_exists(pid) and is_java_process(pid):
|
|
|
|
|
response_msg = f"Server {server['server_name']} läuft bereits."
|
|
|
|
|
return response_msg
|
|
|
|
|
else:
|
|
|
|
|
os.remove(pid_file)
|
|
|
|
|
|
|
|
|
|
with open(log_file, 'w') as log:
|
|
|
|
|
process = subprocess.Popen(
|
|
|
|
|
server['command'],
|
|
|
|
|
cwd=server['directory'],
|
|
|
|
|
stdout=log,
|
|
|
|
|
stderr=log,
|
|
|
|
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == 'nt' else 0
|
|
|
|
|
)
|
|
|
|
|
#time.sleep(wait_time)
|
|
|
|
|
with open(pid_file, 'w') as file:
|
|
|
|
|
file.write(str(process.pid))
|
|
|
|
|
response_msg = f"Server {server['server_name']} wurde mit PID '{process.pid}' gestartet."
|
|
|
|
|
executable_type = server['exec_type']
|
|
|
|
|
match executable_type:
|
|
|
|
|
case "java":
|
|
|
|
|
# Bei Java gibt es nur eine Jar zur Ausführung (nur eine Command)
|
|
|
|
|
os.chdir(server['directory'])
|
|
|
|
|
pid_file = os.path.join(server['directory'], 'server.pid')
|
|
|
|
|
log_file = os.path.join(server['directory'], 'logs', f'server_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log')
|
|
|
|
|
#wait_time = server['wait_time']
|
|
|
|
|
|
|
|
|
|
# Create logs directory if it doesn't exist
|
|
|
|
|
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
if os.path.exists(pid_file):
|
|
|
|
|
with open(pid_file, 'r') as file:
|
|
|
|
|
pid = int(file.read().strip())
|
|
|
|
|
if psutil.pid_exists(pid) and is_java_process(pid):
|
|
|
|
|
response_msg = f"Server {server['server_name']} läuft bereits."
|
|
|
|
|
return response_msg
|
|
|
|
|
else:
|
|
|
|
|
os.remove(pid_file)
|
|
|
|
|
|
|
|
|
|
with open(log_file, 'w') as log:
|
|
|
|
|
process = subprocess.Popen(
|
|
|
|
|
server['command'],
|
|
|
|
|
cwd=server['directory'],
|
|
|
|
|
stdout=log,
|
|
|
|
|
stderr=log,
|
|
|
|
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == 'nt' else 0
|
|
|
|
|
)
|
|
|
|
|
#time.sleep(wait_time)
|
|
|
|
|
with open(pid_file, 'w') as file:
|
|
|
|
|
file.write(str(process.pid))
|
|
|
|
|
response_msg = f"Server {server['server_name']} wurde mit PID '{process.pid}' gestartet."
|
|
|
|
|
case "exe_dst":
|
|
|
|
|
# Bei exe der DST sind immer mehrere Commands abzusetzen (je nach dem wie viele Shards da sind)
|
|
|
|
|
os.chdir(server['directory'])
|
|
|
|
|
# check for all shards -> everyone of them needs a pid and a log
|
|
|
|
|
cur_dir = Path.cwd()
|
|
|
|
|
dst_shards = [shard.name for shard in cur_dir.iterdir() if shard.is_dir() and shard.name != 'Agreements']
|
|
|
|
|
shard_cnt = len(dst_shards)
|
|
|
|
|
for shard in dst_shards:
|
|
|
|
|
|
|
|
|
|
pid_file = os.path.join(server['directory'], f'{shard}.pid')
|
|
|
|
|
log_file = os.path.join(server['directory'], 'logs', f'server_{shard}_{datetime.now().strftime("%Y%m%d_%H%M%S")}.log')
|
|
|
|
|
|
|
|
|
|
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# checken wie prozesse heißen
|
|
|
|
|
#if os.path.exists(pid_file):
|
|
|
|
|
# with open(pid_file, 'r') as file:
|
|
|
|
|
# pid = int(file.read().strip())
|
|
|
|
|
# if psutil.pid_exists(pid) and is_java_process(pid):
|
|
|
|
|
# response_msg = f"Server {server['server_name']} läuft bereits."
|
|
|
|
|
# return response_msg
|
|
|
|
|
# else:
|
|
|
|
|
# os.remove(pid_file)
|
|
|
|
|
|
|
|
|
|
with open(log_file, 'w') as log:
|
|
|
|
|
process = subprocess.Popen(
|
|
|
|
|
server[f'command_{shard}'],
|
|
|
|
|
cwd=server['directory'],
|
|
|
|
|
stdout=log,
|
|
|
|
|
stderr=log,
|
|
|
|
|
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == 'nt' else 0
|
|
|
|
|
)
|
|
|
|
|
#time.sleep(wait_time)
|
|
|
|
|
with open(pid_file, 'w') as file:
|
|
|
|
|
file.write(str(process.pid))
|
|
|
|
|
response_msg = f"Server {server['server_name']} wurde mit PID '{process.pid}' gestartet."
|
|
|
|
|
else:
|
|
|
|
|
response_msg = f"Server Informationen für Profile {profile} existieren nicht. Bitte prüfen."
|
|
|
|
|
return response_msg
|
|
|
|
|