Changeset 199 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Sep 22, 2014, 11:15:14 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes
- Files:
-
- 5 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r197 r199 125 125 <Compile Include="src\CustomCommands\Unban.cs" /> 126 126 <Compile Include="src\ItemList.cs" /> 127 <Compile Include="src\FileCache\AbstractCache.cs" /> 128 <Compile Include="src\FileCache\DirectAccess.cs" /> 129 <Compile Include="src\FileCache\SimpleCache.cs" /> 130 <Compile Include="src\FileCache\MapTileCache.cs" /> 127 131 </ItemGroup> 128 132 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> … … 138 142 <Folder Include="src\NetConnections\Servers\Web\API\" /> 139 143 <Folder Include="src\JSON\Parser\" /> 144 <Folder Include="src\FileCache\" /> 140 145 </ItemGroup> 141 146 </Project> -
binary-improvements/7dtd-server-fixes/src/ItemList.cs
r197 r199 49 49 string name = ib.GetItemName (invF.itemValue); 50 50 if (name != null && name.Length > 0) { 51 if (!items.ContainsKey (name)) 51 if (!items.ContainsKey (name)) { 52 52 items.Add (name, invF.itemValue); 53 else 54 Log.Out ("Item \"" + name + "\" already in list!"); 53 } else { 54 //Log.Out ("Item \"" + name + "\" already in list!"); 55 } 55 56 } 56 57 } … … 59 60 string name = ib.GetItemName (invF.itemValue); 60 61 if (name != null && name.Length > 0) { 61 if (!items.ContainsKey (name)) 62 if (!items.ContainsKey (name)) { 62 63 items.Add (name, invF.itemValue); 63 else 64 Log.Out ("Item \"" + name + "\" already in list!"); 64 } else { 65 //Log.Out ("Item \"" + name + "\" already in list!"); 66 } 65 67 } 66 68 } -
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRenderBlockBuffer.cs
r189 r199 13 13 private Texture2D zoomBuffer = new Texture2D (1, 1); 14 14 private Color nullColor = new Color (0, 0, 0, 0); 15 private AllocsFixes.FileCache.MapTileCache cache; 15 16 16 public MapRenderBlockBuffer (int level )17 public MapRenderBlockBuffer (int level, AllocsFixes.FileCache.MapTileCache cache) 17 18 { 18 19 zoomLevel = level; 20 this.cache = cache; 19 21 } 20 22 … … 68 70 private void loadTextureFromFile (string _fileName) 69 71 { 70 try {71 byte[] array = File.ReadAllBytes (_fileName);72 byte[] array = cache.LoadTile (zoomLevel, _fileName); 73 if (array != null) { 72 74 blockMap.LoadImage (array); 73 } catch (Exception) { 75 } else { 76 //try { 77 //byte[] array = File.ReadAllBytes (_fileName); 78 //blockMap.LoadImage (array); 79 //} catch (Exception) { 74 80 for (int x = 0; x < Constants.MAP_BLOCK_SIZE; x++) { 75 81 for (int y = 0; y < Constants.MAP_BLOCK_SIZE; y++) { … … 82 88 private void saveTextureToFile (string _fileName) 83 89 { 84 try { 85 byte[] array = blockMap.EncodeToPNG (); 86 File.WriteAllBytes (_fileName, array); 87 } catch (Exception e) { 88 Log.Out ("Exception in MapRenderBlockBuffer.saveTextureToFile(): " + e); 89 } 90 byte[] array = blockMap.EncodeToPNG (); 91 cache.SaveTile (zoomLevel, array); 92 // try { 93 // byte[] array = blockMap.EncodeToPNG (); 94 // File.WriteAllBytes (_fileName, array); 95 // } catch (Exception e) { 96 // Log.Out ("Exception in MapRenderBlockBuffer.saveTextureToFile(): " + e); 97 // } 90 98 } 91 99 -
binary-improvements/7dtd-server-fixes/src/MapRendering/MapRendering.cs
r192 r199 29 29 public static bool renderingEnabled = true; 30 30 private MicroStopwatch msw = new MicroStopwatch (); 31 private AllocsFixes.FileCache.MapTileCache cache = new AllocsFixes.FileCache.MapTileCache (); 32 33 public AllocsFixes.FileCache.MapTileCache TileCache { 34 get { return cache; } 35 } 31 36 32 37 private MapRendering () … … 39 44 } 40 45 46 cache.SetZoomCount (Constants.ZOOMLEVELS); 47 41 48 zoomLevelBuffers = new MapRenderBlockBuffer[Constants.ZOOMLEVELS]; 42 49 for (int i = 0; i < Constants.ZOOMLEVELS; i++) { 43 zoomLevelBuffers [i] = new MapRenderBlockBuffer (i );50 zoomLevelBuffers [i] = new MapRenderBlockBuffer (i, cache); 44 51 } 45 52 -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
r189 r199 11 11 private string datapath; 12 12 private string staticPart; 13 private boolcache;13 private AllocsFixes.FileCache.AbstractCache cache; 14 14 private bool logMissingFiles; 15 private Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> ();16 15 17 public StaticHandler (string staticPart, string filePath, boolcache, bool logMissingFiles)16 public StaticHandler (string staticPart, string filePath, AllocsFixes.FileCache.AbstractCache cache, bool logMissingFiles) 18 17 { 19 18 this.staticPart = staticPart; … … 28 27 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 29 28 30 byte[] content; 31 if (cache) { 32 lock (fileCache) { 33 if (!fileCache.ContainsKey (fn)) { 34 if (!File.Exists (datapath + "/" + fn)) { 35 throw new FileNotFoundException (); 36 } 37 38 fileCache.Add (fn, File.ReadAllBytes (datapath + "/" + fn)); 39 } 40 41 content = fileCache [fn]; 42 } 29 byte[] content = cache.GetFileContent (datapath + "/" + fn); 30 if (content != null) { 31 resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn)); 32 resp.ContentLength64 = content.Length; 33 resp.OutputStream.Write (content, 0, content.Length); 43 34 } else { 44 if (!File.Exists (datapath + "/" + fn)) { 45 throw new FileNotFoundException (); 46 } 47 48 content = File.ReadAllBytes (datapath + "/" + fn); 35 resp.StatusCode = (int)HttpStatusCode.NotFound; 36 if (logMissingFiles) 37 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 38 return; 49 39 } 50 51 resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn));52 resp.ContentLength64 = content.Length;53 resp.OutputStream.Write (content, 0, content.Length);54 } catch (FileNotFoundException) {55 resp.StatusCode = (int)HttpStatusCode.NotFound;56 if (logMissingFiles)57 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\"");58 return;59 40 } catch (Exception e) { 60 41 Log.Out ("Error in StaticHandler.HandleRequest: " + e); -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
r190 r199 34 34 } 35 35 36 handlers.Add ("/index.htm", new SimpleRedirectHandler ("/static/index.html")); 37 handlers.Add ("/static/", new StaticHandler ("/static/", Application.dataPath + "/../webserver", false/*true*/, true)); // TODO: Enable cache 38 handlers.Add ("/map/", new StaticHandler ("/map/", StaticDirectories.GetSaveGameDir () + "/map", false, false)); 36 handlers.Add ( 37 "/index.htm", 38 new SimpleRedirectHandler ("/static/index.html")); 39 handlers.Add ( 40 "/static/", 41 new StaticHandler ( 42 "/static/", 43 Application.dataPath + "/../webserver", 44 new AllocsFixes.FileCache.DirectAccess (), 45 true) 46 ); // TODO: Enable cache 47 handlers.Add ( 48 "/map/", 49 new StaticHandler ( 50 "/map/", 51 StaticDirectories.GetSaveGameDir () + "/map", 52 MapRendering.MapRendering.Instance.TileCache, 53 false) 54 ); 39 55 handlers.Add ("/api/", new ApiHandler ("/api/")); 40 56 … … 61 77 ); 62 78 63 NetTelnetServer.RegisterServer (this);79 NetTelnetServer.RegisterServer (this); 64 80 65 81
Note:
See TracChangeset
for help on using the changeset viewer.