diff --git a/.gitignore b/.gitignore index fea5a5b..8dc6169 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ listings/lp-output/* cache cache-lt +# Local config +config/*.ini + # Archives /etc/archives/logrotate.status diff --git a/.phpenv.php b/.phpenv.php index 387580f..14befcb 100644 --- a/.phpenv.php +++ b/.phpenv.php @@ -94,6 +94,11 @@ */ $SOURCES_CACHE="$LONG_TERM_CACHE_ROOT/sources"; + /** + * @var string $CONFIG_ROOT + * Directory containing local config files. + */ + $CONFIG_ROOT="$PROJECT_ROOT/config"; /** * @var string $LISTING_PROVIDER_ROOT diff --git a/config/room-overrides.ini.sample b/config/room-overrides.ini.sample new file mode 100644 index 0000000..c9e721d --- /dev/null +++ b/config/room-overrides.ini.sample @@ -0,0 +1,2 @@ +[room+1234] +staff_count=4 diff --git a/php/servers/servers-rooms.php b/php/servers/servers-rooms.php index 87dcc37..d2ecaad 100644 --- a/php/servers/servers-rooms.php +++ b/php/servers/servers-rooms.php @@ -11,6 +11,7 @@ require_once 'assets/room-icons.php'; require_once 'assets/room-invites.php'; require_once 'utils/numeric.php'; + require_once 'utils/read-config.php'; /** * Represents a Session Community. @@ -404,7 +405,11 @@ * @return int */ function get_staff_count(): int { - return count($this->get_staff()); + global $LOCAL_CONFIG; + return ( + $LOCAL_CONFIG->get_room_staff_count_override($this->get_room_identifier()) + ?? count($this->get_staff()) + ); } /** diff --git a/php/utils/read-config.php b/php/utils/read-config.php new file mode 100644 index 0000000..db0bd8a --- /dev/null +++ b/php/utils/read-config.php @@ -0,0 +1,54 @@ +room_overrides = + LocalConfig::maybe_parse_ini_file(LocalConfig::ROOM_OVERRIDES_CONFIG) + ?? array(); + } + + private const ROOM_OVERRIDES_CONFIG = "room-overrides.ini"; + + private readonly array $room_overrides; + + private static function maybe_parse_ini_file(string $filename): array | null { + global $CONFIG_ROOT; + $file = "$CONFIG_ROOT/$filename"; + + if (!file_exists($file)) { + log_warning("config file not found: $file"); + return null; + } + + return parse_ini_file($file, process_sections: true, scanner_mode: INI_SCANNER_RAW); + } + + /** + * Read local config from the filesystem. + */ + public static function read_from_files() { + return new LocalConfig(); + } + + private function get_room_override(string $room_id, string $override_key) { + $room_overrides = $this->room_overrides[$room_id] ?? array(); + return $room_overrides[$override_key] ?? null; + } + + public function get_room_staff_count_override(string $room_id) { + return $this->get_room_override($room_id, 'staff_count'); + } +} + +/** + * @var LocalConfig $LOCAL_CONFIG + */ +$LOCAL_CONFIG = LocalConfig::read_from_files(); + +?>