-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.bat
192 lines (174 loc) · 8.67 KB
/
run.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
::Version: 1.2.3
@echo off
setlocal enableextensions enabledelayedexpansion
set ckBUILD=0&set ckEULA=0&set ckRES=0&set sE=0
set lp=
set m=512
set /a k=%m%*1024
set /a b=%k%*1024
set numList=0123456789
set "link=https://sourceforge.net/projects/upnp-portmapper/files/v2.1.1/portmapper-2.1.1.jar"
set ops=batch.settings&set prop=server.properties&set log=logs\latest.log&set "arqs=%date:~-4%-%date:~3,2%-%date:~0,2%-"
set "com=%~1"&if "%~2" neq "" (set /a port=%~2+1 &&echo.server-port:!port!>>!prop!)
for /f "tokens=*" %%f in ('dir /b /ad "..\*"') do (echo.%com%|find "%%f">nul||set n=%%f&&goto :getName)
:getName
set ret=%cd%
for /l %%i in (-1,-1,-128) do (echo.\/|find "!cd:~%%i,1!">nul&&(title Server !name! !port!&goto :run)||(set name=!cd:~%%i!||call :err dir_Check 0xA2 fetch_FAIL))
:run
call :batCall
call :mapCheck
if not exist !ver!-server.jar (call :buildServer)
if /i "!ver!"=="latest" (call :buildServer)
if %ckEULA%==3 (call :err eula_Set 0xD8 false)
if %ckRES%==3 (call :err restart_Set 0xD9 false)
if exist spigot.yml (call :spigUpdate)
if "%bun%"==" true" (echo.%com%%name%|find /i "%n%"||(start cmd /c "cd ..\%n% &&for %%i in (*run*.bat) do (start %%i %com%%n% %port%)"))
cls
echo.Join Externally Using !address![:!port!]
echo.Or Internally Using !intIP!:!port!
echo.
echo.Version=%ver%
echo.RAM=%ram%B
echo.
if not exist eula.txt (echo.eula=true>eula.txt)
call :mapSet add&java -Xmx!ram! -jar !ver!-server.jar nogui||call :err server_Strt 0xD4 FAIL
:chk
find /i "agree to the EULA" %log%>nul&&(set /a ckEULA=%ckEULA%+1&set /a sE=!sE!+1&echo.&&echo.Use This Time To Edit The Server Properties To How You Wish.&&pause>nul|echo.Press Any Key To Retry...&&goto :run)
find /i "Startup script" %log%>nul&&(cls&set /a ckRES=!ckRES!+1&set /a sE=!sE!+1&echo.&&echo.In Order For The Restart Command To Work You Must Edit Spigot.yml And Change "!rs!" to "restart-script: %runFile%".&&pause>nul|echo.Press Any Key To Restart...&&goto :run)
find /i "Attempting to restart" %log%>nul&&exit
call :mapSet delete
echo.%bun%|find /i "true">nul&&exit
choice /c YN /n /m "Do You Want To Backup Your Server (Y/ N): "
if %errorlevel% equ 1 (goto :backup) else (call :err end&&exit)
:backup
set backup=%backLoc%\%name%_Backup\%date:~8,2%-%date:~3,2%-%date:~0,2%
xcopy /S /Q /Y /F /I "..\%name%" "%backup%"||call :err backup_Comp 0x4D FAIL
call :err end back
echo.Your Server Has Been Backed Up To %backup%.&pause&&exit
:ver
cls&&echo.Fetching Version.
for /l %%i in (3,1,260) do (echo.!numList!|find /i "!cd:~%%i,1!">nul&&(if "!start!"=="" (set /a start=%%i) else (set /a end=%%i)))
set /a "len=%end%-%start%+1"
set ver=!cd:~%start%,%len%!
if "!ver!"=="%cd:~0,-1%" (set /p ver=No Version Found, Please Input A Valid Version: ||(set /a sE=!sE!+1&&call :ver||(call :err inv_Version 0x72 bad_FETCH)))
:loop
cls&if /i "!ver!"=="latest" exit /b
if "!ver:~%lp%!"=="" exit /b
echo.!numList!.|find /i "!ver:~%lp%,1!">nul||(set /p ver=Invalid Version, Please Input A Valid Version: &&set lp=||call :err inv_Version 0x73 no_VERSION)
set /a lp=%lp%+1&&goto :loop||call :err loop_Fail 0xC3 no_INC
:buildServer
if exist latest-server.jar (del latest-server.jar)
if %ckBUILD% == 3 (call :err build_Err 0x8E, "build_Attempts=%ckBUILD%")
echo.Version=!ver!
for /l %%i in (260,-1,0) do (echo.\/|find /i "!cd:~%%i,1!">nul&&set /a te=!te!+1)
for /l %%i in (1,1,%te%) do (if %%i neq !te! (cd ../&&if exist BuildTools (goto :cont)) else (cd !ret!&&cd ../&&mkdir BuildTools||call :err build_Err 0x83 mkdir_FAIL))
:cont
cd BuildTools
set buildLoc=%cd%
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastStableBuild/artifact/target/BuildTools.jar||call :err build_Err 0x89 no_BuildTool
cls
java -Xmx%ram% -jar BuildTools.jar --rev %ver% --output-dir %ret%||call :err build_Err 0x87 buildTool_FAIL
cd %ret%&cls
ren *spigot*.jar %ver%-server.jar||(set /a ckBUILD=%ckBUILD%+1&&goto :buildServer)
exit /b
:IP
for /f "tokens=3" %%g in ('route print 0.*') do (if "%%g" neq "" (set gw=%%g||call :err gw_IP 0xF0 fetch_FAIL))
for /f "tokens=*" %%i in ('curl -s ip-adresim.app -4') do set extIP=%%i||call :err ret_IP 0xF5 fetch_FAIL
for /f "tokens=2 delims=:" %%a in ('ipconfig^|find "v4"') do (set intIP=%%a&&set intIP=!intIP:~1!||call :err ret_IP 0xF6 fetch_FAIL)
exit /b
:port
cls&for /f "tokens=2 delims==" %%p in ('find /I "server-port" !prop!') do set port=%%p
if "%port%" equ "" (set /p "port=Please Select An IP Port For The Server (Default 25565): "||set port=25565)
if %port% lss 1024 (call :err inv_Port 0xF3 %port%)
if %port% gtr 65535 (call :err inv_Port 0xF3 %port%)
for /l %%i in (0,1,4) do (if "!port:~%%i,1!" neq "" (echo.!numList!|find /i "!port:~%%i,1!">nul||call :err inv_Port 0xF9 %port%))
echo.server-port=!port!>>!prop!||call :err inv_Port 0xFD save_FAIL
exit /b
:ram
cls
if "%~1"=="set" (set /p "ram=Input Max RAM Access For Server (Default 2GB): "||set ram=2G)
for /l %%i in (1,1,12) do (echo.GMKB|find /i "!ram:~%%i,1!">nul&&(set ram=!ram:~0,%%i!!ram:~%%i,1!&&break))
if /i "%ram:~-1%" equ "B" (if %ram:~0,-1% lss %b% (call :err inv_RAM 0x5A %ram%))
if /i "%ram:~-1%" equ "K" (if %ram:~0,-1% lss %k% (call :err inv_RAM 0x5A %ram%))
if /i "%ram:~-1%" equ "M" (if %ram:~0,-1% lss %m% (call :err inv_RAM 0x5A %ram%))
exit /b
:batCall
set "address="
echo.level-name=%name%>>!prop!
call :port&call :IP
for %%i in (*run*.bat) do set runFile=%%i
for /f "tokens=*" %%r in ('find /i "script" spigot.yml') do set rs=%%r
for /f "tokens=2 delims=:" %%b in ('find /i "bun" spigot.yml') do set bun=%%b
for /f "tokens=2 delims==" %%v in ('find /i "vers" %ops%') do set ver=%%v
for /f "tokens=2 delims==" %%s in ('find /i "skip" %ops%') do set skip=%%s
for /f "tokens=2 delims==" %%r in ('find /i "ram" %ops%') do set ram=%%r
for /f "tokens=2 delims==" %%a in ('find /i "add" %ops%') do set address=%%a
for /f "tokens=2 delims==" %%d in ('find /i "Def" %ops%') do set backDef=%%d
for /f "tokens=2 delims==" %%l in ('find /i "Loc" %ops%') do set backLoc=%%l
if "%ver%"=="" call :ver&&call :batRfrsh ver !ver!
if "%skip%"=="" call :batRfrsh skip false
if "%ram%"=="" call :ram set&&call :batRfrsh ram !ram!
if "%backDef%"=="" call :batRfrsh backDef No
if "%backLoc%"=="" call :batRfrsh backLoc !userprofile!\Desktop\Server_Backups
if "%address%"=="" set address=!extIP!
exit /b
:batRfrsh
set "%~1=%~2"&& (echo.version=!ver!>%ops%&&echo.skip-UPnP=!skip!>>%ops%&&echo.ram=!ram!>>%ops%&&echo.address=!address!>>%ops%&&echo.backup-Default=!backDef!>>%ops%&&echo.backup-Location=!backLoc!>>%ops%||call :err bat_Update 0xA8 FAIL)
exit /b
:mapCheck
cls&for %%i in (*portmap*.jar) do set portFile=%%i
if %skip%==false (
if not exist !portFile! (
echo.If You Don't Have The Port Mapper You Will Need To Port Forward Manually, To Do This You Will Need To Sign In To Your Default Gateway At !gw!, The Port Mapper Does Not Work If You Are Hosting A Network Bridge On This Host Device. Get The UPnP Port Mapper Version 2.1.1 From !link!
choice /c YN /n /m "Do You Want To Get It Now (Y/ N): "
if !errorlevel! equ 1 (start !link!) else (
choice /c YN /n /m "Do You Want To Skip The Portmapper Check In The Future (Y/ N): "
if !errorlevel! equ 1 (call :batRfrsh skip true) else (call :batRfrsh skip false)
echo.This Can Be Changed In The %ops% File To Re-enable This Check.&&timeout 3 /nobreak>nul
)
)
)
cls&exit /b
:mapSet
if exist !portFile! (java -jar !portFile! -%~1 -externalPort %port% -internalPort %port% -protocol TCP -lib org.chris.portmapper.router.weupnp.WeUPnPRouterFactory -description Minecraft>nul||call :err port_Set 0x2E %~1_FAILED)
exit /b
:spigUpdate
for /f "tokens=* delims=:" %%a in (spigot.yml) do (
echo.%%a|find /i "restart-script"&&(echo. restart-script: !runFile!>>tmp.yml)||(
if "%com%" neq "" (
echo.%%a|find /i "bungeecord"&&echo. bungeecord: true>>tmp.yml&&echo.online-mode=false>>!prop!||echo.%%a>>tmp.yml
)
if "%com%" equ "" (
echo.%%a|find /i "bungeecord"&&echo. bungeecord: false>>tmp.yml&&echo.online-mode=true>>!prop!||echo.%%a>>tmp.yml
)
)
echo.%%a
)
cls
del spigot.yml
ren tmp.yml spigot.yml
exit /b
:arq
cd logs
if exist "latest.log" (
for /l %%i in (1,1,9999) do (if not exist "%arqs%%%i.log.*" (tar -cf %arqs%%%i.log.tar latest.log)&&del latest.log&&cd %ret%&exit /b)
)
:err
cd %ret%&cls
if %~1==end (
echo.[%time:~0,-3%] Server.Name: !name!>>%log%
if "%~2"=="back" (echo.[%time:~0,-3%] Server.Backup: !backup!>>%log%)
echo.[%time:~0,-3%] Server.Flags: !sE!>>%log%
exit /b
)
call :arq
set /a sE=%sE%+1
echo.Error: %~1&&echo.[%time:~0,-3%] Error.Name: %~1>>%log%
echo.Tag: %~2&&echo.[%time:~0,-3%] Error.Tag: %~2>>%log%
echo.Value: %~3&&echo.[%time:~0,-3%] Error.Value: %~3>>%log%
if exist error-Codes.txt (
for /f "tokens=2 delims=-" %%e in ('find /i "%~2" error-Codes.txt') do set des=%%e
if "!des!" neq "" (echo.Description:!des!&&echo.[%time:~0,-3%] Error.Description:!des!>>%log%)
)
pause
exit 1