mirror of
https://github.com/opensim/opensim.git
synced 2026-08-11 11:57:03 +08:00
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.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
@@ -618,6 +619,47 @@ namespace OpenSim.Framework
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static string Compress(string text)
|
||||
{
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(text);
|
||||
MemoryStream memory = new MemoryStream();
|
||||
using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
|
||||
{
|
||||
compressor.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
memory.Position = 0;
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
|
||||
byte[] compressed = new byte[memory.Length];
|
||||
memory.Read(compressed, 0, compressed.Length);
|
||||
|
||||
byte[] compressedBuffer = new byte[compressed.Length + 4];
|
||||
System.Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
|
||||
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
|
||||
return Convert.ToBase64String(compressedBuffer);
|
||||
}
|
||||
|
||||
public static string Decompress(string compressedText)
|
||||
{
|
||||
byte[] compressedBuffer = Convert.FromBase64String(compressedText);
|
||||
using (MemoryStream memory = new MemoryStream())
|
||||
{
|
||||
int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
|
||||
memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
|
||||
|
||||
byte[] buffer = new byte[msgLength];
|
||||
|
||||
memory.Position = 0;
|
||||
using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
|
||||
{
|
||||
decompressor.Read(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] ParseStartLocationRequest(string startLocationRequest)
|
||||
{
|
||||
string[] returnstring = new string[4];
|
||||
|
||||
Reference in New Issue
Block a user