# "How will your friends join?" - the last step of setup.cmd, and option 10 in the cs.cmd menu. # Each choice either sets things up or walks you through it. param([Parameter(Mandatory = $true)][string]$Root) . (Join-Path $PSScriptRoot 'common.ps1') $settingsFile = Join-Path $Root 'settings.txt' $s = Read-Settings $settingsFile $port = [int]$s.CS_PORT function Pause-Enter($text = 'Press Enter when done') { [void](Read-Host " $text") } function Ensure-Firewall { if (Test-FirewallRule $Root) { Write-Host ' Windows Firewall: the server is allowed in.'; return } Write-Host ' Windows Firewall blocks players from other PCs until you allow the server.' Write-Host ' Windows will now ask for admin permission (one time).' if (Add-FirewallRule $Root) { Write-Host ' Firewall: allowed.' -ForegroundColor Green } else { Warn ' Firewall not changed. Only players on this PC can join until you allow it:' Warn ' run cs.cmd -> 10 (how friends join) and say Yes to the admin prompt.' } } function Show-Connect($addr) { Write-Host " connect $addr" -ForegroundColor Green } function Join-Lan { Ensure-Firewall $ips = @(Get-LanIPv4) Write-Host '' Write-Host ' Players in your home open Counter-Strike, press ~ for the console and type:' if ($ips.Count -eq 0) { Show-Connect ":$port"; Write-Host ' (no network address found: are you connected to your router?)' } foreach ($ip in $ips) { Show-Connect "${ip}:$port" } Write-Host ' On this same PC:'; Show-Connect "127.0.0.1:$port" } function Join-Playit { Write-Host '' Write-Host ' playit.gg gives your server a public address without touching your router. It is free.' Write-Host ' 1. Your browser opens playit.gg/download: download and install the Windows app.' Write-Host ' 2. Start playit. It opens a page to sign up (or log in) and link this PC: follow it.' Write-Host ' 3. On playit.gg, add a tunnel:' Write-Host ' type: UDP' -ForegroundColor Green Write-Host " local address: 127.0.0.1 local port: $port" -ForegroundColor Green Write-Host ' 4. playit shows the address of the tunnel, something like name.ply.gg:12345' Write-Host ' Keep the playit app running while you play.' Pause-Enter 'Press Enter to open playit.gg' Start-Process 'https://playit.gg/download' $addr = (Read-Host ' Paste the tunnel address here (or Enter to do it later)').Trim() if ($addr) { $addr = $addr -replace '^(udp|https?)://', '' -replace '/.*$', '' Write-Setting $settingsFile 'CS_PUBLIC_ADDR' $addr Write-Host ' Saved. Your friends open Counter-Strike, press ~ and type:' Show-Connect $addr $hp = $addr -split ':' if ($hp.Count -eq 2 -and (Get-A2SInfo $hp[0] ([int]$hp[1]) 4000)) { Write-Host ' Checked: the server answers through the tunnel.' -ForegroundColor Green } else { Write-Host " (could not reach the server through the tunnel yet: check the tunnel is UDP and points to 127.0.0.1:$port)" } } } function Join-PortForward { Ensure-Firewall $gw = (Get-NetRoute -DestinationPrefix '0.0.0.0/0' -ErrorAction SilentlyContinue | Sort-Object RouteMetric | Select-Object -First 1).NextHop $lan = @(Get-LanIPv4) $pub = $null try { $pub = (Invoke-WebRequest -UseBasicParsing -Uri 'https://api.ipify.org' -TimeoutSec 10).Content.Trim() } catch { } Write-Host '' Write-Host ' Your router has to send game traffic to this PC:' Write-Host " 1. Open your router's page in a browser: http://$gw (the login is often on a sticker on the router)" Write-Host ' 2. Find "Port forwarding" (sometimes under NAT, Virtual server or Gaming) and add:' Write-Host " protocol: UDP external port: $port internal port: $port" -ForegroundColor Green Write-Host " device / internal IP: $(if ($lan.Count) { $lan[0] } else { "this PC's IP" })" -ForegroundColor Green Write-Host ' 3. Save. Some routers need a restart.' Write-Host ' Tip: in your router, give this PC a fixed (reserved) IP, or the rule breaks when the IP changes.' Write-Host '' if ($pub) { Write-Host ' Your friends then type in the Counter-Strike console:'; Show-Connect "${pub}:$port"; Write-Setting $settingsFile 'CS_PUBLIC_ADDR' "${pub}:$port" } else { Write-Host " Your friends then use connect :$port (look it up on whatismyip.com)" } Write-Host ' You cannot test this from your own PC (most routers do not loop back): ask a friend to connect.' Write-Host ' If it never works, your internet may be behind CGNAT (common on mobile and some fiber):' Write-Host ' use playit.gg instead (option 2).' } function Join-Vpn { $v = @(Get-VpnIPv4) # @(): one address would otherwise come back as a single object Write-Host '' Write-Host ' With a VPN like Tailscale or ZeroTier, everyone installs the same app and joins your network.' Write-Host ' Good for a fixed group of friends; no router setup.' if ($v.Count) { Ensure-Firewall Write-Host ' Found on this PC:' foreach ($x in $v) { Write-Host " $($x.Name):"; Show-Connect "$($x.IP):$port" } } else { Write-Host ' Not installed yet. Get one (free for small groups):' Write-Host ' Tailscale: https://tailscale.com/download' Write-Host ' ZeroTier: https://www.zerotier.com/download/' Write-Host ' Invite your friends to your network, then run this step again (cs.cmd -> 10) to see your address.' } } Say 'How will your friends join?' Write-Host ' 1) same house / LAN' Write-Host ' 2) over the internet with playit.gg (easiest, no router setup)' Write-Host ' 3) over the internet with port forwarding on your router' Write-Host ' 4) VPN (Tailscale / ZeroTier)' Write-Host ' 0) skip for now (cs.cmd -> 10 brings you back here)' $c = (Read-Host ' >').Trim() switch ($c) { '1' { Join-Lan } '2' { Join-Playit } '3' { Join-PortForward } '4' { Join-Vpn } default { Write-Host ' skipped: double-click cs.cmd and pick 10 any time.' } }