Mercurial > hg > batmud > maputils
changeset 2037:e82ba6f55708
Refactor how the location filtering works internally to use proper LOC flags.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 Jan 2019 01:42:39 +0200 |
parents | c596f23908cc |
children | cc15357c6aa6 |
files | www/common.inc.php www/info.php www/latest.php www/level.php www/loc.php www/quests.php www/simple.php www/ss.php |
diffstat | 8 files changed, 62 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/www/common.inc.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/common.inc.php Sat Jan 26 01:42:39 2019 +0200 @@ -24,7 +24,7 @@ define("LOCF_T_TRAINER" , 0x000100); // 'T' Guild trainer define("LOCF_T_FORT" , 0x000200); // 'F' Regions fort define("LOCF_T_MASK" , 0x00fff0); -define("LOCF_MASK" , (LOCF_M_MASK | LOCF_T_MASK)); +define("LOCF_MASK" , (LOCF_M_PCITY | LOCF_M_CITY | LOCF_T_MASK)); // Extra flags define("LOCF_INVIS" , 0x010000); // '-' Invisible marker / Don't show label @@ -45,21 +45,22 @@ define("LTI_NAME_PREFIX" , 0); define("LTI_PAGE_DESC" , 1); define("LTI_MENU_TITLE" , 2); -define("LTI_REGEXP" , 3); +define("LTI_INVERT_FLAGS" , 3); +define("LTI_FLAGS" , 4); $locationTypes = [ -//ID => Loc name prefix, Page description , Menu title , Selector regex - "" => ["" , "ALL" , "EVERYTHING" , ""], - "A" => ["" , "Areas" , "Areas" , ""], - "S" => ["SHRINE" , "Race and other shrines" , "Shrines" , "S"], - "G" => ["GUILD" , "Guilds" , "Guilds" , "G"], - "P" => ["SS" , "Outworld secret societies" , "SS" , "P"], - "M" => ["MONSTER" , "Special outworld monsters" , "Monsters" , "M"], - "c" => ["CITY" , "Major cities" , "Cities" , "c"], - "T" => ["TRAINER" , "Guild trainers" , "Trainers" , "T"], - "C" => ["PCITY" , "Player cities" , "PCities" , "C"], -//"F" => ["FORT" , "Regional Forts" , "Forts" , "F"], +//ID => Loc name prefix, Page description , Menu title , InvFlags, Mask flags + "" => ["" , "ALL" , "EVERYTHING" , TRUE , 0 ], + "A" => ["" , "Areas" , "Areas" , TRUE , LOCF_MASK ], + "S" => ["SHRINE" , "Race and other shrines" , "Shrines" , FALSE , LOCF_T_SHRINE ], + "G" => ["GUILD" , "Guilds" , "Guilds" , FALSE , LOCF_T_GUILD ], + "P" => ["SS" , "Outworld secret societies" , "SS" , FALSE , LOCF_T_SS ], + "M" => ["MONSTER" , "Special outworld monsters" , "Monsters" , FALSE , LOCF_T_MONSTER ], + "c" => ["CITY" , "Major cities" , "Cities" , FALSE , LOCF_M_CITY ], + "T" => ["TRAINER" , "Guild trainers" , "Trainers" , FALSE , LOCF_T_TRAINER ], + "C" => ["PCITY" , "Player cities" , "PCities" , FALSE , LOCF_M_PCITY ], +//"F" => ["FORT" , "Regional Forts" , "Forts" , FALSE , LOCF_T_FORT ], ]; @@ -243,7 +244,7 @@ } -function mpParseLocFile($filename, &$locations, $applyFilter, $filterStr) +function mpParseLocFile($filename, &$locations, $applyFilter, $invertFilter, $filterMask) { global $locationTypes; @@ -322,7 +323,7 @@ // Is the location visible? Does it match the filter, if any? if (($flags & LOCF_INVIS) == 0 && - (!$applyFilter || preg_match("/^[\%\?]*".$filterStr."\$/", $rawflags))) + (!$applyFilter || (($flags & $filterMask) ? TRUE : FALSE) != $invertFilter)) { // Check for duplicate locations if (isset($locations[$id])) @@ -355,8 +356,7 @@ "y" => $record[2], "globalx" => $glx, "globaly" => $gly, - "flags" => $rawflags, - "cflags" => $flags, + "flags" => $flags, "coders" => $coders, "added" => $added, "url" => strlen($record[7]) ? $record[7] : NULL, @@ -375,7 +375,9 @@ } -function mpReadLocationFiles($applyFilter = FALSE, $filterStr = "[^CF]*") +function mpParseLocFiles($applyFilter, + $invertFilter = TRUE, + $filterMask = LOCF_M_PCITY | LOCF_T_FORT) { global $continentList; $locations = []; @@ -383,7 +385,7 @@ foreach ($continentList as $id => $data) { if ($data[CTI_REG_CONT]) - mpParseLocFile($id, $locations, $applyFilter, $filterStr); + mpParseLocFile($id, $locations, $applyFilter, $invertFilter, $filterMask); } return $locations;
--- a/www/info.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/info.php Sat Jan 26 01:42:39 2019 +0200 @@ -36,7 +36,7 @@ $locTable = apcu_fetch("info_locTable"); if (empty($locTable)) { - $locTable = mpReadLocationFiles(); + $locTable = mpParseLocFiles(TRUE); apcu_store("info_locTable", $locTable, 3600); } $wizTable = apcu_fetch("wizTable");
--- a/www/latest.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/latest.php Sat Jan 26 01:42:39 2019 +0200 @@ -4,7 +4,7 @@ require "common.inc.php"; $showAll = isset($_REQUEST["all"]); -$locTable = mpReadLocationFiles(!$showAll, "[^CF]*"); +$locTable = mpParseLocFiles(!$showAll); mpPrintPageHeader($pageTitle." - Latest added locations"); //echo "<div><b>DEVELOPMENT VERSION</b></div>"; @@ -23,6 +23,27 @@ </div> <hr /> <? +function pflags($flags) +{ + switch ($flags & LOCF_M_MASK) + { + case LOCF_M_PCITY: return "pcity"; + case LOCF_M_CITY: return "city"; + default: + switch ($flags & LOCF_T_MASK) + { + case LOCF_T_SHRINE: return "shrine"; + case LOCF_T_GUILD: return "guild"; + case LOCF_T_SS: return "SS"; + case LOCF_T_MONSTER: return "monster"; + case LOCF_T_TRAINER: return "trainer"; + case LOCF_T_FORT: return "fort"; + default: return ""; + } + } +} + + // Compare two location records by addition date timestamp and primary name function locCompare($a, $b) { @@ -82,8 +103,8 @@ " <tr>\n". " <td>".(($iv["added"] <= 0) ? "?" : mpStrFTime($iv["added"]))."</td>\n". " <td class=\"".$iv["continent"]."\">".mpGetMapLink($iv, TRUE)."</td>\n". - ($showAll ? " <th>".$iv["flags"]."</td>\n" : ""). " <td>".$continentList[$iv["continent"]][CTI_NAME]."</td>\n". + ($showAll ? " <th>".pflags($iv["flags"])."</td>\n" : ""). " <td>".implode(", ", $fs)."</td>\n". " <td>".(isset($iv["freeform"]) ? chentities($iv["freeform"]) : "")."</td>\n". " </tr>\n";
--- a/www/level.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/level.php Sat Jan 26 01:42:39 2019 +0200 @@ -7,11 +7,11 @@ if (($hcbat = isset($_GET["hcbat"]))) { $locTable = array(); - mpParseLocFile("hcbat", $locTable, FALSE, ""); + mpParseLocFile("hcbat", $locTable, FALSE, FALSE, 0); } else { - $locTable = mpReadLocationFiles(); + $locTable = mpParseLocFiles(FALSE); } //========================================================================
--- a/www/loc.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/loc.php Sat Jan 26 01:42:39 2019 +0200 @@ -118,7 +118,7 @@ if (empty($locTable)) { $locTable = []; - mpParseLocFile($setName, $locTable, $applyFilter, $applyFilter ? $locationTypes[$filterID][LTI_REGEXP] : ""); + mpParseLocFile($setName, $locTable, $applyFilter, $locationTypes[$filterID][LTI_INVERT_FLAGS], $locationTypes[$filterID][LTI_FLAGS]); apcu_store("loc_".$setName, $locTable, 3600); } } @@ -133,7 +133,7 @@ $locTable = apcu_fetch("loc_locTable"); if (empty($locTable)) { - $locTable = mpReadLocationFiles($applyFilter, $applyFilter ? $locationTypes[$filterID][LTI_REGEXP] : ""); + $locTable = mpParseLocFiles($applyFilter, $locationTypes[$filterID][LTI_INVERT_FLAGS], $locationTypes[$filterID][LTI_FLAGS]); apcu_store("loc_locTable", $locTable, 3600); } } @@ -376,9 +376,11 @@ // Coder / society names if (count($iv["coders"]) > 0 && $showCoders) { - $isSG = preg_match("/[SG]/", $iv["flags"]); - if ((!isset($coderName) && !$isSG) || isset($coderName)) - { +// XXX not sure what this was about .. :D +// $isSG = preg_match("/[SG]/", $iv["flags"]); +// if ((!isset($coderName) && ($iv["flags"] & (LOCF_T_SHRINE | LOCF_T_GUILD)) == 0) || +// isset($coderName)) +// { $fs = []; foreach ($iv["coders"] as $name) { @@ -399,7 +401,7 @@ $fs[] = $name["name"]; } echo "<div class=\"locCoders\">".implode(", ", $fs)."</div>"; - } +// } } if (/* isset($coderName) && */ $iv["added"] > 0)
--- a/www/quests.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/quests.php Sat Jan 26 01:42:39 2019 +0200 @@ -7,11 +7,11 @@ if (($hcbat = isset($_GET["hcbat"]))) { $locTable = array(); - mpParseLocFile("hcbat", $locTable, FALSE, ""); + mpParseLocFile("hcbat", $locTable, FALSE, FALSE, 0); } else { - $locTable = mpReadLocationFiles(); + $locTable = mpParseLocFiles(FALSE); }
--- a/www/simple.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/simple.php Sat Jan 26 01:42:39 2019 +0200 @@ -6,7 +6,7 @@ $locTable = apcu_fetch("loc_locTable"); if (empty($locTable)) { - $locTable = mpReadLocationFiles(TRUE, "[^C]*"); + $locTable = mpParseLocFiles(TRUE); apcu_store("loc_locTable", $locTable, 3600); }
--- a/www/ss.php Sat Jan 26 01:40:23 2019 +0200 +++ b/www/ss.php Sat Jan 26 01:42:39 2019 +0200 @@ -7,9 +7,9 @@ $locPTable = apcu_fetch("ss_locPTable"); if (empty($locTable) || empty($locPTable)) { - $locTable = mpReadLocationFiles(TRUE, "C"); - mpParseLocFile("limbo", $locTable, TRUE, "C"); - $locPTable = mpReadLocationFiles(TRUE, "P"); + $locTable = mpParseLocFiles(TRUE, FALSE, LOCF_M_PCITY); + mpParseLocFile("limbo", $locTable, TRUE, FALSE, LOCF_M_PCITY); + $locPTable = mpParseLocFiles(TRUE, FALSE, LOCF_T_SS); apcu_store("ss_locTable", $locTable, 3600); apcu_store("ss_locPTable", $locPTable, 3600); @@ -38,7 +38,7 @@ "<table class=\"locTable societies\">\n". " <tr>\n". " <th>Society name</th>\n". - " <th>Player city</th>\n". + " <th>Player city/location</th>\n". " <th>Continent</th>\n". " </tr>\n";