aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-03-12 20:06:40 +0000
committerJustin Clark-Casey (justincc)2010-03-12 20:06:40 +0000
commit7d738156faf923f2b23aa9bd3ecb6e2cd4d9d54f (patch)
tree909a3bf1baeb83a34154b28aaa46fcfc855462bc /OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
parentFix tests broken in 88771aeed3d45e60a18aa9a810eeb37b8e5def12 (diff)
parentFixed SimianGrid.ini to use GridCommon.ini(.example) (diff)
downloadopensim-SC-7d738156faf923f2b23aa9bd3ecb6e2cd4d9d54f.zip
opensim-SC-7d738156faf923f2b23aa9bd3ecb6e2cd4d9d54f.tar.gz
opensim-SC-7d738156faf923f2b23aa9bd3ecb6e2cd4d9d54f.tar.bz2
opensim-SC-7d738156faf923f2b23aa9bd3ecb6e2cd4d9d54f.tar.xz
Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs259
1 files changed, 259 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
new file mode 100644
index 0000000..220f143
--- /dev/null
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
@@ -0,0 +1,259 @@
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 System;
29using System.Collections.Generic;
30using System.Collections.Specialized;
31using System.IO;
32using System.Net;
33using System.Reflection;
34using log4net;
35using Mono.Addins;
36using Nini.Config;
37using OpenSim.Framework;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Server.Base;
41using OpenSim.Services.Interfaces;
42using OpenMetaverse;
43using OpenMetaverse.StructuredData;
44
45namespace OpenSim.Services.Connectors.SimianGrid
46{
47 /// <summary>
48 /// Connects avatar appearance data to the SimianGrid backend
49 /// </summary>
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
51 public class SimianAvatarServiceConnector : IAvatarService, ISharedRegionModule
52 {
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56 private static string ZeroID = UUID.Zero.ToString();
57
58 private string m_serverUrl = String.Empty;
59
60 #region ISharedRegionModule
61
62 public Type ReplaceableInterface { get { return null; } }
63 public void RegionLoaded(Scene scene) { }
64 public void PostInitialise() { }
65 public void Close() { }
66
67 public SimianAvatarServiceConnector() { }
68 public string Name { get { return "SimianAvatarServiceConnector"; } }
69 public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IAvatarService>(this); }
70 public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IAvatarService>(this); }
71
72 #endregion ISharedRegionModule
73
74 public SimianAvatarServiceConnector(IConfigSource source)
75 {
76 Initialise(source);
77 }
78
79 public void Initialise(IConfigSource source)
80 {
81 IConfig gridConfig = source.Configs["AvatarService"];
82 if (gridConfig == null)
83 {
84 m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini");
85 throw new Exception("Avatar connector init error");
86 }
87
88 string serviceUrl = gridConfig.GetString("AvatarServerURI");
89 if (String.IsNullOrEmpty(serviceUrl))
90 {
91 m_log.Error("[AVATAR CONNECTOR]: No AvatarServerURI in section AvatarService");
92 throw new Exception("Avatar connector init error");
93 }
94
95 if (!serviceUrl.EndsWith("/"))
96 serviceUrl = serviceUrl + '/';
97
98 m_serverUrl = serviceUrl;
99 }
100
101 #region IAvatarService
102
103 public AvatarData GetAvatar(UUID userID)
104 {
105 NameValueCollection requestArgs = new NameValueCollection
106 {
107 { "RequestMethod", "GetUser" },
108 { "UserID", userID.ToString() }
109 };
110
111 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
112 if (response["Success"].AsBoolean())
113 {
114 OSDMap map = null;
115 try { map = OSDParser.DeserializeJson(response["LLAppearance"].AsString()) as OSDMap; }
116 catch { }
117
118 if (map != null)
119 {
120 AvatarWearable[] wearables = new AvatarWearable[13];
121 wearables[0] = new AvatarWearable(map["ShapeItem"].AsUUID(), map["ShapeAsset"].AsUUID());
122 wearables[1] = new AvatarWearable(map["SkinItem"].AsUUID(), map["SkinAsset"].AsUUID());
123 wearables[2] = new AvatarWearable(map["HairItem"].AsUUID(), map["HairAsset"].AsUUID());
124 wearables[3] = new AvatarWearable(map["EyesItem"].AsUUID(), map["EyesAsset"].AsUUID());
125 wearables[4] = new AvatarWearable(map["ShirtItem"].AsUUID(), map["ShirtAsset"].AsUUID());
126 wearables[5] = new AvatarWearable(map["PantsItem"].AsUUID(), map["PantsAsset"].AsUUID());
127 wearables[6] = new AvatarWearable(map["ShoesItem"].AsUUID(), map["ShoesAsset"].AsUUID());
128 wearables[7] = new AvatarWearable(map["SocksItem"].AsUUID(), map["SocksAsset"].AsUUID());
129 wearables[8] = new AvatarWearable(map["JacketItem"].AsUUID(), map["JacketAsset"].AsUUID());
130 wearables[9] = new AvatarWearable(map["GlovesItem"].AsUUID(), map["GlovesAsset"].AsUUID());
131 wearables[10] = new AvatarWearable(map["UndershirtItem"].AsUUID(), map["UndershirtAsset"].AsUUID());
132 wearables[11] = new AvatarWearable(map["UnderpantsItem"].AsUUID(), map["UnderpantsAsset"].AsUUID());
133 wearables[12] = new AvatarWearable(map["SkirtItem"].AsUUID(), map["SkirtAsset"].AsUUID());
134
135 AvatarAppearance appearance = new AvatarAppearance(userID);
136 appearance.Wearables = wearables;
137 appearance.AvatarHeight = (float)map["Height"].AsReal();
138
139 AvatarData avatar = new AvatarData(appearance);
140
141 // Get attachments
142 map = null;
143 try { map = OSDParser.DeserializeJson(response["LLAttachments"].AsString()) as OSDMap; }
144 catch { }
145
146 if (map != null)
147 {
148 foreach (KeyValuePair<string, OSD> kvp in map)
149 avatar.Data[kvp.Key] = kvp.Value.AsString();
150 }
151
152 return avatar;
153 }
154 else
155 {
156 m_log.Warn("[AVATAR CONNECTOR]: Failed to get user appearance for " + userID +
157 ", LLAppearance is missing or invalid");
158 return null;
159 }
160 }
161 else
162 {
163 m_log.Warn("[AVATAR CONNECTOR]: Failed to get user appearance for " + userID + ": " +
164 response["Message"].AsString());
165 }
166
167 return null;
168 }
169
170 public bool SetAvatar(UUID userID, AvatarData avatar)
171 {
172 m_log.Debug("[AVATAR CONNECTOR]: SetAvatar called for " + userID);
173
174 if (avatar.AvatarType == 1) // LLAvatar
175 {
176 AvatarAppearance appearance = avatar.ToAvatarAppearance(userID);
177
178 OSDMap map = new OSDMap();
179
180 map["Height"] = OSD.FromReal(appearance.AvatarHeight);
181
182 map["ShapeItem"] = OSD.FromUUID(appearance.BodyItem);
183 map["ShapeAsset"] = OSD.FromUUID(appearance.BodyAsset);
184 map["SkinItem"] = OSD.FromUUID(appearance.SkinItem);
185 map["SkinAsset"] = OSD.FromUUID(appearance.SkinAsset);
186 map["HairItem"] = OSD.FromUUID(appearance.HairItem);
187 map["HairAsset"] = OSD.FromUUID(appearance.HairAsset);
188 map["EyesItem"] = OSD.FromUUID(appearance.EyesItem);
189 map["EyesAsset"] = OSD.FromUUID(appearance.EyesAsset);
190 map["ShirtItem"] = OSD.FromUUID(appearance.ShirtItem);
191 map["ShirtAsset"] = OSD.FromUUID(appearance.ShirtAsset);
192 map["PantsItem"] = OSD.FromUUID(appearance.PantsItem);
193 map["PantsAsset"] = OSD.FromUUID(appearance.PantsAsset);
194 map["ShoesItem"] = OSD.FromUUID(appearance.ShoesItem);
195 map["ShoesAsset"] = OSD.FromUUID(appearance.ShoesAsset);
196 map["SocksItem"] = OSD.FromUUID(appearance.SocksItem);
197 map["SocksAsset"] = OSD.FromUUID(appearance.SocksAsset);
198 map["JacketItem"] = OSD.FromUUID(appearance.JacketItem);
199 map["JacketAsset"] = OSD.FromUUID(appearance.JacketAsset);
200 map["GlovesItem"] = OSD.FromUUID(appearance.GlovesItem);
201 map["GlovesAsset"] = OSD.FromUUID(appearance.GlovesAsset);
202 map["UndershirtItem"] = OSD.FromUUID(appearance.UnderShirtItem);
203 map["UndershirtAsset"] = OSD.FromUUID(appearance.UnderShirtAsset);
204 map["UnderpantsItem"] = OSD.FromUUID(appearance.UnderPantsItem);
205 map["UnderpantsAsset"] = OSD.FromUUID(appearance.UnderPantsAsset);
206 map["SkirtItem"] = OSD.FromUUID(appearance.SkirtItem);
207 map["SkirtAsset"] = OSD.FromUUID(appearance.SkirtAsset);
208
209 OSDMap items = new OSDMap();
210 foreach (KeyValuePair<string, string> kvp in avatar.Data)
211 {
212 if (kvp.Key.StartsWith("_ap_"))
213 items.Add(kvp.Key, OSD.FromString(kvp.Value));
214 }
215
216 NameValueCollection requestArgs = new NameValueCollection
217 {
218 { "RequestMethod", "AddUserData" },
219 { "UserID", userID.ToString() },
220 { "LLAppearance", OSDParser.SerializeJsonString(map) },
221 { "LLAttachments", OSDParser.SerializeJsonString(items) }
222 };
223
224 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
225 bool success = response["Success"].AsBoolean();
226
227 if (!success)
228 m_log.Warn("[AVATAR CONNECTOR]: Failed saving appearance for " + userID + ": " + response["Message"].AsString());
229
230 return success;
231 }
232 else
233 {
234 m_log.Error("[AVATAR CONNECTOR]: Can't save appearance for " + userID + ". Unhandled avatar type " + avatar.AvatarType);
235 return false;
236 }
237 }
238
239 public bool ResetAvatar(UUID userID)
240 {
241 m_log.Error("[AVATAR CONNECTOR]: ResetAvatar called for " + userID + ", implement this");
242 return false;
243 }
244
245 public bool SetItems(UUID userID, string[] names, string[] values)
246 {
247 m_log.Error("[AVATAR CONNECTOR]: SetItems called for " + userID + " with " + names.Length + " names and " + values.Length + " values, implement this");
248 return false;
249 }
250
251 public bool RemoveItems(UUID userID, string[] names)
252 {
253 m_log.Error("[AVATAR CONNECTOR]: RemoveItems called for " + userID + " with " + names.Length + " names, implement this");
254 return false;
255 }
256
257 #endregion IAvatarService
258 }
259}