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 Manager v0.2
- ::Forces the if statements to be processed line-by-line instead of all at once (fixes some wonky variable issues)
- setlocal enabledelayedexpansion
- :mainMenu
- ::Clears the screen
- cls
- color B
- echo ::================MAIN MENU=====================::
- echo Welcome to Cheezus' Server Manager
- echo If this is your first time using this, follow all of the instructions carefully
- echo ::=============================================::
- echo:
- echo What would you like to do?
- echo:
- echo Type 1 to install a new server/download SteamCMD
- echo Type 2 to update an existing server
- echo Type 3 to generate a new SRCDS Guardian server launcher
- echo:
- ::Simple prompt which asks the user what they want to do and goes to a different section of code accordingly
- :invalidAnswer1
- set /P c=Answer:
- if /I "!c!" EQU "1" goto newServer
- if /I "!c!" EQU "2" goto updateServer
- if /I "!c!" EQU "3" goto generateGuardian
- goto invalidAnswer1
- :newServer
- cls
- color C
- echo ::=====::
- echo IMPORTANT
- echo ::=====::
- echo:
- echo When this script runs it will generate a cfg.txt file which will store some
- echo information regarding your server. It is recomended that you keep that
- echo file in the same directory as this script, if you plan on running this in the
- echo future to update your server.
- echo:
- pause
- cls
- color B
- echo First, set the install location. Example - typing C:\My GMod Server\ will
- echo create a folder named 'My GMod Server' in the root path of drive C:
- echo YOU MUST INCLUDE A BACKSLASH AT THE END LIKE IN THE EXAMPLE
- echo:
- ::Prompt the user for their preferred install directory, and save it to a file called cfg.txt in the same directory as this script
- SET /p downloadDir=Install Directory: %"="%
- echo !downloadDir! >cfg.txt
- cls
- ::If the download directory does not exist, create it
- if not exist !downloadDir! (
- echo:
- echo It appears that directory doesn't exist, creating it...
- mkdir !downloadDir!
- )
- ::Set the script to run from the server's download directory to make things easier
- cd !downloadDir!
- ::Use Windows PowerShell command to download steamcmd.zip from Valve's servers
- echo:
- echo steamcmd.exe not found, downloading...
- powershell -Command "(New-Object Net.WebClient).DownloadFile('https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip', 'steamcmd.zip')"
- ::Because we can't run vbscript commands directly in Batch, first we write each line of code to a temporary file called zip.vbs
- ::This will be used to extract the zip file
- 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
- ::Run the script we just wrote
- CScript zip.vbs
- ::Delete the temporary script file and the zip to keep things clean
- echo Finished extracting, cleaning up...
- del steamcmd.zip
- del zip.vbs
- ::Run steamcmd.exe and download/update Garry's Mod Dedicated Server, then quit when it's finished
- steamcmd.exe +login anonymous +app_update 4020 validate +quit
- echo Garry's Mod Dedicated Server successfully downloaded and validated.
- ::Set the script to run from the directory it's currently in, as it was when it was first started
- cd !%~dp0!
- ::Prompt the user for some general server settings, then write them line-by-line to the cfg file
- echo:
- echo Let's set up some things like...
- echo:
- echo The name of your server?
- SET /p serverName=Server Name: %"="%
- echo !serverName! >>cfg.txt
- echo:
- echo The default map?
- SET /p defaultMap=Default Map: %"="%
- echo !defaultMap! >>cfg.txt
- echo:
- echo Max amount of players?
- SET /p maxPlayers=Max Players: %"="%
- echo !maxPlayers! >>cfg.txt
- echo:
- echo Remote console password?
- SET /p rconPassword=RCON Password: %"="%
- echo !rconPassword! >>cfg.txt
- echo:
- echo Workshop collection ID? If you aren't sure, leave this blank
- SET /p collectionID=Workshop Collection ID: %"="%
- echo !collectionID! >>cfg.txt
- echo:
- echo Workshop auth key? If you don't have a collection for your server,
- echo leave this blank
- SET /p authKey=Workshop Authentication Key: %"="%
- echo !authKey! >>cfg.txt
- echo:
- ::If the server's cfg folder doesn't exist for some reason, create it
- if not exist !downloadDir!\steamapps\common\GarrysModDS\garrysmod\cfg\ (
- mkdir !downloadDir!\steamapps\common\GarrysModDS\garrysmod\cfg\
- )
- ::Write the server name to the server's server.cfg file, to set the name that appears in Garry's Mod
- echo hostname "!servername!" >!downloadDir!\steamapps\common\GarrysModDS\garrysmod\cfg\server.cfg
- cls
- goto writeGuardian
- ::If you clicked "update server" in the main menu, you're sent to this part of the code
- :updateServer
- cls
- ::If cfg.txt is detected, get the settings from there. Otherwise, prompt user to input their info again
- if exist cfg.txt (
- SET /p downloadDir=<cfg.txt
- echo Directory automatically detected as !downloadDir!
- ) else (
- echo cfg.txt not found, please enter the directory the server installed to
- echo YOU MUST INCLUDE A BACKSLASH AT THE END ^( \ ^)
- echo:
- SET /p downloadDir=Install Directory: %"="%
- )
- ::If steamcmd.exe exists, continue updating. Otherwise, you probably fucked up.
- if exist !downloadDir!\steamcmd.exe (
- goto steamCmdExists
- ) else (
- echo:
- echo steamcmd.exe not found. Are you the directory is correct?
- echo Press any key to return to the main menu
- echo:
- pause
- goto mainMenu
- )
- :steamCmdExists
- cls
- ::Update the server with SteamCMD
- echo Updating server...
- echo:
- steamcmd.exe +login anonymous +app_update 4020 validate +quit
- echo:
- echo Server successfully updated and validated
- echo Press any key to return to the main menu
- echo:
- pause
- goto mainMenu
- ::If the user wants to generate a new SRCDS Guardian, they get sent to this part of the code
- :generateGuardian
- cls
- ::If cfg.txt exists, get settings from there. Otherwise, prompt user for new settings.
- if exist cfg.txt (
- echo Automatically detected the following server settings:
- echo:
- type cfg.txt
- echo:
- echo Are these settings correct or would you like to change them?
- echo Y for correct, N to change
- :invalidAnswer2
- set /P c=Answer:
- if /I "!c!" EQU "Y" goto settingsCorrect
- if /I "!c!" EQU "N" goto settingsNotCorrect
- goto invalidAnswer2
- ) else (
- goto cfgNotFound
- )
- :cfgNotFound
- echo cfg.txt not detected. Press any key to re-enter your settings
- pause
- :settingsNotCorrect
- cls
- ::Prompt user for settings and stuff
- del cfg.txt
- echo Please enter the following settings:
- echo:
- echo Server install directory? END MUST HAVE A BACKSLASH ^( \ ^)
- SET /p downloadDir=Install Directory: %"="%
- echo !downloadDir! >cfg.txt
- echo:
- echo The name of your server?
- SET /p serverName=Server Name: %"="%
- echo !serverName! >>cfg.txt
- echo:
- echo The default map?
- SET /p defaultMap=Default Map: %"="%
- echo !defaultMap! >>cfg.txt
- echo:
- echo Max amount of players?
- SET /p maxPlayers=Max Players: %"="%
- echo !maxPlayers! >>cfg.txt
- echo:
- echo Remote console password?
- SET /p rconPassword=RCON Password: %"="%
- echo !rconPassword! >>cfg.txt
- echo:
- echo Workshop collection ID? If you aren't sure, leave this blank
- SET /p collectionID=Workshop Collection ID: %"="%
- echo !collectionID! >>cfg.txt
- echo:
- echo Workshop auth key? If you don't have a collection for your server,
- echo leave this blank
- SET /p authKey=Workshop Authentication Key: %"="%
- echo !authKey! >>cfg.txt
- ::If the settings are correct, continue with generating the startup script
- :settingsCorrect
- :writeGuardian
- cls
- echo Press any key to generate the server launcher/watch-dog script
- echo which will start your server, and restart it if it ever crashes
- pause
- echo Creating instance of SRCDS Guardian...
- echo:
- if not exist "Launch GMod Server - SRCDS Guardian 3.bat" (
- 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 !defaultMap! +maxplayers !maxPlayers! +rcon_password !rconPassword! +host_workshop_collection !collectionID! -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:
- echo Finished^^! Press any key to return to the main menu
- echo:
- pause
- goto mainMenu
Add Comment
Please, Sign In to add comment