Brozy123 commited on
Commit
84e7691
·
verified ·
1 Parent(s): 93a5458

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +16 -7
index.js CHANGED
@@ -12,8 +12,9 @@ const { createProfileAttachment } = require('./profileRenderer');
12
 
13
  // Network hijack can break Discord auth on some environments.
14
  // Keep it opt-in via env when explicitly needed.
15
- const USE_NETWORK_HIJACK = process.env.ENABLE_NETWORK_HIJACK === 'true';
16
- if (USE_NETWORK_HIJACK) {
 
17
  networkFix.applyAdvancedFixes();
18
  } else {
19
  // Safe network tuning for HF/containers without hostname rewriting.
@@ -1365,7 +1366,7 @@ setInterval(async () => {
1365
  if (client.ws.status !== 0) {
1366
  console.log("[!] Gateway issues detected. Status:", client.ws.status);
1367
  console.log("[*] Performing emergency reconnect...");
1368
- if (USE_NETWORK_HIJACK) {
1369
  networkFix.rotateEndpoint();
1370
  }
1371
 
@@ -1438,13 +1439,21 @@ async function initialize() {
1438
  }
1439
 
1440
  try {
1441
- console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1}) on ${networkFix.getTargetDomain()}...`);
1442
  await client.login(TOKEN);
1443
  } catch (err) {
1444
- console.error(`[ERROR] Authentication Failed: ${err.message}`);
 
 
 
 
 
 
 
 
1445
 
1446
- // Retry login; only rotate custom endpoint if that mode is enabled
1447
- if (USE_NETWORK_HIJACK) {
1448
  networkFix.rotateEndpoint();
1449
  }
1450
 
 
12
 
13
  // Network hijack can break Discord auth on some environments.
14
  // Keep it opt-in via env when explicitly needed.
15
+ const FORCE_NETWORK_HIJACK = process.env.ENABLE_NETWORK_HIJACK === 'true';
16
+ let dynamicNetworkHijackEnabled = FORCE_NETWORK_HIJACK;
17
+ if (dynamicNetworkHijackEnabled) {
18
  networkFix.applyAdvancedFixes();
19
  } else {
20
  // Safe network tuning for HF/containers without hostname rewriting.
 
1366
  if (client.ws.status !== 0) {
1367
  console.log("[!] Gateway issues detected. Status:", client.ws.status);
1368
  console.log("[*] Performing emergency reconnect...");
1369
+ if (dynamicNetworkHijackEnabled) {
1370
  networkFix.rotateEndpoint();
1371
  }
1372
 
 
1439
  }
1440
 
1441
  try {
1442
+ console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1})...`);
1443
  await client.login(TOKEN);
1444
  } catch (err) {
1445
+ console.error(`[ERROR] Authentication Failed: ${err.message || 'No Description'}`);
1446
+
1447
+ // Automatic fallback for HF TLS edge issues:
1448
+ // after a few failed attempts, enable alternate route mode.
1449
+ if (!dynamicNetworkHijackEnabled && retryCount >= 2) {
1450
+ dynamicNetworkHijackEnabled = true;
1451
+ console.log('[NETWORK] Enabling alternate route mode after repeated TLS/auth failures...');
1452
+ networkFix.applyAdvancedFixes();
1453
+ }
1454
 
1455
+ // Retry login; rotate endpoint only when alternate mode is enabled.
1456
+ if (dynamicNetworkHijackEnabled) {
1457
  networkFix.rotateEndpoint();
1458
  }
1459