aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/UserProfiles
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/Avatar/UserProfiles
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/UserProfiles')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs986
1 files changed, 775 insertions, 211 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index c20369c..e02ca49 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -31,6 +31,7 @@ using System.Text;
31using System.Collections; 31using System.Collections;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Globalization; 33using System.Globalization;
34using System.Linq;
34using System.Net; 35using System.Net;
35using System.Net.Sockets; 36using System.Net.Sockets;
36using System.Reflection; 37using System.Reflection;
@@ -56,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
56 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")] 57 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")]
57 public class UserProfileModule : IProfileModule, INonSharedRegionModule 58 public class UserProfileModule : IProfileModule, INonSharedRegionModule
58 { 59 {
60 const double PROFILECACHEEXPIRE = 300;
59 /// <summary> 61 /// <summary>
60 /// Logging 62 /// Logging
61 /// </summary> 63 /// </summary>
@@ -66,8 +68,11 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
66 // count. The entries are removed when the interest count reaches 0. 68 // count. The entries are removed when the interest count reaches 0.
67 Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>(); 69 Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>();
68 Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>(); 70 Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>();
71 ExpiringCache<UUID, UserProfileCacheEntry> m_profilesCache = new ExpiringCache<UUID, UserProfileCacheEntry>();
72 IAssetCache m_assetCache;
69 73
70 private JsonRpcRequestManager rpc = new JsonRpcRequestManager(); 74 private JsonRpcRequestManager rpc = new JsonRpcRequestManager();
75 private bool m_allowUserProfileWebURLs = true;
71 76
72 public Scene Scene 77 public Scene Scene
73 { 78 {
@@ -80,7 +85,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
80 /// <value> 85 /// <value>
81 /// The configuration 86 /// The configuration
82 /// </value> 87 /// </value>
83 public IConfigSource Config 88 public IConfigSource Config
84 { 89 {
85 get; 90 get;
86 set; 91 set;
@@ -92,7 +97,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
92 /// <value> 97 /// <value>
93 /// The profile server URI. 98 /// The profile server URI.
94 /// </value> 99 /// </value>
95 public string ProfileServerUri 100 public string ProfileServerUri
96 { 101 {
97 get; 102 get;
98 set; 103 set;
@@ -115,23 +120,22 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
115 /// <value> 120 /// <value>
116 /// <c>true</c> if enabled; otherwise, <c>false</c>. 121 /// <c>true</c> if enabled; otherwise, <c>false</c>.
117 /// </value> 122 /// </value>
118 public bool Enabled 123 public bool Enabled
119 { 124 {
120 get; 125 get;
121 set; 126 set;
122 } 127 }
123 128
124 public string MyGatekeeper 129 public string MyGatekeeper
125 { 130 {
126 get; private set; 131 get; private set;
127 } 132 }
128 133
129
130 #region IRegionModuleBase implementation 134 #region IRegionModuleBase implementation
131 /// <summary> 135 /// <summary>
132 /// This is called to initialize the region module. For shared modules, this is called exactly once, after 136 /// This is called to initialize the region module. For shared modules, this is called exactly once, after
133 /// creating the single (shared) instance. For non-shared modules, this is called once on each instance, after 137 /// creating the single (shared) instance. For non-shared modules, this is called once on each instance, after
134 /// the instace for the region has been created. 138 /// the instace for the region has been created.
135 /// </summary> 139 /// </summary>
136 /// <param name='source'> 140 /// <param name='source'>
137 /// Source. 141 /// Source.
@@ -145,7 +149,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
145 149
146 if (profileConfig == null) 150 if (profileConfig == null)
147 { 151 {
148 m_log.Debug("[PROFILES]: UserProfiles disabled, no configuration"); 152 //m_log.Debug("[PROFILES]: UserProfiles disabled, no configuration");
149 Enabled = false; 153 Enabled = false;
150 return; 154 return;
151 } 155 }
@@ -158,7 +162,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
158 Enabled = false; 162 Enabled = false;
159 return; 163 return;
160 } 164 }
161 165
166 m_allowUserProfileWebURLs = profileConfig.GetBoolean("AllowUserProfileWebURLs", m_allowUserProfileWebURLs);
167
162 m_log.Debug("[PROFILES]: Full Profiles Enabled"); 168 m_log.Debug("[PROFILES]: Full Profiles Enabled");
163 ReplaceableInterface = null; 169 ReplaceableInterface = null;
164 Enabled = true; 170 Enabled = true;
@@ -181,22 +187,11 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
181 Scene = scene; 187 Scene = scene;
182 Scene.RegisterModuleInterface<IProfileModule>(this); 188 Scene.RegisterModuleInterface<IProfileModule>(this);
183 Scene.EventManager.OnNewClient += OnNewClient; 189 Scene.EventManager.OnNewClient += OnNewClient;
184 Scene.EventManager.OnMakeRootAgent += HandleOnMakeRootAgent; 190 Scene.EventManager.OnClientClosed += OnClientClosed;
185 191
186 UserManagementModule = Scene.RequestModuleInterface<IUserManagement>(); 192 UserManagementModule = Scene.RequestModuleInterface<IUserManagement>();
187 } 193 }
188 194
189 void HandleOnMakeRootAgent (ScenePresence obj)
190 {
191 if(obj.PresenceType == PresenceType.Npc)
192 return;
193
194 Util.FireAndForget(delegate
195 {
196 GetImageAssets(((IScenePresence)obj).UUID);
197 }, null, "UserProfileModule.GetImageAssets");
198 }
199
200 /// <summary> 195 /// <summary>
201 /// Removes the region. 196 /// Removes the region.
202 /// </summary> 197 /// </summary>
@@ -207,13 +202,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
207 { 202 {
208 if(!Enabled) 203 if(!Enabled)
209 return; 204 return;
205
206 m_profilesCache.Clear();
207 m_classifiedCache.Clear();
208 m_classifiedInterest.Clear();
210 } 209 }
211 210
212 /// <summary> 211 /// <summary>
213 /// This will be called once for every scene loaded. In a shared module this will be multiple times in one 212 /// This will be called once for every scene loaded. In a shared module this will be multiple times in one
214 /// instance, while a nonshared module instance will only be called once. This method is called after AddRegion 213 /// instance, while a nonshared module instance will only be called once. This method is called after AddRegion
215 /// has been called in all modules for that scene, providing an opportunity to request another module's 214 /// has been called in all modules for that scene, providing an opportunity to request another module's
216 /// interface, or hook an event from another module. 215 /// interface, or hook an event from another module.
217 /// </summary> 216 /// </summary>
218 /// <param name='scene'> 217 /// <param name='scene'>
219 /// Scene. 218 /// Scene.
@@ -222,6 +221,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
222 { 221 {
223 if(!Enabled) 222 if(!Enabled)
224 return; 223 return;
224 m_assetCache = Scene.RequestModuleInterface<IAssetCache>();
225 } 225 }
226 226
227 /// <summary> 227 /// <summary>
@@ -230,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
230 /// module has registered the interface by then, this module will be activated, else it will remain inactive, 230 /// module has registered the interface by then, this module will be activated, else it will remain inactive,
231 /// letting the other module take over. This should return non-null ONLY in modules that are intended to be 231 /// letting the other module take over. This should return non-null ONLY in modules that are intended to be
232 /// easily replaceable, e.g. stub implementations that the developer expects to be replaced by third party 232 /// easily replaceable, e.g. stub implementations that the developer expects to be replaced by third party
233 /// provided modules. 233 /// provided modules.
234 /// </summary> 234 /// </summary>
235 /// <value> 235 /// <value>
236 /// The replaceable interface. 236 /// The replaceable interface.
@@ -248,7 +248,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
248 } 248 }
249 249
250 /// <value> 250 /// <value>
251 /// The name of the module 251 /// The name of the module
252 /// </value> 252 /// </value>
253 /// <summary> 253 /// <summary>
254 /// Gets the module name. 254 /// Gets the module name.
@@ -293,6 +293,40 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
293 client.OnUserInfoRequest += UserPreferencesRequest; 293 client.OnUserInfoRequest += UserPreferencesRequest;
294 client.OnUpdateUserInfo += UpdateUserPreferences; 294 client.OnUpdateUserInfo += UpdateUserPreferences;
295 } 295 }
296
297 void OnClientClosed(UUID AgentId, Scene scene)
298 {
299 ScenePresence sp = scene.GetScenePresence(AgentId);
300 IClientAPI client = sp.ControllingClient;
301 if (client == null)
302 return;
303
304 //Profile
305 client.OnRequestAvatarProperties -= RequestAvatarProperties;
306 client.OnUpdateAvatarProperties -= AvatarPropertiesUpdate;
307 client.OnAvatarInterestUpdate -= AvatarInterestsUpdate;
308
309 // Classifieds
310// client.r GenericPacketHandler("avatarclassifiedsrequest", ClassifiedsRequest);
311 client.OnClassifiedInfoUpdate -= ClassifiedInfoUpdate;
312 client.OnClassifiedInfoRequest -= ClassifiedInfoRequest;
313 client.OnClassifiedDelete -= ClassifiedDelete;
314
315 // Picks
316// client.AddGenericPacketHandler("avatarpicksrequest", PicksRequest);
317// client.AddGenericPacketHandler("pickinforequest", PickInfoRequest);
318 client.OnPickInfoUpdate -= PickInfoUpdate;
319 client.OnPickDelete -= PickDelete;
320
321 // Notes
322// client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest);
323 client.OnAvatarNotesUpdate -= NotesUpdate;
324
325 // Preferences
326 client.OnUserInfoRequest -= UserPreferencesRequest;
327 client.OnUpdateUserInfo -= UpdateUserPreferences;
328 }
329
296 #endregion Region Event Handlers 330 #endregion Region Event Handlers
297 331
298 #region Classified 332 #region Classified
@@ -315,38 +349,74 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
315 return; 349 return;
316 350
317 IClientAPI remoteClient = (IClientAPI)sender; 351 IClientAPI remoteClient = (IClientAPI)sender;
352 Dictionary<UUID, string> classifieds = new Dictionary<UUID, string>();
318 353
319 UUID targetID; 354 UUID targetID;
320 UUID.TryParse(args[0], out targetID); 355 if(!UUID.TryParse(args[0], out targetID) || targetID == UUID.Zero)
356 return;
321 357
322 // Can't handle NPC yet...
323 ScenePresence p = FindPresence(targetID); 358 ScenePresence p = FindPresence(targetID);
359 if (p != null && p.IsNPC)
360 {
361 remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
362 return;
363 }
324 364
325 if (null != p) 365 UserProfileCacheEntry uce = null;
366 lock(m_profilesCache)
326 { 367 {
327 if (p.PresenceType == PresenceType.Npc) 368 if(m_profilesCache.TryGetValue(targetID, out uce) && uce != null)
328 return; 369 {
370 if(uce.classifiedsLists != null)
371 {
372 foreach(KeyValuePair<UUID,string> kvp in uce.classifiedsLists)
373 {
374 UUID kvpkey = kvp.Key;
375 classifieds[kvpkey] = kvp.Value;
376 lock (m_classifiedCache)
377 {
378 if (!m_classifiedCache.ContainsKey(kvpkey))
379 {
380 m_classifiedCache.Add(kvpkey,targetID);
381 m_classifiedInterest.Add(kvpkey, 0);
382 }
383
384 m_classifiedInterest[kvpkey]++;
385 }
386 }
387 remoteClient.SendAvatarClassifiedReply(targetID, uce.classifiedsLists);
388 return;
389 }
390 }
329 } 391 }
330 392
331 string serverURI = string.Empty; 393 string serverURI = string.Empty;
332 GetUserProfileServerURI(targetID, out serverURI); 394 GetUserProfileServerURI(targetID, out serverURI);
333 UUID creatorId = UUID.Zero; 395 if(string.IsNullOrWhiteSpace(serverURI))
334 Dictionary<UUID, string> classifieds = new Dictionary<UUID, string>(); 396 {
397 remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
398 return;
399 }
335 400
336 OSDMap parameters= new OSDMap(); 401 OSDMap parameters= new OSDMap();
337 UUID.TryParse(args[0], out creatorId); 402
338 parameters.Add("creatorId", OSD.FromUUID(creatorId)); 403 parameters.Add("creatorId", OSD.FromUUID(targetID));
339 OSD Params = (OSD)parameters; 404 OSD Params = (OSD)parameters;
340 if(!rpc.JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString())) 405 if(!rpc.JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
341 { 406 {
342 remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds); 407 remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
343 return; 408 return;
344 } 409 }
345 410
346 parameters = (OSDMap)Params; 411 parameters = (OSDMap)Params;
347 412
348 OSDArray list = (OSDArray)parameters["result"]; 413 if(!parameters.ContainsKey("result") || parameters["result"] == null)
414 {
415 remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
416 return;
417 }
349 418
419 OSDArray list = (OSDArray)parameters["result"];
350 420
351 foreach(OSD map in list) 421 foreach(OSD map in list)
352 { 422 {
@@ -360,7 +430,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
360 { 430 {
361 if (!m_classifiedCache.ContainsKey(cid)) 431 if (!m_classifiedCache.ContainsKey(cid))
362 { 432 {
363 m_classifiedCache.Add(cid,creatorId); 433 m_classifiedCache.Add(cid,targetID);
364 m_classifiedInterest.Add(cid, 0); 434 m_classifiedInterest.Add(cid, 0);
365 } 435 }
366 436
@@ -368,11 +438,20 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
368 } 438 }
369 } 439 }
370 440
371 remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds); 441 lock(m_profilesCache)
442 {
443 if(!m_profilesCache.TryGetValue(targetID, out uce) || uce == null)
444 uce = new UserProfileCacheEntry();
445 uce.classifiedsLists = classifieds;
446
447 m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE);
448 }
449
450 remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
372 } 451 }
373 452
374 public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient) 453 public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient)
375 { 454 {
376 UUID target = remoteClient.AgentId; 455 UUID target = remoteClient.AgentId;
377 UserClassifiedAdd ad = new UserClassifiedAdd(); 456 UserClassifiedAdd ad = new UserClassifiedAdd();
378 ad.ClassifiedId = queryClassifiedID; 457 ad.ClassifiedId = queryClassifiedID;
@@ -380,7 +459,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
380 lock (m_classifiedCache) 459 lock (m_classifiedCache)
381 { 460 {
382 if (m_classifiedCache.ContainsKey(queryClassifiedID)) 461 if (m_classifiedCache.ContainsKey(queryClassifiedID))
383 { 462 {
384 target = m_classifiedCache[queryClassifiedID]; 463 target = m_classifiedCache[queryClassifiedID];
385 464
386 m_classifiedInterest[queryClassifiedID] --; 465 m_classifiedInterest[queryClassifiedID] --;
@@ -392,9 +471,33 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
392 } 471 }
393 } 472 }
394 } 473 }
395 474
475 UserProfileCacheEntry uce = null;
476 lock(m_profilesCache)
477 {
478 if(m_profilesCache.TryGetValue(target, out uce) && uce != null)
479 {
480 if(uce.classifieds != null && uce.classifieds.ContainsKey(queryClassifiedID))
481 {
482 ad = uce.classifieds[queryClassifiedID];
483 Vector3 gPos = new Vector3();
484 Vector3.TryParse(ad.GlobalPos, out gPos);
485
486 remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate,
487 (uint)ad.ExpirationDate, (uint)ad.Category, ad.Name, ad.Description,
488 ad.ParcelId, (uint)ad.ParentEstate, ad.SnapshotId, ad.SimName,
489 gPos, ad.ParcelName, ad.Flags, ad.Price);
490 return;
491 }
492 }
493 }
494
396 string serverURI = string.Empty; 495 string serverURI = string.Empty;
397 GetUserProfileServerURI(target, out serverURI); 496 bool foreign = GetUserProfileServerURI(target, out serverURI);
497 if(string.IsNullOrWhiteSpace(serverURI))
498 {
499 return;
500 }
398 501
399 object Ad = (object)ad; 502 object Ad = (object)ad;
400 if(!rpc.JsonRpcRequest(ref Ad, "classifieds_info_query", serverURI, UUID.Random().ToString())) 503 if(!rpc.JsonRpcRequest(ref Ad, "classifieds_info_query", serverURI, UUID.Random().ToString()))
@@ -408,6 +511,20 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
408 if(ad.CreatorId == UUID.Zero) 511 if(ad.CreatorId == UUID.Zero)
409 return; 512 return;
410 513
514 if(foreign)
515 cacheForeignImage(target, ad.SnapshotId);
516
517 lock(m_profilesCache)
518 {
519 if(!m_profilesCache.TryGetValue(target, out uce) || uce == null)
520 uce = new UserProfileCacheEntry();
521 if(uce.classifieds == null)
522 uce.classifieds = new Dictionary<UUID, UserClassifiedAdd>();
523 uce.classifieds[ad.ClassifiedId] = ad;
524
525 m_profilesCache.AddOrUpdate(target, uce, PROFILECACHEEXPIRE);
526 }
527
411 Vector3 globalPos = new Vector3(); 528 Vector3 globalPos = new Vector3();
412 Vector3.TryParse(ad.GlobalPos, out globalPos); 529 Vector3.TryParse(ad.GlobalPos, out globalPos);
413 530
@@ -458,36 +575,62 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
458 int queryclassifiedPrice, IClientAPI remoteClient) 575 int queryclassifiedPrice, IClientAPI remoteClient)
459 { 576 {
460 Scene s = (Scene)remoteClient.Scene; 577 Scene s = (Scene)remoteClient.Scene;
461 IMoneyModule money = s.RequestModuleInterface<IMoneyModule>(); 578 Vector3 pos = remoteClient.SceneAgent.AbsolutePosition;
579 ILandObject land = s.LandChannel.GetLandObject(pos.X, pos.Y);
580 UUID creatorId = remoteClient.AgentId;
581 ScenePresence p = FindPresence(creatorId);
462 582
463 if (money != null) 583 UserProfileCacheEntry uce = null;
584 lock(m_profilesCache)
585 m_profilesCache.TryGetValue(remoteClient.AgentId, out uce);
586
587 string serverURI = string.Empty;
588 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
589 if(string.IsNullOrWhiteSpace(serverURI))
464 { 590 {
465 if (!money.AmountCovered(remoteClient.AgentId, queryclassifiedPrice)) 591 return;
466 {
467 remoteClient.SendAgentAlertMessage("You do not have enough money to create requested classified.", false);
468 return;
469 }
470 money.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge);
471 } 592 }
472 593
473 UserClassifiedAdd ad = new UserClassifiedAdd(); 594 if(foreign)
474 595 {
475 Vector3 pos = remoteClient.SceneAgent.AbsolutePosition; 596 remoteClient.SendAgentAlertMessage("Please change classifieds on your home grid", true);
476 ILandObject land = s.LandChannel.GetLandObject(pos.X, pos.Y); 597 if(uce != null && uce.classifiedsLists != null)
477 ScenePresence p = FindPresence(remoteClient.AgentId); 598 remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
478 599 return;
479 string serverURI = string.Empty; 600 }
480 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
481 601
482 if (land == null) 602 OSDMap parameters = new OSDMap {{"creatorId", OSD.FromUUID(creatorId)}};
603 OSD Params = (OSD)parameters;
604 if (!rpc.JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
483 { 605 {
484 ad.ParcelName = string.Empty; 606 remoteClient.SendAgentAlertMessage("Error fetching classifieds", false);
607 return;
485 } 608 }
486 else 609 parameters = (OSDMap)Params;
610 OSDArray list = (OSDArray)parameters["result"];
611 bool exists = list.Cast<OSDMap>().Where(map => map.ContainsKey("classifieduuid"))
612 .Any(map => map["classifieduuid"].AsUUID().Equals(queryclassifiedID));
613
614 IMoneyModule money = null;
615 if (!exists)
487 { 616 {
488 ad.ParcelName = land.LandData.Name; 617 money = s.RequestModuleInterface<IMoneyModule>();
618 if (money != null)
619 {
620 if (!money.AmountCovered(remoteClient.AgentId, queryclassifiedPrice))
621 {
622 remoteClient.SendAgentAlertMessage("You do not have enough money to create this classified.", false);
623 if(uce != null && uce.classifiedsLists != null)
624 remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
625 return;
626 }
627// money.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge);
628 }
489 } 629 }
490 630
631 UserClassifiedAdd ad = new UserClassifiedAdd();
632
633 ad.ParcelName = land == null ? string.Empty : land.LandData.Name;
491 ad.CreatorId = remoteClient.AgentId; 634 ad.CreatorId = remoteClient.AgentId;
492 ad.ClassifiedId = queryclassifiedID; 635 ad.ClassifiedId = queryclassifiedID;
493 ad.Category = Convert.ToInt32(queryCategory); 636 ad.Category = Convert.ToInt32(queryCategory);
@@ -507,10 +650,26 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
507 650
508 if(!rpc.JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString())) 651 if(!rpc.JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString()))
509 { 652 {
510 remoteClient.SendAgentAlertMessage( 653 remoteClient.SendAgentAlertMessage("Error updating classified", false);
511 "Error updating classified", false); 654 if(uce != null && uce.classifiedsLists != null)
655 remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
512 return; 656 return;
513 } 657 }
658
659 // only charge if it worked
660 if (money != null)
661 money.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge);
662
663 // just flush cache for now
664 lock(m_profilesCache)
665 {
666 if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null)
667 {
668 uce.classifieds = null;
669 uce.classifiedsLists = null;
670 }
671 }
672
514 } 673 }
515 674
516 /// <summary> 675 /// <summary>
@@ -524,12 +683,23 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
524 /// </param> 683 /// </param>
525 public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient) 684 public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient)
526 { 685 {
686
527 string serverURI = string.Empty; 687 string serverURI = string.Empty;
528 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 688 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
689 if(string.IsNullOrWhiteSpace(serverURI))
690 return;
691
692 if(foreign)
693 {
694 remoteClient.SendAgentAlertMessage("Please change classifieds on your home grid", true);
695 return;
696 }
529 697
530 UUID classifiedId; 698 UUID classifiedId;
699 if(!UUID.TryParse(queryClassifiedID.ToString(), out classifiedId))
700 return;
701
531 OSDMap parameters= new OSDMap(); 702 OSDMap parameters= new OSDMap();
532 UUID.TryParse(queryClassifiedID.ToString(), out classifiedId);
533 parameters.Add("classifiedId", OSD.FromUUID(classifiedId)); 703 parameters.Add("classifiedId", OSD.FromUUID(classifiedId));
534 OSD Params = (OSD)parameters; 704 OSD Params = (OSD)parameters;
535 if(!rpc.JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString())) 705 if(!rpc.JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString()))
@@ -539,6 +709,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
539 return; 709 return;
540 } 710 }
541 711
712 // flush cache
713 UserProfileCacheEntry uce = null;
714 lock(m_profilesCache)
715 {
716 if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null)
717 {
718 uce.classifieds = null;
719 uce.classifiedsLists = null;
720 }
721 }
722
542 parameters = (OSDMap)Params; 723 parameters = (OSDMap)Params;
543 } 724 }
544 #endregion Classified 725 #endregion Classified
@@ -564,33 +745,54 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
564 IClientAPI remoteClient = (IClientAPI)sender; 745 IClientAPI remoteClient = (IClientAPI)sender;
565 746
566 UUID targetId; 747 UUID targetId;
567 UUID.TryParse(args[0], out targetId); 748 if(!UUID.TryParse(args[0], out targetId))
749 return;
750
751 Dictionary<UUID, string> picks = new Dictionary<UUID, string>();
568 752
569 // Can't handle NPC yet...
570 ScenePresence p = FindPresence(targetId); 753 ScenePresence p = FindPresence(targetId);
754 if (p != null && p.IsNPC)
755 {
756 remoteClient.SendAvatarPicksReply(targetId, picks);
757 return;
758 }
571 759
572 if (null != p) 760 UserProfileCacheEntry uce = null;
761 lock(m_profilesCache)
573 { 762 {
574 if (p.PresenceType == PresenceType.Npc) 763 if(m_profilesCache.TryGetValue(targetId, out uce) && uce != null)
575 return; 764 {
765 if(uce != null && uce.picksList != null)
766 {
767 remoteClient.SendAvatarPicksReply(targetId, uce.picksList);
768 return;
769 }
770 }
576 } 771 }
577 772
578 string serverURI = string.Empty; 773 string serverURI = string.Empty;
579 GetUserProfileServerURI(targetId, out serverURI); 774 GetUserProfileServerURI(targetId, out serverURI);
580 775 if(string.IsNullOrWhiteSpace(serverURI))
581 Dictionary<UUID, string> picks = new Dictionary<UUID, string>(); 776 {
777 remoteClient.SendAvatarPicksReply(targetId, picks);
778 return;
779 }
582 780
583 OSDMap parameters= new OSDMap(); 781 OSDMap parameters= new OSDMap();
584 parameters.Add("creatorId", OSD.FromUUID(targetId)); 782 parameters.Add("creatorId", OSD.FromUUID(targetId));
585 OSD Params = (OSD)parameters; 783 OSD Params = (OSD)parameters;
586 if(!rpc.JsonRpcRequest(ref Params, "avatarpicksrequest", serverURI, UUID.Random().ToString())) 784 if(!rpc.JsonRpcRequest(ref Params, "avatarpicksrequest", serverURI, UUID.Random().ToString()))
587 { 785 {
588 remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks); 786 remoteClient.SendAvatarPicksReply(targetId, picks);
589 return; 787 return;
590 } 788 }
591 789
592 parameters = (OSDMap)Params; 790 parameters = (OSDMap)Params;
593 791 if(!parameters.ContainsKey("result") || parameters["result"] == null)
792 {
793 remoteClient.SendAvatarPicksReply(targetId, picks);
794 return;
795 }
594 OSDArray list = (OSDArray)parameters["result"]; 796 OSDArray list = (OSDArray)parameters["result"];
595 797
596 foreach(OSD map in list) 798 foreach(OSD map in list)
@@ -598,12 +800,19 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
598 OSDMap m = (OSDMap)map; 800 OSDMap m = (OSDMap)map;
599 UUID cid = m["pickuuid"].AsUUID(); 801 UUID cid = m["pickuuid"].AsUUID();
600 string name = m["name"].AsString(); 802 string name = m["name"].AsString();
601
602 m_log.DebugFormat("[PROFILES]: PicksRequest {0}", name);
603
604 picks[cid] = name; 803 picks[cid] = name;
605 } 804 }
606 remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks); 805
806 lock(m_profilesCache)
807 {
808 if(!m_profilesCache.TryGetValue(targetId, out uce) || uce == null)
809 uce = new UserProfileCacheEntry();
810 uce.picksList = picks;
811
812 m_profilesCache.AddOrUpdate(targetId, uce, PROFILECACHEEXPIRE);
813 }
814
815 remoteClient.SendAvatarPicksReply(targetId, picks);
607 } 816 }
608 817
609 /// <summary> 818 /// <summary>
@@ -623,21 +832,45 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
623 if (!(sender is IClientAPI)) 832 if (!(sender is IClientAPI))
624 return; 833 return;
625 834
835 UserProfilePick pick = new UserProfilePick ();
626 UUID targetID; 836 UUID targetID;
627 UUID.TryParse (args [0], out targetID); 837 if(!UUID.TryParse(args [0], out targetID))
628 string serverURI = string.Empty; 838 return;
629 GetUserProfileServerURI (targetID, out serverURI);
630 839
631 string theirGatekeeperURI; 840 pick.CreatorId = targetID;
632 GetUserGatekeeperURI (targetID, out theirGatekeeperURI); 841
842 if(!UUID.TryParse (args [1], out pick.PickId))
843 return;
633 844
634 IClientAPI remoteClient = (IClientAPI)sender; 845 IClientAPI remoteClient = (IClientAPI)sender;
846 UserProfileCacheEntry uce = null;
847 lock(m_profilesCache)
848 {
849 if(m_profilesCache.TryGetValue(targetID, out uce) && uce != null)
850 {
851 if(uce != null && uce.picks != null && uce.picks.ContainsKey(pick.PickId))
852 {
853 pick = uce.picks[pick.PickId];
854 Vector3 gPos = new Vector3(Vector3.Zero);
855 Vector3.TryParse(pick.GlobalPos, out gPos);
856 remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
857 pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
858 gPos,pick.SortOrder,pick.Enabled);
859 return;
860 }
861 }
862 }
635 863
636 UserProfilePick pick = new UserProfilePick (); 864 string serverURI = string.Empty;
637 UUID.TryParse (args [0], out pick.CreatorId); 865 bool foreign = GetUserProfileServerURI (targetID, out serverURI);
638 UUID.TryParse (args [1], out pick.PickId); 866 if(string.IsNullOrWhiteSpace(serverURI))
867 {
868 return;
869 }
870
871 string theirGatekeeperURI;
872 GetUserGatekeeperURI(targetID, out theirGatekeeperURI);
639 873
640
641 object Pick = (object)pick; 874 object Pick = (object)pick;
642 if (!rpc.JsonRpcRequest (ref Pick, "pickinforequest", serverURI, UUID.Random ().ToString ())) { 875 if (!rpc.JsonRpcRequest (ref Pick, "pickinforequest", serverURI, UUID.Random ().ToString ())) {
643 remoteClient.SendAgentAlertMessage ( 876 remoteClient.SendAgentAlertMessage (
@@ -645,15 +878,13 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
645 return; 878 return;
646 } 879 }
647 pick = (UserProfilePick)Pick; 880 pick = (UserProfilePick)Pick;
648 881 if(foreign)
882 cacheForeignImage(targetID, pick.SnapshotId);
883
649 Vector3 globalPos = new Vector3(Vector3.Zero); 884 Vector3 globalPos = new Vector3(Vector3.Zero);
650 885 Vector3.TryParse(pick.GlobalPos, out globalPos);
651 // Smoke and mirrors 886
652 if (pick.Gatekeeper == MyGatekeeper) 887 if (!string.IsNullOrWhiteSpace(MyGatekeeper) && pick.Gatekeeper != MyGatekeeper)
653 {
654 Vector3.TryParse(pick.GlobalPos,out globalPos);
655 }
656 else
657 { 888 {
658 // Setup the illusion 889 // Setup the illusion
659 string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName); 890 string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName);
@@ -661,26 +892,52 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
661 892
662 if(target == null) 893 if(target == null)
663 { 894 {
664 // This is a dead or unreachable region 895 // This is a unreachable region
665 } 896 }
666 else 897 else
667 { 898 {
668 // Work our slight of hand 899 // we have a proxy on map
669 int x = target.RegionLocX; 900 ulong oriHandle;
670 int y = target.RegionLocY; 901 uint oriX;
902 uint oriY;
903 if(Util.ParseFakeParcelID(pick.ParcelId, out oriHandle, out oriX, out oriY))
904 {
905 pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, oriX, oriY);
906 globalPos.X = target.RegionLocX + oriX;
907 globalPos.Y = target.RegionLocY + oriY;
908 pick.GlobalPos = globalPos.ToString();
909 }
910 else
911 {
912 // this is a fail on large regions
913 uint gtmp = (uint)globalPos.X >> 8;
914 globalPos.X -= (gtmp << 8);
915
916 gtmp = (uint)globalPos.Y >> 8;
917 globalPos.Y -= (gtmp << 8);
671 918
672 dynamic synthX = globalPos.X - (globalPos.X/Constants.RegionSize) * Constants.RegionSize; 919 pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, (uint)globalPos.X, (uint)globalPos.Y);
673 synthX += x;
674 globalPos.X = synthX;
675 920
676 dynamic synthY = globalPos.Y - (globalPos.Y/Constants.RegionSize) * Constants.RegionSize; 921 globalPos.X += target.RegionLocX;
677 synthY += y; 922 globalPos.Y += target.RegionLocY;
678 globalPos.Y = synthY; 923 pick.GlobalPos = globalPos.ToString();
924 }
679 } 925 }
680 } 926 }
681 927
682 m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString()); 928 m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());
683 929
930 lock(m_profilesCache)
931 {
932 if(!m_profilesCache.TryGetValue(targetID, out uce) || uce == null)
933 uce = new UserProfileCacheEntry();
934 if(uce.picks == null)
935 uce.picks = new Dictionary<UUID, UserProfilePick>();
936 uce.picks[pick.PickId] = pick;
937
938 m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE);
939 }
940
684 // Pull the rabbit out of the hat 941 // Pull the rabbit out of the hat
685 remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name, 942 remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
686 pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName, 943 pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
@@ -718,13 +975,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
718 /// Enabled. 975 /// Enabled.
719 /// </param> 976 /// </param>
720 public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled) 977 public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
721 { 978 {
722 //TODO: See how this works with NPC, May need to test
723 m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString()); 979 m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());
724 980
725 UserProfilePick pick = new UserProfilePick(); 981 UserProfilePick pick = new UserProfilePick();
726 string serverURI = string.Empty; 982 string serverURI = string.Empty;
727 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 983 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
984 if(string.IsNullOrWhiteSpace(serverURI))
985 {
986 return;
987 }
988
728 ScenePresence p = FindPresence(remoteClient.AgentId); 989 ScenePresence p = FindPresence(remoteClient.AgentId);
729 990
730 Vector3 avaPos = p.AbsolutePosition; 991 Vector3 avaPos = p.AbsolutePosition;
@@ -734,24 +995,27 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
734 avaPos.Z); 995 avaPos.Z);
735 996
736 string landParcelName = "My Parcel"; 997 string landParcelName = "My Parcel";
737 UUID landParcelID = p.currentParcelUUID; 998// UUID landParcelID = p.currentParcelUUID;
738 999
1000 // to locate parcels we use a fake id that encodes the region handle
1001 // since we do not have a global locator
1002 // this fails on HG
1003 UUID landParcelID = Util.BuildFakeParcelID(remoteClient.Scene.RegionInfo.RegionHandle, (uint)avaPos.X, (uint)avaPos.Y);
739 ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y); 1004 ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);
740 1005
741 if (land != null) 1006 if (land != null)
742 { 1007 {
743 // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved 1008 // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved
744 landParcelName = land.LandData.Name; 1009 landParcelName = land.LandData.Name;
745 landParcelID = land.LandData.GlobalID; 1010// landParcelID = land.LandData.GlobalID;
746 } 1011 }
747 else 1012 else
748 { 1013 {
749 m_log.WarnFormat( 1014 m_log.WarnFormat(
750 "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}", 1015 "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}",
751 avaPos.X, avaPos.Y, p.Scene.Name); 1016 avaPos.X, avaPos.Y, p.Scene.Name);
752 } 1017 }
753 1018
754
755 pick.PickId = pickID; 1019 pick.PickId = pickID;
756 pick.CreatorId = creatorID; 1020 pick.CreatorId = creatorID;
757 pick.TopPick = topPick; 1021 pick.TopPick = topPick;
@@ -774,6 +1038,24 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
774 return; 1038 return;
775 } 1039 }
776 1040
1041 UserProfileCacheEntry uce = null;
1042 lock(m_profilesCache)
1043 {
1044 if(!m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) || uce == null)
1045 uce = new UserProfileCacheEntry();
1046 if(uce.picks == null)
1047 uce.picks = new Dictionary<UUID, UserProfilePick>();
1048 if(uce.picksList == null)
1049 uce.picksList = new Dictionary<UUID, string>();
1050 uce.picks[pick.PickId] = pick;
1051 uce.picksList[pick.PickId] = pick.Name;
1052 m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE);
1053 }
1054 remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList);
1055 remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
1056 pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
1057 posGlobal,pick.SortOrder,pick.Enabled);
1058
777 m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString()); 1059 m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
778 } 1060 }
779 1061
@@ -790,6 +1072,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
790 { 1072 {
791 string serverURI = string.Empty; 1073 string serverURI = string.Empty;
792 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1074 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
1075 if(string.IsNullOrWhiteSpace(serverURI))
1076 {
1077 return;
1078 }
793 1079
794 OSDMap parameters= new OSDMap(); 1080 OSDMap parameters= new OSDMap();
795 parameters.Add("pickId", OSD.FromUUID(queryPickID)); 1081 parameters.Add("pickId", OSD.FromUUID(queryPickID));
@@ -800,6 +1086,23 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
800 "Error picks delete", false); 1086 "Error picks delete", false);
801 return; 1087 return;
802 } 1088 }
1089
1090 UserProfileCacheEntry uce = null;
1091 lock(m_profilesCache)
1092 {
1093 if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null)
1094 {
1095 if(uce.picks != null && uce.picks.ContainsKey(queryPickID))
1096 uce.picks.Remove(queryPickID);
1097 if(uce.picksList != null && uce.picksList.ContainsKey(queryPickID))
1098 uce.picksList.Remove(queryPickID);
1099 m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE);
1100 }
1101 }
1102 if(uce != null && uce.picksList != null)
1103 remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList);
1104 else
1105 remoteClient.SendAvatarPicksReply(remoteClient.AgentId, new Dictionary<UUID, string>());
803 } 1106 }
804 #endregion Picks 1107 #endregion Picks
805 1108
@@ -823,11 +1126,19 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
823 if (!(sender is IClientAPI)) 1126 if (!(sender is IClientAPI))
824 return; 1127 return;
825 1128
1129 if(!UUID.TryParse(args[0], out note.TargetId))
1130 return;
1131
826 IClientAPI remoteClient = (IClientAPI)sender; 1132 IClientAPI remoteClient = (IClientAPI)sender;
1133 note.UserId = remoteClient.AgentId;
1134
827 string serverURI = string.Empty; 1135 string serverURI = string.Empty;
828 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1136 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
829 note.UserId = remoteClient.AgentId; 1137 if(string.IsNullOrWhiteSpace(serverURI))
830 UUID.TryParse(args[0], out note.TargetId); 1138 {
1139 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
1140 return;
1141 }
831 1142
832 object Note = (object)note; 1143 object Note = (object)note;
833 if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString())) 1144 if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
@@ -836,7 +1147,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
836 return; 1147 return;
837 } 1148 }
838 note = (UserProfileNotes) Note; 1149 note = (UserProfileNotes) Note;
839
840 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes); 1150 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
841 } 1151 }
842 1152
@@ -854,6 +1164,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
854 /// </param> 1164 /// </param>
855 public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes) 1165 public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
856 { 1166 {
1167 ScenePresence p = FindPresence(queryTargetID);
1168 if (p != null && p.IsNPC)
1169 {
1170 remoteClient.SendAgentAlertMessage(
1171 "Notes for NPCs not available", false);
1172 return;
1173 }
1174
857 UserProfileNotes note = new UserProfileNotes(); 1175 UserProfileNotes note = new UserProfileNotes();
858 1176
859 note.UserId = remoteClient.AgentId; 1177 note.UserId = remoteClient.AgentId;
@@ -862,6 +1180,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
862 1180
863 string serverURI = string.Empty; 1181 string serverURI = string.Empty;
864 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1182 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
1183 if(string.IsNullOrWhiteSpace(serverURI))
1184 return;
865 1185
866 object Note = note; 1186 object Note = note;
867 if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString())) 1187 if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
@@ -873,6 +1193,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
873 } 1193 }
874 #endregion Notes 1194 #endregion Notes
875 1195
1196
876 #region User Preferences 1197 #region User Preferences
877 /// <summary> 1198 /// <summary>
878 /// Updates the user preferences. 1199 /// Updates the user preferences.
@@ -896,16 +1217,18 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
896 1217
897 string serverURI = string.Empty; 1218 string serverURI = string.Empty;
898 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1219 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
1220 if(string.IsNullOrWhiteSpace(serverURI))
1221 return;
899 1222
900 object Pref = pref; 1223 object Pref = pref;
901 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString())) 1224 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString()))
902 { 1225 {
903 m_log.InfoFormat("[PROFILES]: UserPreferences update error"); 1226 m_log.InfoFormat("[PROFILES]: UserPreferences update error");
904 remoteClient.SendAgentAlertMessage("Error updating preferences", false); 1227 remoteClient.SendAgentAlertMessage("Error updating preferences", false);
905 return; 1228 return;
906 } 1229 }
907 } 1230 }
908 1231
909 /// <summary> 1232 /// <summary>
910 /// Users the preferences request. 1233 /// Users the preferences request.
911 /// </summary> 1234 /// </summary>
@@ -920,7 +1243,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
920 1243
921 string serverURI = string.Empty; 1244 string serverURI = string.Empty;
922 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1245 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
923 1246 if(string.IsNullOrWhiteSpace(serverURI))
1247 return;
924 1248
925 object Pref = (object)pref; 1249 object Pref = (object)pref;
926 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString())) 1250 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString()))
@@ -932,7 +1256,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
932 pref = (UserPreferences) Pref; 1256 pref = (UserPreferences) Pref;
933 1257
934 remoteClient.SendUserInfoReply(pref.IMViaEmail, pref.Visible, pref.EMail); 1258 remoteClient.SendUserInfoReply(pref.IMViaEmail, pref.Visible, pref.EMail);
935 1259
936 } 1260 }
937 #endregion User Preferences 1261 #endregion User Preferences
938 1262
@@ -960,6 +1284,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
960 /// </param> 1284 /// </param>
961 public void AvatarInterestsUpdate(IClientAPI remoteClient, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages) 1285 public void AvatarInterestsUpdate(IClientAPI remoteClient, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages)
962 { 1286 {
1287
963 UserProfileProperties prop = new UserProfileProperties(); 1288 UserProfileProperties prop = new UserProfileProperties();
964 1289
965 prop.UserId = remoteClient.AgentId; 1290 prop.UserId = remoteClient.AgentId;
@@ -971,6 +1296,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
971 1296
972 string serverURI = string.Empty; 1297 string serverURI = string.Empty;
973 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1298 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
1299 if(string.IsNullOrWhiteSpace(serverURI))
1300 return;
974 1301
975 object Param = prop; 1302 object Param = prop;
976 if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString())) 1303 if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString()))
@@ -979,6 +1306,17 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
979 "Error updating interests", false); 1306 "Error updating interests", false);
980 return; 1307 return;
981 } 1308 }
1309
1310 // flush cache
1311 UserProfileCacheEntry uce = null;
1312 lock(m_profilesCache)
1313 {
1314 if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null)
1315 {
1316 uce.props = null;
1317 }
1318 }
1319
982 } 1320 }
983 1321
984 public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID) 1322 public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
@@ -990,13 +1328,55 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
990 return; 1328 return;
991 } 1329 }
992 1330
993 // Can't handle NPC yet...
994 ScenePresence p = FindPresence(avatarID); 1331 ScenePresence p = FindPresence(avatarID);
995 1332 if (p != null && p.IsNPC)
996 if (null != p)
997 { 1333 {
998 if (p.PresenceType == PresenceType.Npc) 1334 remoteClient.SendAvatarProperties(avatarID, ((INPC)(p.ControllingClient)).profileAbout, ((INPC)(p.ControllingClient)).Born,
999 return; 1335 Utils.StringToBytes("Non Player Character (NPC)"), "NPCs have no life", 0x10,
1336 UUID.Zero, ((INPC)(p.ControllingClient)).profileImage, "", UUID.Zero);
1337 remoteClient.SendAvatarInterestsReply(avatarID, 0, "",
1338 0, "Getting into trouble", "Droidspeak");
1339 return;
1340 }
1341 UserProfileProperties props;
1342 UserProfileCacheEntry uce = null;
1343 lock(m_profilesCache)
1344 {
1345 if(m_profilesCache.TryGetValue(avatarID, out uce) && uce != null)
1346 {
1347 if(uce.props != null)
1348 {
1349 props = uce.props;
1350 uint cflags = uce.flags;
1351 // if on same region force online
1352 if(p != null && !p.IsDeleted)
1353 cflags |= 0x10;
1354
1355 remoteClient.SendAvatarProperties(props.UserId, props.AboutText,
1356 uce.born, uce.membershipType , props.FirstLifeText, cflags,
1357 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
1358
1359 remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask,
1360 props.WantToText, (uint)props.SkillsMask,
1361 props.SkillsText, props.Language);
1362 return;
1363 }
1364 else
1365 {
1366 if(uce.ClientsWaitingProps == null)
1367 uce.ClientsWaitingProps = new HashSet<IClientAPI>();
1368 else if(uce.ClientsWaitingProps.Contains(remoteClient))
1369 return;
1370 uce.ClientsWaitingProps.Add(remoteClient);
1371 }
1372 }
1373 else
1374 {
1375 uce = new UserProfileCacheEntry();
1376 uce.ClientsWaitingProps = new HashSet<IClientAPI>();
1377 uce.ClientsWaitingProps.Add(remoteClient);
1378 m_profilesCache.AddOrUpdate(avatarID, uce, PROFILECACHEEXPIRE);
1379 }
1000 } 1380 }
1001 1381
1002 string serverURI = string.Empty; 1382 string serverURI = string.Empty;
@@ -1014,20 +1394,16 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1014 userInfo = new Dictionary<string, object>(); 1394 userInfo = new Dictionary<string, object>();
1015 } 1395 }
1016 1396
1017 Byte[] charterMember = new Byte[1]; 1397 Byte[] membershipType = new Byte[1];
1018 string born = String.Empty; 1398 string born = string.Empty;
1019 uint flags = 0x00; 1399 uint flags = 0x00;
1020 1400
1021 if (null != account) 1401 if (null != account)
1022 { 1402 {
1023 if (account.UserTitle == "") 1403 if (account.UserTitle == "")
1024 { 1404 membershipType[0] = (Byte)((account.UserFlags & 0xf00) >> 8);
1025 charterMember[0] = (Byte)((account.UserFlags & 0xf00) >> 8);
1026 }
1027 else 1405 else
1028 { 1406 membershipType = Utils.StringToBytes(account.UserTitle);
1029 charterMember = Utils.StringToBytes(account.UserTitle);
1030 }
1031 1407
1032 born = Util.ToDateTime(account.Created).ToString( 1408 born = Util.ToDateTime(account.Created).ToString(
1033 "M/d/yyyy", CultureInfo.InvariantCulture); 1409 "M/d/yyyy", CultureInfo.InvariantCulture);
@@ -1038,16 +1414,13 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1038 if (GetUserAccountData(avatarID, out userInfo) == true) 1414 if (GetUserAccountData(avatarID, out userInfo) == true)
1039 { 1415 {
1040 if ((string)userInfo["user_title"] == "") 1416 if ((string)userInfo["user_title"] == "")
1041 { 1417 membershipType[0] = (Byte)(((Byte)userInfo["user_flags"] & 0xf00) >> 8);
1042 charterMember[0] = (Byte)(((Byte)userInfo["user_flags"] & 0xf00) >> 8);
1043 }
1044 else 1418 else
1045 { 1419 membershipType = Utils.StringToBytes((string)userInfo["user_title"]);
1046 charterMember = Utils.StringToBytes((string)userInfo["user_title"]);
1047 }
1048 1420
1049 int val_born = (int)userInfo["user_created"]; 1421 int val_born = (int)userInfo["user_created"];
1050 born = Util.ToDateTime(val_born).ToString( 1422 if(val_born != 0)
1423 born = Util.ToDateTime(val_born).ToString(
1051 "M/d/yyyy", CultureInfo.InvariantCulture); 1424 "M/d/yyyy", CultureInfo.InvariantCulture);
1052 1425
1053 // picky, picky 1426 // picky, picky
@@ -1056,23 +1429,60 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1056 } 1429 }
1057 } 1430 }
1058 1431
1059 UserProfileProperties props = new UserProfileProperties(); 1432 props = new UserProfileProperties();
1433 props.UserId = avatarID;
1434
1060 string result = string.Empty; 1435 string result = string.Empty;
1436 if(!GetProfileData(ref props, foreign, serverURI, out result))
1437 {
1438 props.AboutText ="Profile not available at this time. User may still be unknown to this grid";
1439 }
1061 1440
1062 props.UserId = avatarID; 1441 if(!m_allowUserProfileWebURLs)
1442 props.WebUrl ="";
1063 1443
1064 if (!GetProfileData(ref props, foreign, out result)) 1444 HashSet<IClientAPI> clients;
1445 lock(m_profilesCache)
1065 { 1446 {
1066// m_log.DebugFormat("Error getting profile for {0}: {1}", avatarID, result); 1447 if(!m_profilesCache.TryGetValue(props.UserId, out uce) || uce == null)
1067 return; 1448 uce = new UserProfileCacheEntry();
1449 uce.props = props;
1450 uce.born = born;
1451 uce.membershipType = membershipType;
1452 uce.flags = flags;
1453 clients = uce.ClientsWaitingProps;
1454 uce.ClientsWaitingProps = null;
1455 m_profilesCache.AddOrUpdate(props.UserId, uce, PROFILECACHEEXPIRE);
1068 } 1456 }
1069 1457
1070 remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags, 1458 // if on same region force online
1459 if(p != null && !p.IsDeleted)
1460 flags |= 0x10;
1461
1462 if(clients == null)
1463 {
1464 remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType , props.FirstLifeText, flags,
1071 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId); 1465 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
1072 1466
1467 remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
1468 (uint)props.SkillsMask, props.SkillsText, props.Language);
1469 }
1470 else
1471 {
1472 if(!clients.Contains(remoteClient))
1473 clients.Add(remoteClient);
1474 foreach(IClientAPI cli in clients)
1475 {
1476 if(!cli.IsActive)
1477 continue;
1478 cli.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType , props.FirstLifeText, flags,
1479 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
1480
1481 cli.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
1482 (uint)props.SkillsMask, props.SkillsText, props.Language);
1073 1483
1074 remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText, (uint)props.SkillsMask, 1484 }
1075 props.SkillsText, props.Language); 1485 }
1076 } 1486 }
1077 1487
1078 /// <summary> 1488 /// <summary>
@@ -1088,6 +1498,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1088 { 1498 {
1089 if (remoteClient.AgentId == newProfile.ID) 1499 if (remoteClient.AgentId == newProfile.ID)
1090 { 1500 {
1501
1091 UserProfileProperties prop = new UserProfileProperties(); 1502 UserProfileProperties prop = new UserProfileProperties();
1092 1503
1093 prop.UserId = remoteClient.AgentId; 1504 prop.UserId = remoteClient.AgentId;
@@ -1097,6 +1508,9 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1097 prop.FirstLifeImageId = newProfile.FirstLifeImage; 1508 prop.FirstLifeImageId = newProfile.FirstLifeImage;
1098 prop.FirstLifeText = newProfile.FirstLifeAboutText; 1509 prop.FirstLifeText = newProfile.FirstLifeAboutText;
1099 1510
1511 if(!m_allowUserProfileWebURLs)
1512 prop.WebUrl ="";
1513
1100 string serverURI = string.Empty; 1514 string serverURI = string.Empty;
1101 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 1515 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
1102 1516
@@ -1109,6 +1523,16 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1109 return; 1523 return;
1110 } 1524 }
1111 1525
1526 // flush cache
1527 UserProfileCacheEntry uce = null;
1528 lock(m_profilesCache)
1529 {
1530 if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce != null)
1531 {
1532 uce.props = null;
1533 }
1534 }
1535
1112 RequestAvatarProperties(remoteClient, newProfile.ID); 1536 RequestAvatarProperties(remoteClient, newProfile.ID);
1113 } 1537 }
1114 } 1538 }
@@ -1119,28 +1543,11 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1119 /// <returns> 1543 /// <returns>
1120 /// The profile data. 1544 /// The profile data.
1121 /// </returns> 1545 /// </returns>
1122 bool GetProfileData(ref UserProfileProperties properties, bool foreign, out string message) 1546 bool GetProfileData(ref UserProfileProperties properties, bool foreign, string serverURI, out string message)
1123 { 1547 {
1124 // Can't handle NPC yet...
1125 ScenePresence p = FindPresence(properties.UserId);
1126
1127 if (null != p)
1128 {
1129 if (p.PresenceType == PresenceType.Npc)
1130 {
1131 message = "Id points to NPC";
1132 return false;
1133 }
1134 }
1135
1136 string serverURI = string.Empty;
1137 GetUserProfileServerURI(properties.UserId, out serverURI);
1138
1139 // This is checking a friend on the home grid
1140 // Not HG friend
1141 if (String.IsNullOrEmpty(serverURI)) 1548 if (String.IsNullOrEmpty(serverURI))
1142 { 1549 {
1143 message = "No Presence - foreign friend"; 1550 message = "User profile service unknown at this time";
1144 return false; 1551 return false;
1145 } 1552 }
1146 1553
@@ -1161,7 +1568,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1161 { 1568 {
1162 m_log.Debug( 1569 m_log.Debug(
1163 string.Format( 1570 string.Format(
1164 "[PROFILES]: Request using the OpenProfile API for user {0} to {1} failed", 1571 "[PROFILES]: Request using the OpenProfile API for user {0} to {1} failed",
1165 properties.UserId, serverURI), 1572 properties.UserId, serverURI),
1166 e); 1573 e);
1167 1574
@@ -1178,10 +1585,14 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1178 1585
1179 return false; 1586 return false;
1180 } 1587 }
1181 // else, continue below
1182 } 1588 }
1183 1589
1184 properties = (UserProfileProperties)Prop; 1590 properties = (UserProfileProperties)Prop;
1591 if(foreign)
1592 {
1593 cacheForeignImage(properties.UserId, properties.ImageId);
1594 cacheForeignImage(properties.UserId, properties.FirstLifeImageId);
1595 }
1185 1596
1186 message = "Success"; 1597 message = "Success";
1187 return true; 1598 return true;
@@ -1189,49 +1600,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1189 #endregion Avatar Properties 1600 #endregion Avatar Properties
1190 1601
1191 #region Utils 1602 #region Utils
1192 bool GetImageAssets(UUID avatarId)
1193 {
1194 string profileServerURI = string.Empty;
1195 string assetServerURI = string.Empty;
1196
1197 bool foreign = GetUserProfileServerURI(avatarId, out profileServerURI);
1198
1199 if(!foreign)
1200 return true;
1201
1202 assetServerURI = UserManagementModule.GetUserServerURL(avatarId, "AssetServerURI");
1203
1204 if(string.IsNullOrEmpty(profileServerURI) || string.IsNullOrEmpty(assetServerURI))
1205 return false;
1206
1207 OSDMap parameters= new OSDMap();
1208 parameters.Add("avatarId", OSD.FromUUID(avatarId));
1209 OSD Params = (OSD)parameters;
1210 if(!rpc.JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString()))
1211 {
1212 return false;
1213 }
1214
1215 parameters = (OSDMap)Params;
1216
1217 if (parameters.ContainsKey("result"))
1218 {
1219 OSDArray list = (OSDArray)parameters["result"];
1220
1221 foreach (OSD asset in list)
1222 {
1223 OSDString assetId = (OSDString)asset;
1224
1225 Scene.AssetService.Get(string.Format("{0}/{1}", assetServerURI, assetId.AsString()));
1226 }
1227 return true;
1228 }
1229 else
1230 {
1231 m_log.ErrorFormat("[PROFILES]: Problematic response for image_assets_request from {0}", profileServerURI);
1232 return false;
1233 }
1234 }
1235 1603
1236 /// <summary> 1604 /// <summary>
1237 /// Gets the user account data. 1605 /// Gets the user account data.
@@ -1336,7 +1704,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1336 { 1704 {
1337 bool local; 1705 bool local;
1338 local = UserManagementModule.IsLocalGridUser(userID); 1706 local = UserManagementModule.IsLocalGridUser(userID);
1339 1707
1340 if (!local) 1708 if (!local)
1341 { 1709 {
1342 serverURI = UserManagementModule.GetUserServerURL(userID, "GatekeeperURI"); 1710 serverURI = UserManagementModule.GetUserServerURL(userID, "GatekeeperURI");
@@ -1382,6 +1750,27 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1382 } 1750 }
1383 } 1751 }
1384 1752
1753 void cacheForeignImage(UUID agent, UUID imageID)
1754 {
1755 if(imageID == null || imageID == UUID.Zero)
1756 return;
1757
1758 string assetServerURI = UserManagementModule.GetUserServerURL(agent, "AssetServerURI");
1759 if(string.IsNullOrWhiteSpace(assetServerURI))
1760 return;
1761
1762 string imageIDstr = imageID.ToString();
1763
1764
1765 if(m_assetCache != null && m_assetCache.Check(imageIDstr))
1766 return;
1767
1768 if(Scene.AssetService.Get(imageIDstr) != null)
1769 return;
1770
1771 Scene.AssetService.Get(string.Format("{0}/{1}", assetServerURI, imageIDstr));
1772 }
1773
1385 /// <summary> 1774 /// <summary>
1386 /// Finds the presence. 1775 /// Finds the presence.
1387 /// </summary> 1776 /// </summary>
@@ -1402,5 +1791,180 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1402 return null; 1791 return null;
1403 } 1792 }
1404 #endregion Util 1793 #endregion Util
1794
1795 #region Web Util
1796 /// <summary>
1797 /// Sends json-rpc request with a serializable type.
1798 /// </summary>
1799 /// <returns>
1800 /// OSD Map.
1801 /// </returns>
1802 /// <param name='parameters'>
1803 /// Serializable type .
1804 /// </param>
1805 /// <param name='method'>
1806 /// Json-rpc method to call.
1807 /// </param>
1808 /// <param name='uri'>
1809 /// URI of json-rpc service.
1810 /// </param>
1811 /// <param name='jsonId'>
1812 /// Id for our call.
1813 /// </param>
1814 bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
1815 {
1816 if (jsonId == null)
1817 throw new ArgumentNullException ("jsonId");
1818 if (uri == null)
1819 throw new ArgumentNullException ("uri");
1820 if (method == null)
1821 throw new ArgumentNullException ("method");
1822 if (parameters == null)
1823 throw new ArgumentNullException ("parameters");
1824
1825 // Prep our payload
1826 OSDMap json = new OSDMap();
1827
1828 json.Add("jsonrpc", OSD.FromString("2.0"));
1829 json.Add("id", OSD.FromString(jsonId));
1830 json.Add("method", OSD.FromString(method));
1831
1832 json.Add("params", OSD.SerializeMembers(parameters));
1833
1834 string jsonRequestData = OSDParser.SerializeJsonString(json);
1835 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1836
1837 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1838
1839 webRequest.ContentType = "application/json-rpc";
1840 webRequest.Method = "POST";
1841
1842 WebResponse webResponse = null;
1843 try
1844 {
1845 using(Stream dataStream = webRequest.GetRequestStream())
1846 dataStream.Write(content,0,content.Length);
1847
1848 webResponse = webRequest.GetResponse();
1849 }
1850 catch (WebException e)
1851 {
1852 Console.WriteLine("Web Error" + e.Message);
1853 Console.WriteLine ("Please check input");
1854 return false;
1855 }
1856
1857 OSDMap mret = new OSDMap();
1858
1859 using (Stream rstream = webResponse.GetResponseStream())
1860 {
1861 try
1862 {
1863 mret = (OSDMap)OSDParser.DeserializeJson(rstream);
1864 }
1865 catch (Exception e)
1866 {
1867 m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
1868 if (webResponse != null)
1869 webResponse.Close();
1870 return false;
1871 }
1872 }
1873
1874 if (webResponse != null)
1875 webResponse.Close();
1876
1877 if (mret.ContainsKey("error"))
1878 return false;
1879
1880 // get params...
1881 OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]);
1882 return true;
1883 }
1884
1885 /// <summary>
1886 /// Sends json-rpc request with OSD parameter.
1887 /// </summary>
1888 /// <returns>
1889 /// The rpc request.
1890 /// </returns>
1891 /// <param name='data'>
1892 /// data - incoming as parameters, outgong as result/error
1893 /// </param>
1894 /// <param name='method'>
1895 /// Json-rpc method to call.
1896 /// </param>
1897 /// <param name='uri'>
1898 /// URI of json-rpc service.
1899 /// </param>
1900 /// <param name='jsonId'>
1901 /// If set to <c>true</c> json identifier.
1902 /// </param>
1903 bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
1904 {
1905 OSDMap map = new OSDMap();
1906
1907 map["jsonrpc"] = "2.0";
1908 if(string.IsNullOrEmpty(jsonId))
1909 map["id"] = UUID.Random().ToString();
1910 else
1911 map["id"] = jsonId;
1912
1913 map["method"] = method;
1914 map["params"] = data;
1915
1916 string jsonRequestData = OSDParser.SerializeJsonString(map);
1917 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1918
1919 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1920 webRequest.ContentType = "application/json-rpc";
1921 webRequest.Method = "POST";
1922
1923 WebResponse webResponse = null;
1924 try
1925 {
1926 using(Stream dataStream = webRequest.GetRequestStream())
1927 dataStream.Write(content,0,content.Length);
1928
1929 webResponse = webRequest.GetResponse();
1930 }
1931 catch (WebException e)
1932 {
1933 Console.WriteLine("Web Error" + e.Message);
1934 Console.WriteLine ("Please check input");
1935 return false;
1936 }
1937
1938 OSDMap response = new OSDMap();
1939
1940 using (Stream rstream = webResponse.GetResponseStream())
1941 {
1942 try
1943 {
1944 response = (OSDMap)OSDParser.DeserializeJson(rstream);
1945 }
1946 catch (Exception e)
1947 {
1948 m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
1949 if (webResponse != null)
1950 webResponse.Close();
1951 return false;
1952 }
1953 }
1954
1955 if (webResponse != null)
1956 webResponse.Close();
1957
1958 if(response.ContainsKey("error"))
1959 {
1960 data = response["error"];
1961 return false;
1962 }
1963
1964 data = response;
1965
1966 return true;
1967 }
1968 #endregion Web Util
1405 } 1969 }
1406} 1970}