diff --git a/MinecraftClient/Protocol/SessionCache/SessionCache.cs b/MinecraftClient/Protocol/SessionCache/SessionCache.cs index 7a03fa9d..abd3cd85 100644 --- a/MinecraftClient/Protocol/SessionCache/SessionCache.cs +++ b/MinecraftClient/Protocol/SessionCache/SessionCache.cs @@ -156,22 +156,38 @@ namespace MinecraftClient.Protocol.SessionCache private static void SaveToDisk() { bool fileexists = File.Exists(SessionCacheFile); + IOException lastEx = null; + int attempt = 1; - using (FileStream fs = new FileStream(SessionCacheFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) + while (attempt < 4) { - cachemonitor.EnableRaisingEvents = false; - - // delete existing file contents - if (fileexists) + try { - fs.SetLength(0); - fs.Flush(); - } + using (FileStream fs = new FileStream(SessionCacheFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) + { + cachemonitor.EnableRaisingEvents = false; - formatter.Serialize(fs, sessions); - cachemonitor.EnableRaisingEvents = true; + // delete existing file contents + if (fileexists) + { + fs.SetLength(0); + fs.Flush(); + } + + formatter.Serialize(fs, sessions); + cachemonitor.EnableRaisingEvents = true; + } + return; + } + catch (IOException ex) + { + lastEx = ex; + attempt++; + System.Threading.Thread.Sleep(new Random().Next(150, 350) * attempt); //CSMA/CD :) + } } + Console.WriteLine("Error writing cached sessions to disk" + (lastEx != null ? ": " + lastEx.Message : "")); } } } diff --git a/MinecraftClient/config/README.txt b/MinecraftClient/config/README.txt index db038351..a55ff28f 100644 --- a/MinecraftClient/config/README.txt +++ b/MinecraftClient/config/README.txt @@ -112,7 +112,7 @@ If you are experienced with C#, you may also write a C# script. That's a bit more involved, but way more powerful than regular scripts. You can look to the provided sample C# scripts for getting started. -C# scripts can be used for creating your own ChatBot without recompiling the wole project. +C# scripts can be used for creating your own ChatBot without recompiling the whole project. These bots are embedded in a script file, which is compiled and loaded on the fly. ChatBots can access plugin channels for communicating with your own plugin.