aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorMW2008-06-25 19:33:19 +0000
committerMW2008-06-25 19:33:19 +0000
commit7a9922af27658ac570517df530dd7c2cf6d6dded (patch)
treef086664feaf6e917184b929bfc111e901f4359bc /OpenSim/Framework/Util.cs
parentmake lots of properties virtual, which lets nhibernate do (diff)
downloadopensim-SC-7a9922af27658ac570517df530dd7c2cf6d6dded.zip
opensim-SC-7a9922af27658ac570517df530dd7c2cf6d6dded.tar.gz
opensim-SC-7a9922af27658ac570517df530dd7c2cf6d6dded.tar.bz2
opensim-SC-7a9922af27658ac570517df530dd7c2cf6d6dded.tar.xz
Added support for terrain map to be serialised to xml(as base64 binary). useful for places that the terrain map is needed in a serialised form. Also could add console commands to save and load from files, which should be faster than .raw files (these load/save commands are not included/implemented)
Add util functions to compress and uncompress strings. Fixed a couple of modules so they use SceneCommunicationService rather than directly call functions on the CommsManager.
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 719dda6..a835cec 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Data; 29using System.Data;
30using System.IO; 30using System.IO;
31using System.IO.Compression;
31using System.Net; 32using System.Net;
32using System.Net.Sockets; 33using System.Net.Sockets;
33using System.Reflection; 34using System.Reflection;
@@ -618,6 +619,47 @@ namespace OpenSim.Framework
618 return ret; 619 return ret;
619 } 620 }
620 621
622 public static string Compress(string text)
623 {
624 byte[] buffer = Encoding.UTF8.GetBytes(text);
625 MemoryStream memory = new MemoryStream();
626 using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
627 {
628 compressor.Write(buffer, 0, buffer.Length);
629 }
630
631 memory.Position = 0;
632 MemoryStream outStream = new MemoryStream();
633
634 byte[] compressed = new byte[memory.Length];
635 memory.Read(compressed, 0, compressed.Length);
636
637 byte[] compressedBuffer = new byte[compressed.Length + 4];
638 System.Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
639 System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
640 return Convert.ToBase64String(compressedBuffer);
641 }
642
643 public static string Decompress(string compressedText)
644 {
645 byte[] compressedBuffer = Convert.FromBase64String(compressedText);
646 using (MemoryStream memory = new MemoryStream())
647 {
648 int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
649 memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
650
651 byte[] buffer = new byte[msgLength];
652
653 memory.Position = 0;
654 using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
655 {
656 decompressor.Read(buffer, 0, buffer.Length);
657 }
658
659 return Encoding.UTF8.GetString(buffer);
660 }
661 }
662
621 public static string[] ParseStartLocationRequest(string startLocationRequest) 663 public static string[] ParseStartLocationRequest(string startLocationRequest)
622 { 664 {
623 string[] returnstring = new string[4]; 665 string[] returnstring = new string[4];