Skip to content

Commit

Permalink
Tag banned players and prevent them from playing #2482 #2289
Browse files Browse the repository at this point in the history
  • Loading branch information
Feiryn committed Jan 26, 2025
1 parent 697e41f commit c23a689
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Core/src/core/database/game/migrations/019-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function up({context}: { context: QueryInterface }): Promise<void>
[Op.lt]: 100
},
effectEndDate: {
[Op.lt]: new Date(2050, 1, 1)
[Op.lt]: new Date(2050, 0, 1)
}
});

Expand Down
22 changes: 22 additions & 0 deletions Core/src/core/database/game/migrations/024-v5-banned-players.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {DataTypes, Op, QueryInterface} from "sequelize";

export async function up({context}: { context: QueryInterface }): Promise<void> {
await context.addColumn("players", "banned", {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
});

await context.bulkUpdate("players", {
banned: true
}, {
score: 0,
effectEndDate: {
[Op.gt]: new Date(2050, 0, 1)
}
});
}

export async function down({context}: { context: QueryInterface }): Promise<void> {
await context.removeColumn("players", "banned");
}
6 changes: 6 additions & 0 deletions Core/src/core/database/game/models/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export class Player extends Model {

declare rage: number;

declare banned: boolean;

declare updatedAt: Date;

declare createdAt: Date;
Expand Down Expand Up @@ -1516,6 +1518,10 @@ export function initModel(sequelize: Sequelize): void {
type: DataTypes.INTEGER,
defaultValue: 0
},
banned: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: moment()
Expand Down
7 changes: 7 additions & 0 deletions Core/src/core/utils/CommandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {RequirementGuildRolePacket} from "../../../../Lib/src/packets/commands/r
import {RequirementRightPacket} from "../../../../Lib/src/packets/commands/requirements/RequirementRightPacket";
import {BlockingUtils} from "./BlockingUtils";
import {draftBotInstance} from "../../index";
import {ErrorBannedPacket} from "../../../../Lib/src/packets/commands/ErrorPacket";

type Requirements = {
disallowedEffects?: Effect[];
Expand Down Expand Up @@ -190,6 +191,12 @@ export const commandRequires = <T extends DraftBotPacket>(packet: PacketLike<T>,
(target: unknown, prop: string, descriptor: TypedPropertyDescriptor<WithPlayerPacketListenerCallbackServer<T>>): void => {
draftBotInstance.packetListener.addPacketListener<T>(packet, async (response: DraftBotPacket[], packet: T, context: PacketContext): Promise<void> => {
const player = await Players.getOrRegister(context.keycloakId);

if (player.banned) {
response.push(makePacket(ErrorBannedPacket, {}));
return;
}

// Warning: order of the checks is important, as appendBlockedPacket can add a packet to the response
if (requirements.notBlocked && BlockingUtils.appendBlockedPacket(player, response)) {
return;
Expand Down
8 changes: 7 additions & 1 deletion Discord/src/packetHandlers/handlers/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {packetHandler} from "../PacketHandler";
import {PacketContext} from "../../../../Lib/src/packets/DraftBotPacket";
import {DiscordCache} from "../../bot/DiscordCache";
import i18n from "../../translations/i18n";
import {ErrorMaintenancePacket, ErrorPacket} from "../../../../Lib/src/packets/commands/ErrorPacket";
import {ErrorBannedPacket, ErrorMaintenancePacket, ErrorPacket} from "../../../../Lib/src/packets/commands/ErrorPacket";
import {DraftBotEmbed} from "../../messages/DraftBotEmbed";
import {BlockedPacket} from "../../../../Lib/src/packets/commands/BlockedPacket";
import {KeycloakUtils} from "../../../../Lib/src/keycloak/KeycloakUtils";
import {keycloakConfig} from "../../bot/DraftBotShard";
import {LANGUAGE} from "../../../../Lib/src/Language";
import {handleClassicError} from "../../utils/ErrorUtils";

export default class ErrorHandler {
@packetHandler(ErrorPacket)
Expand Down Expand Up @@ -81,4 +82,9 @@ export default class ErrorHandler {
await interaction?.channel.send({embeds: [embed]});
}
}

@packetHandler(ErrorBannedPacket)
async bannedHandler(context: PacketContext, _packet: ErrorBannedPacket): Promise<void> {
await handleClassicError(context, "error:banned");
}
}
3 changes: 2 additions & 1 deletion Lang/fr/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@
"errorOccurredTitle": "Une erreur est survenue",
"errorOccurred": "Une erreur est survenue lors de l'exécution de cette commande :(\n\nMerci de rapporter ce problème à un membre de l'équipe, en précisant l'heure ainsi que le serveur sur lequel vous avez rencontré ce problème.\n\nN'hésitez pas à rejoindre notre serveur de support pour obtenir de l'aide : https://discord.gg/5JqrMtZ",
"maintenanceTitle": "Maintenance",
"maintenance": "Le jeu est actuellement en maintenance, veuillez réessayer plus tard.\n\nPour plus d'informations, rendez-vous sur le serveur Discord officiel : https://discord.gg/AP3Wmzb"
"maintenance": "Le jeu est actuellement en maintenance, veuillez réessayer plus tard.\n\nPour plus d'informations, rendez-vous sur le serveur Discord officiel : https://discord.gg/AP3Wmzb",
"banned": "Vous avez été banni du jeu."
}
5 changes: 4 additions & 1 deletion Lib/src/packets/commands/ErrorPacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export class ErrorPacket extends DraftBotPacket {
}

@sendablePacket(PacketDirection.BACK_TO_FRONT)
export class ErrorMaintenancePacket extends DraftBotPacket {}
export class ErrorMaintenancePacket extends DraftBotPacket {}

@sendablePacket(PacketDirection.BACK_TO_FRONT)
export class ErrorBannedPacket extends DraftBotPacket {}

0 comments on commit c23a689

Please sign in to comment.