mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
fix: fixed error in credentials management
This commit is contained in:
parent
5a4a202805
commit
74e2332b17
@ -140,6 +140,8 @@ export class InfoPopupEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class WrongCredentialsEvent extends BaseOlympusEvent {}
|
||||
|
||||
export class ShortcutsChangedEvent {
|
||||
static on(callback: (shortcuts: { [key: string]: Shortcut }) => void, singleShot = false) {
|
||||
document.addEventListener(
|
||||
@ -818,6 +820,23 @@ export class MissionDataChangedEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class EnabledCommandModesChangedEvent {
|
||||
static on(callback: (enabledCommandModes: string[]) => void, singleShot = false) {
|
||||
document.addEventListener(
|
||||
this.name,
|
||||
(ev: CustomEventInit) => {
|
||||
callback(ev.detail.enabledCommandModes);
|
||||
},
|
||||
{ once: singleShot }
|
||||
);
|
||||
}
|
||||
|
||||
static dispatch(enabledCommandModes: string[]) {
|
||||
document.dispatchEvent(new CustomEvent(this.name, { detail: { enabledCommandModes } }));
|
||||
// Logging disabled since periodic
|
||||
}
|
||||
}
|
||||
|
||||
/************** Other events ***************/
|
||||
export class WeaponsRefreshedEvent {
|
||||
static on(callback: (weapons: Weapon[]) => void, singleShot = false) {
|
||||
|
||||
@ -6,7 +6,7 @@ import { BLUE_COMMANDER, GAME_MASTER, NONE, RED_COMMANDER } from "../constants/c
|
||||
import { AirbasesData, BullseyesData, CommandModeOptions, DateAndTime, MissionData } from "../interfaces";
|
||||
import { Coalition } from "../types/types";
|
||||
import { Carrier } from "./carrier";
|
||||
import { AirbaseSelectedEvent, AppStateChangedEvent, BullseyesDataChangedEvent, CommandModeOptionsChangedEvent, MissionDataChangedEvent } from "../events";
|
||||
import { AirbaseSelectedEvent, AppStateChangedEvent, BullseyesDataChangedEvent, CommandModeOptionsChangedEvent, EnabledCommandModesChangedEvent, MissionDataChangedEvent } from "../events";
|
||||
|
||||
/** The MissionManager */
|
||||
export class MissionManager {
|
||||
@ -225,6 +225,7 @@ export class MissionManager {
|
||||
|
||||
setEnabledCommandModes(enabledCommandModes: string[]) {
|
||||
this.#enabledCommandModes = enabledCommandModes;
|
||||
EnabledCommandModesChangedEvent.dispatch(enabledCommandModes);
|
||||
}
|
||||
|
||||
getEnabledCommandModes() {
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
reactionsToThreat,
|
||||
} from "../constants/constants";
|
||||
import { AirbasesData, BullseyesData, CommandModeOptions, GeneralSettings, MissionData, Radio, ServerRequestOptions, ServerStatus, TACAN } from "../interfaces";
|
||||
import { MapOptionsChangedEvent, ServerStatusUpdatedEvent } from "../events";
|
||||
import { MapOptionsChangedEvent, ServerStatusUpdatedEvent, WrongCredentialsEvent } from "../events";
|
||||
|
||||
export class ServerManager {
|
||||
#connected: boolean = false;
|
||||
@ -130,6 +130,7 @@ export class ServerManager {
|
||||
} else if (xmlHttp.status == 401) {
|
||||
/* Bad credentials */
|
||||
console.error("Incorrect username/password");
|
||||
WrongCredentialsEvent.dispatch();
|
||||
errorCallback && errorCallback(xmlHttp.status);
|
||||
} else {
|
||||
/* Failure, probably disconnected */
|
||||
|
||||
@ -8,10 +8,9 @@ import { getApp, VERSION } from "../../olympusapp";
|
||||
import { sha256 } from "js-sha256";
|
||||
import { LoginSubState, NO_SUBSTATE, OlympusState } from "../../constants/constants";
|
||||
import { OlDropdown, OlDropdownItem } from "../components/oldropdown";
|
||||
import { AppStateChangedEvent } from "../../events";
|
||||
import { AppStateChangedEvent, EnabledCommandModesChangedEvent, MissionDataChangedEvent, WrongCredentialsEvent } 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("");
|
||||
@ -24,6 +23,10 @@ export function LoginModal(props: { open: boolean }) {
|
||||
AppStateChangedEvent.on((state, subState) => {
|
||||
setSubState(subState);
|
||||
});
|
||||
WrongCredentialsEvent.on(() => {
|
||||
setLoginError(true);
|
||||
setCheckingPassword(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const usernameCallback = useCallback(() => getApp()?.getServerManager().setUsername(username), [username]);
|
||||
@ -37,28 +40,21 @@ export function LoginModal(props: { open: boolean }) {
|
||||
|
||||
const login = useCallback(() => {
|
||||
setCheckingPassword(true);
|
||||
|
||||
EnabledCommandModesChangedEvent.on((commandModes) => {
|
||||
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);
|
||||
}, 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);
|
||||
}
|
||||
);
|
||||
.getMission(() => {});
|
||||
}, [commandModes, username, password]);
|
||||
|
||||
const connect = useCallback(() => {
|
||||
@ -94,9 +90,10 @@ export function LoginModal(props: { open: boolean }) {
|
||||
max-md:border-none
|
||||
`}
|
||||
>
|
||||
<img src="images/splash/1.jpg" className={`
|
||||
contents-center w-full object-cover opacity-[7%]
|
||||
`}></img>
|
||||
<img
|
||||
src="images/splash/1.jpg"
|
||||
className={`contents-center w-full object-cover opacity-[7%]`}
|
||||
></img>
|
||||
<div
|
||||
className={`
|
||||
absolute h-full w-full bg-gradient-to-r from-blue-200/25
|
||||
@ -154,9 +151,10 @@ export function LoginModal(props: { open: boolean }) {
|
||||
`}
|
||||
>
|
||||
<span className="size-[80px] min-w-14">
|
||||
<img src="images/olympus-500x500.png" className={`
|
||||
flex w-full
|
||||
`}></img>
|
||||
<img
|
||||
src="images/olympus-500x500.png"
|
||||
className={`flex w-full`}
|
||||
></img>
|
||||
</span>
|
||||
<div className={`flex flex-col items-start gap-1`}>
|
||||
<h1
|
||||
@ -273,9 +271,10 @@ export function LoginModal(props: { open: boolean }) {
|
||||
>
|
||||
Choose your role
|
||||
</label>
|
||||
<OlDropdown label={activeCommandMode ?? ""} className={`
|
||||
w-48
|
||||
`}>
|
||||
<OlDropdown
|
||||
label={activeCommandMode ?? ""}
|
||||
className={`w-48`}
|
||||
>
|
||||
{commandModes?.map((commandMode) => {
|
||||
return <OlDropdownItem onClick={() => setActiveCommandMode(commandMode)}>{commandMode}</OlDropdownItem>;
|
||||
})}
|
||||
@ -310,7 +309,7 @@ export function LoginModal(props: { open: boolean }) {
|
||||
description="The Olympus Server at this address could not be reached or the password is incorrect. Check your password. If correct, check the address is correct, restart the Olympus server or reinstall Olympus. Ensure the ports set are not already used."
|
||||
></ErrorCallout>
|
||||
<div className={`text-sm font-medium text-gray-200`}>
|
||||
Still having issues? See our
|
||||
Still having issues? See our{" "}
|
||||
<a
|
||||
href=""
|
||||
className={`
|
||||
|
||||
@ -194,7 +194,7 @@ module.exports = function (configLocation, viteProxy) {
|
||||
if (userConfig.roles[0] in defaultUsers) {
|
||||
/* Apply the authorization headers */
|
||||
req.headers.authorization = `Basic ${btoa(
|
||||
user + ":" + defaultUsers[userConfig.roles[0]]
|
||||
userConfig.roles[0] + ":" + defaultUsers[userConfig.roles[0]]
|
||||
)}`;
|
||||
} else {
|
||||
res.sendStatus(401); // Unauthorized
|
||||
@ -207,7 +207,7 @@ module.exports = function (configLocation, viteProxy) {
|
||||
/* Send back the roles that the user is enabled to */
|
||||
if (userConfig) res.set("X-Enabled-Command-Modes", `${userConfig.roles}`);
|
||||
else if (user in defaultUsers)
|
||||
res.set("X-Enabled-Command-Modes", `[${user}]`);
|
||||
res.set("X-Enabled-Command-Modes", `${user}`);
|
||||
next();
|
||||
} else {
|
||||
res.sendStatus(401); // Unauthorized
|
||||
|
||||
@ -26,6 +26,10 @@ Olympus.weaponIndex = 0 -- Counter used to spread the computational load of da
|
||||
Olympus.weaponStep = 50 -- Max number of weapons that get updated each cycle
|
||||
Olympus.weapons = {} -- Table holding references to all the currently existing weapons
|
||||
|
||||
-- Spots (laser/IR) data
|
||||
Olympus.spots = {}
|
||||
Olympus.spotsCounter = 1
|
||||
|
||||
-- Miscellaneous initializations
|
||||
Olympus.missionStartTime = DCS.getRealTime()
|
||||
Olympus.napalmCounter = 1
|
||||
@ -574,7 +578,18 @@ function Olympus.fireLaser(ID, code, lat, lng)
|
||||
|
||||
local unit = Olympus.getUnitByID(ID)
|
||||
if unit ~= nil and unit:isExist() then
|
||||
local ray = Spot.createLaser(unit, {x = 0, y = 1, z = 0}, vec3, code)
|
||||
local spot = Spot.createLaser(unit, {x = 0, y = 1, z = 0}, vec3, code)
|
||||
Olympus.spotsCounter = Olympus.spotsCounter + 1
|
||||
Olympus.spots[Olympus.spotsCounter] = {
|
||||
type = "laser",
|
||||
object = spot,
|
||||
sourceUnitID = ID,
|
||||
targetPosition = {
|
||||
lat = lat,
|
||||
lng = lng
|
||||
},
|
||||
code = code
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -586,7 +601,16 @@ function Olympus.fireInfrared(ID, lat, lng)
|
||||
|
||||
local unit = Olympus.getUnitByID(ID)
|
||||
if unit ~= nil and unit:isExist() then
|
||||
local ray = Spot.createInfraRed(unit, {x = 0, y = 1, z = 0}, vec3)
|
||||
local spot = Spot.createInfraRed(unit, {x = 0, y = 1, z = 0}, vec3)
|
||||
Olympus.spots[Olympus.spotsCounter] = {
|
||||
type = "infrared",
|
||||
object = spot,
|
||||
sourceUnitID = ID,
|
||||
targetPosition = {
|
||||
lat = lat,
|
||||
lng = lng
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -1354,10 +1378,30 @@ function Olympus.setMissionData(arg, time)
|
||||
mission.coalitions[coalitionName][#mission.coalitions[coalitionName] + 1] = countryName
|
||||
end
|
||||
|
||||
-- Spots
|
||||
-- Initialize an empty table to store spots
|
||||
local spots = {}
|
||||
|
||||
-- Iterate over each spot in Olympus.spots
|
||||
for ID, spot in pairs(Olympus.spots) do
|
||||
-- Create a new entry in the spots table with the same ID
|
||||
spots[ID] = {
|
||||
type = spot.type,
|
||||
sourceUnitID = spot.sourceUnitID,
|
||||
targetPosition = spot.targetPosition,
|
||||
}
|
||||
|
||||
-- If the spot type is "laser", add the code to the spot entry
|
||||
if spot.type == "laser" then
|
||||
spots[ID]["code"] = spot.code
|
||||
end
|
||||
end
|
||||
|
||||
-- Assemble table
|
||||
Olympus.missionData["bullseyes"] = bullseyes
|
||||
Olympus.missionData["airbases"] = airbases
|
||||
Olympus.missionData["mission"] = mission
|
||||
Olympus.missionData["spots"] = spots
|
||||
|
||||
Olympus.OlympusDLL.setMissionData()
|
||||
return time + 1 -- For perfomance reasons weapons are updated once every second
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user