From 0f186576d39776ae48bfe5dfb49b87a9a9a95a58 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Wed, 2 Aug 2023 23:29:53 +0200 Subject: [PATCH] Filter/Fixups * fixed wrong indizes for gem color picker in locale 3 (deDE) * fixed interpretation of filter enums. Some are providing their value directly, others have an intermediate key. * createSQLForCriterium is no longer abstract. (was implemented in exactly the same way everywhere) * erronous criteria are now logged and discarded entirely) --- includes/basetype.class.php | 29 +++++++++++++++++++++++----- includes/types/achievement.class.php | 11 ----------- includes/types/areatrigger.class.php | 11 ----------- includes/types/arenateam.class.php | 2 -- includes/types/creature.class.php | 13 +------------ includes/types/enchantment.class.php | 11 ----------- includes/types/gameobject.class.php | 19 ++---------------- includes/types/guild.class.php | 2 -- includes/types/icon.class.php | 11 ----------- includes/types/item.class.php | 13 +------------ includes/types/itemset.class.php | 11 ----------- includes/types/profile.class.php | 11 ----------- includes/types/quest.class.php | 11 ----------- includes/types/sound.class.php | 8 -------- includes/types/spell.class.php | 11 ----------- static/js/locale_dede.js | 4 ++-- 16 files changed, 30 insertions(+), 148 deletions(-) diff --git a/includes/basetype.class.php b/includes/basetype.class.php index cff32184..b6faa392 100644 --- a/includes/basetype.class.php +++ b/includes/basetype.class.php @@ -908,7 +908,7 @@ abstract class Filter [FILTER_CR_FLAG, , , ] # default param2: matchExact [FILTER_CR_NUMERIC, , , ] [FILTER_CR_STRING, , , null] - [FILTER_CR_ENUM, , , ] + [FILTER_CR_ENUM, , , ] # param3 ? cr[2] is val in enum : key in enum [FILTER_CR_STAFFFLAG, , null, null] [FILTER_CR_CALLBACK, , , ] [FILTER_CR_NYI_PH, null, , param2] # mostly 1: to ignore this criterium; 0: to fail the whole query @@ -1072,7 +1072,8 @@ abstract class Filter // criteria foreach ($this->criteriaIterator() as &$_cr) - $this->cndSet[] = $this->createSQLForCriterium($_cr); + if ($cnd = $this->createSQLForCriterium($_cr)) + $this->cndSet[] = $cnd; if ($this->cndSet) array_unshift($this->cndSet, empty($this->fiData['v']['ma']) ? 'AND' : 'OR'); @@ -1514,9 +1515,11 @@ abstract class Filter $result = $this->genericString($gen[1], $cr[2], $gen[2]); break; case FILTER_CR_ENUM: - if (isset($this->enums[$cr[0]][$cr[1]])) + if (!$gen[3] && isset($this->enums[$cr[0]][$cr[1]])) $result = $this->genericEnum($gen[1], $this->enums[$cr[0]][$cr[1]]); - else if (($gen[2] && $cr[1] == FILTER_ENUM_ANY) || ($gen[3] && $cr[1] == FILTER_ENUM_NONE)) + if ($gen[3] && in_array($cr[1], $this->enums[$cr[0]])) + $result = $this->genericEnum($gen[1], $cr[1]); + else if ($gen[2] && ($cr[1] == FILTER_ENUM_ANY || $cr[1] == FILTER_ENUM_NONE)) $result = $this->genericEnum($gen[1], $cr[1]); break; case FILTER_CR_CALLBACK: @@ -1550,7 +1553,23 @@ abstract class Filter /* non-generic values and criteria */ /***********************************/ - abstract protected function createSQLForCriterium(&$cr); + protected function createSQLForCriterium(array &$cr) : array + { + if (!$this->genericFilter) // criteria not in use - no error + return []; + + if (in_array($cr[0], array_keys($this->genericFilter))) + if ($genCr = $this->genericCriterion($cr)) + return $genCr; + + $this->error = true; + trigger_error('Filter::createSQLForCriterium - received unhandled criterium: ["'.$cr[0].'", "'.$cr[1].'", "'.$cr[2].'"]', E_USER_WARNING); + + unset($cr); + + return []; + } + abstract protected function createSQLForValues(); } diff --git a/includes/types/achievement.class.php b/includes/types/achievement.class.php index 41c5b3a3..bc2eb62b 100644 --- a/includes/types/achievement.class.php +++ b/includes/types/achievement.class.php @@ -330,17 +330,6 @@ class AchievementListFilter extends Filter 'maxpt' => [FILTER_V_RANGE, [1, 99], false] // required level max ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if (($genCr = $this->genericCriterion($cr)) !== null) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/areatrigger.class.php b/includes/types/areatrigger.class.php index 90a639d0..4334204b 100644 --- a/includes/types/areatrigger.class.php +++ b/includes/types/areatrigger.class.php @@ -70,17 +70,6 @@ class AreaTriggerListFilter extends Filter 'ty' => [FILTER_V_RANGE, [0, 5], true ] // types ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/arenateam.class.php b/includes/types/arenateam.class.php index 1a141947..84525776 100644 --- a/includes/types/arenateam.class.php +++ b/includes/types/arenateam.class.php @@ -55,8 +55,6 @@ class ArenaTeamListFilter extends Filter 'sv' => [FILTER_V_CALLBACK, 'cbServerCheck', false], // server ); - protected function createSQLForCriterium(&$cr) { } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/creature.class.php b/includes/types/creature.class.php index f4c890cc..995df80c 100644 --- a/includes/types/creature.class.php +++ b/includes/types/creature.class.php @@ -295,7 +295,7 @@ class CreatureListFilter extends Filter 2 => [FILTER_CR_CALLBACK, 'cbHealthMana', 'manaMin', 'manaMax' ], // mana [num] 3 => [FILTER_CR_CALLBACK, 'cbFaction', null, null ], // faction [enum] 5 => [FILTER_CR_FLAG, 'npcflag', NPC_FLAG_REPAIRER ], // canrepair - 6 => [FILTER_CR_ENUM, 's.areaId', ], // foundin + 6 => [FILTER_CR_ENUM, 's.areaId', false, true ], // foundin 7 => [FILTER_CR_CALLBACK, 'cbQuestRelation', 'startsQuests', 0x1 ], // startsquest [enum] 8 => [FILTER_CR_CALLBACK, 'cbQuestRelation', 'endsQuests', 0x2 ], // endsquest [enum] 9 => [FILTER_CR_BOOLEAN, 'lootId', ], // lootable @@ -344,17 +344,6 @@ class CreatureListFilter extends Filter 'rh' => [FILTER_V_LIST, [-1, 0, 1], false] // react horde [int] ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/enchantment.class.php b/includes/types/enchantment.class.php index ebb674ac..b8af0c4d 100644 --- a/includes/types/enchantment.class.php +++ b/includes/types/enchantment.class.php @@ -312,17 +312,6 @@ class EnchantmentListFilter extends Filter 'ty' => [FILTER_V_RANGE, [1, 8], true ] // types ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/gameobject.class.php b/includes/types/gameobject.class.php index 9b9d36e4..e0351b7e 100644 --- a/includes/types/gameobject.class.php +++ b/includes/types/gameobject.class.php @@ -144,15 +144,11 @@ class GameObjectListFilter extends Filter protected $enums = array( 1 => parent::ENUM_ZONE, 16 => parent::ENUM_EVENT, - 50 => array( - null, 1, 2, 3, 4, - 663 => 663, - 883 => 883 - ) + 50 => [1, 2, 3, 4, 663, 883] ); protected $genericFilter = array( - 1 => [FILTER_CR_ENUM, 's.areaId' ], // foundin + 1 => [FILTER_CR_ENUM, 's.areaId', false, true], // foundin 2 => [FILTER_CR_CALLBACK, 'cbQuestRelation', 'startsQuests', 0x1 ], // startsquest [side] 3 => [FILTER_CR_CALLBACK, 'cbQuestRelation', 'endsQuests', 0x2 ], // endsquest [side] 4 => [FILTER_CR_CALLBACK, 'cbOpenable', null, null], // openable [yn] @@ -174,17 +170,6 @@ class GameObjectListFilter extends Filter 'ma' => [FILTER_V_EQUAL, 1, false] // match any / all filter ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCR = $this->genericCriterion($cr)) - return $genCR; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/guild.class.php b/includes/types/guild.class.php index f51fe452..b450875d 100644 --- a/includes/types/guild.class.php +++ b/includes/types/guild.class.php @@ -97,8 +97,6 @@ class GuildListFilter extends Filter 'sv' => [FILTER_V_CALLBACK, 'cbServerCheck', false], // server ); - protected function createSQLForCriterium(&$cr) { } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/icon.class.php b/includes/types/icon.class.php index 756ff07b..7a7dedd3 100644 --- a/includes/types/icon.class.php +++ b/includes/types/icon.class.php @@ -164,17 +164,6 @@ class IconListFilter extends Filter return $ids ? ['id', array_keys($ids), '!'] : [1]; } - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/item.class.php b/includes/types/item.class.php index 154dbd2f..177b0728 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -1889,7 +1889,7 @@ class ItemListFilter extends Filter 88 => [FILTER_CR_CALLBACK, 'cbObtainedBy', 20, null ], // otprospecting [yn] 89 => [FILTER_CR_FLAG, 'flags', ITEM_FLAG_PROSPECTABLE ], // prospectable 90 => [FILTER_CR_CALLBACK, 'cbAvgBuyout', null, null ], // avgbuyout [op] [int] - 91 => [FILTER_CR_ENUM, 'totemCategory' ], // tool + 91 => [FILTER_CR_ENUM, 'totemCategory', false, true ], // tool 92 => [FILTER_CR_CALLBACK, 'cbObtainedBy', 5, null ], // soldbyvendor [yn] 93 => [FILTER_CR_CALLBACK, 'cbObtainedBy', 3, null ], // otpvp [pvp] 94 => [FILTER_CR_NUMERIC, 'is.splpen', NUM_CAST_INT, true ], // splpen @@ -2049,17 +2049,6 @@ class ItemListFilter extends Filter return $this->wtCnd; } - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/itemset.class.php b/includes/types/itemset.class.php index 96827d14..cfd19e48 100644 --- a/includes/types/itemset.class.php +++ b/includes/types/itemset.class.php @@ -204,17 +204,6 @@ class ItemsetListFilter extends Filter 'ta' => [FILTER_V_RANGE, [1, 30], false] // tag / content group ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCR = $this->genericCriterion($cr)) - return $genCR; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/profile.class.php b/includes/types/profile.class.php index 8ba36da6..9c60a3ce 100644 --- a/includes/types/profile.class.php +++ b/includes/types/profile.class.php @@ -308,17 +308,6 @@ class ProfileListFilter extends Filter $this->useLocalList = true; } - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCR = $this->genericCriterion($cr)) - return $genCR; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/quest.class.php b/includes/types/quest.class.php index d1af282e..d5380efd 100644 --- a/includes/types/quest.class.php +++ b/includes/types/quest.class.php @@ -485,17 +485,6 @@ class QuestListFilter extends Filter 'ty' => [FILTER_V_LIST, [0, 1, 21, 41, 62, [81, 85], 88, 89], true ] // type ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/sound.class.php b/includes/types/sound.class.php index 950d3c5a..0248313f 100644 --- a/includes/types/sound.class.php +++ b/includes/types/sound.class.php @@ -101,14 +101,6 @@ class SoundListFilter extends Filter 'ty' => [FILTER_V_LIST, [[1, 4], 6, 9, 10, 12, 13, 14, 16, 17, [19, 23], [25, 31], 50, 52, 53], true ] // type ); - // we have no criteria for this one... - protected function createSQLForCriterium(&$cr) - { - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/includes/types/spell.class.php b/includes/types/spell.class.php index 6f7905c1..a876eaef 100644 --- a/includes/types/spell.class.php +++ b/includes/types/spell.class.php @@ -2547,17 +2547,6 @@ class SpellListFilter extends Filter 'me' => [FILTER_V_RANGE, [1, 31], false] // mechanics ); - protected function createSQLForCriterium(&$cr) - { - if (in_array($cr[0], array_keys($this->genericFilter))) - if ($genCr = $this->genericCriterion($cr)) - return $genCr; - - unset($cr); - $this->error = true; - return [1]; - } - protected function createSQLForValues() { $parts = []; diff --git a/static/js/locale_dede.js b/static/js/locale_dede.js index 12b69525..beb6b531 100644 --- a/static/js/locale_dede.js +++ b/static/js/locale_dede.js @@ -3612,8 +3612,8 @@ var LANG = { [1, "Heilig"], [0, "Physisch"] ], gem: [ - [7, "Ja"], [1, "Meta"], [2, "Rot"], [3, "Gelb"], [4, "Blau"], - [8, "Nein"] + [5, "Ja"], [1, "Meta"], [2, "Rot"], [3, "Gelb"], [4, "Blau"], + [6, "Nein"] ], profession: [ [11, "Ja"], [1, "Alchemie"], [13, "Angeln"], [9, "Bergbau"], [6, "Erste Hilfe"],