forked from OpenWF/SpaceNinjaServer
Compare commits
4 Commits
unique-pee
...
main
Author | SHA1 | Date | |
---|---|---|---|
173a4791d9 | |||
8a29f06207 | |||
cf3007b744 | |||
7f5592e00c |
@ -1,25 +1,23 @@
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { updateTheme } from "@/src/services/inventoryService";
|
||||
import { IThemeUpdateRequest } from "@/src/types/requestTypes";
|
||||
import { RequestHandler } from "express";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
|
||||
const updateThemeController: RequestHandler = async (request, response) => {
|
||||
export const updateThemeController: RequestHandler = async (request, response) => {
|
||||
const accountId = await getAccountIdForRequest(request);
|
||||
const body = String(request.body);
|
||||
const data = getJSONfromString<IThemeUpdateRequest>(String(request.body));
|
||||
|
||||
try {
|
||||
const json = getJSONfromString<IThemeUpdateRequest>(body);
|
||||
if (typeof json !== "object") {
|
||||
throw new Error("Invalid data format");
|
||||
}
|
||||
|
||||
await updateTheme(json, accountId);
|
||||
} catch (err) {
|
||||
console.error("Error parsing JSON data:", err);
|
||||
}
|
||||
const inventory = await getInventory(accountId, "ThemeStyle ThemeBackground ThemeSounds");
|
||||
if (data.Style) inventory.ThemeStyle = data.Style;
|
||||
if (data.Background) inventory.ThemeBackground = data.Background;
|
||||
if (data.Sounds) inventory.ThemeSounds = data.Sounds;
|
||||
await inventory.save();
|
||||
|
||||
response.json({});
|
||||
};
|
||||
|
||||
export { updateThemeController };
|
||||
interface IThemeUpdateRequest {
|
||||
Style?: string;
|
||||
Background?: string;
|
||||
Sounds?: string;
|
||||
}
|
||||
|
@ -1,9 +1,24 @@
|
||||
import { getAccountForRequest } from "@/src/services/loginService";
|
||||
import { Account } from "@/src/models/loginModel";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const ircDroppedController: RequestHandler = async (req, res) => {
|
||||
const account = await getAccountForRequest(req);
|
||||
account.Dropped = true;
|
||||
await account.save();
|
||||
if (!req.query.accountId) {
|
||||
throw new Error("Request is missing accountId parameter");
|
||||
}
|
||||
const nonce: number = parseInt(req.query.nonce as string);
|
||||
if (!nonce) {
|
||||
throw new Error("Request is missing nonce parameter");
|
||||
}
|
||||
|
||||
await Account.updateOne(
|
||||
{
|
||||
_id: req.query.accountId,
|
||||
Nonce: nonce
|
||||
},
|
||||
{
|
||||
Dropped: true
|
||||
}
|
||||
);
|
||||
|
||||
res.end();
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountForRequest, isNameTaken } from "@/src/services/loginService";
|
||||
import { getAccountForRequest, isAdministrator, isNameTaken } from "@/src/services/loginService";
|
||||
import { config, saveConfig } from "@/src/services/configService";
|
||||
|
||||
export const renameAccountController: RequestHandler = async (req, res) => {
|
||||
const account = await getAccountForRequest(req);
|
||||
@ -7,8 +8,18 @@ export const renameAccountController: RequestHandler = async (req, res) => {
|
||||
if (await isNameTaken(req.query.newname)) {
|
||||
res.status(409).json("Name already in use");
|
||||
} else {
|
||||
if (isAdministrator(account)) {
|
||||
for (let i = 0; i != config.administratorNames!.length; ++i) {
|
||||
if (config.administratorNames![i] == account.DisplayName) {
|
||||
config.administratorNames![i] = req.query.newname;
|
||||
}
|
||||
}
|
||||
await saveConfig();
|
||||
}
|
||||
|
||||
account.DisplayName = req.query.newname;
|
||||
await account.save();
|
||||
|
||||
res.end();
|
||||
}
|
||||
} else {
|
||||
|
10
src/index.ts
10
src/index.ts
@ -19,9 +19,13 @@ import mongoose from "mongoose";
|
||||
return "<BIGINT>" + this.toString() + "</BIGINT>";
|
||||
};
|
||||
const og_stringify = JSON.stringify;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
||||
(JSON as any).stringify = (obj: any): string => {
|
||||
return og_stringify(obj).split(`"<BIGINT>`).join(``).split(`</BIGINT>"`).join(``);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
JSON.stringify = (obj: any, replacer?: any, space?: string | number): string => {
|
||||
return og_stringify(obj, replacer as string[], space)
|
||||
.split(`"<BIGINT>`)
|
||||
.join(``)
|
||||
.split(`</BIGINT>"`)
|
||||
.join(``);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ interface IConfig {
|
||||
httpsPort?: number;
|
||||
myIrcAddresses?: string[];
|
||||
NRS?: string[];
|
||||
administratorNames?: string[] | string;
|
||||
administratorNames?: string[];
|
||||
autoCreateAccount?: boolean;
|
||||
skipTutorial?: boolean;
|
||||
skipAllDialogue?: boolean;
|
||||
@ -83,10 +83,15 @@ export const updateConfig = async (data: string): Promise<void> => {
|
||||
Object.assign(config, JSON.parse(data));
|
||||
};
|
||||
|
||||
export const saveConfig = async (): Promise<void> => {
|
||||
amnesia = true;
|
||||
await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
|
||||
};
|
||||
|
||||
export const validateConfig = (): void => {
|
||||
if (typeof config.administratorNames == "string") {
|
||||
logger.warn(
|
||||
`"administratorNames" should be an array; please add square brackets: ["${config.administratorNames}"]`
|
||||
);
|
||||
logger.info(`Updating config.json to make administratorNames an array.`);
|
||||
config.administratorNames = [config.administratorNames];
|
||||
void saveConfig();
|
||||
}
|
||||
};
|
||||
|
@ -29,11 +29,7 @@ import {
|
||||
ICrewShipWeaponClient
|
||||
} from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate";
|
||||
import {
|
||||
IMissionInventoryUpdateRequest,
|
||||
IThemeUpdateRequest,
|
||||
IUpdateChallengeProgressRequest
|
||||
} from "../types/requestTypes";
|
||||
import { IMissionInventoryUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { convertInboxMessage, fromStoreItem, getExalted, getKeyChainItems } from "@/src/services/itemDataService";
|
||||
import {
|
||||
@ -891,15 +887,6 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string): Pr
|
||||
};
|
||||
};
|
||||
|
||||
export const updateTheme = async (data: IThemeUpdateRequest, accountId: string): Promise<void> => {
|
||||
const inventory = await getInventory(accountId);
|
||||
if (data.Style) inventory.ThemeStyle = data.Style;
|
||||
if (data.Background) inventory.ThemeBackground = data.Background;
|
||||
if (data.Sounds) inventory.ThemeSounds = data.Sounds;
|
||||
|
||||
await inventory.save();
|
||||
};
|
||||
|
||||
export const addEquipment = (
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
category: TEquipmentKey,
|
||||
|
@ -69,36 +69,31 @@ export const getAccountForRequest = async (req: Request): Promise<TAccountDocume
|
||||
if (!req.query.accountId) {
|
||||
throw new Error("Request is missing accountId parameter");
|
||||
}
|
||||
if (!req.query.nonce || parseInt(req.query.nonce as string) === 0) {
|
||||
const nonce: number = parseInt(req.query.nonce as string);
|
||||
if (!nonce) {
|
||||
throw new Error("Request is missing nonce parameter");
|
||||
}
|
||||
|
||||
const account = await Account.findOne({
|
||||
_id: req.query.accountId,
|
||||
Nonce: req.query.nonce
|
||||
Nonce: nonce
|
||||
});
|
||||
if (!account) {
|
||||
throw new Error("Invalid accountId-nonce pair");
|
||||
}
|
||||
if (account.Dropped && req.query.ct) {
|
||||
account.Dropped = undefined;
|
||||
await account.save();
|
||||
}
|
||||
return account;
|
||||
};
|
||||
|
||||
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
|
||||
const account = await getAccountForRequest(req);
|
||||
if (account.Dropped && req.query.ct) {
|
||||
account.Dropped = undefined;
|
||||
await account.save();
|
||||
}
|
||||
return account._id.toString();
|
||||
return (await getAccountForRequest(req))._id.toString();
|
||||
};
|
||||
|
||||
export const isAdministrator = (account: TAccountDocument): boolean => {
|
||||
if (!config.administratorNames) {
|
||||
return false;
|
||||
}
|
||||
if (typeof config.administratorNames == "string") {
|
||||
return config.administratorNames == account.DisplayName;
|
||||
}
|
||||
return !!config.administratorNames.find(x => x == account.DisplayName);
|
||||
return !!config.administratorNames?.find(x => x == account.DisplayName);
|
||||
};
|
||||
|
||||
const platform_magics = [753, 639, 247, 37, 60];
|
||||
|
@ -19,12 +19,6 @@ import {
|
||||
ICollectibleEntry
|
||||
} from "./inventoryTypes/inventoryTypes";
|
||||
|
||||
export interface IThemeUpdateRequest {
|
||||
Style?: string;
|
||||
Background?: string;
|
||||
Sounds?: string;
|
||||
}
|
||||
|
||||
export interface IAffiliationChange {
|
||||
Tag: string;
|
||||
Standing: number;
|
||||
|
68096
static/webui/inventory.json
Normal file
68096
static/webui/inventory.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user