Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -26,8 +26,9 @@ delete process.env.all_proxy;
|
|
| 26 |
|
| 27 |
// Network hijack can break Discord auth on some environments.
|
| 28 |
// Keep it opt-in via env when explicitly needed.
|
| 29 |
-
const
|
| 30 |
-
|
|
|
|
| 31 |
networkFix.applyAdvancedFixes();
|
| 32 |
} else {
|
| 33 |
// Safe network tuning for HF/containers without hostname rewriting.
|
|
@@ -1379,7 +1380,7 @@ setInterval(async () => {
|
|
| 1379 |
if (client.ws.status !== 0) {
|
| 1380 |
console.log("[!] Gateway issues detected. Status:", client.ws.status);
|
| 1381 |
console.log("[*] Performing emergency reconnect...");
|
| 1382 |
-
if (
|
| 1383 |
networkFix.rotateEndpoint();
|
| 1384 |
}
|
| 1385 |
|
|
@@ -1465,8 +1466,21 @@ async function initialize() {
|
|
| 1465 |
} catch (err) {
|
| 1466 |
console.error(`[ERROR] Authentication Failed: ${err.message || 'No Description'}`);
|
| 1467 |
|
| 1468 |
-
|
| 1469 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1470 |
networkFix.rotateEndpoint();
|
| 1471 |
}
|
| 1472 |
|
|
|
|
| 26 |
|
| 27 |
// Network hijack can break Discord auth on some environments.
|
| 28 |
// Keep it opt-in via env when explicitly needed.
|
| 29 |
+
const FORCE_NETWORK_HIJACK = process.env.ENABLE_NETWORK_HIJACK === 'true';
|
| 30 |
+
let dynamicNetworkHijackEnabled = FORCE_NETWORK_HIJACK;
|
| 31 |
+
if (dynamicNetworkHijackEnabled) {
|
| 32 |
networkFix.applyAdvancedFixes();
|
| 33 |
} else {
|
| 34 |
// Safe network tuning for HF/containers without hostname rewriting.
|
|
|
|
| 1380 |
if (client.ws.status !== 0) {
|
| 1381 |
console.log("[!] Gateway issues detected. Status:", client.ws.status);
|
| 1382 |
console.log("[*] Performing emergency reconnect...");
|
| 1383 |
+
if (dynamicNetworkHijackEnabled) {
|
| 1384 |
networkFix.rotateEndpoint();
|
| 1385 |
}
|
| 1386 |
|
|
|
|
| 1466 |
} catch (err) {
|
| 1467 |
console.error(`[ERROR] Authentication Failed: ${err.message || 'No Description'}`);
|
| 1468 |
|
| 1469 |
+
const errMsg = String(err?.message || '').toLowerCase();
|
| 1470 |
+
const isTlsHandshakeFailure =
|
| 1471 |
+
errMsg.includes('before secure tls connection was established') ||
|
| 1472 |
+
errMsg.includes('client network socket disconnected') ||
|
| 1473 |
+
errMsg.includes('connect timeout');
|
| 1474 |
+
|
| 1475 |
+
// Auto-enable alternate official routes after repeated TLS failures.
|
| 1476 |
+
if (!dynamicNetworkHijackEnabled && isTlsHandshakeFailure && retryCount >= 2) {
|
| 1477 |
+
dynamicNetworkHijackEnabled = true;
|
| 1478 |
+
console.log('[NETWORK] Enabling alternate Discord routes (discord.com/canary/ptb)...');
|
| 1479 |
+
networkFix.applyAdvancedFixes();
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
// Retry login; rotate route only when alternate mode is enabled.
|
| 1483 |
+
if (dynamicNetworkHijackEnabled) {
|
| 1484 |
networkFix.rotateEndpoint();
|
| 1485 |
}
|
| 1486 |
|