Index: binary-improvements/MapRendering/Web/Web.cs
===================================================================
--- binary-improvements/MapRendering/Web/Web.cs	(revision 314)
+++ binary-improvements/MapRendering/Web/Web.cs	(revision 325)
@@ -1,5 +1,4 @@
 using System;
 using System.Collections.Generic;
-using System.Collections.Specialized;
 using System.IO;
 using System.Net;
@@ -8,28 +7,18 @@
 using System.Text;
 using System.Threading;
+using AllocsFixes.FileCache;
+using AllocsFixes.NetConnections.Servers.Web.Handlers;
 using UnityEngine;
 
-using AllocsFixes.NetConnections.Servers.Web.Handlers;
-
-namespace AllocsFixes.NetConnections.Servers.Web
-{
+namespace AllocsFixes.NetConnections.Servers.Web {
 	public class Web : IConsoleServer {
 		private const int GUEST_PERMISSION_LEVEL = 2000;
+		public static int handlingCount;
+		public static int currentHandlers;
+		public static long totalHandlingTime = 0;
 		private readonly HttpListener _listener = new HttpListener ();
-		private Dictionary<string, PathHandler> handlers = new Dictionary<string, PathHandler> ();
-		public static int handlingCount = 0;
-		public static int currentHandlers = 0;
-		public static long totalHandlingTime = 0;
-		private string dataFolder;
-		private bool useStaticCache = false;
-
-		public static bool isSslRedirected (HttpListenerRequest req) {
-			string proto = req.Headers ["X-Forwarded-Proto"];
-			if (!string.IsNullOrEmpty (proto)) {
-				return proto.Equals ("https", StringComparison.OrdinalIgnoreCase);
-			}
-
-			return false;
-		}
+		private readonly string dataFolder;
+		private readonly Dictionary<string, PathHandler> handlers = new Dictionary<string, PathHandler> ();
+		private readonly bool useStaticCache;
 
 		public ConnectionHandler connectionHandler;
@@ -42,5 +31,7 @@
 					return;
 				}
-				if (!Directory.Exists (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/webserver")) {
+
+				if (!Directory.Exists (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) +
+				                       "/webserver")) {
 					Log.Out ("Webserver not started (folder \"webserver\" not found in WebInterface mod folder)");
 					return;
@@ -56,39 +47,39 @@
 					return;
 				}
- 
-				handlers.Add (
-						"/index.htm",
-						new SimpleRedirectHandler ("/static/index.html"));
-				handlers.Add (
-						"/favicon.ico",
-						new SimpleRedirectHandler ("/static/favicon.ico"));
-				handlers.Add (
+
+				handlers.Add (
+					"/index.htm",
+					new SimpleRedirectHandler ("/static/index.html"));
+				handlers.Add (
+					"/favicon.ico",
+					new SimpleRedirectHandler ("/static/favicon.ico"));
+				handlers.Add (
+					"/session/",
+					new SessionHandler (
 						"/session/",
-						new SessionHandler (
-									"/session/",
-									dataFolder,
-									this)
-				);
-				handlers.Add (
-						"/userstatus",
-						new UserStatusHandler ()
+						dataFolder,
+						this)
+				);
+				handlers.Add (
+					"/userstatus",
+					new UserStatusHandler ()
 				);
 				if (useStaticCache) {
 					handlers.Add (
+						"/static/",
+						new StaticHandler (
 							"/static/",
-							new StaticHandler (
-									"/static/",
-									dataFolder,
-									new AllocsFixes.FileCache.SimpleCache (),
-									false)
+							dataFolder,
+							new SimpleCache (),
+							false)
 					);
 				} else {
 					handlers.Add (
+						"/static/",
+						new StaticHandler (
 							"/static/",
-							new StaticHandler (
-									"/static/",
-									dataFolder,
-									new AllocsFixes.FileCache.DirectAccess (),
-									false)
+							dataFolder,
+							new DirectAccess (),
+							false)
 					);
 				}
@@ -118,10 +109,10 @@
 				connectionHandler = new ConnectionHandler (this);
 
-				_listener.Prefixes.Add (String.Format ("http://*:{0}/", webPort + 2));
+				_listener.Prefixes.Add (string.Format ("http://*:{0}/", webPort + 2));
 				_listener.Start ();
 
 				SdtdConsole.Instance.RegisterServer (this);
 
-				_listener.BeginGetContext (new AsyncCallback (HandleRequest), _listener);
+				_listener.BeginGetContext (HandleRequest, _listener);
 
 				Log.Out ("Started Webserver on " + (webPort + 2));
@@ -129,4 +120,30 @@
 				Log.Out ("Error in Web.ctor: " + e);
 			}
+		}
+
+		public void Disconnect () {
+			try {
+				_listener.Stop ();
+				_listener.Close ();
+			} catch (Exception e) {
+				Log.Out ("Error in Web.Disconnect: " + e);
+			}
+		}
+
+		public void SendLine (string line) {
+			connectionHandler.SendLine (line);
+		}
+
+		public void SendLog (string text, string trace, LogType type) {
+			// Do nothing, handled by LogBuffer internally
+		}
+
+		public static bool isSslRedirected (HttpListenerRequest req) {
+			string proto = req.Headers ["X-Forwarded-Proto"];
+			if (!string.IsNullOrEmpty (proto)) {
+				return proto.Equals ("https", StringComparison.OrdinalIgnoreCase);
+			}
+
+			return false;
 		}
 
@@ -135,7 +152,8 @@
 				Interlocked.Increment (ref handlingCount);
 				Interlocked.Increment (ref currentHandlers);
+
 //				MicroStopwatch msw = new MicroStopwatch ();
 				HttpListenerContext ctx = _listener.EndGetContext (result);
-				_listener.BeginGetContext (new AsyncCallback (HandleRequest), _listener);
+				_listener.BeginGetContext (HandleRequest, _listener);
 				try {
 					HttpListenerRequest request = ctx.Request;
@@ -163,5 +181,5 @@
 					// No game yet -> fail request
 					if (GameManager.Instance.World == null) {
-						response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
+						response.StatusCode = (int) HttpStatusCode.ServiceUnavailable;
 						return;
 					}
@@ -174,13 +192,12 @@
 							if (request.Url.AbsolutePath.StartsWith (kvp.Key)) {
 								if (!kvp.Value.IsAuthorizedForHandler (conn, permissionLevel)) {
-									response.StatusCode = (int)HttpStatusCode.Forbidden;
+									response.StatusCode = (int) HttpStatusCode.Forbidden;
 									if (conn != null) {
 										//Log.Out ("Web.HandleRequest: user '{0}' not allowed to access '{1}'", conn.SteamID, kvp.Value.ModuleName);
-									} else {
-										//Log.Out ("Web.HandleRequest: unidentified user from '{0}' not allowed to access '{1}'", request.RemoteEndPoint.Address, kvp.Value.ModuleName);
 									}
 								} else {
 									kvp.Value.HandleRequest (request, response, conn, permissionLevel);
 								}
+
 								return;
 							}
@@ -190,8 +207,9 @@
 					// Not really relevant for non-debugging purposes:
 					//Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + request.Url.AbsolutePath + "\"");
-					response.StatusCode = (int)HttpStatusCode.NotFound;
+					response.StatusCode = (int) HttpStatusCode.NotFound;
 				} catch (IOException e) {
 					if (e.InnerException is SocketException) {
-						Log.Out ("Error in Web.HandleRequest(): Remote host closed connection: " + e.InnerException.Message);
+						Log.Out ("Error in Web.HandleRequest(): Remote host closed connection: " +
+						         e.InnerException.Message);
 					} else {
 						Log.Out ("Error (IO) in Web.HandleRequest(): " + e);
@@ -203,4 +221,5 @@
 						ctx.Response.Close ();
 					}
+
 //					msw.Stop ();
 //					totalHandlingTime += msw.ElapsedMicroseconds;
@@ -223,15 +242,17 @@
 				if (con != null) {
 					_con = con;
-					return GameManager.Instance.adminTools.GetAdminToolsClientInfo (_con.SteamID.ToString ()).PermissionLevel;
+					return GameManager.Instance.adminTools.GetAdminToolsClientInfo (_con.SteamID.ToString ())
+						.PermissionLevel;
 				}
 			}
 
 			if (_req.QueryString ["adminuser"] != null && _req.QueryString ["admintoken"] != null) {
-				WebPermissions.AdminToken admin = WebPermissions.Instance.GetWebAdmin (_req.QueryString ["adminuser"], _req.QueryString ["admintoken"]);
+				WebPermissions.AdminToken admin = WebPermissions.Instance.GetWebAdmin (_req.QueryString ["adminuser"],
+					_req.QueryString ["admintoken"]);
 				if (admin != null) {
 					return admin.permissionLevel;
-				} else {
-					Log.Warning ("Invalid Admintoken used from " + _req.RemoteEndPoint.ToString ());
-				}
+				}
+
+				Log.Warning ("Invalid Admintoken used from " + _req.RemoteEndPoint);
 			}
 
@@ -242,10 +263,12 @@
 						WebConnection con = connectionHandler.LogIn (id, _req.RemoteEndPoint.Address.ToString ());
 						_con = con;
-						int level = GameManager.Instance.adminTools.GetAdminToolsClientInfo (id.ToString ()).PermissionLevel;
-						Log.Out ("Steam OpenID login from {0} with ID {1}, permission level {2}", _req.RemoteEndPoint.ToString (), con.SteamID, level);
+						int level = GameManager.Instance.adminTools.GetAdminToolsClientInfo (id.ToString ())
+							.PermissionLevel;
+						Log.Out ("Steam OpenID login from {0} with ID {1}, permission level {2}",
+							_req.RemoteEndPoint.ToString (), con.SteamID, level);
 						return level;
-					} else {
-						Log.Out ("Steam OpenID login failed from {0}", _req.RemoteEndPoint.ToString ());
-					}
+					}
+
+					Log.Out ("Steam OpenID login failed from {0}", _req.RemoteEndPoint.ToString ());
 				} catch (Exception e) {
 					Log.Error ("Error validating login:");
@@ -255,21 +278,4 @@
 
 			return GUEST_PERMISSION_LEVEL;
-		}
-
-		public void Disconnect () {
-			try {
-				_listener.Stop ();
-				_listener.Close ();
-			} catch (Exception e) {
-				Log.Out ("Error in Web.Disconnect: " + e);
-			}
-		}
-
-		public void SendLine (string line) {
-			connectionHandler.SendLine (line);
-		}
-
-		public void SendLog (string text, string trace, UnityEngine.LogType type) {
-			// Do nothing, handled by LogBuffer internally
 		}
 
@@ -281,5 +287,4 @@
 			resp.OutputStream.Write (buf, 0, buf.Length);
 		}
-
 	}
 }
