Compare commits

..

7 Commits

Author SHA1 Message Date
a7f252468a consider that research may be completed by lowering tier
All checks were successful
Build / build (18) (push) Successful in 1m18s
Build / build (22) (push) Successful in 1m21s
Build / build (22) (pull_request) Successful in 1m22s
Build / build (20) (push) Successful in 44s
Build / build (18) (pull_request) Successful in 45s
Build / build (20) (pull_request) Successful in 1m14s
2025-03-30 13:41:42 +02:00
fec842f4f9 ignore fully funded projects 2025-03-30 13:41:42 +02:00
03adbc2420 adjust research costs based on new tier 2025-03-30 13:41:42 +02:00
da89f38b42 add 'addVaultMiscItems' utility 2025-03-30 13:41:29 +02:00
93a5d5322c update clan tier from barracks being built & destroyed 2025-03-30 13:41:23 +02:00
86ea01483b scale guild resource costs based on tier 2025-03-30 13:41:22 +02:00
f7ada5a7e5 chore: delete guild when founding warlord leaves (#1371)
All checks were successful
Build / build (18) (push) Successful in 46s
Build / build (22) (push) Successful in 1m16s
Build / build (20) (push) Successful in 1m10s
Build Docker image / docker (push) Successful in 35s
Reviewed-on: #1371
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-03-30 04:40:00 -07:00
4 changed files with 68 additions and 45 deletions

View File

@ -32,7 +32,7 @@ export const abortDojoComponentController: RequestHandler = async (req, res) =>
if (request.DecoId) {
removeDojoDeco(guild, request.ComponentId, request.DecoId);
} else {
removeDojoRoom(guild, request.ComponentId);
await removeDojoRoom(guild, request.ComponentId);
}
await guild.save();

View File

@ -1,7 +1,7 @@
import { GuildMember } from "@/src/models/guildModel";
import { Inbox } from "@/src/models/inboxModel";
import { Account } from "@/src/models/loginModel";
import { getGuildForRequest, hasGuildPermission } from "@/src/services/guildService";
import { deleteGuild, getGuildForRequest, hasGuildPermission } from "@/src/services/guildService";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
import { GuildPermission } from "@/src/types/guildTypes";
@ -18,50 +18,54 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
}
const guildMember = (await GuildMember.findOne({ accountId: payload.userId, guildId: guild._id }))!;
if (guildMember.status == 0) {
const inventory = await getInventory(payload.userId);
inventory.GuildId = undefined;
// Remove clan key or blueprint from kicked member
const itemIndex = inventory.LevelKeys.findIndex(x => x.ItemType == "/Lotus/Types/Keys/DojoKey");
if (itemIndex != -1) {
inventory.LevelKeys.splice(itemIndex, 1);
} else {
const recipeIndex = inventory.Recipes.findIndex(x => x.ItemType == "/Lotus/Types/Keys/DojoKeyBlueprint");
if (recipeIndex != -1) {
inventory.Recipes.splice(recipeIndex, 1);
}
}
await inventory.save();
// TODO: Handle clan leader kicking themselves (guild should be deleted in this case, I think)
} else if (guildMember.status == 2) {
// Delete the inbox message for the invite
await Inbox.deleteOne({
ownerId: guildMember.accountId,
contextInfo: guild._id.toString(),
acceptAction: "GUILD_INVITE"
});
}
await GuildMember.deleteOne({ _id: guildMember._id });
guild.RosterActivity ??= [];
if (isKick) {
const kickee = (await Account.findById(payload.userId))!;
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 12,
details: getSuffixedName(kickee) + "," + getSuffixedName(account)
});
if (guildMember.rank == 0) {
await deleteGuild(guild._id);
} else {
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 7,
details: getSuffixedName(account)
});
if (guildMember.status == 0) {
const inventory = await getInventory(payload.userId);
inventory.GuildId = undefined;
// Remove clan key or blueprint from kicked member
const itemIndex = inventory.LevelKeys.findIndex(x => x.ItemType == "/Lotus/Types/Keys/DojoKey");
if (itemIndex != -1) {
inventory.LevelKeys.splice(itemIndex, 1);
} else {
const recipeIndex = inventory.Recipes.findIndex(
x => x.ItemType == "/Lotus/Types/Keys/DojoKeyBlueprint"
);
if (recipeIndex != -1) {
inventory.Recipes.splice(recipeIndex, 1);
}
}
await inventory.save();
} else if (guildMember.status == 2) {
// Delete the inbox message for the invite
await Inbox.deleteOne({
ownerId: guildMember.accountId,
contextInfo: guild._id.toString(),
acceptAction: "GUILD_INVITE"
});
}
await GuildMember.deleteOne({ _id: guildMember._id });
guild.RosterActivity ??= [];
if (isKick) {
const kickee = (await Account.findById(payload.userId))!;
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 12,
details: getSuffixedName(kickee) + "," + getSuffixedName(account)
});
} else {
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 7,
details: getSuffixedName(account)
});
}
await guild.save();
}
await guild.save();
res.json({
_id: payload.userId,

View File

@ -9,10 +9,17 @@ import { Ship } from "@/src/models/shipModel";
import { Stats } from "@/src/models/statsModel";
import { GuildMember } from "@/src/models/guildModel";
import { Leaderboard } from "@/src/models/leaderboardModel";
import { deleteGuild } from "@/src/services/guildService";
export const deleteAccountController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
// TODO: Handle the account being the creator of a guild
// If account is the founding warlord of a guild, delete that guild as well.
const guildMember = await GuildMember.findOne({ accountId, rank: 0, status: 0 });
if (guildMember) {
await deleteGuild(guildMember.guildId);
}
await Promise.all([
Account.deleteOne({ _id: accountId }),
GuildMember.deleteMany({ accountId: accountId }),

View File

@ -23,6 +23,7 @@ import { logger } from "../utils/logger";
import { config } from "./configService";
import { Account } from "../models/loginModel";
import { getRandomInt } from "./rngService";
import { Inbox } from "../models/inboxModel";
import { ITypeCount } from "../types/inventoryTypes/inventoryTypes";
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
@ -497,3 +498,14 @@ const setGuildTier = async (guild: TGuildDatabaseDocument, newTier: number): Pro
}
}
};
export const deleteGuild = async (guildId: Types.ObjectId): Promise<void> => {
await Guild.deleteOne({ _id: guildId });
await GuildMember.deleteMany({ guildId });
// If guild sent any invites, delete those inbox messages as well.
await Inbox.deleteMany({
contextInfo: guildId.toString(),
acceptAction: "GUILD_INVITE"
});
};