diff --git a/MinecraftClient/Protocol/SessionCache/SessionCache.cs b/MinecraftClient/Protocol/SessionCache/SessionCache.cs index abd3cd85..7e76c0f0 100644 --- a/MinecraftClient/Protocol/SessionCache/SessionCache.cs +++ b/MinecraftClient/Protocol/SessionCache/SessionCache.cs @@ -11,16 +11,13 @@ namespace MinecraftClient.Protocol.SessionCache /// /// Handle sessions caching and storage. /// - public static class SessionCache { private const string SessionCacheFile = "SessionCache.db"; - private static Dictionary sessions = new Dictionary(); private static FileSystemWatcher cachemonitor = new FileSystemWatcher(); private static Timer updatetimer = new Timer(100); private static List> pendingadds = new List>(); - private static BinaryFormatter formatter = new BinaryFormatter(); /// @@ -28,7 +25,6 @@ namespace MinecraftClient.Protocol.SessionCache /// /// User login used with Minecraft.net /// TRUE if session is available - public static bool Contains(string login) { return sessions.ContainsKey(login); @@ -39,7 +35,6 @@ namespace MinecraftClient.Protocol.SessionCache /// /// User login used with Minecraft.net /// User session token used with Minecraft.net - public static void Store(string login, SessionToken session) { if (Contains(login)) @@ -66,7 +61,6 @@ namespace MinecraftClient.Protocol.SessionCache /// /// User login used with Minecraft.net /// SessionToken for given login - public static SessionToken Get(string login) { return sessions[login]; @@ -76,7 +70,6 @@ namespace MinecraftClient.Protocol.SessionCache /// Initialize cache monitoring to keep cache updated with external changes. /// /// TRUE if session tokens are seeded from file - public static bool InitializeDiskCache() { cachemonitor.Path = AppDomain.CurrentDomain.BaseDirectory; @@ -96,7 +89,6 @@ namespace MinecraftClient.Protocol.SessionCache /// /// Sender /// Event data - private static void OnChanged(object sender, FileSystemEventArgs e) { updatetimer.Stop(); @@ -108,9 +100,9 @@ namespace MinecraftClient.Protocol.SessionCache /// /// Sender /// Event data - private static void HandlePending(object sender, ElapsedEventArgs e) { + updatetimer.Stop(); LoadFromDisk(); foreach(KeyValuePair pending in pendingadds.ToArray()) @@ -124,9 +116,11 @@ namespace MinecraftClient.Protocol.SessionCache /// Reads cache file and loads SessionTokens into SessionCache. /// /// True if data is successfully loaded - private static bool LoadFromDisk() { + if (Settings.DebugMessages) + ConsoleIO.WriteLineFormatted("§8Updating session cache from disk"); + if (File.Exists(SessionCacheFile)) { try @@ -139,11 +133,11 @@ namespace MinecraftClient.Protocol.SessionCache } catch (IOException ex) { - Console.WriteLine("Error reading cached sessions from disk: " + ex.Message); + ConsoleIO.WriteLineFormatted("§8Failed to read session cache from disk: " + ex.Message); } - catch (SerializationException) + catch (SerializationException ex2) { - Console.WriteLine("Malformed sessions from cache file "); + ConsoleIO.WriteLineFormatted("§8Got malformed data while reading session cache from disk: " + ex2.Message); } } return false; @@ -152,9 +146,11 @@ namespace MinecraftClient.Protocol.SessionCache /// /// Saves SessionToken's from SessionCache into cache file. /// - private static void SaveToDisk() { + if (Settings.DebugMessages) + ConsoleIO.WriteLineFormatted("§8Saving session cache to disk"); + bool fileexists = File.Exists(SessionCacheFile); IOException lastEx = null; int attempt = 1; @@ -187,7 +183,7 @@ namespace MinecraftClient.Protocol.SessionCache } } - Console.WriteLine("Error writing cached sessions to disk" + (lastEx != null ? ": " + lastEx.Message : "")); + ConsoleIO.WriteLineFormatted("§8Failed to write session cache to disk" + (lastEx != null ? ": " + lastEx.Message : "")); } } }