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