Index: binary-improvements/MapRendering/Web/WebPermissions.cs
===================================================================
--- binary-improvements/MapRendering/Web/WebPermissions.cs	(revision 279)
+++ binary-improvements/MapRendering/Web/WebPermissions.cs	(revision 325)
@@ -1,29 +1,19 @@
-using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Xml;
 
-namespace AllocsFixes.NetConnections.Servers.Web
-{
+namespace AllocsFixes.NetConnections.Servers.Web {
 	public class WebPermissions {
-		private static WebPermissions instance = null;
-
-		public static WebPermissions Instance {
-			get {
-				lock (typeof(WebPermissions)) {
-					if (instance == null) {
-						instance = new WebPermissions ();
-					}
-					return instance;
-				}
-			}
-		}
-
 		private const string PERMISSIONS_FILE = "webpermissions.xml";
-		Dictionary<string, AdminToken> admintokens;
-		Dictionary<string, WebModulePermission> modules;
-		Dictionary<string, WebModulePermission> knownModules = new Dictionary<string, WebModulePermission> ();
-		WebModulePermission defaultModulePermission = new WebModulePermission ("", 0);
-		FileSystemWatcher fileWatcher;
+		private static WebPermissions instance;
+		private readonly WebModulePermission defaultModulePermission = new WebModulePermission ("", 0);
+
+		private readonly Dictionary<string, WebModulePermission> knownModules =
+			new Dictionary<string, WebModulePermission> ();
+
+		private Dictionary<string, AdminToken> admintokens;
+		private FileSystemWatcher fileWatcher;
+
+		private Dictionary<string, WebModulePermission> modules;
 
 		public WebPermissions () {
@@ -33,4 +23,16 @@
 		}
 
+		public static WebPermissions Instance {
+			get {
+				lock (typeof (WebPermissions)) {
+					if (instance == null) {
+						instance = new WebPermissions ();
+					}
+
+					return instance;
+				}
+			}
+		}
+
 		public bool ModuleAllowedWithLevel (string _module, int _level) {
 			WebModulePermission permInfo = GetModulePermission (_module);
@@ -41,7 +43,7 @@
 			if (IsAdmin (_name) && admintokens [_name].token == _token) {
 				return admintokens [_name];
-			} else {
-				return null;
-			}
+			}
+
+			return null;
 		}
 
@@ -50,4 +52,5 @@
 				return modules [_module.ToLower ()];
 			}
+
 			return defaultModulePermission;
 		}
@@ -83,5 +86,5 @@
 			return result;
 		}
-	
+
 
 		// Commands
@@ -99,7 +102,8 @@
 			if (!string.IsNullOrEmpty (_module)) {
 				lock (this) {
-                    if (!IsKnownModule( _module)) {
+					if (!IsKnownModule (_module)) {
 						knownModules.Add (_module, new WebModulePermission (_module, _defaultPermission));
-                    }
+					}
+
 					if (_defaultPermission > 0 && !modules.ContainsKey (_module.ToLower ())) {
 						AddModulePermission (_module, _defaultPermission);
@@ -114,9 +118,9 @@
 					return knownModules.ContainsKey (_module);
 				}
-			} else {
-				return false;
-			}
-		}
-	
+			}
+
+			return false;
+		}
+
 		public void RemoveModulePermission (string _module, bool _save = true) {
 			lock (this) {
@@ -140,5 +144,5 @@
 			return result;
 		}
-	
+
 
 		//IO Tasks
@@ -146,7 +150,7 @@
 		private void InitFileWatcher () {
 			fileWatcher = new FileSystemWatcher (GetFilePath (), GetFileName ());
-			fileWatcher.Changed += new FileSystemEventHandler (OnFileChanged);
-			fileWatcher.Created += new FileSystemEventHandler (OnFileChanged);
-			fileWatcher.Deleted += new FileSystemEventHandler (OnFileChanged);
+			fileWatcher.Changed += OnFileChanged;
+			fileWatcher.Created += OnFileChanged;
+			fileWatcher.Deleted += OnFileChanged;
 			fileWatcher.EnableRaisingEvents = true;
 		}
@@ -198,4 +202,5 @@
 							continue;
 						}
+
 						if (subChild.NodeType != XmlNodeType.Element) {
 							Log.Warning ("Unexpected XML node found in 'admintokens' section: " + subChild.OuterXml);
@@ -203,18 +208,21 @@
 						}
 
-						XmlElement lineItem = (XmlElement)subChild;
+						XmlElement lineItem = (XmlElement) subChild;
 
 						if (!lineItem.HasAttribute ("name")) {
-							Log.Warning ("Ignoring admintoken-entry because of missing 'name' attribute: " + subChild.OuterXml);
+							Log.Warning ("Ignoring admintoken-entry because of missing 'name' attribute: " +
+							             subChild.OuterXml);
 							continue;
 						}
 
 						if (!lineItem.HasAttribute ("token")) {
-							Log.Warning ("Ignoring admintoken-entry because of missing 'token' attribute: " + subChild.OuterXml);
+							Log.Warning ("Ignoring admintoken-entry because of missing 'token' attribute: " +
+							             subChild.OuterXml);
 							continue;
 						}
 
 						if (!lineItem.HasAttribute ("permission_level")) {
-							Log.Warning ("Ignoring admintoken-entry because of missing 'permission_level' attribute: " + subChild.OuterXml);
+							Log.Warning ("Ignoring admintoken-entry because of missing 'permission_level' attribute: " +
+							             subChild.OuterXml);
 							continue;
 						}
@@ -224,10 +232,11 @@
 						int permissionLevel = 2000;
 						if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) {
-							Log.Warning ("Ignoring admintoken-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + subChild.OuterXml);
-							continue;
-						}
-
-						AddAdmin (name, token, permissionLevel, false); 
-					
+							Log.Warning (
+								"Ignoring admintoken-entry because of invalid (non-numeric) value for 'permission_level' attribute: " +
+								subChild.OuterXml);
+							continue;
+						}
+
+						AddAdmin (name, token, permissionLevel, false);
 					}
 				}
@@ -238,4 +247,5 @@
 							continue;
 						}
+
 						if (subChild.NodeType != XmlNodeType.Element) {
 							Log.Warning ("Unexpected XML node found in 'permissions' section: " + subChild.OuterXml);
@@ -243,26 +253,29 @@
 						}
 
-						XmlElement lineItem = (XmlElement)subChild;
+						XmlElement lineItem = (XmlElement) subChild;
 
 						if (!lineItem.HasAttribute ("module")) {
-							Log.Warning ("Ignoring permission-entry because of missing 'module' attribute: " + subChild.OuterXml);
-							continue;
-						}
-					
+							Log.Warning ("Ignoring permission-entry because of missing 'module' attribute: " +
+							             subChild.OuterXml);
+							continue;
+						}
+
 						if (!lineItem.HasAttribute ("permission_level")) {
-							Log.Warning ("Ignoring permission-entry because of missing 'permission_level' attribute: " + subChild.OuterXml);
-							continue;
-						}
-					
+							Log.Warning ("Ignoring permission-entry because of missing 'permission_level' attribute: " +
+							             subChild.OuterXml);
+							continue;
+						}
+
 						int permissionLevel = 0;
 						if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) {
-							Log.Warning ("Ignoring permission-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + subChild.OuterXml);
-							continue;
-						}
-
-						AddModulePermission (lineItem.GetAttribute ("module").ToLower (), permissionLevel, false); 
-					}
-				}
-
+							Log.Warning (
+								"Ignoring permission-entry because of invalid (non-numeric) value for 'permission_level' attribute: " +
+								subChild.OuterXml);
+							continue;
+						}
+
+						AddModulePermission (lineItem.GetAttribute ("module").ToLower (), permissionLevel, false);
+					}
+				}
 			}
 
@@ -273,40 +286,47 @@
 			fileWatcher.EnableRaisingEvents = false;
 
-			using (StreamWriter sw = new StreamWriter(GetFullPath ())) {
-                sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-                sw.WriteLine ("<webpermissions>");
-                sw.WriteLine  ();
-                sw.WriteLine ("	<admintokens>");
-                sw.WriteLine ("		<!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->");
-                foreach (AdminToken at in admintokens.Values) {
-                    sw.WriteLine (string.Format ("		<token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token, at.permissionLevel));
-                }
-                sw.WriteLine ("	</admintokens>");
-                sw.WriteLine ();
-                sw.WriteLine ("	<permissions>");
-                foreach (WebModulePermission wap in modules.Values) {
-                    sw.WriteLine (string.Format ("		<permission module=\"{0}\" permission_level=\"{1}\" />", wap.module, wap.permissionLevel));
-                }
-                sw.WriteLine ("		<!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getlog\" permission_level=\"0\" /> -->");
-                sw.WriteLine ("		<!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getstats\" permission_level=\"1000\" /> -->");
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1000\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getplayerslocation\" permission_level=\"1000\" /> -->");
-                sw.WriteLine ("		<!-- <permission module=\"webapi.viewallplayers\" permission_level=\"1\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getlandclaims\" permission_level=\"1000\" /> -->");
-                sw.WriteLine ("		<!-- <permission module=\"webapi.viewallclaims\" permission_level=\"1\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getplayerinventory\" permission_level=\"1\" /> -->");
-                sw.WriteLine ();
-                sw.WriteLine ("		<!-- <permission module=\"webapi.gethostilelocation\" permission_level=\"1\" /> -->");
-                sw.WriteLine ("		<!-- <permission module=\"webapi.getanimalslocation\" permission_level=\"1\" /> -->");
-                sw.WriteLine ("	</permissions>");
-                sw.WriteLine ();
-                sw.WriteLine ("</webpermissions>");
+			using (StreamWriter sw = new StreamWriter (GetFullPath ())) {
+				sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+				sw.WriteLine ("<webpermissions>");
+				sw.WriteLine ();
+				sw.WriteLine ("	<admintokens>");
+				sw.WriteLine (
+					"		<!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->");
+				foreach (AdminToken at in admintokens.Values) {
+					sw.WriteLine ("		<token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token,
+						at.permissionLevel);
+				}
+
+				sw.WriteLine ("	</admintokens>");
+				sw.WriteLine ();
+				sw.WriteLine ("	<permissions>");
+				foreach (WebModulePermission wap in modules.Values) {
+					sw.WriteLine ("		<permission module=\"{0}\" permission_level=\"{1}\" />", wap.module,
+						wap.permissionLevel);
+				}
+
+				sw.WriteLine ("		<!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getlog\" permission_level=\"0\" /> -->");
+				sw.WriteLine (
+					"		<!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getstats\" permission_level=\"1000\" /> -->");
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1000\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine (
+					"		<!-- <permission module=\"webapi.getplayerslocation\" permission_level=\"1000\" /> -->");
+				sw.WriteLine ("		<!-- <permission module=\"webapi.viewallplayers\" permission_level=\"1\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getlandclaims\" permission_level=\"1000\" /> -->");
+				sw.WriteLine ("		<!-- <permission module=\"webapi.viewallclaims\" permission_level=\"1\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getplayerinventory\" permission_level=\"1\" /> -->");
+				sw.WriteLine ();
+				sw.WriteLine ("		<!-- <permission module=\"webapi.gethostilelocation\" permission_level=\"1\" /> -->");
+				sw.WriteLine ("		<!-- <permission module=\"webapi.getanimalslocation\" permission_level=\"1\" /> -->");
+				sw.WriteLine ("	</permissions>");
+				sw.WriteLine ();
+				sw.WriteLine ("</webpermissions>");
 
 				sw.Flush ();
@@ -318,9 +338,8 @@
 
 
-		
 		public class AdminToken {
 			public string name;
+			public int permissionLevel;
 			public string token;
-			public int permissionLevel;
 
 			public AdminToken (string _name, string _token, int _permissionLevel) {
@@ -340,7 +359,4 @@
 			}
 		}
-
-
 	}
 }
-
