Skip to content

Commit 4e6f2dc

Browse files
committed
remove autorefresh; improve logs
1 parent 9bb66bc commit 4e6f2dc

File tree

5 files changed

+6
-277
lines changed

5 files changed

+6
-277
lines changed

commands/admin/autorefresh.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

libs/save.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function initGame(gameName) {
2727
gameState.population = {};
2828
gameState.graveyard = {};
2929
gameState.children = {};
30-
gameState.autoRefresh = true; // Default to auto-refresh enabled
3130
messages = {};
3231
for (locationName in locations) {
3332
gameState.gameTrack[locationName] = 1;

tests/tribes-interface.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ class TribesClient {
240240
this.refreshTimer = null;
241241
this.currentVersion = document.querySelector('meta[name="interface-version"]')?.content || 'unknown';
242242
this.lastRefreshTime = 0;
243-
this.autoRefresh = true;
244243
this.isLoggedIn = false;
245244
this.currentSessionToken = null;
246245
this.currentPlayerName = null;

tribes-interface.html

Lines changed: 6 additions & 228 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,17 +1079,11 @@ <h3 id="selectedCommandName">Game Messages</h3>
10791079
this.reconnectAttempts = 0;
10801080
this.maxReconnectAttempts = 5;
10811081
this.reconnectInterval = 2000;
1082-
this.refreshTimer = null; // Timer for automatic refresh every 30 seconds
1083-
this.versionCheckTimer = null; // Timer for version checking
1084-
this.currentVersion = document.querySelector('meta[name="interface-version"]')?.content || 'unknown';
1085-
this.lastRefreshTime = 0; // Track when last refresh occurred
1086-
this.autoRefresh = true; // Default to true, will be overridden by server
10871082
this.isLoggedIn = false; // Track login state
10881083

10891084
this.loadSavedSettings();
10901085
this.initializeEventListeners();
10911086
this.hideCommandsSection(); // Initially hide commands until login
1092-
this.startVersionChecking();
10931087
this.connect();
10941088
}
10951089

@@ -1285,8 +1279,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
12851279
this.reconnectAttempts = 0;
12861280
this.requestCommandList();
12871281
this.requestSettings();
1288-
// Auto-refresh game data on connection
1289-
this.refreshGameData();
12901282
};
12911283

12921284
this.ws.onmessage = (event) => {
@@ -1300,10 +1292,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
13001292
this.ws.onclose = () => {
13011293
logWithTimestamp('WebSocket closed');
13021294
this.updateConnectionStatus('disconnected');
1303-
if (this.refreshTimer) {
1304-
clearTimeout(this.refreshTimer);
1305-
this.refreshTimer = null;
1306-
}
13071295
if (onCloseCallback) onCloseCallback();
13081296
};
13091297
}
@@ -1362,10 +1350,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
13621350
this.ws.onclose = () => {
13631351
logWithTimestamp('WebSocket closed');
13641352
this.updateConnectionStatus('disconnected');
1365-
if (this.refreshTimer) {
1366-
clearTimeout(this.refreshTimer);
1367-
this.refreshTimer = null;
1368-
}
13691353
if (successCallback) successCallback();
13701354
};
13711355
};
@@ -1532,7 +1516,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
15321516
this.minimizeLoginArea();
15331517
this.addMessage(`Welcome back, ${data.playerName}!`, 'success');
15341518
this.requestCommandList();
1535-
this.refreshGameData();
15361519
} else {
15371520
// Session invalid, clear it and show login
15381521
this.clearSession();
@@ -1566,38 +1549,23 @@ <h3 id="selectedCommandName">Game Messages</h3>
15661549
}
15671550

15681551
handleInfoResponse(data) {
1569-
// Check if this is an automatic refresh from the server
1570-
const isAutoRefresh = data.autoRefresh === true;
1571-
15721552
switch (data.label) {
15731553
case 'population':
15741554
this.currentPopulation = data.content;
15751555
this.updatePopulationTable(data.content);
15761556
// Update command list when population data changes (for chief status)
15771557
this.updateCommandList();
1578-
if (isAutoRefresh) {
1579-
this.showAutoRefreshIndicator('Population updated');
1580-
}
15811558
break;
15821559
case 'children':
15831560
this.currentChildren = data.content; // Store for targeting dropdowns
15841561
this.updateChildrenTable(data.content);
1585-
if (isAutoRefresh) {
1586-
this.showAutoRefreshIndicator('Children data updated');
1587-
}
15881562
break;
15891563
case 'status':
15901564
this.updateStatusText(data.content);
1591-
if (isAutoRefresh) {
1592-
this.showAutoRefreshIndicator('Game status updated');
1593-
}
15941565
break;
15951566
case 'romance':
15961567
this.currentRomanceLists = data.content;
15971568
this.displayCurrentRomanceLists(data.content);
1598-
if (isAutoRefresh) {
1599-
this.showAutoRefreshIndicator('Romance lists updated');
1600-
}
16011569
break;
16021570
case 'error':
16031571
this.addMessage(data.content, 'error');
@@ -1658,7 +1626,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
16581626

16591627
this.isLoggedIn = true; // Set logged in state
16601628
this.showCommandsSection(); // Show commands after successful login
1661-
this.refreshGameData();
16621629
this.requestCommandList(); // Refresh command list in case chief status changed
16631630
this.minimizeLoginArea(); // Minimize login area after successful registration
16641631
}
@@ -3166,49 +3133,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
31663133
}
31673134
}
31683135

3169-
showAutoRefreshIndicator(text) {
3170-
// Create a subtle visual indicator for automatic refreshes
3171-
const indicator = document.createElement('div');
3172-
indicator.className = 'auto-refresh-indicator';
3173-
indicator.textContent = `🔄 ${text}`;
3174-
indicator.style.cssText = `
3175-
position: fixed;
3176-
top: 80px;
3177-
right: 20px;
3178-
background: rgba(40, 167, 69, 0.9);
3179-
color: white;
3180-
padding: 8px 12px;
3181-
border-radius: 4px;
3182-
font-size: 0.9rem;
3183-
z-index: 1001;
3184-
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
3185-
animation: fadeInOut 2s ease-in-out;
3186-
`;
3187-
3188-
// Add CSS animation if not already exists
3189-
if (!document.getElementById('autoRefreshStyle')) {
3190-
const style = document.createElement('style');
3191-
style.id = 'autoRefreshStyle';
3192-
style.textContent = `
3193-
@keyframes fadeInOut {
3194-
0% { opacity: 0; transform: translateY(-10px); }
3195-
20%, 80% { opacity: 1; transform: translateY(0); }
3196-
100% { opacity: 0; transform: translateY(-10px); }
3197-
}
3198-
`;
3199-
document.head.appendChild(style);
3200-
}
3201-
3202-
document.body.appendChild(indicator);
3203-
3204-
// Remove after animation completes
3205-
setTimeout(() => {
3206-
if (indicator.parentNode) {
3207-
indicator.parentNode.removeChild(indicator);
3208-
}
3209-
}, 2000);
3210-
}
3211-
32123136
getMessageHistoryKey() {
32133137
const tribe = document.getElementById('tribeSelect').value || 'default';
32143138
const player = document.getElementById('playerName').value || 'anonymous';
@@ -3313,20 +3237,8 @@ <h3 id="selectedCommandName">Game Messages</h3>
33133237
}
33143238

33153239
handleSettingsResponse(data) {
3316-
if (data.content && typeof data.content.autoRefresh !== 'undefined') {
3317-
this.autoRefresh = data.content.autoRefresh;
3318-
console.log(`Auto-refresh ${this.autoRefresh ? 'enabled' : 'disabled'} by server`);
3319-
3320-
// Set up or clear the timer based on the setting
3321-
if (this.autoRefresh) {
3322-
this.setupAutoRefreshTimer();
3323-
} else {
3324-
if (this.refreshTimer) {
3325-
clearTimeout(this.refreshTimer);
3326-
this.refreshTimer = null;
3327-
}
3328-
}
3329-
}
3240+
// Settings response handler - autorefresh functionality removed
3241+
// Settings can be extended here for other configuration options
33303242
}
33313243

33323244
handleHelpContent(data) {
@@ -3336,27 +3248,10 @@ <h3 id="selectedCommandName">Game Messages</h3>
33363248
}
33373249
}
33383250

3339-
requestSettings() {
3340-
this.send({
3341-
type: 'infoRequest',
3342-
selection: 'settings'
3343-
});
3344-
}
3345-
3346-
handleSettingsResponse(data) {
3347-
if (data.content && typeof data.content.autoRefresh !== 'undefined') {
3348-
this.autoRefresh = data.content.autoRefresh;
3349-
console.log(`Auto-refresh ${this.autoRefresh ? 'enabled' : 'disabled'} by server`);
3350-
3351-
// Set up or clear the timer based on the setting
3352-
if (this.autoRefresh) {
3353-
this.setupAutoRefreshTimer();
3354-
} else {
3355-
if (this.refreshTimer) {
3356-
clearTimeout(this.refreshTimer);
3357-
this.refreshTimer = null;
3358-
}
3359-
}
3251+
handleHelpContent(data) {
3252+
const helpContent = document.getElementById('helpContent');
3253+
if (helpContent) {
3254+
helpContent.textContent = data.content;
33603255
}
33613256
}
33623257

@@ -3365,30 +3260,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
33653260
this.send({ type: 'infoRequest', selection: 'population' });
33663261
this.send({ type: 'infoRequest', selection: 'children' });
33673262
this.send({ type: 'infoRequest', selection: 'status' });
3368-
this.lastRefreshTime = Date.now();
3369-
this.resetAutoRefreshTimer();
3370-
}
3371-
3372-
setupAutoRefreshTimer() {
3373-
// Only set up timer if autoRefresh is enabled
3374-
if (this.autoRefresh) {
3375-
this.resetAutoRefreshTimer();
3376-
}
3377-
}
3378-
3379-
resetAutoRefreshTimer() {
3380-
if (this.refreshTimer) {
3381-
clearTimeout(this.refreshTimer);
3382-
}
3383-
3384-
// Only set up timer if autoRefresh is enabled
3385-
if (this.autoRefresh) {
3386-
this.refreshTimer = setTimeout(() => {
3387-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
3388-
this.refreshGameData();
3389-
}
3390-
}, 30000); // 30 seconds
3391-
}
33923263
}
33933264

33943265
registerPlayer() {
@@ -3665,99 +3536,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
36653536
};
36663537
});
36673538
}
3668-
3669-
// Version checking methods for auto-refresh
3670-
startVersionChecking() {
3671-
// Check for interface updates every 30 seconds
3672-
this.versionCheckTimer = setInterval(() => {
3673-
this.checkInterfaceVersion();
3674-
}, 30000); // 30 seconds
3675-
}
3676-
3677-
stopVersionChecking() {
3678-
if (this.versionCheckTimer) {
3679-
clearInterval(this.versionCheckTimer);
3680-
this.versionCheckTimer = null;
3681-
}
3682-
}
3683-
3684-
async checkInterfaceVersion() {
3685-
try {
3686-
// Make a request to check if the interface file has changed
3687-
const response = await fetch(window.location.href, {
3688-
method: 'HEAD',
3689-
cache: 'no-cache',
3690-
headers: {
3691-
'Cache-Control': 'no-cache'
3692-
}
3693-
});
3694-
3695-
if (response.ok) {
3696-
// Check last-modified header or ETag for changes
3697-
const lastModified = response.headers.get('Last-Modified');
3698-
const etag = response.headers.get('ETag');
3699-
3700-
// Store version info based on what's available
3701-
const serverVersion = etag || lastModified || 'unknown';
3702-
3703-
if (this.currentVersion !== 'unknown' &&
3704-
serverVersion !== 'unknown' &&
3705-
serverVersion !== this.currentVersion) {
3706-
this.handleVersionChange();
3707-
}
3708-
}
3709-
} catch (error) {
3710-
console.log('Version check failed:', error);
3711-
// Continue silently - don't disrupt user experience
3712-
}
3713-
}
3714-
3715-
handleVersionChange() {
3716-
// Show a non-intrusive notification about the update
3717-
const notification = document.createElement('div');
3718-
notification.style.cssText = `
3719-
position: fixed;
3720-
top: 20px;
3721-
right: 20px;
3722-
background: #4CAF50;
3723-
color: white;
3724-
padding: 15px 20px;
3725-
border-radius: 5px;
3726-
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
3727-
z-index: 10000;
3728-
font-family: Arial, sans-serif;
3729-
font-size: 14px;
3730-
cursor: pointer;
3731-
transition: opacity 0.3s;
3732-
`;
3733-
notification.innerHTML = `
3734-
Interface updated! Click to reload.
3735-
<div style="font-size: 12px; opacity: 0.8; margin-top: 5px;">
3736-
New features may be available
3737-
</div>
3738-
`;
3739-
3740-
// Auto-refresh when clicked
3741-
notification.onclick = () => {
3742-
window.location.reload();
3743-
};
3744-
3745-
// Add to page
3746-
document.body.appendChild(notification);
3747-
3748-
// Auto-remove after 10 seconds if not clicked
3749-
setTimeout(() => {
3750-
if (notification.parentNode) {
3751-
notification.style.opacity = '0';
3752-
setTimeout(() => {
3753-
notification.remove();
3754-
}, 300);
3755-
}
3756-
}, 10000);
3757-
3758-
// Stop checking once we've notified the user
3759-
this.stopVersionChecking();
3760-
}
37613539
}
37623540

37633541
// Initialize the client when page loads

0 commit comments

Comments
 (0)