diff options
author | MW | 2008-06-25 19:33:19 +0000 |
---|---|---|
committer | MW | 2008-06-25 19:33:19 +0000 |
commit | 7a9922af27658ac570517df530dd7c2cf6d6dded (patch) | |
tree | f086664feaf6e917184b929bfc111e901f4359bc /OpenSim/Framework/Util.cs | |
parent | make lots of properties virtual, which lets nhibernate do (diff) | |
download | opensim-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.cs | 42 |
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 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Data; | 29 | using System.Data; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.IO.Compression; | ||
31 | using System.Net; | 32 | using System.Net; |
32 | using System.Net.Sockets; | 33 | using System.Net.Sockets; |
33 | using System.Reflection; | 34 | using 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]; |