// Shared in-memory state -- the union of online + whitelisted players is what
// tab-completion matches against, so we keep it centralised here.
"use strict";

export const state = {
    onlinePlayers: [],
    whitelistedPlayers: [],
    knownPlayers: [], // sorted union, for autocomplete
    cmdHistory: [],
    cmdHistoryIdx: -1,
};

export function rebuildKnownPlayers() {
    const set = new Set();
    state.onlinePlayers.forEach(n => set.add(n));
    state.whitelistedPlayers.forEach(n => set.add(n));
    state.knownPlayers = [...set].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
}
