feat: Adding the name of capturers of planets + displaying usernames for each team
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
getDbCreatedAt,
|
||||
getVictoryPoints,
|
||||
getActivePlayerCounts,
|
||||
getActivePlayerIds,
|
||||
getMilitaryDeductions,
|
||||
addMilitaryDeduction,
|
||||
recordCellAttack,
|
||||
@@ -37,6 +38,7 @@ import {
|
||||
getUserActionsRow,
|
||||
resetUserActions,
|
||||
decrementUserActions,
|
||||
getUsersByIds,
|
||||
} from "../db/usersDb.js";
|
||||
import { computeCell, rowToCellPayload } from "../helpers/cell.js";
|
||||
import { computeTeamMilitaryPower } from "../helpers/economy.js";
|
||||
@@ -252,7 +254,7 @@ router.post("/cell/capture", authMiddleware, async (req, res) => {
|
||||
}
|
||||
|
||||
// Transfer ownership to capturing team
|
||||
await setTileOwner(worldSeed, x, y, team);
|
||||
await setTileOwner(worldSeed, x, y, team, req.user.username);
|
||||
|
||||
const updatedCell = await getExistingCell(worldSeed, x, y);
|
||||
const updatedTeamRow = await getTeamActionsRow(team);
|
||||
@@ -391,6 +393,24 @@ router.get("/active-players", async (_req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/active-players/names
|
||||
router.get("/active-players/names", async (_req, res) => {
|
||||
try {
|
||||
const worldSeed = await ensureSeedEpoch();
|
||||
const playerIds = await getActivePlayerIds(worldSeed);
|
||||
const allIds = [...playerIds.blue, ...playerIds.red];
|
||||
const users = await getUsersByIds(allIds);
|
||||
const result = { blue: [], red: [] };
|
||||
for (const user of users) {
|
||||
if (result[user.team]) result[user.team].push(user.username);
|
||||
}
|
||||
res.json(result);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.status(500).json({ error: "database_error" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/scores
|
||||
router.get("/scores", async (_req, res) => {
|
||||
try {
|
||||
@@ -449,7 +469,7 @@ router.post("/military/attack", authMiddleware, async (req, res) => {
|
||||
await addMilitaryDeduction(worldSeed, attackingTeam, COST_BILLIONS);
|
||||
|
||||
// Transfer tile ownership to the attacking team
|
||||
await setTileOwner(worldSeed, x, y, attackingTeam);
|
||||
await setTileOwner(worldSeed, x, y, attackingTeam, req.user.username);
|
||||
|
||||
// Record the attack event
|
||||
await recordCellAttack(worldSeed, x, y, attackingTeam);
|
||||
|
||||
Reference in New Issue
Block a user