runserver.bat 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. @echo off
  2. rem ----- Configuration -----
  3. rem Defines the server type (txt or sql).
  4. set SERVER_TYPE=txt
  5. rem Defines how long to wait before restarting (in seconds).
  6. set SLEEP_TIME=15
  7. rem Defines whether to run all servers in one window (yes or no).
  8. set SINGLE_WINDOW=no
  9. rem ----- ------------- -----
  10. :L_Init
  11. set this=%0
  12. if %SERVER_TYPE% == txt set suffix=
  13. if %SERVER_TYPE% == sql set suffix=_sql
  14. if %SINGLE_WINDOW% == yes set wndswitch=/B
  15. :L_Main
  16. set command=%1
  17. if "%command%" == "" goto L_DefaultAction
  18. if %command% == exec goto L_ExecServerExe
  19. if %command% == start goto L_StartServerExe
  20. if %command% == stop goto L_StopServerExe
  21. if %command% == restart echo "TODO"
  22. goto L_EOF
  23. :L_DefaultAction
  24. :L_StartServer
  25. call %this% start login-server%suffix%.exe
  26. call %this% start char-server%suffix%.exe
  27. call %this% start map-server%suffix%.exe
  28. goto L_EOF
  29. :L_StopServer
  30. call %this% stop login-server%suffix%.exe
  31. call %this% stop char-server%suffix%.exe
  32. call %this% stop map-server%suffix%.exe
  33. goto L_EOF
  34. :L_StartServerExe
  35. set filename=%2
  36. if "%filename%" == "" goto L_StartServer
  37. if exist %filename% goto L_HaveExe
  38. echo Cannot start '%filename%' because the file is missing!
  39. goto L_EOF
  40. :L_HaveExe
  41. echo Starting %filename%...
  42. start "%filename%" %wndswitch% %this% exec %filename%
  43. goto L_EOF
  44. :L_StopServerExe
  45. set filename=%2
  46. if "%filename%" == "" goto L_StopServer
  47. if exist %windir%\system32\taskkill.exe goto L_HaveTaskKill
  48. echo The 'stop' command is not available on your system.
  49. exit
  50. :L_HaveTaskKill
  51. rem CAUTION! This will kill all processes called %filename%.
  52. echo Stopping '%filename%'...
  53. taskkill /F /FI "WINDOWTITLE eq %filename% - %this% exec %filename%"
  54. taskkill /F /IM "%filename%"
  55. goto L_EOF
  56. :L_ExecServerExe
  57. %filename%
  58. echo .
  59. echo .
  60. echo Server exited, restarting in %SLEEP_TIME% seconds! Press CTRL+C to abort!
  61. ping.exe -n %SLEEP_TIME% 127.0.0.1 > nul
  62. goto L_ExecServerExe
  63. :L_EOF