import React, { useCallback, useEffect, useState } from "react"; import { Modal } from "./components/modal"; import { Card } from "./components/card"; import { ErrorCallout } from "../components/olcallout"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faArrowRight, faCheckCircle, faExternalLink } from "@fortawesome/free-solid-svg-icons"; import { getApp, VERSION } from "../../olympusapp"; import { sha256 } from "js-sha256"; import { BLUE_COMMANDER, GAME_MASTER, LoginSubState, NO_SUBSTATE, OlympusState, RED_COMMANDER } from "../../constants/constants"; import { OlDropdown, OlDropdownItem } from "../components/oldropdown"; import { AppStateChangedEvent } from "../../events"; export function LoginModal(props: { open: boolean }) { // TODO: add warning if not in secure context and some features are disabled const [subState, setSubState] = useState(NO_SUBSTATE); const [password, setPassword] = useState(""); const [username, setUsername] = useState(""); const [checkingPassword, setCheckingPassword] = useState(false); const [loginError, setLoginError] = useState(false); const [commandModes, setCommandModes] = useState(null as null | string[]); const [activeCommandMode, setActiveCommandMode] = useState(null as null | string); useEffect(() => { AppStateChangedEvent.on((state, subState) => { setSubState(subState); }); }, []); const usernameCallback = useCallback(() => getApp()?.getServerManager().setUsername(username), [username]); useEffect(usernameCallback, [username]); const passwordCallback = useCallback(() => { var hash = sha256.create(); getApp()?.getServerManager().setPassword(hash.update(password).hex()); }, [password]); useEffect(passwordCallback, [password]); const login = useCallback(() => { setCheckingPassword(true); getApp() .getServerManager() .getMission( (response) => { const commandModes = getApp().getMissionManager().getEnabledCommandModes(); if (commandModes.length > 1) { setCommandModes(commandModes); setActiveCommandMode(commandModes[0]); } else if (commandModes.length == 1) { setActiveCommandMode(commandModes[0]); getApp().setState(OlympusState.LOGIN, LoginSubState.CONNECT); } else { setLoginError(true); } setCheckingPassword(false); }, () => { setLoginError(true); setCheckingPassword(false); } ); }, [commandModes, username, password]); const connect = useCallback(() => { if (activeCommandMode) { getApp().getServerManager().setActiveCommandMode(activeCommandMode); getApp().getServerManager().startUpdate(); getApp().setState(OlympusState.IDLE); /* If no profile exists already with that name, create it from scratch from the defaults */ if (getApp().getProfile() === null) getApp().saveProfile(); /* Load the profile */ getApp().loadProfile(); } }, [activeCommandMode]); const subStateCallback = useCallback(() => { if (subState === LoginSubState.COMMAND_MODE) { login(); } else if (subState === LoginSubState.CONNECT) { connect(); } }, [subState, activeCommandMode, commandModes, username, password]); useEffect(subStateCallback, [subState]); return (
{!checkingPassword ? ( <>
Connect to
{window.location.toString()}

DCS Olympus

Version {VERSION}
{!loginError ? ( <> {subState === LoginSubState.CREDENTIALS && ( <>
setUsername(ev.currentTarget.value)} className={` block w-full max-w-80 rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500 focus:border-blue-500 focus:ring-blue-500 `} placeholder="Enter display name" value={username} required /> setPassword(ev.currentTarget.value)} className={` block w-full max-w-80 rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500 focus:border-blue-500 focus:ring-blue-500 `} placeholder="Enter password" required />
{/* */}
)} {subState === LoginSubState.COMMAND_MODE && ( <>
{commandModes?.map((commandMode) => { return setActiveCommandMode(commandMode)}>{commandMode}; })}
)} ) : ( <>
Still having issues? See our troubleshooting guide here .
)} ) : (
)}
YouTube Video Guide
Check out our official video tutorial on how to get started with Olympus - so you can immediately start controlling the battlefield.
Wiki Guide
Find out more about Olympus through our online wiki guide.
DCS Olympus (the "MATERIAL" or "Software") is provided completely free to users subject to the terms of the CC BY-NC-SA 4.0 Licence except where such terms conflict with this disclaimer, in which case, the terms of this disclaimer shall prevail. Any party making use of the Software in any manner agrees to be bound by the terms set out in the disclaimer. THIS MATERIAL IS NOT MADE OR SUPPORTED BY EAGLE DYNAMICS SA.
); }