Changeset 455 for binary-improvements/MapRendering/API.cs
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API.cs
r454 r455 1 1 using System; 2 2 using System.IO; 3 using Webserver;3 using JetBrains.Annotations; 4 4 using Webserver.FileCache; 5 5 using Webserver.UrlHandlers; 6 6 7 namespace AllocsFixes { 7 namespace AllocsFixes.Web { 8 [UsedImplicitly] 8 9 public class API : IModApi { 9 private Mod modInstance;10 private static Mod modInstance; 10 11 11 12 public void InitMod (Mod _modInstance) { 12 13 modInstance = _modInstance; 13 14 14 Web.ServerInitialized += _web => { 15 try { 16 const string legacyModUrl = "/legacymap"; 17 const string legacyFilesFoldername = "webserver_legacy"; 18 string legacyFilePath = $"{modInstance.Path}/{legacyFilesFoldername}"; 19 20 if (!Directory.Exists (legacyFilePath)) { 21 Log.Out ($"Legacy webmod feature not started (folder \"{legacyFilesFoldername}\" not found in Allocs_WebAndMapRendering mod folder)"); 22 return; 23 } 24 25 // TODO: Read from config 26 bool useStaticCache = false; 27 28 _web.RegisterPathHandler ("/legacymap.htm", new SimpleRedirectHandler ($"{legacyModUrl}/index.html")); 29 _web.RegisterPathHandler ($"{legacyModUrl}/", new StaticHandler (legacyFilePath, useStaticCache ? (AbstractCache) new SimpleCache () : new DirectAccess (), false)); 30 31 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.WebDashboardPort))); 32 Log.Out ($"Started legacy webmod feature on port {webPort}, local adress {legacyModUrl}"); 33 } catch (Exception e) { 34 Log.Out ("Error in Web.ctor: " + e); 35 } 36 }; 15 Webserver.Web.ServerInitialized += OnWebServerInitialized; 37 16 } 38 17 39 // public static void SetResponseTextContent (HttpListenerResponse _context.Response, string _text) { 40 // byte[] buf = Encoding.UTF8.GetBytes (_text); 41 // _context.Response.ContentLength64 = buf.Length; 42 // _context.Response.ContentType = "text/html"; 43 // _context.Response.ContentEncoding = Encoding.UTF8; 44 // _context.Response.OutputStream.Write (buf, 0, buf.Length); 45 // } 18 private static void OnWebServerInitialized (Webserver.Web _web) { 19 try { 20 const string legacyModUrl = "/legacymap"; 21 const string legacyFilesFoldername = "webserver_legacy"; 22 string legacyFilePath = $"{modInstance.Path}/{legacyFilesFoldername}"; 46 23 47 24 if (!Directory.Exists (legacyFilePath)) { 25 Log.Out ($"Legacy webmod feature not started (folder \"{legacyFilesFoldername}\" not found in Allocs_WebAndMapRendering mod folder)"); 26 return; 27 } 28 29 // TODO: Read from config 30 bool useStaticCache = false; 31 32 _web.RegisterPathHandler ($"{legacyModUrl}", new SimpleRedirectHandler ($"{legacyModUrl}/index.html")); 33 _web.RegisterPathHandler ($"{legacyModUrl}/", new StaticHandler (legacyFilePath, useStaticCache ? new SimpleCache () : new DirectAccess (), false)); 34 35 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof(EnumGamePrefs.WebDashboardPort))); 36 Log.Out ($"Started legacy webmod feature on port {webPort}, local adress {legacyModUrl}"); 37 } catch (Exception e) { 38 Log.Out ($"Error in Web.ctor: {e}"); 39 } 40 } 48 41 } 49 42 }
Note:
See TracChangeset
for help on using the changeset viewer.