Changeset 325 for binary-improvements/MapRendering/Web
- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- Location:
- binary-improvements/MapRendering/Web
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/ExecuteConsoleCommand.cs
r306 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 1 using System; 4 using System.Collections.Generic;5 2 using System.Net; 6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class ExecuteConsoleCommand : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 5 public class ExecuteConsoleCommand : WebAPI { 6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 7 int permissionLevel) { 12 8 if (string.IsNullOrEmpty (req.QueryString ["command"])) { 13 resp.StatusCode = (int) HttpStatusCode.BadRequest;9 resp.StatusCode = (int) HttpStatusCode.BadRequest; 14 10 Web.SetResponseTextContent (resp, "No command given"); 15 11 return; … … 17 13 18 14 WebCommandResult.ResultType responseType = 19 req.QueryString ["raw"] != null ? WebCommandResult.ResultType.Raw : 20 (req.QueryString ["simple"] != null ? WebCommandResult.ResultType.ResultOnly : 21 WebCommandResult.ResultType.Full); 15 req.QueryString ["raw"] != null 16 ? WebCommandResult.ResultType.Raw 17 : (req.QueryString ["simple"] != null 18 ? WebCommandResult.ResultType.ResultOnly 19 : WebCommandResult.ResultType.Full); 22 20 23 21 string commandline = req.QueryString ["command"]; … … 28 26 29 27 if (command == null) { 30 resp.StatusCode = (int) HttpStatusCode.NotImplemented;28 resp.StatusCode = (int) HttpStatusCode.NotImplemented; 31 29 Web.SetResponseTextContent (resp, "Unknown command"); 32 30 return; 33 31 } 34 32 35 AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ()); 33 AdminToolsCommandPermissions atcp = 34 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ()); 36 35 37 36 if (permissionLevel > atcp.PermissionLevel) { 38 resp.StatusCode = (int) HttpStatusCode.Forbidden;37 resp.StatusCode = (int) HttpStatusCode.Forbidden; 39 38 Web.SetResponseTextContent (resp, "You are not allowed to execute this command"); 40 39 return; … … 51 50 } 52 51 } 53 -
binary-improvements/MapRendering/Web/API/GetAllowedCommands.cs
r279 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 using AllocsFixes.PersistentData;3 using System;4 using System.Collections.Generic;5 using System.Net;6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 5 public class GetAllowedCommands : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 7 int permissionLevel) { 11 8 JSONObject result = new JSONObject (); 12 9 JSONArray entries = new JSONArray (); 13 10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 14 AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ()); 11 AdminToolsCommandPermissions atcp = 12 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ()); 15 13 if (permissionLevel <= atcp.PermissionLevel) { 16 14 string cmd = string.Empty; … … 20 18 } 21 19 } 20 22 21 JSONObject cmdObj = new JSONObject (); 23 22 cmdObj.Add ("command", new JSONString (cmd)); … … 38 37 } 39 38 } 40 -
binary-improvements/MapRendering/Web/API/GetAnimalsLocation.cs
r313 r325 1 using AllocsFixes.JSON; 1 using System.Collections.Generic; 2 using System.Net; 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.LiveData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 class GetAnimalsLocation : WebAPI 10 { 11 private List<EntityAnimal> animals = new List<EntityAnimal> (); 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 internal class GetAnimalsLocation : WebAPI { 8 private readonly List<EntityAnimal> animals = new List<EntityAnimal> (); 12 9 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 14 15 JSONArray animalsJsResult = new JSONArray();10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 11 int permissionLevel) { 12 JSONArray animalsJsResult = new JSONArray (); 16 13 17 14 Animals.Instance.Get (animals); 18 for (int i = 0; i < animals.Count; i++) 19 { 15 for (int i = 0; i < animals.Count; i++) { 20 16 EntityAnimal entity = animals [i]; 21 Vector3i position = new Vector3i(entity.GetPosition());17 Vector3i position = new Vector3i (entity.GetPosition ()); 22 18 23 JSONObject jsonPOS = new JSONObject();24 jsonPOS.Add("x", new JSONNumber(position.x));25 jsonPOS.Add("y", new JSONNumber(position.y));26 jsonPOS.Add("z", new JSONNumber(position.z));19 JSONObject jsonPOS = new JSONObject (); 20 jsonPOS.Add ("x", new JSONNumber (position.x)); 21 jsonPOS.Add ("y", new JSONNumber (position.y)); 22 jsonPOS.Add ("z", new JSONNumber (position.z)); 27 23 28 JSONObject pJson = new JSONObject();29 pJson.Add("id", new JSONNumber(entity.entityId));24 JSONObject pJson = new JSONObject (); 25 pJson.Add ("id", new JSONNumber (entity.entityId)); 30 26 31 if (!string.IsNullOrEmpty(entity.EntityName)) 32 pJson.Add("name", new JSONString(entity.EntityName)); 33 else 34 pJson.Add("name", new JSONString("animal class #" + entity.entityClass.ToString())); 27 if (!string.IsNullOrEmpty (entity.EntityName)) { 28 pJson.Add ("name", new JSONString (entity.EntityName)); 29 } else { 30 pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass)); 31 } 35 32 36 pJson.Add("position", jsonPOS);33 pJson.Add ("position", jsonPOS); 37 34 38 animalsJsResult.Add(pJson);39 40 41 WriteJSON(resp, animalsJsResult);42 43 35 animalsJsResult.Add (pJson); 36 } 37 38 WriteJSON (resp, animalsJsResult); 39 } 40 } 44 41 } -
binary-improvements/MapRendering/Web/API/GetHostileLocation.cs
r313 r325 1 using AllocsFixes.JSON; 1 using System.Collections.Generic; 2 using System.Net; 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.LiveData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 class GetHostileLocation : WebAPI 10 { 11 private List<EntityEnemy> enemies = new List<EntityEnemy> (); 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 internal class GetHostileLocation : WebAPI { 8 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> (); 12 9 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 14 15 JSONArray hostilesJsResult = new JSONArray();10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 11 int permissionLevel) { 12 JSONArray hostilesJsResult = new JSONArray (); 16 13 17 14 Hostiles.Instance.Get (enemies); 18 for (int i = 0; i < enemies.Count; i++) 19 { 15 for (int i = 0; i < enemies.Count; i++) { 20 16 EntityEnemy entity = enemies [i]; 21 Vector3i position = new Vector3i(entity.GetPosition());17 Vector3i position = new Vector3i (entity.GetPosition ()); 22 18 23 JSONObject jsonPOS = new JSONObject();24 jsonPOS.Add("x", new JSONNumber(position.x));25 jsonPOS.Add("y", new JSONNumber(position.y));26 jsonPOS.Add("z", new JSONNumber(position.z));19 JSONObject jsonPOS = new JSONObject (); 20 jsonPOS.Add ("x", new JSONNumber (position.x)); 21 jsonPOS.Add ("y", new JSONNumber (position.y)); 22 jsonPOS.Add ("z", new JSONNumber (position.z)); 27 23 28 JSONObject pJson = new JSONObject();29 pJson.Add("id", new JSONNumber(entity.entityId));24 JSONObject pJson = new JSONObject (); 25 pJson.Add ("id", new JSONNumber (entity.entityId)); 30 26 31 if (!string.IsNullOrEmpty(entity.EntityName)) 32 pJson.Add("name", new JSONString(entity.EntityName)); 33 else 34 pJson.Add("name", new JSONString("enemy class #" + entity.entityClass.ToString())); 27 if (!string.IsNullOrEmpty (entity.EntityName)) { 28 pJson.Add ("name", new JSONString (entity.EntityName)); 29 } else { 30 pJson.Add ("name", new JSONString ("enemy class #" + entity.entityClass)); 31 } 35 32 36 pJson.Add("position", jsonPOS);33 pJson.Add ("position", jsonPOS); 37 34 38 hostilesJsResult.Add(pJson);39 35 hostilesJsResult.Add (pJson); 36 } 40 37 41 WriteJSON(resp, hostilesJsResult);42 43 38 WriteJSON (resp, hostilesJsResult); 39 } 40 } 44 41 } -
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r253 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 7 public class GetLandClaims : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 11 10 string requestedSteamID = string.Empty; 12 11 … … 15 14 requestedSteamID = req.QueryString ["steamid"]; 16 15 if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) { 17 resp.StatusCode = (int) HttpStatusCode.BadRequest;16 resp.StatusCode = (int) HttpStatusCode.BadRequest; 18 17 Web.SetResponseTextContent (resp, "Invalid SteamID given"); 19 18 return; … … 25 24 26 25 bool bViewAll = WebConnection.CanViewAllClaims (permissionLevel); 27 26 28 27 JSONObject result = new JSONObject (); 29 28 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize))); … … 35 34 if (!string.IsNullOrEmpty (requestedSteamID) || !bViewAll) { 36 35 if (!string.IsNullOrEmpty (requestedSteamID) && !bViewAll) { 37 ownerFilters = new LandClaimList.OwnerFilter[] {36 ownerFilters = new[] { 38 37 LandClaimList.SteamIdFilter (user.SteamID.ToString ()), 39 38 LandClaimList.SteamIdFilter (requestedSteamID) 40 39 }; 41 40 } else if (!bViewAll) { 42 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (user.SteamID.ToString ())};41 ownerFilters = new[] {LandClaimList.SteamIdFilter (user.SteamID.ToString ())}; 43 42 } else { 44 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (requestedSteamID)};43 ownerFilters = new[] {LandClaimList.SteamIdFilter (requestedSteamID)}; 45 44 } 46 45 } 46 47 47 LandClaimList.PositionFilter[] posFilters = null; 48 48 49 Dictionary<P ersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);49 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters); 50 50 51 foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) { 52 51 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 53 52 try { 54 53 JSONObject owner = new JSONObject (); … … 83 82 } 84 83 } 85 -
binary-improvements/MapRendering/Web/API/GetLog.cs
r253 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 using System;4 1 using System.Collections.Generic; 5 2 using System.Net; 3 using AllocsFixes.JSON; 6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 6 public class GetLog : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 11 9 int firstLine, lastLine; 12 10 … … 39 37 } 40 38 } 41 -
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r321 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 6 public class GetPlayerInventories : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 9 JSONArray AllInventoriesResult = new JSONArray (); 9 10 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {11 JSONArray AllInventoriesResult = new JSONArray ();12 13 11 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) { 14 12 Player p = PersistentContainer.Instance.Players [sid, false]; … … 55 53 WriteJSON (resp, AllInventoriesResult); 56 54 } 57 58 55 } 59 56 } 60 -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r321 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 7 public class GetPlayerInventory : WebAPI { 10 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,int permissionLevel) {8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 12 10 if (req.QueryString ["steamid"] == null) { 13 resp.StatusCode = (int) HttpStatusCode.InternalServerError;11 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 14 12 Web.SetResponseTextContent (resp, "No SteamID given"); 15 13 return; … … 18 16 Player p = PersistentContainer.Instance.Players [req.QueryString ["steamid"], false]; 19 17 if (p == null) { 20 resp.StatusCode = (int) HttpStatusCode.InternalServerError;18 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 21 19 Web.SetResponseTextContent (resp, "Invalid or unknown SteamID given"); 22 20 return; … … 87 85 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); 88 86 } 87 89 88 return jsonItem; 90 } else {91 return new JSONNull ();92 89 } 90 91 return new JSONNull (); 93 92 } 94 95 93 } 96 94 } 97 -
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r324 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 1 using System; 4 2 using System.Collections.Generic; … … 6 4 using System.Net; 7 5 using System.Text.RegularExpressions; 8 9 namespace AllocsFixes.NetConnections.Servers.Web.API 10 { 11 public class GetPlayerList : WebAPI 12 { 13 private static Regex numberFilterMatcher = new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); 14 private enum NumberMatchType { 15 Equal, 16 Greater, 17 GreaterEqual, 18 Lesser, 19 LesserEqual 20 } 21 22 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 23 { 24 AdminTools admTools = GameManager.Instance.adminTools; 25 user = user ?? new WebConnection ("", "", 0L); 26 27 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 6 using AllocsFixes.JSON; 7 using AllocsFixes.PersistentData; 8 9 namespace AllocsFixes.NetConnections.Servers.Web.API { 10 public class GetPlayerList : WebAPI { 11 private static readonly Regex numberFilterMatcher = 12 new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); 13 14 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 15 int permissionLevel) { 16 AdminTools admTools = GameManager.Instance.adminTools; 17 user = user ?? new WebConnection ("", "", 0L); 18 19 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 28 20 29 21 // TODO: Sort (and filter?) prior to converting to JSON ... hard as how to get the correct column's data? (i.e. column name matches JSON object field names, not source data) … … 46 38 47 39 foreach (string sid in playersList.SteamIDs) { 48 Player p = playersList [sid, false]; 49 50 ulong player_steam_ID = 0L; 51 if (!ulong.TryParse (sid, out player_steam_ID)) 52 player_steam_ID = 0L; 53 54 if ((player_steam_ID == user.SteamID) || bViewAll) { 55 JSONObject pos = new JSONObject (); 56 pos.Add("x", new JSONNumber (p.LastPosition.x)); 57 pos.Add("y", new JSONNumber (p.LastPosition.y)); 58 pos.Add("z", new JSONNumber (p.LastPosition.z)); 59 60 JSONObject pJson = new JSONObject (); 61 pJson.Add("steamid", new JSONString (sid)); 62 pJson.Add("entityid", new JSONNumber (p.EntityID)); 63 pJson.Add("ip", new JSONString (p.IP)); 64 pJson.Add("name", new JSONString (p.Name)); 65 pJson.Add("online", new JSONBoolean (p.IsOnline)); 66 pJson.Add("position", pos); 40 Player p = playersList [sid, false]; 41 42 ulong player_steam_ID = 0L; 43 if (!ulong.TryParse (sid, out player_steam_ID)) { 44 player_steam_ID = 0L; 45 } 46 47 if (player_steam_ID == user.SteamID || bViewAll) { 48 JSONObject pos = new JSONObject (); 49 pos.Add ("x", new JSONNumber (p.LastPosition.x)); 50 pos.Add ("y", new JSONNumber (p.LastPosition.y)); 51 pos.Add ("z", new JSONNumber (p.LastPosition.z)); 52 53 JSONObject pJson = new JSONObject (); 54 pJson.Add ("steamid", new JSONString (sid)); 55 pJson.Add ("entityid", new JSONNumber (p.EntityID)); 56 pJson.Add ("ip", new JSONString (p.IP)); 57 pJson.Add ("name", new JSONString (p.Name)); 58 pJson.Add ("online", new JSONBoolean (p.IsOnline)); 59 pJson.Add ("position", pos); 67 60 68 61 pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 69 pJson.Add ("lastonline", new JSONString (p.LastOnline.ToUniversalTime ().ToString ("yyyy-MM-ddTHH:mm:ssZ"))); 62 pJson.Add ("lastonline", 63 new JSONString (p.LastOnline.ToUniversalTime ().ToString ("yyyy-MM-ddTHH:mm:ssZ"))); 70 64 pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 71 65 … … 76 70 banned = new JSONBoolean (false); 77 71 } 72 78 73 pJson.Add ("banned", banned); 79 74 80 75 playerList.Add (pJson); 81 82 76 } 77 } 83 78 84 79 IEnumerable<JSONObject> list = playerList; … … 124 119 } 125 120 126 private IEnumerable<JSONObject> ExecuteFilter (IEnumerable<JSONObject> _list, string _filterCol, string _filterVal) { 121 private IEnumerable<JSONObject> ExecuteFilter (IEnumerable<JSONObject> _list, string _filterCol, 122 string _filterVal) { 127 123 if (_list.Count () == 0) { 128 124 return _list; … … 131 127 if (_list.First ().ContainsKey (_filterCol)) { 132 128 Type colType = _list.First () [_filterCol].GetType (); 133 if (colType == typeof (JSONNumber)) {129 if (colType == typeof (JSONNumber)) { 134 130 return ExecuteNumberFilter (_list, _filterCol, _filterVal); 135 } else if (colType == typeof(JSONBoolean)) { 131 } 132 133 if (colType == typeof (JSONBoolean)) { 136 134 bool value = _filterVal.Trim ().ToLower () == "true"; 137 135 return _list.Where (line => (line [_filterCol] as JSONBoolean).GetBool () == value); 138 } else if (colType == typeof(JSONString)) { 136 } 137 138 if (colType == typeof (JSONString)) { 139 139 // regex-match whole ^string$, replace * by .*, ? by .?, + by .+ 140 140 _filterVal = _filterVal.Replace ("*", ".*").Replace ("?", ".?").Replace ("+", ".+"); 141 141 _filterVal = "^" + _filterVal + "$"; 142 142 143 //Log.Out ("GetPlayerList: Filter on String with Regex '" + _filterVal + "'"); 143 144 Regex matcher = new Regex (_filterVal, RegexOptions.IgnoreCase); … … 145 146 } 146 147 } 148 147 149 return _list; 148 150 } 149 151 150 152 151 private IEnumerable<JSONObject> ExecuteNumberFilter (IEnumerable<JSONObject> _list, string _filterCol, string _filterVal) { 153 private IEnumerable<JSONObject> ExecuteNumberFilter (IEnumerable<JSONObject> _list, string _filterCol, 154 string _filterVal) { 152 155 // allow value (exact match), =, ==, >=, >, <=, < 153 156 Match filterMatch = numberFilterMatcher.Match (_filterVal); … … 157 160 double epsilon = value / 100000; 158 161 switch (filterMatch.Groups [1].Value) { 159 case "": 160 case "=": 161 case "==": 162 matchType = NumberMatchType.Equal; 163 break; 164 case ">": 165 matchType = NumberMatchType.Greater; 166 break; 167 case ">=": 168 case "=>": 169 matchType = NumberMatchType.GreaterEqual; 170 break; 171 case "<": 172 matchType = NumberMatchType.Lesser; 173 break; 174 case "<=": 175 case "=<": 176 matchType = NumberMatchType.LesserEqual; 177 break; 178 default: 179 matchType = NumberMatchType.Equal; 180 break; 181 } 182 return _list.Where (delegate(JSONObject line) { 162 case "": 163 case "=": 164 case "==": 165 matchType = NumberMatchType.Equal; 166 break; 167 case ">": 168 matchType = NumberMatchType.Greater; 169 break; 170 case ">=": 171 case "=>": 172 matchType = NumberMatchType.GreaterEqual; 173 break; 174 case "<": 175 matchType = NumberMatchType.Lesser; 176 break; 177 case "<=": 178 case "=<": 179 matchType = NumberMatchType.LesserEqual; 180 break; 181 default: 182 matchType = NumberMatchType.Equal; 183 break; 184 } 185 186 return _list.Where (delegate (JSONObject line) { 183 187 double objVal = (line [_filterCol] as JSONNumber).GetDouble (); 184 188 switch (matchType) { 185 case NumberMatchType.Greater:186 return objVal > value;187 case NumberMatchType.GreaterEqual:188 return objVal >= value;189 case NumberMatchType.Lesser:190 return objVal < value;191 case NumberMatchType.LesserEqual:192 return objVal <= value;193 case NumberMatchType.Equal:194 default:195 return NearlyEqual (objVal, value, epsilon);189 case NumberMatchType.Greater: 190 return objVal > value; 191 case NumberMatchType.GreaterEqual: 192 return objVal >= value; 193 case NumberMatchType.Lesser: 194 return objVal < value; 195 case NumberMatchType.LesserEqual: 196 return objVal <= value; 197 case NumberMatchType.Equal: 198 default: 199 return NearlyEqual (objVal, value, epsilon); 196 200 } 197 201 }); 198 } else {199 Log.Out ("GetPlayerList: ignoring invalid filter for number-column '{0}': '{1}'", _filterCol, _filterVal); 200 }202 } 203 204 Log.Out ("GetPlayerList: ignoring invalid filter for number-column '{0}': '{1}'", _filterCol, _filterVal); 201 205 return _list; 202 206 } … … 210 214 if (_list.First ().ContainsKey (_sortCol)) { 211 215 Type colType = _list.First () [_sortCol].GetType (); 212 if (colType == typeof (JSONNumber)) {216 if (colType == typeof (JSONNumber)) { 213 217 if (_ascending) { 214 218 return _list.OrderBy (line => (line [_sortCol] as JSONNumber).GetDouble ()); 215 } else { 216 return _list.OrderByDescending (line => (line [_sortCol] as JSONNumber).GetDouble ()); 217 } 218 } else if (colType == typeof(JSONBoolean)) { 219 } 220 221 return _list.OrderByDescending (line => (line [_sortCol] as JSONNumber).GetDouble ()); 222 } 223 224 if (colType == typeof (JSONBoolean)) { 219 225 if (_ascending) { 220 226 return _list.OrderBy (line => (line [_sortCol] as JSONBoolean).GetBool ()); 221 } else { 222 return _list.OrderByDescending (line => (line [_sortCol] as JSONBoolean).GetBool ()); 223 } 224 } else { 225 if (_ascending) { 226 return _list.OrderBy (line => line [_sortCol].ToString ()); 227 } else { 228 return _list.OrderByDescending (line => line [_sortCol].ToString ()); 229 } 230 } 231 } 227 } 228 229 return _list.OrderByDescending (line => (line [_sortCol] as JSONBoolean).GetBool ()); 230 } 231 232 if (_ascending) { 233 return _list.OrderBy (line => line [_sortCol].ToString ()); 234 } 235 236 return _list.OrderByDescending (line => line [_sortCol].ToString ()); 237 } 238 232 239 return _list; 233 240 } 234 241 235 242 236 private bool NearlyEqual(double a, double b, double epsilon) 237 { 238 double absA = Math.Abs(a); 239 double absB = Math.Abs(b); 240 double diff = Math.Abs(a - b); 241 242 if (a == b) 243 { // shortcut, handles infinities 243 private bool NearlyEqual (double a, double b, double epsilon) { 244 double absA = Math.Abs (a); 245 double absB = Math.Abs (b); 246 double diff = Math.Abs (a - b); 247 248 if (a == b) { 244 249 return true; 245 } 246 else if (a == 0 || b == 0 || diff < Double.Epsilon) 247 { 248 // a or b is zero or both are extremely close to it 249 // relative error is less meaningful here 250 } 251 252 if (a == 0 || b == 0 || diff < double.Epsilon) { 250 253 return diff < epsilon; 251 254 } 252 else 253 { // use relative error 254 return diff / (absA + absB) < epsilon; 255 } 256 } 257 255 256 return diff / (absA + absB) < epsilon; 257 } 258 259 private enum NumberMatchType { 260 Equal, 261 Greater, 262 GreaterEqual, 263 Lesser, 264 LesserEqual 265 } 258 266 } 259 267 } 260 -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r315 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetPlayersLocation : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 13 AdminTools admTools = GameManager.Instance.adminTools; 14 user = user ?? new WebConnection ("", "", 0L); 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetPlayersLocation : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 9 AdminTools admTools = GameManager.Instance.adminTools; 10 user = user ?? new WebConnection ("", "", 0L); 15 11 16 12 bool listOffline = false; … … 19 15 } 20 16 21 17 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 22 18 23 19 JSONArray playersJsResult = new JSONArray (); 24 20 25 21 Players playersList = PersistentContainer.Instance.Players; 26 22 27 23 foreach (string sid in playersList.SteamIDs) { 28 if (admTools != null) 29 if (admTools.IsBanned (sid)) 30 continue; 24 if (admTools != null) { 25 if (admTools.IsBanned (sid)) { 26 continue; 27 } 28 } 31 29 32 30 Player p = playersList [sid, false]; 33 31 34 32 if (listOffline || p.IsOnline) { 35 ulong player_steam_ID = 0L; 36 if (!ulong.TryParse (sid, out player_steam_ID)) 37 player_steam_ID = 0L; 33 ulong player_steam_ID = 0L; 34 if (!ulong.TryParse (sid, out player_steam_ID)) { 35 player_steam_ID = 0L; 36 } 38 37 39 if ((player_steam_ID == user.SteamID)|| bViewAll) {40 41 pos.Add("x", new JSONNumber (p.LastPosition.x));42 pos.Add("y", new JSONNumber (p.LastPosition.y));43 pos.Add("z", new JSONNumber (p.LastPosition.z));38 if (player_steam_ID == user.SteamID || bViewAll) { 39 JSONObject pos = new JSONObject (); 40 pos.Add ("x", new JSONNumber (p.LastPosition.x)); 41 pos.Add ("y", new JSONNumber (p.LastPosition.y)); 42 pos.Add ("z", new JSONNumber (p.LastPosition.z)); 44 43 45 JSONObject pJson = new JSONObject (); 46 pJson.Add("steamid", new JSONString (sid)); 47 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 48 // pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add("name", new JSONString (p.Name)); 50 pJson.Add("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add("position", pos); 44 JSONObject pJson = new JSONObject (); 45 pJson.Add ("steamid", new JSONString (sid)); 52 46 53 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 54 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 55 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 47 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 48 // pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add ("name", new JSONString (p.Name)); 50 pJson.Add ("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add ("position", pos); 52 53 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 54 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 55 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 56 56 57 57 playersJsResult.Add (pJson); 58 58 } 59 59 } 60 60 } 61 61 62 62 WriteJSON (resp, playersJsResult); … … 64 64 } 65 65 } 66 -
binary-improvements/MapRendering/Web/API/GetPlayersOnline.cs
r324 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetPlayersOnline : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 13 JSONArray players = new JSONArray(); 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetPlayersOnline : WebAPI { 8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 10 JSONArray players = new JSONArray (); 14 11 15 12 World w = GameManager.Instance.World; … … 18 15 Player player = PersistentContainer.Instance.Players [ci.playerId, false]; 19 16 20 JSONObject pos = new JSONObject ();21 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x));22 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y));23 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z));17 JSONObject pos = new JSONObject (); 18 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x)); 19 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y)); 20 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z)); 24 21 25 JSONObject p = new JSONObject ();22 JSONObject p = new JSONObject (); 26 23 p.Add ("steamid", new JSONString (ci.playerId)); 27 24 p.Add ("entityid", new JSONNumber (ci.entityId)); … … 46 43 p.Add ("ping", new JSONNumber (ci != null ? ci.ping : -1)); 47 44 48 players.Add (p);45 players.Add (p); 49 46 } 50 47 51 WriteJSON (resp, players);48 WriteJSON (resp, players); 52 49 } 53 50 } 54 51 } 55 -
binary-improvements/MapRendering/Web/API/GetServerInfo.cs
r279 r325 1 using System; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 using AllocsFixes.PersistentData;3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetServerInfo : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetServerInfo : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 13 9 JSONObject serverInfo = new JSONObject (); 14 10 15 11 GameServerInfo gsi = Steam.Masterserver.Server.LocalGameInfo; 16 12 17 foreach (string stringGamePref in Enum.GetNames (typeof(GameInfoString))) {18 string value = gsi.GetValue ( (GameInfoString)Enum.Parse (typeof(GameInfoString), stringGamePref));13 foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) { 14 string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref)); 19 15 20 16 JSONObject singleStat = new JSONObject (); … … 25 21 } 26 22 27 foreach (string intGamePref in Enum.GetNames (typeof(GameInfoInt))) {28 int value = gsi.GetValue ( (GameInfoInt)Enum.Parse (typeof(GameInfoInt), intGamePref));23 foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) { 24 int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref)); 29 25 30 26 JSONObject singleStat = new JSONObject (); … … 35 31 } 36 32 37 foreach (string boolGamePref in Enum.GetNames (typeof(GameInfoBool))) {38 bool value = gsi.GetValue ( (GameInfoBool)Enum.Parse (typeof(GameInfoBool), boolGamePref));33 foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) { 34 bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref)); 39 35 40 36 JSONObject singleStat = new JSONObject (); … … 46 42 47 43 48 WriteJSON (resp, serverInfo);44 WriteJSON (resp, serverInfo); 49 45 } 50 46 } 51 47 } 52 -
binary-improvements/MapRendering/Web/API/GetStats.cs
r313 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.LiveData; 3 using AllocsFixes.PersistentData;4 using System;5 using System.Collections.Generic;6 using System.Net;7 4 8 namespace AllocsFixes.NetConnections.Servers.Web.API 9 { 10 public class GetStats : WebAPI 11 { 12 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 13 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetStats : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 14 9 JSONObject result = new JSONObject (); 15 10 … … 32 27 } 33 28 } 34 -
binary-improvements/MapRendering/Web/API/GetWebUIUpdates.cs
r313 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.LiveData; 3 using AllocsFixes.PersistentData;4 using System;5 using System.Collections.Generic;6 using System.Net;7 4 8 namespace AllocsFixes.NetConnections.Servers.Web.API 9 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 10 6 public class GetWebUIUpdates : WebAPI { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 12 9 int latestLine; 13 if (req.QueryString ["latestLine"] == null || !int.TryParse (req.QueryString ["latestLine"], out latestLine)) { 10 if (req.QueryString ["latestLine"] == null || 11 !int.TryParse (req.QueryString ["latestLine"], out latestLine)) { 14 12 latestLine = 0; 15 13 } … … 37 35 } 38 36 } 39 -
binary-improvements/MapRendering/Web/API/Null.cs
r251 r325 1 using AllocsFixes.JSON; 2 using System; 3 using System.Collections.Generic; 4 using System.Net; 1 using System.Net; 5 2 using System.Text; 6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class Null : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 5 public class Null : WebAPI { 6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 7 int permissionLevel) { 13 8 resp.ContentLength64 = 0; 14 9 resp.ContentType = "text/plain"; 15 10 resp.ContentEncoding = Encoding.ASCII; 16 11 resp.OutputStream.Write (new byte[] { }, 0, 0); 17 18 12 } 13 } 19 14 } -
binary-improvements/MapRendering/Web/API/WebAPI.cs
r309 r325 1 using System;2 1 using System.Net; 3 2 using System.Text; 3 using AllocsFixes.JSON; 4 4 5 namespace AllocsFixes.NetConnections.Servers.Web.API 6 { 7 public abstract class WebAPI 8 { 9 public static void WriteJSON (HttpListenerResponse resp, JSON.JSONNode root) 10 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public abstract class WebAPI { 7 public static void WriteJSON (HttpListenerResponse resp, JSONNode root) { 11 8 StringBuilder sb = new StringBuilder (); 12 9 root.ToString (sb); … … 18 15 } 19 16 20 public static void WriteText (HttpListenerResponse _resp, string _text) 21 { 17 public static void WriteText (HttpListenerResponse _resp, string _text) { 22 18 byte[] buf = Encoding.UTF8.GetBytes (_text); 23 19 _resp.ContentLength64 = buf.Length; … … 27 23 } 28 24 29 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel); 25 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 26 int permissionLevel); 30 27 31 28 public virtual int DefaultPermissionLevel () { … … 34 31 } 35 32 } 36 -
binary-improvements/MapRendering/Web/ConnectionHandler.cs
r250 r325 2 2 using System.Collections.Generic; 3 3 4 namespace AllocsFixes.NetConnections.Servers.Web 5 { 4 namespace AllocsFixes.NetConnections.Servers.Web { 6 5 public class ConnectionHandler { 6 private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> (); 7 7 private Web parent; 8 private Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> ();9 8 10 9 public ConnectionHandler (Web _parent) { … … 18 17 19 18 WebConnection con = connections [_sessionId]; 19 20 20 // if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) { 21 21 // connections.Remove (_sessionId); … … 49 49 } 50 50 } 51 52 51 } 53 52 } 54 -
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r279 r325 1 using AllocsFixes.NetConnections.Servers.Web.API;2 1 using System; 3 2 using System.Collections.Generic; 4 using System.IO;5 3 using System.Net; 6 4 using System.Reflection; 7 using System.Threading;5 using AllocsFixes.NetConnections.Servers.Web.API; 8 6 9 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 10 { 7 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 11 8 public class ApiHandler : PathHandler { 12 private string staticPart;13 private Dictionary<String, WebAPI> apis = new Dictionary<string, WebAPI> ();9 private readonly Dictionary<string, WebAPI> apis = new Dictionary<string, WebAPI> (); 10 private readonly string staticPart; 14 11 15 12 public ApiHandler (string staticPart, string moduleName = null) : base (moduleName) { … … 17 14 18 15 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { 19 if (!t.IsAbstract && t.IsSubclassOf (typeof (WebAPI))) {16 if (!t.IsAbstract && t.IsSubclassOf (typeof (WebAPI))) { 20 17 ConstructorInfo ctor = t.GetConstructor (new Type [0]); 21 18 if (ctor != null) { 22 WebAPI apiInstance = (WebAPI) ctor.Invoke (new object [0]);19 WebAPI apiInstance = (WebAPI) ctor.Invoke (new object [0]); 23 20 addApi (t.Name.ToLower (), apiInstance); 24 21 } … … 26 23 } 27 24 28 29 Type dummy_t = typeof (API.Null);30 31 32 WebAPI dummy_apiInstance = (WebAPI)dummy_ctor.Invoke (new object[0]);25 // Add dummy types 26 Type dummy_t = typeof (Null); 27 ConstructorInfo dummy_ctor = dummy_t.GetConstructor (new Type [0]); 28 if (dummy_ctor != null) { 29 WebAPI dummy_apiInstance = (WebAPI) dummy_ctor.Invoke (new object[0]); 33 30 34 35 addApi("viewallclaims", dummy_apiInstance);36 addApi("viewallplayers", dummy_apiInstance);37 31 // Permissions that don't map to a real API 32 addApi ("viewallclaims", dummy_apiInstance); 33 addApi ("viewallplayers", dummy_apiInstance); 34 } 38 35 } 39 36 … … 43 40 } 44 41 45 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 42 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 43 int permissionLevel) { 46 44 string apiName = req.Url.AbsolutePath.Remove (0, staticPart.Length); 47 45 if (!AuthorizeForCommand (apiName, user, permissionLevel)) { 48 resp.StatusCode = (int) HttpStatusCode.Forbidden;46 resp.StatusCode = (int) HttpStatusCode.Forbidden; 49 47 if (user != null) { 50 48 //Log.Out ("ApiHandler: user '{0}' not allowed to execute '{1}'", user.SteamID, apiName); 51 } else {52 //Log.Out ("ApiHandler: unidentified user from '{0}' not allowed to execute '{1}'", req.RemoteEndPoint.Address, apiName);53 49 } 50 54 51 return; 55 } else {56 foreach (KeyValuePair<string, WebAPI> kvp in apis) { 57 if (apiName.StartsWith (kvp.Key)) {58 try{59 kvp.Value.HandleRequest (req, resp, user, permissionLevel);60 return;61 } catch (Exception e) {62 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", kvp.Key);63 Log.Exception (e);64 resp.StatusCode = (int)HttpStatusCode.InternalServerError;65 return;66 }52 } 53 54 foreach (KeyValuePair<string, WebAPI> kvp in apis) { 55 if (apiName.StartsWith (kvp.Key)) { 56 try { 57 kvp.Value.HandleRequest (req, resp, user, permissionLevel); 58 return; 59 } catch (Exception e) { 60 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", kvp.Key); 61 Log.Exception (e); 62 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 63 return; 67 64 } 68 65 } 69 66 } 70 67 71 68 Log.Out ("Error in ApiHandler.HandleRequest(): No handler found for API \"" + apiName + "\""); 72 resp.StatusCode = (int) HttpStatusCode.NotFound;69 resp.StatusCode = (int) HttpStatusCode.NotFound; 73 70 } 74 71 … … 76 73 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi." + apiName, permissionLevel); 77 74 } 78 79 75 } 80 81 76 } 82 -
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r306 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO; 3 4 using System.Net; 4 using System.Threading; 5 using UnityEngine; 6 using Object = UnityEngine.Object; 5 7 6 using UnityEngine; 7 using System.IO; 8 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 9 public class ItemIconHandler : PathHandler { 10 private readonly Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 11 private readonly bool logMissingFiles; 8 12 9 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 10 { 11 public class ItemIconHandler : PathHandler { 12 private static ItemIconHandler instance = null; 13 public static ItemIconHandler Instance { 14 get { return instance; } 13 private readonly string staticPart; 14 private bool loaded; 15 16 static ItemIconHandler () { 17 Instance = null; 15 18 } 16 19 17 private string staticPart; 18 private bool logMissingFiles; 19 private Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 20 private bool loaded = false; 21 22 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base(moduleName) { 20 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base (moduleName) { 23 21 this.staticPart = staticPart; 24 22 this.logMissingFiles = logMissingFiles; 25 I temIconHandler.instance = this;23 Instance = this; 26 24 } 27 25 28 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 26 public static ItemIconHandler Instance { get; private set; } 27 28 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 29 int permissionLevel) { 29 30 if (!loaded) { 30 resp.StatusCode = (int) HttpStatusCode.InternalServerError;31 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 31 32 Log.Out ("Web:IconHandler: Icons not loaded"); 32 33 return; … … 44 45 resp.OutputStream.Write (itemIconData, 0, itemIconData.Length); 45 46 } else { 46 resp.StatusCode = (int) HttpStatusCode.NotFound;47 resp.StatusCode = (int) HttpStatusCode.NotFound; 47 48 if (logMissingFiles) { 48 49 Log.Out ("Web:IconHandler:FileNotFound: \"" + req.Url.AbsolutePath + "\" "); 49 50 } 50 return;51 51 } 52 52 } … … 66 66 return false; 67 67 } 68 68 69 DynamicUIAtlas atlas = atlasObj.GetComponent<DynamicUIAtlas> (); 69 70 if (atlas == null) { … … 78 79 Texture2D atlasTex; 79 80 80 if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor (textureResourceName, out sprites, out elementWidth, out elementHeight)) { 81 if (!DynamicUIAtlasTools.ReadPrebakedAtlasDescriptor (textureResourceName, out sprites, 82 out elementWidth, out elementHeight)) { 81 83 SdtdConsole.Instance.Output ("Web:IconHandler: Could not read dynamic atlas descriptor"); 82 84 return false; … … 98 100 tintedIcons.Add (name, new List<Color> ()); 99 101 } 102 100 103 List<Color> list = tintedIcons [name]; 101 104 list.Add (tintColor); … … 108 111 string name = data.name; 109 112 Texture2D tex = new Texture2D (data.width, data.height, TextureFormat.ARGB32, false); 110 tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, data.height)); 113 tex.SetPixels (atlasTex.GetPixels (data.x, atlasTex.height - data.height - data.y, data.width, 114 data.height)); 111 115 112 116 AddIcon (name, tex, tintedIcons); 113 117 114 UnityEngine.Object.Destroy (tex);118 Object.Destroy (tex); 115 119 } 116 Resources.UnloadAsset(atlasTex); 120 121 Resources.UnloadAsset (atlasTex); 117 122 118 123 // Load icons from mods … … 131 136 } 132 137 133 UnityEngine.Object.Destroy (tex);138 Object.Destroy (tex); 134 139 } 135 140 } … … 168 173 icons [tintedName] = tintedTex.EncodeToPNG (); 169 174 170 UnityEngine.Object.Destroy (tintedTex);175 Object.Destroy (tintedTex); 171 176 } 172 177 } 173 178 } 174 179 } 175 176 180 } 177 181 } 178 -
binary-improvements/MapRendering/Web/Handlers/PathHandler.cs
r279 r325 1 using System;2 1 using System.Net; 3 2 4 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 5 { 6 public abstract class PathHandler 7 { 8 private string moduleName = null; 3 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 4 public abstract class PathHandler { 5 private readonly string moduleName; 6 7 protected PathHandler (string _moduleName, int _defaultPermissionLevel = 0) { 8 moduleName = _moduleName; 9 WebPermissions.Instance.AddKnownModule (_moduleName, _defaultPermissionLevel); 10 } 11 9 12 public string ModuleName { 10 13 get { return moduleName; } 11 14 } 12 15 13 protected PathHandler (string _moduleName, int _defaultPermissionLevel = 0) { 14 this.moduleName = _moduleName; 15 WebPermissions.Instance.AddKnownModule (_moduleName, _defaultPermissionLevel); 16 } 17 18 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel); 16 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 17 int permissionLevel); 19 18 20 19 public bool IsAuthorizedForHandler (WebConnection user, int permissionLevel) { 21 20 if (moduleName != null) { 22 21 return WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, permissionLevel); 23 } else {24 return true;25 22 } 23 24 return true; 26 25 } 27 26 } 28 27 } 29 -
binary-improvements/MapRendering/Web/Handlers/SessionHandler.cs
r311 r325 1 using System;2 using System.Collections.Generic;3 1 using System.IO; 4 2 using System.Net; 5 3 using System.Text; 6 using System.Threading;7 4 8 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 9 { 5 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 10 6 public class SessionHandler : PathHandler { 11 private string staticPart;12 private Web parent;13 private string header = "";14 private string footer = "";7 private readonly string footer = ""; 8 private readonly string header = ""; 9 private readonly Web parent; 10 private readonly string staticPart; 15 11 16 public SessionHandler (string _staticPart, string _dataFolder, Web _parent, string moduleName = null) : base(moduleName) { 17 this.staticPart = _staticPart; 18 this.parent = _parent; 12 public SessionHandler (string _staticPart, string _dataFolder, Web _parent, string moduleName = null) : 13 base (moduleName) { 14 staticPart = _staticPart; 15 parent = _parent; 19 16 20 17 if (File.Exists (_dataFolder + "/sessionheader.tmpl")) { … … 27 24 } 28 25 29 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 26 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 27 int permissionLevel) { 30 28 string subpath = req.Url.AbsolutePath.Remove (0, staticPart.Length); 31 29 … … 37 35 resp.Redirect ("/static/index.html"); 38 36 return; 39 } else {40 result.Append ("<h1>Login failed, <a href=\"/static/index.html\">click to return to main page</a>.</h1>");41 37 } 38 39 result.Append ( 40 "<h1>Login failed, <a href=\"/static/index.html\">click to return to main page</a>.</h1>"); 42 41 } else if (subpath.StartsWith ("logout")) { 43 42 if (user != null) { … … 48 47 resp.Redirect ("/static/index.html"); 49 48 return; 50 } else {51 result.Append ("<h1>Not logged in, <a href=\"/static/index.html\">click to return to main page</a>.</h1>");52 49 } 50 51 result.Append ( 52 "<h1>Not logged in, <a href=\"/static/index.html\">click to return to main page</a>.</h1>"); 53 53 } else if (subpath.StartsWith ("login")) { 54 54 string host = (Web.isSslRedirected (req) ? "https://" : "http://") + req.UserHostName; … … 57 57 return; 58 58 } else { 59 result.Append ("<h1>Unknown command, <a href=\"/static/index.html\">click to return to main page</a>.</h1>"); 59 result.Append ( 60 "<h1>Unknown command, <a href=\"/static/index.html\">click to return to main page</a>.</h1>"); 60 61 } 61 62 … … 68 69 resp.OutputStream.Write (buf, 0, buf.Length); 69 70 } 70 71 71 } 72 73 72 } 74 -
binary-improvements/MapRendering/Web/Handlers/SimpleRedirectHandler.cs
r244 r325 1 using System;2 1 using System.Net; 3 2 4 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 5 { 6 public class SimpleRedirectHandler : PathHandler 7 { 8 string target; 3 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 4 public class SimpleRedirectHandler : PathHandler { 5 private readonly string target; 9 6 10 public SimpleRedirectHandler (string target, string moduleName = null) : base(moduleName) 11 { 7 public SimpleRedirectHandler (string target, string moduleName = null) : base (moduleName) { 12 8 this.target = target; 13 9 } 14 10 15 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)16 {11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 12 int permissionLevel) { 17 13 resp.Redirect (target); 18 14 } 19 15 } 20 16 } 21 -
binary-improvements/MapRendering/Web/Handlers/StaticHandler.cs
r251 r325 1 using System;2 using System.Collections.Generic;3 1 using System.IO; 4 2 using System.Net; 5 using System.Threading;3 using AllocsFixes.FileCache; 6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 8 { 9 public class StaticHandler : PathHandler 10 { 11 private string datapath; 12 private string staticPart; 13 private AllocsFixes.FileCache.AbstractCache cache; 14 private bool logMissingFiles; 5 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 6 public class StaticHandler : PathHandler { 7 private readonly AbstractCache cache; 8 private readonly string datapath; 9 private readonly bool logMissingFiles; 10 private readonly string staticPart; 15 11 16 public StaticHandler (string staticPart, string filePath, A llocsFixes.FileCache.AbstractCache cache, bool logMissingFiles, string moduleName = null) : base(moduleName)17 {12 public StaticHandler (string staticPart, string filePath, AbstractCache cache, bool logMissingFiles, 13 string moduleName = null) : base (moduleName) { 18 14 this.staticPart = staticPart; 19 this.datapath = filePath;15 datapath = filePath; 20 16 this.cache = cache; 21 17 this.logMissingFiles = logMissingFiles; 22 18 } 23 19 24 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)25 {20 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 21 int permissionLevel) { 26 22 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 27 23 … … 33 29 resp.OutputStream.Write (content, 0, content.Length); 34 30 } else { 35 resp.StatusCode = (int)HttpStatusCode.NotFound; 36 if (logMissingFiles) 37 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 38 return; 31 resp.StatusCode = (int) HttpStatusCode.NotFound; 32 if (logMissingFiles) { 33 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + 34 req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 35 } 39 36 } 40 37 } 41 38 } 42 39 } 43 -
binary-improvements/MapRendering/Web/Handlers/UserStatusHandler.cs
r309 r325 1 using System;2 using System.Collections.Generic;3 using System.IO;4 1 using System.Net; 5 using System.Threading;6 using System.Text;7 2 using AllocsFixes.JSON; 3 using AllocsFixes.NetConnections.Servers.Web.API; 8 4 9 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 10 { 5 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { 11 6 public class UserStatusHandler : PathHandler { 12 public UserStatusHandler (string moduleName = null) : base (moduleName) {7 public UserStatusHandler (string moduleName = null) : base (moduleName) { 13 8 } 14 9 15 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 11 int permissionLevel) { 16 12 JSONObject result = new JSONObject (); 17 13 … … 23 19 JSONObject permObj = new JSONObject (); 24 20 permObj.Add ("module", new JSONString (perm.module)); 25 permObj.Add ("allowed", new JSONBoolean (WebPermissions.Instance.ModuleAllowedWithLevel (perm.module, permissionLevel))); 21 permObj.Add ("allowed", 22 new JSONBoolean (WebPermissions.Instance.ModuleAllowedWithLevel (perm.module, permissionLevel))); 26 23 perms.Add (permObj); 27 24 } 25 28 26 result.Add ("permissions", perms); 29 27 30 AllocsFixes.NetConnections.Servers.Web.API.WebAPI.WriteJSON (resp, result);28 WebAPI.WriteJSON (resp, result); 31 29 } 32 33 30 } 34 35 31 } 36 -
binary-improvements/MapRendering/Web/LogBuffer.cs
r270 r325 2 2 using System.Collections.Generic; 3 3 using System.Text.RegularExpressions; 4 5 4 using UnityEngine; 6 5 7 namespace AllocsFixes.NetConnections.Servers.Web 8 { 6 namespace AllocsFixes.NetConnections.Servers.Web { 9 7 public class LogBuffer { 10 8 private const int MAX_ENTRIES = 3000; 11 9 private static LogBuffer instance; 10 11 private static readonly Regex logMessageMatcher = 12 new Regex (@"^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}) ([0-9]+[,.][0-9]+) [A-Z]+ (.*)$"); 13 14 private readonly List<LogEntry> logEntries = new List<LogEntry> (); 15 16 private int listOffset; 17 18 private LogBuffer () { 19 Logger.Main.LogCallbacks += LogCallback; 20 } 12 21 13 22 public static LogBuffer Instance { … … 16 25 instance = new LogBuffer (); 17 26 } 27 18 28 return instance; 19 29 } 20 30 } 21 22 private static Regex logMessageMatcher = new Regex (@"^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}) ([0-9]+[,.][0-9]+) [A-Z]+ (.*)$");23 private List<LogEntry> logEntries = new List<LogEntry> ();24 private int listOffset = 0;25 31 26 32 public int OldestLine { … … 55 61 } 56 62 } 63 57 64 return null; 58 65 } 59 }60 61 private LogBuffer () {62 Logger.Main.LogCallbacks += LogCallback;63 66 } 64 67 … … 123 126 public class LogEntry { 124 127 public string date; 128 public string message; 125 129 public string time; 126 public string uptime;127 public string message;128 130 public string trace; 129 131 public LogType type; 132 public string uptime; 130 133 } 131 134 } 132 135 } 133 -
binary-improvements/MapRendering/Web/MimeType.cs
r230 r325 2 2 using System.Collections.Generic; 3 3 4 namespace AllocsFixes.NetConnections.Servers.Web 5 { 6 public class MimeType 7 { 8 private static IDictionary<string, string> _mappings = new Dictionary<string, string> (StringComparer.InvariantCultureIgnoreCase) { 9 {".323", "text/h323"}, 10 {".3g2", "video/3gpp2"}, 11 {".3gp", "video/3gpp"}, 12 {".3gp2", "video/3gpp2"}, 13 {".3gpp", "video/3gpp"}, 14 {".7z", "application/x-7z-compressed"}, 15 {".aa", "audio/audible"}, 16 {".AAC", "audio/aac"}, 17 {".aaf", "application/octet-stream"}, 18 {".aax", "audio/vnd.audible.aax"}, 19 {".ac3", "audio/ac3"}, 20 {".aca", "application/octet-stream"}, 21 {".accda", "application/msaccess.addin"}, 22 {".accdb", "application/msaccess"}, 23 {".accdc", "application/msaccess.cab"}, 24 {".accde", "application/msaccess"}, 25 {".accdr", "application/msaccess.runtime"}, 26 {".accdt", "application/msaccess"}, 27 {".accdw", "application/msaccess.webapplication"}, 28 {".accft", "application/msaccess.ftemplate"}, 29 {".acx", "application/internet-property-stream"}, 30 {".AddIn", "text/xml"}, 31 {".ade", "application/msaccess"}, 32 {".adobebridge", "application/x-bridge-url"}, 33 {".adp", "application/msaccess"}, 34 {".ADT", "audio/vnd.dlna.adts"}, 35 {".ADTS", "audio/aac"}, 36 {".afm", "application/octet-stream"}, 37 {".ai", "application/postscript"}, 38 {".aif", "audio/x-aiff"}, 39 {".aifc", "audio/aiff"}, 40 {".aiff", "audio/aiff"}, 41 {".air", "application/vnd.adobe.air-application-installer-package+zip"}, 42 {".amc", "application/x-mpeg"}, 43 {".application", "application/x-ms-application"}, 44 {".art", "image/x-jg"}, 45 {".asa", "application/xml"}, 46 {".asax", "application/xml"}, 47 {".ascx", "application/xml"}, 48 {".asd", "application/octet-stream"}, 49 {".asf", "video/x-ms-asf"}, 50 {".ashx", "application/xml"}, 51 {".asi", "application/octet-stream"}, 52 {".asm", "text/plain"}, 53 {".asmx", "application/xml"}, 54 {".aspx", "application/xml"}, 55 {".asr", "video/x-ms-asf"}, 56 {".asx", "video/x-ms-asf"}, 57 {".atom", "application/atom+xml"}, 58 {".au", "audio/basic"}, 59 {".avi", "video/x-msvideo"}, 60 {".axs", "application/olescript"}, 61 {".bas", "text/plain"}, 62 {".bcpio", "application/x-bcpio"}, 63 {".bin", "application/octet-stream"}, 64 {".bmp", "image/bmp"}, 65 {".c", "text/plain"}, 66 {".cab", "application/octet-stream"}, 67 {".caf", "audio/x-caf"}, 68 {".calx", "application/vnd.ms-office.calx"}, 69 {".cat", "application/vnd.ms-pki.seccat"}, 70 {".cc", "text/plain"}, 71 {".cd", "text/plain"}, 72 {".cdda", "audio/aiff"}, 73 {".cdf", "application/x-cdf"}, 74 {".cer", "application/x-x509-ca-cert"}, 75 {".chm", "application/octet-stream"}, 76 {".class", "application/x-java-applet"}, 77 {".clp", "application/x-msclip"}, 78 {".cmx", "image/x-cmx"}, 79 {".cnf", "text/plain"}, 80 {".cod", "image/cis-cod"}, 81 {".config", "application/xml"}, 82 {".contact", "text/x-ms-contact"}, 83 {".coverage", "application/xml"}, 84 {".cpio", "application/x-cpio"}, 85 {".cpp", "text/plain"}, 86 {".crd", "application/x-mscardfile"}, 87 {".crl", "application/pkix-crl"}, 88 {".crt", "application/x-x509-ca-cert"}, 89 {".cs", "text/plain"}, 90 {".csdproj", "text/plain"}, 91 {".csh", "application/x-csh"}, 92 {".csproj", "text/plain"}, 93 {".css", "text/css"}, 94 {".csv", "text/csv"}, 95 {".cur", "application/octet-stream"}, 96 {".cxx", "text/plain"}, 97 {".dat", "application/octet-stream"}, 98 {".datasource", "application/xml"}, 99 {".dbproj", "text/plain"}, 100 {".dcr", "application/x-director"}, 101 {".def", "text/plain"}, 102 {".deploy", "application/octet-stream"}, 103 {".der", "application/x-x509-ca-cert"}, 104 {".dgml", "application/xml"}, 105 {".dib", "image/bmp"}, 106 {".dif", "video/x-dv"}, 107 {".dir", "application/x-director"}, 108 {".disco", "text/xml"}, 109 {".dll", "application/x-msdownload"}, 110 {".dll.config", "text/xml"}, 111 {".dlm", "text/dlm"}, 112 {".doc", "application/msword"}, 113 {".docm", "application/vnd.ms-word.document.macroEnabled.12"}, 114 {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, 115 {".dot", "application/msword"}, 116 {".dotm", "application/vnd.ms-word.template.macroEnabled.12"}, 117 {".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, 118 {".dsp", "application/octet-stream"}, 119 {".dsw", "text/plain"}, 120 {".dtd", "text/xml"}, 121 {".dtsConfig", "text/xml"}, 122 {".dv", "video/x-dv"}, 123 {".dvi", "application/x-dvi"}, 124 {".dwf", "drawing/x-dwf"}, 125 {".dwp", "application/octet-stream"}, 126 {".dxr", "application/x-director"}, 127 {".eml", "message/rfc822"}, 128 {".emz", "application/octet-stream"}, 129 {".eot", "application/octet-stream"}, 130 {".eps", "application/postscript"}, 131 {".etl", "application/etl"}, 132 {".etx", "text/x-setext"}, 133 {".evy", "application/envoy"}, 134 {".exe", "application/octet-stream"}, 135 {".exe.config", "text/xml"}, 136 {".fdf", "application/vnd.fdf"}, 137 {".fif", "application/fractals"}, 138 {".filters", "Application/xml"}, 139 {".fla", "application/octet-stream"}, 140 {".flr", "x-world/x-vrml"}, 141 {".flv", "video/x-flv"}, 142 {".fsscript", "application/fsharp-script"}, 143 {".fsx", "application/fsharp-script"}, 144 {".generictest", "application/xml"}, 145 {".gif", "image/gif"}, 146 {".group", "text/x-ms-group"}, 147 {".gsm", "audio/x-gsm"}, 148 {".gtar", "application/x-gtar"}, 149 {".gz", "application/x-gzip"}, 150 {".h", "text/plain"}, 151 {".hdf", "application/x-hdf"}, 152 {".hdml", "text/x-hdml"}, 153 {".hhc", "application/x-oleobject"}, 154 {".hhk", "application/octet-stream"}, 155 {".hhp", "application/octet-stream"}, 156 {".hlp", "application/winhlp"}, 157 {".hpp", "text/plain"}, 158 {".hqx", "application/mac-binhex40"}, 159 {".hta", "application/hta"}, 160 {".htc", "text/x-component"}, 161 {".htm", "text/html"}, 162 {".html", "text/html"}, 163 {".htt", "text/webviewhtml"}, 164 {".hxa", "application/xml"}, 165 {".hxc", "application/xml"}, 166 {".hxd", "application/octet-stream"}, 167 {".hxe", "application/xml"}, 168 {".hxf", "application/xml"}, 169 {".hxh", "application/octet-stream"}, 170 {".hxi", "application/octet-stream"}, 171 {".hxk", "application/xml"}, 172 {".hxq", "application/octet-stream"}, 173 {".hxr", "application/octet-stream"}, 174 {".hxs", "application/octet-stream"}, 175 {".hxt", "text/html"}, 176 {".hxv", "application/xml"}, 177 {".hxw", "application/octet-stream"}, 178 {".hxx", "text/plain"}, 179 {".i", "text/plain"}, 180 {".ico", "image/x-icon"}, 181 {".ics", "application/octet-stream"}, 182 {".idl", "text/plain"}, 183 {".ief", "image/ief"}, 184 {".iii", "application/x-iphone"}, 185 {".inc", "text/plain"}, 186 {".inf", "application/octet-stream"}, 187 {".inl", "text/plain"}, 188 {".ins", "application/x-internet-signup"}, 189 {".ipa", "application/x-itunes-ipa"}, 190 {".ipg", "application/x-itunes-ipg"}, 191 {".ipproj", "text/plain"}, 192 {".ipsw", "application/x-itunes-ipsw"}, 193 {".iqy", "text/x-ms-iqy"}, 194 {".isp", "application/x-internet-signup"}, 195 {".ite", "application/x-itunes-ite"}, 196 {".itlp", "application/x-itunes-itlp"}, 197 {".itms", "application/x-itunes-itms"}, 198 {".itpc", "application/x-itunes-itpc"}, 199 {".IVF", "video/x-ivf"}, 200 {".jar", "application/java-archive"}, 201 {".java", "application/octet-stream"}, 202 {".jck", "application/liquidmotion"}, 203 {".jcz", "application/liquidmotion"}, 204 {".jfif", "image/pjpeg"}, 205 {".jnlp", "application/x-java-jnlp-file"}, 206 {".jpb", "application/octet-stream"}, 207 {".jpe", "image/jpeg"}, 208 {".jpeg", "image/jpeg"}, 209 {".jpg", "image/jpeg"}, 210 {".js", "application/x-javascript"}, 211 {".json", "application/json"}, 212 {".jsx", "text/jscript"}, 213 {".jsxbin", "text/plain"}, 214 {".latex", "application/x-latex"}, 215 {".library-ms", "application/windows-library+xml"}, 216 {".lit", "application/x-ms-reader"}, 217 {".loadtest", "application/xml"}, 218 {".lpk", "application/octet-stream"}, 219 {".lsf", "video/x-la-asf"}, 220 {".lst", "text/plain"}, 221 {".lsx", "video/x-la-asf"}, 222 {".lzh", "application/octet-stream"}, 223 {".m13", "application/x-msmediaview"}, 224 {".m14", "application/x-msmediaview"}, 225 {".m1v", "video/mpeg"}, 226 {".m2t", "video/vnd.dlna.mpeg-tts"}, 227 {".m2ts", "video/vnd.dlna.mpeg-tts"}, 228 {".m2v", "video/mpeg"}, 229 {".m3u", "audio/x-mpegurl"}, 230 {".m3u8", "audio/x-mpegurl"}, 231 {".m4a", "audio/m4a"}, 232 {".m4b", "audio/m4b"}, 233 {".m4p", "audio/m4p"}, 234 {".m4r", "audio/x-m4r"}, 235 {".m4v", "video/x-m4v"}, 236 {".mac", "image/x-macpaint"}, 237 {".mak", "text/plain"}, 238 {".man", "application/x-troff-man"}, 239 {".manifest", "application/x-ms-manifest"}, 240 {".map", "text/plain"}, 241 {".master", "application/xml"}, 242 {".mda", "application/msaccess"}, 243 {".mdb", "application/x-msaccess"}, 244 {".mde", "application/msaccess"}, 245 {".mdp", "application/octet-stream"}, 246 {".me", "application/x-troff-me"}, 247 {".mfp", "application/x-shockwave-flash"}, 248 {".mht", "message/rfc822"}, 249 {".mhtml", "message/rfc822"}, 250 {".mid", "audio/mid"}, 251 {".midi", "audio/mid"}, 252 {".mix", "application/octet-stream"}, 253 {".mk", "text/plain"}, 254 {".mmf", "application/x-smaf"}, 255 {".mno", "text/xml"}, 256 {".mny", "application/x-msmoney"}, 257 {".mod", "video/mpeg"}, 258 {".mov", "video/quicktime"}, 259 {".movie", "video/x-sgi-movie"}, 260 {".mp2", "video/mpeg"}, 261 {".mp2v", "video/mpeg"}, 262 {".mp3", "audio/mpeg"}, 263 {".mp4", "video/mp4"}, 264 {".mp4v", "video/mp4"}, 265 {".mpa", "video/mpeg"}, 266 {".mpe", "video/mpeg"}, 267 {".mpeg", "video/mpeg"}, 268 {".mpf", "application/vnd.ms-mediapackage"}, 269 {".mpg", "video/mpeg"}, 270 {".mpp", "application/vnd.ms-project"}, 271 {".mpv2", "video/mpeg"}, 272 {".mqv", "video/quicktime"}, 273 {".ms", "application/x-troff-ms"}, 274 {".msi", "application/octet-stream"}, 275 {".mso", "application/octet-stream"}, 276 {".mts", "video/vnd.dlna.mpeg-tts"}, 277 {".mtx", "application/xml"}, 278 {".mvb", "application/x-msmediaview"}, 279 {".mvc", "application/x-miva-compiled"}, 280 {".mxp", "application/x-mmxp"}, 281 {".nc", "application/x-netcdf"}, 282 {".nsc", "video/x-ms-asf"}, 283 {".nws", "message/rfc822"}, 284 {".ocx", "application/octet-stream"}, 285 {".oda", "application/oda"}, 286 {".odc", "text/x-ms-odc"}, 287 {".odh", "text/plain"}, 288 {".odl", "text/plain"}, 289 {".odp", "application/vnd.oasis.opendocument.presentation"}, 290 {".ods", "application/oleobject"}, 291 {".odt", "application/vnd.oasis.opendocument.text"}, 292 {".one", "application/onenote"}, 293 {".onea", "application/onenote"}, 294 {".onepkg", "application/onenote"}, 295 {".onetmp", "application/onenote"}, 296 {".onetoc", "application/onenote"}, 297 {".onetoc2", "application/onenote"}, 298 {".orderedtest", "application/xml"}, 299 {".osdx", "application/opensearchdescription+xml"}, 300 {".p10", "application/pkcs10"}, 301 {".p12", "application/x-pkcs12"}, 302 {".p7b", "application/x-pkcs7-certificates"}, 303 {".p7c", "application/pkcs7-mime"}, 304 {".p7m", "application/pkcs7-mime"}, 305 {".p7r", "application/x-pkcs7-certreqresp"}, 306 {".p7s", "application/pkcs7-signature"}, 307 {".pbm", "image/x-portable-bitmap"}, 308 {".pcast", "application/x-podcast"}, 309 {".pct", "image/pict"}, 310 {".pcx", "application/octet-stream"}, 311 {".pcz", "application/octet-stream"}, 312 {".pdf", "application/pdf"}, 313 {".pfb", "application/octet-stream"}, 314 {".pfm", "application/octet-stream"}, 315 {".pfx", "application/x-pkcs12"}, 316 {".pgm", "image/x-portable-graymap"}, 317 {".pic", "image/pict"}, 318 {".pict", "image/pict"}, 319 {".pkgdef", "text/plain"}, 320 {".pkgundef", "text/plain"}, 321 {".pko", "application/vnd.ms-pki.pko"}, 322 {".pls", "audio/scpls"}, 323 {".pma", "application/x-perfmon"}, 324 {".pmc", "application/x-perfmon"}, 325 {".pml", "application/x-perfmon"}, 326 {".pmr", "application/x-perfmon"}, 327 {".pmw", "application/x-perfmon"}, 328 {".png", "image/png"}, 329 {".pnm", "image/x-portable-anymap"}, 330 {".pnt", "image/x-macpaint"}, 331 {".pntg", "image/x-macpaint"}, 332 {".pnz", "image/png"}, 333 {".pot", "application/vnd.ms-powerpoint"}, 334 {".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"}, 335 {".potx", "application/vnd.openxmlformats-officedocument.presentationml.template"}, 336 {".ppa", "application/vnd.ms-powerpoint"}, 337 {".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12"}, 338 {".ppm", "image/x-portable-pixmap"}, 339 {".pps", "application/vnd.ms-powerpoint"}, 340 {".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"}, 341 {".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, 342 {".ppt", "application/vnd.ms-powerpoint"}, 343 {".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, 344 {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, 345 {".prf", "application/pics-rules"}, 346 {".prm", "application/octet-stream"}, 347 {".prx", "application/octet-stream"}, 348 {".ps", "application/postscript"}, 349 {".psc1", "application/PowerShell"}, 350 {".psd", "application/octet-stream"}, 351 {".psess", "application/xml"}, 352 {".psm", "application/octet-stream"}, 353 {".psp", "application/octet-stream"}, 354 {".pub", "application/x-mspublisher"}, 355 {".pwz", "application/vnd.ms-powerpoint"}, 356 {".qht", "text/x-html-insertion"}, 357 {".qhtm", "text/x-html-insertion"}, 358 {".qt", "video/quicktime"}, 359 {".qti", "image/x-quicktime"}, 360 {".qtif", "image/x-quicktime"}, 361 {".qtl", "application/x-quicktimeplayer"}, 362 {".qxd", "application/octet-stream"}, 363 {".ra", "audio/x-pn-realaudio"}, 364 {".ram", "audio/x-pn-realaudio"}, 365 {".rar", "application/octet-stream"}, 366 {".ras", "image/x-cmu-raster"}, 367 {".rat", "application/rat-file"}, 368 {".rc", "text/plain"}, 369 {".rc2", "text/plain"}, 370 {".rct", "text/plain"}, 371 {".rdlc", "application/xml"}, 372 {".resx", "application/xml"}, 373 {".rf", "image/vnd.rn-realflash"}, 374 {".rgb", "image/x-rgb"}, 375 {".rgs", "text/plain"}, 376 {".rm", "application/vnd.rn-realmedia"}, 377 {".rmi", "audio/mid"}, 378 {".rmp", "application/vnd.rn-rn_music_package"}, 379 {".roff", "application/x-troff"}, 380 {".rpm", "audio/x-pn-realaudio-plugin"}, 381 {".rqy", "text/x-ms-rqy"}, 382 {".rtf", "application/rtf"}, 383 {".rtx", "text/richtext"}, 384 {".ruleset", "application/xml"}, 385 {".s", "text/plain"}, 386 {".safariextz", "application/x-safari-safariextz"}, 387 {".scd", "application/x-msschedule"}, 388 {".sct", "text/scriptlet"}, 389 {".sd2", "audio/x-sd2"}, 390 {".sdp", "application/sdp"}, 391 {".sea", "application/octet-stream"}, 392 {".searchConnector-ms", "application/windows-search-connector+xml"}, 393 {".setpay", "application/set-payment-initiation"}, 394 {".setreg", "application/set-registration-initiation"}, 395 {".settings", "application/xml"}, 396 {".sgimb", "application/x-sgimb"}, 397 {".sgml", "text/sgml"}, 398 {".sh", "application/x-sh"}, 399 {".shar", "application/x-shar"}, 400 {".shtml", "text/html"}, 401 {".sit", "application/x-stuffit"}, 402 {".sitemap", "application/xml"}, 403 {".skin", "application/xml"}, 404 {".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12"}, 405 {".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide"}, 406 {".slk", "application/vnd.ms-excel"}, 407 {".sln", "text/plain"}, 408 {".slupkg-ms", "application/x-ms-license"}, 409 {".smd", "audio/x-smd"}, 410 {".smi", "application/octet-stream"}, 411 {".smx", "audio/x-smd"}, 412 {".smz", "audio/x-smd"}, 413 {".snd", "audio/basic"}, 414 {".snippet", "application/xml"}, 415 {".snp", "application/octet-stream"}, 416 {".sol", "text/plain"}, 417 {".sor", "text/plain"}, 418 {".spc", "application/x-pkcs7-certificates"}, 419 {".spl", "application/futuresplash"}, 420 {".src", "application/x-wais-source"}, 421 {".srf", "text/plain"}, 422 {".SSISDeploymentManifest", "text/xml"}, 423 {".ssm", "application/streamingmedia"}, 424 {".sst", "application/vnd.ms-pki.certstore"}, 425 {".stl", "application/vnd.ms-pki.stl"}, 426 {".sv4cpio", "application/x-sv4cpio"}, 427 {".sv4crc", "application/x-sv4crc"}, 428 {".svc", "application/xml"}, 429 {".swf", "application/x-shockwave-flash"}, 430 {".t", "application/x-troff"}, 431 {".tar", "application/x-tar"}, 432 {".tcl", "application/x-tcl"}, 433 {".testrunconfig", "application/xml"}, 434 {".testsettings", "application/xml"}, 435 {".tex", "application/x-tex"}, 436 {".texi", "application/x-texinfo"}, 437 {".texinfo", "application/x-texinfo"}, 438 {".tgz", "application/x-compressed"}, 439 {".thmx", "application/vnd.ms-officetheme"}, 440 {".thn", "application/octet-stream"}, 441 {".tif", "image/tiff"}, 442 {".tiff", "image/tiff"}, 443 {".tlh", "text/plain"}, 444 {".tli", "text/plain"}, 445 {".toc", "application/octet-stream"}, 446 {".tr", "application/x-troff"}, 447 {".trm", "application/x-msterminal"}, 448 {".trx", "application/xml"}, 449 {".ts", "video/vnd.dlna.mpeg-tts"}, 450 {".tsv", "text/tab-separated-values"}, 451 {".ttf", "application/octet-stream"}, 452 {".tts", "video/vnd.dlna.mpeg-tts"}, 453 {".txt", "text/plain"}, 454 {".u32", "application/octet-stream"}, 455 {".uls", "text/iuls"}, 456 {".user", "text/plain"}, 457 {".ustar", "application/x-ustar"}, 458 {".vb", "text/plain"}, 459 {".vbdproj", "text/plain"}, 460 {".vbk", "video/mpeg"}, 461 {".vbproj", "text/plain"}, 462 {".vbs", "text/vbscript"}, 463 {".vcf", "text/x-vcard"}, 464 {".vcproj", "Application/xml"}, 465 {".vcs", "text/plain"}, 466 {".vcxproj", "Application/xml"}, 467 {".vddproj", "text/plain"}, 468 {".vdp", "text/plain"}, 469 {".vdproj", "text/plain"}, 470 {".vdx", "application/vnd.ms-visio.viewer"}, 471 {".vml", "text/xml"}, 472 {".vscontent", "application/xml"}, 473 {".vsct", "text/xml"}, 474 {".vsd", "application/vnd.visio"}, 475 {".vsi", "application/ms-vsi"}, 476 {".vsix", "application/vsix"}, 477 {".vsixlangpack", "text/xml"}, 478 {".vsixmanifest", "text/xml"}, 479 {".vsmdi", "application/xml"}, 480 {".vspscc", "text/plain"}, 481 {".vss", "application/vnd.visio"}, 482 {".vsscc", "text/plain"}, 483 {".vssettings", "text/xml"}, 484 {".vssscc", "text/plain"}, 485 {".vst", "application/vnd.visio"}, 486 {".vstemplate", "text/xml"}, 487 {".vsto", "application/x-ms-vsto"}, 488 {".vsw", "application/vnd.visio"}, 489 {".vsx", "application/vnd.visio"}, 490 {".vtx", "application/vnd.visio"}, 491 {".wav", "audio/wav"}, 492 {".wave", "audio/wav"}, 493 {".wax", "audio/x-ms-wax"}, 494 {".wbk", "application/msword"}, 495 {".wbmp", "image/vnd.wap.wbmp"}, 496 {".wcm", "application/vnd.ms-works"}, 497 {".wdb", "application/vnd.ms-works"}, 498 {".wdp", "image/vnd.ms-photo"}, 499 {".webarchive", "application/x-safari-webarchive"}, 500 {".webtest", "application/xml"}, 501 {".wiq", "application/xml"}, 502 {".wiz", "application/msword"}, 503 {".wks", "application/vnd.ms-works"}, 504 {".WLMP", "application/wlmoviemaker"}, 505 {".wlpginstall", "application/x-wlpg-detect"}, 506 {".wlpginstall3", "application/x-wlpg3-detect"}, 507 {".wm", "video/x-ms-wm"}, 508 {".wma", "audio/x-ms-wma"}, 509 {".wmd", "application/x-ms-wmd"}, 510 {".wmf", "application/x-msmetafile"}, 511 {".wml", "text/vnd.wap.wml"}, 512 {".wmlc", "application/vnd.wap.wmlc"}, 513 {".wmls", "text/vnd.wap.wmlscript"}, 514 {".wmlsc", "application/vnd.wap.wmlscriptc"}, 515 {".wmp", "video/x-ms-wmp"}, 516 {".wmv", "video/x-ms-wmv"}, 517 {".wmx", "video/x-ms-wmx"}, 518 {".wmz", "application/x-ms-wmz"}, 519 {".wpl", "application/vnd.ms-wpl"}, 520 {".wps", "application/vnd.ms-works"}, 521 {".wri", "application/x-mswrite"}, 522 {".wrl", "x-world/x-vrml"}, 523 {".wrz", "x-world/x-vrml"}, 524 {".wsc", "text/scriptlet"}, 525 {".wsdl", "text/xml"}, 526 {".wvx", "video/x-ms-wvx"}, 527 {".x", "application/directx"}, 528 {".xaf", "x-world/x-vrml"}, 529 {".xaml", "application/xaml+xml"}, 530 {".xap", "application/x-silverlight-app"}, 531 {".xbap", "application/x-ms-xbap"}, 532 {".xbm", "image/x-xbitmap"}, 533 {".xdr", "text/plain"}, 534 {".xht", "application/xhtml+xml"}, 535 {".xhtml", "application/xhtml+xml"}, 536 {".xla", "application/vnd.ms-excel"}, 537 {".xlam", "application/vnd.ms-excel.addin.macroEnabled.12"}, 538 {".xlc", "application/vnd.ms-excel"}, 539 {".xld", "application/vnd.ms-excel"}, 540 {".xlk", "application/vnd.ms-excel"}, 541 {".xll", "application/vnd.ms-excel"}, 542 {".xlm", "application/vnd.ms-excel"}, 543 {".xls", "application/vnd.ms-excel"}, 544 {".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, 545 {".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12"}, 546 {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, 547 {".xlt", "application/vnd.ms-excel"}, 548 {".xltm", "application/vnd.ms-excel.template.macroEnabled.12"}, 549 {".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"}, 550 {".xlw", "application/vnd.ms-excel"}, 551 {".xml", "text/xml"}, 552 {".xmta", "application/xml"}, 553 {".xof", "x-world/x-vrml"}, 554 {".XOML", "text/plain"}, 555 {".xpm", "image/x-xpixmap"}, 556 {".xps", "application/vnd.ms-xpsdocument"}, 557 {".xrm-ms", "text/xml"}, 558 {".xsc", "application/xml"}, 559 {".xsd", "text/xml"}, 560 {".xsf", "text/xml"}, 561 {".xsl", "text/xml"}, 562 {".xslt", "text/xml"}, 563 {".xsn", "application/octet-stream"}, 564 {".xss", "application/xml"}, 565 {".xtp", "application/octet-stream"}, 566 {".xwd", "image/x-xwindowdump"}, 567 {".z", "application/x-compress"}, 568 {".zip", "application/x-zip-compressed"}, 569 }; 4 namespace AllocsFixes.NetConnections.Servers.Web { 5 public class MimeType { 6 private static readonly IDictionary<string, string> _mappings = 7 new Dictionary<string, string> (StringComparer.InvariantCultureIgnoreCase) { 8 {".323", "text/h323"}, 9 {".3g2", "video/3gpp2"}, 10 {".3gp", "video/3gpp"}, 11 {".3gp2", "video/3gpp2"}, 12 {".3gpp", "video/3gpp"}, 13 {".7z", "application/x-7z-compressed"}, 14 {".aa", "audio/audible"}, 15 {".AAC", "audio/aac"}, 16 {".aaf", "application/octet-stream"}, 17 {".aax", "audio/vnd.audible.aax"}, 18 {".ac3", "audio/ac3"}, 19 {".aca", "application/octet-stream"}, 20 {".accda", "application/msaccess.addin"}, 21 {".accdb", "application/msaccess"}, 22 {".accdc", "application/msaccess.cab"}, 23 {".accde", "application/msaccess"}, 24 {".accdr", "application/msaccess.runtime"}, 25 {".accdt", "application/msaccess"}, 26 {".accdw", "application/msaccess.webapplication"}, 27 {".accft", "application/msaccess.ftemplate"}, 28 {".acx", "application/internet-property-stream"}, 29 {".AddIn", "text/xml"}, 30 {".ade", "application/msaccess"}, 31 {".adobebridge", "application/x-bridge-url"}, 32 {".adp", "application/msaccess"}, 33 {".ADT", "audio/vnd.dlna.adts"}, 34 {".ADTS", "audio/aac"}, 35 {".afm", "application/octet-stream"}, 36 {".ai", "application/postscript"}, 37 {".aif", "audio/x-aiff"}, 38 {".aifc", "audio/aiff"}, 39 {".aiff", "audio/aiff"}, 40 {".air", "application/vnd.adobe.air-application-installer-package+zip"}, 41 {".amc", "application/x-mpeg"}, 42 {".application", "application/x-ms-application"}, 43 {".art", "image/x-jg"}, 44 {".asa", "application/xml"}, 45 {".asax", "application/xml"}, 46 {".ascx", "application/xml"}, 47 {".asd", "application/octet-stream"}, 48 {".asf", "video/x-ms-asf"}, 49 {".ashx", "application/xml"}, 50 {".asi", "application/octet-stream"}, 51 {".asm", "text/plain"}, 52 {".asmx", "application/xml"}, 53 {".aspx", "application/xml"}, 54 {".asr", "video/x-ms-asf"}, 55 {".asx", "video/x-ms-asf"}, 56 {".atom", "application/atom+xml"}, 57 {".au", "audio/basic"}, 58 {".avi", "video/x-msvideo"}, 59 {".axs", "application/olescript"}, 60 {".bas", "text/plain"}, 61 {".bcpio", "application/x-bcpio"}, 62 {".bin", "application/octet-stream"}, 63 {".bmp", "image/bmp"}, 64 {".c", "text/plain"}, 65 {".cab", "application/octet-stream"}, 66 {".caf", "audio/x-caf"}, 67 {".calx", "application/vnd.ms-office.calx"}, 68 {".cat", "application/vnd.ms-pki.seccat"}, 69 {".cc", "text/plain"}, 70 {".cd", "text/plain"}, 71 {".cdda", "audio/aiff"}, 72 {".cdf", "application/x-cdf"}, 73 {".cer", "application/x-x509-ca-cert"}, 74 {".chm", "application/octet-stream"}, 75 {".class", "application/x-java-applet"}, 76 {".clp", "application/x-msclip"}, 77 {".cmx", "image/x-cmx"}, 78 {".cnf", "text/plain"}, 79 {".cod", "image/cis-cod"}, 80 {".config", "application/xml"}, 81 {".contact", "text/x-ms-contact"}, 82 {".coverage", "application/xml"}, 83 {".cpio", "application/x-cpio"}, 84 {".cpp", "text/plain"}, 85 {".crd", "application/x-mscardfile"}, 86 {".crl", "application/pkix-crl"}, 87 {".crt", "application/x-x509-ca-cert"}, 88 {".cs", "text/plain"}, 89 {".csdproj", "text/plain"}, 90 {".csh", "application/x-csh"}, 91 {".csproj", "text/plain"}, 92 {".css", "text/css"}, 93 {".csv", "text/csv"}, 94 {".cur", "application/octet-stream"}, 95 {".cxx", "text/plain"}, 96 {".dat", "application/octet-stream"}, 97 {".datasource", "application/xml"}, 98 {".dbproj", "text/plain"}, 99 {".dcr", "application/x-director"}, 100 {".def", "text/plain"}, 101 {".deploy", "application/octet-stream"}, 102 {".der", "application/x-x509-ca-cert"}, 103 {".dgml", "application/xml"}, 104 {".dib", "image/bmp"}, 105 {".dif", "video/x-dv"}, 106 {".dir", "application/x-director"}, 107 {".disco", "text/xml"}, 108 {".dll", "application/x-msdownload"}, 109 {".dll.config", "text/xml"}, 110 {".dlm", "text/dlm"}, 111 {".doc", "application/msword"}, 112 {".docm", "application/vnd.ms-word.document.macroEnabled.12"}, 113 {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, 114 {".dot", "application/msword"}, 115 {".dotm", "application/vnd.ms-word.template.macroEnabled.12"}, 116 {".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, 117 {".dsp", "application/octet-stream"}, 118 {".dsw", "text/plain"}, 119 {".dtd", "text/xml"}, 120 {".dtsConfig", "text/xml"}, 121 {".dv", "video/x-dv"}, 122 {".dvi", "application/x-dvi"}, 123 {".dwf", "drawing/x-dwf"}, 124 {".dwp", "application/octet-stream"}, 125 {".dxr", "application/x-director"}, 126 {".eml", "message/rfc822"}, 127 {".emz", "application/octet-stream"}, 128 {".eot", "application/octet-stream"}, 129 {".eps", "application/postscript"}, 130 {".etl", "application/etl"}, 131 {".etx", "text/x-setext"}, 132 {".evy", "application/envoy"}, 133 {".exe", "application/octet-stream"}, 134 {".exe.config", "text/xml"}, 135 {".fdf", "application/vnd.fdf"}, 136 {".fif", "application/fractals"}, 137 {".filters", "Application/xml"}, 138 {".fla", "application/octet-stream"}, 139 {".flr", "x-world/x-vrml"}, 140 {".flv", "video/x-flv"}, 141 {".fsscript", "application/fsharp-script"}, 142 {".fsx", "application/fsharp-script"}, 143 {".generictest", "application/xml"}, 144 {".gif", "image/gif"}, 145 {".group", "text/x-ms-group"}, 146 {".gsm", "audio/x-gsm"}, 147 {".gtar", "application/x-gtar"}, 148 {".gz", "application/x-gzip"}, 149 {".h", "text/plain"}, 150 {".hdf", "application/x-hdf"}, 151 {".hdml", "text/x-hdml"}, 152 {".hhc", "application/x-oleobject"}, 153 {".hhk", "application/octet-stream"}, 154 {".hhp", "application/octet-stream"}, 155 {".hlp", "application/winhlp"}, 156 {".hpp", "text/plain"}, 157 {".hqx", "application/mac-binhex40"}, 158 {".hta", "application/hta"}, 159 {".htc", "text/x-component"}, 160 {".htm", "text/html"}, 161 {".html", "text/html"}, 162 {".htt", "text/webviewhtml"}, 163 {".hxa", "application/xml"}, 164 {".hxc", "application/xml"}, 165 {".hxd", "application/octet-stream"}, 166 {".hxe", "application/xml"}, 167 {".hxf", "application/xml"}, 168 {".hxh", "application/octet-stream"}, 169 {".hxi", "application/octet-stream"}, 170 {".hxk", "application/xml"}, 171 {".hxq", "application/octet-stream"}, 172 {".hxr", "application/octet-stream"}, 173 {".hxs", "application/octet-stream"}, 174 {".hxt", "text/html"}, 175 {".hxv", "application/xml"}, 176 {".hxw", "application/octet-stream"}, 177 {".hxx", "text/plain"}, 178 {".i", "text/plain"}, 179 {".ico", "image/x-icon"}, 180 {".ics", "application/octet-stream"}, 181 {".idl", "text/plain"}, 182 {".ief", "image/ief"}, 183 {".iii", "application/x-iphone"}, 184 {".inc", "text/plain"}, 185 {".inf", "application/octet-stream"}, 186 {".inl", "text/plain"}, 187 {".ins", "application/x-internet-signup"}, 188 {".ipa", "application/x-itunes-ipa"}, 189 {".ipg", "application/x-itunes-ipg"}, 190 {".ipproj", "text/plain"}, 191 {".ipsw", "application/x-itunes-ipsw"}, 192 {".iqy", "text/x-ms-iqy"}, 193 {".isp", "application/x-internet-signup"}, 194 {".ite", "application/x-itunes-ite"}, 195 {".itlp", "application/x-itunes-itlp"}, 196 {".itms", "application/x-itunes-itms"}, 197 {".itpc", "application/x-itunes-itpc"}, 198 {".IVF", "video/x-ivf"}, 199 {".jar", "application/java-archive"}, 200 {".java", "application/octet-stream"}, 201 {".jck", "application/liquidmotion"}, 202 {".jcz", "application/liquidmotion"}, 203 {".jfif", "image/pjpeg"}, 204 {".jnlp", "application/x-java-jnlp-file"}, 205 {".jpb", "application/octet-stream"}, 206 {".jpe", "image/jpeg"}, 207 {".jpeg", "image/jpeg"}, 208 {".jpg", "image/jpeg"}, 209 {".js", "application/x-javascript"}, 210 {".json", "application/json"}, 211 {".jsx", "text/jscript"}, 212 {".jsxbin", "text/plain"}, 213 {".latex", "application/x-latex"}, 214 {".library-ms", "application/windows-library+xml"}, 215 {".lit", "application/x-ms-reader"}, 216 {".loadtest", "application/xml"}, 217 {".lpk", "application/octet-stream"}, 218 {".lsf", "video/x-la-asf"}, 219 {".lst", "text/plain"}, 220 {".lsx", "video/x-la-asf"}, 221 {".lzh", "application/octet-stream"}, 222 {".m13", "application/x-msmediaview"}, 223 {".m14", "application/x-msmediaview"}, 224 {".m1v", "video/mpeg"}, 225 {".m2t", "video/vnd.dlna.mpeg-tts"}, 226 {".m2ts", "video/vnd.dlna.mpeg-tts"}, 227 {".m2v", "video/mpeg"}, 228 {".m3u", "audio/x-mpegurl"}, 229 {".m3u8", "audio/x-mpegurl"}, 230 {".m4a", "audio/m4a"}, 231 {".m4b", "audio/m4b"}, 232 {".m4p", "audio/m4p"}, 233 {".m4r", "audio/x-m4r"}, 234 {".m4v", "video/x-m4v"}, 235 {".mac", "image/x-macpaint"}, 236 {".mak", "text/plain"}, 237 {".man", "application/x-troff-man"}, 238 {".manifest", "application/x-ms-manifest"}, 239 {".map", "text/plain"}, 240 {".master", "application/xml"}, 241 {".mda", "application/msaccess"}, 242 {".mdb", "application/x-msaccess"}, 243 {".mde", "application/msaccess"}, 244 {".mdp", "application/octet-stream"}, 245 {".me", "application/x-troff-me"}, 246 {".mfp", "application/x-shockwave-flash"}, 247 {".mht", "message/rfc822"}, 248 {".mhtml", "message/rfc822"}, 249 {".mid", "audio/mid"}, 250 {".midi", "audio/mid"}, 251 {".mix", "application/octet-stream"}, 252 {".mk", "text/plain"}, 253 {".mmf", "application/x-smaf"}, 254 {".mno", "text/xml"}, 255 {".mny", "application/x-msmoney"}, 256 {".mod", "video/mpeg"}, 257 {".mov", "video/quicktime"}, 258 {".movie", "video/x-sgi-movie"}, 259 {".mp2", "video/mpeg"}, 260 {".mp2v", "video/mpeg"}, 261 {".mp3", "audio/mpeg"}, 262 {".mp4", "video/mp4"}, 263 {".mp4v", "video/mp4"}, 264 {".mpa", "video/mpeg"}, 265 {".mpe", "video/mpeg"}, 266 {".mpeg", "video/mpeg"}, 267 {".mpf", "application/vnd.ms-mediapackage"}, 268 {".mpg", "video/mpeg"}, 269 {".mpp", "application/vnd.ms-project"}, 270 {".mpv2", "video/mpeg"}, 271 {".mqv", "video/quicktime"}, 272 {".ms", "application/x-troff-ms"}, 273 {".msi", "application/octet-stream"}, 274 {".mso", "application/octet-stream"}, 275 {".mts", "video/vnd.dlna.mpeg-tts"}, 276 {".mtx", "application/xml"}, 277 {".mvb", "application/x-msmediaview"}, 278 {".mvc", "application/x-miva-compiled"}, 279 {".mxp", "application/x-mmxp"}, 280 {".nc", "application/x-netcdf"}, 281 {".nsc", "video/x-ms-asf"}, 282 {".nws", "message/rfc822"}, 283 {".ocx", "application/octet-stream"}, 284 {".oda", "application/oda"}, 285 {".odc", "text/x-ms-odc"}, 286 {".odh", "text/plain"}, 287 {".odl", "text/plain"}, 288 {".odp", "application/vnd.oasis.opendocument.presentation"}, 289 {".ods", "application/oleobject"}, 290 {".odt", "application/vnd.oasis.opendocument.text"}, 291 {".one", "application/onenote"}, 292 {".onea", "application/onenote"}, 293 {".onepkg", "application/onenote"}, 294 {".onetmp", "application/onenote"}, 295 {".onetoc", "application/onenote"}, 296 {".onetoc2", "application/onenote"}, 297 {".orderedtest", "application/xml"}, 298 {".osdx", "application/opensearchdescription+xml"}, 299 {".p10", "application/pkcs10"}, 300 {".p12", "application/x-pkcs12"}, 301 {".p7b", "application/x-pkcs7-certificates"}, 302 {".p7c", "application/pkcs7-mime"}, 303 {".p7m", "application/pkcs7-mime"}, 304 {".p7r", "application/x-pkcs7-certreqresp"}, 305 {".p7s", "application/pkcs7-signature"}, 306 {".pbm", "image/x-portable-bitmap"}, 307 {".pcast", "application/x-podcast"}, 308 {".pct", "image/pict"}, 309 {".pcx", "application/octet-stream"}, 310 {".pcz", "application/octet-stream"}, 311 {".pdf", "application/pdf"}, 312 {".pfb", "application/octet-stream"}, 313 {".pfm", "application/octet-stream"}, 314 {".pfx", "application/x-pkcs12"}, 315 {".pgm", "image/x-portable-graymap"}, 316 {".pic", "image/pict"}, 317 {".pict", "image/pict"}, 318 {".pkgdef", "text/plain"}, 319 {".pkgundef", "text/plain"}, 320 {".pko", "application/vnd.ms-pki.pko"}, 321 {".pls", "audio/scpls"}, 322 {".pma", "application/x-perfmon"}, 323 {".pmc", "application/x-perfmon"}, 324 {".pml", "application/x-perfmon"}, 325 {".pmr", "application/x-perfmon"}, 326 {".pmw", "application/x-perfmon"}, 327 {".png", "image/png"}, 328 {".pnm", "image/x-portable-anymap"}, 329 {".pnt", "image/x-macpaint"}, 330 {".pntg", "image/x-macpaint"}, 331 {".pnz", "image/png"}, 332 {".pot", "application/vnd.ms-powerpoint"}, 333 {".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"}, 334 {".potx", "application/vnd.openxmlformats-officedocument.presentationml.template"}, 335 {".ppa", "application/vnd.ms-powerpoint"}, 336 {".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12"}, 337 {".ppm", "image/x-portable-pixmap"}, 338 {".pps", "application/vnd.ms-powerpoint"}, 339 {".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"}, 340 {".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, 341 {".ppt", "application/vnd.ms-powerpoint"}, 342 {".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, 343 {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, 344 {".prf", "application/pics-rules"}, 345 {".prm", "application/octet-stream"}, 346 {".prx", "application/octet-stream"}, 347 {".ps", "application/postscript"}, 348 {".psc1", "application/PowerShell"}, 349 {".psd", "application/octet-stream"}, 350 {".psess", "application/xml"}, 351 {".psm", "application/octet-stream"}, 352 {".psp", "application/octet-stream"}, 353 {".pub", "application/x-mspublisher"}, 354 {".pwz", "application/vnd.ms-powerpoint"}, 355 {".qht", "text/x-html-insertion"}, 356 {".qhtm", "text/x-html-insertion"}, 357 {".qt", "video/quicktime"}, 358 {".qti", "image/x-quicktime"}, 359 {".qtif", "image/x-quicktime"}, 360 {".qtl", "application/x-quicktimeplayer"}, 361 {".qxd", "application/octet-stream"}, 362 {".ra", "audio/x-pn-realaudio"}, 363 {".ram", "audio/x-pn-realaudio"}, 364 {".rar", "application/octet-stream"}, 365 {".ras", "image/x-cmu-raster"}, 366 {".rat", "application/rat-file"}, 367 {".rc", "text/plain"}, 368 {".rc2", "text/plain"}, 369 {".rct", "text/plain"}, 370 {".rdlc", "application/xml"}, 371 {".resx", "application/xml"}, 372 {".rf", "image/vnd.rn-realflash"}, 373 {".rgb", "image/x-rgb"}, 374 {".rgs", "text/plain"}, 375 {".rm", "application/vnd.rn-realmedia"}, 376 {".rmi", "audio/mid"}, 377 {".rmp", "application/vnd.rn-rn_music_package"}, 378 {".roff", "application/x-troff"}, 379 {".rpm", "audio/x-pn-realaudio-plugin"}, 380 {".rqy", "text/x-ms-rqy"}, 381 {".rtf", "application/rtf"}, 382 {".rtx", "text/richtext"}, 383 {".ruleset", "application/xml"}, 384 {".s", "text/plain"}, 385 {".safariextz", "application/x-safari-safariextz"}, 386 {".scd", "application/x-msschedule"}, 387 {".sct", "text/scriptlet"}, 388 {".sd2", "audio/x-sd2"}, 389 {".sdp", "application/sdp"}, 390 {".sea", "application/octet-stream"}, 391 {".searchConnector-ms", "application/windows-search-connector+xml"}, 392 {".setpay", "application/set-payment-initiation"}, 393 {".setreg", "application/set-registration-initiation"}, 394 {".settings", "application/xml"}, 395 {".sgimb", "application/x-sgimb"}, 396 {".sgml", "text/sgml"}, 397 {".sh", "application/x-sh"}, 398 {".shar", "application/x-shar"}, 399 {".shtml", "text/html"}, 400 {".sit", "application/x-stuffit"}, 401 {".sitemap", "application/xml"}, 402 {".skin", "application/xml"}, 403 {".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12"}, 404 {".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide"}, 405 {".slk", "application/vnd.ms-excel"}, 406 {".sln", "text/plain"}, 407 {".slupkg-ms", "application/x-ms-license"}, 408 {".smd", "audio/x-smd"}, 409 {".smi", "application/octet-stream"}, 410 {".smx", "audio/x-smd"}, 411 {".smz", "audio/x-smd"}, 412 {".snd", "audio/basic"}, 413 {".snippet", "application/xml"}, 414 {".snp", "application/octet-stream"}, 415 {".sol", "text/plain"}, 416 {".sor", "text/plain"}, 417 {".spc", "application/x-pkcs7-certificates"}, 418 {".spl", "application/futuresplash"}, 419 {".src", "application/x-wais-source"}, 420 {".srf", "text/plain"}, 421 {".SSISDeploymentManifest", "text/xml"}, 422 {".ssm", "application/streamingmedia"}, 423 {".sst", "application/vnd.ms-pki.certstore"}, 424 {".stl", "application/vnd.ms-pki.stl"}, 425 {".sv4cpio", "application/x-sv4cpio"}, 426 {".sv4crc", "application/x-sv4crc"}, 427 {".svc", "application/xml"}, 428 {".swf", "application/x-shockwave-flash"}, 429 {".t", "application/x-troff"}, 430 {".tar", "application/x-tar"}, 431 {".tcl", "application/x-tcl"}, 432 {".testrunconfig", "application/xml"}, 433 {".testsettings", "application/xml"}, 434 {".tex", "application/x-tex"}, 435 {".texi", "application/x-texinfo"}, 436 {".texinfo", "application/x-texinfo"}, 437 {".tgz", "application/x-compressed"}, 438 {".thmx", "application/vnd.ms-officetheme"}, 439 {".thn", "application/octet-stream"}, 440 {".tif", "image/tiff"}, 441 {".tiff", "image/tiff"}, 442 {".tlh", "text/plain"}, 443 {".tli", "text/plain"}, 444 {".toc", "application/octet-stream"}, 445 {".tr", "application/x-troff"}, 446 {".trm", "application/x-msterminal"}, 447 {".trx", "application/xml"}, 448 {".ts", "video/vnd.dlna.mpeg-tts"}, 449 {".tsv", "text/tab-separated-values"}, 450 {".ttf", "application/octet-stream"}, 451 {".tts", "video/vnd.dlna.mpeg-tts"}, 452 {".txt", "text/plain"}, 453 {".u32", "application/octet-stream"}, 454 {".uls", "text/iuls"}, 455 {".user", "text/plain"}, 456 {".ustar", "application/x-ustar"}, 457 {".vb", "text/plain"}, 458 {".vbdproj", "text/plain"}, 459 {".vbk", "video/mpeg"}, 460 {".vbproj", "text/plain"}, 461 {".vbs", "text/vbscript"}, 462 {".vcf", "text/x-vcard"}, 463 {".vcproj", "Application/xml"}, 464 {".vcs", "text/plain"}, 465 {".vcxproj", "Application/xml"}, 466 {".vddproj", "text/plain"}, 467 {".vdp", "text/plain"}, 468 {".vdproj", "text/plain"}, 469 {".vdx", "application/vnd.ms-visio.viewer"}, 470 {".vml", "text/xml"}, 471 {".vscontent", "application/xml"}, 472 {".vsct", "text/xml"}, 473 {".vsd", "application/vnd.visio"}, 474 {".vsi", "application/ms-vsi"}, 475 {".vsix", "application/vsix"}, 476 {".vsixlangpack", "text/xml"}, 477 {".vsixmanifest", "text/xml"}, 478 {".vsmdi", "application/xml"}, 479 {".vspscc", "text/plain"}, 480 {".vss", "application/vnd.visio"}, 481 {".vsscc", "text/plain"}, 482 {".vssettings", "text/xml"}, 483 {".vssscc", "text/plain"}, 484 {".vst", "application/vnd.visio"}, 485 {".vstemplate", "text/xml"}, 486 {".vsto", "application/x-ms-vsto"}, 487 {".vsw", "application/vnd.visio"}, 488 {".vsx", "application/vnd.visio"}, 489 {".vtx", "application/vnd.visio"}, 490 {".wav", "audio/wav"}, 491 {".wave", "audio/wav"}, 492 {".wax", "audio/x-ms-wax"}, 493 {".wbk", "application/msword"}, 494 {".wbmp", "image/vnd.wap.wbmp"}, 495 {".wcm", "application/vnd.ms-works"}, 496 {".wdb", "application/vnd.ms-works"}, 497 {".wdp", "image/vnd.ms-photo"}, 498 {".webarchive", "application/x-safari-webarchive"}, 499 {".webtest", "application/xml"}, 500 {".wiq", "application/xml"}, 501 {".wiz", "application/msword"}, 502 {".wks", "application/vnd.ms-works"}, 503 {".WLMP", "application/wlmoviemaker"}, 504 {".wlpginstall", "application/x-wlpg-detect"}, 505 {".wlpginstall3", "application/x-wlpg3-detect"}, 506 {".wm", "video/x-ms-wm"}, 507 {".wma", "audio/x-ms-wma"}, 508 {".wmd", "application/x-ms-wmd"}, 509 {".wmf", "application/x-msmetafile"}, 510 {".wml", "text/vnd.wap.wml"}, 511 {".wmlc", "application/vnd.wap.wmlc"}, 512 {".wmls", "text/vnd.wap.wmlscript"}, 513 {".wmlsc", "application/vnd.wap.wmlscriptc"}, 514 {".wmp", "video/x-ms-wmp"}, 515 {".wmv", "video/x-ms-wmv"}, 516 {".wmx", "video/x-ms-wmx"}, 517 {".wmz", "application/x-ms-wmz"}, 518 {".wpl", "application/vnd.ms-wpl"}, 519 {".wps", "application/vnd.ms-works"}, 520 {".wri", "application/x-mswrite"}, 521 {".wrl", "x-world/x-vrml"}, 522 {".wrz", "x-world/x-vrml"}, 523 {".wsc", "text/scriptlet"}, 524 {".wsdl", "text/xml"}, 525 {".wvx", "video/x-ms-wvx"}, 526 {".x", "application/directx"}, 527 {".xaf", "x-world/x-vrml"}, 528 {".xaml", "application/xaml+xml"}, 529 {".xap", "application/x-silverlight-app"}, 530 {".xbap", "application/x-ms-xbap"}, 531 {".xbm", "image/x-xbitmap"}, 532 {".xdr", "text/plain"}, 533 {".xht", "application/xhtml+xml"}, 534 {".xhtml", "application/xhtml+xml"}, 535 {".xla", "application/vnd.ms-excel"}, 536 {".xlam", "application/vnd.ms-excel.addin.macroEnabled.12"}, 537 {".xlc", "application/vnd.ms-excel"}, 538 {".xld", "application/vnd.ms-excel"}, 539 {".xlk", "application/vnd.ms-excel"}, 540 {".xll", "application/vnd.ms-excel"}, 541 {".xlm", "application/vnd.ms-excel"}, 542 {".xls", "application/vnd.ms-excel"}, 543 {".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, 544 {".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12"}, 545 {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, 546 {".xlt", "application/vnd.ms-excel"}, 547 {".xltm", "application/vnd.ms-excel.template.macroEnabled.12"}, 548 {".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"}, 549 {".xlw", "application/vnd.ms-excel"}, 550 {".xml", "text/xml"}, 551 {".xmta", "application/xml"}, 552 {".xof", "x-world/x-vrml"}, 553 {".XOML", "text/plain"}, 554 {".xpm", "image/x-xpixmap"}, 555 {".xps", "application/vnd.ms-xpsdocument"}, 556 {".xrm-ms", "text/xml"}, 557 {".xsc", "application/xml"}, 558 {".xsd", "text/xml"}, 559 {".xsf", "text/xml"}, 560 {".xsl", "text/xml"}, 561 {".xslt", "text/xml"}, 562 {".xsn", "application/octet-stream"}, 563 {".xss", "application/xml"}, 564 {".xtp", "application/octet-stream"}, 565 {".xwd", "image/x-xwindowdump"}, 566 {".z", "application/x-compress"}, 567 {".zip", "application/x-zip-compressed"} 568 }; 570 569 571 public static string GetMimeType (string extension) 572 { 570 public static string GetMimeType (string extension) { 573 571 if (extension == null) { 574 572 throw new ArgumentNullException ("extension"); … … 585 583 } 586 584 } 587 -
binary-improvements/MapRendering/Web/OpenID.cs
r318 r325 5 5 using System.Net; 6 6 using System.Net.Security; 7 using System.Reflection; 8 using System.Security.Cryptography.X509Certificates; 7 9 using System.Text; 8 10 using System.Text.RegularExpressions; 9 using System.Security.Cryptography.X509Certificates; 10 using System.Reflection; 11 12 namespace AllocsFixes.NetConnections.Servers.Web 13 { 11 12 namespace AllocsFixes.NetConnections.Servers.Web { 14 13 public static class OpenID { 15 14 private const string STEAM_LOGIN = "https://steamcommunity.com/openid/login"; 16 private static Regex steamIdUrlMatcher = new Regex (@"^https?:\/\/steamcommunity\.com\/openid\/id\/([0-9]{17,18})"); 17 18 private static readonly X509Certificate2 caCert = new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/steam-rootca.cer"); 19 private static readonly X509Certificate2 caIntermediateCert = new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/steam-intermediate.cer"); 15 16 private static readonly Regex steamIdUrlMatcher = 17 new Regex (@"^https?:\/\/steamcommunity\.com\/openid\/id\/([0-9]{17,18})"); 18 19 private static readonly X509Certificate2 caCert = 20 new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + 21 "/steam-rootca.cer"); 22 23 private static readonly X509Certificate2 caIntermediateCert = 24 new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + 25 "/steam-intermediate.cer"); 20 26 21 27 private static readonly bool verboseSsl = false; 22 public static bool debugOpenId = false;28 public static bool debugOpenId; 23 29 24 30 static OpenID () { 25 for (int i = 0; i < System.Environment.GetCommandLineArgs ().Length; i++) {26 if ( System.Environment.GetCommandLineArgs () [i].EqualsCaseInsensitive ("-debugopenid")) {31 for (int i = 0; i < Environment.GetCommandLineArgs ().Length; i++) { 32 if (Environment.GetCommandLineArgs () [i].EqualsCaseInsensitive ("-debugopenid")) { 27 33 debugOpenId = true; 28 34 } … … 34 40 Log.Out ("Steam certificate: No error (1)"); 35 41 } 42 36 43 return true; 37 44 } … … 49 56 Log.Out ("Steam certificate: No error (2)"); 50 57 } 58 51 59 return true; 52 60 } … … 58 66 Log.Out ("Steam certificate: No error (3)"); 59 67 } 68 60 69 return true; 61 70 } … … 66 75 Log.Out ("Validating cert: " + chainEl.Certificate.Subject); 67 76 } 77 68 78 // Iterate all status flags of the current cert 69 79 foreach (X509ChainStatus chainStatus in chainEl.ChainElementStatus) { … … 71 81 Log.Out (" Status: " + chainStatus.Status); 72 82 } 83 73 84 if (chainStatus.Status == X509ChainStatusFlags.NoError) { 74 85 // This status is not an error, skip 75 86 continue; 76 87 } 88 77 89 if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot && chainEl.Certificate == caCert) { 78 90 // This status is about the cert being an untrusted root certificate but the certificate is one of those we added, ignore 79 91 continue; 80 92 } 93 81 94 // This status is an error, print information 82 Log.Warning ("Steam certificate error: " + chainEl.Certificate.Subject + " ### Error: " + chainStatus.Status); 95 Log.Warning ("Steam certificate error: " + chainEl.Certificate.Subject + " ### Error: " + 96 chainStatus.Status); 83 97 privateChain.Reset (); 84 98 return false; … … 87 101 88 102 foreach (X509ChainStatus chainStatus in privateChain.ChainStatus) { 89 if (chainStatus.Status != X509ChainStatusFlags.NoError && chainStatus.Status != X509ChainStatusFlags.UntrustedRoot) { 103 if (chainStatus.Status != X509ChainStatusFlags.NoError && 104 chainStatus.Status != X509ChainStatusFlags.UntrustedRoot) { 90 105 Log.Warning ("Steam certificate error: " + chainStatus.Status); 91 106 privateChain.Reset (); … … 99 114 Log.Out ("Steam certificate: No error (4)"); 100 115 } 116 101 117 return true; 102 118 }; 103 104 119 } 105 120 … … 123 138 return 0; 124 139 } 140 125 141 if (mode == "error") { 126 142 Log.Warning ("Steam OpenID login error: " + getValue (_req, "openid.error")); … … 128 144 PrintOpenIdResponse (_req); 129 145 } 146 130 147 return 0; 131 148 } 149 132 150 string steamIdString = getValue (_req, "openid.claimed_id"); 133 151 ulong steamId = 0; … … 140 158 PrintOpenIdResponse (_req); 141 159 } 160 142 161 return 0; 143 162 } … … 161 180 162 181 byte[] postData = Encoding.ASCII.GetBytes (buildUrlParams (queryParams)); 163 HttpWebRequest request = (HttpWebRequest) WebRequest.Create (STEAM_LOGIN);182 HttpWebRequest request = (HttpWebRequest) WebRequest.Create (STEAM_LOGIN); 164 183 request.Method = "POST"; 165 184 request.ContentType = "application/x-www-form-urlencoded"; … … 170 189 } 171 190 172 HttpWebResponse response = (HttpWebResponse) request.GetResponse ();191 HttpWebResponse response = (HttpWebResponse) request.GetResponse (); 173 192 string responseString = null; 174 193 using (Stream st = response.GetResponseStream ()) { … … 180 199 if (responseString.ToLower ().Contains ("is_valid:true")) { 181 200 return steamId; 182 } else {183 Log.Warning ("Steam OpenID login failed: {0}", responseString); 184 return 0;185 }201 } 202 203 Log.Warning ("Steam OpenID login failed: {0}", responseString); 204 return 0; 186 205 } 187 206 … … 192 211 paramsArr [i++] = kvp.Key + "=" + Uri.EscapeDataString (kvp.Value); 193 212 } 213 194 214 return string.Join ("&", paramsArr); 195 215 } … … 200 220 throw new MissingMemberException ("OpenID parameter \"" + _name + "\" missing"); 201 221 } 222 202 223 return nvc [_name]; 203 224 } … … 209 230 } 210 231 } 211 212 232 } 213 233 } 214 -
binary-improvements/MapRendering/Web/Web.cs
r314 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Collections.Specialized;4 3 using System.IO; 5 4 using System.Net; … … 8 7 using System.Text; 9 8 using System.Threading; 9 using AllocsFixes.FileCache; 10 using AllocsFixes.NetConnections.Servers.Web.Handlers; 10 11 using UnityEngine; 11 12 12 using AllocsFixes.NetConnections.Servers.Web.Handlers; 13 14 namespace AllocsFixes.NetConnections.Servers.Web 15 { 13 namespace AllocsFixes.NetConnections.Servers.Web { 16 14 public class Web : IConsoleServer { 17 15 private const int GUEST_PERMISSION_LEVEL = 2000; 16 public static int handlingCount; 17 public static int currentHandlers; 18 public static long totalHandlingTime = 0; 18 19 private readonly HttpListener _listener = new HttpListener (); 19 private Dictionary<string, PathHandler> handlers = new Dictionary<string, PathHandler> (); 20 public static int handlingCount = 0; 21 public static int currentHandlers = 0; 22 public static long totalHandlingTime = 0; 23 private string dataFolder; 24 private bool useStaticCache = false; 25 26 public static bool isSslRedirected (HttpListenerRequest req) { 27 string proto = req.Headers ["X-Forwarded-Proto"]; 28 if (!string.IsNullOrEmpty (proto)) { 29 return proto.Equals ("https", StringComparison.OrdinalIgnoreCase); 30 } 31 32 return false; 33 } 20 private readonly string dataFolder; 21 private readonly Dictionary<string, PathHandler> handlers = new Dictionary<string, PathHandler> (); 22 private readonly bool useStaticCache; 34 23 35 24 public ConnectionHandler connectionHandler; … … 42 31 return; 43 32 } 44 if (!Directory.Exists (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/webserver")) { 33 34 if (!Directory.Exists (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + 35 "/webserver")) { 45 36 Log.Out ("Webserver not started (folder \"webserver\" not found in WebInterface mod folder)"); 46 37 return; … … 56 47 return; 57 48 } 58 59 handlers.Add ( 60 "/index.htm", 61 new SimpleRedirectHandler ("/static/index.html")); 62 handlers.Add ( 63 "/favicon.ico", 64 new SimpleRedirectHandler ("/static/favicon.ico")); 65 handlers.Add ( 49 50 handlers.Add ( 51 "/index.htm", 52 new SimpleRedirectHandler ("/static/index.html")); 53 handlers.Add ( 54 "/favicon.ico", 55 new SimpleRedirectHandler ("/static/favicon.ico")); 56 handlers.Add ( 57 "/session/", 58 new SessionHandler ( 66 59 "/session/", 67 new SessionHandler ( 68 "/session/", 69 dataFolder, 70 this) 71 ); 72 handlers.Add ( 73 "/userstatus", 74 new UserStatusHandler () 60 dataFolder, 61 this) 62 ); 63 handlers.Add ( 64 "/userstatus", 65 new UserStatusHandler () 75 66 ); 76 67 if (useStaticCache) { 77 68 handlers.Add ( 69 "/static/", 70 new StaticHandler ( 78 71 "/static/", 79 new StaticHandler ( 80 "/static/", 81 dataFolder, 82 new AllocsFixes.FileCache.SimpleCache (), 83 false) 72 dataFolder, 73 new SimpleCache (), 74 false) 84 75 ); 85 76 } else { 86 77 handlers.Add ( 78 "/static/", 79 new StaticHandler ( 87 80 "/static/", 88 new StaticHandler ( 89 "/static/", 90 dataFolder, 91 new AllocsFixes.FileCache.DirectAccess (), 92 false) 81 dataFolder, 82 new DirectAccess (), 83 false) 93 84 ); 94 85 } … … 118 109 connectionHandler = new ConnectionHandler (this); 119 110 120 _listener.Prefixes.Add ( String.Format ("http://*:{0}/", webPort + 2));111 _listener.Prefixes.Add (string.Format ("http://*:{0}/", webPort + 2)); 121 112 _listener.Start (); 122 113 123 114 SdtdConsole.Instance.RegisterServer (this); 124 115 125 _listener.BeginGetContext ( new AsyncCallback (HandleRequest), _listener);116 _listener.BeginGetContext (HandleRequest, _listener); 126 117 127 118 Log.Out ("Started Webserver on " + (webPort + 2)); … … 129 120 Log.Out ("Error in Web.ctor: " + e); 130 121 } 122 } 123 124 public void Disconnect () { 125 try { 126 _listener.Stop (); 127 _listener.Close (); 128 } catch (Exception e) { 129 Log.Out ("Error in Web.Disconnect: " + e); 130 } 131 } 132 133 public void SendLine (string line) { 134 connectionHandler.SendLine (line); 135 } 136 137 public void SendLog (string text, string trace, LogType type) { 138 // Do nothing, handled by LogBuffer internally 139 } 140 141 public static bool isSslRedirected (HttpListenerRequest req) { 142 string proto = req.Headers ["X-Forwarded-Proto"]; 143 if (!string.IsNullOrEmpty (proto)) { 144 return proto.Equals ("https", StringComparison.OrdinalIgnoreCase); 145 } 146 147 return false; 131 148 } 132 149 … … 135 152 Interlocked.Increment (ref handlingCount); 136 153 Interlocked.Increment (ref currentHandlers); 154 137 155 // MicroStopwatch msw = new MicroStopwatch (); 138 156 HttpListenerContext ctx = _listener.EndGetContext (result); 139 _listener.BeginGetContext ( new AsyncCallback (HandleRequest), _listener);157 _listener.BeginGetContext (HandleRequest, _listener); 140 158 try { 141 159 HttpListenerRequest request = ctx.Request; … … 163 181 // No game yet -> fail request 164 182 if (GameManager.Instance.World == null) { 165 response.StatusCode = (int) HttpStatusCode.ServiceUnavailable;183 response.StatusCode = (int) HttpStatusCode.ServiceUnavailable; 166 184 return; 167 185 } … … 174 192 if (request.Url.AbsolutePath.StartsWith (kvp.Key)) { 175 193 if (!kvp.Value.IsAuthorizedForHandler (conn, permissionLevel)) { 176 response.StatusCode = (int) HttpStatusCode.Forbidden;194 response.StatusCode = (int) HttpStatusCode.Forbidden; 177 195 if (conn != null) { 178 196 //Log.Out ("Web.HandleRequest: user '{0}' not allowed to access '{1}'", conn.SteamID, kvp.Value.ModuleName); 179 } else {180 //Log.Out ("Web.HandleRequest: unidentified user from '{0}' not allowed to access '{1}'", request.RemoteEndPoint.Address, kvp.Value.ModuleName);181 197 } 182 198 } else { 183 199 kvp.Value.HandleRequest (request, response, conn, permissionLevel); 184 200 } 201 185 202 return; 186 203 } … … 190 207 // Not really relevant for non-debugging purposes: 191 208 //Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + request.Url.AbsolutePath + "\""); 192 response.StatusCode = (int) HttpStatusCode.NotFound;209 response.StatusCode = (int) HttpStatusCode.NotFound; 193 210 } catch (IOException e) { 194 211 if (e.InnerException is SocketException) { 195 Log.Out ("Error in Web.HandleRequest(): Remote host closed connection: " + e.InnerException.Message); 212 Log.Out ("Error in Web.HandleRequest(): Remote host closed connection: " + 213 e.InnerException.Message); 196 214 } else { 197 215 Log.Out ("Error (IO) in Web.HandleRequest(): " + e); … … 203 221 ctx.Response.Close (); 204 222 } 223 205 224 // msw.Stop (); 206 225 // totalHandlingTime += msw.ElapsedMicroseconds; … … 223 242 if (con != null) { 224 243 _con = con; 225 return GameManager.Instance.adminTools.GetAdminToolsClientInfo (_con.SteamID.ToString ()).PermissionLevel; 244 return GameManager.Instance.adminTools.GetAdminToolsClientInfo (_con.SteamID.ToString ()) 245 .PermissionLevel; 226 246 } 227 247 } 228 248 229 249 if (_req.QueryString ["adminuser"] != null && _req.QueryString ["admintoken"] != null) { 230 WebPermissions.AdminToken admin = WebPermissions.Instance.GetWebAdmin (_req.QueryString ["adminuser"], _req.QueryString ["admintoken"]); 250 WebPermissions.AdminToken admin = WebPermissions.Instance.GetWebAdmin (_req.QueryString ["adminuser"], 251 _req.QueryString ["admintoken"]); 231 252 if (admin != null) { 232 253 return admin.permissionLevel; 233 } else {234 Log.Warning ("Invalid Admintoken used from " + _req.RemoteEndPoint.ToString ()); 235 }254 } 255 256 Log.Warning ("Invalid Admintoken used from " + _req.RemoteEndPoint); 236 257 } 237 258 … … 242 263 WebConnection con = connectionHandler.LogIn (id, _req.RemoteEndPoint.Address.ToString ()); 243 264 _con = con; 244 int level = GameManager.Instance.adminTools.GetAdminToolsClientInfo (id.ToString ()).PermissionLevel; 245 Log.Out ("Steam OpenID login from {0} with ID {1}, permission level {2}", _req.RemoteEndPoint.ToString (), con.SteamID, level); 265 int level = GameManager.Instance.adminTools.GetAdminToolsClientInfo (id.ToString ()) 266 .PermissionLevel; 267 Log.Out ("Steam OpenID login from {0} with ID {1}, permission level {2}", 268 _req.RemoteEndPoint.ToString (), con.SteamID, level); 246 269 return level; 247 } else {248 Log.Out ("Steam OpenID login failed from {0}", _req.RemoteEndPoint.ToString ()); 249 }270 } 271 272 Log.Out ("Steam OpenID login failed from {0}", _req.RemoteEndPoint.ToString ()); 250 273 } catch (Exception e) { 251 274 Log.Error ("Error validating login:"); … … 255 278 256 279 return GUEST_PERMISSION_LEVEL; 257 }258 259 public void Disconnect () {260 try {261 _listener.Stop ();262 _listener.Close ();263 } catch (Exception e) {264 Log.Out ("Error in Web.Disconnect: " + e);265 }266 }267 268 public void SendLine (string line) {269 connectionHandler.SendLine (line);270 }271 272 public void SendLog (string text, string trace, UnityEngine.LogType type) {273 // Do nothing, handled by LogBuffer internally274 280 } 275 281 … … 281 287 resp.OutputStream.Write (buf, 0, buf.Length); 282 288 } 283 284 289 } 285 290 } -
binary-improvements/MapRendering/Web/WebCommandResult.cs
r309 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO; 3 4 using System.Net; 5 using System.Net.Sockets; 4 6 using System.Text; 7 using System.Threading; 8 using AllocsFixes.JSON; 9 using AllocsFixes.NetConnections.Servers.Web.API; 10 using UnityEngine; 5 11 6 using AllocsFixes.JSON; 7 using System.IO; 8 using System.Net.Sockets; 9 using System.Threading; 10 using AllocsFixes.NetConnections.Servers.Web.API; 11 12 namespace AllocsFixes.NetConnections.Servers.Web 13 { 14 public class WebCommandResult : IConsoleConnection 15 { 12 namespace AllocsFixes.NetConnections.Servers.Web { 13 public class WebCommandResult : IConsoleConnection { 16 14 public enum ResultType { 17 15 Full, … … 20 18 } 21 19 22 public static int handlingCount = 0; 23 public static int currentHandlers = 0; 24 public static long totalHandlingTime = 0; 20 public static int handlingCount; 21 public static int currentHandlers; 22 public static long totalHandlingTime; 23 private readonly string command; 24 private readonly string parameters; 25 25 26 private HttpListenerResponse response; 27 private string command; 28 private string parameters; 29 private ResultType responseType; 26 private readonly HttpListenerResponse response; 27 private readonly ResultType responseType; 30 28 31 public WebCommandResult (string _command, string _parameters, ResultType _responseType, HttpListenerResponse _response) { 29 public WebCommandResult (string _command, string _parameters, ResultType _responseType, 30 HttpListenerResponse _response) { 32 31 Interlocked.Increment (ref handlingCount); 33 32 Interlocked.Increment (ref currentHandlers); … … 65 64 result = resultObj; 66 65 } 66 67 67 WebAPI.WriteJSON (response, result); 68 68 } 69 69 } catch (IOException e) { 70 70 if (e.InnerException is SocketException) { 71 Log.Out ("Error in WebCommandResult.SendLines(): Remote host closed connection: " + e.InnerException.Message); 71 Log.Out ("Error in WebCommandResult.SendLines(): Remote host closed connection: " + 72 e.InnerException.Message); 72 73 } else { 73 74 Log.Out ("Error (IO) in WebCommandResult.SendLines(): " + e); … … 85 86 Log.Out ("WebCommandResult.SendLines(): Took {0} µs", msw.ElapsedMicroseconds); 86 87 } 88 87 89 Interlocked.Decrement (ref currentHandlers); 88 90 } … … 93 95 } 94 96 95 public void SendLog (string _msg, string _trace, UnityEngine.LogType _type) {97 public void SendLog (string _msg, string _trace, LogType _type) { 96 98 //throw new NotImplementedException (); 97 99 } 98 100 99 public void EnableLogLevel ( UnityEngine.LogType _type, bool _enable) {101 public void EnableLogLevel (LogType _type, bool _enable) { 100 102 //throw new NotImplementedException (); 101 103 } … … 106 108 } 107 109 } 108 -
binary-improvements/MapRendering/Web/WebConnection.cs
r253 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using AllocsFixes.NetConnections.Servers.Web;4 3 using UnityEngine; 5 4 6 namespace AllocsFixes.NetConnections.Servers.Web 7 { 5 namespace AllocsFixes.NetConnections.Servers.Web { 8 6 public class WebConnection : ConsoleConnectionAbstract { 9 private string sessionId; 10 private string endpoint; 11 private ulong steamId; 12 private DateTime login; 7 private readonly DateTime login; 8 private readonly List<string> outputLines = new List<string> (); 13 9 private DateTime lastAction; 14 private List<string> outputLines = new List<string> ();10 private readonly string conDescription; 15 11 16 public string SessionID { 17 get { return sessionId; } 12 public WebConnection (string _sessionId, string _endpoint, ulong _steamId) { 13 SessionID = _sessionId; 14 Endpoint = _endpoint; 15 SteamID = _steamId; 16 login = DateTime.Now; 17 lastAction = login; 18 conDescription = "WebPanel from " + Endpoint; 18 19 } 19 20 20 public string Endpoint { 21 get { return endpoint; } 22 } 21 public string SessionID { get; private set; } 23 22 24 public ulong SteamID {25 get { return steamId; } 26 }23 public string Endpoint { get; private set; } 24 25 public ulong SteamID { get; private set; } 27 26 28 27 public TimeSpan Age { … … 30 29 } 31 30 32 33 31 public static bool CanViewAllPlayers (int _permissionLevel) { 32 bool val = false; 34 33 35 36 34 try { 35 const int defaultPermissionLevel = 0; 37 36 38 37 val = _permissionLevel <= defaultPermissionLevel; 39 38 40 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) 41 if (wap.module.Trim ().ToLower () == "webapi.viewallplayers") 42 val = _permissionLevel <= wap.permissionLevel; 43 } 44 catch { } 39 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) { 40 if (wap.module.Trim ().ToLower () == "webapi.viewallplayers") { 41 val = _permissionLevel <= wap.permissionLevel; 42 } 43 } 44 } catch { 45 } 45 46 46 47 47 return val; 48 } 48 49 49 50 50 public static bool CanViewAllClaims (int _permissionLevel) { 51 bool val = false; 51 52 52 53 53 try { 54 const int defaultPermissionLevel = 0; 54 55 55 56 val = _permissionLevel <= defaultPermissionLevel; 56 57 57 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) 58 if (wap.module.Trim ().ToLower () == "webapi.viewallclaims") 59 val = _permissionLevel <= wap.permissionLevel; 60 } 61 catch { } 58 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) { 59 if (wap.module.Trim ().ToLower () == "webapi.viewallclaims") { 60 val = _permissionLevel <= wap.permissionLevel; 61 } 62 } 63 } catch { 64 } 62 65 63 return val; 64 } 65 66 public WebConnection (string _sessionId, string _endpoint, ulong _steamId) { 67 this.sessionId = _sessionId; 68 this.endpoint = _endpoint; 69 this.steamId = _steamId; 70 this.login = DateTime.Now; 71 this.lastAction = this.login; 66 return val; 72 67 } 73 68 74 69 public void UpdateUsage () { 75 this.lastAction = DateTime.Now;70 lastAction = DateTime.Now; 76 71 } 77 72 78 73 public override string GetDescription () { 79 return "WebPanel from " + endpoint;74 return conDescription; 80 75 } 81 76 … … 91 86 // Do nothing, handled by LogBuffer 92 87 } 93 94 88 } 95 89 } 96 -
binary-improvements/MapRendering/Web/WebPermissions.cs
r279 r325 1 using System;2 1 using System.Collections.Generic; 3 2 using System.IO; 4 3 using System.Xml; 5 4 6 namespace AllocsFixes.NetConnections.Servers.Web 7 { 5 namespace AllocsFixes.NetConnections.Servers.Web { 8 6 public class WebPermissions { 9 private static WebPermissions instance = null;10 11 public static WebPermissions Instance {12 get {13 lock (typeof(WebPermissions)) {14 if (instance == null) {15 instance = new WebPermissions ();16 }17 return instance;18 }19 }20 }21 22 7 private const string PERMISSIONS_FILE = "webpermissions.xml"; 23 Dictionary<string, AdminToken> admintokens; 24 Dictionary<string, WebModulePermission> modules; 25 Dictionary<string, WebModulePermission> knownModules = new Dictionary<string, WebModulePermission> (); 26 WebModulePermission defaultModulePermission = new WebModulePermission ("", 0); 27 FileSystemWatcher fileWatcher; 8 private static WebPermissions instance; 9 private readonly WebModulePermission defaultModulePermission = new WebModulePermission ("", 0); 10 11 private readonly Dictionary<string, WebModulePermission> knownModules = 12 new Dictionary<string, WebModulePermission> (); 13 14 private Dictionary<string, AdminToken> admintokens; 15 private FileSystemWatcher fileWatcher; 16 17 private Dictionary<string, WebModulePermission> modules; 28 18 29 19 public WebPermissions () { … … 33 23 } 34 24 25 public static WebPermissions Instance { 26 get { 27 lock (typeof (WebPermissions)) { 28 if (instance == null) { 29 instance = new WebPermissions (); 30 } 31 32 return instance; 33 } 34 } 35 } 36 35 37 public bool ModuleAllowedWithLevel (string _module, int _level) { 36 38 WebModulePermission permInfo = GetModulePermission (_module); … … 41 43 if (IsAdmin (_name) && admintokens [_name].token == _token) { 42 44 return admintokens [_name]; 43 } else {44 return null; 45 }45 } 46 47 return null; 46 48 } 47 49 … … 50 52 return modules [_module.ToLower ()]; 51 53 } 54 52 55 return defaultModulePermission; 53 56 } … … 83 86 return result; 84 87 } 85 88 86 89 87 90 // Commands … … 99 102 if (!string.IsNullOrEmpty (_module)) { 100 103 lock (this) { 101 if (!IsKnownModule(_module)) {104 if (!IsKnownModule (_module)) { 102 105 knownModules.Add (_module, new WebModulePermission (_module, _defaultPermission)); 103 } 106 } 107 104 108 if (_defaultPermission > 0 && !modules.ContainsKey (_module.ToLower ())) { 105 109 AddModulePermission (_module, _defaultPermission); … … 114 118 return knownModules.ContainsKey (_module); 115 119 } 116 } else {117 return false; 118 }119 } 120 120 } 121 122 return false; 123 } 124 121 125 public void RemoveModulePermission (string _module, bool _save = true) { 122 126 lock (this) { … … 140 144 return result; 141 145 } 142 146 143 147 144 148 //IO Tasks … … 146 150 private void InitFileWatcher () { 147 151 fileWatcher = new FileSystemWatcher (GetFilePath (), GetFileName ()); 148 fileWatcher.Changed += new FileSystemEventHandler (OnFileChanged);149 fileWatcher.Created += new FileSystemEventHandler (OnFileChanged);150 fileWatcher.Deleted += new FileSystemEventHandler (OnFileChanged);152 fileWatcher.Changed += OnFileChanged; 153 fileWatcher.Created += OnFileChanged; 154 fileWatcher.Deleted += OnFileChanged; 151 155 fileWatcher.EnableRaisingEvents = true; 152 156 } … … 198 202 continue; 199 203 } 204 200 205 if (subChild.NodeType != XmlNodeType.Element) { 201 206 Log.Warning ("Unexpected XML node found in 'admintokens' section: " + subChild.OuterXml); … … 203 208 } 204 209 205 XmlElement lineItem = (XmlElement) subChild;210 XmlElement lineItem = (XmlElement) subChild; 206 211 207 212 if (!lineItem.HasAttribute ("name")) { 208 Log.Warning ("Ignoring admintoken-entry because of missing 'name' attribute: " + subChild.OuterXml); 213 Log.Warning ("Ignoring admintoken-entry because of missing 'name' attribute: " + 214 subChild.OuterXml); 209 215 continue; 210 216 } 211 217 212 218 if (!lineItem.HasAttribute ("token")) { 213 Log.Warning ("Ignoring admintoken-entry because of missing 'token' attribute: " + subChild.OuterXml); 219 Log.Warning ("Ignoring admintoken-entry because of missing 'token' attribute: " + 220 subChild.OuterXml); 214 221 continue; 215 222 } 216 223 217 224 if (!lineItem.HasAttribute ("permission_level")) { 218 Log.Warning ("Ignoring admintoken-entry because of missing 'permission_level' attribute: " + subChild.OuterXml); 225 Log.Warning ("Ignoring admintoken-entry because of missing 'permission_level' attribute: " + 226 subChild.OuterXml); 219 227 continue; 220 228 } … … 224 232 int permissionLevel = 2000; 225 233 if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) { 226 Log.Warning ("Ignoring admintoken-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + subChild.OuterXml); 227 continue; 228 } 229 230 AddAdmin (name, token, permissionLevel, false); 231 234 Log.Warning ( 235 "Ignoring admintoken-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + 236 subChild.OuterXml); 237 continue; 238 } 239 240 AddAdmin (name, token, permissionLevel, false); 232 241 } 233 242 } … … 238 247 continue; 239 248 } 249 240 250 if (subChild.NodeType != XmlNodeType.Element) { 241 251 Log.Warning ("Unexpected XML node found in 'permissions' section: " + subChild.OuterXml); … … 243 253 } 244 254 245 XmlElement lineItem = (XmlElement) subChild;255 XmlElement lineItem = (XmlElement) subChild; 246 256 247 257 if (!lineItem.HasAttribute ("module")) { 248 Log.Warning ("Ignoring permission-entry because of missing 'module' attribute: " + subChild.OuterXml); 249 continue; 250 } 251 258 Log.Warning ("Ignoring permission-entry because of missing 'module' attribute: " + 259 subChild.OuterXml); 260 continue; 261 } 262 252 263 if (!lineItem.HasAttribute ("permission_level")) { 253 Log.Warning ("Ignoring permission-entry because of missing 'permission_level' attribute: " + subChild.OuterXml); 254 continue; 255 } 256 264 Log.Warning ("Ignoring permission-entry because of missing 'permission_level' attribute: " + 265 subChild.OuterXml); 266 continue; 267 } 268 257 269 int permissionLevel = 0; 258 270 if (!int.TryParse (lineItem.GetAttribute ("permission_level"), out permissionLevel)) { 259 Log.Warning ("Ignoring permission-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + subChild.OuterXml); 260 continue; 261 } 262 263 AddModulePermission (lineItem.GetAttribute ("module").ToLower (), permissionLevel, false); 264 } 265 } 266 271 Log.Warning ( 272 "Ignoring permission-entry because of invalid (non-numeric) value for 'permission_level' attribute: " + 273 subChild.OuterXml); 274 continue; 275 } 276 277 AddModulePermission (lineItem.GetAttribute ("module").ToLower (), permissionLevel, false); 278 } 279 } 267 280 } 268 281 … … 273 286 fileWatcher.EnableRaisingEvents = false; 274 287 275 using (StreamWriter sw = new StreamWriter(GetFullPath ())) { 276 sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 277 sw.WriteLine ("<webpermissions>"); 278 sw.WriteLine (); 279 sw.WriteLine (" <admintokens>"); 280 sw.WriteLine (" <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 281 foreach (AdminToken at in admintokens.Values) { 282 sw.WriteLine (string.Format (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token, at.permissionLevel)); 283 } 284 sw.WriteLine (" </admintokens>"); 285 sw.WriteLine (); 286 sw.WriteLine (" <permissions>"); 287 foreach (WebModulePermission wap in modules.Values) { 288 sw.WriteLine (string.Format (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module, wap.permissionLevel)); 289 } 290 sw.WriteLine (" <!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->"); 291 sw.WriteLine (); 292 sw.WriteLine (" <!-- <permission module=\"webapi.getlog\" permission_level=\"0\" /> -->"); 293 sw.WriteLine (" <!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->"); 294 sw.WriteLine (); 295 sw.WriteLine (" <!-- <permission module=\"webapi.getstats\" permission_level=\"1000\" /> -->"); 296 sw.WriteLine (" <!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1000\" /> -->"); 297 sw.WriteLine (); 298 sw.WriteLine (" <!-- <permission module=\"webapi.getplayerslocation\" permission_level=\"1000\" /> -->"); 299 sw.WriteLine (" <!-- <permission module=\"webapi.viewallplayers\" permission_level=\"1\" /> -->"); 300 sw.WriteLine (); 301 sw.WriteLine (" <!-- <permission module=\"webapi.getlandclaims\" permission_level=\"1000\" /> -->"); 302 sw.WriteLine (" <!-- <permission module=\"webapi.viewallclaims\" permission_level=\"1\" /> -->"); 303 sw.WriteLine (); 304 sw.WriteLine (" <!-- <permission module=\"webapi.getplayerinventory\" permission_level=\"1\" /> -->"); 305 sw.WriteLine (); 306 sw.WriteLine (" <!-- <permission module=\"webapi.gethostilelocation\" permission_level=\"1\" /> -->"); 307 sw.WriteLine (" <!-- <permission module=\"webapi.getanimalslocation\" permission_level=\"1\" /> -->"); 308 sw.WriteLine (" </permissions>"); 309 sw.WriteLine (); 310 sw.WriteLine ("</webpermissions>"); 288 using (StreamWriter sw = new StreamWriter (GetFullPath ())) { 289 sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 290 sw.WriteLine ("<webpermissions>"); 291 sw.WriteLine (); 292 sw.WriteLine (" <admintokens>"); 293 sw.WriteLine ( 294 " <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 295 foreach (AdminToken at in admintokens.Values) { 296 sw.WriteLine (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token, 297 at.permissionLevel); 298 } 299 300 sw.WriteLine (" </admintokens>"); 301 sw.WriteLine (); 302 sw.WriteLine (" <permissions>"); 303 foreach (WebModulePermission wap in modules.Values) { 304 sw.WriteLine (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module, 305 wap.permissionLevel); 306 } 307 308 sw.WriteLine (" <!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->"); 309 sw.WriteLine (); 310 sw.WriteLine (" <!-- <permission module=\"webapi.getlog\" permission_level=\"0\" /> -->"); 311 sw.WriteLine ( 312 " <!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->"); 313 sw.WriteLine (); 314 sw.WriteLine (" <!-- <permission module=\"webapi.getstats\" permission_level=\"1000\" /> -->"); 315 sw.WriteLine (" <!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1000\" /> -->"); 316 sw.WriteLine (); 317 sw.WriteLine ( 318 " <!-- <permission module=\"webapi.getplayerslocation\" permission_level=\"1000\" /> -->"); 319 sw.WriteLine (" <!-- <permission module=\"webapi.viewallplayers\" permission_level=\"1\" /> -->"); 320 sw.WriteLine (); 321 sw.WriteLine (" <!-- <permission module=\"webapi.getlandclaims\" permission_level=\"1000\" /> -->"); 322 sw.WriteLine (" <!-- <permission module=\"webapi.viewallclaims\" permission_level=\"1\" /> -->"); 323 sw.WriteLine (); 324 sw.WriteLine (" <!-- <permission module=\"webapi.getplayerinventory\" permission_level=\"1\" /> -->"); 325 sw.WriteLine (); 326 sw.WriteLine (" <!-- <permission module=\"webapi.gethostilelocation\" permission_level=\"1\" /> -->"); 327 sw.WriteLine (" <!-- <permission module=\"webapi.getanimalslocation\" permission_level=\"1\" /> -->"); 328 sw.WriteLine (" </permissions>"); 329 sw.WriteLine (); 330 sw.WriteLine ("</webpermissions>"); 311 331 312 332 sw.Flush (); … … 318 338 319 339 320 321 340 public class AdminToken { 322 341 public string name; 342 public int permissionLevel; 323 343 public string token; 324 public int permissionLevel;325 344 326 345 public AdminToken (string _name, string _token, int _permissionLevel) { … … 340 359 } 341 360 } 342 343 344 361 } 345 362 } 346
Note:
See TracChangeset
for help on using the changeset viewer.