Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongodb code #28

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fe6934e
MongoDB player profile!
Sep 21, 2023
47627c8
Code cleanup; refactoring, better names/locations
Sep 22, 2023
5c19b13
Rename routes and clean up code
Sep 22, 2023
dbad35c
remove yarn.lock
Sep 22, 2023
54aaf8c
Creating graceful failure logic for mongo
Sep 22, 2023
980b8e0
pattern cleanup
Sep 22, 2023
6b89743
add crew field as index to trackedAssignments
Sep 22, 2023
78c4a9f
add route for /getTrackedData
Sep 22, 2023
d3351cf
Add debugging script to package.json
Sep 22, 2023
498aed5
test gittower here, instead
Sep 23, 2023
bdefb14
add indices for fleet and squadron
Sep 24, 2023
79a262c
get profile by fleet and squadron
Sep 24, 2023
11438b2
code-cleanup gittower test
Sep 24, 2023
4fd36b1
test gittower again
Sep 24, 2023
5fc9ee7
another test
Sep 24, 2023
a38df5f
another tower test
Sep 24, 2023
185ff21
test gittower
Sep 24, 2023
e2841fd
test
Sep 24, 2023
fa990ad
gittower test
Sep 24, 2023
2fd7559
add post many assignments.
Sep 25, 2023
cf7d454
Implement Fleet Boss Battle Models, Logic, and Routes
Oct 3, 2023
756fc68
Typo
Oct 3, 2023
1b54e58
Code cleanup/bug fix
Oct 3, 2023
22e7894
Create compound index as advised.
Oct 4, 2023
22f296c
test gittower
Oct 4, 2023
9568133
test gittower
Oct 4, 2023
e8f3e0c
test gittower
Oct 4, 2023
a4307f5
Update normal path to use mongo if available.
Oct 6, 2023
046e376
change telemetry to not do any work on return data set
Oct 6, 2023
3f1978a
disable all-time
Oct 6, 2023
d6dcef1
disable since telem
Oct 6, 2023
4bc188c
restore all-time/since-last-telemetry
Oct 6, 2023
f23a0f6
Merge branch 'limit-hof' into mongodb-code
Oct 6, 2023
79595b6
Merge branch 'master' into mongodb-code
Oct 6, 2023
ff6a8d9
add save profile file to new route (temp)
Oct 7, 2023
52ee6e3
expand voyage telemetry
Oct 9, 2023
5e93a92
disable all-time
Oct 9, 2023
9f06bb5
remove "all since new telemetry"
Oct 9, 2023
8234df9
try one less query
Oct 9, 2023
a5f4a9f
Change 404 to 204
Oct 12, 2023
3d9fdfc
make routes return normalized output no matter what
Oct 14, 2023
a739fbb
normalize 400 pathways
Oct 14, 2023
ee90d3f
204 is truly empty?
Oct 14, 2023
dd6a548
Fix bug (wrong database)
Oct 14, 2023
4e85cc9
trials
Oct 14, 2023
27063af
add dbid sha256 hash hex digest (expirmental)
Oct 15, 2023
cc28d3e
update route
Oct 15, 2023
2708db0
update timestamp for player refresh
Oct 16, 2023
a719d45
refining remote voyage tracker process
Oct 24, 2023
9ff0495
typo
Oct 27, 2023
171b249
Disable write profile to disk, mongo route
Oct 27, 2023
11b9ff6
Mongo Voyage Telemetry (optional adaptation)
Oct 29, 2023
d190b76
turn back on write to disk on post mongo
Oct 29, 2023
257ac3b
Revert test port #
Oct 29, 2023
a8a5f3d
Disable write to disk on mongo route, again
Oct 29, 2023
350dbf2
restore file write (for sqlite-based bot testing)
Nov 1, 2023
e6438f5
Continuum missions model
Nov 7, 2023
e155684
Add bonuses to mission reward model
Nov 7, 2023
ad04ca4
Merge branch 'master' into mongodb-code
Nov 7, 2023
4d31e6a
Model updates
Nov 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ STT_BOT_USERNAME=
STT_BOT_PASSWORD=
JWT_SECRET=
DB_CONNECTION_STRING=postgres://...
MONGO_CONN_STRING=mongodb://admin:secret@localhost
MONGO_DB_NAME=datacore
MONGO_PROFILE_COLLECTION=playerProfiles
MONGO_TRACKED_VOYAGES_COLLECTION=trackedVoyages
MONGO_TRACKED_ASSIGNMENTS_COLLECTION=trackedAssignments
MONGO_TELEMETRY_VOYAGE_COLLECTION=telemetry
MONGO_FBB_SOLVES_COLLECTION=solves
MONGO_FBB_TRIALS_COLLECTION=trials
MONGO_FBB_COLLECTION=bossBattles
MONGO_DISCORD_USERS_COLLECTION=discordUsers
CORS_ORIGIN=https://datacore.app/
PROFILE_DATA_PATH=static
LOG_PATH=
294 changes: 293 additions & 1 deletion app/controllers/api.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Router, Request, Response } from 'express';
import { DataCoreAPI, LogData } from '../logic';
import { ApiResult, DataCoreAPI, LogData } from '../logic';
import { PlayerData } from '../datacore/player';
import { ITrackedAssignment, ITrackedVoyage } from '../datacore/voyage';
import { IFBB_BossBattle_Document } from '../mongoModels/playerCollab';
import { CrewTrial, Solve } from '../datacore/boss';

// Assign router to the express.Router() instance
const router: Router = Router();
Expand Down Expand Up @@ -174,6 +178,294 @@ router.post('/telemetry', async (req: Request, res: Response, next) => {
});


/** MongoDB-connected routes */

router.get('/queryAlive', async (req: Request, res: Response, next) => {
if (!req.query || !req.query.what) {
res.status(400).send('Whaat?');
return;
}

try {
let apiResult = {
Status: 200,
Body: {
service: req.query.what,
result: "UP"
}
}

if (req.query.what === 'mongodb') {
if (!DataCoreAPI.mongoAvailable) {
apiResult.Status = 503;
apiResult.Body.result = "DOWN";
}
}

res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});


router.post('/postProfile', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}
try {
let playerData = req.body as PlayerData;
let apiResult = await DataCoreAPI.mongoPostPlayerData(playerData.player.dbid, playerData, getLogDataFromReq(req));
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.get('/getProfile', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.dbid && !req.query.dbidhash)) {
res.status(400).send('Whaat?');
return;
}

try {
let apiResult: ApiResult | undefined = undefined;

if (req.query.dbid) {
apiResult = await DataCoreAPI.mongoGetPlayerData(Number.parseInt(req.query.dbid.toString()));
}
else if (req.query.dbidhash) {
apiResult = await DataCoreAPI.mongoGetPlayerData(undefined, req.query.dbidhash.toString());
}
if (apiResult) {
res.status(apiResult.Status).send(apiResult.Body);
}
else {
res.status(500).send();
}
} catch (e) {
next(e);
}
});

router.get('/getProfiles', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.fleet && !req.query.squadron )) {
res.status(400).send('Whaat?');
return;
}

try {
let fleet = req.query?.fleet ? Number.parseInt(req.query.fleet.toString()) : undefined;
let squadron = req.query?.squadron ? Number.parseInt(req.query.squadron.toString()) : undefined;
let apiResult = await DataCoreAPI.mongoGetManyPlayers(fleet, squadron);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.post('/postVoyage', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}
try {
let dbid = req.body.dbid;
let voyage = req.body.voyage as ITrackedVoyage;
let apiResult = await DataCoreAPI.mongoPostTrackedVoyage(dbid, voyage, getLogDataFromReq(req));
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.get('/getVoyages', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.dbid && !req.query.trackerId )) {
res.status(400).send('Whaat?');
return;
}

try {
let dbid = req.query?.dbid ? Number.parseInt(req.query.dbid.toString()) : undefined;
let trackerId = req.query?.trackerId ? Number.parseInt(req.query.trackerId.toString()) : undefined;
let apiResult = await DataCoreAPI.mongoGetTrackedVoyages(dbid, trackerId);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.post('/postAssignment', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}

try {
let dbid = req.body.dbid;
let crew = req.body.crew;
let assignment = req.body.assignment as ITrackedAssignment;
let apiResult = await DataCoreAPI.mongoPostTrackedAssignment(dbid, crew, assignment, getLogDataFromReq(req));
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.post('/postAssignments', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}

try {
let dbid = req.body.dbid;
let assign = req.body.assignments as { [key: string]: ITrackedAssignment[] };
let crew = Object.keys(assign);
let assignmap = Object.values(assign);
let assignments = [] as ITrackedAssignment[];
let finalcrew = [] as string[];
let x = 0;

for (let a1 of assignmap) {
let symbol = crew[x];
for (let a2 of a1) {
assignments.push(a2);
finalcrew.push(symbol);
}
x++;
}

let apiResult = await DataCoreAPI.mongoPostTrackedAssignmentsMany(dbid, finalcrew, assignments, getLogDataFromReq(req));
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.get('/getAssignments', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.dbid && !req.query.trackerId )) {
res.status(400).send('Whaat?');
return;
}

try {
let dbid = req.query?.dbid ? Number.parseInt(req.query.dbid.toString()) : undefined;
let trackerId = req.query?.trackerId ? Number.parseInt(req.query.trackerId.toString()) : undefined;
let apiResult = await DataCoreAPI.mongoGetTrackedVoyages(dbid, trackerId);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.get('/getTrackedData', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.dbid && !req.query.trackerId )) {
res.status(400).send('Whaat?');
return;
}

try {
let dbid = req.query?.dbid ? Number.parseInt(req.query.dbid.toString()) : undefined;
let trackerId = req.query?.trackerId ? Number.parseInt(req.query.trackerId.toString()) : undefined;
let apiResult = await DataCoreAPI.mongoGetTrackedData(dbid, trackerId);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.post('/postBossBattle', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}

try {
if ("id" in req.body) {
req.body.bossBattleId = req.body.id;
delete req.body.id;
}
let battle = req.body as IFBB_BossBattle_Document;
let apiResult = await DataCoreAPI.mongoPostBossBattle(battle);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});


router.post('/postBossBattleSolves', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}

try {
let bossBattleId = req.body.bossBattleId as number;
let chainIndex = req.body.chainIndex as number;
let solves = req.body.solves as Solve[];

if (!bossBattleId || !chainIndex || !solves) {
res.status(400).send("Bad data");
}

let apiResult = await DataCoreAPI.mongoPostSolves(bossBattleId, chainIndex, solves);

res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

router.post('/postBossBattleTrials', async (req: Request, res: Response, next) => {
if (!req.body) {
res.status(400).send('Whaat?');
return;
}

try {
let bossBattleId = req.body.bossBattleId as number;
let chainIndex = req.body.chainIndex as number;
let trials = req.body.trials as CrewTrial[];

if (!bossBattleId || !chainIndex || !trials) {
res.status(400).send("Bad data");
}

let apiResult = await DataCoreAPI.mongoPostTrials(bossBattleId, chainIndex, trials);

res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});


router.get('/getBossBattle', async (req: Request, res: Response, next) => {
if (!req.query || (!req.query.room && !req.query.id )) {
res.status(400).send('Whaat?');
return;
}

try {
let room = undefined as string | undefined;
let id = undefined as number | undefined;

if (req.query.room) {
room = req.query.room as string;
}
if (req.query.id) {
id = Number.parseInt(req.query.id as string);
}

let apiResult = await DataCoreAPI.mongoGetCollaboration(id, room);
res.status(apiResult.Status).send(apiResult.Body);
} catch (e) {
next(e);
}
});

// Export the express.Router() instance to be used by server.ts
export const ApiController: Router = router;
62 changes: 62 additions & 0 deletions app/datacore/archetype.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Icon } from "./game-elements"

export interface ArchetypeRoot20 {
archetypes: Archetype20[]
}

export interface ArchetypeRoot17 {
archetypes: Archetype17[]
}

export interface ArchetypeBase {
id: number;
type: string | number;
symbol: string;
name: string;
icon: Icon;
flavor: string;
rarity: number;
recipe?: ArchetypeRecipe;
item_sources: ItemSource[];
bonuses?: ArchetypeBonus;
short_name?: string;
}

export interface Archetype20 extends ArchetypeBase {
type: string;
item_type: number;
}

export interface Archetype17 extends ArchetypeBase {
type: number;
}

export interface ArchetypeRecipe {
demands: ArchetypeDemand[]
validity_hash: string
}

export interface ArchetypeDemand {
archetype_id: number
count: number
}

export interface ItemSource {
challenge_id?: number
challenge_skill?: string
challenge_difficulty?: number
type: number
id: number
name: string
energy_quotient: number
chance_grade: number
place?: string
mission?: number
dispute?: number
mastery?: number
}

export interface ArchetypeBonus {
[key: string]: number | undefined;
}

Loading