mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 10:31:47 -03:00
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:
@@ -13,6 +13,12 @@ const PATCHES_CONFIG_SOURCES = [
|
||||
];
|
||||
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
|
||||
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() {
|
||||
const now = Date.now();
|
||||
@@ -177,31 +194,48 @@ async function fetchMirrorManifest() {
|
||||
return manifestCache;
|
||||
}
|
||||
|
||||
const baseUrl = await getPatchesBaseUrl();
|
||||
const manifestUrl = `${baseUrl}/manifest.json`;
|
||||
const mirrors = await getAllMirrorUrls();
|
||||
|
||||
try {
|
||||
console.log('[Mirror] Fetching manifest from:', manifestUrl);
|
||||
const response = await axios.get(manifestUrl, {
|
||||
timeout: 15000,
|
||||
headers: { 'User-Agent': 'Hytale-F2P-Launcher' }
|
||||
});
|
||||
for (let i = 0; i < mirrors.length; i++) {
|
||||
const baseUrl = mirrors[i];
|
||||
const manifestUrl = `${baseUrl}/manifest.json`;
|
||||
try {
|
||||
console.log(`[Mirror] Fetching manifest from: ${manifestUrl}`);
|
||||
const response = await axios.get(manifestUrl, {
|
||||
timeout: 15000,
|
||||
maxRedirects: 5,
|
||||
headers: { 'User-Agent': 'Hytale-F2P-Launcher' }
|
||||
});
|
||||
|
||||
if (response.data && response.data.files) {
|
||||
manifestCache = response.data;
|
||||
manifestCacheTime = now;
|
||||
console.log('[Mirror] Manifest fetched successfully');
|
||||
return response.data;
|
||||
if (response.data && response.data.files) {
|
||||
manifestCache = response.data;
|
||||
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');
|
||||
return response.data;
|
||||
}
|
||||
throw new Error('Invalid manifest structure');
|
||||
} catch (error) {
|
||||
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...`);
|
||||
}
|
||||
}
|
||||
throw new Error('Invalid manifest structure');
|
||||
} catch (error) {
|
||||
console.error('[Mirror] Error fetching manifest:', error.message);
|
||||
if (manifestCache) {
|
||||
console.log('[Mirror] Using expired cache');
|
||||
return manifestCache;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
// All mirrors failed — use cached manifest if available
|
||||
if (manifestCache) {
|
||||
console.log('[Mirror] All mirrors failed, using expired cache');
|
||||
return manifestCache;
|
||||
}
|
||||
throw new Error('All mirrors failed and no cached manifest available');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -499,5 +533,6 @@ module.exports = {
|
||||
extractVersionNumber,
|
||||
getPlatformPatches,
|
||||
findOptimalPatchPath,
|
||||
getPatchesBaseUrl
|
||||
getPatchesBaseUrl,
|
||||
getAllMirrorUrls
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user