source: binary-improvements/MapRendering/API.cs@ 454

Last change on this file since 454 was 454, checked in by alloc, 16 months ago

24_29_43
Switched over to vanilla Web infrastructure

File size: 1.7 KB
RevLine 
[454]1using System;
2using System.IO;
3using Webserver;
4using Webserver.FileCache;
5using Webserver.UrlHandlers;
[224]6
[331]7namespace AllocsFixes {
[324]8 public class API : IModApi {
[454]9 private Mod modInstance;
[367]10
[369]11 public void InitMod (Mod _modInstance) {
[454]12 modInstance = _modInstance;
[325]13
[454]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 }
[224]24
[454]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 };
[291]37 }
[267]38
[454]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 // }
46
47
[224]48 }
[325]49}
Note: See TracBrowser for help on using the repository browser.