diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | |
parent | Add a build script. (diff) | |
download | opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs index 414f06a..61e461a 100644 --- a/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs | |||
@@ -53,6 +53,7 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
53 | private UTF8Encoding enc = new UTF8Encoding(); | 53 | private UTF8Encoding enc = new UTF8Encoding(); |
54 | private string m_URL = String.Empty; | 54 | private string m_URL = String.Empty; |
55 | private static XmlSerializer m_serializer = new XmlSerializer(typeof(AssetBase)); | 55 | private static XmlSerializer m_serializer = new XmlSerializer(typeof(AssetBase)); |
56 | private static bool m_enabled = false; | ||
56 | 57 | ||
57 | private static IServiceAuth m_Auth; | 58 | private static IServiceAuth m_Auth; |
58 | 59 | ||
@@ -63,11 +64,19 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
63 | return; | 64 | return; |
64 | 65 | ||
65 | m_URL = config.GetString("URL", String.Empty); | 66 | m_URL = config.GetString("URL", String.Empty); |
67 | if (m_URL == String.Empty) | ||
68 | return; | ||
69 | |||
70 | m_enabled = true; | ||
71 | |||
66 | m_Auth = ServiceAuth.Create(configSource, "XBakes"); | 72 | m_Auth = ServiceAuth.Create(configSource, "XBakes"); |
67 | } | 73 | } |
68 | 74 | ||
69 | public void AddRegion(Scene scene) | 75 | public void AddRegion(Scene scene) |
70 | { | 76 | { |
77 | if (!m_enabled) | ||
78 | return; | ||
79 | |||
71 | // m_log.InfoFormat("[XBakes]: Enabled for region {0}", scene.RegionInfo.RegionName); | 80 | // m_log.InfoFormat("[XBakes]: Enabled for region {0}", scene.RegionInfo.RegionName); |
72 | m_Scene = scene; | 81 | m_Scene = scene; |
73 | 82 | ||
@@ -101,8 +110,6 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
101 | if (m_URL == String.Empty) | 110 | if (m_URL == String.Empty) |
102 | return null; | 111 | return null; |
103 | 112 | ||
104 | int size = 0; | ||
105 | |||
106 | using (RestClient rc = new RestClient(m_URL)) | 113 | using (RestClient rc = new RestClient(m_URL)) |
107 | { | 114 | { |
108 | List<WearableCacheItem> ret = new List<WearableCacheItem>(); | 115 | List<WearableCacheItem> ret = new List<WearableCacheItem>(); |
@@ -113,35 +120,42 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
113 | 120 | ||
114 | try | 121 | try |
115 | { | 122 | { |
116 | Stream s = rc.Request(m_Auth); | 123 | using(Stream s = rc.Request(m_Auth)) |
117 | |||
118 | using (XmlTextReader sr = new XmlTextReader(s)) | ||
119 | { | 124 | { |
120 | sr.ReadStartElement("BakedAppearance"); | 125 | using(XmlTextReader sr = new XmlTextReader(s)) |
121 | while (sr.LocalName == "BakedTexture") | ||
122 | { | 126 | { |
123 | string sTextureIndex = sr.GetAttribute("TextureIndex"); | 127 | sr.ProhibitDtd = true; |
124 | int lTextureIndex = Convert.ToInt32(sTextureIndex); | 128 | |
125 | string sCacheId = sr.GetAttribute("CacheId"); | 129 | sr.ReadStartElement("BakedAppearance"); |
126 | UUID lCacheId = UUID.Zero; | 130 | while(sr.LocalName == "BakedTexture") |
127 | if (!(UUID.TryParse(sCacheId, out lCacheId))) | ||
128 | { | 131 | { |
132 | string sTextureIndex = sr.GetAttribute("TextureIndex"); | ||
133 | int lTextureIndex = Convert.ToInt32(sTextureIndex); | ||
134 | string sCacheId = sr.GetAttribute("CacheId"); | ||
135 | UUID lCacheId = UUID.Zero; | ||
136 | if(!(UUID.TryParse(sCacheId,out lCacheId))) | ||
137 | { | ||
129 | // ?? Nothing here | 138 | // ?? Nothing here |
139 | } | ||
140 | |||
141 | sr.ReadStartElement("BakedTexture"); | ||
142 | if(sr.Name=="AssetBase") | ||
143 | { | ||
144 | AssetBase a = (AssetBase)m_serializer.Deserialize(sr); | ||
145 | ret.Add(new WearableCacheItem() | ||
146 | { | ||
147 | CacheId = lCacheId, | ||
148 | TextureIndex = (uint)lTextureIndex, | ||
149 | TextureAsset = a, | ||
150 | TextureID = a.FullID | ||
151 | }); | ||
152 | sr.ReadEndElement(); | ||
153 | } | ||
130 | } | 154 | } |
131 | 155 | m_log.DebugFormat("[XBakes]: read {0} textures for user {1}",ret.Count,id); | |
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 | } | 156 | } |
140 | 157 | return ret.ToArray(); | |
141 | m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id); | ||
142 | } | 158 | } |
143 | |||
144 | return ret.ToArray(); | ||
145 | } | 159 | } |
146 | catch (XmlException) | 160 | catch (XmlException) |
147 | { | 161 | { |
@@ -150,11 +164,20 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
150 | } | 164 | } |
151 | } | 165 | } |
152 | 166 | ||
167 | public void Store(UUID agentId) | ||
168 | { | ||
169 | } | ||
170 | |||
171 | public void UpdateMeshAvatar(UUID agentId) | ||
172 | { | ||
173 | } | ||
174 | |||
153 | public void Store(UUID agentId, WearableCacheItem[] data) | 175 | public void Store(UUID agentId, WearableCacheItem[] data) |
154 | { | 176 | { |
155 | if (m_URL == String.Empty) | 177 | if (m_URL == String.Empty) |
156 | return; | 178 | return; |
157 | 179 | ||
180 | int numberWears = 0; | ||
158 | MemoryStream reqStream; | 181 | MemoryStream reqStream; |
159 | 182 | ||
160 | using (MemoryStream bakeStream = new MemoryStream()) | 183 | using (MemoryStream bakeStream = new MemoryStream()) |
@@ -164,15 +187,16 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
164 | 187 | ||
165 | for (int i = 0; i < data.Length; i++) | 188 | for (int i = 0; i < data.Length; i++) |
166 | { | 189 | { |
167 | if (data[i] != null) | 190 | if (data[i] != null && data[i].TextureAsset != null) |
168 | { | 191 | { |
169 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); | 192 | bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty); |
170 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); | 193 | bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString()); |
171 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); | 194 | bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString()); |
172 | if (data[i].TextureAsset != null) | 195 | // if (data[i].TextureAsset != null) |
173 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); | 196 | m_serializer.Serialize(bakeWriter, data[i].TextureAsset); |
174 | 197 | ||
175 | bakeWriter.WriteEndElement(); | 198 | bakeWriter.WriteEndElement(); |
199 | numberWears++; | ||
176 | } | 200 | } |
177 | } | 201 | } |
178 | 202 | ||
@@ -182,19 +206,22 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures | |||
182 | reqStream = new MemoryStream(bakeStream.ToArray()); | 206 | reqStream = new MemoryStream(bakeStream.ToArray()); |
183 | } | 207 | } |
184 | 208 | ||
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( | 209 | Util.FireAndForget( |
192 | delegate | 210 | delegate |
193 | { | 211 | { |
194 | rc.Request(reqStream, m_Auth); | 212 | using(RestClient rc = new RestClient(m_URL)) |
195 | m_log.DebugFormat("[XBakes]: stored {0} textures for user {1}", data.Length, agentId); | 213 | { |
214 | rc.AddResourcePath("bakes"); | ||
215 | rc.AddResourcePath(agentId.ToString()); | ||
216 | rc.RequestMethod = "POST"; | ||
217 | |||
218 | rc.Request(reqStream, m_Auth); | ||
219 | m_log.DebugFormat("[XBakes]: stored {0} textures for user {1}", numberWears, agentId); | ||
220 | } | ||
221 | if(reqStream != null) | ||
222 | reqStream.Dispose(); | ||
196 | }, null, "XBakesModule.Store" | 223 | }, null, "XBakesModule.Store" |
197 | ); | 224 | ); |
198 | } | 225 | } |
199 | } | 226 | } |
200 | } \ No newline at end of file | 227 | } |