v2.3.7: add non-Cloudflare mirror fallback for blocked regions

Users in Russia/Ukraine where Cloudflare IPs are blocked can now
download game files via htdwnldsan.top (direct VPS → MEGA redirect).
Both manifest fetch and archive downloads try mirrors automatically
on ETIMEDOUT/ECONNREFUSED errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
sanasol
2026-02-21 13:21:19 +01:00
parent 4e04d657b7
commit 9b20c454d3
3 changed files with 115 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ const path = require('path');
const { execFile } = require('child_process'); const { execFile } = require('child_process');
const { downloadFile, retryDownload } = require('../utils/fileManager'); const { downloadFile, retryDownload } = require('../utils/fileManager');
const { getOS, getArch } = require('../utils/platformUtils'); const { getOS, getArch } = require('../utils/platformUtils');
const { validateChecksum, extractVersionDetails, getInstalledClientVersion, getUpdatePlan, extractVersionNumber } = require('../services/versionManager'); const { validateChecksum, extractVersionDetails, getInstalledClientVersion, getUpdatePlan, extractVersionNumber, getAllMirrorUrls, getPatchesBaseUrl } = require('../services/versionManager');
const { installButler } = require('./butlerManager'); const { installButler } = require('./butlerManager');
const { GAME_DIR, CACHE_DIR, TOOLS_DIR } = require('../core/paths'); const { GAME_DIR, CACHE_DIR, TOOLS_DIR } = require('../core/paths');
const { saveVersionClient } = require('../core/config'); const { saveVersionClient } = require('../core/config');
@@ -31,15 +31,62 @@ async function acquireGameArchive(downloadUrl, targetPath, checksum, progressCal
console.log(`Downloading game archive from: ${downloadUrl}`); console.log(`Downloading game archive from: ${downloadUrl}`);
try { // Try primary URL first, then mirror URLs on timeout/connection failure
if (allowRetry) { const mirrors = await getAllMirrorUrls();
await retryDownload(downloadUrl, targetPath, progressCallback); const primaryBase = await getPatchesBaseUrl();
} else { const urlsToTry = [downloadUrl];
await downloadFile(downloadUrl, targetPath, progressCallback);
// Build mirror URLs by replacing the base URL
for (const mirror of mirrors) {
if (mirror !== primaryBase && downloadUrl.startsWith(primaryBase)) {
const mirrorUrl = downloadUrl.replace(primaryBase, mirror);
if (!urlsToTry.includes(mirrorUrl)) {
urlsToTry.push(mirrorUrl);
} }
}
}
let lastError;
for (let i = 0; i < urlsToTry.length; i++) {
const url = urlsToTry[i];
try {
if (i > 0) {
console.log(`[Download] Trying mirror ${i}: ${url}`);
if (progressCallback) {
progressCallback(`Trying alternative mirror (${i}/${urlsToTry.length - 1})...`, 0, null, null, null);
}
// Clean up partial download from previous attempt
if (fs.existsSync(targetPath)) {
try { fs.unlinkSync(targetPath); } catch (e) {}
}
}
if (allowRetry) {
await retryDownload(url, targetPath, progressCallback);
} else {
await downloadFile(url, targetPath, progressCallback);
}
lastError = null;
break; // Success
} catch (error) { } catch (error) {
const enhancedError = new Error(`Archive download failed: ${error.message}`); lastError = error;
enhancedError.originalError = error; const isConnectionError = error.message && (
error.message.includes('ETIMEDOUT') ||
error.message.includes('ECONNREFUSED') ||
error.message.includes('ECONNABORTED') ||
error.message.includes('timeout')
);
if (isConnectionError && i < urlsToTry.length - 1) {
console.warn(`[Download] Connection failed (${error.message}), will try mirror...`);
continue;
}
// Non-connection error or last mirror — throw
break;
}
}
if (lastError) {
const enhancedError = new Error(`Archive download failed: ${lastError.message}`);
enhancedError.originalError = lastError;
enhancedError.downloadUrl = downloadUrl; enhancedError.downloadUrl = downloadUrl;
enhancedError.targetPath = targetPath; enhancedError.targetPath = targetPath;
throw enhancedError; throw enhancedError;

View File

@@ -13,6 +13,12 @@ const PATCHES_CONFIG_SOURCES = [
]; ];
const HARDCODED_FALLBACK = 'https://dl.vboro.de/patches'; const HARDCODED_FALLBACK = 'https://dl.vboro.de/patches';
// Non-Cloudflare mirrors for users where Cloudflare IPs are blocked (Russia, Ukraine, etc.)
// These redirect to MEGA S3 which is not behind Cloudflare
const NON_CF_MIRRORS = [
'https://htdwnldsan.top/patches', // Direct IP VPS → MEGA redirect
];
// Fallback: latest known build number if manifest is unreachable // Fallback: latest known build number if manifest is unreachable
const FALLBACK_LATEST_BUILD = 11; const FALLBACK_LATEST_BUILD = 11;
@@ -167,7 +173,18 @@ async function getPatchesBaseUrl() {
} }
/** /**
* Fetch the mirror manifest * Get all available mirror base URLs (primary + non-Cloudflare fallbacks)
* Used by download logic to retry on different mirrors when primary is blocked
*/
async function getAllMirrorUrls() {
const primary = await getPatchesBaseUrl();
// Deduplicate: don't include mirrors that match primary
const mirrors = NON_CF_MIRRORS.filter(m => m !== primary);
return [primary, ...mirrors];
}
/**
* Fetch the mirror manifest — tries primary URL first, then non-Cloudflare mirrors
*/ */
async function fetchMirrorManifest() { async function fetchMirrorManifest() {
const now = Date.now(); const now = Date.now();
@@ -177,31 +194,48 @@ async function fetchMirrorManifest() {
return manifestCache; return manifestCache;
} }
const baseUrl = await getPatchesBaseUrl(); const mirrors = await getAllMirrorUrls();
const manifestUrl = `${baseUrl}/manifest.json`;
for (let i = 0; i < mirrors.length; i++) {
const baseUrl = mirrors[i];
const manifestUrl = `${baseUrl}/manifest.json`;
try { try {
console.log('[Mirror] Fetching manifest from:', manifestUrl); console.log(`[Mirror] Fetching manifest from: ${manifestUrl}`);
const response = await axios.get(manifestUrl, { const response = await axios.get(manifestUrl, {
timeout: 15000, timeout: 15000,
maxRedirects: 5,
headers: { 'User-Agent': 'Hytale-F2P-Launcher' } headers: { 'User-Agent': 'Hytale-F2P-Launcher' }
}); });
if (response.data && response.data.files) { if (response.data && response.data.files) {
manifestCache = response.data; manifestCache = response.data;
manifestCacheTime = now; manifestCacheTime = now;
// If a non-primary mirror worked, switch to it for downloads too
if (i > 0) {
console.log(`[Mirror] Primary unreachable, switching to mirror: ${baseUrl}`);
patchesBaseUrl = baseUrl;
patchesConfigTime = now;
saveDiskCache(baseUrl);
}
console.log('[Mirror] Manifest fetched successfully'); console.log('[Mirror] Manifest fetched successfully');
return response.data; return response.data;
} }
throw new Error('Invalid manifest structure'); throw new Error('Invalid manifest structure');
} catch (error) { } catch (error) {
console.error('[Mirror] Error fetching manifest:', error.message); const isTimeout = error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED' || error.message.includes('timeout');
console.error(`[Mirror] Error fetching manifest from ${baseUrl}: ${error.message}${isTimeout ? ' (Cloudflare may be blocked)' : ''}`);
if (i < mirrors.length - 1) {
console.log(`[Mirror] Trying next mirror...`);
}
}
}
// All mirrors failed — use cached manifest if available
if (manifestCache) { if (manifestCache) {
console.log('[Mirror] Using expired cache'); console.log('[Mirror] All mirrors failed, using expired cache');
return manifestCache; return manifestCache;
} }
throw error; throw new Error('All mirrors failed and no cached manifest available');
}
} }
/** /**
@@ -499,5 +533,6 @@ module.exports = {
extractVersionNumber, extractVersionNumber,
getPlatformPatches, getPlatformPatches,
findOptimalPatchPath, findOptimalPatchPath,
getPatchesBaseUrl getPatchesBaseUrl,
getAllMirrorUrls
}; };

View File

@@ -1,6 +1,6 @@
{ {
"name": "hytale-f2p-launcher", "name": "hytale-f2p-launcher",
"version": "2.3.6", "version": "2.3.7",
"description": "A modern, cross-platform launcher for Hytale with automatic updates and multi-client support", "description": "A modern, cross-platform launcher for Hytale with automatic updates and multi-client support",
"homepage": "https://git.sanhost.net/sanasol/hytale-f2p", "homepage": "https://git.sanhost.net/sanasol/hytale-f2p",
"main": "main.js", "main": "main.js",