aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMelanie2014-02-04 02:09:39 +0000
committerMelanie2014-02-04 02:09:39 +0000
commit11976582339d068a6e8eb793166199a532b78b88 (patch)
treea6e219070b244ad66c52f5bbfe96ee08768b1e7b /OpenSim/Region
parentMerge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff)
downloadopensim-SC_OLD-11976582339d068a6e8eb793166199a532b78b88.zip
opensim-SC_OLD-11976582339d068a6e8eb793166199a532b78b88.tar.gz
opensim-SC_OLD-11976582339d068a6e8eb793166199a532b78b88.tar.bz2
opensim-SC_OLD-11976582339d068a6e8eb793166199a532b78b88.tar.xz
Adding the Avination XBakesModule, the client for the persistent bakes system
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs189
1 files changed, 189 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs
new file mode 100644
index 0000000..6ef5e39
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs
@@ -0,0 +1,189 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29using Nini.Config;
30using System;
31using System.IO;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35using System.Collections;
36using System.Collections.Generic;
37using System.Reflection;
38using log4net;
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Services.Interfaces;
44using Mono.Addins;
45
46namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
47{
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XBakes.Module")]
49 public class XBakesModule : INonSharedRegionModule, IBakedTextureModule
50 {
51 protected Scene m_Scene;
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private UTF8Encoding enc = new UTF8Encoding();
54 private string m_URL = String.Empty;
55 private static XmlSerializer m_serializer = new XmlSerializer(typeof(AssetBase));
56
57
58
59 public void Initialise(IConfigSource configSource)
60 {
61 IConfig config = configSource.Configs["XBakes"];
62 if (config == null)
63 return;
64
65 m_URL = config.GetString("URL", String.Empty);
66 }
67
68 public void AddRegion(Scene scene)
69 {
70 // m_log.InfoFormat("[XBakes]: Enabled for region {0}", scene.RegionInfo.RegionName);
71 m_Scene = scene;
72
73 scene.RegisterModuleInterface<IBakedTextureModule>(this);
74 }
75
76 public void RegionLoaded(Scene scene)
77 {
78 }
79
80 public void RemoveRegion(Scene scene)
81 {
82 }
83
84 public void Close()
85 {
86 }
87
88 public string Name
89 {
90 get { return "XBakes.Module"; }
91 }
92
93 public Type ReplaceableInterface
94 {
95 get { return null; }
96 }
97
98 public WearableCacheItem[] Get(UUID id)
99 {
100 if (m_URL == String.Empty)
101 return null;
102
103 int size = 0;
104 RestClient rc = new RestClient(m_URL);
105 List<WearableCacheItem> ret = new List<WearableCacheItem>();
106 rc.AddResourcePath("bakes");
107 rc.AddResourcePath(id.ToString());
108
109 rc.RequestMethod = "GET";
110
111 try
112 {
113 Stream s = rc.Request();
114 XmlTextReader sr = new XmlTextReader(s);
115
116 sr.ReadStartElement("BakedAppearance");
117 while (sr.LocalName == "BakedTexture")
118 {
119 string sTextureIndex = sr.GetAttribute("TextureIndex");
120 int lTextureIndex = Convert.ToInt32(sTextureIndex);
121 string sCacheId = sr.GetAttribute("CacheId");
122 UUID lCacheId = UUID.Zero;
123 if (!(UUID.TryParse(sCacheId, out lCacheId)))
124 {
125 // ?? Nothing here
126 }
127
128 ++size;
129
130 sr.ReadStartElement("BakedTexture");
131 AssetBase a = (AssetBase)m_serializer.Deserialize(sr);
132 ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID });
133
134 sr.ReadEndElement();
135 }
136 m_log.DebugFormat("[XBakes]: Ended reading");
137 sr.Close();
138 s.Close();
139
140
141 return ret.ToArray();
142 }
143 catch (XmlException e)
144 {
145 return null;
146 }
147 }
148
149 public void Store(UUID agentId, WearableCacheItem[] data)
150 {
151 MemoryStream bakeStream = new MemoryStream();
152 XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null);
153
154 bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty);
155
156 for (int i = 0; i < data.Length; i++)
157 {
158 if (data[i] != null)
159 {
160 bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty);
161 bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString());
162 bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString());
163 if (data[i].TextureAsset != null)
164 m_serializer.Serialize(bakeWriter, data[i].TextureAsset);
165
166 bakeWriter.WriteEndElement();
167 }
168 }
169
170 bakeWriter.WriteEndElement();
171 bakeWriter.Flush();
172
173 RestClient rc = new RestClient(m_URL);
174 rc.AddResourcePath("bakes");
175 rc.AddResourcePath(agentId.ToString());
176
177 rc.RequestMethod = "POST";
178
179 MemoryStream reqStream = new MemoryStream(bakeStream.ToArray());
180 Util.FireAndForget(
181 delegate
182 {
183 rc.Request(reqStream);
184 }
185 );
186 }
187
188 }
189}