UserProfileModule.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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. using System;
  28. using System.IO;
  29. using System.Text;
  30. using System.Collections;
  31. using System.Collections.Generic;
  32. using System.Globalization;
  33. using System.Net;
  34. using System.Net.Sockets;
  35. using System.Reflection;
  36. using System.Xml;
  37. using OpenMetaverse;
  38. using OpenMetaverse.StructuredData;
  39. using log4net;
  40. using Nini.Config;
  41. using Nwc.XmlRpc;
  42. using OpenSim.Framework;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Services.Interfaces;
  46. using Mono.Addins;
  47. using OpenSim.Services.Connectors.Hypergrid;
  48. namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
  49. {
  50. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")]
  51. public class UserProfileModule : IProfileModule, INonSharedRegionModule
  52. {
  53. /// <summary>
  54. /// Logging
  55. /// </summary>
  56. static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  57. // The pair of Dictionaries are used to handle the switching of classified ads
  58. // by maintaining a cache of classified id to creator id mappings and an interest
  59. // count. The entries are removed when the interest count reaches 0.
  60. Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>();
  61. Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>();
  62. public Scene Scene
  63. {
  64. get; private set;
  65. }
  66. /// <summary>
  67. /// Gets or sets the ConfigSource.
  68. /// </summary>
  69. /// <value>
  70. /// The configuration
  71. /// </value>
  72. public IConfigSource Config {
  73. get;
  74. set;
  75. }
  76. /// <summary>
  77. /// Gets or sets the URI to the profile server.
  78. /// </summary>
  79. /// <value>
  80. /// The profile server URI.
  81. /// </value>
  82. public string ProfileServerUri {
  83. get;
  84. set;
  85. }
  86. IProfileModule ProfileModule
  87. {
  88. get; set;
  89. }
  90. IUserManagement UserManagementModule
  91. {
  92. get; set;
  93. }
  94. /// <summary>
  95. /// Gets or sets a value indicating whether this
  96. /// <see cref="OpenSim.Region.Coremodules.UserProfiles.UserProfileModule"/> is enabled.
  97. /// </summary>
  98. /// <value>
  99. /// <c>true</c> if enabled; otherwise, <c>false</c>.
  100. /// </value>
  101. public bool Enabled {
  102. get;
  103. set;
  104. }
  105. #region IRegionModuleBase implementation
  106. /// <summary>
  107. /// This is called to initialize the region module. For shared modules, this is called exactly once, after
  108. /// creating the single (shared) instance. For non-shared modules, this is called once on each instance, after
  109. /// the instace for the region has been created.
  110. /// </summary>
  111. /// <param name='source'>
  112. /// Source.
  113. /// </param>
  114. public void Initialise(IConfigSource source)
  115. {
  116. Config = source;
  117. ReplaceableInterface = typeof(IProfileModule);
  118. IConfig profileConfig = Config.Configs["UserProfiles"];
  119. if (profileConfig == null)
  120. {
  121. m_log.Debug("[PROFILES]: UserProfiles disabled, no configuration");
  122. Enabled = false;
  123. return;
  124. }
  125. // If we find ProfileURL then we configure for FULL support
  126. // else we setup for BASIC support
  127. ProfileServerUri = profileConfig.GetString("ProfileServiceURL", "");
  128. if (ProfileServerUri == "")
  129. {
  130. Enabled = false;
  131. return;
  132. }
  133. m_log.Debug("[PROFILES]: Full Profiles Enabled");
  134. ReplaceableInterface = null;
  135. Enabled = true;
  136. }
  137. /// <summary>
  138. /// Adds the region.
  139. /// </summary>
  140. /// <param name='scene'>
  141. /// Scene.
  142. /// </param>
  143. public void AddRegion(Scene scene)
  144. {
  145. if(!Enabled)
  146. return;
  147. Scene = scene;
  148. Scene.RegisterModuleInterface<IProfileModule>(this);
  149. Scene.EventManager.OnNewClient += OnNewClient;
  150. Scene.EventManager.OnMakeRootAgent += HandleOnMakeRootAgent;
  151. UserManagementModule = Scene.RequestModuleInterface<IUserManagement>();
  152. }
  153. void HandleOnMakeRootAgent (ScenePresence obj)
  154. {
  155. if(obj.PresenceType == PresenceType.Npc)
  156. return;
  157. Util.FireAndForget(delegate
  158. {
  159. GetImageAssets(((IScenePresence)obj).UUID);
  160. });
  161. }
  162. /// <summary>
  163. /// Removes the region.
  164. /// </summary>
  165. /// <param name='scene'>
  166. /// Scene.
  167. /// </param>
  168. public void RemoveRegion(Scene scene)
  169. {
  170. if(!Enabled)
  171. return;
  172. }
  173. /// <summary>
  174. /// This will be called once for every scene loaded. In a shared module this will be multiple times in one
  175. /// instance, while a nonshared module instance will only be called once. This method is called after AddRegion
  176. /// has been called in all modules for that scene, providing an opportunity to request another module's
  177. /// interface, or hook an event from another module.
  178. /// </summary>
  179. /// <param name='scene'>
  180. /// Scene.
  181. /// </param>
  182. public void RegionLoaded(Scene scene)
  183. {
  184. if(!Enabled)
  185. return;
  186. }
  187. /// <summary>
  188. /// If this returns non-null, it is the type of an interface that this module intends to register. This will
  189. /// cause the loader to defer loading of this module until all other modules have been loaded. If no other
  190. /// module has registered the interface by then, this module will be activated, else it will remain inactive,
  191. /// letting the other module take over. This should return non-null ONLY in modules that are intended to be
  192. /// easily replaceable, e.g. stub implementations that the developer expects to be replaced by third party
  193. /// provided modules.
  194. /// </summary>
  195. /// <value>
  196. /// The replaceable interface.
  197. /// </value>
  198. public Type ReplaceableInterface
  199. {
  200. get; private set;
  201. }
  202. /// <summary>
  203. /// Called as the instance is closed.
  204. /// </summary>
  205. public void Close()
  206. {
  207. }
  208. /// <value>
  209. /// The name of the module
  210. /// </value>
  211. /// <summary>
  212. /// Gets the module name.
  213. /// </summary>
  214. public string Name
  215. {
  216. get { return "UserProfileModule"; }
  217. }
  218. #endregion IRegionModuleBase implementation
  219. #region Region Event Handlers
  220. /// <summary>
  221. /// Raises the new client event.
  222. /// </summary>
  223. /// <param name='client'>
  224. /// Client.
  225. /// </param>
  226. void OnNewClient(IClientAPI client)
  227. {
  228. //Profile
  229. client.OnRequestAvatarProperties += RequestAvatarProperties;
  230. client.OnUpdateAvatarProperties += AvatarPropertiesUpdate;
  231. client.OnAvatarInterestUpdate += AvatarInterestsUpdate;
  232. // Classifieds
  233. client.AddGenericPacketHandler("avatarclassifiedsrequest", ClassifiedsRequest);
  234. client.OnClassifiedInfoUpdate += ClassifiedInfoUpdate;
  235. client.OnClassifiedInfoRequest += ClassifiedInfoRequest;
  236. client.OnClassifiedDelete += ClassifiedDelete;
  237. // Picks
  238. client.AddGenericPacketHandler("avatarpicksrequest", PicksRequest);
  239. client.AddGenericPacketHandler("pickinforequest", PickInfoRequest);
  240. client.OnPickInfoUpdate += PickInfoUpdate;
  241. client.OnPickDelete += PickDelete;
  242. // Notes
  243. client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest);
  244. client.OnAvatarNotesUpdate += NotesUpdate;
  245. }
  246. #endregion Region Event Handlers
  247. #region Classified
  248. ///
  249. /// <summary>
  250. /// Handles the avatar classifieds request.
  251. /// </summary>
  252. /// <param name='sender'>
  253. /// Sender.
  254. /// </param>
  255. /// <param name='method'>
  256. /// Method.
  257. /// </param>
  258. /// <param name='args'>
  259. /// Arguments.
  260. /// </param>
  261. public void ClassifiedsRequest(Object sender, string method, List<String> args)
  262. {
  263. if (!(sender is IClientAPI))
  264. return;
  265. IClientAPI remoteClient = (IClientAPI)sender;
  266. UUID targetID;
  267. UUID.TryParse(args[0], out targetID);
  268. // Can't handle NPC yet...
  269. ScenePresence p = FindPresence(targetID);
  270. if (null != p)
  271. {
  272. if (p.PresenceType == PresenceType.Npc)
  273. return;
  274. }
  275. string serverURI = string.Empty;
  276. GetUserProfileServerURI(targetID, out serverURI);
  277. UUID creatorId = UUID.Zero;
  278. OSDMap parameters= new OSDMap();
  279. UUID.TryParse(args[0], out creatorId);
  280. parameters.Add("creatorId", OSD.FromUUID(creatorId));
  281. OSD Params = (OSD)parameters;
  282. if(!JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
  283. {
  284. // Error Handling here!
  285. // if(parameters.ContainsKey("message")
  286. }
  287. parameters = (OSDMap)Params;
  288. OSDArray list = (OSDArray)parameters["result"];
  289. Dictionary<UUID, string> classifieds = new Dictionary<UUID, string>();
  290. foreach(OSD map in list)
  291. {
  292. OSDMap m = (OSDMap)map;
  293. UUID cid = m["classifieduuid"].AsUUID();
  294. string name = m["name"].AsString();
  295. classifieds[cid] = name;
  296. lock (m_classifiedCache)
  297. {
  298. if (!m_classifiedCache.ContainsKey(cid))
  299. {
  300. m_classifiedCache.Add(cid,creatorId);
  301. m_classifiedInterest.Add(cid, 0);
  302. }
  303. m_classifiedInterest[cid]++;
  304. }
  305. }
  306. remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds);
  307. }
  308. public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient)
  309. {
  310. UUID target = remoteClient.AgentId;
  311. UserClassifiedAdd ad = new UserClassifiedAdd();
  312. ad.ClassifiedId = queryClassifiedID;
  313. lock (m_classifiedCache)
  314. {
  315. if (m_classifiedCache.ContainsKey(queryClassifiedID))
  316. {
  317. target = m_classifiedCache[queryClassifiedID];
  318. m_classifiedInterest[queryClassifiedID] --;
  319. if (m_classifiedInterest[queryClassifiedID] == 0)
  320. {
  321. m_classifiedInterest.Remove(queryClassifiedID);
  322. m_classifiedCache.Remove(queryClassifiedID);
  323. }
  324. }
  325. }
  326. string serverURI = string.Empty;
  327. GetUserProfileServerURI(target, out serverURI);
  328. object Ad = (object)ad;
  329. if(!JsonRpcRequest(ref Ad, "classifieds_info_query", serverURI, UUID.Random().ToString()))
  330. {
  331. remoteClient.SendAgentAlertMessage(
  332. "Error getting classified info", false);
  333. return;
  334. }
  335. ad = (UserClassifiedAdd) Ad;
  336. if(ad.CreatorId == UUID.Zero)
  337. return;
  338. Vector3 globalPos = new Vector3();
  339. Vector3.TryParse(ad.GlobalPos, out globalPos);
  340. remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, (uint)ad.ExpirationDate,
  341. (uint)ad.Category, ad.Name, ad.Description, ad.ParcelId, (uint)ad.ParentEstate,
  342. ad.SnapshotId, ad.SimName, globalPos, ad.ParcelName, ad.Flags, ad.Price);
  343. }
  344. /// <summary>
  345. /// Classifieds info update.
  346. /// </summary>
  347. /// <param name='queryclassifiedID'>
  348. /// Queryclassified I.
  349. /// </param>
  350. /// <param name='queryCategory'>
  351. /// Query category.
  352. /// </param>
  353. /// <param name='queryName'>
  354. /// Query name.
  355. /// </param>
  356. /// <param name='queryDescription'>
  357. /// Query description.
  358. /// </param>
  359. /// <param name='queryParcelID'>
  360. /// Query parcel I.
  361. /// </param>
  362. /// <param name='queryParentEstate'>
  363. /// Query parent estate.
  364. /// </param>
  365. /// <param name='querySnapshotID'>
  366. /// Query snapshot I.
  367. /// </param>
  368. /// <param name='queryGlobalPos'>
  369. /// Query global position.
  370. /// </param>
  371. /// <param name='queryclassifiedFlags'>
  372. /// Queryclassified flags.
  373. /// </param>
  374. /// <param name='queryclassifiedPrice'>
  375. /// Queryclassified price.
  376. /// </param>
  377. /// <param name='remoteClient'>
  378. /// Remote client.
  379. /// </param>
  380. public void ClassifiedInfoUpdate(UUID queryclassifiedID, uint queryCategory, string queryName, string queryDescription, UUID queryParcelID,
  381. uint queryParentEstate, UUID querySnapshotID, Vector3 queryGlobalPos, byte queryclassifiedFlags,
  382. int queryclassifiedPrice, IClientAPI remoteClient)
  383. {
  384. UserClassifiedAdd ad = new UserClassifiedAdd();
  385. Scene s = (Scene) remoteClient.Scene;
  386. Vector3 pos = remoteClient.SceneAgent.AbsolutePosition;
  387. ILandObject land = s.LandChannel.GetLandObject(pos.X, pos.Y);
  388. ScenePresence p = FindPresence(remoteClient.AgentId);
  389. // Vector3 avaPos = p.AbsolutePosition;
  390. string serverURI = string.Empty;
  391. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  392. if (land == null)
  393. {
  394. ad.ParcelName = string.Empty;
  395. }
  396. else
  397. {
  398. ad.ParcelName = land.LandData.Name;
  399. }
  400. ad.CreatorId = remoteClient.AgentId;
  401. ad.ClassifiedId = queryclassifiedID;
  402. ad.Category = Convert.ToInt32(queryCategory);
  403. ad.Name = queryName;
  404. ad.Description = queryDescription;
  405. ad.ParentEstate = Convert.ToInt32(queryParentEstate);
  406. ad.SnapshotId = querySnapshotID;
  407. ad.SimName = remoteClient.Scene.RegionInfo.RegionName;
  408. ad.GlobalPos = queryGlobalPos.ToString ();
  409. ad.Flags = queryclassifiedFlags;
  410. ad.Price = queryclassifiedPrice;
  411. ad.ParcelId = p.currentParcelUUID;
  412. object Ad = ad;
  413. OSD.SerializeMembers(Ad);
  414. if(!JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString()))
  415. {
  416. remoteClient.SendAgentAlertMessage(
  417. "Error updating classified", false);
  418. }
  419. }
  420. /// <summary>
  421. /// Classifieds delete.
  422. /// </summary>
  423. /// <param name='queryClassifiedID'>
  424. /// Query classified I.
  425. /// </param>
  426. /// <param name='remoteClient'>
  427. /// Remote client.
  428. /// </param>
  429. public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient)
  430. {
  431. string serverURI = string.Empty;
  432. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  433. UUID classifiedId;
  434. OSDMap parameters= new OSDMap();
  435. UUID.TryParse(queryClassifiedID.ToString(), out classifiedId);
  436. parameters.Add("classifiedId", OSD.FromUUID(classifiedId));
  437. OSD Params = (OSD)parameters;
  438. if(!JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString()))
  439. {
  440. remoteClient.SendAgentAlertMessage(
  441. "Error classified delete", false);
  442. }
  443. parameters = (OSDMap)Params;
  444. }
  445. #endregion Classified
  446. #region Picks
  447. /// <summary>
  448. /// Handles the avatar picks request.
  449. /// </summary>
  450. /// <param name='sender'>
  451. /// Sender.
  452. /// </param>
  453. /// <param name='method'>
  454. /// Method.
  455. /// </param>
  456. /// <param name='args'>
  457. /// Arguments.
  458. /// </param>
  459. public void PicksRequest(Object sender, string method, List<String> args)
  460. {
  461. if (!(sender is IClientAPI))
  462. return;
  463. IClientAPI remoteClient = (IClientAPI)sender;
  464. UUID targetId;
  465. UUID.TryParse(args[0], out targetId);
  466. // Can't handle NPC yet...
  467. ScenePresence p = FindPresence(targetId);
  468. if (null != p)
  469. {
  470. if (p.PresenceType == PresenceType.Npc)
  471. return;
  472. }
  473. string serverURI = string.Empty;
  474. GetUserProfileServerURI(targetId, out serverURI);
  475. OSDMap parameters= new OSDMap();
  476. parameters.Add("creatorId", OSD.FromUUID(targetId));
  477. OSD Params = (OSD)parameters;
  478. if(!JsonRpcRequest(ref Params, "avatarpicksrequest", serverURI, UUID.Random().ToString()))
  479. {
  480. remoteClient.SendAgentAlertMessage(
  481. "Error requesting picks", false);
  482. return;
  483. }
  484. parameters = (OSDMap)Params;
  485. OSDArray list = (OSDArray)parameters["result"];
  486. Dictionary<UUID, string> picks = new Dictionary<UUID, string>();
  487. foreach(OSD map in list)
  488. {
  489. OSDMap m = (OSDMap)map;
  490. UUID cid = m["pickuuid"].AsUUID();
  491. string name = m["name"].AsString();
  492. m_log.DebugFormat("[PROFILES]: PicksRequest {0}", name);
  493. picks[cid] = name;
  494. }
  495. remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks);
  496. }
  497. /// <summary>
  498. /// Handles the pick info request.
  499. /// </summary>
  500. /// <param name='sender'>
  501. /// Sender.
  502. /// </param>
  503. /// <param name='method'>
  504. /// Method.
  505. /// </param>
  506. /// <param name='args'>
  507. /// Arguments.
  508. /// </param>
  509. public void PickInfoRequest(Object sender, string method, List<String> args)
  510. {
  511. if (!(sender is IClientAPI))
  512. return;
  513. UUID targetID;
  514. UUID.TryParse(args[0], out targetID);
  515. string serverURI = string.Empty;
  516. GetUserProfileServerURI(targetID, out serverURI);
  517. IClientAPI remoteClient = (IClientAPI)sender;
  518. UserProfilePick pick = new UserProfilePick();
  519. UUID.TryParse(args[0], out pick.CreatorId);
  520. UUID.TryParse(args[1], out pick.PickId);
  521. object Pick = (object)pick;
  522. if(!JsonRpcRequest(ref Pick, "pickinforequest", serverURI, UUID.Random().ToString()))
  523. {
  524. remoteClient.SendAgentAlertMessage(
  525. "Error selecting pick", false);
  526. }
  527. pick = (UserProfilePick) Pick;
  528. if(pick.SnapshotId == UUID.Zero)
  529. {
  530. // In case of a new UserPick, the data may not be ready and we would send wrong data, skip it...
  531. m_log.DebugFormat("[PROFILES]: PickInfoRequest: SnapshotID is {0}", UUID.Zero.ToString());
  532. return;
  533. }
  534. Vector3 globalPos;
  535. Vector3.TryParse(pick.GlobalPos,out globalPos);
  536. m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());
  537. remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
  538. pick.Desc,pick.SnapshotId,pick.User,pick.OriginalName,pick.SimName,
  539. globalPos,pick.SortOrder,pick.Enabled);
  540. }
  541. /// <summary>
  542. /// Updates the userpicks
  543. /// </summary>
  544. /// <param name='remoteClient'>
  545. /// Remote client.
  546. /// </param>
  547. /// <param name='pickID'>
  548. /// Pick I.
  549. /// </param>
  550. /// <param name='creatorID'>
  551. /// the creator of the pick
  552. /// </param>
  553. /// <param name='topPick'>
  554. /// Top pick.
  555. /// </param>
  556. /// <param name='name'>
  557. /// Name.
  558. /// </param>
  559. /// <param name='desc'>
  560. /// Desc.
  561. /// </param>
  562. /// <param name='snapshotID'>
  563. /// Snapshot I.
  564. /// </param>
  565. /// <param name='sortOrder'>
  566. /// Sort order.
  567. /// </param>
  568. /// <param name='enabled'>
  569. /// Enabled.
  570. /// </param>
  571. public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
  572. {
  573. m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());
  574. UserProfilePick pick = new UserProfilePick();
  575. string serverURI = string.Empty;
  576. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  577. ScenePresence p = FindPresence(remoteClient.AgentId);
  578. Vector3 avaPos = p.AbsolutePosition;
  579. // Getting the global position for the Avatar
  580. Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionLocX*Constants.RegionSize + avaPos.X,
  581. remoteClient.Scene.RegionInfo.RegionLocY*Constants.RegionSize + avaPos.Y,
  582. avaPos.Z);
  583. string landOwnerName = string.Empty;
  584. ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);
  585. if(land.LandData.IsGroupOwned)
  586. {
  587. IGroupsModule groupMod = p.Scene.RequestModuleInterface<IGroupsModule>();
  588. UUID groupId = land.LandData.GroupID;
  589. GroupRecord groupRecord = groupMod.GetGroupRecord(groupId);
  590. landOwnerName = groupRecord.GroupName;
  591. }
  592. else
  593. {
  594. IUserAccountService accounts = p.Scene.RequestModuleInterface<IUserAccountService>();
  595. UserAccount user = accounts.GetUserAccount(p.Scene.RegionInfo.ScopeID, land.LandData.OwnerID);
  596. landOwnerName = user.Name;
  597. }
  598. pick.PickId = pickID;
  599. pick.CreatorId = creatorID;
  600. pick.TopPick = topPick;
  601. pick.Name = name;
  602. pick.Desc = desc;
  603. pick.ParcelId = p.currentParcelUUID;
  604. pick.SnapshotId = snapshotID;
  605. pick.User = landOwnerName;
  606. pick.SimName = remoteClient.Scene.RegionInfo.RegionName;
  607. pick.GlobalPos = posGlobal.ToString();
  608. pick.SortOrder = sortOrder;
  609. pick.Enabled = enabled;
  610. object Pick = (object)pick;
  611. if(!JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
  612. {
  613. remoteClient.SendAgentAlertMessage(
  614. "Error updating pick", false);
  615. }
  616. m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
  617. }
  618. /// <summary>
  619. /// Delete a Pick
  620. /// </summary>
  621. /// <param name='remoteClient'>
  622. /// Remote client.
  623. /// </param>
  624. /// <param name='queryPickID'>
  625. /// Query pick I.
  626. /// </param>
  627. public void PickDelete(IClientAPI remoteClient, UUID queryPickID)
  628. {
  629. string serverURI = string.Empty;
  630. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  631. OSDMap parameters= new OSDMap();
  632. parameters.Add("pickId", OSD.FromUUID(queryPickID));
  633. OSD Params = (OSD)parameters;
  634. if(!JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString()))
  635. {
  636. remoteClient.SendAgentAlertMessage(
  637. "Error picks delete", false);
  638. }
  639. }
  640. #endregion Picks
  641. #region Notes
  642. /// <summary>
  643. /// Handles the avatar notes request.
  644. /// </summary>
  645. /// <param name='sender'>
  646. /// Sender.
  647. /// </param>
  648. /// <param name='method'>
  649. /// Method.
  650. /// </param>
  651. /// <param name='args'>
  652. /// Arguments.
  653. /// </param>
  654. public void NotesRequest(Object sender, string method, List<String> args)
  655. {
  656. UserProfileNotes note = new UserProfileNotes();
  657. if (!(sender is IClientAPI))
  658. return;
  659. IClientAPI remoteClient = (IClientAPI)sender;
  660. string serverURI = string.Empty;
  661. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  662. note.TargetId = remoteClient.AgentId;
  663. UUID.TryParse(args[0], out note.UserId);
  664. object Note = (object)note;
  665. if(!JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
  666. {
  667. remoteClient.SendAgentAlertMessage(
  668. "Error requesting note", false);
  669. }
  670. note = (UserProfileNotes) Note;
  671. remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
  672. }
  673. /// <summary>
  674. /// Avatars the notes update.
  675. /// </summary>
  676. /// <param name='remoteClient'>
  677. /// Remote client.
  678. /// </param>
  679. /// <param name='queryTargetID'>
  680. /// Query target I.
  681. /// </param>
  682. /// <param name='queryNotes'>
  683. /// Query notes.
  684. /// </param>
  685. public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
  686. {
  687. UserProfileNotes note = new UserProfileNotes();
  688. note.UserId = remoteClient.AgentId;
  689. note.TargetId = queryTargetID;
  690. note.Notes = queryNotes;
  691. string serverURI = string.Empty;
  692. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  693. object Note = note;
  694. if(!JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
  695. {
  696. remoteClient.SendAgentAlertMessage(
  697. "Error updating note", false);
  698. }
  699. }
  700. #endregion Notes
  701. #region Avatar Properties
  702. /// <summary>
  703. /// Update the avatars interests .
  704. /// </summary>
  705. /// <param name='remoteClient'>
  706. /// Remote client.
  707. /// </param>
  708. /// <param name='wantmask'>
  709. /// Wantmask.
  710. /// </param>
  711. /// <param name='wanttext'>
  712. /// Wanttext.
  713. /// </param>
  714. /// <param name='skillsmask'>
  715. /// Skillsmask.
  716. /// </param>
  717. /// <param name='skillstext'>
  718. /// Skillstext.
  719. /// </param>
  720. /// <param name='languages'>
  721. /// Languages.
  722. /// </param>
  723. public void AvatarInterestsUpdate(IClientAPI remoteClient, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages)
  724. {
  725. UserProfileProperties prop = new UserProfileProperties();
  726. prop.UserId = remoteClient.AgentId;
  727. prop.WantToMask = (int)wantmask;
  728. prop.WantToText = wanttext;
  729. prop.SkillsMask = (int)skillsmask;
  730. prop.SkillsText = skillstext;
  731. prop.Language = languages;
  732. string serverURI = string.Empty;
  733. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  734. object Param = prop;
  735. if(!JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString()))
  736. {
  737. remoteClient.SendAgentAlertMessage(
  738. "Error updating interests", false);
  739. }
  740. }
  741. public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
  742. {
  743. if ( String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString()))
  744. {
  745. // Looking for a reason that some viewers are sending null Id's
  746. m_log.DebugFormat("[PROFILES]: This should not happen remoteClient.AgentId {0} - avatarID {1}", remoteClient.AgentId, avatarID);
  747. return;
  748. }
  749. // Can't handle NPC yet...
  750. ScenePresence p = FindPresence(avatarID);
  751. if (null != p)
  752. {
  753. if (p.PresenceType == PresenceType.Npc)
  754. return;
  755. }
  756. string serverURI = string.Empty;
  757. bool foreign = GetUserProfileServerURI(avatarID, out serverURI);
  758. UserAccount account = null;
  759. Dictionary<string,object> userInfo;
  760. if (!foreign)
  761. {
  762. account = Scene.UserAccountService.GetUserAccount(Scene.RegionInfo.ScopeID, avatarID);
  763. }
  764. else
  765. {
  766. userInfo = new Dictionary<string, object>();
  767. }
  768. Byte[] charterMember = new Byte[1];
  769. string born = String.Empty;
  770. uint flags = 0x00;
  771. if (null != account)
  772. {
  773. if (account.UserTitle == "")
  774. {
  775. charterMember[0] = (Byte)((account.UserFlags & 0xf00) >> 8);
  776. }
  777. else
  778. {
  779. charterMember = Utils.StringToBytes(account.UserTitle);
  780. }
  781. born = Util.ToDateTime(account.Created).ToString(
  782. "M/d/yyyy", CultureInfo.InvariantCulture);
  783. flags = (uint)(account.UserFlags & 0xff);
  784. }
  785. else
  786. {
  787. if (GetUserAccountData(avatarID, out userInfo) == true)
  788. {
  789. if ((string)userInfo["user_title"] == "")
  790. {
  791. charterMember[0] = (Byte)(((Byte)userInfo["user_flags"] & 0xf00) >> 8);
  792. }
  793. else
  794. {
  795. charterMember = Utils.StringToBytes((string)userInfo["user_title"]);
  796. }
  797. int val_born = (int)userInfo["user_created"];
  798. born = Util.ToDateTime(val_born).ToString(
  799. "M/d/yyyy", CultureInfo.InvariantCulture);
  800. // picky, picky
  801. int val_flags = (int)userInfo["user_flags"];
  802. flags = (uint)(val_flags & 0xff);
  803. }
  804. }
  805. UserProfileProperties props = new UserProfileProperties();
  806. string result = string.Empty;
  807. props.UserId = avatarID;
  808. GetProfileData(ref props, out result);
  809. remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags,
  810. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  811. remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText, (uint)props.SkillsMask,
  812. props.SkillsText, props.Language);
  813. }
  814. /// <summary>
  815. /// Updates the avatar properties.
  816. /// </summary>
  817. /// <param name='remoteClient'>
  818. /// Remote client.
  819. /// </param>
  820. /// <param name='newProfile'>
  821. /// New profile.
  822. /// </param>
  823. public void AvatarPropertiesUpdate(IClientAPI remoteClient, UserProfileData newProfile)
  824. {
  825. if (remoteClient.AgentId == newProfile.ID)
  826. {
  827. UserProfileProperties prop = new UserProfileProperties();
  828. prop.UserId = remoteClient.AgentId;
  829. prop.WebUrl = newProfile.ProfileUrl;
  830. prop.ImageId = newProfile.Image;
  831. prop.AboutText = newProfile.AboutText;
  832. prop.FirstLifeImageId = newProfile.FirstLifeImage;
  833. prop.FirstLifeText = newProfile.FirstLifeAboutText;
  834. string serverURI = string.Empty;
  835. GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
  836. object Prop = prop;
  837. if(!JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString()))
  838. {
  839. remoteClient.SendAgentAlertMessage(
  840. "Error updating properties", false);
  841. }
  842. RequestAvatarProperties(remoteClient, newProfile.ID);
  843. }
  844. }
  845. /// <summary>
  846. /// Gets the profile data.
  847. /// </summary>
  848. /// <returns>
  849. /// The profile data.
  850. /// </returns>
  851. /// <param name='userID'>
  852. /// User I.
  853. /// </param>
  854. bool GetProfileData(ref UserProfileProperties properties, out string message)
  855. {
  856. // Can't handle NPC yet...
  857. ScenePresence p = FindPresence(properties.UserId);
  858. if (null != p)
  859. {
  860. if (p.PresenceType == PresenceType.Npc)
  861. {
  862. message = "Id points to NPC";
  863. return false;
  864. }
  865. }
  866. string serverURI = string.Empty;
  867. GetUserProfileServerURI(properties.UserId, out serverURI);
  868. // This is checking a friend on the home grid
  869. // Not HG friend
  870. if ( String.IsNullOrEmpty(serverURI))
  871. {
  872. message = "No Presence - foreign friend";
  873. return false;
  874. }
  875. object Prop = (object)properties;
  876. JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString());
  877. properties = (UserProfileProperties)Prop;
  878. message = "Success";
  879. return true;
  880. }
  881. #endregion Avatar Properties
  882. #region Utils
  883. bool GetImageAssets(UUID avatarId)
  884. {
  885. string profileServerURI = string.Empty;
  886. string assetServerURI = string.Empty;
  887. bool foreign = GetUserProfileServerURI(avatarId, out profileServerURI);
  888. if(!foreign)
  889. return true;
  890. assetServerURI = UserManagementModule.GetUserServerURL(avatarId, "AssetServerURI");
  891. OSDMap parameters= new OSDMap();
  892. parameters.Add("avatarId", OSD.FromUUID(avatarId));
  893. OSD Params = (OSD)parameters;
  894. if(!JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString()))
  895. {
  896. // Error Handling here!
  897. // if(parameters.ContainsKey("message")
  898. return false;
  899. }
  900. parameters = (OSDMap)Params;
  901. OSDArray list = (OSDArray)parameters["result"];
  902. foreach(OSD asset in list)
  903. {
  904. OSDString assetId = (OSDString)asset;
  905. Scene.AssetService.Get(string.Format("{0}/{1}",assetServerURI, assetId.AsString()));
  906. }
  907. return true;
  908. }
  909. /// <summary>
  910. /// Gets the user account data.
  911. /// </summary>
  912. /// <returns>
  913. /// The user profile data.
  914. /// </returns>
  915. /// <param name='userID'>
  916. /// If set to <c>true</c> user I.
  917. /// </param>
  918. /// <param name='userInfo'>
  919. /// If set to <c>true</c> user info.
  920. /// </param>
  921. bool GetUserAccountData(UUID userID, out Dictionary<string, object> userInfo)
  922. {
  923. Dictionary<string,object> info = new Dictionary<string, object>();
  924. if (UserManagementModule.IsLocalGridUser(userID))
  925. {
  926. // Is local
  927. IUserAccountService uas = Scene.UserAccountService;
  928. UserAccount account = uas.GetUserAccount(Scene.RegionInfo.ScopeID, userID);
  929. info["user_flags"] = account.UserFlags;
  930. info["user_created"] = account.Created;
  931. if (!String.IsNullOrEmpty(account.UserTitle))
  932. info["user_title"] = account.UserTitle;
  933. else
  934. info["user_title"] = "";
  935. userInfo = info;
  936. return false;
  937. }
  938. else
  939. {
  940. // Is Foreign
  941. string home_url = UserManagementModule.GetUserServerURL(userID, "HomeURI");
  942. if (String.IsNullOrEmpty(home_url))
  943. {
  944. info["user_flags"] = 0;
  945. info["user_created"] = 0;
  946. info["user_title"] = "Unavailable";
  947. userInfo = info;
  948. return true;
  949. }
  950. UserAgentServiceConnector uConn = new UserAgentServiceConnector(home_url);
  951. Dictionary<string, object> account = uConn.GetUserInfo(userID);
  952. if (account.Count > 0)
  953. {
  954. if (account.ContainsKey("user_flags"))
  955. info["user_flags"] = account["user_flags"];
  956. else
  957. info["user_flags"] = "";
  958. if (account.ContainsKey("user_created"))
  959. info["user_created"] = account["user_created"];
  960. else
  961. info["user_created"] = "";
  962. info["user_title"] = "HG Visitor";
  963. }
  964. else
  965. {
  966. info["user_flags"] = 0;
  967. info["user_created"] = 0;
  968. info["user_title"] = "HG Visitor";
  969. }
  970. userInfo = info;
  971. return true;
  972. }
  973. }
  974. /// <summary>
  975. /// Gets the user profile server UR.
  976. /// </summary>
  977. /// <returns>
  978. /// The user profile server UR.
  979. /// </returns>
  980. /// <param name='userID'>
  981. /// If set to <c>true</c> user I.
  982. /// </param>
  983. /// <param name='serverURI'>
  984. /// If set to <c>true</c> server UR.
  985. /// </param>
  986. bool GetUserProfileServerURI(UUID userID, out string serverURI)
  987. {
  988. bool local;
  989. local = UserManagementModule.IsLocalGridUser(userID);
  990. if (!local)
  991. {
  992. serverURI = UserManagementModule.GetUserServerURL(userID, "ProfileServerURI");
  993. // Is Foreign
  994. return true;
  995. }
  996. else
  997. {
  998. serverURI = ProfileServerUri;
  999. // Is local
  1000. return false;
  1001. }
  1002. }
  1003. /// <summary>
  1004. /// Finds the presence.
  1005. /// </summary>
  1006. /// <returns>
  1007. /// The presence.
  1008. /// </returns>
  1009. /// <param name='clientID'>
  1010. /// Client I.
  1011. /// </param>
  1012. ScenePresence FindPresence(UUID clientID)
  1013. {
  1014. ScenePresence p;
  1015. p = Scene.GetScenePresence(clientID);
  1016. if (p != null && !p.IsChildAgent)
  1017. return p;
  1018. return null;
  1019. }
  1020. #endregion Util
  1021. #region Web Util
  1022. /// <summary>
  1023. /// Sends json-rpc request with a serializable type.
  1024. /// </summary>
  1025. /// <returns>
  1026. /// OSD Map.
  1027. /// </returns>
  1028. /// <param name='parameters'>
  1029. /// Serializable type .
  1030. /// </param>
  1031. /// <param name='method'>
  1032. /// Json-rpc method to call.
  1033. /// </param>
  1034. /// <param name='uri'>
  1035. /// URI of json-rpc service.
  1036. /// </param>
  1037. /// <param name='jsonId'>
  1038. /// Id for our call.
  1039. /// </param>
  1040. bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
  1041. {
  1042. if (jsonId == null)
  1043. throw new ArgumentNullException ("jsonId");
  1044. if (uri == null)
  1045. throw new ArgumentNullException ("uri");
  1046. if (method == null)
  1047. throw new ArgumentNullException ("method");
  1048. if (parameters == null)
  1049. throw new ArgumentNullException ("parameters");
  1050. // Prep our payload
  1051. OSDMap json = new OSDMap();
  1052. json.Add("jsonrpc", OSD.FromString("2.0"));
  1053. json.Add("id", OSD.FromString(jsonId));
  1054. json.Add("method", OSD.FromString(method));
  1055. // Experiment
  1056. json.Add("params", OSD.SerializeMembers(parameters));
  1057. string jsonRequestData = OSDParser.SerializeJsonString(json);
  1058. byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
  1059. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
  1060. // webRequest.Credentials = new NetworkCredential(rpcUser, rpcPass);
  1061. webRequest.ContentType = "application/json-rpc";
  1062. webRequest.Method = "POST";
  1063. Stream dataStream = webRequest.GetRequestStream();
  1064. dataStream.Write(content, 0, content.Length);
  1065. dataStream.Close();
  1066. WebResponse webResponse = null;
  1067. try
  1068. {
  1069. webResponse = webRequest.GetResponse();
  1070. }
  1071. catch (WebException e)
  1072. {
  1073. Console.WriteLine("Web Error" + e.Message);
  1074. Console.WriteLine ("Please check input");
  1075. return false;
  1076. }
  1077. Stream rstream = webResponse.GetResponseStream();
  1078. OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream);
  1079. if (mret.ContainsKey("error"))
  1080. return false;
  1081. // get params...
  1082. OSD.DeserializeMembers(ref parameters, (OSDMap) mret["result"]);
  1083. return true;
  1084. }
  1085. /// <summary>
  1086. /// Sends json-rpc request with OSD parameter.
  1087. /// </summary>
  1088. /// <returns>
  1089. /// The rpc request.
  1090. /// </returns>
  1091. /// <param name='data'>
  1092. /// data - incoming as parameters, outgong as result/error
  1093. /// </param>
  1094. /// <param name='method'>
  1095. /// Json-rpc method to call.
  1096. /// </param>
  1097. /// <param name='uri'>
  1098. /// URI of json-rpc service.
  1099. /// </param>
  1100. /// <param name='jsonId'>
  1101. /// If set to <c>true</c> json identifier.
  1102. /// </param>
  1103. bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
  1104. {
  1105. OSDMap map = new OSDMap();
  1106. map["jsonrpc"] = "2.0";
  1107. if(string.IsNullOrEmpty(jsonId))
  1108. map["id"] = UUID.Random().ToString();
  1109. else
  1110. map["id"] = jsonId;
  1111. map["method"] = method;
  1112. map["params"] = data;
  1113. string jsonRequestData = OSDParser.SerializeJsonString(map);
  1114. byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
  1115. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
  1116. webRequest.ContentType = "application/json-rpc";
  1117. webRequest.Method = "POST";
  1118. Stream dataStream = webRequest.GetRequestStream();
  1119. dataStream.Write(content, 0, content.Length);
  1120. dataStream.Close();
  1121. WebResponse webResponse = null;
  1122. try
  1123. {
  1124. webResponse = webRequest.GetResponse();
  1125. }
  1126. catch (WebException e)
  1127. {
  1128. Console.WriteLine("Web Error" + e.Message);
  1129. Console.WriteLine ("Please check input");
  1130. return false;
  1131. }
  1132. Stream rstream = webResponse.GetResponseStream();
  1133. OSDMap response = new OSDMap();
  1134. try
  1135. {
  1136. response = (OSDMap)OSDParser.DeserializeJson(rstream);
  1137. }
  1138. catch (Exception e)
  1139. {
  1140. m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
  1141. return false;
  1142. }
  1143. if(response.ContainsKey("error"))
  1144. {
  1145. data = response["error"];
  1146. return false;
  1147. }
  1148. data = response;
  1149. return true;
  1150. }
  1151. #endregion Web Util
  1152. }
  1153. }