aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs125
1 files changed, 5 insertions, 120 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs
index fb5239f..ac542c2 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs
@@ -27,6 +27,7 @@
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection; 29using System.Reflection;
30using System.Text;
30using log4net; 31using log4net;
31using Nini.Config; 32using Nini.Config;
32using OpenMetaverse; 33using OpenMetaverse;
@@ -43,16 +44,6 @@ using System.Security.Cryptography;
43 44
44namespace OpenSim.Region.CoreModules.Avatar.InstantMessage 45namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
45{ 46{
46 public class MuteData
47 {
48 public UUID AgentID;
49 public UUID MuteID;
50 public string MuteName;
51 public int MuteType;
52 public int MuteFlags;
53 public int Stamp;
54 }
55
56 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XMute")] 47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XMute")]
57 public class XMuteModule : ISharedRegionModule 48 public class XMuteModule : ISharedRegionModule
58 { 49 {
@@ -163,17 +154,16 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
163 } 154 }
164 else 155 else
165 { 156 {
166 List<string> mutes = new List<string>(); 157 StringBuilder sb = new StringBuilder(1024);
167 158
168 foreach (MuteData d in data) 159 foreach (MuteData d in data)
169 mutes.Add(String.Format("{0} {1} {2}|{3}", 160 sb.AppendFormat("{0} {1} {2}|{3}\n",
170 d.MuteType, 161 d.MuteType,
171 d.MuteID.ToString(), 162 d.MuteID.ToString(),
172 d.MuteName, 163 d.MuteName,
173 d.MuteFlags)); 164 d.MuteFlags);
174 165
175 Byte[] filedata = Util.UTF8.GetBytes(String.Join("\n", 166 Byte[] filedata = Util.UTF8.GetBytes(sb.ToString());
176 mutes.ToArray()) + "\n");
177 167
178 uint dataCrc = Crc32.Compute(filedata); 168 uint dataCrc = Crc32.Compute(filedata);
179 169
@@ -248,110 +238,5 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
248 } 238 }
249 } 239 }
250 } 240 }
251
252 public class Crc32 : HashAlgorithm
253 {
254 public const UInt32 DefaultPolynomial = 0xedb88320;
255 public const UInt32 DefaultSeed = 0xffffffff;
256
257 private UInt32 hash;
258 private UInt32 seed;
259 private UInt32[] table;
260 private static UInt32[] defaultTable;
261
262 public Crc32()
263 {
264 table = InitializeTable(DefaultPolynomial);
265 seed = DefaultSeed;
266 Initialize();
267 }
268
269 public Crc32(UInt32 polynomial, UInt32 seed)
270 {
271 table = InitializeTable(polynomial);
272 this.seed = seed;
273 Initialize();
274 }
275
276 public override void Initialize()
277 {
278 hash = seed;
279 }
280
281 protected override void HashCore(byte[] buffer, int start, int length)
282 {
283 hash = CalculateHash(table, hash, buffer, start, length);
284 }
285
286 protected override byte[] HashFinal()
287 {
288 byte[] hashBuffer = UInt32ToBigEndianBytes(~hash);
289 this.HashValue = hashBuffer;
290 return hashBuffer;
291 }
292
293 public override int HashSize
294 {
295 get { return 32; }
296 }
297
298 public static UInt32 Compute(byte[] buffer)
299 {
300 return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length);
301 }
302
303 public static UInt32 Compute(UInt32 seed, byte[] buffer)
304 {
305 return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length);
306 }
307
308 public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer)
309 {
310 return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length);
311 }
312
313 private static UInt32[] InitializeTable(UInt32 polynomial)
314 {
315 if (polynomial == DefaultPolynomial && defaultTable != null)
316 return defaultTable;
317
318 UInt32[] createTable = new UInt32[256];
319 for (int i = 0; i < 256; i++)
320 {
321 UInt32 entry = (UInt32)i;
322 for (int j = 0; j < 8; j++)
323 if ((entry & 1) == 1)
324 entry = (entry >> 1) ^ polynomial;
325 else
326 entry = entry >> 1;
327 createTable[i] = entry;
328 }
329
330 if (polynomial == DefaultPolynomial)
331 defaultTable = createTable;
332
333 return createTable;
334 }
335
336 private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size)
337 {
338 UInt32 crc = seed;
339 for (int i = start; i < size; i++)
340 unchecked
341 {
342 crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff];
343 }
344 return crc;
345 }
346
347 private byte[] UInt32ToBigEndianBytes(UInt32 x)
348 {
349 return new byte[] {
350 (byte)((x >> 24) & 0xff),
351 (byte)((x >> 16) & 0xff),
352 (byte)((x >> 8) & 0xff),
353 (byte)(x & 0xff) };
354 }
355 }
356} 241}
357 242