Closed freghar closed 3 years ago
Sneaky!
Can't say I write much Powershell, but here's a beta version!
Missing features:
# --- User Config ---
# Which mod repos do you want to run? Pick between: main, main+dev, main+campaign or main+dev+campaign
$modRepo = "main"
# WE DEAL WITH ABSOLUTES!
$configLocation = "C:\Users\did\Documents\GIT-CNTO\testscript"
# Main cnto repo directory path
$mainRepoPath = "X:\Games\steamapps\common\Arma 3\Main-Repo"
# Campaign cnto repo path (optional)
$campaignRepoPath = "X:\Games\steamapps\common\Arma 3\Campaign-Repo"
# Dev cnto repo path (optional)
$devRepoPath = "X:\Games\steamapps\common\Arma 3\Dev-Repo"
# Path to Arma3
$armaPath = "X:\Games\steamapps\common\Arma 3"
# Start HC: yes/no
$startHC = "yes"
# Use latest CBA settings: yes/no
$useLatestCBA = "yes"
# Static Config
Set-Location $configLocation
$currentLocation = Get-Location
$ServerScriptUrl = "https://github.com/CntoDev/misc-scripts/archive/refs/heads/master.zip"
$cbaSettingsURL = "https://raw.githubusercontent.com/CntoDev/cba-settings-lock/master/cba_settings_userconfig/cba_settings.sqf"
$basicCfgURL = "https://raw.githubusercontent.com/freghar/arma3dedicated/master/dedicated-config/basic.cfg"
$commonServerParameters = "-port 2302 -noSplash -noLand -enableHT -hugePages -profiles=$configDir\profiles"
$configDir = "$configLocation\server-setup"
#IfExists
$mainMods = Get-ChildItem $mainRepoPath
$campaignMods = Get-ChildItem $campaignRepoPath
$devMods = Get-ChildItem $devRepoPath
# Functions
function Get-MainMods() {
$modList = $mainMods | Group-Object -Property Directory | ForEach-Object {
@(
$_.Group | Resolve-Path | Convert-Path
)-join','
}
return $modList
}
function Get-CampaignMods() {
$campaignModList = $campaignMods | Group-Object -Property Directory | ForEach-Object {
@(
$_.Group | Resolve-Path | Convert-Path
)-join','
}
return $campaignModList
}
function Get-DevModDiff() {
$devDiff = Compare-Object -ReferenceObject $mainMods -DifferenceObject $devMods -IncludeEqual -ExcludeDifferent -PassThru
$modList = Compare-Object -ReferenceObject $devDiff -DifferenceObject $mainMods -PassThru | Group-Object -Property Directory | ForEach-Object {
@(
$_.Group | Resolve-Path | Convert-Path
)-join','
}
$devModList = $devMods | Group-Object -Property Directory | ForEach-Object {
@(
$_.Group | Resolve-Path | Convert-Path
)-join','
}
return $modList+','+$devModList
}
# Awful switch statement to get correct mods
function Get-ModList($type) {
switch ($type) {
"main" {return Get-MainMods}
"main+dev" {return Get-DevModDiff}
"main+campaign" {return "$(Get-MainMods)+','+$(Get-CampaignMods)"}
"main+dev+campaign" {return "$(Get-DevModDiff)+','+$(Get-CampaignMods)"}
}
}
function Start-Server($type,$getLatestCBA,$useHC) {
# Force overwrite cba_settings.sqf
if ($getLatestCBA -eq "yes") {
Write-Host "Downloading latest CBA Settings from Github"
Invoke-RestMethod -Uri $cbaSettingsURL -OutFile "$armaPath\userconfig\cba_settings.sqf"
}
if ($useHC -eq "yes") {
Write-Host "Starting headless client..."
Start-Process -FilePath "$armapath\arma3server.exe" -ArgumentList "$commonServerParameters -client -connect=127.0.0.1 -password=cnto -mod=`"$(Get-ModList($type))`""
}
Write-Host "Starting the server..."
Start-Process -FilePath "$armapath\arma3server.exe" -ArgumentList "$commonServerParameters -filePatching -name=server -config=$configDir\server.cfg -cfg=$configDir\basic.cfg -mod=`"$(Get-ModList($type))`""
}
# First Setup -
# https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.1
function Initialize-Server {
# Add confirmation dialogue about overwriting
Write-Host "Downloading the latest startup script ZIP from Github"
Invoke-RestMethod -Uri $ServerScriptUrl -OutFile "$configLocation\master.zip"
Write-Host "Extracting it..."
Expand-Archive -Path "$configLocation\master.zip" -DestinationPath $currentLocation -Force
Write-Host "Deleting the ZIP after extraction has been completed"
Copy-Item -Path "$configLocation\misc-scripts-master\server-setup" -Destination "$configLocation" -Force -Recurse
Invoke-RestMethod -Uri $basicCfgURL -OutFile "$configDir\basic.cfg"
Remove-Item -Path "$configLocation\misc-scripts-master" -Force -Recurse
Remove-Item -Path "$configLocation\master.zip" -Force
# Create userconfig folder in arma3 folder, if it doesn't exist:
New-Item -Path "$armaPath" -Name "userconfig" -ItemType "directory" -Force | Out-Null
# Add cba_settings
Invoke-RestMethod -Uri $cbaSettingsURL -OutFile "$armaPath\userconfig\cba_settings.sqf"
}
Initialize-Server
Start-Server -type $modRepo -getLatestCBA $useLatestCBA -useHC $startHC
Development ongoing in https://github.com/CntoDev/arma-startup-scripts
When testing mods or missions, I always start up a local dedicated server, since it's different to a Multiplayer Preview in the editor or even a Hosted MP server. However it would be worth making this easy to use for others.
Create a (windows batch / powershell) script + related directory, both of which would be put inside the Arma 3 install dir:
server.cfg
,basic.cfg
and aprofiles
directory with aserver.Arma3Profile
, kind of like https://github.com/CntoDev/misc-scripts/tree/master/server-setup.-mod=
stringuserconfig
folder, overriding anycba_settings.sqf
present therearma3server.exe
in the background (if possible) with-port=2302
-name=server
-config=%configdir%\server.cfg
(configdir
is "Config directory name" from above)-cfg=%configdir%\basic.cfg
-profiles=%configdir%\profiles
-filePatching
(needed for theuserconfig
thing to work)-noSplash
-noLand
-enableHT
-hugePages
-mod=...
(collected list of mods from above)arma3server.exe
in the background with-client
-connect=127.0.0.1
-port=2302
-password=abcd
(the counterpart of which is inserver.cfg
)-profiles=%configdir%\profiles
-noSplash
-noLand
-enableHT
-hugePages
-mod=...
(collected list of mods from above)The actual
server.cfg
/basic.cfg
/server.Arma3Profile
are easy to make - get them either from https://github.com/freghar/arma3dedicated/tree/master/dedicated-config or https://github.com/CntoDev/misc-scripts/tree/master/server-setup or just poke me.For the record - I don't plan to work on this, but it would be really good if somebody with PowerShell powers could. :)
Thanks!