Changeset 402 for binary-improvements2/WebServer/src/Web.cs
- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/Web.cs
r398 r402 3 3 using System.IO; 4 4 using System.Net.Sockets; 5 using AllocsFixes.FileCache;6 using MapRendering;7 5 using SpaceWizards.HttpListener; 8 6 using UnityEngine; 7 using Webserver.FileCache; 9 8 using Webserver.UrlHandlers; 10 9 using Cookie = System.Net.Cookie; … … 14 13 namespace Webserver { 15 14 public class Web : IConsoleServer { 15 public static event Action<Web> ServerInitialized; 16 16 17 private const int guestPermissionLevel = 2000; 17 18 private const string indexPageUrl = "/app"; … … 26 27 public Web (string _modInstancePath) { 27 28 try { 28 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> ( "ControlPanelPort"));29 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.ControlPanelPort))); 29 30 if (webPort < 1 || webPort > 65533) { 30 31 Log.Out ("[Web] Webserver not started (ControlPanelPort not within 1-65533)"); … … 44 45 45 46 string webfilesFolder = DetectWebserverFolder (_modInstancePath); 46 string webfilesFolderLegacy = _modInstancePath + "/weblegacy";47 string webfilesFolderLegacy = $"{_modInstancePath}/weblegacy"; 47 48 48 49 connectionHandler = new ConnectionHandler (); … … 56 57 RegisterPathHandler ("/weblegacy", new StaticHandler ( 57 58 webfilesFolderLegacy, 58 useStaticCache ? (AbstractCache)new SimpleCache () : new DirectAccess (),59 useStaticCache ? new SimpleCache () : new DirectAccess (), 59 60 false) 60 61 ); … … 68 69 RegisterPathHandler ("/files/", new StaticHandler ( 69 70 webfilesFolder, 70 useStaticCache ? (AbstractCache)new SimpleCache () : new DirectAccess (),71 useStaticCache ? new SimpleCache () : new DirectAccess (), 71 72 false) 72 73 ); 73 74 RegisterPathHandler ("/itemicons/", new ItemIconHandler (true)); 74 RegisterPathHandler ("/map/", new StaticHandler (75 GameIO.GetSaveGameDir () + "/map",76 MapRenderer.GetTileCache (),77 false,78 "web.map")79 );80 75 RegisterPathHandler ("/api/", new ApiHandler ()); 76 77 // Allow other code to add their stuff 78 ServerInitialized?.Invoke (this); 81 79 82 80 listener.Prefixes.Add ($"http://+:{webPort}/"); … … 87 85 SdtdConsole.Instance.RegisterServer (this); 88 86 89 Log.Out ( "[Web] Started Webserver on port " + webPort);87 Log.Out ($"[Web] Started Webserver on port {webPort}"); 90 88 } catch (Exception e) { 91 89 Log.Error ("[Web] Error in Web.ctor: "); … … 95 93 96 94 private static string DetectWebserverFolder (string _modInstancePath) { 97 string webserverFolder = _modInstancePath + "/webserver";95 string webserverFolder = $"{_modInstancePath}/webserver"; 98 96 99 97 foreach (Mod mod in ModManager.GetLoadedMods ()) { 100 string modServerFolder = mod.Path + "/webserver";98 string modServerFolder = $"{mod.Path}/webserver"; 101 99 102 100 if (Directory.Exists (modServerFolder)) { … … 127 125 foreach (Mod mod in ModManager.GetLoadedMods ()) { 128 126 try { 129 string webModPath = mod.Path + "/WebMod";127 string webModPath = $"{mod.Path}/WebMod"; 130 128 if (!Directory.Exists (webModPath)) { 131 129 continue; … … 136 134 webMods.Add (webMod); 137 135 } catch (InvalidDataException e) { 138 Log.Error ($"[Web] Could not load webmod from mod {mod. ModInfo.Name.Value}: {e.Message}");136 Log.Error ($"[Web] Could not load webmod from mod {mod.Name}: {e.Message}"); 139 137 } 140 138 } catch (Exception e) { 141 Log.Error ( "[Web] Failed loading web mods from mod " + mod.ModInfo.Name.Value);139 Log.Error ($"[Web] Failed loading web mods from mod {mod.Name}"); 142 140 Log.Exception (e); 143 141 } … … 150 148 listener.Close (); 151 149 } catch (Exception e) { 152 Log.Out ( "[Web] Error in Web.Disconnect: " + e);150 Log.Out ($"[Web] Error in Web.Disconnect: {e}"); 153 151 } 154 152 } … … 238 236 } catch (IOException e) { 239 237 if (e.InnerException is SocketException) { 240 Log.Out ( "[Web] Error in Web.HandleRequest(): Remote host closed connection: " + e.InnerException.Message);238 Log.Out ($"[Web] Error in Web.HandleRequest(): Remote host closed connection: {e.InnerException.Message}"); 241 239 } else { 242 Log.Out ( "[Web] Error (IO) in Web.HandleRequest(): " + e);240 Log.Out ($"[Web] Error (IO) in Web.HandleRequest(): {e}"); 243 241 } 244 242 } catch (Exception e) { … … 313 311 } 314 312 315 Log.Warning ( "[Web] Invalid Admintoken used from " + reqRemoteEndPoint);313 Log.Warning ($"[Web] Invalid Admintoken used from {reqRemoteEndPoint}"); 316 314 317 315 return guestPermissionLevel;
Note:
See TracChangeset
for help on using the changeset viewer.