mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 19:51:47 -03:00
Compare commits
3 Commits
v2.3.6
...
44834e7d12
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44834e7d12 | ||
|
|
cb7f7e51bf | ||
|
|
9b20c454d3 |
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}
|
||||||
const enhancedError = new Error(`Archive download failed: ${error.message}`);
|
|
||||||
enhancedError.originalError = error;
|
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) {
|
||||||
|
lastError = 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;
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ const { getOS, getArch } = require('../utils/platformUtils');
|
|||||||
// Patches base URL fetched dynamically via multi-source fallback chain
|
// Patches base URL fetched dynamically via multi-source fallback chain
|
||||||
const AUTH_DOMAIN = process.env.HYTALE_AUTH_DOMAIN || 'auth.sanasol.ws';
|
const AUTH_DOMAIN = process.env.HYTALE_AUTH_DOMAIN || 'auth.sanasol.ws';
|
||||||
const PATCHES_CONFIG_SOURCES = [
|
const PATCHES_CONFIG_SOURCES = [
|
||||||
{ type: 'http', url: `https://${AUTH_DOMAIN}/api/patches-config`, name: 'auth-server' },
|
{ type: 'http', url: `https://${AUTH_DOMAIN}/api/patches-config`, name: 'primary' },
|
||||||
{ type: 'http', url: 'https://htdwnldsan.top/patches-config', name: 'backup-http' },
|
{ type: 'http', url: 'https://htdwnldsan.top/patches-config', name: 'backup-1' },
|
||||||
|
{ type: 'http', url: 'https://dl1.htdwnldsan.top/patches-config', name: 'backup-2' },
|
||||||
{ type: 'doh', name: '_patches.htdwnldsan.top', name_label: 'dns-txt' },
|
{ type: 'doh', name: '_patches.htdwnldsan.top', name_label: 'dns-txt' },
|
||||||
];
|
];
|
||||||
const HARDCODED_FALLBACK = 'https://dl.vboro.de/patches';
|
const HARDCODED_FALLBACK = 'https://dl.vboro.de/patches';
|
||||||
|
|
||||||
|
// Alternative mirrors (non-Cloudflare) for regions where CF is blocked
|
||||||
|
const NON_CF_MIRRORS = [
|
||||||
|
'https://dl1.htdwnldsan.top',
|
||||||
|
'https://htdwnldsan.top/patches',
|
||||||
|
];
|
||||||
|
|
||||||
// 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 +174,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 +195,48 @@ async function fetchMirrorManifest() {
|
|||||||
return manifestCache;
|
return manifestCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseUrl = await getPatchesBaseUrl();
|
const mirrors = await getAllMirrorUrls();
|
||||||
const manifestUrl = `${baseUrl}/manifest.json`;
|
|
||||||
|
|
||||||
try {
|
for (let i = 0; i < mirrors.length; i++) {
|
||||||
console.log('[Mirror] Fetching manifest from:', manifestUrl);
|
const baseUrl = mirrors[i];
|
||||||
const response = await axios.get(manifestUrl, {
|
const manifestUrl = `${baseUrl}/manifest.json`;
|
||||||
timeout: 15000,
|
try {
|
||||||
headers: { 'User-Agent': 'Hytale-F2P-Launcher' }
|
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) {
|
if (response.data && response.data.files) {
|
||||||
manifestCache = response.data;
|
manifestCache = response.data;
|
||||||
manifestCacheTime = now;
|
manifestCacheTime = now;
|
||||||
console.log('[Mirror] Manifest fetched successfully');
|
// If a non-primary mirror worked, switch to it for downloads too
|
||||||
return response.data;
|
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 +534,6 @@ module.exports = {
|
|||||||
extractVersionNumber,
|
extractVersionNumber,
|
||||||
getPlatformPatches,
|
getPlatformPatches,
|
||||||
findOptimalPatchPath,
|
findOptimalPatchPath,
|
||||||
getPatchesBaseUrl
|
getPatchesBaseUrl,
|
||||||
|
getAllMirrorUrls
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ const MAX_DOMAIN_LENGTH = 16;
|
|||||||
|
|
||||||
// DualAuth ByteBuddy Agent (runtime class transformation, no JAR modification)
|
// DualAuth ByteBuddy Agent (runtime class transformation, no JAR modification)
|
||||||
const DUALAUTH_AGENT_URL = 'https://github.com/sanasol/hytale-auth-server/releases/latest/download/dualauth-agent.jar';
|
const DUALAUTH_AGENT_URL = 'https://github.com/sanasol/hytale-auth-server/releases/latest/download/dualauth-agent.jar';
|
||||||
|
const DUALAUTH_AGENT_VERSION_API = 'https://api.github.com/repos/sanasol/hytale-auth-server/releases/latest';
|
||||||
const DUALAUTH_AGENT_FILENAME = 'dualauth-agent.jar';
|
const DUALAUTH_AGENT_FILENAME = 'dualauth-agent.jar';
|
||||||
|
const DUALAUTH_AGENT_VERSION_FILE = 'dualauth-agent.version';
|
||||||
|
|
||||||
function getTargetDomain() {
|
function getTargetDomain() {
|
||||||
if (process.env.HYTALE_AUTH_DOMAIN) {
|
if (process.env.HYTALE_AUTH_DOMAIN) {
|
||||||
@@ -511,30 +513,70 @@ class ClientPatcher {
|
|||||||
*/
|
*/
|
||||||
async ensureAgentAvailable(serverDir, progressCallback) {
|
async ensureAgentAvailable(serverDir, progressCallback) {
|
||||||
const agentPath = this.getAgentPath(serverDir);
|
const agentPath = this.getAgentPath(serverDir);
|
||||||
|
const versionPath = path.join(serverDir, DUALAUTH_AGENT_VERSION_FILE);
|
||||||
|
|
||||||
console.log('=== DualAuth Agent (ByteBuddy) ===');
|
console.log('=== DualAuth Agent (ByteBuddy) ===');
|
||||||
console.log(`Target: ${agentPath}`);
|
console.log(`Target: ${agentPath}`);
|
||||||
|
|
||||||
// Check if agent already exists and is valid
|
// Check local version and whether file exists
|
||||||
|
let localVersion = null;
|
||||||
|
let agentExists = false;
|
||||||
if (fs.existsSync(agentPath)) {
|
if (fs.existsSync(agentPath)) {
|
||||||
try {
|
try {
|
||||||
const stats = fs.statSync(agentPath);
|
const stats = fs.statSync(agentPath);
|
||||||
if (stats.size > 1024) {
|
if (stats.size > 1024) {
|
||||||
console.log(`DualAuth Agent present (${(stats.size / 1024).toFixed(0)} KB)`);
|
agentExists = true;
|
||||||
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
if (fs.existsSync(versionPath)) {
|
||||||
return { success: true, agentPath, alreadyExists: true };
|
localVersion = fs.readFileSync(versionPath, 'utf8').trim();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Agent file appears corrupt, re-downloading...');
|
||||||
|
fs.unlinkSync(agentPath);
|
||||||
}
|
}
|
||||||
// File exists but too small - corrupt, re-download
|
|
||||||
console.log('Agent file appears corrupt, re-downloading...');
|
|
||||||
fs.unlinkSync(agentPath);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Could not check agent file:', e.message);
|
console.warn('Could not check agent file:', e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for updates from GitHub
|
||||||
|
let remoteVersion = null;
|
||||||
|
let needsDownload = !agentExists;
|
||||||
|
if (agentExists) {
|
||||||
|
try {
|
||||||
|
if (progressCallback) progressCallback('Checking for agent updates...', 5);
|
||||||
|
const axios = require('axios');
|
||||||
|
const resp = await axios.get(DUALAUTH_AGENT_VERSION_API, {
|
||||||
|
timeout: 5000,
|
||||||
|
headers: { 'Accept': 'application/vnd.github.v3+json' }
|
||||||
|
});
|
||||||
|
remoteVersion = resp.data.tag_name; // e.g. "v1.1.10"
|
||||||
|
if (localVersion && localVersion === remoteVersion) {
|
||||||
|
console.log(`DualAuth Agent up to date (${localVersion})`);
|
||||||
|
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
||||||
|
return { success: true, agentPath, alreadyExists: true, version: localVersion };
|
||||||
|
}
|
||||||
|
console.log(`Agent update available: ${localVersion || 'unknown'} → ${remoteVersion}`);
|
||||||
|
needsDownload = true;
|
||||||
|
} catch (e) {
|
||||||
|
// GitHub API failed - use existing agent if available
|
||||||
|
console.warn(`Could not check for updates: ${e.message}`);
|
||||||
|
if (agentExists) {
|
||||||
|
console.log(`Using existing agent (${localVersion || 'unknown version'})`);
|
||||||
|
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
||||||
|
return { success: true, agentPath, alreadyExists: true, version: localVersion };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!needsDownload) {
|
||||||
|
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
||||||
|
return { success: true, agentPath, alreadyExists: true, version: localVersion };
|
||||||
|
}
|
||||||
|
|
||||||
// Download agent from GitHub releases
|
// Download agent from GitHub releases
|
||||||
if (progressCallback) progressCallback('Downloading DualAuth Agent...', 20);
|
const action = agentExists ? 'Updating' : 'Downloading';
|
||||||
console.log(`Downloading from: ${DUALAUTH_AGENT_URL}`);
|
if (progressCallback) progressCallback(`${action} DualAuth Agent...`, 20);
|
||||||
|
console.log(`${action} from: ${DUALAUTH_AGENT_URL}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Ensure server directory exists
|
// Ensure server directory exists
|
||||||
@@ -548,7 +590,7 @@ class ClientPatcher {
|
|||||||
const stream = await smartDownloadStream(DUALAUTH_AGENT_URL, (chunk, downloadedBytes, total) => {
|
const stream = await smartDownloadStream(DUALAUTH_AGENT_URL, (chunk, downloadedBytes, total) => {
|
||||||
if (progressCallback && total) {
|
if (progressCallback && total) {
|
||||||
const percent = 20 + Math.floor((downloadedBytes / total) * 70);
|
const percent = 20 + Math.floor((downloadedBytes / total) * 70);
|
||||||
progressCallback(`Downloading agent... ${(downloadedBytes / 1024).toFixed(0)} KB`, percent);
|
progressCallback(`${action} agent... ${(downloadedBytes / 1024).toFixed(0)} KB`, percent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -575,9 +617,13 @@ class ClientPatcher {
|
|||||||
}
|
}
|
||||||
fs.renameSync(tmpPath, agentPath);
|
fs.renameSync(tmpPath, agentPath);
|
||||||
|
|
||||||
console.log(`DualAuth Agent downloaded (${(stats.size / 1024).toFixed(0)} KB)`);
|
// Save version
|
||||||
|
const version = remoteVersion || 'unknown';
|
||||||
|
fs.writeFileSync(versionPath, version, 'utf8');
|
||||||
|
|
||||||
|
console.log(`DualAuth Agent ${agentExists ? 'updated' : 'downloaded'} (${(stats.size / 1024).toFixed(0)} KB, ${version})`);
|
||||||
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
if (progressCallback) progressCallback('DualAuth Agent ready', 100);
|
||||||
return { success: true, agentPath };
|
return { success: true, agentPath, updated: agentExists, version };
|
||||||
|
|
||||||
} catch (downloadError) {
|
} catch (downloadError) {
|
||||||
console.error(`Failed to download DualAuth Agent: ${downloadError.message}`);
|
console.error(`Failed to download DualAuth Agent: ${downloadError.message}`);
|
||||||
@@ -586,6 +632,11 @@ class ClientPatcher {
|
|||||||
if (fs.existsSync(tmpPath)) {
|
if (fs.existsSync(tmpPath)) {
|
||||||
try { fs.unlinkSync(tmpPath); } catch (e) { /* ignore */ }
|
try { fs.unlinkSync(tmpPath); } catch (e) { /* ignore */ }
|
||||||
}
|
}
|
||||||
|
// If we had an existing agent, still use it
|
||||||
|
if (agentExists) {
|
||||||
|
console.log('Using existing agent despite update failure');
|
||||||
|
return { success: true, agentPath, alreadyExists: true, version: localVersion };
|
||||||
|
}
|
||||||
return { success: false, error: downloadError.message };
|
return { success: false, error: downloadError.message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hytale-f2p-launcher",
|
"name": "hytale-f2p-launcher",
|
||||||
"version": "2.3.6",
|
"version": "2.3.8",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user