diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/CoreModules/Avatar/BakedTextures | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/BakedTextures')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | 200 |
1 files changed, 200 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..414f06a --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | |||
@@ -0,0 +1,200 @@ | |||
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 | |||
28 | using OpenMetaverse; | ||
29 | using Nini.Config; | ||
30 | using System; | ||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using System.Xml; | ||
34 | using System.Xml.Serialization; | ||
35 | using System.Collections; | ||
36 | using System.Collections.Generic; | ||
37 | using System.Reflection; | ||
38 | using log4net; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.ServiceAuth; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Services.Interfaces; | ||
44 | using Mono.Addins; | ||
45 | |||
46 | namespace 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 | private static IServiceAuth m_Auth; | ||
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 | m_Auth = ServiceAuth.Create(configSource, "XBakes"); | ||
67 | } | ||
68 | |||
69 | public void AddRegion(Scene scene) | ||
70 | { | ||
71 | // m_log.InfoFormat("[XBakes]: Enabled for region {0}", scene.RegionInfo.RegionName); | ||
72 | m_Scene = scene; | ||
73 | |||
74 | scene.RegisterModuleInterface<IBakedTextureModule>(this); | ||
75 | } | ||
76 | |||
77 | public void RegionLoaded(Scene scene) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | } | ||
84 | |||
85 | public void Close() | ||
86 | { | ||
87 | } | ||
88 | |||
89 | public string Name | ||
90 | { | ||
91 | get { return "XBakes.Module"; } | ||
92 | } | ||
93 | |||
94 | public Type ReplaceableInterface | ||
95 | { | ||
96 | get { return null; } | ||
97 | } | ||
98 | |||
99 | public WearableCacheItem[] Get(UUID id) | ||
100 | { | ||
101 | if (m_URL == String.Empty) | ||
102 | return null; | ||
103 | |||
104 | int size = 0; | ||
105 | |||
106 | using (RestClient rc = new RestClient(m_URL)) | ||
107 | { | ||
108 | List<WearableCacheItem> ret = new List<WearableCacheItem>(); | ||
109 | rc.AddResourcePath("bakes"); | ||
110 | rc.AddResourcePath(id.ToString()); | ||
111 | |||
112 | rc.RequestMethod = "GET"; | ||
113 | |||
114 | try | ||
115 | { | ||
116 | Stream s = rc.Request(m_Auth); | ||
117 | |||
118 | using (XmlTextReader sr = new XmlTextReader(s)) | ||
119 | { | ||
120 | sr.ReadStartElement("BakedAppearance"); | ||
121 | while (sr.LocalName == "BakedTexture") | ||
122 | { | ||
123 | string sTextureIndex = sr.GetAttribute("TextureIndex"); | ||
124 | int lTextureIndex = Convert.ToInt32(sTextureIndex); | ||
125 | string sCacheId = sr.GetAttribute("CacheId"); | ||
126 | UUID lCacheId = UUID.Zero; | ||
127 | if (!(UUID.TryParse(sCacheId, out lCacheId))) | ||
128 | { | ||
129 | // ?? Nothing here | ||
130 | } | ||
131 | |||
132 | ++size; | ||
133 | |||
134 | sr.ReadStartElement("BakedTexture"); | ||
135 | AssetBase a = (AssetBase)m_serializer.Deserialize(sr); | ||
136 | ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID }); | ||
137 | |||
138 | sr.ReadEndElement(); | ||
139 | } | ||
140 | |||
141 | m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); | ||
142 | } | ||
143 | |||
144 | return ret.ToArray(); | ||
145 | } | ||
146 | catch (XmlException) | ||
147 | { | ||
148 | return null; | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | public void Store(UUID agentId, WearableCacheItem[] data) | ||
154 | { | ||
155 | if (m_URL == String.Empty) | ||
156 | return; | ||
157 | |||
158 | MemoryStream reqStream; | ||
159 | |||
160 | using (MemoryStream bakeStream = new MemoryStream()) | ||
161 | using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null)) | ||
162 | { | ||
163 | bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); | ||
164 | |||
165 | for (int i = 0; i < data.Length; i++) | ||
166 | { | ||
167 | if (data[i] != null) | ||
168 | { | ||
169 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); | ||
170 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); | ||
171 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); | ||
172 | if (data[i].TextureAsset != null) | ||
173 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); | ||
174 | |||
175 | bakeWriter.WriteEndElement(); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | bakeWriter.WriteEndElement(); | ||
180 | bakeWriter.Flush(); | ||
181 | |||
182 | reqStream = new MemoryStream(bakeStream.ToArray()); | ||
183 | } | ||
184 | |||
185 | RestClient rc = new RestClient(m_URL); | ||
186 | rc.AddResourcePath("bakes"); | ||
187 | rc.AddResourcePath(agentId.ToString()); | ||
188 | |||
189 | rc.RequestMethod = "POST"; | ||
190 | |||
191 | Util.FireAndForget( | ||
192 | delegate | ||
193 | { | ||
194 | rc.Request(reqStream, m_Auth); | ||
195 | m_log.DebugFormat("[XBakes]: stored {0} textures for user {1}", data.Length, agentId); | ||
196 | }, null, "XBakesModule.Store" | ||
197 | ); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||