Changeset 384
- Timestamp:
- Aug 3, 2022, 9:10:12 PM (2 years ago)
- Location:
- binary-improvements2/MapRendering
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/Handlers/ApiHandler.cs
r382 r384 11 11 private readonly Dictionary<string, WebAPI> apis = new CaseInsensitiveStringDictionary<WebAPI> (); 12 12 13 public ApiHandler ( string _moduleName = null) : base (_moduleName) {13 public ApiHandler () : base (null) { 14 14 15 } 16 17 public override void SetBasePathAndParent (Web _parent, string _relativePath) { 18 base.SetBasePathAndParent (_parent, _relativePath); 19 20 Type[] apiWithParentCtorTypes = { typeof (Web) }; 21 Object[] apiWithParentCtorArgs = { _parent }; 22 23 Type[] apiEmptyCtorTypes = { }; 24 Object[] apiEmptyCtorArgs = { }; 25 15 26 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { 16 27 if (!t.IsAbstract && t.IsSubclassOf (typeof (WebAPI))) { 17 ConstructorInfo ctor = t.GetConstructor ( new Type [0]);28 ConstructorInfo ctor = t.GetConstructor (apiWithParentCtorTypes); 18 29 if (ctor != null) { 19 WebAPI apiInstance = (WebAPI) ctor.Invoke (new object [0]); 30 WebAPI apiInstance = (WebAPI) ctor.Invoke (apiWithParentCtorArgs); 31 addApi (apiInstance); 32 continue; 33 } 34 35 ctor = t.GetConstructor (apiEmptyCtorTypes); 36 if (ctor != null) { 37 WebAPI apiInstance = (WebAPI) ctor.Invoke (apiEmptyCtorArgs); 20 38 addApi (apiInstance); 21 39 } -
binary-improvements2/MapRendering/Web/Web.cs
r383 r384 17 17 public class Web : IConsoleServer { 18 18 private const int guestPermissionLevel = 2000; 19 private const string indexPage Path= "/app";19 private const string indexPageUrl = "/app"; 20 20 21 21 public static int handlingCount; … … 23 23 public static long totalHandlingTime = 0; 24 24 private readonly List<AbsHandler> handlers = new List<AbsHandler> (); 25 public readonly List<WebMod> webMods = new List<WebMod> (); 25 26 private readonly ConnectionHandler connectionHandler; 26 27 … … 64 65 ); 65 66 67 // Do mods relatively early as they should not be requested a lot, unlike the later registrations, especially for API and map tiles 68 RegisterWebMods (useStaticCache); 69 66 70 RegisterPathHandler ("/session/", new SessionHandler (webfilesFolder, connectionHandler)); 67 71 RegisterPathHandler ("/userstatus", new UserStatusHandler ()); 72 RegisterPathHandler ("/sse/", new SseHandler ()); 68 73 RegisterPathHandler ("/files/", new StaticHandler ( 69 70 71 74 webfilesFolder, 75 useStaticCache ? (AbstractCache) new SimpleCache () : new DirectAccess (), 76 false) 72 77 ); 73 78 RegisterPathHandler ("/itemicons/", new ItemIconHandler (true)); 74 79 RegisterPathHandler ("/map/", new StaticHandler ( 75 76 77 78 80 GameIO.GetSaveGameDir () + "/map", 81 MapRendering.MapRendering.GetTileCache (), 82 false, 83 "web.map") 79 84 ); 80 85 RegisterPathHandler ("/api/", new ApiHandler ()); 81 RegisterPathHandler ("/sse/", new SseHandler ());82 86 83 87 listener.Prefixes.Add ($"http://+:{webPort}/"); … … 105 109 handlers.Add (_handler); 106 110 _handler.SetBasePathAndParent (this, _urlBasePath); 111 } 112 113 private void RegisterWebMods (bool _useStaticCache) { 114 foreach (Mod mod in ModManager.GetLoadedMods ()) { 115 try { 116 string webModPath = mod.Path + "/WebMod"; 117 if (!Directory.Exists (webModPath)) { 118 continue; 119 } 120 121 try { 122 WebMod webMod = new WebMod (this, mod, _useStaticCache); 123 webMods.Add (webMod); 124 } catch (InvalidDataException e) { 125 Log.Error ($"Could not load webmod from mod {mod.ModInfo.Name.Value}: {e.Message}"); 126 } 127 } catch (Exception e) { 128 Log.Error ("Failed loading web mods from mod " + mod.ModInfo.Name.Value); 129 Log.Exception (e); 130 } 131 } 107 132 } 108 133 … … 198 223 199 224 if (requestPath.Length < 2) { 200 response.Redirect (indexPage Path);225 response.Redirect (indexPageUrl); 201 226 return; 202 227 } -
binary-improvements2/MapRendering/WebAndMapRendering.csproj
r382 r384 87 87 <Compile Include="Web\API\GetAnimalsLocation.cs" /> 88 88 <Compile Include="Web\API\GetHostileLocation.cs" /> 89 <Compile Include="Web\API\GetWebMods.cs" /> 89 90 <Compile Include="Web\API\Null.cs" /> 90 91 <Compile Include="Web\Handlers\RewriteHandler.cs" /> … … 104 105 <Compile Include="Web\OpenID.cs" /> 105 106 <Compile Include="Web\ConnectionHandler.cs" /> 107 <Compile Include="Web\WebMod.cs" /> 106 108 <Compile Include="Web\WebPermissions.cs" /> 107 109 <Compile Include="Web\Handlers\ApiHandler.cs" />
Note:
See TracChangeset
for help on using the changeset viewer.