Changeset 172
- Timestamp:
- Sep 5, 2014, 11:15:20 PM (10 years ago)
- Location:
- binary-improvements
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
r168 r172 13 13 private readonly HttpListener _listener = new HttpListener (); 14 14 private Dictionary<string, PathHandler> handlers = new Dictionary<string, PathHandler> (); 15 private bool authEnabled = false; 16 private string realm = "7dtd Admin Panel"; 15 17 16 18 public Web (int port) … … 26 28 27 29 _listener.Prefixes.Add (String.Format ("http://*:{0}/", port)); 28 if (File.Exists (Application.dataPath + "/../webserver/protect")) 30 authEnabled = File.Exists (Application.dataPath + "/../webserver/protect"); 31 if (authEnabled) 29 32 _listener.AuthenticationSchemes = AuthenticationSchemes.Basic; 30 33 _listener.Start (); 34 _listener.Realm = realm; 31 35 32 36 ThreadPool.QueueUserWorkItem ((o) => … … 45 49 ); 46 50 47 Log.Out ("Started Webserver on " + port + " (authentication " + ( _listener.AuthenticationSchemes == AuthenticationSchemes.Basic? "enabled" : "disabled") + ")");51 Log.Out ("Started Webserver on " + port + " (authentication " + (authEnabled ? "enabled" : "disabled") + ")"); 48 52 } catch (Exception e) { 49 53 Log.Out ("Error in Web.ctor: " + e); … … 58 62 HttpListenerBasicIdentity user = Authorize (ctx); 59 63 60 if (ctx.Request.Url.AbsolutePath.Length < 2) { 61 handlers ["/index.htm"].HandleRequest (ctx.Request, ctx.Response, user); 62 return; 63 } else { 64 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 65 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 66 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 67 return; 64 if (!authEnabled || (user.Name.ToLower ().Equals ("admin") && user.Password.Equals (GamePrefs.GetString (EnumGamePrefs.ControlPanelPassword)))) { 65 if (ctx.Request.Url.AbsolutePath.Length < 2) { 66 handlers ["/index.htm"].HandleRequest (ctx.Request, ctx.Response, user); 67 return; 68 } else { 69 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 70 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 71 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 72 return; 73 } 68 74 } 69 75 } 76 77 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\""); 78 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; 79 } else { 80 ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; 81 ctx.Response.Headers ["WWW-Authenticate"] = "Basic realm=\"" + realm + "\""; 70 82 } 71 72 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\"");73 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound;74 83 75 84 // byte[] buf = Encoding.UTF8.GetBytes ("Hello World"); -
binary-improvements/bin/Release/7dtd-server-fixes_version.txt
r168 r172 1 Version: 0.92.5361. 288331 Version: 0.92.5361.41834
Note:
See TracChangeset
for help on using the changeset viewer.