feat/tray #1
@@ -20,18 +20,11 @@ const isDev = !electron_1.app.isPackaged;
|
|||||||
electron_1.app.name = "Ultimate Ban Tracker";
|
electron_1.app.name = "Ultimate Ban Tracker";
|
||||||
// Load environment variables
|
// Load environment variables
|
||||||
dotenv_1.default.config({ path: path_1.default.join(electron_1.app.getAppPath(), '..', '.env') });
|
dotenv_1.default.config({ path: path_1.default.join(electron_1.app.getAppPath(), '..', '.env') });
|
||||||
// --- Server Configuration ---
|
// --- App State ---
|
||||||
|
let mainWindow = null;
|
||||||
|
let tray = null;
|
||||||
let backend = null;
|
let backend = null;
|
||||||
const initBackend = () => {
|
electron_1.app.isQuitting = false;
|
||||||
const config = store.get('serverConfig');
|
|
||||||
if (config && config.enabled && config.url) {
|
|
||||||
console.log(`[Backend] Initializing with URL: ${config.url}`);
|
|
||||||
backend = new backend_1.BackendService(config.url, config.token);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
backend = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const store = new electron_store_1.default({
|
const store = new electron_store_1.default({
|
||||||
defaults: {
|
defaults: {
|
||||||
accounts: [],
|
accounts: [],
|
||||||
@@ -55,62 +48,131 @@ const downloadAvatar = async (steamId, url) => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
electron_1.protocol.registerSchemesAsPrivileged([
|
// --- Backend ---
|
||||||
{ scheme: 'steam-resource', privileges: { secure: true, standard: true, supportFetchAPI: true } }
|
const initBackend = () => {
|
||||||
]);
|
const config = store.get('serverConfig');
|
||||||
// --- Main Window ---
|
if (config && config.enabled && config.url) {
|
||||||
let mainWindow = null;
|
backend = new backend_1.BackendService(config.url, config.token);
|
||||||
function createWindow() {
|
|
||||||
mainWindow = new electron_1.BrowserWindow({
|
|
||||||
width: 1280,
|
|
||||||
height: 800,
|
|
||||||
title: "Ultimate Ban Tracker Desktop",
|
|
||||||
backgroundColor: '#171a21',
|
|
||||||
autoHideMenuBar: true,
|
|
||||||
webPreferences: {
|
|
||||||
preload: path_1.default.join(__dirname, 'preload.js'),
|
|
||||||
nodeIntegration: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
mainWindow.setMenu(null);
|
|
||||||
if (isDev) {
|
|
||||||
mainWindow.loadURL('http://localhost:5173');
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mainWindow.loadFile(path_1.default.join(__dirname, '..', 'dist', 'index.html'));
|
backend = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
// --- Sync Logic ---
|
// --- System Tray ---
|
||||||
|
const createTray = () => {
|
||||||
|
const assetsDir = path_1.default.join(__dirname, '..', 'assets-build');
|
||||||
|
const possibleIcons = ['icon.svg', 'icon.png'];
|
||||||
|
let iconPath = '';
|
||||||
|
for (const name of possibleIcons) {
|
||||||
|
const fullPath = path_1.default.join(assetsDir, name);
|
||||||
|
if (fs_1.default.existsSync(fullPath)) {
|
||||||
|
iconPath = fullPath;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`);
|
||||||
|
if (!iconPath) {
|
||||||
|
console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
||||||
|
tray = new electron_1.Tray(icon);
|
||||||
|
tray.setToolTip('Ultimate Ban Tracker');
|
||||||
|
tray.on('click', () => {
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.show();
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateTrayMenu();
|
||||||
|
console.log(`[Tray] Successfully initialized`);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(`[Tray] Critical error during initialization: ${e.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const updateTrayMenu = () => {
|
||||||
|
if (!tray)
|
||||||
|
return;
|
||||||
|
const accounts = store.get('accounts');
|
||||||
|
const config = store.get('serverConfig');
|
||||||
|
const contextMenu = electron_1.Menu.buildFromTemplate([
|
||||||
|
{ label: `Ultimate Ban Tracker v${electron_1.app.getVersion()}`, enabled: false },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Switch Account',
|
||||||
|
submenu: accounts.length > 0 ? accounts.map(acc => ({
|
||||||
|
label: `${acc.personaName} ${acc.loginName ? `(${acc.loginName})` : ''}`,
|
||||||
|
enabled: !!acc.loginName,
|
||||||
|
click: () => handleSwitchAccount(acc.loginName)
|
||||||
|
})) : [{ label: 'No accounts found', enabled: false }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sync Now',
|
||||||
|
enabled: !!config?.enabled,
|
||||||
|
click: () => syncAccounts()
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{ label: 'Show Dashboard', click: () => { if (mainWindow)
|
||||||
|
mainWindow.show(); } },
|
||||||
|
{ label: 'Quit', click: () => { electron_1.app.isQuitting = true; electron_1.app.quit(); } }
|
||||||
|
]);
|
||||||
|
tray.setContextMenu(contextMenu);
|
||||||
|
};
|
||||||
|
// --- Steam Logic ---
|
||||||
|
const killSteam = async () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const command = process.platform === 'win32' ? 'taskkill /f /im steam.exe' : 'pkill -9 steam';
|
||||||
|
(0, child_process_1.exec)(command, () => setTimeout(resolve, 1000));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const startSteam = () => {
|
||||||
|
const command = process.platform === 'win32' ? 'start steam://open/main' : 'steam &';
|
||||||
|
(0, child_process_1.exec)(command);
|
||||||
|
};
|
||||||
|
const handleSwitchAccount = async (loginName) => {
|
||||||
|
if (!loginName)
|
||||||
|
return false;
|
||||||
|
try {
|
||||||
|
await killSteam();
|
||||||
|
const accounts = store.get('accounts');
|
||||||
|
const account = accounts.find(a => a.loginName === loginName);
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const regCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v AutoLoginUser /t REG_SZ /d "${loginName}" /f`;
|
||||||
|
const rememberCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v RememberPassword /t REG_DWORD /d 1 /f`;
|
||||||
|
await new Promise((res, rej) => (0, child_process_1.exec)(`${regCommand} && ${rememberCommand}`, (e) => e ? rej(e) : res()));
|
||||||
|
if (account && account.loginConfig)
|
||||||
|
steam_client_1.steamClient.injectAccountConfig(loginName, account.loginConfig);
|
||||||
|
}
|
||||||
|
else if (process.platform === 'linux') {
|
||||||
|
await steam_client_1.steamClient.setAutoLoginUser(loginName, account?.loginConfig, account?.steamId);
|
||||||
|
}
|
||||||
|
startSteam();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// --- Sync Worker ---
|
||||||
const syncAccounts = async () => {
|
const syncAccounts = async () => {
|
||||||
initBackend();
|
initBackend();
|
||||||
let accounts = store.get('accounts');
|
let accounts = store.get('accounts');
|
||||||
let hasChanges = false;
|
let hasChanges = false;
|
||||||
// 1. PULL SHARED ACCOUNTS FROM SERVER
|
|
||||||
if (backend) {
|
if (backend) {
|
||||||
console.log('[Sync] Phase 1: Pulling from server...');
|
|
||||||
try {
|
try {
|
||||||
const shared = await backend.getSharedAccounts();
|
const shared = await backend.getSharedAccounts();
|
||||||
for (const s of shared) {
|
for (const s of shared) {
|
||||||
const exists = accounts.find(a => a.steamId === s.steamId);
|
const exists = accounts.find(a => a.steamId === s.steamId);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
console.log(`[Sync] Discovered new account on server: ${s.personaName}`);
|
|
||||||
accounts.push({
|
accounts.push({
|
||||||
_id: `shared_${s.steamId}`,
|
_id: `shared_${s.steamId}`,
|
||||||
steamId: s.steamId,
|
steamId: s.steamId, personaName: s.personaName, avatar: s.avatar, profileUrl: s.profileUrl,
|
||||||
personaName: s.personaName,
|
vacBanned: s.vacBanned, gameBans: s.gameBans, cooldownExpiresAt: s.cooldownExpiresAt,
|
||||||
avatar: s.avatar,
|
loginName: s.loginName || '', steamLoginSecure: s.steamLoginSecure, loginConfig: s.loginConfig,
|
||||||
profileUrl: s.profileUrl,
|
sessionUpdatedAt: s.sessionUpdatedAt, autoCheckCooldown: !!s.steamLoginSecure,
|
||||||
vacBanned: s.vacBanned,
|
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
||||||
gameBans: s.gameBans,
|
|
||||||
cooldownExpiresAt: s.cooldownExpiresAt,
|
|
||||||
loginName: s.loginName || '',
|
|
||||||
steamLoginSecure: s.steamLoginSecure,
|
|
||||||
loginConfig: s.loginConfig,
|
|
||||||
sessionUpdatedAt: s.sessionUpdatedAt,
|
|
||||||
autoCheckCooldown: s.steamLoginSecure ? true : false,
|
|
||||||
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none',
|
|
||||||
lastBanCheck: new Date().toISOString()
|
|
||||||
});
|
});
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
@@ -118,7 +180,6 @@ const syncAccounts = async () => {
|
|||||||
const sDate = s.sessionUpdatedAt ? new Date(s.sessionUpdatedAt) : new Date(0);
|
const sDate = s.sessionUpdatedAt ? new Date(s.sessionUpdatedAt) : new Date(0);
|
||||||
const lDate = exists.sessionUpdatedAt ? new Date(exists.sessionUpdatedAt) : new Date(0);
|
const lDate = exists.sessionUpdatedAt ? new Date(exists.sessionUpdatedAt) : new Date(0);
|
||||||
if (sDate > lDate) {
|
if (sDate > lDate) {
|
||||||
console.log(`[Sync] Updating session for ${exists.personaName} (Server is newer)`);
|
|
||||||
if (s.loginName)
|
if (s.loginName)
|
||||||
exists.loginName = s.loginName;
|
exists.loginName = s.loginName;
|
||||||
if (s.loginConfig)
|
if (s.loginConfig)
|
||||||
@@ -138,28 +199,23 @@ const syncAccounts = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) { }
|
||||||
console.error('[Sync] Pull failed');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// BROADCAST PULL RESULTS IMMEDIATELY
|
|
||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
store.set('accounts', accounts);
|
store.set('accounts', accounts);
|
||||||
if (mainWindow)
|
if (mainWindow)
|
||||||
mainWindow.webContents.send('accounts-updated', accounts);
|
mainWindow.webContents.send('accounts-updated', accounts);
|
||||||
|
updateTrayMenu();
|
||||||
}
|
}
|
||||||
if (accounts.length === 0)
|
if (accounts.length === 0)
|
||||||
return;
|
return;
|
||||||
// 2. BACKGROUND STEALTH CHECKS
|
|
||||||
console.log(`[Sync] Phase 2: Starting background checks for ${accounts.length} accounts...`);
|
|
||||||
const updatedAccounts = [...accounts];
|
const updatedAccounts = [...accounts];
|
||||||
let scrapeChanges = false;
|
let scrapeChanges = false;
|
||||||
for (const account of updatedAccounts) {
|
for (const account of updatedAccounts) {
|
||||||
try {
|
try {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
|
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
|
||||||
const hoursSinceCheck = (now.getTime() - lastCheck.getTime()) / 3600000;
|
if ((now.getTime() - lastCheck.getTime()) / 3600000 > 6 || !account.personaName) {
|
||||||
if (hoursSinceCheck > 6 || !account.personaName) {
|
|
||||||
const profile = await (0, steam_web_1.fetchProfileData)(account.steamId, account.steamLoginSecure);
|
const profile = await (0, steam_web_1.fetchProfileData)(account.steamId, account.steamLoginSecure);
|
||||||
const bans = await (0, steam_web_1.scrapeBanStatus)(profile.profileUrl, account.steamLoginSecure);
|
const bans = await (0, steam_web_1.scrapeBanStatus)(profile.profileUrl, account.steamLoginSecure);
|
||||||
account.personaName = profile.personaName;
|
account.personaName = profile.personaName;
|
||||||
@@ -189,23 +245,14 @@ const syncAccounts = async () => {
|
|||||||
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now)
|
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now)
|
||||||
continue;
|
continue;
|
||||||
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
|
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
|
||||||
const hoursSinceScrape = (now.getTime() - lastScrape.getTime()) / 3600000;
|
if ((now.getTime() - lastScrape.getTime()) / 3600000 > 8) {
|
||||||
if (hoursSinceScrape > 8) {
|
await new Promise(r => setTimeout(r, Math.floor(Math.random() * 60000) + 5000));
|
||||||
const jitter = Math.floor(Math.random() * 60000) + 5000;
|
|
||||||
await new Promise(r => setTimeout(r, jitter));
|
|
||||||
try {
|
try {
|
||||||
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, account.steamLoginSecure);
|
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, account.steamLoginSecure);
|
||||||
account.authError = false;
|
account.authError = false;
|
||||||
account.lastScrapeTime = new Date().toISOString();
|
account.lastScrapeTime = new Date().toISOString();
|
||||||
if (result.isActive) {
|
if (result.isActive) {
|
||||||
if (result.expiresAt) {
|
account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString();
|
||||||
account.cooldownExpiresAt = result.expiresAt.toISOString();
|
|
||||||
}
|
|
||||||
else if (!account.cooldownExpiresAt) {
|
|
||||||
const placeholder = new Date();
|
|
||||||
placeholder.setHours(placeholder.getHours() + 24);
|
|
||||||
account.cooldownExpiresAt = placeholder.toISOString();
|
|
||||||
}
|
|
||||||
if (backend)
|
if (backend)
|
||||||
await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
||||||
}
|
}
|
||||||
@@ -231,14 +278,13 @@ const syncAccounts = async () => {
|
|||||||
store.set('accounts', updatedAccounts);
|
store.set('accounts', updatedAccounts);
|
||||||
if (mainWindow)
|
if (mainWindow)
|
||||||
mainWindow.webContents.send('accounts-updated', updatedAccounts);
|
mainWindow.webContents.send('accounts-updated', updatedAccounts);
|
||||||
|
updateTrayMenu();
|
||||||
}
|
}
|
||||||
console.log('[Sync] Sync cycle finished.');
|
|
||||||
};
|
};
|
||||||
const scheduleNextSync = () => {
|
const scheduleNextSync = () => {
|
||||||
const delay = isDev ? 120000 : (Math.random() * 30 * 60000) + 30 * 60000;
|
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, isDev ? 120000 : 1800000);
|
||||||
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, delay);
|
|
||||||
};
|
};
|
||||||
// --- Steam Auto-Discovery ---
|
// --- Discovery ---
|
||||||
const addingAccounts = new Set();
|
const addingAccounts = new Set();
|
||||||
const handleLocalAccountsFound = async (localAccounts) => {
|
const handleLocalAccountsFound = async (localAccounts) => {
|
||||||
const currentAccounts = store.get('accounts');
|
const currentAccounts = store.get('accounts');
|
||||||
@@ -261,17 +307,11 @@ const handleLocalAccountsFound = async (localAccounts) => {
|
|||||||
const localPath = await downloadAvatar(profile.steamId, profile.avatar);
|
const localPath = await downloadAvatar(profile.steamId, profile.avatar);
|
||||||
currentAccounts.push({
|
currentAccounts.push({
|
||||||
_id: Date.now().toString() + Math.random().toString().slice(2, 5),
|
_id: Date.now().toString() + Math.random().toString().slice(2, 5),
|
||||||
steamId: local.steamId,
|
steamId: local.steamId, personaName: profile.personaName || local.accountName,
|
||||||
personaName: profile.personaName || local.personaName || local.accountName,
|
loginName: local.accountName, autoCheckCooldown: false, avatar: profile.avatar,
|
||||||
loginName: local.accountName,
|
localAvatar: localPath, profileUrl: profile.profileUrl,
|
||||||
autoCheckCooldown: false,
|
|
||||||
avatar: profile.avatar,
|
|
||||||
localAvatar: localPath,
|
|
||||||
profileUrl: profile.profileUrl,
|
|
||||||
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none',
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none',
|
||||||
vacBanned: bans.vacBanned,
|
vacBanned: bans.vacBanned, gameBans: bans.gameBans, lastBanCheck: new Date().toISOString()
|
||||||
gameBans: bans.gameBans,
|
|
||||||
lastBanCheck: new Date().toISOString()
|
|
||||||
});
|
});
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
@@ -283,8 +323,29 @@ const handleLocalAccountsFound = async (localAccounts) => {
|
|||||||
store.set('accounts', currentAccounts);
|
store.set('accounts', currentAccounts);
|
||||||
if (mainWindow)
|
if (mainWindow)
|
||||||
mainWindow.webContents.send('accounts-updated', currentAccounts);
|
mainWindow.webContents.send('accounts-updated', currentAccounts);
|
||||||
|
updateTrayMenu();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// --- Main Window Creation ---
|
||||||
|
function createWindow() {
|
||||||
|
mainWindow = new electron_1.BrowserWindow({
|
||||||
|
width: 1280, height: 800, title: "Ultimate Ban Tracker", backgroundColor: '#171a21', autoHideMenuBar: true,
|
||||||
|
webPreferences: { preload: path_1.default.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true }
|
||||||
|
});
|
||||||
|
mainWindow.setMenu(null);
|
||||||
|
mainWindow.on('close', (event) => {
|
||||||
|
if (!electron_1.app.isQuitting) {
|
||||||
|
event.preventDefault();
|
||||||
|
mainWindow?.hide();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (isDev)
|
||||||
|
mainWindow.loadURL('http://localhost:5173');
|
||||||
|
else
|
||||||
|
mainWindow.loadFile(path_1.default.join(__dirname, '..', 'dist', 'index.html'));
|
||||||
|
}
|
||||||
|
// --- App Lifecycle ---
|
||||||
electron_1.app.whenReady().then(() => {
|
electron_1.app.whenReady().then(() => {
|
||||||
electron_1.protocol.handle('steam-resource', (request) => {
|
electron_1.protocol.handle('steam-resource', (request) => {
|
||||||
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
|
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
|
||||||
@@ -301,13 +362,19 @@ electron_1.app.whenReady().then(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
createWindow();
|
createWindow();
|
||||||
|
createTray();
|
||||||
initBackend();
|
initBackend();
|
||||||
setTimeout(syncAccounts, 5000);
|
setTimeout(syncAccounts, 5000);
|
||||||
scheduleNextSync();
|
scheduleNextSync();
|
||||||
steam_client_1.steamClient.startWatching(handleLocalAccountsFound);
|
steam_client_1.steamClient.startWatching(handleLocalAccountsFound);
|
||||||
});
|
});
|
||||||
|
electron_1.app.on('window-all-closed', () => { if (process.platform !== 'darwin' && electron_1.app.isQuitting)
|
||||||
|
electron_1.app.quit(); });
|
||||||
|
electron_1.app.on('activate', () => { if (electron_1.BrowserWindow.getAllWindows().length === 0)
|
||||||
|
createWindow();
|
||||||
|
else
|
||||||
|
mainWindow?.show(); });
|
||||||
// --- IPC Handlers ---
|
// --- IPC Handlers ---
|
||||||
console.log('[Main] Registering IPC Handlers...');
|
|
||||||
electron_1.ipcMain.handle('get-accounts', () => store.get('accounts'));
|
electron_1.ipcMain.handle('get-accounts', () => store.get('accounts'));
|
||||||
electron_1.ipcMain.handle('get-server-config', () => store.get('serverConfig'));
|
electron_1.ipcMain.handle('get-server-config', () => store.get('serverConfig'));
|
||||||
electron_1.ipcMain.handle('update-server-config', (event, config) => {
|
electron_1.ipcMain.handle('update-server-config', (event, config) => {
|
||||||
@@ -333,7 +400,6 @@ electron_1.ipcMain.handle('login-to-server', async () => {
|
|||||||
if (captured)
|
if (captured)
|
||||||
return;
|
return;
|
||||||
captured = true;
|
captured = true;
|
||||||
console.log('[ServerAuth] Securely captured token');
|
|
||||||
let serverSteamId = undefined;
|
let serverSteamId = undefined;
|
||||||
try {
|
try {
|
||||||
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||||
@@ -346,7 +412,6 @@ electron_1.ipcMain.handle('login-to-server', async () => {
|
|||||||
authWindow.close();
|
authWindow.close();
|
||||||
resolve(true);
|
resolve(true);
|
||||||
};
|
};
|
||||||
// METHOD 1: Sniff HTTP Headers
|
|
||||||
const filter = { urls: [`${config.url}/*`] };
|
const filter = { urls: [`${config.url}/*`] };
|
||||||
authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
|
authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
|
||||||
const headers = details.responseHeaders || {};
|
const headers = details.responseHeaders || {};
|
||||||
@@ -355,7 +420,6 @@ electron_1.ipcMain.handle('login-to-server', async () => {
|
|||||||
saveServerAuth(authToken);
|
saveServerAuth(authToken);
|
||||||
callback({ cancel: false });
|
callback({ cancel: false });
|
||||||
});
|
});
|
||||||
// METHOD 2: Watch Window Title (Fallback)
|
|
||||||
authWindow.on('page-title-updated', (event, title) => {
|
authWindow.on('page-title-updated', (event, title) => {
|
||||||
if (title.includes('AUTH_TOKEN:')) {
|
if (title.includes('AUTH_TOKEN:')) {
|
||||||
const token = title.split('AUTH_TOKEN:')[1];
|
const token = title.split('AUTH_TOKEN:')[1];
|
||||||
@@ -363,7 +427,7 @@ electron_1.ipcMain.handle('login-to-server', async () => {
|
|||||||
saveServerAuth(token);
|
saveServerAuth(token);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
authWindow.on('closed', () => { resolve(false); });
|
authWindow.on('closed', () => resolve(false));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
electron_1.ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
|
electron_1.ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
|
||||||
@@ -371,7 +435,6 @@ electron_1.ipcMain.handle('sync-now', async () => { await syncAccounts(); return
|
|||||||
electron_1.ipcMain.handle('add-account', async (event, { identifier }) => {
|
electron_1.ipcMain.handle('add-account', async (event, { identifier }) => {
|
||||||
try {
|
try {
|
||||||
initBackend();
|
initBackend();
|
||||||
// OPTIMIZATION: Check community server first
|
|
||||||
if (backend) {
|
if (backend) {
|
||||||
const shared = await backend.getCommunityAccounts();
|
const shared = await backend.getCommunityAccounts();
|
||||||
const existing = shared.find((s) => s.steamId === identifier || s.profileUrl.includes(identifier));
|
const existing = shared.find((s) => s.steamId === identifier || s.profileUrl.includes(identifier));
|
||||||
@@ -380,23 +443,16 @@ electron_1.ipcMain.handle('add-account', async (event, { identifier }) => {
|
|||||||
if (accounts.find(a => a.steamId === existing.steamId))
|
if (accounts.find(a => a.steamId === existing.steamId))
|
||||||
throw new Error('Account already tracked');
|
throw new Error('Account already tracked');
|
||||||
const newAccount = {
|
const newAccount = {
|
||||||
_id: `shared_${existing.steamId}`,
|
_id: `shared_${existing.steamId}`, steamId: existing.steamId, personaName: existing.personaName,
|
||||||
steamId: existing.steamId,
|
avatar: existing.avatar, profileUrl: existing.profileUrl, vacBanned: existing.vacBanned,
|
||||||
personaName: existing.personaName,
|
gameBans: existing.gameBans, cooldownExpiresAt: existing.cooldownExpiresAt,
|
||||||
avatar: existing.avatar,
|
loginName: existing.loginName || '', steamLoginSecure: existing.steamLoginSecure,
|
||||||
profileUrl: existing.profileUrl,
|
loginConfig: existing.loginConfig, sessionUpdatedAt: existing.sessionUpdatedAt,
|
||||||
vacBanned: existing.vacBanned,
|
autoCheckCooldown: !!existing.steamLoginSecure, status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
|
||||||
gameBans: existing.gameBans,
|
|
||||||
cooldownExpiresAt: existing.cooldownExpiresAt,
|
|
||||||
loginName: existing.loginName || '',
|
|
||||||
steamLoginSecure: existing.steamLoginSecure,
|
|
||||||
loginConfig: existing.loginConfig,
|
|
||||||
sessionUpdatedAt: existing.sessionUpdatedAt,
|
|
||||||
autoCheckCooldown: existing.steamLoginSecure ? true : false,
|
|
||||||
status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
|
|
||||||
lastBanCheck: new Date().toISOString()
|
lastBanCheck: new Date().toISOString()
|
||||||
};
|
};
|
||||||
store.set('accounts', [...accounts, newAccount]);
|
store.set('accounts', [...accounts, newAccount]);
|
||||||
|
updateTrayMenu();
|
||||||
return newAccount;
|
return newAccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,13 +461,13 @@ electron_1.ipcMain.handle('add-account', async (event, { identifier }) => {
|
|||||||
const localAvatar = await downloadAvatar(profile.steamId, profile.avatar);
|
const localAvatar = await downloadAvatar(profile.steamId, profile.avatar);
|
||||||
const accounts = store.get('accounts');
|
const accounts = store.get('accounts');
|
||||||
const newAccount = {
|
const newAccount = {
|
||||||
_id: Date.now().toString(),
|
_id: Date.now().toString(), steamId: profile.steamId, personaName: profile.personaName,
|
||||||
steamId: profile.steamId, personaName: profile.personaName, loginName: '',
|
loginName: '', avatar: profile.avatar, localAvatar: localAvatar, profileUrl: profile.profileUrl,
|
||||||
avatar: profile.avatar, localAvatar: localAvatar, profileUrl: profile.profileUrl,
|
|
||||||
autoCheckCooldown: false, vacBanned: bans.vacBanned, gameBans: bans.gameBans,
|
autoCheckCooldown: false, vacBanned: bans.vacBanned, gameBans: bans.gameBans,
|
||||||
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
||||||
};
|
};
|
||||||
store.set('accounts', [...accounts, newAccount]);
|
store.set('accounts', [...accounts, newAccount]);
|
||||||
|
updateTrayMenu();
|
||||||
return newAccount;
|
return newAccount;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -424,6 +480,7 @@ electron_1.ipcMain.handle('update-account', (event, id, data) => {
|
|||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
accounts[index] = { ...accounts[index], ...data };
|
accounts[index] = { ...accounts[index], ...data };
|
||||||
store.set('accounts', accounts);
|
store.set('accounts', accounts);
|
||||||
|
updateTrayMenu();
|
||||||
return accounts[index];
|
return accounts[index];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -431,6 +488,7 @@ electron_1.ipcMain.handle('update-account', (event, id, data) => {
|
|||||||
electron_1.ipcMain.handle('delete-account', (event, id) => {
|
electron_1.ipcMain.handle('delete-account', (event, id) => {
|
||||||
const accounts = store.get('accounts');
|
const accounts = store.get('accounts');
|
||||||
store.set('accounts', accounts.filter((a) => a._id !== id));
|
store.set('accounts', accounts.filter((a) => a._id !== id));
|
||||||
|
updateTrayMenu();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
electron_1.ipcMain.handle('share-account-with-user', async (event, steamId, targetSteamId) => {
|
electron_1.ipcMain.handle('share-account-with-user', async (event, steamId, targetSteamId) => {
|
||||||
@@ -446,56 +504,15 @@ electron_1.ipcMain.handle('share-account-with-user', async (event, steamId, targ
|
|||||||
});
|
});
|
||||||
electron_1.ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
|
electron_1.ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
|
||||||
electron_1.ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
|
electron_1.ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
|
||||||
const killSteam = async () => {
|
electron_1.ipcMain.handle('switch-account', async (event, loginName) => await handleSwitchAccount(loginName));
|
||||||
return new Promise((resolve) => {
|
|
||||||
const command = process.platform === 'win32' ? 'taskkill /f /im steam.exe' : 'pkill -9 steam';
|
|
||||||
(0, child_process_1.exec)(command, () => setTimeout(resolve, 1000));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const startSteam = () => {
|
|
||||||
const command = process.platform === 'win32' ? 'start steam://open/main' : 'steam &';
|
|
||||||
(0, child_process_1.exec)(command);
|
|
||||||
};
|
|
||||||
electron_1.ipcMain.handle('switch-account', async (event, loginName) => {
|
|
||||||
if (!loginName)
|
|
||||||
return false;
|
|
||||||
try {
|
|
||||||
await killSteam();
|
|
||||||
const accounts = store.get('accounts');
|
|
||||||
const account = accounts.find(a => a.loginName === loginName);
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
const regCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v AutoLoginUser /t REG_SZ /d "${loginName}" /f`;
|
|
||||||
const rememberCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v RememberPassword /t REG_DWORD /d 1 /f`;
|
|
||||||
await new Promise((res, rej) => (0, child_process_1.exec)(`${regCommand} && ${rememberCommand}`, (e) => e ? rej(e) : res()));
|
|
||||||
if (account && account.loginConfig)
|
|
||||||
steam_client_1.steamClient.injectAccountConfig(loginName, account.loginConfig);
|
|
||||||
}
|
|
||||||
else if (process.platform === 'linux') {
|
|
||||||
await steam_client_1.steamClient.setAutoLoginUser(loginName, account?.loginConfig, account?.steamId);
|
|
||||||
}
|
|
||||||
startSteam();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
electron_1.ipcMain.handle('open-external', (event, url) => electron_1.shell.openExternal(url));
|
electron_1.ipcMain.handle('open-external', (event, url) => electron_1.shell.openExternal(url));
|
||||||
electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) => {
|
electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) => {
|
||||||
const loginSession = electron_1.session.fromPartition('persist:steam-login');
|
const loginSession = electron_1.session.fromPartition('persist:steam-login');
|
||||||
await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
|
await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const loginWindow = new electron_1.BrowserWindow({
|
const loginWindow = new electron_1.BrowserWindow({
|
||||||
width: 800,
|
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Steam',
|
||||||
height: 700,
|
webPreferences: { nodeIntegration: false, contextIsolation: true, partition: 'persist:steam-login' }
|
||||||
parent: mainWindow || undefined,
|
|
||||||
modal: true,
|
|
||||||
title: 'Login to Steam (Ensure "Remember Me" is checked!)',
|
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
partition: 'persist:steam-login'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
loginWindow.loadURL('https://steamcommunity.com/login/home/?goto=my/gcpd/730');
|
loginWindow.loadURL('https://steamcommunity.com/login/home/?goto=my/gcpd/730');
|
||||||
const checkCookie = setInterval(async () => {
|
const checkCookie = setInterval(async () => {
|
||||||
@@ -505,13 +522,10 @@ electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) =>
|
|||||||
if (secureCookie) {
|
if (secureCookie) {
|
||||||
const steamId = decodeURIComponent(secureCookie.value).split('|')[0];
|
const steamId = decodeURIComponent(secureCookie.value).split('|')[0];
|
||||||
if (steamId) {
|
if (steamId) {
|
||||||
if (expectedSteamId && steamId !== expectedSteamId) {
|
if (expectedSteamId && steamId !== expectedSteamId)
|
||||||
console.error(`[Auth] ID Mismatch! Expected ${expectedSteamId}, got ${steamId}`);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
clearInterval(checkCookie);
|
clearInterval(checkCookie);
|
||||||
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
||||||
console.log(`[Auth] Captured session for SteamID: ${steamId}`);
|
|
||||||
const accounts = store.get('accounts');
|
const accounts = store.get('accounts');
|
||||||
const accountIndex = accounts.findIndex(a => a.steamId === steamId);
|
const accountIndex = accounts.findIndex(a => a.steamId === steamId);
|
||||||
if (accountIndex !== -1) {
|
if (accountIndex !== -1) {
|
||||||
@@ -526,25 +540,18 @@ electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) =>
|
|||||||
account.loginConfig = config;
|
account.loginConfig = config;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
console.log(`[Auth] Performing initial scrape for ${account.personaName}...`);
|
|
||||||
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, cookieString);
|
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, cookieString);
|
||||||
account.lastScrapeTime = new Date().toISOString();
|
account.lastScrapeTime = new Date().toISOString();
|
||||||
if (result.isActive && result.expiresAt) {
|
account.cooldownExpiresAt = result.isActive && result.expiresAt ? result.expiresAt.toISOString() : undefined;
|
||||||
account.cooldownExpiresAt = result.expiresAt.toISOString();
|
|
||||||
}
|
|
||||||
else if (!result.isActive) {
|
|
||||||
account.cooldownExpiresAt = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.error('[Auth] Initial scrape failed:', e);
|
|
||||||
}
|
}
|
||||||
|
catch (e) { }
|
||||||
initBackend();
|
initBackend();
|
||||||
if (backend)
|
if (backend)
|
||||||
await backend.shareAccount(account);
|
await backend.shareAccount(account);
|
||||||
store.set('accounts', accounts);
|
store.set('accounts', accounts);
|
||||||
if (mainWindow)
|
if (mainWindow)
|
||||||
mainWindow.webContents.send('accounts-updated', accounts);
|
mainWindow.webContents.send('accounts-updated', accounts);
|
||||||
|
updateTrayMenu();
|
||||||
loginWindow.close();
|
loginWindow.close();
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
@@ -553,11 +560,6 @@ electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) =>
|
|||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
}, 1000);
|
}, 1000);
|
||||||
loginWindow.on('closed', () => {
|
loginWindow.on('closed', () => { clearInterval(checkCookie); resolve(false); });
|
||||||
clearInterval(checkCookie);
|
|
||||||
resolve(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
electron_1.app.on('window-all-closed', () => { if (process.platform !== 'darwin')
|
|
||||||
electron_1.app.quit(); });
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { app, BrowserWindow, ipcMain, shell, session, protocol, net } from 'electron';
|
import { app, BrowserWindow, ipcMain, shell, session, protocol, net, Tray, Menu, nativeImage } from 'electron';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import Store from 'electron-store';
|
import Store from 'electron-store';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import cron from 'node-cron';
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { pathToFileURL } from 'url';
|
import { pathToFileURL } from 'url';
|
||||||
@@ -20,20 +19,7 @@ app.name = "Ultimate Ban Tracker";
|
|||||||
// Load environment variables
|
// Load environment variables
|
||||||
dotenv.config({ path: path.join(app.getAppPath(), '..', '.env') });
|
dotenv.config({ path: path.join(app.getAppPath(), '..', '.env') });
|
||||||
|
|
||||||
// --- Server Configuration ---
|
// --- Types & Interfaces ---
|
||||||
let backend: BackendService | null = null;
|
|
||||||
|
|
||||||
const initBackend = () => {
|
|
||||||
const config = store.get('serverConfig');
|
|
||||||
if (config && config.enabled && config.url) {
|
|
||||||
console.log(`[Backend] Initializing with URL: ${config.url}`);
|
|
||||||
backend = new BackendService(config.url, config.token);
|
|
||||||
} else {
|
|
||||||
backend = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Local Data Store ---
|
|
||||||
interface Account {
|
interface Account {
|
||||||
_id: string;
|
_id: string;
|
||||||
steamId: string;
|
steamId: string;
|
||||||
@@ -61,8 +47,15 @@ interface ServerConfig {
|
|||||||
token?: string;
|
token?: string;
|
||||||
serverSteamId?: string;
|
serverSteamId?: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
theme?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- App State ---
|
||||||
|
let mainWindow: BrowserWindow | null = null;
|
||||||
|
let tray: Tray | null = null;
|
||||||
|
let backend: BackendService | null = null;
|
||||||
|
(app as any).isQuitting = false;
|
||||||
|
|
||||||
const store = new Store<{ accounts: Account[], serverConfig: ServerConfig }>({
|
const store = new Store<{ accounts: Account[], serverConfig: ServerConfig }>({
|
||||||
defaults: {
|
defaults: {
|
||||||
accounts: [],
|
accounts: [],
|
||||||
@@ -86,403 +79,84 @@ const downloadAvatar = async (steamId: string, url: string): Promise<string | un
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protocol.registerSchemesAsPrivileged([
|
// --- Backend ---
|
||||||
{ scheme: 'steam-resource', privileges: { secure: true, standard: true, supportFetchAPI: true } }
|
const initBackend = () => {
|
||||||
]);
|
const config = store.get('serverConfig');
|
||||||
|
if (config && config.enabled && config.url) {
|
||||||
// --- Main Window ---
|
backend = new BackendService(config.url, config.token);
|
||||||
let mainWindow: BrowserWindow | null = null;
|
|
||||||
|
|
||||||
function createWindow() {
|
|
||||||
mainWindow = new BrowserWindow({
|
|
||||||
width: 1280,
|
|
||||||
height: 800,
|
|
||||||
title: "Ultimate Ban Tracker Desktop",
|
|
||||||
backgroundColor: '#171a21',
|
|
||||||
autoHideMenuBar: true,
|
|
||||||
webPreferences: {
|
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
|
||||||
nodeIntegration: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
mainWindow.setMenu(null);
|
|
||||||
|
|
||||||
if (isDev) {
|
|
||||||
mainWindow.loadURL('http://localhost:5173');
|
|
||||||
} else {
|
} else {
|
||||||
mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
|
backend = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// --- Sync Logic ---
|
// --- System Tray ---
|
||||||
|
const createTray = () => {
|
||||||
|
const assetsDir = path.join(__dirname, '..', 'assets-build');
|
||||||
|
const possibleIcons = ['icon.svg', 'icon.png'];
|
||||||
|
let iconPath = '';
|
||||||
|
|
||||||
const syncAccounts = async () => {
|
for (const name of possibleIcons) {
|
||||||
initBackend();
|
const fullPath = path.join(assetsDir, name);
|
||||||
let accounts = store.get('accounts') as Account[];
|
if (fs.existsSync(fullPath)) {
|
||||||
let hasChanges = false;
|
iconPath = fullPath;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 1. PULL SHARED ACCOUNTS FROM SERVER
|
console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`);
|
||||||
if (backend) {
|
|
||||||
console.log('[Sync] Phase 1: Pulling from server...');
|
if (!iconPath) {
|
||||||
try {
|
console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`);
|
||||||
const shared = await backend.getSharedAccounts();
|
return;
|
||||||
for (const s of shared) {
|
|
||||||
const exists = accounts.find(a => a.steamId === s.steamId);
|
|
||||||
if (!exists) {
|
|
||||||
console.log(`[Sync] Discovered new account on server: ${s.personaName}`);
|
|
||||||
accounts.push({
|
|
||||||
_id: `shared_${s.steamId}`,
|
|
||||||
steamId: s.steamId,
|
|
||||||
personaName: s.personaName,
|
|
||||||
avatar: s.avatar,
|
|
||||||
profileUrl: s.profileUrl,
|
|
||||||
vacBanned: s.vacBanned,
|
|
||||||
gameBans: s.gameBans,
|
|
||||||
cooldownExpiresAt: s.cooldownExpiresAt,
|
|
||||||
loginName: s.loginName || '',
|
|
||||||
steamLoginSecure: s.steamLoginSecure,
|
|
||||||
loginConfig: s.loginConfig,
|
|
||||||
sessionUpdatedAt: s.sessionUpdatedAt,
|
|
||||||
autoCheckCooldown: s.steamLoginSecure ? true : false,
|
|
||||||
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none',
|
|
||||||
lastBanCheck: new Date().toISOString()
|
|
||||||
});
|
|
||||||
hasChanges = true;
|
|
||||||
} else {
|
|
||||||
const sDate = s.sessionUpdatedAt ? new Date(s.sessionUpdatedAt) : new Date(0);
|
|
||||||
const lDate = exists.sessionUpdatedAt ? new Date(exists.sessionUpdatedAt) : new Date(0);
|
|
||||||
|
|
||||||
if (sDate > lDate) {
|
|
||||||
console.log(`[Sync] Updating session for ${exists.personaName} (Server is newer)`);
|
|
||||||
if (s.loginName) exists.loginName = s.loginName;
|
|
||||||
if (s.loginConfig) exists.loginConfig = s.loginConfig;
|
|
||||||
if (s.steamLoginSecure) {
|
|
||||||
exists.steamLoginSecure = s.steamLoginSecure;
|
|
||||||
exists.autoCheckCooldown = true;
|
|
||||||
exists.authError = false;
|
|
||||||
}
|
|
||||||
exists.sessionUpdatedAt = s.sessionUpdatedAt;
|
|
||||||
hasChanges = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.cooldownExpiresAt && (!exists.cooldownExpiresAt || new Date(s.cooldownExpiresAt) > new Date(exists.cooldownExpiresAt))) {
|
|
||||||
exists.cooldownExpiresAt = s.cooldownExpiresAt;
|
|
||||||
hasChanges = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[Sync] Pull failed');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BROADCAST PULL RESULTS IMMEDIATELY
|
|
||||||
if (hasChanges) {
|
|
||||||
store.set('accounts', accounts);
|
|
||||||
if (mainWindow) mainWindow.webContents.send('accounts-updated', accounts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accounts.length === 0) return;
|
|
||||||
|
|
||||||
// 2. BACKGROUND STEALTH CHECKS
|
|
||||||
console.log(`[Sync] Phase 2: Starting background checks for ${accounts.length} accounts...`);
|
|
||||||
const updatedAccounts = [...accounts];
|
|
||||||
let scrapeChanges = false;
|
|
||||||
|
|
||||||
for (const account of updatedAccounts) {
|
|
||||||
try {
|
|
||||||
const now = new Date();
|
|
||||||
|
|
||||||
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
|
|
||||||
const hoursSinceCheck = (now.getTime() - lastCheck.getTime()) / 3600000;
|
|
||||||
|
|
||||||
if (hoursSinceCheck > 6 || !account.personaName) {
|
|
||||||
const profile = await fetchProfileData(account.steamId, account.steamLoginSecure);
|
|
||||||
const bans = await scrapeBanStatus(profile.profileUrl, account.steamLoginSecure);
|
|
||||||
|
|
||||||
account.personaName = profile.personaName;
|
|
||||||
account.profileUrl = profile.profileUrl;
|
|
||||||
account.vacBanned = bans.vacBanned;
|
|
||||||
account.gameBans = bans.gameBans;
|
|
||||||
account.status = (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none';
|
|
||||||
account.lastBanCheck = now.toISOString();
|
|
||||||
|
|
||||||
if (profile.avatar && (!account.localAvatar || profile.avatar !== account.avatar)) {
|
|
||||||
account.avatar = profile.avatar;
|
|
||||||
const localPath = await downloadAvatar(account.steamId, profile.avatar);
|
|
||||||
if (localPath) account.localAvatar = localPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account.loginName) {
|
|
||||||
const config = steamClient.extractAccountConfig(account.loginName);
|
|
||||||
if (config) {
|
|
||||||
account.loginConfig = config;
|
|
||||||
account.sessionUpdatedAt = new Date().toISOString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backend) await backend.shareAccount(account);
|
|
||||||
scrapeChanges = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account.autoCheckCooldown && account.steamLoginSecure) {
|
|
||||||
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now) continue;
|
|
||||||
|
|
||||||
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
|
|
||||||
const hoursSinceScrape = (now.getTime() - lastScrape.getTime()) / 3600000;
|
|
||||||
|
|
||||||
if (hoursSinceScrape > 8) {
|
|
||||||
const jitter = Math.floor(Math.random() * 60000) + 5000;
|
|
||||||
await new Promise(r => setTimeout(r, jitter));
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await scrapeCooldown(account.steamId, account.steamLoginSecure);
|
|
||||||
account.authError = false;
|
|
||||||
account.lastScrapeTime = new Date().toISOString();
|
|
||||||
|
|
||||||
if (result.isActive) {
|
|
||||||
if (result.expiresAt) {
|
|
||||||
account.cooldownExpiresAt = result.expiresAt.toISOString();
|
|
||||||
} else if (!account.cooldownExpiresAt) {
|
|
||||||
const placeholder = new Date();
|
|
||||||
placeholder.setHours(placeholder.getHours() + 24);
|
|
||||||
account.cooldownExpiresAt = placeholder.toISOString();
|
|
||||||
}
|
|
||||||
if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
|
||||||
} else if (account.cooldownExpiresAt) {
|
|
||||||
account.cooldownExpiresAt = undefined;
|
|
||||||
if (backend) await backend.pushCooldown(account.steamId, undefined);
|
|
||||||
}
|
|
||||||
scrapeChanges = true;
|
|
||||||
} catch (e: any) {
|
|
||||||
if (e.message.includes('cookie') || e.message.includes('Sign In')) {
|
|
||||||
account.authError = true;
|
|
||||||
scrapeChanges = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scrapeChanges) {
|
|
||||||
store.set('accounts', updatedAccounts);
|
|
||||||
if (mainWindow) mainWindow.webContents.send('accounts-updated', updatedAccounts);
|
|
||||||
}
|
|
||||||
console.log('[Sync] Sync cycle finished.');
|
|
||||||
};
|
|
||||||
|
|
||||||
const scheduleNextSync = () => {
|
|
||||||
const delay = isDev ? 120000 : (Math.random() * 30 * 60000) + 30 * 60000;
|
|
||||||
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, delay);
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Steam Auto-Discovery ---
|
|
||||||
const addingAccounts = new Set<string>();
|
|
||||||
|
|
||||||
const handleLocalAccountsFound = async (localAccounts: LocalSteamAccount[]) => {
|
|
||||||
const currentAccounts = store.get('accounts') as Account[];
|
|
||||||
let hasChanges = false;
|
|
||||||
|
|
||||||
for (const local of localAccounts) {
|
|
||||||
if (addingAccounts.has(local.steamId)) continue;
|
|
||||||
const exists = currentAccounts.find(a => a.steamId === local.steamId);
|
|
||||||
if (exists) {
|
|
||||||
if (!exists.loginName && local.accountName) { exists.loginName = local.accountName; hasChanges = true; }
|
|
||||||
} else {
|
|
||||||
addingAccounts.add(local.steamId);
|
|
||||||
try {
|
|
||||||
const profile = await fetchProfileData(local.steamId);
|
|
||||||
const bans = await scrapeBanStatus(profile.profileUrl);
|
|
||||||
const localPath = await downloadAvatar(profile.steamId, profile.avatar);
|
|
||||||
currentAccounts.push({
|
|
||||||
_id: Date.now().toString() + Math.random().toString().slice(2, 5),
|
|
||||||
steamId: local.steamId,
|
|
||||||
personaName: profile.personaName || local.personaName || local.accountName,
|
|
||||||
loginName: local.accountName,
|
|
||||||
autoCheckCooldown: false,
|
|
||||||
avatar: profile.avatar,
|
|
||||||
localAvatar: localPath,
|
|
||||||
profileUrl: profile.profileUrl,
|
|
||||||
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none',
|
|
||||||
vacBanned: bans.vacBanned,
|
|
||||||
gameBans: bans.gameBans,
|
|
||||||
lastBanCheck: new Date().toISOString()
|
|
||||||
});
|
|
||||||
hasChanges = true;
|
|
||||||
} catch (e) { }
|
|
||||||
addingAccounts.delete(local.steamId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasChanges) {
|
|
||||||
store.set('accounts', currentAccounts);
|
|
||||||
if (mainWindow) mainWindow.webContents.send('accounts-updated', currentAccounts);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
|
||||||
protocol.handle('steam-resource', (request) => {
|
|
||||||
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
|
|
||||||
if (process.platform !== 'win32' && !rawPath.startsWith('/')) rawPath = '/' + rawPath;
|
|
||||||
const absolutePath = path.isAbsolute(rawPath) ? rawPath : path.resolve(rawPath);
|
|
||||||
if (!fs.existsSync(absolutePath)) return new Response('Not Found', { status: 404 });
|
|
||||||
try { return net.fetch(pathToFileURL(absolutePath).toString()); } catch (e) { return new Response('Error', { status: 500 }); }
|
|
||||||
});
|
|
||||||
|
|
||||||
createWindow();
|
|
||||||
initBackend();
|
|
||||||
setTimeout(syncAccounts, 5000);
|
|
||||||
scheduleNextSync();
|
|
||||||
steamClient.startWatching(handleLocalAccountsFound);
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- IPC Handlers ---
|
|
||||||
console.log('[Main] Registering IPC Handlers...');
|
|
||||||
|
|
||||||
ipcMain.handle('get-accounts', () => store.get('accounts'));
|
|
||||||
ipcMain.handle('get-server-config', () => store.get('serverConfig'));
|
|
||||||
|
|
||||||
ipcMain.handle('update-server-config', (event, config: Partial<ServerConfig>) => {
|
|
||||||
const current = store.get('serverConfig');
|
|
||||||
const updated = { ...current, ...config };
|
|
||||||
store.set('serverConfig', updated);
|
|
||||||
initBackend();
|
|
||||||
return updated;
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('login-to-server', async () => {
|
|
||||||
initBackend();
|
|
||||||
const config = store.get('serverConfig') as ServerConfig;
|
|
||||||
if (!config.url) return false;
|
|
||||||
|
|
||||||
return new Promise<boolean>((resolve) => {
|
|
||||||
const authWindow = new BrowserWindow({
|
|
||||||
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Ban Tracker Server',
|
|
||||||
webPreferences: { nodeIntegration: false, contextIsolation: true }
|
|
||||||
});
|
|
||||||
authWindow.loadURL(`${config.url}/auth/steam`);
|
|
||||||
|
|
||||||
let captured = false;
|
|
||||||
const saveServerAuth = (token: string) => {
|
|
||||||
if (captured) return;
|
|
||||||
captured = true;
|
|
||||||
console.log('[ServerAuth] Securely captured token');
|
|
||||||
let serverSteamId = undefined;
|
|
||||||
try {
|
|
||||||
const payload = JSON.parse(Buffer.from(token.split('.')[1]!, 'base64').toString());
|
|
||||||
serverSteamId = payload.steamId;
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
const current = store.get('serverConfig');
|
|
||||||
store.set('serverConfig', { ...current, token, serverSteamId, enabled: true });
|
|
||||||
initBackend();
|
|
||||||
authWindow.close();
|
|
||||||
resolve(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
// METHOD 1: Sniff HTTP Headers
|
|
||||||
const filter = { urls: [`${config.url}/*`] };
|
|
||||||
authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
|
|
||||||
const headers = details.responseHeaders || {};
|
|
||||||
const authToken = headers['x-ubt-auth-token']?.[0] || headers['X-UBT-Auth-Token']?.[0];
|
|
||||||
if (authToken) saveServerAuth(authToken);
|
|
||||||
callback({ cancel: false });
|
|
||||||
});
|
|
||||||
|
|
||||||
// METHOD 2: Watch Window Title (Fallback)
|
|
||||||
authWindow.on('page-title-updated', (event, title) => {
|
|
||||||
if (title.includes('AUTH_TOKEN:')) {
|
|
||||||
const token = title.split('AUTH_TOKEN:')[1];
|
|
||||||
if (token) saveServerAuth(token);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
authWindow.on('closed', () => { resolve(false); });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
|
|
||||||
|
|
||||||
ipcMain.handle('sync-now', async () => { await syncAccounts(); return true; });
|
|
||||||
|
|
||||||
ipcMain.handle('add-account', async (event, { identifier }) => {
|
|
||||||
try {
|
try {
|
||||||
initBackend();
|
const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
||||||
// OPTIMIZATION: Check community server first
|
tray = new Tray(icon);
|
||||||
if (backend) {
|
tray.setToolTip('Ultimate Ban Tracker');
|
||||||
const shared = await backend.getCommunityAccounts();
|
tray.on('click', () => {
|
||||||
const existing = shared.find((s: any) => s.steamId === identifier || s.profileUrl.includes(identifier));
|
if (mainWindow) {
|
||||||
if (existing) {
|
mainWindow.show();
|
||||||
const accounts = store.get('accounts') as Account[];
|
mainWindow.focus();
|
||||||
if (accounts.find(a => a.steamId === existing.steamId)) throw new Error('Account already tracked');
|
|
||||||
|
|
||||||
const newAccount: Account = {
|
|
||||||
_id: `shared_${existing.steamId}`,
|
|
||||||
steamId: existing.steamId,
|
|
||||||
personaName: existing.personaName,
|
|
||||||
avatar: existing.avatar,
|
|
||||||
profileUrl: existing.profileUrl,
|
|
||||||
vacBanned: existing.vacBanned,
|
|
||||||
gameBans: existing.gameBans,
|
|
||||||
cooldownExpiresAt: existing.cooldownExpiresAt,
|
|
||||||
loginName: existing.loginName || '',
|
|
||||||
steamLoginSecure: existing.steamLoginSecure,
|
|
||||||
loginConfig: existing.loginConfig,
|
|
||||||
sessionUpdatedAt: existing.sessionUpdatedAt,
|
|
||||||
autoCheckCooldown: existing.steamLoginSecure ? true : false,
|
|
||||||
status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
|
|
||||||
lastBanCheck: new Date().toISOString()
|
|
||||||
};
|
|
||||||
store.set('accounts', [...accounts, newAccount]);
|
|
||||||
return newAccount;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
updateTrayMenu();
|
||||||
const profile = await fetchProfileData(identifier);
|
console.log(`[Tray] Successfully initialized`);
|
||||||
const bans = await scrapeBanStatus(profile.profileUrl);
|
} catch (e: any) {
|
||||||
const localAvatar = await downloadAvatar(profile.steamId, profile.avatar);
|
console.error(`[Tray] Critical error during initialization: ${e.message}`);
|
||||||
const accounts = store.get('accounts') as Account[];
|
|
||||||
const newAccount: Account = {
|
|
||||||
_id: Date.now().toString(),
|
|
||||||
steamId: profile.steamId, personaName: profile.personaName, loginName: '',
|
|
||||||
avatar: profile.avatar, localAvatar: localAvatar, profileUrl: profile.profileUrl,
|
|
||||||
autoCheckCooldown: false, vacBanned: bans.vacBanned, gameBans: bans.gameBans,
|
|
||||||
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
|
||||||
};
|
|
||||||
store.set('accounts', [...accounts, newAccount]);
|
|
||||||
return newAccount;
|
|
||||||
} catch (error: any) { throw error; }
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('update-account', (event, id: string, data: Partial<Account>) => {
|
|
||||||
const accounts = store.get('accounts') as Account[];
|
|
||||||
const index = accounts.findIndex((a: Account) => a._id === id);
|
|
||||||
if (index !== -1) { accounts[index] = { ...accounts[index], ...data } as Account; store.set('accounts', accounts); return accounts[index]; }
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('delete-account', (event, id: string) => {
|
|
||||||
const accounts = store.get('accounts') as Account[];
|
|
||||||
store.set('accounts', accounts.filter((a: Account) => a._id !== id));
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('share-account-with-user', async (event, steamId: string, targetSteamId: string) => {
|
|
||||||
initBackend();
|
|
||||||
if (backend) {
|
|
||||||
const accounts = store.get('accounts') as Account[];
|
|
||||||
const account = accounts.find(a => a.steamId === steamId);
|
|
||||||
if (account) await backend.shareAccount(account);
|
|
||||||
return await backend.shareWithUser(steamId, targetSteamId);
|
|
||||||
}
|
}
|
||||||
throw new Error('Backend not configured');
|
};
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
|
const updateTrayMenu = () => {
|
||||||
ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
|
if (!tray) return;
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
const config = store.get('serverConfig');
|
||||||
|
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{ label: `Ultimate Ban Tracker v${app.getVersion()}`, enabled: false },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Switch Account',
|
||||||
|
submenu: accounts.length > 0 ? accounts.map(acc => ({
|
||||||
|
label: `${acc.personaName} ${acc.loginName ? `(${acc.loginName})` : ''}`,
|
||||||
|
enabled: !!acc.loginName,
|
||||||
|
click: () => handleSwitchAccount(acc.loginName)
|
||||||
|
})) : [{ label: 'No accounts found', enabled: false }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Sync Now',
|
||||||
|
enabled: !!config?.enabled,
|
||||||
|
click: () => syncAccounts()
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{ label: 'Show Dashboard', click: () => { if (mainWindow) mainWindow.show(); } },
|
||||||
|
{ label: 'Quit', click: () => { (app as any).isQuitting = true; app.quit(); } }
|
||||||
|
]);
|
||||||
|
|
||||||
|
tray.setContextMenu(contextMenu);
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Steam Logic ---
|
||||||
const killSteam = async () => {
|
const killSteam = async () => {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
const command = process.platform === 'win32' ? 'taskkill /f /im steam.exe' : 'pkill -9 steam';
|
const command = process.platform === 'win32' ? 'taskkill /f /im steam.exe' : 'pkill -9 steam';
|
||||||
@@ -495,7 +169,7 @@ const startSteam = () => {
|
|||||||
exec(command);
|
exec(command);
|
||||||
};
|
};
|
||||||
|
|
||||||
ipcMain.handle('switch-account', async (event, loginName: string) => {
|
const handleSwitchAccount = async (loginName: string) => {
|
||||||
if (!loginName) return false;
|
if (!loginName) return false;
|
||||||
try {
|
try {
|
||||||
await killSteam();
|
await killSteam();
|
||||||
@@ -512,30 +186,322 @@ ipcMain.handle('switch-account', async (event, loginName: string) => {
|
|||||||
startSteam();
|
startSteam();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) { return false; }
|
} catch (e) { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Sync Worker ---
|
||||||
|
const syncAccounts = async () => {
|
||||||
|
initBackend();
|
||||||
|
let accounts = store.get('accounts') as Account[];
|
||||||
|
let hasChanges = false;
|
||||||
|
|
||||||
|
if (backend) {
|
||||||
|
try {
|
||||||
|
const shared = await backend.getSharedAccounts();
|
||||||
|
for (const s of shared) {
|
||||||
|
const exists = accounts.find(a => a.steamId === s.steamId);
|
||||||
|
if (!exists) {
|
||||||
|
accounts.push({
|
||||||
|
_id: `shared_${s.steamId}`,
|
||||||
|
steamId: s.steamId, personaName: s.personaName, avatar: s.avatar, profileUrl: s.profileUrl,
|
||||||
|
vacBanned: s.vacBanned, gameBans: s.gameBans, cooldownExpiresAt: s.cooldownExpiresAt,
|
||||||
|
loginName: s.loginName || '', steamLoginSecure: s.steamLoginSecure, loginConfig: s.loginConfig,
|
||||||
|
sessionUpdatedAt: s.sessionUpdatedAt, autoCheckCooldown: !!s.steamLoginSecure,
|
||||||
|
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
||||||
|
});
|
||||||
|
hasChanges = true;
|
||||||
|
} else {
|
||||||
|
const sDate = s.sessionUpdatedAt ? new Date(s.sessionUpdatedAt) : new Date(0);
|
||||||
|
const lDate = exists.sessionUpdatedAt ? new Date(exists.sessionUpdatedAt) : new Date(0);
|
||||||
|
if (sDate > lDate) {
|
||||||
|
if (s.loginName) exists.loginName = s.loginName;
|
||||||
|
if (s.loginConfig) exists.loginConfig = s.loginConfig;
|
||||||
|
if (s.steamLoginSecure) { exists.steamLoginSecure = s.steamLoginSecure; exists.autoCheckCooldown = true; exists.authError = false; }
|
||||||
|
exists.sessionUpdatedAt = s.sessionUpdatedAt;
|
||||||
|
hasChanges = true;
|
||||||
|
}
|
||||||
|
if (s.cooldownExpiresAt && (!exists.cooldownExpiresAt || new Date(s.cooldownExpiresAt) > new Date(exists.cooldownExpiresAt))) {
|
||||||
|
exists.cooldownExpiresAt = s.cooldownExpiresAt;
|
||||||
|
hasChanges = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
store.set('accounts', accounts);
|
||||||
|
if (mainWindow) mainWindow.webContents.send('accounts-updated', accounts);
|
||||||
|
updateTrayMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accounts.length === 0) return;
|
||||||
|
|
||||||
|
const updatedAccounts = [...accounts];
|
||||||
|
let scrapeChanges = false;
|
||||||
|
|
||||||
|
for (const account of updatedAccounts) {
|
||||||
|
try {
|
||||||
|
const now = new Date();
|
||||||
|
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
|
||||||
|
if ((now.getTime() - lastCheck.getTime()) / 3600000 > 6 || !account.personaName) {
|
||||||
|
const profile = await fetchProfileData(account.steamId, account.steamLoginSecure);
|
||||||
|
const bans = await scrapeBanStatus(profile.profileUrl, account.steamLoginSecure);
|
||||||
|
account.personaName = profile.personaName; account.profileUrl = profile.profileUrl;
|
||||||
|
account.vacBanned = bans.vacBanned; account.gameBans = bans.gameBans;
|
||||||
|
account.status = (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none';
|
||||||
|
account.lastBanCheck = now.toISOString();
|
||||||
|
if (profile.avatar && (!account.localAvatar || profile.avatar !== account.avatar)) {
|
||||||
|
account.avatar = profile.avatar;
|
||||||
|
const localPath = await downloadAvatar(account.steamId, profile.avatar);
|
||||||
|
if (localPath) account.localAvatar = localPath;
|
||||||
|
}
|
||||||
|
if (account.loginName) {
|
||||||
|
const config = steamClient.extractAccountConfig(account.loginName);
|
||||||
|
if (config) { account.loginConfig = config; account.sessionUpdatedAt = new Date().toISOString(); }
|
||||||
|
}
|
||||||
|
if (backend) await backend.shareAccount(account);
|
||||||
|
scrapeChanges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.autoCheckCooldown && account.steamLoginSecure) {
|
||||||
|
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now) continue;
|
||||||
|
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
|
||||||
|
if ((now.getTime() - lastScrape.getTime()) / 3600000 > 8) {
|
||||||
|
await new Promise(r => setTimeout(r, Math.floor(Math.random() * 60000) + 5000));
|
||||||
|
try {
|
||||||
|
const result = await scrapeCooldown(account.steamId, account.steamLoginSecure);
|
||||||
|
account.authError = false; account.lastScrapeTime = new Date().toISOString();
|
||||||
|
if (result.isActive) {
|
||||||
|
account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString();
|
||||||
|
if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
||||||
|
} else if (account.cooldownExpiresAt) {
|
||||||
|
account.cooldownExpiresAt = undefined;
|
||||||
|
if (backend) await backend.pushCooldown(account.steamId, undefined);
|
||||||
|
}
|
||||||
|
scrapeChanges = true;
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e.message.includes('cookie') || e.message.includes('Sign In')) { account.authError = true; scrapeChanges = true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrapeChanges) {
|
||||||
|
store.set('accounts', updatedAccounts);
|
||||||
|
if (mainWindow) mainWindow.webContents.send('accounts-updated', updatedAccounts);
|
||||||
|
updateTrayMenu();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduleNextSync = () => {
|
||||||
|
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, isDev ? 120000 : 1800000);
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Discovery ---
|
||||||
|
const addingAccounts = new Set<string>();
|
||||||
|
const handleLocalAccountsFound = async (localAccounts: LocalSteamAccount[]) => {
|
||||||
|
const currentAccounts = store.get('accounts') as Account[];
|
||||||
|
let hasChanges = false;
|
||||||
|
for (const local of localAccounts) {
|
||||||
|
if (addingAccounts.has(local.steamId)) continue;
|
||||||
|
const exists = currentAccounts.find(a => a.steamId === local.steamId);
|
||||||
|
if (exists) {
|
||||||
|
if (!exists.loginName && local.accountName) { exists.loginName = local.accountName; hasChanges = true; }
|
||||||
|
} else {
|
||||||
|
addingAccounts.add(local.steamId);
|
||||||
|
try {
|
||||||
|
const profile = await fetchProfileData(local.steamId);
|
||||||
|
const bans = await scrapeBanStatus(profile.profileUrl);
|
||||||
|
const localPath = await downloadAvatar(profile.steamId, profile.avatar);
|
||||||
|
currentAccounts.push({
|
||||||
|
_id: Date.now().toString() + Math.random().toString().slice(2, 5),
|
||||||
|
steamId: local.steamId, personaName: profile.personaName || local.accountName,
|
||||||
|
loginName: local.accountName, autoCheckCooldown: false, avatar: profile.avatar,
|
||||||
|
localAvatar: localPath, profileUrl: profile.profileUrl,
|
||||||
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none',
|
||||||
|
vacBanned: bans.vacBanned, gameBans: bans.gameBans, lastBanCheck: new Date().toISOString()
|
||||||
|
});
|
||||||
|
hasChanges = true;
|
||||||
|
} catch (e) { }
|
||||||
|
addingAccounts.delete(local.steamId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasChanges) {
|
||||||
|
store.set('accounts', currentAccounts);
|
||||||
|
if (mainWindow) mainWindow.webContents.send('accounts-updated', currentAccounts);
|
||||||
|
updateTrayMenu();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Main Window Creation ---
|
||||||
|
function createWindow() {
|
||||||
|
mainWindow = new BrowserWindow({
|
||||||
|
width: 1280, height: 800, title: "Ultimate Ban Tracker", backgroundColor: '#171a21', autoHideMenuBar: true,
|
||||||
|
webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
mainWindow.setMenu(null);
|
||||||
|
|
||||||
|
mainWindow.on('close', (event) => {
|
||||||
|
if (!(app as any).isQuitting) {
|
||||||
|
event.preventDefault();
|
||||||
|
mainWindow?.hide();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isDev) mainWindow.loadURL('http://localhost:5173');
|
||||||
|
else mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- App Lifecycle ---
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
protocol.handle('steam-resource', (request) => {
|
||||||
|
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
|
||||||
|
if (process.platform !== 'win32' && !rawPath.startsWith('/')) rawPath = '/' + rawPath;
|
||||||
|
const absolutePath = path.isAbsolute(rawPath) ? rawPath : path.resolve(rawPath);
|
||||||
|
if (!fs.existsSync(absolutePath)) return new Response('Not Found', { status: 404 });
|
||||||
|
try { return net.fetch(pathToFileURL(absolutePath).toString()); } catch (e) { return new Response('Error', { status: 500 }); }
|
||||||
|
});
|
||||||
|
|
||||||
|
createWindow();
|
||||||
|
createTray();
|
||||||
|
initBackend();
|
||||||
|
setTimeout(syncAccounts, 5000);
|
||||||
|
scheduleNextSync();
|
||||||
|
steamClient.startWatching(handleLocalAccountsFound);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on('window-all-closed', () => { if (process.platform !== 'darwin' && (app as any).isQuitting) app.quit(); });
|
||||||
|
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); else mainWindow?.show(); });
|
||||||
|
|
||||||
|
// --- IPC Handlers ---
|
||||||
|
ipcMain.handle('get-accounts', () => store.get('accounts'));
|
||||||
|
ipcMain.handle('get-server-config', () => store.get('serverConfig'));
|
||||||
|
ipcMain.handle('update-server-config', (event, config: Partial<ServerConfig>) => {
|
||||||
|
const current = store.get('serverConfig');
|
||||||
|
const updated = { ...current, ...config };
|
||||||
|
store.set('serverConfig', updated);
|
||||||
|
initBackend();
|
||||||
|
return updated;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('login-to-server', async () => {
|
||||||
|
initBackend();
|
||||||
|
const config = store.get('serverConfig') as ServerConfig;
|
||||||
|
if (!config.url) return false;
|
||||||
|
return new Promise<boolean>((resolve) => {
|
||||||
|
const authWindow = new BrowserWindow({
|
||||||
|
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Ban Tracker Server',
|
||||||
|
webPreferences: { nodeIntegration: false, contextIsolation: true }
|
||||||
|
});
|
||||||
|
authWindow.loadURL(`${config.url}/auth/steam`);
|
||||||
|
let captured = false;
|
||||||
|
const saveServerAuth = (token: string) => {
|
||||||
|
if (captured) return; captured = true;
|
||||||
|
let serverSteamId = undefined;
|
||||||
|
try { const payload = JSON.parse(Buffer.from(token.split('.')[1]!, 'base64').toString()); serverSteamId = payload.steamId; } catch (e) {}
|
||||||
|
const current = store.get('serverConfig');
|
||||||
|
store.set('serverConfig', { ...current, token, serverSteamId, enabled: true });
|
||||||
|
initBackend();
|
||||||
|
authWindow.close();
|
||||||
|
resolve(true);
|
||||||
|
};
|
||||||
|
const filter = { urls: [`${config.url}/*`] };
|
||||||
|
authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
|
||||||
|
const headers = details.responseHeaders || {};
|
||||||
|
const authToken = headers['x-ubt-auth-token']?.[0] || headers['X-UBT-Auth-Token']?.[0];
|
||||||
|
if (authToken) saveServerAuth(authToken);
|
||||||
|
callback({ cancel: false });
|
||||||
|
});
|
||||||
|
authWindow.on('page-title-updated', (event, title) => {
|
||||||
|
if (title.includes('AUTH_TOKEN:')) { const token = title.split('AUTH_TOKEN:')[1]; if (token) saveServerAuth(token); }
|
||||||
|
});
|
||||||
|
authWindow.on('closed', () => resolve(false));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
|
||||||
|
ipcMain.handle('sync-now', async () => { await syncAccounts(); return true; });
|
||||||
|
ipcMain.handle('add-account', async (event, { identifier }) => {
|
||||||
|
try {
|
||||||
|
initBackend();
|
||||||
|
if (backend) {
|
||||||
|
const shared = await backend.getCommunityAccounts();
|
||||||
|
const existing = shared.find((s: any) => s.steamId === identifier || s.profileUrl.includes(identifier));
|
||||||
|
if (existing) {
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
if (accounts.find(a => a.steamId === existing.steamId)) throw new Error('Account already tracked');
|
||||||
|
const newAccount: Account = {
|
||||||
|
_id: `shared_${existing.steamId}`, steamId: existing.steamId, personaName: existing.personaName,
|
||||||
|
avatar: existing.avatar, profileUrl: existing.profileUrl, vacBanned: existing.vacBanned,
|
||||||
|
gameBans: existing.gameBans, cooldownExpiresAt: existing.cooldownExpiresAt,
|
||||||
|
loginName: existing.loginName || '', steamLoginSecure: existing.steamLoginSecure,
|
||||||
|
loginConfig: existing.loginConfig, sessionUpdatedAt: existing.sessionUpdatedAt,
|
||||||
|
autoCheckCooldown: !!existing.steamLoginSecure, status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
|
||||||
|
lastBanCheck: new Date().toISOString()
|
||||||
|
};
|
||||||
|
store.set('accounts', [...accounts, newAccount]);
|
||||||
|
updateTrayMenu();
|
||||||
|
return newAccount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const profile = await fetchProfileData(identifier);
|
||||||
|
const bans = await scrapeBanStatus(profile.profileUrl);
|
||||||
|
const localAvatar = await downloadAvatar(profile.steamId, profile.avatar);
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
const newAccount: Account = {
|
||||||
|
_id: Date.now().toString(), steamId: profile.steamId, personaName: profile.personaName,
|
||||||
|
loginName: '', avatar: profile.avatar, localAvatar: localAvatar, profileUrl: profile.profileUrl,
|
||||||
|
autoCheckCooldown: false, vacBanned: bans.vacBanned, gameBans: bans.gameBans,
|
||||||
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
||||||
|
};
|
||||||
|
store.set('accounts', [...accounts, newAccount]);
|
||||||
|
updateTrayMenu();
|
||||||
|
return newAccount;
|
||||||
|
} catch (error: any) { throw error; }
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('update-account', (event, id: string, data: Partial<Account>) => {
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
const index = accounts.findIndex((a: Account) => a._id === id);
|
||||||
|
if (index !== -1) { accounts[index] = { ...accounts[index], ...data } as Account; store.set('accounts', accounts); updateTrayMenu(); return accounts[index]; }
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('delete-account', (event, id: string) => {
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
store.set('accounts', accounts.filter((a: Account) => a._id !== id));
|
||||||
|
updateTrayMenu();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('share-account-with-user', async (event, steamId: string, targetSteamId: string) => {
|
||||||
|
initBackend();
|
||||||
|
if (backend) {
|
||||||
|
const accounts = store.get('accounts') as Account[];
|
||||||
|
const account = accounts.find(a => a.steamId === steamId);
|
||||||
|
if (account) await backend.shareAccount(account);
|
||||||
|
return await backend.shareWithUser(steamId, targetSteamId);
|
||||||
|
}
|
||||||
|
throw new Error('Backend not configured');
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
|
||||||
|
ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
|
||||||
|
ipcMain.handle('switch-account', async (event, loginName: string) => await handleSwitchAccount(loginName));
|
||||||
ipcMain.handle('open-external', (event, url: string) => shell.openExternal(url));
|
ipcMain.handle('open-external', (event, url: string) => shell.openExternal(url));
|
||||||
|
|
||||||
ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => {
|
ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => {
|
||||||
const loginSession = session.fromPartition('persist:steam-login');
|
const loginSession = session.fromPartition('persist:steam-login');
|
||||||
await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
|
await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
|
||||||
|
|
||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
const loginWindow = new BrowserWindow({
|
const loginWindow = new BrowserWindow({
|
||||||
width: 800,
|
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Steam',
|
||||||
height: 700,
|
webPreferences: { nodeIntegration: false, contextIsolation: true, partition: 'persist:steam-login' }
|
||||||
parent: mainWindow || undefined,
|
|
||||||
modal: true,
|
|
||||||
title: 'Login to Steam (Ensure "Remember Me" is checked!)',
|
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
partition: 'persist:steam-login'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loginWindow.loadURL('https://steamcommunity.com/login/home/?goto=my/gcpd/730');
|
loginWindow.loadURL('https://steamcommunity.com/login/home/?goto=my/gcpd/730');
|
||||||
|
|
||||||
const checkCookie = setInterval(async () => {
|
const checkCookie = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const cookies = await loginSession.cookies.get({ domain: 'steamcommunity.com' });
|
const cookies = await loginSession.cookies.get({ domain: 'steamcommunity.com' });
|
||||||
@@ -543,45 +509,29 @@ ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => {
|
|||||||
if (secureCookie) {
|
if (secureCookie) {
|
||||||
const steamId = decodeURIComponent(secureCookie.value).split('|')[0];
|
const steamId = decodeURIComponent(secureCookie.value).split('|')[0];
|
||||||
if (steamId) {
|
if (steamId) {
|
||||||
if (expectedSteamId && steamId !== expectedSteamId) {
|
if (expectedSteamId && steamId !== expectedSteamId) return;
|
||||||
console.error(`[Auth] ID Mismatch! Expected ${expectedSteamId}, got ${steamId}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearInterval(checkCookie);
|
clearInterval(checkCookie);
|
||||||
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
||||||
console.log(`[Auth] Captured session for SteamID: ${steamId}`);
|
|
||||||
const accounts = store.get('accounts') as Account[];
|
const accounts = store.get('accounts') as Account[];
|
||||||
const accountIndex = accounts.findIndex(a => a.steamId === steamId);
|
const accountIndex = accounts.findIndex(a => a.steamId === steamId);
|
||||||
if (accountIndex !== -1) {
|
if (accountIndex !== -1) {
|
||||||
const account = accounts[accountIndex]!;
|
const account = accounts[accountIndex]!;
|
||||||
account.steamLoginSecure = cookieString;
|
account.steamLoginSecure = cookieString; account.autoCheckCooldown = true; account.authError = false;
|
||||||
account.autoCheckCooldown = true;
|
|
||||||
account.authError = false;
|
|
||||||
account.sessionUpdatedAt = new Date().toISOString();
|
account.sessionUpdatedAt = new Date().toISOString();
|
||||||
|
|
||||||
if (account.loginName) {
|
if (account.loginName) {
|
||||||
const config = steamClient.extractAccountConfig(account.loginName);
|
const config = steamClient.extractAccountConfig(account.loginName);
|
||||||
if (config) account.loginConfig = config;
|
if (config) account.loginConfig = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`[Auth] Performing initial scrape for ${account.personaName}...`);
|
|
||||||
const result = await scrapeCooldown(account.steamId, cookieString);
|
const result = await scrapeCooldown(account.steamId, cookieString);
|
||||||
account.lastScrapeTime = new Date().toISOString();
|
account.lastScrapeTime = new Date().toISOString();
|
||||||
if (result.isActive && result.expiresAt) {
|
account.cooldownExpiresAt = result.isActive && result.expiresAt ? result.expiresAt.toISOString() : undefined;
|
||||||
account.cooldownExpiresAt = result.expiresAt.toISOString();
|
} catch (e) { }
|
||||||
} else if (!result.isActive) {
|
|
||||||
account.cooldownExpiresAt = undefined;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[Auth] Initial scrape failed:', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
initBackend();
|
initBackend();
|
||||||
if (backend) await backend.shareAccount(account);
|
if (backend) await backend.shareAccount(account);
|
||||||
|
|
||||||
store.set('accounts', accounts);
|
store.set('accounts', accounts);
|
||||||
if (mainWindow) mainWindow.webContents.send('accounts-updated', accounts);
|
if (mainWindow) mainWindow.webContents.send('accounts-updated', accounts);
|
||||||
|
updateTrayMenu();
|
||||||
loginWindow.close();
|
loginWindow.close();
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
@@ -589,12 +539,6 @@ ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => {
|
|||||||
}
|
}
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
loginWindow.on('closed', () => { clearInterval(checkCookie); resolve(false); });
|
||||||
loginWindow.on('closed', () => {
|
|
||||||
clearInterval(checkCookie);
|
|
||||||
resolve(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });
|
|
||||||
|
|||||||
Reference in New Issue
Block a user