aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMW2008-06-25 19:33:19 +0000
committerMW2008-06-25 19:33:19 +0000
commit7a9922af27658ac570517df530dd7c2cf6d6dded (patch)
treef086664feaf6e917184b929bfc111e901f4359bc
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 '')
-rw-r--r--OpenSim/Framework/Util.cs42
-rw-r--r--OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs75
-rw-r--r--OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs4
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs5
7 files changed, 127 insertions, 5 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];
diff --git a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
index 0db1294..952ca0a 100644
--- a/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
+++ b/OpenSim/Region/Environment/Interfaces/ITerrainChannel.cs
@@ -36,5 +36,7 @@ namespace OpenSim.Region.Environment.Interfaces
36 double[,] GetDoubles(); 36 double[,] GetDoubles();
37 bool Tainted(int x, int y); 37 bool Tainted(int x, int y);
38 ITerrainChannel MakeCopy(); 38 ITerrainChannel MakeCopy();
39 string SaveToXmlString();
40 void LoadFromXmlString(string data);
39 } 41 }
40} 42}
diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
index b22ca79..0944406 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
@@ -523,7 +523,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
523 { 523 {
524 if (upd.AgentOnline) 524 if (upd.AgentOnline)
525 { 525 {
526 RegionInfo reginfo = m_scenes[0].CommsManager.GridService.RequestNeighbourInfo(upd.Handle); 526 RegionInfo reginfo = m_scenes[0].SceneGridService.RequestNeighbouringRegionInfo(upd.Handle);
527 if (reginfo != null) 527 if (reginfo != null)
528 { 528 {
529 GridInstantMessage msg = new GridInstantMessage(); 529 GridInstantMessage msg = new GridInstantMessage();
diff --git a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs
index eccaa78..a851cad 100644
--- a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs
@@ -950,8 +950,6 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions
950 950
951 return true; 951 return true;
952 } 952 }
953
954
955 } 953 }
956 954
957} 955}
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
index 1399960..53d03fc 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
@@ -27,6 +27,11 @@
27 27
28using OpenSim.Framework; 28using OpenSim.Framework;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30using System;
31using System.Text;
32using System.Xml;
33using System.IO;
34using System.Xml.Serialization;
30 35
31namespace OpenSim.Region.Environment.Modules.World.Terrain 36namespace OpenSim.Region.Environment.Modules.World.Terrain
32{ 37{
@@ -151,5 +156,75 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
151 156
152 return copy; 157 return copy;
153 } 158 }
159
160 public string SaveToXmlString()
161 {
162 XmlWriterSettings settings = new XmlWriterSettings();
163 settings.Encoding = Encoding.UTF8;
164 using (StringWriter sw = new StringWriter())
165 {
166 using (XmlWriter writer = XmlWriter.Create(sw, settings))
167 {
168 WriteXml(writer);
169 }
170 string output = sw.ToString();
171 return output;
172 }
173 }
174
175 private void WriteXml(XmlWriter writer)
176 {
177 writer.WriteStartElement(String.Empty, "TerrainMap", String.Empty);
178 ToXml(writer);
179 writer.WriteEndElement();
180 }
181
182 public void LoadFromXmlString(string data)
183 {
184 StringReader sr = new StringReader(data);
185 XmlTextReader reader = new XmlTextReader(sr);
186 reader.Read();
187
188 ReadXml(reader);
189 reader.Close();
190 sr.Close();
191 }
192
193 private void ReadXml(XmlReader reader)
194 {
195 reader.ReadStartElement("TerrainMap");
196 FromXml(reader);
197 }
198
199 private void ToXml(XmlWriter xmlWriter)
200 {
201 float[] mapData = GetFloatsSerialised();
202 byte[] buffer = new byte[mapData.Length * 4];
203 for (int i = 0; i < mapData.Length; i++)
204 {
205 byte[] value = BitConverter.GetBytes(mapData[i]);
206 Array.Copy(value, 0, buffer, (i * 4), 4);
207 }
208 XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
209 serializer.Serialize(xmlWriter, buffer);
210 }
211
212 private void FromXml(XmlReader xmlReader)
213 {
214 XmlSerializer serializer = new XmlSerializer(typeof(byte[]));
215 byte[] dataArray = (byte[])serializer.Deserialize(xmlReader);
216 int index = 0;
217
218 for (int y = 0; y < Height; y++)
219 {
220 for (int x = 0; x < Width; x++)
221 {
222 float value;
223 value = BitConverter.ToSingle(dataArray, index);
224 index += 4;
225 this[x, y] = (double)value;
226 }
227 }
228 }
154 } 229 }
155} \ No newline at end of file 230} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs
index c8d2ef6..5287517 100644
--- a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs
@@ -166,7 +166,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
166 { 166 {
167 List<MapBlockData> mapBlocks; 167 List<MapBlockData> mapBlocks;
168 168
169 mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks((int)m_scene.RegionInfo.RegionLocX - 8, (int)m_scene.RegionInfo.RegionLocY - 8, (int)m_scene.RegionInfo.RegionLocX + 8, (int)m_scene.RegionInfo.RegionLocY + 8); 169 mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks((int)m_scene.RegionInfo.RegionLocX - 8, (int)m_scene.RegionInfo.RegionLocY - 8, (int)m_scene.RegionInfo.RegionLocX + 8, (int)m_scene.RegionInfo.RegionLocY + 8);
170 avatarPresence.ControllingClient.SendMapBlock(mapBlocks); 170 avatarPresence.ControllingClient.SendMapBlock(mapBlocks);
171 171
172 lock (cachedMapBlocks) 172 lock (cachedMapBlocks)
@@ -244,7 +244,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
244 public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) 244 public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
245 { 245 {
246 List<MapBlockData> mapBlocks; 246 List<MapBlockData> mapBlocks;
247 mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4); 247 mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4);
248 remoteClient.SendMapBlock(mapBlocks); 248 remoteClient.SendMapBlock(mapBlocks);
249 } 249 }
250 public Hashtable OnHTTPGetMapImage(Hashtable keysvals) 250 public Hashtable OnHTTPGetMapImage(Hashtable keysvals)
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index bbef28f..c7de419 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -101,6 +101,11 @@ namespace OpenSim.Region.Environment.Scenes
101 101
102 protected SceneCommunicationService m_sceneGridService; 102 protected SceneCommunicationService m_sceneGridService;
103 103
104 public SceneCommunicationService SceneGridService
105 {
106 get { return m_sceneGridService; }
107 }
108
104 /// <summary> 109 /// <summary>
105 /// Each agent has its own capabilities handler. 110 /// Each agent has its own capabilities handler.
106 /// </summary> 111 /// </summary>