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
+41 -77
View File
@@ -151,67 +151,37 @@
</div>
<script type="module">
const fpPromise = import('https://openfpcdn.io/fingerprintjs/v5')
.then(FingerprintJS => FingerprintJS.load());
// ── Name generation from IP ───────────────────────────────────────────
function hashString(str) {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
hash = hash & 0x7fffffff; // keep positive 31-bit
hash = hash & 0x7fffffff;
}
return hash;
}
function visitorIdToName(input) {
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 h1 = hashString(input);
const h2 = hashString(input + '1');
const h3 = hashString(input + '2');
const adjIndex = h1 % adjectives.length;
const nounIndex = h2 % nouns.length;
const number = h3 % 9999;
return `${adjectives[adjIndex]} ${nouns[nounIndex]} ${number}`;
}
let visitorName = null;
async function initVisitorName() {
try {
const fp = await fpPromise;
const result = await fp.get();
if (result.visitorId) {
visitorName = visitorIdToName(result.visitorId);
return;
}
} catch (e) {
}
// Fallback: request IP from server
// Wait until WebSocket is open
const waitForIp = new Promise(resolve => {
await new Promise(resolve => {
const handler = e => {
if (e.data instanceof Blob) return;
const msg = JSON.parse(e.data);
if (msg.type === 'your_ip') {
visitorName = visitorIdToName(msg.ip);
sigWs.removeEventListener('message', handler);
resolve();
}
try {
const msg = JSON.parse(e.data);
if (msg.type === 'your_ip') {
visitorName = msg.ip; // server already sent the name
sigWs.removeEventListener('message', handler);
resolve();
}
} catch {}
};
sigWs.addEventListener('message', handler);
sigWs.send(JSON.stringify({ type: 'get_ip' }));
});
await waitForIp;
}
// ── State ─────────────────────────────────────────────────────────────
const SIG_URL = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}`;
const statusEl = document.getElementById('status');
@@ -220,17 +190,15 @@
const queueList = document.getElementById('queue-list');
const loadingEl = document.getElementById('loading-overlay');
let sigWs = null;
let pc = null;
let sessionId = null;
let pointerLocked = false;
let isControlling = false;
let isInQueue = false;
let sigWs = null;
let pc = null;
let sessionId = null;
let pointerLocked = false;
let isControlling = false;
let isInQueue = false;
let isWaitingForRestart = false;
function setStatus(msg) {
statusEl.textContent = msg;
}
function setStatus(msg) { statusEl.textContent = msg; }
function setLoading(visible) {
loadingEl.classList.toggle('visible', visible);
@@ -270,9 +238,7 @@
video: false,
});
return true;
} catch (e) {
return false;
}
} catch (e) { return false; }
}
async function startMic() {
@@ -292,7 +258,9 @@
if (sigWs && sigWs.readyState === WebSocket.OPEN) sigWs.send(int16.buffer);
};
source.connect(micProcessor);
micProcessor.connect(audioContext.destination);
// Connect to a dummy destination to keep onaudioprocess firing
// without routing audio to speakers
micProcessor.connect(audioContext.createMediaStreamDestination());
micActive = true;
}
@@ -316,9 +284,9 @@
}
function enterControl() {
isControlling = true;
isInQueue = false;
isWaitingForRestart = false;
isControlling = true;
isInQueue = false;
isWaitingForRestart = false;
canvas.classList.replace('watching', 'controlling');
canvas.muted = false;
canvas.requestPointerLock();
@@ -326,15 +294,13 @@
}
function exitControl() {
isControlling = false;
isInQueue = false;
isWaitingForRestart = false;
isControlling = false;
isInQueue = false;
isWaitingForRestart = false;
canvas.classList.replace('controlling', 'watching');
hintEl.textContent = 'Click to take control';
stopMic();
if (document.pointerLockElement === canvas) {
document.exitPointerLock();
}
if (document.pointerLockElement === canvas) document.exitPointerLock();
}
// ── WebRTC ────────────────────────────────────────────────────────────
@@ -366,12 +332,11 @@
setStatus('Connecting...');
sigWs = new WebSocket(SIG_URL);
sigWs.onopen = () => {
setStatus('Connected — setting up stream...');
initVisitorName().then(() => {
});
setupPeerConnection();
};
sigWs.onopen = () => {
setStatus('Connected — setting up stream...');
initVisitorName();
setupPeerConnection();
};
sigWs.onmessage = async e => {
if (e.data instanceof Blob) return;
@@ -443,13 +408,12 @@
}
canvas.addEventListener('click', () => {
if (isControlling) {
// Already controller, just recapture pointer lock
canvas.muted = false;
canvas.requestPointerLock();
} else {
requestControl();
}
if (isControlling) {
canvas.muted = false;
canvas.requestPointerLock();
} else {
requestControl();
}
});
document.addEventListener('pointerlockchange', () => {