From afa601fffe760435db19ab035669b41ae5cc49bf Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Sun, 1 Aug 2021 12:16:48 +0000 Subject: [PATCH] Support session-specific viewer cache directories --- hippolyzer/lib/proxy/object_manager.py | 6 +++++- hippolyzer/lib/proxy/sessions.py | 2 ++ hippolyzer/lib/proxy/vocache.py | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hippolyzer/lib/proxy/object_manager.py b/hippolyzer/lib/proxy/object_manager.py index 7497418..ea8adae 100644 --- a/hippolyzer/lib/proxy/object_manager.py +++ b/hippolyzer/lib/proxy/object_manager.py @@ -57,7 +57,11 @@ class ProxyObjectManager(ClientObjectManager): LOG.warning(f"Tried to load cache for {self._region} without a handle") return self.cache_loaded = True - self.object_cache = RegionViewerObjectCacheChain.for_region(handle, self._region.cache_id) + self.object_cache = RegionViewerObjectCacheChain.for_region( + handle=handle, + cache_id=self._region.cache_id, + cache_dir=self._region.session().cache_dir, + ) def request_missed_cached_objects_soon(self): if self._cache_miss_timer: diff --git a/hippolyzer/lib/proxy/sessions.py b/hippolyzer/lib/proxy/sessions.py index 103c68c..03f0851 100644 --- a/hippolyzer/lib/proxy/sessions.py +++ b/hippolyzer/lib/proxy/sessions.py @@ -47,6 +47,8 @@ class Session(BaseClientSession): self.message_handler: MessageHandler[Message, str] = MessageHandler() self.http_message_handler: MessageHandler[HippoHTTPFlow, str] = MessageHandler() self.objects = ProxyWorldObjectManager(self, session_manager.settings, session_manager.name_cache) + # Base path of a newview type cache directory for this session + self.cache_dir: Optional[str] = None self._main_region = None @property diff --git a/hippolyzer/lib/proxy/vocache.py b/hippolyzer/lib/proxy/vocache.py index cf54dc0..6690073 100644 --- a/hippolyzer/lib/proxy/vocache.py +++ b/hippolyzer/lib/proxy/vocache.py @@ -58,6 +58,7 @@ from __future__ import annotations import io import logging +import pathlib from pathlib import Path from typing import * @@ -82,6 +83,7 @@ class ViewerObjectCache: @classmethod def from_path(cls, base_path: Union[str, Path]): + base_path = pathlib.Path(base_path) cache = cls(base_path) with open(cache.base_path / "object.cache", "rb") as fh: reader = se.BufferReader("<", fh.read()) @@ -143,6 +145,10 @@ class ViewerObjectCacheEntry(recordclass.datatuple): # type: ignore data: bytes +def is_valid_vocache_dir(cache_dir): + return (pathlib.Path(cache_dir) / "objectcache" / "object.cache").exists() + + class RegionViewerObjectCache: """Parser and container for .slc files""" def __init__(self, cache_id: UUID, entries: List[ViewerObjectCacheEntry]): @@ -201,7 +207,7 @@ class RegionViewerObjectCacheChain: return None @classmethod - def for_region(cls, handle: int, cache_id: UUID): + def for_region(cls, handle: int, cache_id: UUID, cache_dir: Optional[str] = None): """ Get a cache chain for a specific region, called on region connection @@ -209,8 +215,13 @@ class RegionViewerObjectCacheChain: so we have to try every region object cache file for every viewer installed. """ caches = [] - for cache_dir in iter_viewer_cache_dirs(): - if not (cache_dir / "objectcache" / "object.cache").exists(): + if cache_dir is None: + cache_dirs = iter_viewer_cache_dirs() + else: + cache_dirs = [pathlib.Path(cache_dir)] + + for cache_dir in cache_dirs: + if not is_valid_vocache_dir(cache_dir): continue cache = ViewerObjectCache.from_path(cache_dir / "objectcache") if cache: