48 lines
2.5 KiB
PowerShell
48 lines
2.5 KiB
PowerShell
<#
|
|
Dungeon Siege II revival - Windows Firewall rules (run once per PC; asks for administrator rights).
|
|
|
|
firewall-setup.ps1 [-GameDir <folder with DungeonSiege2.exe>] [-Server] [-Remove]
|
|
|
|
-GameDir defaults to the folder this script is in (put it next to DungeonSiege2.exe).
|
|
-Server also open the revival server's ports (only on the PC that runs server/run.py):
|
|
TCP 6667 (chat), 28910 (server list), 29900/29901 (accounts), 29920 (storage);
|
|
UDP 27900 (availability/hosting), 27901 (NAT negotiation), 27910 (relay).
|
|
-Remove delete every rule this script created.
|
|
|
|
The game rule allows DungeonSiege2.exe to accept connections (DirectPlay 2302, query 6500, peer 13139,
|
|
LAN chat 42000+, LAN discovery 41000+). It is program-scoped: nothing else is opened.
|
|
#>
|
|
param([string]$GameDir = $PSScriptRoot, [switch]$Server, [switch]$Remove)
|
|
|
|
$prefix = 'DS2 Revival'
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
if (-not $isAdmin) {
|
|
$args = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', "`"$PSCommandPath`"", '-GameDir', "`"$GameDir`"")
|
|
if ($Server) { $args += '-Server' }
|
|
if ($Remove) { $args += '-Remove' }
|
|
Start-Process powershell -Verb RunAs -ArgumentList $args -Wait
|
|
exit
|
|
}
|
|
|
|
Get-NetFirewallRule -DisplayName "$prefix*" -ErrorAction SilentlyContinue | Remove-NetFirewallRule
|
|
if ($Remove) { Write-Host 'Removed DS2 Revival firewall rules.'; exit }
|
|
|
|
$exe = Join-Path $GameDir 'DungeonSiege2.exe'
|
|
if (-not (Test-Path $exe)) { Write-Error "DungeonSiege2.exe not found in $GameDir"; exit 1 }
|
|
New-NetFirewallRule -DisplayName "$prefix - Dungeon Siege II" -Direction Inbound -Action Allow -Program $exe `
|
|
-Profile Any | Out-Null
|
|
$dpnsvr = Join-Path $env:WINDIR 'SysWOW64\dpnsvr.exe'
|
|
if (Test-Path $dpnsvr) {
|
|
New-NetFirewallRule -DisplayName "$prefix - DirectPlay8 Server" -Direction Inbound -Action Allow -Program $dpnsvr `
|
|
-Profile Any | Out-Null
|
|
}
|
|
if ($Server) {
|
|
New-NetFirewallRule -DisplayName "$prefix - server TCP" -Direction Inbound -Action Allow -Protocol TCP `
|
|
-LocalPort 6667, 28910, 29900, 29901, 29920 -Profile Any | Out-Null
|
|
New-NetFirewallRule -DisplayName "$prefix - server UDP" -Direction Inbound -Action Allow -Protocol UDP `
|
|
-LocalPort 27900, 27901, 27910 -Profile Any | Out-Null
|
|
}
|
|
Get-NetFirewallRule -DisplayName "$prefix*" | Format-Table DisplayName, Enabled, Direction, Action -AutoSize
|
|
Write-Host 'Done.'
|
|
Start-Sleep 3
|