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

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

26_31_47

  • Updated ModInfo to v2 format
  • Added WebMod that shows link to the legacy map on the vanilla WebDashboard
File size: 1.4 KB
RevLine 
[454]1using System;
2using System.IO;
[455]3using JetBrains.Annotations;
[454]4using Webserver.FileCache;
5using Webserver.UrlHandlers;
[224]6
[455]7namespace AllocsFixes.Web {
8 [UsedImplicitly]
[324]9 public class API : IModApi {
[455]10 private static Mod modInstance;
[367]11
[369]12 public void InitMod (Mod _modInstance) {
[454]13 modInstance = _modInstance;
[325]14
[455]15 Webserver.Web.ServerInitialized += OnWebServerInitialized;
16 }
[224]17
[455]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}";
[454]23
[455]24 if (!Directory.Exists (legacyFilePath)) {
25 Log.Out ($"Legacy webmod feature not started (folder \"{legacyFilesFoldername}\" not found in Allocs_WebAndMapRendering mod folder)");
26 return;
[454]27 }
[267]28
[455]29 // TODO: Read from config
30 bool useStaticCache = false;
[454]31
[455]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)));
[464]36 Log.Out ($"Started legacy webmod feature on port {webPort}, local address {legacyModUrl}");
[455]37 } catch (Exception e) {
38 Log.Out ($"Error in Web.ctor: {e}");
39 }
40 }
[224]41 }
[325]42}
Note: See TracBrowser for help on using the repository browser.