Advertisement
CheezusCrust

Untitled

May 10th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 11.13 KB | None | 0 0
  1. ::Want to understand how this code works? www.ss64.com/nt has a great explanation for most of the commands in here
  2.  
  3. ::Keep the window clean and easy to read
  4. @echo off
  5.  
  6. ::Set the title of the window
  7. title Garry's Mod Server Installer and Updater v0.1
  8.  
  9. ::I don't know what this means but it fixes random things that weren't working related to the if statements
  10. setlocal enabledelayedexpansion
  11.  
  12. ::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)
  13. ::If it does exist, read it and set variable downloadDir to the contents of the file (which would be the install directory)
  14.  
  15. echo ::=============================================::
  16. echo Welcome to Cheezus' Server Creator and Updater Script
  17. echo If this is your first time using this, follow all of the instructions carefully
  18. echo ::=============================================::
  19.  
  20. if not exist cfg.txt (
  21.     echo:
  22.     echo Set the install location. Example - C:\My GMod Server\
  23.     echo YOU MUST INCLUDE A FINAL BACKSLASH AT THE END\
  24.     SET /p downloadDir=Install Directory: %"="%
  25.     echo !downloadDir! >cfg.txt
  26. ) else (
  27.     SET /p downloadDir=<cfg.txt
  28.     echo Previous install directory automatically detected: !downloadDir!
  29.     echo:
  30. )
  31.  
  32. ::If the download directory folder does not exist, create it
  33. if not exist "%downloadDir%" (
  34.     echo:
  35.     echo Install location does not exist, creating folder...
  36.     echo:
  37.     mkdir "%downloadDir%"
  38. )
  39.  
  40. ::Set the command prompt to run directly from the download directory
  41. cd "%downloadDir%"
  42.  
  43. ::If steamcmd.exe already exists, skip downloading and run it. If not, assume it isn't installed and download it
  44. if exist steamcmd.exe (
  45.     echo:
  46.     echo SteamCMD already installed, starting...
  47.     echo:
  48.     goto run
  49. )
  50.  
  51. ::If steamcmd.exe does not exist, use Windows PowerShell to pull it from Steam's website
  52. echo Downloading SteamCMD...
  53.     powershell -Command "(New-Object Net.WebClient).DownloadFile('https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip', 'steamcmd.zip')"
  54.  
  55. ::Random script I found online for extracting files.
  56. ::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)
  57. echo Extracting...
  58.  
  59.     echo ZipFile="steamcmd.zip" > zip.vbs
  60.     echo ExtractTo="./" >> zip.vbs
  61.      
  62.     echo Set fso = CreateObject("Scripting.FileSystemObject") >> zip.vbs
  63.     echo sourceFile = fso.GetAbsolutePathName(ZipFile) >> zip.vbs
  64.     echo destFolder = fso.GetAbsolutePathName(ExtractTo) >> zip.vbs
  65.  
  66.     echo Set objShell = CreateObject("Shell.Application") >> zip.vbs
  67.     echo Set FilesInZip=objShell.NameSpace(sourceFile).Items() >> zip.vbs
  68.     echo objShell.NameSpace(destFolder).copyHere FilesInZip, 16 >> zip.vbs
  69.  
  70.     echo Set fso = Nothing >> zip.vbs
  71.     echo Set objShell = Nothing >> zip.vbs
  72.     echo Set FilesInZip = Nothing >> zip.vbs
  73.  
  74. CScript zip.vbs
  75.  
  76. ::Don't want to keep the downloaded zip and the temporary vbs script lying around do we?
  77. echo Finished extracting, cleaning up...
  78. del steamcmd.zip
  79. del zip.vbs
  80.  
  81. :run
  82. goto skip
  83. ::Launch steamcmd.exe, log in to the Valve servers and begin downloading Garry's Mod Dedicated Server
  84. ::Afterwards, it validates the files and then closes itself
  85. steamcmd.exe +login anonymous +app_update 4020 validate +quit
  86. :skip
  87. ::After the server downloads, create an instance of SRCDS Guardian to launch it
  88. ::Each line of code here is writing itself to a new .bat file which will be used to start the server
  89. echo Garry's Mod Dedicated Server successfully downloaded and validated.
  90. echo:
  91.  
  92. :choice1
  93. echo If you were just updating, type N. If this is your first time, type Y.
  94. set /P c=Was this your first time running this script?[Y/N]
  95. if /I "%c%" EQU "Y" goto :first
  96. if /I "%c%" EQU "N" goto :notfirst
  97. goto :choice1
  98.  
  99. :first
  100. echo Let's set up some things like...
  101. echo:
  102. echo The name of your server?
  103. SET /p servername=Server Name: %"="%
  104. echo:
  105. echo The default map?
  106. SET /p map=Default Map: %"="%
  107. echo:
  108. echo Max amount of players?
  109. SET /p maxplayers=Max Players: %"="%
  110. echo:
  111. echo Remote console password?
  112. SET /p rconpassword=RCON Password: %"="%
  113. echo:
  114. echo Workshop collection ID? If you aren't sure, leave this blank
  115. SET /p hostworkshopcollectionid=Workshop Collection ID: %"="%
  116. echo:
  117. echo Workshop auth key? If you don't have a collection for your server, leave this blank
  118. SET /p authkey=Workshop Authentication Key: %"="%
  119. echo:
  120. del %downloadDir%\steamapps\common\GarrysModDS\garrysmod\cfg\server.cfg
  121. echo hostname "%servername%" >%downloadDir%\steamapps\common\GarrysModDS\garrysmod\cfg\server.cfg
  122. :choice2
  123. echo If you don't already have a shortcut for your server, type Y
  124. set /P c=Do you want to create an instance of SRCDS Guardian?[Y/N]?
  125. if /I "%c%" EQU "Y" goto :yesguardian
  126. if /I "%c%" EQU "N" goto :noguardian
  127. goto :choice2
  128.  
  129. :yesguardian
  130. echo Creating instance of SRCDS Guardian...
  131. echo:
  132. if not exist "%~dp0\Launch GMod Server - SRCDS Guardian 3.bat" (
  133.     cd !%~dp0!
  134.  
  135.     echo ::File generated by Cheezus' Server Installer:: > "Launch Server - SRCDS Guardian 3.bat"
  136.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  137.     echo ::  SRCDS Guardian 3.0   :: >> "Launch Server - SRCDS Guardian 3.bat"
  138.     echo ::         Mooga         :: >> "Launch Server - SRCDS Guardian 3.bat"
  139.     echo ::       SRCDS.com       :: >> "Launch Server - SRCDS Guardian 3.bat"
  140.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  141.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  142.     echo ::=========================================================:: >> "Launch Server - SRCDS Guardian 3.bat"
  143.     echo :: Thanks To Black-Sky ^& Drocona for making SRCDS Guardian :: >> "Launch Server - SRCDS Guardian 3.bat"
  144.     echo :: This script is open source.  Feel free to edit at will. :: >> "Launch Server - SRCDS Guardian 3.bat"
  145.     echo ::                                                         :: >> "Launch Server - SRCDS Guardian 3.bat"
  146.     echo :: This script was writen for the use of the srcds.com     :: >> "Launch Server - SRCDS Guardian 3.bat"
  147.     echo :: online community.  If you are interested in running a   :: >> "Launch Server - SRCDS Guardian 3.bat"
  148.     echo :: Source Dedicated Server or need help, drop by our       :: >> "Launch Server - SRCDS Guardian 3.bat"
  149.     echo :: forums at... http://forums.srcds.com                    :: >> "Launch Server - SRCDS Guardian 3.bat"
  150.     echo ::=========================================================:: >> "Launch Server - SRCDS Guardian 3.bat"
  151.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  152.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  153.     echo ::  SET YOUR VARIABLES!  : class="re0">: >> "Launch Server - SRCDS Guardian 3.bat"
  154.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  155.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  156.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  157.     echo ::  Window and Log name  :: >> "Launch Server - SRCDS Guardian 3.bat"
  158.     echo ::  Replace "My Server"  :: >> "Launch Server - SRCDS Guardian 3.bat"
  159.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  160.     echo set servername=%servername% >> "Launch Server - SRCDS Guardian 3.bat"
  161.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  162.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  163.     echo ::   Your start command  :: >> "Launch Server - SRCDS Guardian 3.bat"
  164.     echo ::    Replace after =    :: >> "Launch Server - SRCDS Guardian 3.bat"
  165.     echo ::=======================::
  166.     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"
  167.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  168.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  169.     echo ::   End of variables    :: >> "Launch Server - SRCDS Guardian 3.bat"
  170.     echo ::=======================:: >> "Launch Server - SRCDS Guardian 3.bat"
  171.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  172.     echo :: This will keep the window clean and easy to read >> "Launch Server - SRCDS Guardian 3.bat"
  173.     echo @echo off >> "Launch Server - SRCDS Guardian 3.bat"
  174.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  175.     echo :: Sets the title of the window >> "Launch Server - SRCDS Guardian 3.bat"
  176.     echo title SRCDS Guardian 3.0   %%servername%% >> "Launch Server - SRCDS Guardian 3.bat"
  177.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  178.     echo :: Clears the window incase there is anything there >> "Launch Server - SRCDS Guardian 3.bat"
  179.     echo cls >> "Launch Server - SRCDS Guardian 3.bat"
  180.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  181.     echo :: Prints to the window what we are doing >> "Launch Server - SRCDS Guardian 3.bat"
  182.     echo echo SRCDS Guardian 3.0 has been started! >> "Launch Server - SRCDS Guardian 3.bat"
  183.     echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
  184.     echo echo ************************************************************************* >> "Launch Server - SRCDS Guardian 3.bat"
  185.     echo echo To close the server, close this window and type exit in the server window >> "Launch Server - SRCDS Guardian 3.bat"
  186.     echo echo ************************************************************************* >> "Launch Server - SRCDS Guardian 3.bat"
  187.     echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
  188.     echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
  189.     echo echo %%servername%% is now starting... >> "Launch Server - SRCDS Guardian 3.bat"
  190.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  191.     echo :: This is a return point in case the server crashes or is closed >> "Launch Server - SRCDS Guardian 3.bat"
  192.     echo :restart >> "Launch Server - SRCDS Guardian 3.bat"
  193.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  194.     echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
  195.     echo echo ^(%%date%%^)^(%%time%%^) %%servername%% is now ONLINE >> "Launch Server - SRCDS Guardian 3.bat"
  196.     echo echo Watching %%servername%% for crashes... >> "Launch Server - SRCDS Guardian 3.bat"
  197.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  198.     echo ::Start the actual server >> "Launch Server - SRCDS Guardian 3.bat"
  199.     echo start /wait %%runcmd%% >> "Launch Server - SRCDS Guardian 3.bat"
  200.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  201.     echo echo. >> "Launch Server - SRCDS Guardian 3.bat"
  202.     echo echo ^(%%date%%^)^(%%time%%^) Crash or Close detected! >> "Launch Server - SRCDS Guardian 3.bat"
  203.     echo echo %%servername%% is now restarting... >> "Launch Server - SRCDS Guardian 3.bat"
  204.     echo: >> "Launch Server - SRCDS Guardian 3.bat"
  205.     echo ::Server crashed or closed, so we point it to the return point to start the server again >> "Launch Server - SRCDS Guardian 3.bat"
  206.     echo goto restart >> "Launch Server - SRCDS Guardian 3.bat"
  207. )
  208. echo:
  209. :noguardian
  210. :notfirst
  211. echo Setup finished.
  212. echo If you delete the cfg.txt this script created, you'll have to type the
  213. echo directory again next time you run it.
  214. echo ::==============================::
  215. echo To launch your server, click on the file that was created when this script ran - 'Launch Server - SRCDS Guardian 3.bat'
  216. echo ::==============================::
  217. echo Whenever you want to update your server, run this script and it will automatically update.
  218. :end
  219. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement