Updated field filter. Update room id -> hash -> seed

This commit is contained in:
UndecimoDia 2026-07-23 19:36:19 +03:00
parent f631595cca
commit 908252d5d9
2 changed files with 26 additions and 7 deletions

View file

@ -363,11 +363,28 @@
};
const byName = () => {
const q = m.inner.querySelector("#rq").value.trim().toLowerCase();
const hit = App.init.citizens.find((c) => c.name.toLowerCase() === q);
out.innerHTML = hit
? ""
: '<p class="dim small">— Записів не знайдено. Перевірте написання.</p>';
if (hit) draw([hit]);
if (!q) {
out.innerHTML = '<p class="dim small">— Введіть ім\'я або прізвище.</p>';
return;
}
// Розбиваємо введений запит на слова
const words = q.split(/\s+/);
// Фільтруємо: кожне введене слово має збігатися з початком якогось слова в імені громадянина
const hits = App.init.citizens.filter((c) => {
const nameWords = c.name.toLowerCase().split(/\s+/);
return words.every((w) => nameWords.some((nw) => nw.startsWith(w)));
});
if (!hits.length) {
out.innerHTML = '<p class="dim small">— Записів не знайдено. Спробуйте інший початок.</p>';
return;
}
out.innerHTML = "";
draw(hits);
};
const byFilter = () => {
const v = (id) => m.inner.querySelector(id).value;

View file

@ -4,6 +4,7 @@ const http = require('http');
const fs = require('fs');
const path = require('path');
const os = require('os');
const crypto = require('crypto');
const { WebSocketServer } = require('ws');
const { generateCase, checkAccusation, md5 } = require('./casegen');
const { unitBuilding } = require('./casegen/district');
@ -39,8 +40,9 @@ function seedRand(seed) {
function getSession(code) {
if (sessions[code]) return sessions[code];
const cs = generateCase(code);
const rng = seedRand([...code].reduce((a, c) => a * 31 + c.charCodeAt(0), 0)); // детермінований rand
const hashedCode = crypto.createHash('sha512').update(code).digest('hex');
const cs = generateCase(hashedCode);
const rng = seedRand([...hashedCode].reduce((a, c) => a * 31 + c.charCodeAt(0), 0));
const stn = cs.district.buildings.find(b => b.id === 'station');
const s = {
code, cs,