diff --git a/src/armory/DataTablesSsp.ts b/src/armory/DataTablesSsp.ts index ee8b8e9..6e4732f 100644 --- a/src/armory/DataTablesSsp.ts +++ b/src/armory/DataTablesSsp.ts @@ -23,6 +23,7 @@ export interface IColumnJoin { column2: string; database2?: string; kind: "INNER" | "FULL OUTER" | "LEFT" | "RIGHT"; + where?: string; } export class DataTablesSsp { @@ -130,8 +131,9 @@ export class DataTablesSsp { private join() { for (const join of this.joins) { - const db2 = join.database2 ? "`" + join.database2 + "`." : ""; - this.joinSql += `${join.kind} JOIN ${db2}\`${join.table2}\` ON ${db2}\`${join.table2}\`.\`${join.column2}\` = \`${join.table1}\`.\`${join.column1}\`\n`; + const db2 = join.database2 ? `\`${join.database2}\`.` : ""; + const where = join.where ? ` ${join.where}` : ""; + this.joinSql += `${join.kind} JOIN ${db2}\`${join.table2}\` ON ${db2}\`${join.table2}\`.\`${join.column2}\` = \`${join.table1}\`.\`${join.column1}\`${where}\n`; } return this; diff --git a/src/armory/controllers/CharacterController.ts b/src/armory/controllers/CharacterController.ts index 243c0ac..60a5aeb 100644 --- a/src/armory/controllers/CharacterController.ts +++ b/src/armory/controllers/CharacterController.ts @@ -315,10 +315,10 @@ export class CharacterController { FROM \`characters\` LEFT JOIN \`guild_member\` ON \`guild_member\`.\`guid\` = \`characters\`.\`guid\` LEFT JOIN \`guild\` ON \`guild\`.\`guildid\` = \`guild_member\`.\`guildid\` - LEFT JOIN \`${realm.authDatabase}\`.\`account_access\` ON \`account_access\`.\`id\` = \`characters\`.\`account\` + LEFT JOIN \`${realm.authDatabase}\`.\`account_access\` ON \`account_access\`.\`id\` = \`characters\`.\`account\` AND \`account_access\`.\`RealmID\` IN (-1, ${realm.realmId}) AND \`account_access\`.\`gmlevel\` > 0 WHERE ${where} - AND (\`account_access\`.\`id\` IS NULL OR \`account_access\`.\`RealmID\` NOT IN (-1, ${realm.realmId}) OR \`account_access\`.\`gmlevel\` = 0 OR ? = 0) + AND (\`account_access\`.\`id\` IS NULL OR ? = 0) `, values: [character, this.armory.config.hideGameMasters ? 1 : 0], timeout: this.armory.config.dbQueryTimeout, diff --git a/src/armory/controllers/GuildController.ts b/src/armory/controllers/GuildController.ts index 6296ab5..d5a8c4e 100644 --- a/src/armory/controllers/GuildController.ts +++ b/src/armory/controllers/GuildController.ts @@ -79,10 +79,9 @@ export class GuildController { column2: "id", database2: realm.authDatabase, kind: "LEFT", + where: `AND \`account_access\`.\`RealmID\` IN (-1, ${realm.realmId}) AND \`account_access\`.\`gmlevel\` > 0`, }); - ssp = ssp.where( - `\`account_access\`.\`id\` IS NULL OR \`account_access\`.\`RealmID\` NOT IN (-1, ${realm.realmId}) OR \`account_access\`.\`gmlevel\` = 0`, - ); + ssp = ssp.where("`account_access`.`id` IS NULL"); } const result = await ssp.where("`guildid` = ?", guildId).where("`deleteInfos_Account` IS NULL").run(this.armory.config.dbQueryTimeout); diff --git a/src/armory/controllers/IndexController.ts b/src/armory/controllers/IndexController.ts index 954ad01..43c825c 100644 --- a/src/armory/controllers/IndexController.ts +++ b/src/armory/controllers/IndexController.ts @@ -50,10 +50,9 @@ export class IndexController { column2: "id", database2: realm.authDatabase, kind: "LEFT", + where: `AND \`account_access\`.\`RealmID\` IN (-1, ${realm.realmId}) AND \`account_access\`.\`gmlevel\` > 0`, }); - ssp = ssp.where( - `\`account_access\`.\`id\` IS NULL OR \`account_access\`.\`RealmID\` NOT IN (-1, ${realm.realmId}) OR \`account_access\`.\`gmlevel\` = 0`, - ); + ssp = ssp.where("`account_access`.`id` IS NULL"); } const result = await ssp.where("`deleteInfos_Account` IS NULL").run(this.armory.config.dbQueryTimeout);