Compare commits
2 Commits
6eb9797e15
...
663f2889d4
Author | SHA1 | Date |
---|---|---|
Alex | 663f2889d4 | 5 months ago |
Alex | c4cdded649 | 5 months ago |
@ -0,0 +1,107 @@
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
# Constants for server executable names
|
||||
LOGIN_SERVER = "login-server.exe"
|
||||
CHAR_SERVER = "char-server.exe"
|
||||
WEB_SERVER = "web-server.exe"
|
||||
MAP_SERVER = "map-server.exe"
|
||||
|
||||
# Store the process IDs for each server
|
||||
server_pids = {
|
||||
"login": None,
|
||||
"char": None,
|
||||
"web": None,
|
||||
"map": None,
|
||||
}
|
||||
|
||||
# Determine if the servers are running
|
||||
server_running = {
|
||||
"login": False,
|
||||
"char": False,
|
||||
"web": False,
|
||||
"map": False,
|
||||
}
|
||||
|
||||
def get_server_status(server_name, exe_name):
|
||||
"""Check if the server is running and retrieve its PID."""
|
||||
try:
|
||||
output = subprocess.check_output(f'tasklist /FI "IMAGENAME eq {exe_name}"', shell=True, text=True, errors="ignore")
|
||||
lines = output.strip().splitlines()
|
||||
if len(lines) > 1 and lines[1]:
|
||||
server_pids[server_name] = lines[1].split()[1]
|
||||
server_running[server_name] = True
|
||||
else:
|
||||
server_running[server_name] = False
|
||||
except subprocess.CalledProcessError:
|
||||
server_running[server_name] = False
|
||||
|
||||
def stop_server(server_name):
|
||||
"""Stop the specified server if it is running."""
|
||||
if server_running[server_name]:
|
||||
subprocess.call(f"taskkill /PID {server_pids[server_name]} /F", cwd=r"C:\Users\4lexK\Desktop\GameServerFiles\SanderRo_rathena\2 . Emulator\rathena", shell=True)
|
||||
print(f"{server_name.capitalize()} server stopped.")
|
||||
else:
|
||||
print(f"{server_name.capitalize()} server is not running.")
|
||||
|
||||
def start_server(server_name, script_name, restart_mode):
|
||||
"""Start the specified server if it is not already running."""
|
||||
if not server_running[server_name]:
|
||||
subprocess.Popen(f"cmd /k {script_name} restart_mode={restart_mode}", cwd=r"C:\Users\4lexK\Desktop\GameServerFiles\SanderRo_rathena\2 . Emulator\rathena", shell=True)
|
||||
print(f"{server_name.capitalize()} server started.")
|
||||
else:
|
||||
print(f"{server_name.capitalize()} server is already running with PID {server_pids[server_name]}.")
|
||||
|
||||
def stop_all_servers():
|
||||
"""Stop all servers."""
|
||||
print("Stopping all servers...")
|
||||
stop_server("login")
|
||||
stop_server("char")
|
||||
stop_server("web")
|
||||
stop_server("map")
|
||||
|
||||
def start_all_servers(restart_mode="off"):
|
||||
"""Start all servers."""
|
||||
print("Starting all servers...")
|
||||
start_server("login", 'logserv.bat', restart_mode)
|
||||
start_server("char", 'charserv.bat', restart_mode)
|
||||
start_server("web", 'webserv.bat', restart_mode)
|
||||
start_server("map", 'mapserv.bat', restart_mode)
|
||||
|
||||
def check_status():
|
||||
""" Check the status of all servers.
|
||||
"""
|
||||
print("Getting status of all servers...")
|
||||
get_server_status("login", LOGIN_SERVER)
|
||||
get_server_status("char", CHAR_SERVER)
|
||||
get_server_status("web", WEB_SERVER)
|
||||
get_server_status("map", MAP_SERVER)
|
||||
|
||||
for server, running in server_running.items():
|
||||
if running:
|
||||
print(f"{server.capitalize()} server is running with PID {server_pids[server]}")
|
||||
else:
|
||||
print(f"{server.capitalize()} server is not running.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="rAthena Ragnarok Online Server Emulator Control Script")
|
||||
parser.add_argument('target', choices=['status', 'watch', 'stop', 'start'], help="Choose the target action")
|
||||
|
||||
# Show help if no arguments are provided
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.target == "status":
|
||||
check_status()
|
||||
elif args.target == "watch":
|
||||
start_all_servers(restart_mode="on")
|
||||
elif args.target == "stop":
|
||||
stop_all_servers()
|
||||
elif args.target == "start":
|
||||
start_all_servers(restart_mode="off")
|
Loading…
Reference in New Issue