From 14c159c1640f1faa3c9ddb5972f40922bea9dcf3 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Mon, 20 Oct 2025 19:08:55 +0200 Subject: [PATCH] Setup/Factions * fix switched base rep field indizes, causing Profiler to miscalculate character standing * replace hardcoded sql table prefixes --- includes/components/profiler.class.php | 8 ++-- setup/sql/01-db_structure.sql | 2 +- setup/sql/updates/1760979719_01.sql | 8 ++++ setup/tools/clisetup/dbconfig.us.php | 4 +- setup/tools/sqlgen/factions.ss.php | 52 +++++++++++++------------- setup/tools/sqlgen/source.ss.php | 4 +- 6 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 setup/sql/updates/1760979719_01.sql diff --git a/includes/components/profiler.class.php b/includes/components/profiler.class.php index 91240710..13e432e8 100644 --- a/includes/components/profiler.class.php +++ b/includes/components/profiler.class.php @@ -703,10 +703,10 @@ class Profiler // get base values for this race/class $reputation = []; $baseRep = DB::Aowow()->selectCol( - 'SELECT `id` AS ARRAY_KEY, `baseRepValue1` FROM aowow_factions WHERE `baseRepValue1` AND (`baseRepRaceMask1` & ?d OR (`baseRepClassMask1` AND NOT `baseRepRaceMask1`)) AND ((`baseRepClassMask1` & ?d) OR NOT `baseRepClassMask1`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue2` FROM aowow_factions WHERE `baseRepValue2` AND (`baseRepRaceMask2` & ?d OR (`baseRepClassMask2` AND NOT `baseRepRaceMask2`)) AND ((`baseRepClassMask2` & ?d) OR NOT `baseRepClassMask2`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue3` FROM aowow_factions WHERE `baseRepValue3` AND (`baseRepRaceMask3` & ?d OR (`baseRepClassMask3` AND NOT `baseRepRaceMask3`)) AND ((`baseRepClassMask3` & ?d) OR NOT `baseRepClassMask3`) UNION - SELECT `id` AS ARRAY_KEY, `baseRepValue4` FROM aowow_factions WHERE `baseRepValue4` AND (`baseRepRaceMask4` & ?d OR (`baseRepClassMask4` AND NOT `baseRepRaceMask4`)) AND ((`baseRepClassMask4` & ?d) OR NOT `baseRepClassMask4`)', + 'SELECT `id` AS ARRAY_KEY, `baseRepValue1` FROM ?_factions WHERE `baseRepValue1` AND (`baseRepRaceMask1` & ?d OR (`baseRepClassMask1` AND NOT `baseRepRaceMask1`)) AND ((`baseRepClassMask1` & ?d) OR NOT `baseRepClassMask1`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue2` FROM ?_factions WHERE `baseRepValue2` AND (`baseRepRaceMask2` & ?d OR (`baseRepClassMask2` AND NOT `baseRepRaceMask2`)) AND ((`baseRepClassMask2` & ?d) OR NOT `baseRepClassMask2`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue3` FROM ?_factions WHERE `baseRepValue3` AND (`baseRepRaceMask3` & ?d OR (`baseRepClassMask3` AND NOT `baseRepRaceMask3`)) AND ((`baseRepClassMask3` & ?d) OR NOT `baseRepClassMask3`) UNION + SELECT `id` AS ARRAY_KEY, `baseRepValue4` FROM ?_factions WHERE `baseRepValue4` AND (`baseRepRaceMask4` & ?d OR (`baseRepClassMask4` AND NOT `baseRepRaceMask4`)) AND ((`baseRepClassMask4` & ?d) OR NOT `baseRepClassMask4`)', $ra->toMask(), $cl->toMask(), $ra->toMask(), $cl->toMask(), $ra->toMask(), $cl->toMask(), $ra->toMask(), $cl->toMask() ); diff --git a/setup/sql/01-db_structure.sql b/setup/sql/01-db_structure.sql index 04e310c6..dcd90ea8 100644 --- a/setup/sql/01-db_structure.sql +++ b/setup/sql/01-db_structure.sql @@ -863,8 +863,8 @@ CREATE TABLE `aowow_factions` ( `baseRepClassMask4` mediumint(8) unsigned NOT NULL, `baseRepValue1` mediumint(9) NOT NULL, `baseRepValue2` mediumint(9) NOT NULL, - `baseRepValue4` mediumint(9) NOT NULL, `baseRepValue3` mediumint(9) NOT NULL, + `baseRepValue4` mediumint(9) NOT NULL, `side` tinyint(3) unsigned NOT NULL, `expansion` tinyint(3) unsigned NOT NULL, `qmNpcIds` varchar(12) NOT NULL COMMENT 'space separated', diff --git a/setup/sql/updates/1760979719_01.sql b/setup/sql/updates/1760979719_01.sql new file mode 100644 index 00000000..c2bbcf7a --- /dev/null +++ b/setup/sql/updates/1760979719_01.sql @@ -0,0 +1,8 @@ +ALTER TABLE `aowow_factions` + DROP COLUMN `baseRepValue3`, + DROP COLUMN `baseRepValue4`, + ADD COLUMN `baseRepValue3` mediumint(9) NOT NULL AFTER `baseRepValue2`, + ADD COLUMN `baseRepValue4` mediumint(9) NOT NULL AFTER `baseRepValue3` +; + +UPDATE `aowow_dbversion` SET `sql` = CONCAT(IFNULL(`sql`, ''), ' factions'); diff --git a/setup/tools/clisetup/dbconfig.us.php b/setup/tools/clisetup/dbconfig.us.php index 3bc433df..c69a8a88 100644 --- a/setup/tools/clisetup/dbconfig.us.php +++ b/setup/tools/clisetup/dbconfig.us.php @@ -216,7 +216,7 @@ CLISetup::registerUtility(new class extends UtilityScript switch ($idx) { case DB_AOWOW: - if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', 'aowow_dbversion')) + if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', '?_dbversion')) Cfg::load(); // first time load after successful db setup else $error[] = ' * '.$what.': doesn\'t seem to contain aowow tables!'; @@ -255,7 +255,7 @@ CLISetup::registerUtility(new class extends UtilityScript switch ($idx) { case DB_AOWOW: - if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', 'aowow_dbversion')) + if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', '?_dbversion')) { if ($date = DB::Aowow()->selectCell('SELECT `date` FROM ?_dbversion')) { diff --git a/setup/tools/sqlgen/factions.ss.php b/setup/tools/sqlgen/factions.ss.php index 7fb7e001..2b0025a4 100644 --- a/setup/tools/sqlgen/factions.ss.php +++ b/setup/tools/sqlgen/factions.ss.php @@ -26,47 +26,47 @@ CLISetup::registerSetup("sql", new class extends SetupScript DB::Aowow()->query( 'INSERT INTO ?_factions - SELECT f.id, - f.repIdx, - baseRepRaceMask1, baseRepRaceMask2, baseRepRaceMask3, baseRepRaceMask4, - baseRepClassMask1, baseRepClassMask2, baseRepClassMask3, baseRepClassMask4, - baseRepValue1, baseRepValue2, baseRepValue3, baseRepValue4, - IF(SUM(ft.ourMask & 0x6) / COUNT(1) = 0x4, 2, IF(SUM(ft.ourMask & 0x6) / COUNT(1) = 0x2, 1, 0)) as side, + SELECT f.`id`, + f.`repIdx`, + `baseRepRaceMask1`, `baseRepRaceMask2`, `baseRepRaceMask3`, `baseRepRaceMask4`, + `baseRepClassMask1`, `baseRepClassMask2`, `baseRepClassMask3`, `baseRepClassMask4`, + `baseRepValue1`, `baseRepValue2`, `baseRepValue3`, `baseRepValue4`, + IF(SUM(ft.`ourMask` & 0x6) / COUNT(1) = 0x4, 2, IF(SUM(ft.`ourMask` & 0x6) / COUNT(1) = 0x2, 1, 0)) AS "side", 0, -- expansion "", -- quartermasterNpcIds "", -- factionTemplateIds 0, -- cuFlags - parentFaction, - spilloverRateIn, spilloverRateOut, spilloverMaxRank, - name_loc0, name_loc2, name_loc3, name_loc4, name_loc6, name_loc8 + `parentFaction`, + `spilloverRateIn`, `spilloverRateOut`, `spilloverMaxRank`, + `name_loc0`, `name_loc2`, `name_loc3`, `name_loc4`, `name_loc6`, `name_loc8` FROM dbc_faction f - LEFT JOIN dbc_factiontemplate ft ON ft.factionid = f.id - GROUP BY f.id' + LEFT JOIN dbc_factiontemplate ft ON ft.`factionid` = f.`id` + GROUP BY f.`id`' ); DB::Aowow()->query( 'INSERT INTO ?_factiontemplate - SELECT id, - factionId, - IF(friendFactionId1 = 1 OR friendFactionId2 = 1 OR friendFactionId3 = 1 OR friendFactionId4 = 1 OR friendlyMask & 0x3, 1, - IF(enemyFactionId1 = 1 OR enemyFactionId2 = 1 OR enemyFactionId3 = 1 OR enemyFactionId4 = 1 OR hostileMask & 0x3, -1, 0)), - IF(friendFactionId1 = 2 OR friendFactionId2 = 2 OR friendFactionId3 = 2 OR friendFactionId4 = 2 OR friendlyMask & 0x5, 1, - IF(enemyFactionId1 = 2 OR enemyFactionId2 = 2 OR enemyFactionId3 = 2 OR enemyFactionId4 = 2 OR hostileMask & 0x5, -1, 0)) + SELECT `id`, + `factionId`, + IF(`friendFactionId1` = 1 OR `friendFactionId2` = 1 OR `friendFactionId3` = 1 OR `friendFactionId4` = 1 OR `friendlyMask` & 0x3, 1, + IF(`enemyFactionId1` = 1 OR `enemyFactionId2` = 1 OR `enemyFactionId3` = 1 OR `enemyFactionId4` = 1 OR `hostileMask` & 0x3, -1, 0)), + IF(`friendFactionId1` = 2 OR `friendFactionId2` = 2 OR `friendFactionId3` = 2 OR `friendFactionId4` = 2 OR `friendlyMask` & 0x5, 1, + IF(`enemyFactionId1` = 2 OR `enemyFactionId2` = 2 OR `enemyFactionId3` = 2 OR `enemyFactionId4` = 2 OR `hostileMask` & 0x5, -1, 0)) FROM dbc_factiontemplate' ); DB::Aowow()->query( 'UPDATE ?_factions f - JOIN (SELECT ft.factionId, GROUP_CONCAT(ft.id SEPARATOR " ") AS tplIds FROM dbc_factiontemplate ft GROUP BY ft.factionId) temp ON f.id = temp.factionId - SET f.templateIds = temp.tplIds' + JOIN (SELECT ft.`factionId`, GROUP_CONCAT(ft.`id` SEPARATOR " ") AS "tplIds" FROM dbc_factiontemplate ft GROUP BY ft.`factionId`) temp ON f.`id` = temp.`factionId` + SET f.`templateIds` = temp.`tplIds`' ); DB::Aowow()->query( 'UPDATE ?_factions x - JOIN dbc_faction f ON f.id = x.id - LEFT JOIN dbc_factiontemplate ft ON f.id = ft.factionId - SET cuFlags = cuFlags | ?d - WHERE f.repIdx < 0 OR ( f.repIdx > 0 AND (f.repFlags1 & 0x8 OR ft.id IS NULL) AND (f.repFlags1 & 0x80) = 0 )', + JOIN dbc_faction f ON f.`id` = x.`id` + LEFT JOIN dbc_factiontemplate ft ON f.`id` = ft.`factionId` + SET `cuFlags` = `cuFlags` | ?d + WHERE f.`repIdx` < 0 OR ( f.`repIdx` > 0 AND (f.`repFlags1` & 0x8 OR ft.`id` IS NULL) AND (f.`repFlags1` & 0x80) = 0 )', CUSTOM_EXCLUDE_FOR_LISTVIEW ); @@ -80,10 +80,10 @@ CLISetup::registerSetup("sql", new class extends SetupScript foreach ($pairs as $p) DB::Aowow()->query( 'UPDATE ?_factions top - JOIN (SELECT id, parentFactionId FROM ?_factions) mid ON mid.parentFactionId IN (?a) - LEFT JOIN (SELECT id, parentFactionId FROM ?_factions) low ON low.parentFactionId = mid.id + JOIN (SELECT `id`, `parentFactionId` FROM ?_factions) mid ON mid.`parentFactionId` IN (?a) + LEFT JOIN (SELECT `id`, `parentFactionId` FROM ?_factions) low ON low.`parentFactionId` = mid.`id` SET ?a - WHERE repIdx > 0 AND (top.id IN (?a) OR top.id = mid.id OR top.id = low.id)', + WHERE `repIdx` > 0 AND (top.`id` IN (?a) OR top.`id` = mid.`id` OR top.`id` = low.`id`)', $p[0], $p[1], $p[0] ); diff --git a/setup/tools/sqlgen/source.ss.php b/setup/tools/sqlgen/source.ss.php index ad7816eb..627afed5 100644 --- a/setup/tools/sqlgen/source.ss.php +++ b/setup/tools/sqlgen/source.ss.php @@ -42,8 +42,8 @@ CLISetup::registerSetup("sql", new class extends SetupScript $this->dummyGOs = DB::Aowow()->select( 'SELECT l1.`objectId` AS ARRAY_KEY, BIT_OR(l1.`difficulty`) AS "0", IFNULL(l2.`npcId`, l1.`npcId`) AS "1" - FROM aowow_loot_link l1 - LEFT JOIN aowow_loot_link l2 ON l1.`objectId` = l2.`objectId` AND l2.`priority` = 1 + FROM ?_loot_link l1 + LEFT JOIN ?_loot_link l2 ON l1.`objectId` = l2.`objectId` AND l2.`priority` = 1 GROUP BY l1.`objectid`' );