Changeset 412
- Timestamp:
- Feb 22, 2023, 5:55:51 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/Web.cs
r404 r412 21 21 private readonly List<AbsHandler> handlers = new List<AbsHandler> (); 22 22 public readonly List<WebMod> webMods = new List<WebMod> (); 23 p rivate readonly ConnectionHandler connectionHandler;23 public readonly ConnectionHandler ConnectionHandler; 24 24 25 25 private readonly HttpListener listener = new HttpListener (); … … 30 30 public Web (string _modInstancePath) { 31 31 try { 32 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.ControlPanelPort))); 32 bool dashboardEnabled = GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.WebDashboardEnabled))); 33 if (!dashboardEnabled) { 34 Log.Out ($"[Web] Webserver not started, {nameof (EnumGamePrefs.WebDashboardEnabled)} set to false"); 35 return; 36 } 37 38 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.WebDashboardPort))); 33 39 if (webPort < 1 || webPort > 65533) { 34 Log.Out ("[Web] Webserver not started (ControlPanelPort not within 1-65533)"); 35 return; 36 } 37 38 // TODO: Remove once this becomes the default control panel 39 webPort += 2; 40 Log.Out ($"[Web] Webserver not started ({nameof (EnumGamePrefs.WebDashboardPort)} not within 1-65535)"); 41 return; 42 } 40 43 41 44 if (!HttpListener.IsSupported) { … … 44 47 } 45 48 49 if (string.IsNullOrEmpty (GamePrefs.GetString (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.WebDashboardUrl))))) { 50 Log.Warning ($"[Web] {nameof (EnumGamePrefs.WebDashboardUrl)} not set. Recommended to set it to the public URL pointing to your dashboard / reverse proxy"); 51 } 52 46 53 // TODO: Read from config 47 bool use StaticCache = false;54 bool useCacheForStatic = StringParsers.ParseBool ("false"); 48 55 49 56 string webfilesFolder = DetectWebserverFolder (_modInstancePath); 50 string webfilesFolderLegacy = $"{_modInstancePath}/weblegacy"; 51 52 connectionHandler = new ConnectionHandler (); 57 58 ConnectionHandler = new ConnectionHandler (); 53 59 54 60 RegisterPathHandler ("/", new RewriteHandler ("/files/")); … … 57 63 RegisterPathHandler ("/app", new RewriteHandler ("/files/index.html", true)); 58 64 59 // Legacy web page60 RegisterPathHandler ("/weblegacy", new StaticHandler (61 webfilesFolderLegacy,62 useStaticCache ? new SimpleCache () : new DirectAccess (),63 false)64 );65 66 65 // Do mods relatively early as they should not be requested a lot, unlike the later registrations, especially for API and map tiles 67 RegisterWebMods (use StaticCache);68 69 RegisterPathHandler ("/session/", new SessionHandler ( connectionHandler));66 RegisterWebMods (useCacheForStatic); 67 68 RegisterPathHandler ("/session/", new SessionHandler (ConnectionHandler)); 70 69 RegisterPathHandler ("/userstatus", new UserStatusHandler ()); 71 70 RegisterPathHandler ("/sse/", new SseHandler ()); 72 71 RegisterPathHandler ("/files/", new StaticHandler ( 73 72 webfilesFolder, 74 use StaticCache? new SimpleCache () : new DirectAccess (),73 useCacheForStatic ? new SimpleCache () : new DirectAccess (), 75 74 false) 76 75 ); … … 82 81 83 82 listener.Prefixes.Add ($"http://+:{webPort}/"); 84 // listener.Prefixes.Add ($"http://[::1]:{webPort}/");85 83 listener.Start (); 86 84 handleRequestDelegate = HandleRequest; … … 163 161 164 162 public void SendLine (string _line) { 165 connectionHandler.SendLine (_line);163 ConnectionHandler.SendLine (_line); 166 164 } 167 165 … … 299 297 300 298 if (!string.IsNullOrEmpty (sessionId)) { 301 _con = connectionHandler.IsLoggedIn (sessionId, reqRemoteEndPoint.Address);299 _con = ConnectionHandler.IsLoggedIn (sessionId, reqRemoteEndPoint.Address); 302 300 if (_con != null) { 303 301 int level1 = GameManager.Instance.adminTools.Users.GetUserPermissionLevel (_con.UserId);
Note:
See TracChangeset
for help on using the changeset viewer.