Advertisement
HasterPaster

Mirror mods from game to server

Jul 17th, 2021
1,269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.28 KB | None | 0 0
  1. @echo off
  2.  
  3. rem Description: This script makes sure the mod files on the server are identical to the corresponding files in the games mod dir (which are automatically updated and therefor always the current version).
  4. rem Version: 1.3
  5. rem Date: 2020-04-12
  6.  
  7. cls
  8. chcp 65001 >nul 2>&1
  9.  
  10. setlocal
  11.  
  12. rem Path to where the servers mods are installed. Don't put a backslash at the end.
  13. set serverModsPath=D:\Spel\steamapps\common\DayZServer
  14.  
  15. rem Path to where the servers keys are installed. Don't put a backslash at the end.
  16. set serverKeysPath=D:\Spel\steamapps\common\DayZServer\keys
  17.  
  18. rem Path to where the games mods are installed. Don't put a backslash at the end.
  19. set gameModsPath=D:\Spel\steamapps\common\DayZ\!Workshop
  20.  
  21. echo.
  22. echo Detta skript kontrollerar så alla moddar installerade på servern är identiska med motsvarande moddar som är installerad i spelet.
  23. echo.
  24. echo Serverns modkatalog: %serverModsPath%
  25. echo Serverns nyckelkatalog: %serverKeysPath%
  26. echo Spelets modkatalog: %gameModsPath%
  27. echo.
  28.  
  29. rem Check to make sure the last character in the paths isn't "\".
  30. if %serverModsPath:~-1% ==\ (
  31.     echo Ett fel uppstod: Det sista tecknet i sökvägen till serverns modkatalog får inte vara "\". Skriptet har avbrutits.
  32.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  33.     pause >nul
  34.     exit /b 0
  35. )  
  36. if %serverKeysPath:~-1% ==\ (
  37.     echo Ett fel uppstod: Det sista tecknet i sökvägen till serverns nyckelkatalog får inte vara "\". Skriptet har avbrutits.
  38.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  39.     pause >nul
  40.     exit /b 0
  41. )  
  42. if %gameModsPath:~-1% ==\ (
  43.     echo Ett fel uppstod: Det sista tecknet i sökvägen till spelets modkatalog får inte vara "\". Skriptet har avbrutits.
  44.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  45.     pause >nul
  46.     exit /b 0
  47. )
  48.  
  49. rem Check to make sure the paths exist.
  50. if not exist "%serverModsPath%" (
  51.     echo Ett fel uppstod: Serverns modkatalog "%serverModsPath%" kunde inte hittas. Skriptet har avbrutits.
  52.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  53.     pause >nul
  54.     exit /b 0
  55. )
  56. if not exist "%serverKeysPath%" (
  57.     echo Ett fel uppstod: Serverns nyckelkatalog "%serverKeysPath%" kunde inte hittas. Skriptet har avbrutits.
  58.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  59.     pause >nul
  60.     exit /b 0
  61. )
  62. if not exist "%gameModsPath%" (
  63.     echo Ett fel uppstod: Spelets modkatalog "%gameModsPath%" kunde inte hittas. Skriptet har avbrutits.
  64.     echo Tryck ENTER för att avsluta skriptet och kontrollera inställningarna.
  65.     pause >nul
  66.     exit /b 0
  67. )
  68.  
  69. echo Tryck ENTER för att påbörja kontrollen.
  70. pause >nul
  71. echo.
  72. echo.
  73.  
  74. set /a modsMirroredNumber=0
  75. set /a keyFilesCopied=0
  76.  
  77. rem Loop through all the folders starting with an @ found in the servers mod path and mirror them if needed as well as copy their keys to the servers key folder.
  78. for /D %%G in ("%serverModsPath%\@*") do (
  79.     set modName=%%~nxG
  80.     echo Modnamn: %%~nxG
  81.     call :MirrorMod
  82.     call :CopyKey
  83.     echo.
  84. )
  85.  
  86. rem Present a summery over what was done.
  87. echo Summering
  88. echo ---------------------------------------
  89. echo Antal moddar som uppdaterades: %modsMirroredNumber%
  90. echo.
  91. if not %modsMirroredNumber%==0 (
  92.     echo Följande moddar uppdaterades:
  93.     for /F "tokens=2 delims==" %%s in ('set modsMirroredNames[') do echo     %%s
  94.     echo.
  95. )
  96.  
  97. echo Antal nycklar som kopierades in till serverns keys-katalog: %keyFilesCopied%
  98. echo Obs: Nycklarna kopieras in varje gång skriptet körs vare sig det behövs eller ej.
  99. echo.
  100. echo Skriptet är färdigt.
  101. echo Tryck ENTER för att stänga ned fönstret.
  102. pause >nul
  103. endlocal
  104. exit /b %errorlevel%
  105.  
  106. :MirrorMod
  107. rem Make sure the first character of the mod directory is "@". This is just a precaution in case anything else slips through the name mask in the directory listing function above, for whatever reason.
  108. set modNameFirstCharacter=%modName:~0,1%
  109. if not %modNameFirstCharacter%==@ (
  110.     echo Status: Moddkatalogens namn börjar inte med ett "@". Kontroll av denna mod avbryts.
  111.     exit /b 0
  112. )
  113.  
  114. rem Make sure the mod on the server actually exists in the games mod directory as well.
  115. if not exist "%gameModsPath%\%modName%" (
  116.     echo Status: Kunde inte hitta moddens motsvarande katalog "%gameModsPath%\%modName%" i spelkatalogen. Kontroll av denna mod avbryts.
  117.     exit /b 0
  118. )
  119.  
  120. rem Mirror the games mod to the servers mod.
  121. robocopy "%gameModsPath%\%modName%" "%serverModsPath%\%modName%" /mir /nfl /ndl /njh /njs /nc /ns /np >nul
  122. if %errorlevel%==1 (
  123.     set /a modsMirroredNumber=%modsMirroredNumber%+1
  124.     call :AddModToMirroredList %modsMirroredNumber%
  125.     echo Status: Ej identisk. Serverns mod uppdaterades.
  126.     exit /b 0
  127. )
  128. echo Status: Identisk
  129. exit /b 0
  130.  
  131. :AddModToMirroredList
  132. set /a currentIndex=%1
  133. set modsMirroredNames[%currentIndex%]=%modName%
  134. exit /b 0
  135.  
  136. :CopyKey
  137. rem The quotation marks on the destination path needs to be escaped using \ in order for forfiles to work, since they are quotes within a quote.
  138. forfiles /p "%serverModsPath%\%modName%" /s /m *.bikey /c "cmd /c xcopy /y @path \"%serverKeysPath%\"" >nul 2>&1
  139. if %errorlevel%==0 (
  140.     set /a keyFilesCopied=%keyFilesCopied%+1
  141.     echo Nyckelfil: Kopierades
  142.     exit /b 0
  143. )
  144. if %errorlevel%==1 (
  145.     echo Nyckelfil: Ingen nyckel hittades till denna mod.
  146.     exit /b 0
  147. )
  148. exit /b 0
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement