opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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.Communications; |
||
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 | |||
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 | if (m_URL == String.Empty) |
||
152 | return; |
||
153 | |||
154 | MemoryStream bakeStream = new MemoryStream(); |
||
155 | XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null); |
||
156 | |||
157 | bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty); |
||
158 | |||
159 | for (int i = 0; i < data.Length; i++) |
||
160 | { |
||
161 | if (data[i] != null) |
||
162 | { |
||
163 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); |
||
164 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); |
||
165 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); |
||
166 | if (data[i].TextureAsset != null) |
||
167 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); |
||
168 | |||
169 | bakeWriter.WriteEndElement(); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | bakeWriter.WriteEndElement(); |
||
174 | bakeWriter.Flush(); |
||
175 | |||
176 | RestClient rc = new RestClient(m_URL); |
||
177 | rc.AddResourcePath("bakes"); |
||
178 | rc.AddResourcePath(agentId.ToString()); |
||
179 | |||
180 | rc.RequestMethod = "POST"; |
||
181 | |||
182 | MemoryStream reqStream = new MemoryStream(bakeStream.ToArray()); |
||
183 | Util.FireAndForget( |
||
184 | delegate |
||
185 | { |
||
186 | rc.Request(reqStream); |
||
187 | } |
||
188 | ); |
||
189 | } |
||
190 | } |
||
191 | } |