feat: modalità amichevole e fix URL remoti in dev (WSL2)
- Aggiunge modalità "Amichevole" in config: i set si vincono normalmente ma la partita non termina mai automaticamente (checkVittoriaPartita restituisce false), consentendo di giocare set illimitati - Dev server ora espone su tutte le interfacce (vite --host) - printServerInfo mostra Display + Controller per dispositivi remoti - Su WSL2 getNetworkIPs() interroga PowerShell per ottenere gli IP Windows reali invece degli IP interni WSL (172.x)
This commit is contained in:
+29
-14
@@ -1,20 +1,34 @@
|
||||
import { networkInterfaces } from 'os'
|
||||
import { readFileSync, existsSync } from 'fs'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
function isWSL() {
|
||||
try {
|
||||
return existsSync('/proc/sys/kernel/osrelease') &&
|
||||
readFileSync('/proc/sys/kernel/osrelease', 'utf8').toLowerCase().includes('microsoft')
|
||||
} catch { return false }
|
||||
}
|
||||
|
||||
export function getNetworkIPs() {
|
||||
const nets = networkInterfaces()
|
||||
const networkIPs = []
|
||||
|
||||
for (const name of Object.keys(nets)) {
|
||||
for (const net of nets[name]) {
|
||||
if (net.family === 'IPv4' &&
|
||||
!net.internal &&
|
||||
!net.address.startsWith('172.17.') &&
|
||||
!net.address.startsWith('172.18.')) {
|
||||
networkIPs.push(net.address)
|
||||
}
|
||||
}
|
||||
if (isWSL()) {
|
||||
try {
|
||||
const out = execSync(
|
||||
'powershell.exe -NoProfile -Command "Get-NetIPAddress -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress"',
|
||||
{ timeout: 3000 }
|
||||
)
|
||||
return out.toString().trim().split('\n')
|
||||
.map(s => s.trim())
|
||||
.filter(ip => ip && !ip.startsWith('127.') && !ip.startsWith('169.254.') && !ip.startsWith('172.'))
|
||||
} catch { return [] }
|
||||
}
|
||||
|
||||
const nets = networkInterfaces()
|
||||
const networkIPs = []
|
||||
for (const name of Object.keys(nets)) {
|
||||
for (const net of nets[name]) {
|
||||
if (net.family === 'IPv4' && !net.internal) networkIPs.push(net.address)
|
||||
}
|
||||
}
|
||||
return networkIPs
|
||||
}
|
||||
|
||||
@@ -26,9 +40,10 @@ export function printServerInfo(port = 3000) {
|
||||
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
||||
|
||||
if (networkIPs.length > 0) {
|
||||
console.log(`\n Controller da dispositivi remoti:`)
|
||||
console.log(`\n Da dispositivi remoti:`)
|
||||
networkIPs.forEach(ip => {
|
||||
console.log(` http://${ip}:${port}/controller`)
|
||||
console.log(` Display: http://${ip}:${port}/display`)
|
||||
console.log(` Controller: http://${ip}:${port}/controller`)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user