5180 fichiers 38.5 Mo 0 téléchargements 218 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / hooks / session / useFirstLoginOfDay.ts
useFirstLoginOfDay.ts 1.4 Ko Télécharger le fichier
import { GetSessionDataManager, IsFirstLoginOfDayEvent } from '@octane/renderer';
import { useState } from 'react';
import { registerSharedHook, useSharedHook } from '@/state/useSharedHook';
import { useMessageEvent } from '../events';

/**
 * Consumes `IsFirstLoginOfDayComposer` (header 793), pushed once during
 * the login handshake.
 *
 * The flag is what the quest engine keys off (the seasonal calendar opens
 * itself on the first login of a day). The packet arrives in the login
 * burst, before this hook mounts, so the session data manager keeps it
 * and seeds the state; `isFirstLoginOfDay` is null on a renderer that
 * does not keep it, until the server speaks again.
 */
const readStoredFirstLoginOfDay = (): boolean => {
    const manager = GetSessionDataManager?.();
    const value = manager ? (manager as { isFirstLoginOfDay?: boolean }).isFirstLoginOfDay : undefined;

    return typeof value === 'boolean' ? value : null;
};

const useFirstLoginOfDayState = () => {
    const [isFirstLoginOfDay, setIsFirstLoginOfDay] = useState<boolean>(readStoredFirstLoginOfDay);

    useMessageEvent<IsFirstLoginOfDayEvent>(IsFirstLoginOfDayEvent, event => {
        setIsFirstLoginOfDay(event.getParser().isFirstLoginOfDay);
    });

    return { isFirstLoginOfDay };
};

export const useFirstLoginOfDay = () => useSharedHook(useFirstLoginOfDayState);

registerSharedHook(useFirstLoginOfDayState);
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser