Skip to content

Commit 86130ce

Browse files
committed
do not show father info
1 parent d9635f4 commit 86130ce

2 files changed

Lines changed: 75 additions & 26 deletions

File tree

tribes-interface.html

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
12801280
this.updateConnectionStatus('connected');
12811281
this.reconnectAttempts = 0;
12821282
this.requestCommandList();
1283-
this.requestSettings();
12841283
};
12851284

12861285
this.ws.onmessage = (event) => {
@@ -1336,7 +1335,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
13361335
this.updateConnectionStatus('connected');
13371336
this.reconnectAttempts = 0;
13381337
this.requestCommandList();
1339-
this.requestSettings();
13401338
};
13411339

13421340
this.ws.onmessage = (event) => {
@@ -1491,11 +1489,7 @@ <h3 id="selectedCommandName">Game Messages</h3>
14911489
this.handleCommandResponse(data);
14921490
break;
14931491
case 'infoRequest':
1494-
if (data.label === 'settings') {
1495-
this.handleSettingsResponse(data);
1496-
} else {
1497-
this.handleInfoResponse(data);
1498-
}
1492+
this.handleInfoResponse(data);
14991493
break;
15001494
case 'tribeMessage':
15011495
this.addMessage(data.message, 'tribe', '[EVERYONE]');
@@ -3151,10 +3145,33 @@ <h3 id="selectedCommandName">Game Messages</h3>
31513145
storeMessage(messageData) {
31523146
try {
31533147
const key = this.getMessageHistoryKey();
3154-
let messages = JSON.parse(this.getCookie(key) || '[]');
3148+
let messages = [];
3149+
3150+
// Try to parse existing messages, fallback to empty array if corrupted
3151+
try {
3152+
const existingData = this.getCookie(key);
3153+
if (existingData) {
3154+
messages = JSON.parse(existingData);
3155+
// Validate that it's an array
3156+
if (!Array.isArray(messages)) {
3157+
messages = [];
3158+
}
3159+
}
3160+
} catch (parseError) {
3161+
console.warn('Existing message history corrupted, starting fresh:', parseError.message);
3162+
messages = [];
3163+
}
3164+
3165+
// Sanitize message data to prevent JSON corruption
3166+
const sanitizedMessage = {
3167+
text: String(messageData.text || '').replace(/[\u0000-\u001f\u007f]/g, ''), // Remove control characters
3168+
type: String(messageData.type || 'info'),
3169+
typeLabel: messageData.typeLabel ? String(messageData.typeLabel) : null,
3170+
timestamp: Number(messageData.timestamp) || Date.now()
3171+
};
31553172

31563173
// Add new message
3157-
messages.push(messageData);
3174+
messages.push(sanitizedMessage);
31583175

31593176
// Keep only last 30 messages to prevent cookie size issues
31603177
if (messages.length > 30) {
@@ -3165,6 +3182,13 @@ <h3 id="selectedCommandName">Game Messages</h3>
31653182
this.setCookie(key, JSON.stringify(messages), 7);
31663183
} catch (error) {
31673184
console.warn('Failed to store message history:', error);
3185+
// Clear corrupted cookie data to prevent future errors
3186+
try {
3187+
const key = this.getMessageHistoryKey();
3188+
this.setCookie(key, '[]', 7);
3189+
} catch (clearError) {
3190+
console.warn('Failed to clear corrupted message history:', clearError);
3191+
}
31683192
}
31693193
}
31703194

@@ -3177,13 +3201,31 @@ <h3 id="selectedCommandName">Game Messages</h3>
31773201
return;
31783202
}
31793203

3180-
const messages = JSON.parse(messagesJson);
3204+
let messages;
3205+
try {
3206+
messages = JSON.parse(messagesJson);
3207+
// Validate that it's an array
3208+
if (!Array.isArray(messages)) {
3209+
console.warn('Invalid message history format, ignoring');
3210+
return;
3211+
}
3212+
} catch (parseError) {
3213+
console.warn('Corrupted message history found, clearing it:', parseError.message);
3214+
// Clear corrupted data
3215+
this.setCookie(key, '[]', 7);
3216+
return;
3217+
}
3218+
31813219
const currentTime = Date.now();
31823220
const maxAge = 24 * 60 * 60 * 1000; // 24 hours
31833221

3184-
// Filter out messages older than 24 hours
3222+
// Filter out messages older than 24 hours and validate message structure
31853223
const recentMessages = messages.filter(msg =>
3186-
currentTime - msg.timestamp < maxAge
3224+
msg &&
3225+
typeof msg.timestamp === 'number' &&
3226+
currentTime - msg.timestamp < maxAge &&
3227+
typeof msg.text === 'string' &&
3228+
msg.text.trim().length > 0
31873229
);
31883230

31893231
if (recentMessages.length > 0) {
@@ -3238,18 +3280,6 @@ <h3 id="selectedCommandName">Game Messages</h3>
32383280
});
32393281
}
32403282

3241-
requestSettings() {
3242-
this.send({
3243-
type: 'infoRequest',
3244-
selection: 'settings'
3245-
});
3246-
}
3247-
3248-
handleSettingsResponse(data) {
3249-
// Settings response handler - autorefresh functionality removed
3250-
// Settings can be extended here for other configuration options
3251-
}
3252-
32533283
handleHelpContent(data) {
32543284
const helpContent = document.getElementById('helpContent');
32553285
if (helpContent) {

websocket-server.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ function handleInfoRequest(ws, data, gameState) {
691691
messageData = {
692692
type: 'infoRequest',
693693
label: 'children',
694-
content: gameState.children,
694+
content: removeFatherReferences(gameState.children),
695695
};
696696
break;
697697

@@ -834,7 +834,7 @@ async function refreshTribeGameData(gameState, tribeName) {
834834
const childrenData = {
835835
type: 'infoRequest',
836836
label: 'children',
837-
content: gameState.children,
837+
content: removeFatherReferences(gameState.children),
838838
};
839839

840840
const statusData = {
@@ -1357,6 +1357,25 @@ function removeClunkyKeys(population) {
13571357
return cleanedPop;
13581358
}
13591359

1360+
function removeFatherReferences(children) {
1361+
const cleanedChildren = {};
1362+
const excludeKeys = [
1363+
'father',
1364+
'fatherName',
1365+
];
1366+
1367+
for (const [name, childData] of Object.entries(children || {})) {
1368+
const cleaned = {};
1369+
for (const [key, value] of Object.entries(childData)) {
1370+
if (excludeKeys.indexOf(key) === -1) {
1371+
cleaned[key] = value;
1372+
}
1373+
}
1374+
cleanedChildren[name] = cleaned;
1375+
}
1376+
return cleanedChildren;
1377+
}
1378+
13601379
function arrayMatch(array1, array2) {
13611380
if (!array1 && !array2) return true;
13621381
if (!array1 || !array2) return false;

0 commit comments

Comments
 (0)