29 using System.Collections.Generic;
30 using System.Collections.Specialized;
32 using System.Diagnostics;
34 using System.Reflection;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Services.Interfaces;
43 using OpenMetaverse.StructuredData;
45 namespace OpenSim.Services.Connectors.SimianGrid
50 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SimianAvatarServiceConnector")]
53 private static readonly ILog m_log =
55 MethodBase.GetCurrentMethod().DeclaringType);
58 private string m_serverUrl = String.Empty;
59 private bool m_Enabled =
false;
61 #region ISharedRegionModule
63 public Type ReplaceableInterface {
get {
return null; } }
69 public string Name {
get {
return "SimianAvatarServiceConnector"; } }
73 #endregion ISharedRegionModule
82 IConfig moduleConfig = source.Configs[
"Modules"];
83 if (moduleConfig != null)
85 string name = moduleConfig.GetString(
"AvatarServices",
"");
91 private void CommonInit(IConfigSource source)
93 IConfig gridConfig = source.Configs[
"AvatarService"];
94 if (gridConfig != null)
96 string serviceUrl = gridConfig.GetString(
"AvatarServerURI");
97 if (!
String.IsNullOrEmpty(serviceUrl))
99 if (!serviceUrl.EndsWith(
"/") && !serviceUrl.EndsWith(
"="))
100 serviceUrl = serviceUrl +
'/';
101 m_serverUrl = serviceUrl;
106 if (
String.IsNullOrEmpty(m_serverUrl))
107 m_log.Info(
"[SIMIAN AVATAR CONNECTOR]: No AvatarServerURI specified, disabling connector");
110 #region IAvatarService
119 NameValueCollection requestArgs =
new NameValueCollection
121 {
"RequestMethod",
"GetUser" },
122 {
"UserID", userID.ToString() }
125 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
126 if (response[
"Success"].AsBoolean())
129 try { map = OSDParser.DeserializeJson(response[
"LLPackedAppearance"].AsString()) as
OSDMap; }
136 m_log.WarnFormat(
"[SIMIAN AVATAR CONNECTOR] retrieved appearance for {0}:\n{1}",userID,appearance.ToString());
141 m_log.WarnFormat(
"[SIMIAN AVATAR CONNECTOR]: Failed to decode appearance for {0}",userID);
145 m_log.WarnFormat(
"[SIMIAN AVATAR CONNECTOR]: Failed to get appearance for {0}: {1}",
146 userID,response[
"Message"].AsString());
156 OSDMap map = appearance.Pack(ctx);
159 m_log.WarnFormat(
"[SIMIAN AVATAR CONNECTOR]: Failed to encode appearance for {0}",userID);
165 NameValueCollection requestArgs =
new NameValueCollection
167 {
"RequestMethod",
"AddUserData" },
168 {
"UserID", userID.ToString() },
169 {
"LLPackedAppearance", OSDParser.SerializeJsonString(map) }
172 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
173 bool success = response[
"Success"].AsBoolean();
176 m_log.WarnFormat(
"[SIMIAN AVATAR CONNECTOR]: Failed to save appearance for {0}: {1}",
177 userID,response[
"Message"].AsString());
187 NameValueCollection requestArgs =
new NameValueCollection
189 {
"RequestMethod",
"GetUser" },
190 {
"UserID", userID.ToString() }
193 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
194 if (response[
"Success"].AsBoolean())
197 try { map = OSDParser.DeserializeJson(response[
"LLAppearance"].AsString()) as
OSDMap; }
203 wearables[0] =
new AvatarWearable(map[
"ShapeItem"].AsUUID(), map[
"ShapeAsset"].AsUUID());
204 wearables[1] =
new AvatarWearable(map[
"SkinItem"].AsUUID(), map[
"SkinAsset"].AsUUID());
205 wearables[2] =
new AvatarWearable(map[
"HairItem"].AsUUID(), map[
"HairAsset"].AsUUID());
206 wearables[3] =
new AvatarWearable(map[
"EyesItem"].AsUUID(), map[
"EyesAsset"].AsUUID());
207 wearables[4] =
new AvatarWearable(map[
"ShirtItem"].AsUUID(), map[
"ShirtAsset"].AsUUID());
208 wearables[5] =
new AvatarWearable(map[
"PantsItem"].AsUUID(), map[
"PantsAsset"].AsUUID());
209 wearables[6] =
new AvatarWearable(map[
"ShoesItem"].AsUUID(), map[
"ShoesAsset"].AsUUID());
210 wearables[7] =
new AvatarWearable(map[
"SocksItem"].AsUUID(), map[
"SocksAsset"].AsUUID());
211 wearables[8] =
new AvatarWearable(map[
"JacketItem"].AsUUID(), map[
"JacketAsset"].AsUUID());
212 wearables[9] =
new AvatarWearable(map[
"GlovesItem"].AsUUID(), map[
"GlovesAsset"].AsUUID());
213 wearables[10] =
new AvatarWearable(map[
"UndershirtItem"].AsUUID(), map[
"UndershirtAsset"].AsUUID());
214 wearables[11] =
new AvatarWearable(map[
"UnderpantsItem"].AsUUID(), map[
"UnderpantsAsset"].AsUUID());
215 wearables[12] =
new AvatarWearable(map[
"SkirtItem"].AsUUID(), map[
"SkirtAsset"].AsUUID());
218 appearance.Wearables = wearables;
219 appearance.AvatarHeight = (float)map[
"Height"].AsReal();
225 try { map = OSDParser.DeserializeJson(response[
"LLAttachments"].AsString()) as
OSDMap; }
230 foreach (KeyValuePair<string, OSD> kvp
in map)
231 avatar.Data[kvp.Key] = kvp.Value.AsString();
238 m_log.Warn(
"[SIMIAN AVATAR CONNECTOR]: Failed to get user appearance for " + userID +
239 ", LLAppearance is missing or invalid");
245 m_log.Warn(
"[SIMIAN AVATAR CONNECTOR]: Failed to get user appearance for " + userID +
": " +
246 response[
"Message"].AsString());
257 m_log.Debug(
"[SIMIAN AVATAR CONNECTOR]: SetAvatar called for " + userID);
265 map[
"Height"] = OSD.FromReal(appearance.AvatarHeight);
267 map[
"BodyItem"] = appearance.Wearables[AvatarWearable.BODY][0].ItemID.ToString();
268 map[
"EyesItem"] = appearance.Wearables[AvatarWearable.EYES][0].ItemID.ToString();
269 map[
"GlovesItem"] = appearance.Wearables[AvatarWearable.GLOVES][0].ItemID.ToString();
270 map[
"HairItem"] = appearance.Wearables[AvatarWearable.HAIR][0].ItemID.ToString();
271 map[
"JacketItem"] = appearance.Wearables[AvatarWearable.JACKET][0].ItemID.ToString();
272 map[
"PantsItem"] = appearance.Wearables[AvatarWearable.PANTS][0].ItemID.ToString();
273 map[
"ShirtItem"] = appearance.Wearables[AvatarWearable.SHIRT][0].ItemID.ToString();
274 map[
"ShoesItem"] = appearance.Wearables[AvatarWearable.SHOES][0].ItemID.ToString();
275 map[
"SkinItem"] = appearance.Wearables[AvatarWearable.SKIN][0].ItemID.ToString();
276 map[
"SkirtItem"] = appearance.Wearables[AvatarWearable.SKIRT][0].ItemID.ToString();
277 map[
"SocksItem"] = appearance.Wearables[AvatarWearable.SOCKS][0].ItemID.ToString();
278 map[
"UnderPantsItem"] = appearance.Wearables[AvatarWearable.UNDERPANTS][0].ItemID.ToString();
279 map[
"UnderShirtItem"] = appearance.Wearables[AvatarWearable.UNDERSHIRT][0].ItemID.ToString();
280 map[
"BodyAsset"] = appearance.Wearables[AvatarWearable.BODY][0].AssetID.ToString();
281 map[
"EyesAsset"] = appearance.Wearables[AvatarWearable.EYES][0].AssetID.ToString();
282 map[
"GlovesAsset"] = appearance.Wearables[AvatarWearable.GLOVES][0].AssetID.ToString();
283 map[
"HairAsset"] = appearance.Wearables[AvatarWearable.HAIR][0].AssetID.ToString();
284 map[
"JacketAsset"] = appearance.Wearables[AvatarWearable.JACKET][0].AssetID.ToString();
285 map[
"PantsAsset"] = appearance.Wearables[AvatarWearable.PANTS][0].AssetID.ToString();
286 map[
"ShirtAsset"] = appearance.Wearables[AvatarWearable.SHIRT][0].AssetID.ToString();
287 map[
"ShoesAsset"] = appearance.Wearables[AvatarWearable.SHOES][0].AssetID.ToString();
288 map[
"SkinAsset"] = appearance.Wearables[AvatarWearable.SKIN][0].AssetID.ToString();
289 map[
"SkirtAsset"] = appearance.Wearables[AvatarWearable.SKIRT][0].AssetID.ToString();
290 map[
"SocksAsset"] = appearance.Wearables[AvatarWearable.SOCKS][0].AssetID.ToString();
291 map[
"UnderPantsAsset"] = appearance.Wearables[AvatarWearable.UNDERPANTS][0].AssetID.ToString();
292 map[
"UnderShirtAsset"] = appearance.Wearables[AvatarWearable.UNDERSHIRT][0].AssetID.ToString();
296 foreach (KeyValuePair<string, string> kvp
in avatar.
Data)
298 if (kvp.Key.StartsWith(
"_ap_"))
299 items.Add(kvp.Key,
OSD.FromString(kvp.Value));
302 NameValueCollection requestArgs =
new NameValueCollection
304 {
"RequestMethod",
"AddUserData" },
305 {
"UserID", userID.ToString() },
306 {
"LLAppearance", OSDParser.SerializeJsonString(map) },
307 {
"LLAttachments", OSDParser.SerializeJsonString(items) }
310 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
311 bool success = response[
"Success"].AsBoolean();
314 m_log.Warn(
"[SIMIAN AVATAR CONNECTOR]: Failed saving appearance for " + userID +
": " + response[
"Message"].AsString());
320 m_log.Error(
"[SIMIAN AVATAR CONNECTOR]: Can't save appearance for " + userID +
". Unhandled avatar type " + avatar.AvatarType);
327 m_log.Error(
"[SIMIAN AVATAR CONNECTOR]: ResetAvatar called for " + userID +
", implement this");
331 public bool SetItems(UUID userID,
string[] names,
string[] values)
333 m_log.Error(
"[SIMIAN AVATAR CONNECTOR]: SetItems called for " + userID +
" with " + names.Length +
" names and " + values.Length +
" values, implement this");
339 m_log.Error(
"[SIMIAN AVATAR CONNECTOR]: RemoveItems called for " + userID +
" with " + names.Length +
" names, implement this");
343 #endregion IAvatarService
Connects avatar appearance data to the SimianGrid backend
bool SetAppearance(UUID userID, AvatarAppearance appearance)
Called by everyone who can change the avatar data (so, regions)
SimianAvatarServiceConnector()
SimianAvatarServiceConnector(IConfigSource source)
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
bool SetAvatar(UUID userID, AvatarData avatar)
Called by everyone who can change the avatar data (so, regions)
Contains the Avatar's Appearance and methods to manipulate the appearance.
OpenMetaverse.StructuredData.OSDMap OSDMap
bool RemoveItems(UUID userID, string[] names)
AvatarAppearance GetAppearance(UUID userID)
Called by the login service
OpenMetaverse.StructuredData.OSD OSD
bool SetItems(UUID userID, string[] names, string[] values)
These methods raison d'etre: No need to send the entire avatar data (SetAvatar) for changing attachme...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Each region/client that uses avatars will have a data structure of this type representing the avatars...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
AvatarData GetAvatar(UUID userID)
Called by the login service
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Dictionary< string, string > Data
bool ResetAvatar(UUID userID)
Not sure if it's needed