fix(multi): restrict search and game settings to room host only
This commit is contained in:
@@ -4,12 +4,15 @@ import { useEffect, useState } from "react";
|
||||
|
||||
const KEY = "wikirush_search_allowed";
|
||||
|
||||
// Pour les modes solo/blitz : état local via localStorage + blocage Ctrl+F
|
||||
export function useSearchAllowed() {
|
||||
const [allowed, setAllowed] = useState<boolean>(() => {
|
||||
if (typeof window === "undefined") return false;
|
||||
return localStorage.getItem(KEY) === "true";
|
||||
});
|
||||
|
||||
useCtrlFBlock(allowed);
|
||||
|
||||
function toggle() {
|
||||
setAllowed((prev) => {
|
||||
const next = !prev;
|
||||
@@ -18,6 +21,11 @@ export function useSearchAllowed() {
|
||||
});
|
||||
}
|
||||
|
||||
return { allowed, toggle };
|
||||
}
|
||||
|
||||
// Pour le mode multi : blocage Ctrl+F basé sur room.searchAllowed (vérité côté serveur)
|
||||
export function useCtrlFBlock(allowed: boolean) {
|
||||
useEffect(() => {
|
||||
function handleKeyDown(e: KeyboardEvent) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === "f") {
|
||||
@@ -30,6 +38,4 @@ export function useSearchAllowed() {
|
||||
window.addEventListener("keydown", handleKeyDown, { capture: true });
|
||||
return () => window.removeEventListener("keydown", handleKeyDown, { capture: true });
|
||||
}, [allowed]);
|
||||
|
||||
return { allowed, toggle };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user