runserver.bat 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. @echo off
  2. rem This is and auto-restart script for the rAthena Ragnarok Online Server Emulator.
  3. rem It will also keep the map server OPEN after it crashes to that errors may be
  4. rem more easily identified
  5. rem Writen by Jbain
  6. rem modified by lighta
  7. set SOURCE_DIR=%~dp0
  8. cd %SOURCE_DIR%
  9. if ["%~1"]==[""] (
  10. REM this is for backward compatibility
  11. set "target=watch"
  12. ) else set target=%~1
  13. echo "target=%target%"
  14. REM to avoid any localization issue
  15. set "login_running=false"
  16. set "char_running=false"
  17. set "map_running=false"
  18. if "%target%" == "status" (
  19. call :getStatus
  20. ) else if "%target%" == "watch" (
  21. call :Watch
  22. ) else if "%target%" == "stop" (
  23. call :Stop
  24. ) else if "%target%" == "stop" (
  25. call :Stop
  26. ) else if "%target%" == "start" (
  27. call :Start
  28. )
  29. goto :EOF
  30. :Stop
  31. echo "Stoping all serv"
  32. call :stopLogin
  33. call :stopChar
  34. call :stopMap
  35. goto :EOF
  36. :Watch
  37. REM this is to align terminology with athena-start, (start with restart mode)
  38. echo "Starting all serv"
  39. set "resart_mode=on"
  40. call :startLogin
  41. call :startChar
  42. call :startMap
  43. goto :EOF
  44. :Start
  45. echo "Starting all serv"
  46. set "resart_mode=off"
  47. call :startLogin
  48. call :startChar
  49. call :startMap
  50. goto :EOF
  51. :getStatus
  52. echo "Getting status of all serv"
  53. call :getLoginStatus
  54. call :getCharStatus
  55. call :getMapStatus
  56. if "%login_running%" == "false" ( echo "login_serv is not running"
  57. ) else echo "login_serv is running pid=%LoginServPID%"
  58. if "%char_running%" == "false" ( echo "char_serv is not running"
  59. ) else echo "char_serv is running pid=%CharServPID%"
  60. if "%map_running%" == "false" ( echo "map_serv is not running"
  61. ) else echo "map_serv is running pid=%MapServPID%"
  62. goto :EOF
  63. REM ====
  64. REM sub targets (a target per serv)
  65. REM ====
  66. REM stop sub targets
  67. :stopLogin
  68. call :getLoginStatus
  69. if "%login_running%" == "true" Taskkill /PID %LoginServPID% /F
  70. goto :EOF
  71. :stopChar
  72. call :getCharStatus
  73. if "%char_running%" == "true" Taskkill /PID %CharServPID% /F
  74. goto :EOF
  75. :stopMap
  76. call :getMapStatus
  77. if "%map_running%" == "true" Taskkill /PID %MapServPID% /F
  78. goto :EOF
  79. REM start sub targets
  80. :startLogin
  81. call :getLoginStatus
  82. if "%login_running%" == "false" ( start cmd /k logserv.bat %resart_mode%
  83. ) else echo "Login serv is already running pid=%LoginServPID%"
  84. goto :EOF
  85. :startChar
  86. call :getCharStatus
  87. if "%char_running%" == "false" ( start cmd /k charserv.bat %resart_mode%
  88. ) else echo "Char serv is already running, pid=%CharServPID%"
  89. goto :EOF
  90. :startMap
  91. call :getMapStatus
  92. if "%map_running%" == "false" ( start cmd /k mapserv.bat %resart_mode%
  93. ) else echo "Map serv is already running, pid=%MapServPID%"
  94. goto :EOF
  95. REM status sub targets
  96. :getLoginStatus
  97. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq login-server.exe"') do set LoginServPID=%%b
  98. echo(%LoginServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "login_running=true" || set "login_running=false"
  99. goto :EOF
  100. :getCharStatus
  101. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq char-server.exe"') do set CharServPID=%%b
  102. echo(%CharServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "char_running=true" || set "char_running=false"
  103. goto :EOF
  104. :getMapStatus
  105. for /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq map-server.exe"') do set MapServPID=%%b
  106. echo(%MapServPID%|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul&& set "map_running=true" || set "map_running=false"
  107. goto :EOF