- Timestamp:
- Sep 2, 2014, 9:32:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
r151 r154 19 19 throw new NotSupportedException ("Needs Windows XP SP2, Server 2003 or later."); 20 20 21 handlers.Add ("/index. ", new SimpleRedirectHandler ("/static/index.html"));21 handlers.Add ("/index.htm", new SimpleRedirectHandler ("/static/index.html")); 22 22 handlers.Add ("/static/", new StaticHandler ("/static/", Application.dataPath + "/../webserver", false/*true*/, true)); // TODO: Enable cache 23 23 handlers.Add ("/map/", new StaticHandler ("/map/", StaticDirectories.GetSaveGameDir () + "/map", false, false)); 24 handlers.Add ("/api/", new ApiHandler ("/api/")); 24 25 25 26 _listener.Prefixes.Add (String.Format ("http://*:{0}/", port)); … … 53 54 ctx.Response.ProtocolVersion = new Version ("1.1"); 54 55 55 HttpListenerBasicIdentity user ;56 HttpListenerBasicIdentity user = Authorize (ctx); 56 57 57 if (Authorize (ctx, out user)) { 58 if (ctx.Request.Url.AbsolutePath.Length < 2) { 59 handlers ["/index."].HandleRequest (ctx.Request, ctx.Response, user); 60 return; 61 } else { 62 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 63 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 64 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 65 return; 66 } 58 if (ctx.Request.Url.AbsolutePath.Length < 2) { 59 handlers ["/index.htm"].HandleRequest (ctx.Request, ctx.Response, user); 60 return; 61 } else { 62 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 63 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 64 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 65 return; 67 66 } 68 67 } 68 } 69 69 70 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\""); 71 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; 72 } else { 73 ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; 74 ctx.Response.AddHeader("WWW-Authenticate", "Basic realm=\"\""); 75 } 70 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\""); 71 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; 76 72 77 73 // byte[] buf = Encoding.UTF8.GetBytes ("Hello World"); … … 87 83 } 88 84 89 private bool Authorize (HttpListenerContext ctx, out HttpListenerBasicIdentity user)85 private HttpListenerBasicIdentity Authorize (HttpListenerContext ctx) 90 86 { 91 user = null;92 return true;93 87 try { 94 user = (HttpListenerBasicIdentity)ctx.User.Identity; 95 return user.Name.Equals ("admin") && user.Password.Equals (GamePrefs.GetString (EnumGamePrefs.ControlPanelPassword)); 88 return (HttpListenerBasicIdentity)ctx.User.Identity; 96 89 } catch (NullReferenceException) { 97 user = null; 98 return false; 90 return null; 99 91 } 100 92 }
Note:
See TracChangeset
for help on using the changeset viewer.