Changeset 332
- Timestamp:
- Nov 16, 2018, 10:38:46 PM (6 years ago)
- Location:
- binary-improvements
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r327 r332 6 6 [Serializable] 7 7 public class Players { 8 p rivate readonly Dictionary<string, Player> players= new Dictionary<string, Player> (StringComparer.OrdinalIgnoreCase);8 public readonly Dictionary<string, Player> Dict = new Dictionary<string, Player> (StringComparer.OrdinalIgnoreCase); 9 9 10 10 public Player this [string steamId, bool create] { … … 14 14 } 15 15 16 if ( players.ContainsKey (steamId)) {17 return players[steamId];16 if (Dict.ContainsKey (steamId)) { 17 return Dict [steamId]; 18 18 } 19 19 … … 24 24 Log.Out ("Created new player entry for ID: " + steamId); 25 25 Player p = new Player (steamId); 26 players.Add (steamId, p);26 Dict.Add (steamId, p); 27 27 return p; 28 28 } 29 29 } 30 30 31 public List<string> SteamIDs {32 get { return new List<string> (players.Keys); }33 }34 35 31 public int Count { 36 get { return players.Count; }32 get { return Dict.Count; } 37 33 } 38 34 … … 58 54 int entityId; 59 55 if (int.TryParse (_nameOrId, out entityId)) { 60 foreach (KeyValuePair<string, Player> kvp in players) {56 foreach (KeyValuePair<string, Player> kvp in Dict) { 61 57 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 62 58 return kvp.Key; … … 65 61 } 66 62 67 foreach (KeyValuePair<string, Player> kvp in players) {63 foreach (KeyValuePair<string, Player> kvp in Dict) { 68 64 string name = kvp.Value.Name; 69 65 if (_ignoreColorCodes) { -
binary-improvements/AllocsCommands/Commands/ListKnownPlayers.cs
r326 r332 62 62 } else { 63 63 int num = 0; 64 foreach ( string sid in PersistentContainer.Instance.Players.SteamIDs) {65 Player p = PersistentContainer.Instance.Players [sid, false];64 foreach (KeyValuePair<string, Player> kvp in PersistentContainer.Instance.Players.Dict) { 65 Player p = kvp.Value; 66 66 67 67 if ( 68 68 (!onlineOnly || p.IsOnline) 69 && (!notBannedOnly || !admTools.IsBanned ( sid))69 && (!notBannedOnly || !admTools.IsBanned (kvp.Key)) 70 70 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter)) 71 71 ) { 72 72 SdtdConsole.Instance.Output (string.Format ( 73 73 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}", 74 ++num, p.Name, p.EntityID, sid, p.IsOnline, p.IP,74 ++num, p.Name, p.EntityID, kvp.Key, p.IsOnline, p.IP, 75 75 p.TotalPlayTime / 60, 76 76 p.LastOnline.ToString ("yyyy-MM-dd HH:mm")) -
binary-improvements/MapRendering/MapRendering/MapRenderBlockBuffer.cs
r331 r332 17 17 private Vector2i currentBlockMapPos = new Vector2i (Int32.MinValue, Int32.MinValue); 18 18 private string currentBlockMapFolder = string.Empty; 19 private string currentBlockMapFilename = string.Empty;20 19 21 20 public MapRenderBlockBuffer (int level, MapTileCache cache) { … … 46 45 public void ResetBlock () { 47 46 currentBlockMapFolder = string.Empty; 48 currentBlockMapFilename = string.Empty;49 47 currentBlockMapPos = new Vector2i (Int32.MinValue, Int32.MinValue); 50 48 } … … 84 82 currentBlockMapFolder = folder; 85 83 currentBlockMapPos = block; 86 currentBlockMapFilename = fileName;87 84 88 85 Profiler.EndSample (); -
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r326 r332 21 21 22 22 // default user, cheap way to avoid 'null reference exception' 23 user = user ?? new WebConnection ("", "", 0L);23 user = user ?? new WebConnection ("", IPAddress.None, 0L); 24 24 25 25 bool bViewAll = WebConnection.CanViewAllClaims (permissionLevel); -
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r325 r332 1 using System.Collections.Generic; 1 2 using System.Net; 2 3 using AllocsFixes.JSON; … … 9 10 JSONArray AllInventoriesResult = new JSONArray (); 10 11 11 foreach ( string sid in PersistentContainer.Instance.Players.SteamIDs) {12 Player p = PersistentContainer.Instance.Players [sid, false];12 foreach (KeyValuePair<string, Player> kvp in PersistentContainer.Instance.Players.Dict) { 13 Player p = kvp.Value; 13 14 14 15 if (p == null) { … … 23 24 JSONArray belt = new JSONArray (); 24 25 JSONObject equipment = new JSONObject (); 25 result.Add ("steamid", new JSONString ( sid));26 result.Add ("steamid", new JSONString (kvp.Key)); 26 27 result.Add ("entityid", new JSONNumber (p.EntityID)); 27 28 result.Add ("playername", new JSONString (p.Name)); -
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r326 r332 6 6 using AllocsFixes.JSON; 7 7 using AllocsFixes.PersistentData; 8 using UnityEngine.Profiling; 8 9 9 10 namespace AllocsFixes.NetConnections.Servers.Web.API { … … 12 13 new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); 13 14 15 #if ENABLE_PROFILER 16 private static readonly CustomSampler jsonSerializeSampler = CustomSampler.Create ("JSON_Build"); 17 #endif 18 14 19 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 15 20 int permissionLevel) { 16 21 AdminTools admTools = GameManager.Instance.adminTools; 17 user = user ?? new WebConnection ("", "", 0L);22 user = user ?? new WebConnection ("", IPAddress.None, 0L); 18 23 19 24 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); … … 35 40 Players playersList = PersistentContainer.Instance.Players; 36 41 42 37 43 List<JSONObject> playerList = new List<JSONObject> (); 38 44 39 foreach (string sid in playersList.SteamIDs) { 40 Player p = playersList [sid, false]; 45 #if ENABLE_PROFILER 46 jsonSerializeSampler.Begin (); 47 #endif 48 49 foreach (KeyValuePair<string, Player> kvp in playersList.Dict) { 50 Player p = kvp.Value; 41 51 42 52 ulong player_steam_ID; 43 if (!ulong.TryParse ( sid, out player_steam_ID)) {53 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 44 54 player_steam_ID = 0L; 45 55 } … … 52 62 53 63 JSONObject pJson = new JSONObject (); 54 pJson.Add ("steamid", new JSONString ( sid));64 pJson.Add ("steamid", new JSONString (kvp.Key)); 55 65 pJson.Add ("entityid", new JSONNumber (p.EntityID)); 56 66 pJson.Add ("ip", new JSONString (p.IP)); … … 66 76 JSONBoolean banned; 67 77 if (admTools != null) { 68 banned = new JSONBoolean (admTools.IsBanned ( sid));78 banned = new JSONBoolean (admTools.IsBanned (kvp.Key)); 69 79 } else { 70 80 banned = new JSONBoolean (false); … … 76 86 } 77 87 } 88 89 #if ENABLE_PROFILER 90 jsonSerializeSampler.End (); 91 #endif 78 92 79 93 IEnumerable<JSONObject> list = playerList; -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r326 r332 1 using System.Collections.Generic; 1 2 using System.Net; 2 3 using AllocsFixes.JSON; … … 8 9 int permissionLevel) { 9 10 AdminTools admTools = GameManager.Instance.adminTools; 10 user = user ?? new WebConnection ("", "", 0L);11 user = user ?? new WebConnection ("", IPAddress.None, 0L); 11 12 12 13 bool listOffline = false; … … 21 22 Players playersList = PersistentContainer.Instance.Players; 22 23 23 foreach ( string sid in playersList.SteamIDs) {24 foreach (KeyValuePair<string, Player> kvp in playersList.Dict) { 24 25 if (admTools != null) { 25 if (admTools.IsBanned ( sid)) {26 if (admTools.IsBanned (kvp.Key)) { 26 27 continue; 27 28 } 28 29 } 29 30 30 Player p = playersList [sid, false];31 Player p = kvp.Value; 31 32 32 33 if (listOffline || p.IsOnline) { 33 34 ulong player_steam_ID; 34 if (!ulong.TryParse ( sid, out player_steam_ID)) {35 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 35 36 player_steam_ID = 0L; 36 37 } … … 43 44 44 45 JSONObject pJson = new JSONObject (); 45 pJson.Add ("steamid", new JSONString ( sid));46 pJson.Add ("steamid", new JSONString (kvp.Key)); 46 47 47 48 // pJson.Add("entityid", new JSONNumber (p.EntityID)); -
binary-improvements/MapRendering/Web/API/WebAPI.cs
r326 r332 2 2 using System.Text; 3 3 using AllocsFixes.JSON; 4 using UnityEngine.Profiling; 4 5 5 6 namespace AllocsFixes.NetConnections.Servers.Web.API { … … 11 12 } 12 13 14 #if ENABLE_PROFILER 15 private static readonly CustomSampler jsonSerializeSampler = CustomSampler.Create ("JSON_Serialize"); 16 private static readonly CustomSampler netWriteSampler = CustomSampler.Create ("JSON_Write"); 17 #endif 18 13 19 public static void WriteJSON (HttpListenerResponse resp, JSONNode root) { 20 #if ENABLE_PROFILER 21 jsonSerializeSampler.Begin (); 22 #endif 14 23 StringBuilder sb = new StringBuilder (); 15 24 root.ToString (sb); 25 #if ENABLE_PROFILER 26 jsonSerializeSampler.End (); 27 netWriteSampler.Begin (); 28 #endif 16 29 byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ()); 17 30 resp.ContentLength64 = buf.Length; … … 19 32 resp.ContentEncoding = Encoding.UTF8; 20 33 resp.OutputStream.Write (buf, 0, buf.Length); 34 #if ENABLE_PROFILER 35 netWriteSampler.End (); 36 #endif 21 37 } 22 38 -
binary-improvements/MapRendering/Web/ConnectionHandler.cs
r326 r332 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Net; 3 4 4 5 namespace AllocsFixes.NetConnections.Servers.Web { … … 6 7 private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> (); 7 8 8 public WebConnection IsLoggedIn (string _sessionId, string _endpoint) {9 public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) { 9 10 if (!connections.ContainsKey (_sessionId)) { 10 11 return null; … … 18 19 // } 19 20 20 if (con.Endpoint != _endpoint) { 21 connections.Remove (_sessionId); 21 if (!Equals (con.Endpoint, _ip)) { 22 // Fixed: Allow different clients from same NAT network 23 // connections.Remove (_sessionId); 22 24 return null; 23 25 } … … 32 34 } 33 35 34 public WebConnection LogIn (ulong _steamId, string _endpoint) {36 public WebConnection LogIn (ulong _steamId, IPAddress _ip) { 35 37 string sessionId = Guid.NewGuid ().ToString (); 36 WebConnection con = new WebConnection (sessionId, _ endpoint, _steamId);38 WebConnection con = new WebConnection (sessionId, _ip, _steamId); 37 39 connections.Add (sessionId, con); 38 40 return con; … … 40 42 41 43 public void SendLine (string line) { 42 foreach ( WebConnection wc in connections.Values) {43 wc.SendLine (line);44 foreach (KeyValuePair<string, WebConnection> kvp in connections) { 45 kvp.Value.SendLine (line); 44 46 } 45 47 } -
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r326 r332 4 4 using System.Reflection; 5 5 using AllocsFixes.NetConnections.Servers.Web.API; 6 using UnityEngine.Profiling; 6 7 7 8 namespace AllocsFixes.NetConnections.Servers.Web.Handlers { … … 40 41 } 41 42 43 #if ENABLE_PROFILER 44 private static readonly CustomSampler apiHandlerSampler = CustomSampler.Create ("API_Handler"); 45 #endif 46 42 47 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 43 48 int permissionLevel) { … … 55 60 if (apis.TryGetValue (apiName, out api)) { 56 61 try { 62 #if ENABLE_PROFILER 63 apiHandlerSampler.Begin (); 64 #endif 57 65 api.HandleRequest (req, resp, user, permissionLevel); 66 #if ENABLE_PROFILER 67 apiHandlerSampler.End (); 68 #endif 58 69 return; 59 70 } catch (Exception e) { -
binary-improvements/MapRendering/Web/Handlers/StaticHandler.cs
r325 r332 13 13 string moduleName = null) : base (moduleName) { 14 14 this.staticPart = staticPart; 15 datapath = filePath ;15 datapath = filePath + (filePath [filePath.Length - 1] == '/' ? "" : "/"); 16 16 this.cache = cache; 17 17 this.logMissingFiles = logMissingFiles; … … 22 22 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 23 23 24 byte[] content = cache.GetFileContent (datapath + "/" +fn);24 byte[] content = cache.GetFileContent (datapath + fn); 25 25 26 26 if (content != null) { … … 31 31 resp.StatusCode = (int) HttpStatusCode.NotFound; 32 32 if (logMissingFiles) { 33 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + 34 req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 33 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + fn + "\""); 35 34 } 36 35 } -
binary-improvements/MapRendering/Web/Handlers/UserStatusHandler.cs
r325 r332 19 19 JSONObject permObj = new JSONObject (); 20 20 permObj.Add ("module", new JSONString (perm.module)); 21 permObj.Add ("allowed", 22 new JSONBoolean (WebPermissions.Instance.ModuleAllowedWithLevel (perm.module, permissionLevel))); 21 permObj.Add ("allowed", new JSONBoolean (perm.permissionLevel >= permissionLevel)); 23 22 perms.Add (permObj); 24 23 } -
binary-improvements/MapRendering/Web/MimeType.cs
r325 r332 5 5 public class MimeType { 6 6 private static readonly IDictionary<string, string> _mappings = 7 new Dictionary<string, string> (StringComparer.InvariantCultureIgnoreCase){7 new CaseInsensitiveStringDictionary<string> { 8 8 {".323", "text/h323"}, 9 9 {".3g2", "video/3gpp2"}, -
binary-improvements/MapRendering/Web/Web.cs
r326 r332 10 10 using AllocsFixes.NetConnections.Servers.Web.Handlers; 11 11 using UnityEngine; 12 using UnityEngine.Profiling; 12 13 13 14 namespace AllocsFixes.NetConnections.Servers.Web { … … 19 20 private readonly HttpListener _listener = new HttpListener (); 20 21 private readonly string dataFolder; 21 private readonly Dictionary<string, PathHandler> handlers = new Dictionary<string,PathHandler> ();22 private readonly Dictionary<string, PathHandler> handlers = new CaseInsensitiveStringDictionary<PathHandler> (); 22 23 private readonly bool useStaticCache; 23 24 … … 147 148 return false; 148 149 } 150 151 private readonly Version HttpProtocolVersion = new Version(1, 1); 152 153 #if ENABLE_PROFILER 154 private readonly CustomSampler authSampler = CustomSampler.Create ("Auth"); 155 private readonly CustomSampler handlerSampler = CustomSampler.Create ("Handler"); 156 #endif 149 157 150 158 private void HandleRequest (IAsyncResult result) { … … 157 165 158 166 // MicroStopwatch msw = new MicroStopwatch (); 167 #if ENABLE_PROFILER 168 Profiler.BeginThreadProfiling ("AllocsMods", "WebRequest"); 169 HttpListenerContext ctx = _listener.EndGetContext (result); 170 try { 171 #else 159 172 HttpListenerContext ctx = _listener.EndGetContext (result); 160 173 _listener.BeginGetContext (HandleRequest, _listener); 174 #endif 161 175 try { 162 176 HttpListenerRequest request = ctx.Request; … … 164 178 response.SendChunked = false; 165 179 166 response.ProtocolVersion = new Version ("1.1");180 response.ProtocolVersion = HttpProtocolVersion; 167 181 168 182 WebConnection conn; 183 #if ENABLE_PROFILER 184 authSampler.Begin (); 185 #endif 169 186 int permissionLevel = DoAuthentication (request, out conn); 187 #if ENABLE_PROFILER 188 authSampler.End (); 189 #endif 170 190 171 191 … … 200 220 } 201 221 } else { 222 #if ENABLE_PROFILER 223 handlerSampler.Begin (); 224 #endif 202 225 kvp.Value.HandleRequest (request, response, conn, permissionLevel); 226 #if ENABLE_PROFILER 227 handlerSampler.End (); 228 #endif 203 229 } 204 230 … … 230 256 Interlocked.Decrement (ref currentHandlers); 231 257 } 258 #if ENABLE_PROFILER 259 } finally { 260 _listener.BeginGetContext (HandleRequest, _listener); 261 Profiler.EndThreadProfiling (); 262 } 263 #endif 232 264 } 233 265 … … 241 273 242 274 if (!string.IsNullOrEmpty (sessionId)) { 243 WebConnection con = connectionHandler.IsLoggedIn (sessionId, _req.RemoteEndPoint.Address .ToString ());275 WebConnection con = connectionHandler.IsLoggedIn (sessionId, _req.RemoteEndPoint.Address); 244 276 if (con != null) { 245 277 _con = con; … … 259 291 } 260 292 261 if (_req.Url.AbsolutePath.StartsWith ("/session/verify" )) {293 if (_req.Url.AbsolutePath.StartsWith ("/session/verify", StringComparison.OrdinalIgnoreCase)) { 262 294 try { 263 295 ulong id = OpenID.Validate (_req); 264 296 if (id > 0) { 265 WebConnection con = connectionHandler.LogIn (id, _req.RemoteEndPoint.Address .ToString ());297 WebConnection con = connectionHandler.LogIn (id, _req.RemoteEndPoint.Address); 266 298 _con = con; 267 299 int level = GameManager.Instance.adminTools.GetAdminToolsClientInfo (id.ToString ()) -
binary-improvements/MapRendering/Web/WebCommandResult.cs
r325 r332 39 39 40 40 public void SendLines (List<string> _output) { 41 MicroStopwatch msw = new MicroStopwatch ();41 // MicroStopwatch msw = new MicroStopwatch (); 42 42 43 43 StringBuilder sb = new StringBuilder (); … … 81 81 } 82 82 83 msw.Stop ();84 if (GamePrefs.GetInt (EnumGamePrefs.HideCommandExecutionLog) < 1) {85 totalHandlingTime += msw.ElapsedMicroseconds;86 Log.Out ("WebCommandResult.SendLines(): Took {0} µs", msw.ElapsedMicroseconds);87 }83 // msw.Stop (); 84 // if (GamePrefs.GetInt (EnumGamePrefs.HideCommandExecutionLog) < 1) { 85 // totalHandlingTime += msw.ElapsedMicroseconds; 86 // Log.Out ("WebCommandResult.SendLines(): Took {0} µs", msw.ElapsedMicroseconds); 87 // } 88 88 89 89 Interlocked.Decrement (ref currentHandlers); -
binary-improvements/MapRendering/Web/WebConnection.cs
r326 r332 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Net; 3 4 using UnityEngine; 4 5 … … 10 11 private readonly string conDescription; 11 12 12 public WebConnection (string _sessionId, string_endpoint, ulong _steamId) {13 public WebConnection (string _sessionId, IPAddress _endpoint, ulong _steamId) { 13 14 SessionID = _sessionId; 14 15 Endpoint = _endpoint; … … 21 22 public string SessionID { get; private set; } 22 23 23 public stringEndpoint { get; private set; }24 public IPAddress Endpoint { get; private set; } 24 25 25 26 public ulong SteamID { get; private set; } … … 30 31 31 32 public static bool CanViewAllPlayers (int _permissionLevel) { 32 const int defaultPermissionLevel = 0; 33 34 bool val = _permissionLevel <= defaultPermissionLevel; 35 36 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) { 37 if (wap.module.EqualsCaseInsensitive ("webapi.viewallplayers")) { 38 val = _permissionLevel <= wap.permissionLevel; 39 } 40 } 41 42 return val; 33 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi.viewallplayers", _permissionLevel); 43 34 } 44 35 45 36 public static bool CanViewAllClaims (int _permissionLevel) { 46 const int defaultPermissionLevel = 0; 47 48 bool val = _permissionLevel <= defaultPermissionLevel; 49 50 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) { 51 if (wap.module.EqualsCaseInsensitive ("webapi.viewallclaims")) { 52 val = _permissionLevel <= wap.permissionLevel; 53 } 54 } 55 56 return val; 37 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi.viewallclaims", _permissionLevel); 57 38 } 58 39 -
binary-improvements/MapRendering/Web/WebPermissions.cs
r326 r332 1 1 using System.Collections.Generic; 2 using System.Collections.ObjectModel; 2 3 using System.IO; 3 4 using System.Xml; 5 using UniLinq; 4 6 5 7 namespace AllocsFixes.NetConnections.Servers.Web { … … 10 12 11 13 private readonly Dictionary<string, WebModulePermission> knownModules = 12 new Dictionary<string,WebModulePermission> ();14 new CaseInsensitiveStringDictionary<WebModulePermission> (); 13 15 14 16 private readonly Dictionary<string, AdminToken> admintokens = new CaseInsensitiveStringDictionary<AdminToken> (); … … 18 20 19 21 public WebPermissions () { 22 allModulesList = new List<WebModulePermission> (); 23 allModulesListRO = new ReadOnlyCollection<WebModulePermission> (allModulesList); 20 24 Directory.CreateDirectory (GetFilePath ()); 21 25 InitFileWatcher (); … … 54 58 } 55 59 60 if (knownModules.TryGetValue (_module, out result)) { 61 return result; 62 } 63 56 64 return defaultModulePermission; 57 65 } … … 93 101 WebModulePermission p = new WebModulePermission (_module, _permissionLevel); 94 102 lock (this) { 103 allModulesList.Clear (); 95 104 modules [_module] = p; 96 105 if (_save) { … … 104 113 return; 105 114 } 106 107 lock (this) { 108 if (!IsKnownModule (_module)) { 109 knownModules.Add (_module, new WebModulePermission (_module, _defaultPermission)); 110 } 111 112 if (_defaultPermission > 0 && !modules.ContainsKey (_module)) { 113 AddModulePermission (_module, _defaultPermission); 114 } 115 116 WebModulePermission p = new WebModulePermission (_module, _defaultPermission); 117 118 lock (this) { 119 allModulesList.Clear (); 120 knownModules [_module] = p; 115 121 } 116 122 } … … 129 135 public void RemoveModulePermission (string _module, bool _save = true) { 130 136 lock (this) { 137 allModulesList.Clear (); 131 138 modules.Remove (_module); 132 139 if (_save) { … … 136 143 } 137 144 138 public List<WebModulePermission> GetModules () { 139 List<WebModulePermission> result = new List<WebModulePermission> (); 140 foreach (string module in knownModules.Keys) { 141 if (modules.ContainsKey (module)) { 142 result.Add (modules [module]); 143 } else { 144 result.Add (knownModules [module]); 145 } 146 } 147 148 return result; 145 private readonly List<WebModulePermission> allModulesList; 146 private readonly ReadOnlyCollection<WebModulePermission> allModulesListRO; 147 148 public IList<WebModulePermission> GetModules () { 149 if (allModulesList.Count == 0) { 150 foreach (KeyValuePair<string, WebModulePermission> kvp in knownModules) { 151 if (modules.ContainsKey (kvp.Key)) { 152 allModulesList.Add (modules [kvp.Key]); 153 } else { 154 allModulesList.Add (kvp.Value); 155 } 156 } 157 } 158 159 return allModulesListRO; 149 160 } 150 161 … … 302 313 sw.WriteLine ( 303 314 " <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 304 foreach ( AdminToken at in admintokens.Values) {305 sw.WriteLine (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token,306 at.permissionLevel);315 foreach (KeyValuePair<string, AdminToken> kvp in admintokens) { 316 sw.WriteLine (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", kvp.Value.name, 317 kvp.Value.token, kvp.Value.permissionLevel); 307 318 } 308 319 … … 310 321 sw.WriteLine (); 311 322 sw.WriteLine (" <permissions>"); 312 foreach ( WebModulePermission wap in modules.Values) {313 sw.WriteLine (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module,314 wap.permissionLevel);323 foreach (KeyValuePair<string, WebModulePermission> kvp in modules) { 324 sw.WriteLine (" <permission module=\"{0}\" permission_level=\"{1}\" />", kvp.Value.module, 325 kvp.Value.permissionLevel); 315 326 } 316 327
Note:
See TracChangeset
for help on using the changeset viewer.