removed fingerprint again and added salt for the name creator

This commit is contained in:
2026-06-06 22:10:59 +01:00
parent 4e4bd6a145
commit d02a51f0ca
3 changed files with 67 additions and 79 deletions
+25 -1
View File
@@ -204,6 +204,29 @@ function stopPacat(browserSessId) {
if (pacat) { pacat.kill(); pacatProcesses.delete(browserSessId); }
}
const NAME_SALT = process.env.NAME_SALT || 'change-this-secret';
function hashString(str) {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
hash = hash & 0x7fffffff;
}
return hash;
}
function ipToName(ip) {
const adjectives = ['Fast','Slow','Red','Blue','Green','Dark','Bright','Wild',
'Cool','Hot','Big','Small','Sharp','Brave','Swift','Bold'];
const nouns = ['Wolf','Eagle','Tiger','Bear','Fox','Lion','Hawk','Shark',
'Snake','Raven','Storm','Rock','Fire','Ice','Wind','Steel'];
const salted = ip + NAME_SALT;
const h1 = hashString(salted);
const h2 = hashString(salted + '1');
const h3 = hashString(salted + '2');
return `${adjectives[h1 % adjectives.length]} ${nouns[h2 % nouns.length]} ${h3 % 9999}`;
}
// ── WebSocket handler ─────────────────────────────────────────────────────────
wss.on('connection', ws => {
let role = null;
@@ -337,7 +360,8 @@ wss.on('connection', ws => {
}
else if (msg.type === 'get_ip') {
const ip = ws._socket.remoteAddress.replace('::ffff:', '');
ws.send(JSON.stringify({ type: 'your_ip', ip }));
const name = ipToName(ip);
ws.send(JSON.stringify({ type: 'your_ip', ip: name }));
}
});