Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::Want to understand how this code works? www.ss64.com/nt has a great explanation for most of the commands in here
- ::Keep the window clean and easy to read
- @echo off
- ::Set the title of the window
- title Garry's Mod Server Installer and Updater v0.1
- ::I don't know what this means but it fixes random things that weren't working related to the if statements
- setlocal enabledelayedexpansion
- ::If cfg.txt does not exist, prompt the user to input an install directory and then write it to a file (So it only has to be typed once)
- ::If it does exist, read it and set variable downloadDir to the contents of the file (which would be the install directory)
- echo ::=============================================::
- echo Welcome to Cheezus' Server Creator and Updater Script
- echo If this is your first time using this, follow all of the instructions carefully
- echo ::=============================================::
- if not exist cfg.txt (
- echo:
- echo Set the install location. Example - C:\My GMod Server\
- echo YOU MUST INCLUDE A FINAL BACKSLASH AT THE END\
- SET /p downloadDir=Install Directory: %"="%
- echo !downloadDir! >cfg.txt
- ) else (
- SET /p downloadDir=<cfg.txt
- echo Previous install directory automatically detected: !downloadDir!
- echo:
- )
- ::If the download directory folder does not exist, create it
- if not exist "%downloadDir%" (
- echo:
- echo Install location does not exist, creating folder...
- echo:
- mkdir "%downloadDir%"
- )
- ::Set the command prompt to run directly from the download directory
- cd "%downloadDir%"
- ::If steamcmd.exe already exists, skip downloading and run it. If not, assume it isn't installed and download it
- if exist steamcmd.exe (
- echo:
- echo SteamCMD already installed, starting...
- echo:
- goto run
- )
- ::If steamcmd.exe does not exist, use Windows PowerShell to pull it from Steam's website
- echo Downloading SteamCMD...
- powershell -Command "(New-Object Net.WebClient).DownloadFile('https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip', 'steamcmd.zip')"
- ::Random script I found online for extracting files.
- ::It works by using the echo command to write line-by-line to a temporary .vbs script file, and then running it afterwards (see line 76)
- echo Extracting...
- echo ZipFile="steamcmd.zip" > zip.vbs
- echo ExtractTo="./" >> zip.vbs
- echo Set fso = CreateObject("Scripting.FileSystemObject") >> zip.vbs
- echo sourceFile = fso.GetAbsolutePathName(ZipFile) >> zip.vbs
- echo destFolder = fso.GetAbsolutePathName(ExtractTo) >> zip.vbs
- echo Set objShell = CreateObject("Shell.Application") >> zip.vbs
- echo Set FilesInZip=objShell.NameSpace(sourceFile).Items() >> zip.vbs
- echo objShell.NameSpace(destFolder).copyHere FilesInZip, 16 >> zip.vbs
- echo Set fso = Nothing >> zip.vbs
- echo Set objShell = Nothing >> zip.vbs
- echo Set FilesInZip = Nothing >> zip.vbs
- CScript zip.vbs
- ::Don't want to keep the downloaded zip and the temporary vbs script lying around do we?
- echo Finished extracting, cleaning up...
- del steamcmd.zip
- del zip.vbs
- :run
- goto skip
- ::Launch steamcmd.exe, log in to the Valve servers and begin downloading Garry's Mod Dedicated Server
- ::Afterwards, it validates the files and then closes itself
- steamcmd.exe +login anonymous +app_update 4020 validate +quit
- :skip
- ::After the server downloads, create an instance of SRCDS Guardian to launch it
- ::Each line of code here is writing itself to a new .bat file which will be used to start the server
- echo Garry's Mod Dedicated Server successfully downloaded and validated.
- echo:
- :choice1
- echo If you were just updating, type N. If this is your first time, type Y.
- set /P c=Was this your first time running this script?[Y/N]
- if /I "%c%" EQU "Y" goto :first
- if /I "%c%" EQU "N" goto :notfirst
- goto :choice1
- :first
- echo Let's set up some things like...
- echo:
- echo The name of your server?
- SET /p servername=Server Name: %"="%
- echo:
- echo The default map?
- SET /p map=Default Map: %"="%
- echo:
- echo Max amount of players?
- SET /p maxplayers=Max Players: %"="%
- echo:
- echo Remote console password?
- SET /p rconpassword=RCON Password: %"="%
- echo:
- echo Workshop collection ID? If you aren't sure, leave this blank
- SET /p hostworkshopcollectionid=Workshop Collection ID: %"="%
- echo:
- echo Workshop auth key? If you don't have a collection for your server, leave this blank
- SET /p authkey=Workshop Authentication Key: %"="%
- echo:
- del %downloadDir%\steamapps\common\GarrysModDS\garrysmod\cfg\server.cfg
- echo hostname "%servername%" >%downloadDir%\steamapps\common\GarrysModDS\garrysmod\cfg\server.cfg
- :choice2
- echo If you don't already have a shortcut for your server, type Y
- set /P c=Do you want to create an instance of SRCDS Guardian?[Y/N]?
- if /I "%c%" EQU "Y" goto :yesguardian
- if /I "%c%" EQU "N" goto :noguardian
- goto :choice2
- :yesguardian
- echo Creating instance of SRCDS Guardian...
- echo:
- if not exist "%~dp0\Launch GMod Server - SRCDS Guardian 3.bat" (
- cd !%~dp0!
- echo ::File generated by Cheezus' Server Installer:: > "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: SRCDS Guardian 3.0 :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Mooga :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: SRCDS.com :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=========================================================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Thanks To Black-Sky ^& Drocona for making SRCDS Guardian :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: This script is open source. Feel free to edit at will. :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: This script was writen for the use of the srcds.com :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: online community. If you are interested in running a :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Source Dedicated Server or need help, drop by our :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: forums at... http://forums.srcds.com :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=========================================================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: SET YOUR VARIABLES! : class="re0">: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Window and Log name :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Replace "My Server" :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo set servername=%servername% >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Your start command :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Replace after = :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================::
- echo set runcmd=%downloadDir%steamapps\common\GarrysModDS\srcds.exe -console -game garrysmod +map %map% +maxplayers %maxplayers% +rcon_password %rconpassword% +host_workshop_collection %hostworkshopcollectionid% -authkey %authkey% >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: End of variables :: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: This will keep the window clean and easy to read >> "Launch Server - SRCDS Guardian 3.bat"
- echo @echo off >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Sets the title of the window >> "Launch Server - SRCDS Guardian 3.bat"
- echo title SRCDS Guardian 3.0 %%servername%% >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Clears the window incase there is anything there >> "Launch Server - SRCDS Guardian 3.bat"
- echo cls >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: Prints to the window what we are doing >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo SRCDS Guardian 3.0 has been started! >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo ************************************************************************* >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo To close the server, close this window and type exit in the server window >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo ************************************************************************* >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo %%servername%% is now starting... >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo :: This is a return point in case the server crashes or is closed >> "Launch Server - SRCDS Guardian 3.bat"
- echo :restart >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo ^(%%date%%^)^(%%time%%^) %%servername%% is now ONLINE >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo Watching %%servername%% for crashes... >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::Start the actual server >> "Launch Server - SRCDS Guardian 3.bat"
- echo start /wait %%runcmd%% >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo ^(%%date%%^)^(%%time%%^) Crash or Close detected! >> "Launch Server - SRCDS Guardian 3.bat"
- echo echo %%servername%% is now restarting... >> "Launch Server - SRCDS Guardian 3.bat"
- echo: >> "Launch Server - SRCDS Guardian 3.bat"
- echo ::Server crashed or closed, so we point it to the return point to start the server again >> "Launch Server - SRCDS Guardian 3.bat"
- echo goto restart >> "Launch Server - SRCDS Guardian 3.bat"
- )
- echo:
- :noguardian
- :notfirst
- echo Setup finished.
- echo If you delete the cfg.txt this script created, you'll have to type the
- echo directory again next time you run it.
- echo ::==============================::
- echo To launch your server, click on the file that was created when this script ran - 'Launch Server - SRCDS Guardian 3.bat'
- echo ::==============================::
- echo Whenever you want to update your server, run this script and it will automatically update.
- :end
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement