-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.bat
288 lines (260 loc) · 10.2 KB
/
start.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@echo off
setlocal enabledelayedexpansion
set Version=1.7.6
set configDir=.\.AdvanceStartup
:: change the line below to use different java (point to java.exe)
set java=java
:firstbootcheck
:: Check if the startup config directory exists if not creat a new directory & configfile
if not exist "%configDir%" (
call :firstboot
)
:: Reads the startup config file and fetches the variables from the config file and ignores "#" comments
for /f "delims=" %%i in (%configDir%\settings.yml) do (
if not "%%i" == "#*" (
for /f "tokens=1,2 delims=: " %%a in ("%%i") do (
set "%%a=%%b"
)
)
)
:: Sets the title of the console window
title %Title%
cls
call :k8
timeout 2 >nul
cls
:: Prints the current configuration
echo.
echo [40;33mServer Console Made By Krak8 ^(https^://krak8.xyz^)
echo [40;36m.......................................................
echo [40;32mStandalone/Proxy: [40;33m%proxy%
echo [40;32mStarting [40;33m%serverjar%
echo [40;32mMaximum memory: [40;33m%maxram% [40;32mInitial memory: [40;33m%iniRam%
echo [40;32mUse Aikar Flags: [40;33m%aikarflags%
echo [40;32mAutoRestart: [40;33m%autorestart%
echo [40;32mEULA: [40;33m%EULA%
echo [40;32mVanila GUI: [40;33m%GUI%
echo [40;36m.......................................................[0m
echo To make changes to current configuration press 0
echo Server is starting ...
CHOICE /N /T 6 /D 9 /C:09
cls
if %errorlevel%==1 ( call :configedit )
:autorestart
if %autorestart%==true (
call :startserver
echo [40;31mServer has closed or crashed...
echo.
echo [40;32mThe Server will restart after %TimeOut%s timeout close console window to stop server or press ctrl^+c ![0m
timeout %TimeOut% >nul
goto :autorestart
)
:startserver
call :ram
call :flags
call :gui
call :pre_autodownload
call :eula
:: Running the forge server
if %aServerJarType%==forge ( %java% %ram% @libraries/net/minecraftforge/forge/%afilename%/win_args.txt %gui% %* )
:: Running the proxy/normal server
if %proxy%==true ( %java% %ram% -jar %serverjar% ) else (
%java% %ram% %flags% -jar %serverjar% %gui%
)
goto :eof
exit
:ram
:: Set the ram var
set ram=-Xmx%maxram% -Xms%iniRam%
cls
goto :eof
:eula
if %EULA%==true (
(
echo #By changing the setting below to TRUE you are indicating your agreement to our EULA ^(https://account.mojang.com/documents/minecraft_eula^).
echo #You also agree that tacos are tasty, and the best food in the world.
echo #Auto generated EULA from script Made By Krak8 ^(https^://youtube.com/krak8^).
echo eula=true
) > eula.txt
)
if %EULA%==false (
(
echo #By changing the setting below to TRUE you are indicating your agreement to our EULA ^(https://account.mojang.com/documents/minecraft_eula^).
echo #You also agree that tacos are tasty, and the best food in the world.
echo #Auto generated EULA from script Made By Krak8 ^(https^://youtube.com/krak8^).
echo eula=false
) > eula.txt
)
:flags
(
:: basic aikar flags
set bflag=-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Daikars.new.flags=true -Dusing.aikars.flags=https://mcutils.com
:: advance aikar flags for 12Gb +
set aflag=-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Daikars.new.flags=true -Dusing.aikars.flags=https://mcutils.com
:: Extract the numeric part and the unit
set "ramValue=%maxram:~0,-1%"
set "ramUnit=%maxram:~-1%"
)
:: Convert to megabytes
if /i "%ramUnit%"=="G" (
set /a ramM= %ramValue% * 1024
)
if %aikarflags%==true (
:: Compare the value
if %ramM% lss 12288 (
set "flags=%bflag% %AdvanceFlags%"
) else (
set "flags=%aflag% %AdvanceFlags%"
)
)
cls
goto :eof
:gui
if %GUI%==true set %gui%=
if %GUI%==false set gui=--nogui
cls
goto :eof
:pre_autodownload
:: Reads the server auto download log and fetches the variables from the file if exists and ignores "#" comments
for /f "delims=" %%i in (%configDir%\autodownload.log) do (
if not "%%i" == "#*" (
for /f "tokens=1,2 delims=: " %%a in ("%%i") do (
set "%%a=%%b"
)
)
)
if %autodownload%==true (
if not exist "%configDir%\autodownload.log" ( call :autodownload ) else (
echo You are currently using %aServerJarType%^-%aServerVersion%
echo if you want to change or update the curent server jar press 0 else ignore.
CHOICE /N /T 6 /D 9 /C:09
if %errorlevel%==1 ( call :autodownload )
)
)
cls
goto :eof
:firstboot
cls
set configUrl=https://raw.githubusercontent.com/Krak8/MC-Startup/refs/heads/main/assets/settings.yml
mkdir %configDir%
cls
echo.
echo This is the first time you are using this Minecraft Server Starter.
echo Please wait for few moments while we create a config file.
echo You will be prompted to edit a settings.yml file using your default editor.
powershell -Command "(New-Object Net.WebClient).DownloadFile('%configUrl%', '%configDir%\settings.yml')"
timeout 10 >nul
cls
:configedit
echo.
echo Press any key once you are done editing the settings.
echo Remember to save the file before pressing key
start "" "%configDir%\settings.yml"
pause >nul
cls
goto :eof
:autodownload
del %serverjar%
del %configDir%\autodownload.log
set autoUrl=https://mcutils.com/api/server-jars
:: Fetch the JSON data using PowerShell and save it to a temporary file
powershell -Command "Invoke-WebRequest -Uri '%autoUrl%' -UseBasicParsing | Select-Object -ExpandProperty Content | Out-File -FilePath server.json"
:: Parse the JSON and extract the keys using PowerShell
for /f "tokens=*" %%i in ('powershell -Command "Get-Content server.json | ConvertFrom-Json | ForEach-Object { $_.key }"') do (
set /a count+=1
set "key!count!=%%i"
)
:: Display the options to the user
echo Please choose the server jar:
for /l %%i in (1,1,%count%) do (
echo %%i. !key%%i!
)
:: Get user input
set /p choice=Enter the number of your choice:
:: Validate the input and save the selected key in a variable
if %choice% gtr 0 if %choice% leq %count% (
set "autoServerJar=!key%choice%!"
echo You selected: !autoServerJar!
:: Clean up the temporary file
del server.json
) else (
echo Invalid choice.
pause
exit
)
echo.
echo.
set choice=0
set count=0
:: Fetch available minecraft versions
powershell -Command "Invoke-WebRequest -Uri '%autoUrl%/!autoServerJar!' -UseBasicParsing | Select-Object -ExpandProperty Content | Out-File -FilePath version.json"
:: Parse the JSON and extract the version using PowerShell
for /f "tokens=*" %%i in ('powershell -Command "Get-Content version.json | ConvertFrom-Json | ForEach-Object { $_.version }"') do (
set /a count+=1
set "version!count!=%%i"
)
:: Display the options to the user
echo Please choose the version:
for /l %%i in (1,1,%count%) do (
echo %%i. !version%%i!
)
:: Get user input
set /p choice=Enter the number of your choice:
:: Validate the input and save the selected key in a variable
if %choice% gtr 0 if %choice% leq %count% (
set "autoVersion=!version%choice%!"
echo You selected: !autoVersion!
:: Clean up the temporary file
del version.json
) else (
echo Invalid choice.
pause
exit
)
(
echo aServerJarType: !autoServerJar!
echo aServerVersion: !autoVersion!
echo aDate: %date%
echo aURL: %autoUrl%/!autoServerJar!/!autoVersion!/download
) > %configDir%\autodownload.log
cls
echo Downloading the server jar ^(!autoServerJar!^-!autoVersion!^) please wait...
powershell -Command "(New-Object Net.WebClient).DownloadFile('%autoUrl%/!autoServerJar!/!autoVersion!/download', '%serverjar%')"
echo The server jar (!autoServerJar!^-!autoVersion!^) has been downloaded and saved as %serverjar%
:: handler for forge
if !autoServerJar!==forge (
:: Download the file and save the response headers
curl -IL "%autoUrl%/!autoServerJar!/!autoVersion!/download" > headers.txt
:: Read the line from headers.txt
for /f "tokens=2 delims=;" %%a in ('findstr /i "content-disposition" headers.txt') do (
set rawname=%%a
)
rem Remove "forge-" and "-installer.jar"
set "temp=!rawname:"forge-=!"
set "rawfilename=!temp:-installer.jar"=!"
rem Extract the filename
for /f "tokens=2 delims== " %%a in ("!rawfilename!") do (
set filename=%%a
)
echo afilename: !filename! >> %configDir%\autodownload.log
%java% -jar %serverjar% --installServer
del headers.txt
del user_jvm_args.txt
del server.jar.log
del run.bat
del run.sh
)
timeout 2 >nul
cls
goto :startserver
:k8
echo.
echo [40;33m /$$ /$$ /$$ /$$$$$$
echo [40;33m^| $$ /$$/ ^| $$ /$$__ $$
echo [40;33m^| $$ /$$/ /$$$$$$ /$$$$$$ ^| $$ /$$ ^| $$ \ $$
echo [40;33m^| $$$$$/ /$$__ $$ ^|____ $$ ^| $$ /$$/ ^| $$$$$$/
echo [40;33m^| $$ $$ ^| $$ \__/ /$$$$$$$ ^| $$$$$$/ ^>$$__ $$
echo [40;33m^| $$\ $$ ^| $$ /$$__ $$ ^| $$_ $$ ^| $$ \ $$
echo [40;33m^| $$ \ $$ ^| $$ ^| $$$$$$$ ^| $$ \ $$ ^| $$$$$$/
echo [40;33m^|__/ \__/ ^|__/ \_______/ ^|__/ \__/ \______/
goto :eof