UserProfileModule.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  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.Collections.Generic;
  29. using System.Collections.Concurrent;
  30. using System.Globalization;
  31. using System.Linq;
  32. using System.Reflection;
  33. using System.Threading;
  34. using OpenMetaverse;
  35. using OpenMetaverse.StructuredData;
  36. using log4net;
  37. using Nini.Config;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Services.Interfaces;
  42. using Mono.Addins;
  43. using OpenSim.Services.Connectors.Hypergrid;
  44. using OpenSim.Framework.Servers.HttpServer;
  45. using OpenSim.Services.UserProfilesService;
  46. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  47. using OpenSim.Region.CoreModules.Avatar.Friends;
  48. namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
  49. {
  50. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")]
  51. public class UserProfileModule : IProfileModule, INonSharedRegionModule
  52. {
  53. const double PROFILECACHEEXPIRE = 300;
  54. /// <summary>
  55. /// Logging
  56. /// </summary>
  57. static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. // The pair of Dictionaries are used to handle the switching of classified ads
  59. // by maintaining a cache of classified id to creator id mappings and an interest
  60. // count. The entries are removed when the interest count reaches 0.
  61. readonly Dictionary<UUID, UUID> m_classifiedCache = new();
  62. readonly Dictionary<UUID, int> m_classifiedInterest = new();
  63. readonly ExpiringCacheOS<UUID, UserProfileCacheEntry> m_profilesCache = new(60000);
  64. IGroupsModule m_groupsModule = null;
  65. private readonly JsonRpcRequestManager rpc = new();
  66. private bool m_allowUserProfileWebURLs = true;
  67. struct AsyncPropsRequest
  68. {
  69. public IClientAPI client;
  70. public ScenePresence presence;
  71. public UUID agent;
  72. public int reqtype;
  73. }
  74. private readonly ConcurrentStack<AsyncPropsRequest> m_asyncRequests = new();
  75. private readonly object m_asyncRequestsLock = new();
  76. private bool m_asyncRequestsRunning = false;
  77. private void ProcessRequests()
  78. {
  79. lock(m_asyncRequestsLock)
  80. {
  81. while (m_asyncRequests.TryPop(out AsyncPropsRequest req))
  82. {
  83. try
  84. {
  85. IClientAPI client = req.client;
  86. if(!client.IsActive)
  87. continue;
  88. if(req.reqtype == 0)
  89. {
  90. ScenePresence p = req.presence;
  91. bool foreign = GetUserProfileServerURI(req.agent, out string serverURI);
  92. bool ok = serverURI.Length > 0;
  93. Byte[] membershipType = new Byte[1];
  94. string born = string.Empty;
  95. uint flags = 0x00;
  96. if (ok && GetUserAccountData(req.agent, out UserAccount acc))
  97. {
  98. flags = (uint)(acc.UserFlags & 0xff);
  99. if (acc.UserTitle.Length == 0)
  100. membershipType[0] = (byte)((acc.UserFlags & 0x0f00) >> 8);
  101. else
  102. membershipType = Utils.StringToBytes(acc.UserTitle);
  103. int val_born = acc.Created;
  104. if (val_born != 0)
  105. born = Util.ToDateTime(val_born).ToString("M/d/yyyy", CultureInfo.InvariantCulture);
  106. }
  107. else
  108. ok = false;
  109. UserProfileProperties props = new() { UserId = req.agent };
  110. if (ok)
  111. ok = GetProfileData(ref props, foreign, serverURI, out string result);
  112. if (!ok)
  113. props.AboutText = "Profile not available at this time. User may still be unknown to this grid";
  114. if (!m_allowUserProfileWebURLs)
  115. props.WebUrl = "";
  116. GroupMembershipData[] agentGroups = null;
  117. if(ok && m_groupsModule is not null)
  118. agentGroups = m_groupsModule.GetMembershipData(req.agent);
  119. HashSet<IClientAPI> clients;
  120. lock (m_profilesCache)
  121. {
  122. if (!m_profilesCache.TryGetValue(props.UserId, out UserProfileCacheEntry uce) || uce is null)
  123. uce = new UserProfileCacheEntry();
  124. uce.props = props;
  125. uce.born = born;
  126. uce.membershipType = membershipType;
  127. uce.flags = flags;
  128. clients = uce.ClientsWaitingProps;
  129. uce.ClientsWaitingProps = null;
  130. uce.avatarGroups = agentGroups;
  131. m_profilesCache.AddOrUpdate(props.UserId, uce, PROFILECACHEEXPIRE);
  132. }
  133. if (IsFriendOnline(req.client, req.agent))
  134. flags |= (uint)ProfileFlags.Online;
  135. else
  136. flags &= (uint)~ProfileFlags.Online;
  137. if (clients is null)
  138. {
  139. client.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType, props.FirstLifeText, flags,
  140. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  141. client.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
  142. (uint)props.SkillsMask, props.SkillsText, props.Language);
  143. if (agentGroups is not null)
  144. client.SendAvatarGroupsReply(req.agent, agentGroups);
  145. }
  146. else
  147. {
  148. if (!clients.Contains(client) && client.IsActive)
  149. {
  150. client.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType, props.FirstLifeText, flags,
  151. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  152. client.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
  153. (uint)props.SkillsMask, props.SkillsText, props.Language);
  154. if (agentGroups is not null)
  155. client.SendAvatarGroupsReply(req.agent, agentGroups);
  156. }
  157. foreach (IClientAPI cli in clients)
  158. {
  159. if (!cli.IsActive)
  160. continue;
  161. cli.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType, props.FirstLifeText, flags,
  162. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  163. cli.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
  164. (uint)props.SkillsMask, props.SkillsText, props.Language);
  165. if (agentGroups is not null)
  166. cli.SendAvatarGroupsReply(req.agent, agentGroups);
  167. }
  168. }
  169. }
  170. }
  171. catch (Exception e)
  172. {
  173. m_log.ErrorFormat("[UserProfileModule]: Process fail {0} : {1}", e.Message, e.StackTrace);
  174. }
  175. }
  176. m_asyncRequestsRunning = false;
  177. }
  178. }
  179. public Scene Scene
  180. {
  181. get; private set;
  182. }
  183. /// <summary>
  184. /// Gets or sets the ConfigSource.
  185. /// </summary>
  186. /// <value>
  187. /// The configuration
  188. /// </value>
  189. public IConfigSource Config
  190. {
  191. get;
  192. set;
  193. }
  194. /// <summary>
  195. /// Gets or sets the URI to the profile server.
  196. /// </summary>
  197. /// <value>
  198. /// The profile server URI.
  199. /// </value>
  200. public string ProfileServerUri
  201. {
  202. get;
  203. set;
  204. }
  205. IProfileModule ProfileModule
  206. {
  207. get; set;
  208. }
  209. IUserManagement UserManagementModule
  210. {
  211. get; set;
  212. }
  213. /// <summary>
  214. /// Gets or sets a value indicating whether this
  215. /// <see cref="OpenSim.Region.Coremodules.UserProfiles.UserProfileModule"/> is enabled.
  216. /// </summary>
  217. /// <value>
  218. /// <c>true</c> if enabled; otherwise, <c>false</c>.
  219. /// </value>
  220. public bool Enabled
  221. {
  222. get;
  223. set;
  224. }
  225. private GridInfo m_thisGridInfo;
  226. #region IRegionModuleBase implementation
  227. /// <summary>
  228. /// This is called to initialize the region module. For shared modules, this is called exactly once, after
  229. /// creating the single (shared) instance. For non-shared modules, this is called once on each instance, after
  230. /// the instace for the region has been created.
  231. /// </summary>
  232. /// <param name='source'>
  233. /// Source.
  234. /// </param>
  235. public void Initialise(IConfigSource source)
  236. {
  237. Config = source;
  238. ReplaceableInterface = typeof(IProfileModule);
  239. IConfig profileConfig = Config.Configs["UserProfiles"];
  240. if (profileConfig is null)
  241. {
  242. //m_log.Debug("[PROFILES]: UserProfiles disabled, no configuration");
  243. Enabled = false;
  244. return;
  245. }
  246. // If we find ProfileURL then we configure for FULL support
  247. // else we setup for BASIC support
  248. ProfileServerUri = profileConfig.GetString("ProfileServiceURL", "");
  249. if (string.IsNullOrEmpty(ProfileServerUri))
  250. {
  251. Enabled = false;
  252. return;
  253. }
  254. OSHTTPURI tmp = new(ProfileServerUri, true);
  255. if (!tmp.IsResolvedHost)
  256. {
  257. m_log.ErrorFormat("[UserProfileModule: {0}", tmp.IsValidHost ? "Could not resolve ProfileServiceURL" : "ProfileServiceURL is a invalid host");
  258. throw new Exception("UserProfileModule init error");
  259. }
  260. ProfileServerUri = tmp.URI;
  261. m_allowUserProfileWebURLs = profileConfig.GetBoolean("AllowUserProfileWebURLs", m_allowUserProfileWebURLs);
  262. m_log.Debug("[UserProfileModule]: Full Profiles Enabled");
  263. ReplaceableInterface = null;
  264. Enabled = true;
  265. }
  266. /// <summary>
  267. /// Adds the region.
  268. /// </summary>
  269. /// <param name='scene'>
  270. /// Scene.
  271. /// </param>
  272. public void AddRegion(Scene scene)
  273. {
  274. if(!Enabled)
  275. return;
  276. Scene = scene;
  277. m_thisGridInfo ??= scene.SceneGridInfo;
  278. Scene.RegisterModuleInterface<IProfileModule>(this);
  279. Scene.EventManager.OnNewClient += OnNewClient;
  280. Scene.EventManager.OnClientClosed += OnClientClosed;
  281. UserManagementModule = Scene.RequestModuleInterface<IUserManagement>();
  282. }
  283. /// <summary>
  284. /// Removes the region.
  285. /// </summary>
  286. /// <param name='scene'>
  287. /// Scene.
  288. /// </param>
  289. public void RemoveRegion(Scene scene)
  290. {
  291. if(!Enabled)
  292. return;
  293. m_profilesCache.Clear();
  294. m_classifiedCache.Clear();
  295. m_classifiedInterest.Clear();
  296. }
  297. /// <summary>
  298. /// This will be called once for every scene loaded. In a shared module this will be multiple times in one
  299. /// instance, while a nonshared module instance will only be called once. This method is called after AddRegion
  300. /// has been called in all modules for that scene, providing an opportunity to request another module's
  301. /// interface, or hook an event from another module.
  302. /// </summary>
  303. /// <param name='scene'>
  304. /// Scene.
  305. /// </param>
  306. public void RegionLoaded(Scene scene)
  307. {
  308. if(!Enabled)
  309. return;
  310. m_groupsModule = Scene.RequestModuleInterface<IGroupsModule>();
  311. }
  312. /// <summary>
  313. /// If this returns non-null, it is the type of an interface that this module intends to register. This will
  314. /// cause the loader to defer loading of this module until all other modules have been loaded. If no other
  315. /// module has registered the interface by then, this module will be activated, else it will remain inactive,
  316. /// letting the other module take over. This should return non-null ONLY in modules that are intended to be
  317. /// easily replaceable, e.g. stub implementations that the developer expects to be replaced by third party
  318. /// provided modules.
  319. /// </summary>
  320. /// <value>
  321. /// The replaceable interface.
  322. /// </value>
  323. public Type ReplaceableInterface
  324. {
  325. get; private set;
  326. }
  327. /// <summary>
  328. /// Called as the instance is closed.
  329. /// </summary>
  330. public void Close()
  331. {
  332. m_thisGridInfo = null;
  333. }
  334. /// <value>
  335. /// The name of the module
  336. /// </value>
  337. /// <summary>
  338. /// Gets the module name.
  339. /// </summary>
  340. public string Name
  341. {
  342. get { return "UserProfileModule"; }
  343. }
  344. #endregion IRegionModuleBase implementation
  345. #region Region Event Handlers
  346. /// <summary>
  347. /// Raises the new client event.
  348. /// </summary>
  349. /// <param name='client'>
  350. /// Client.
  351. /// </param>
  352. void OnNewClient(IClientAPI client)
  353. {
  354. //Profile
  355. client.OnRequestAvatarProperties += RequestAvatarProperties;
  356. client.OnUpdateAvatarProperties += AvatarPropertiesUpdate;
  357. client.OnAvatarInterestUpdate += AvatarInterestsUpdate;
  358. // Classifieds
  359. client.AddGenericPacketHandler("avatarclassifiedsrequest", ClassifiedsRequest);
  360. client.OnClassifiedInfoUpdate += ClassifiedInfoUpdate;
  361. client.OnClassifiedInfoRequest += ClassifiedInfoRequest;
  362. client.OnClassifiedDelete += ClassifiedDelete;
  363. // Picks
  364. client.AddGenericPacketHandler("avatarpicksrequest", PicksRequest);
  365. client.AddGenericPacketHandler("pickinforequest", PickInfoRequest);
  366. client.OnPickInfoUpdate += PickInfoUpdate;
  367. client.OnPickDelete += PickDelete;
  368. // Notes
  369. client.AddGenericPacketHandler("avatarnotesrequest", NotesRequest);
  370. client.OnAvatarNotesUpdate += NotesUpdate;
  371. // Preferences
  372. client.OnUserInfoRequest += UserPreferencesRequest;
  373. client.OnUpdateUserInfo += UpdateUserPreferences;
  374. }
  375. void OnClientClosed(UUID AgentId, Scene scene)
  376. {
  377. ScenePresence sp = scene.GetScenePresence(AgentId);
  378. IClientAPI client = sp.ControllingClient;
  379. if (client is null)
  380. return;
  381. //Profile
  382. client.OnRequestAvatarProperties -= RequestAvatarProperties;
  383. client.OnUpdateAvatarProperties -= AvatarPropertiesUpdate;
  384. client.OnAvatarInterestUpdate -= AvatarInterestsUpdate;
  385. // Classifieds
  386. client.OnClassifiedInfoUpdate -= ClassifiedInfoUpdate;
  387. client.OnClassifiedInfoRequest -= ClassifiedInfoRequest;
  388. client.OnClassifiedDelete -= ClassifiedDelete;
  389. // Picks
  390. client.OnPickInfoUpdate -= PickInfoUpdate;
  391. client.OnPickDelete -= PickDelete;
  392. // Notes
  393. client.OnAvatarNotesUpdate -= NotesUpdate;
  394. // Preferences
  395. client.OnUserInfoRequest -= UserPreferencesRequest;
  396. client.OnUpdateUserInfo -= UpdateUserPreferences;
  397. }
  398. #endregion Region Event Handlers
  399. #region Classified
  400. ///
  401. /// <summary>
  402. /// Handles the avatar classifieds request.
  403. /// </summary>
  404. /// <param name='sender'>
  405. /// Sender.
  406. /// </param>
  407. /// <param name='method'>
  408. /// Method.
  409. /// </param>
  410. /// <param name='args'>
  411. /// Arguments.
  412. /// </param>
  413. public void ClassifiedsRequest(Object sender, string method, List<String> args)
  414. {
  415. if (sender is not IClientAPI remoteClient)
  416. return;
  417. Dictionary<UUID, string> classifieds = new();
  418. if (!UUID.TryParse(args[0], out UUID targetID) || targetID.IsZero())
  419. return;
  420. if (targetID.Equals(Constants.m_MrOpenSimID))
  421. {
  422. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  423. return;
  424. }
  425. ScenePresence p = FindPresence(targetID);
  426. if (p is not null && p.IsNPC)
  427. {
  428. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  429. return;
  430. }
  431. lock(m_profilesCache)
  432. {
  433. if(m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) && uce is not null)
  434. {
  435. if(uce.classifiedsLists is not null)
  436. {
  437. foreach(KeyValuePair<UUID,string> kvp in uce.classifiedsLists)
  438. {
  439. UUID kvpkey = kvp.Key;
  440. classifieds[kvpkey] = kvp.Value;
  441. lock (m_classifiedCache)
  442. {
  443. if (!m_classifiedCache.ContainsKey(kvpkey))
  444. {
  445. m_classifiedCache.Add(kvpkey,targetID);
  446. m_classifiedInterest.Add(kvpkey, 0);
  447. }
  448. m_classifiedInterest[kvpkey]++;
  449. }
  450. }
  451. remoteClient.SendAvatarClassifiedReply(targetID, uce.classifiedsLists);
  452. return;
  453. }
  454. }
  455. }
  456. GetUserProfileServerURI(targetID, out string serverURI);
  457. if(string.IsNullOrWhiteSpace(serverURI))
  458. {
  459. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  460. return;
  461. }
  462. OSDMap parameters= new()
  463. {
  464. {"creatorId", OSD.FromUUID(targetID)}
  465. };
  466. OSD osdtmp = parameters;
  467. if(!rpc.JsonRpcRequest(ref osdtmp, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
  468. {
  469. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  470. return;
  471. }
  472. parameters = (OSDMap)osdtmp;
  473. if(!parameters.TryGetValue("result", out osdtmp) || osdtmp is not OSDArray)
  474. {
  475. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  476. return;
  477. }
  478. OSDArray list = (OSDArray)osdtmp;
  479. foreach(OSD map in list)
  480. {
  481. OSDMap m = (OSDMap)map;
  482. UUID cid = m["classifieduuid"].AsUUID();
  483. string name = m["name"].AsString();
  484. classifieds[cid] = name;
  485. lock (m_classifiedCache)
  486. {
  487. if (!m_classifiedCache.ContainsKey(cid))
  488. {
  489. m_classifiedCache.Add(cid,targetID);
  490. m_classifiedInterest.Add(cid, 0);
  491. }
  492. m_classifiedInterest[cid]++;
  493. }
  494. }
  495. lock(m_profilesCache)
  496. {
  497. if(!m_profilesCache.TryGetValue(targetID, out UserProfileCacheEntry uce) || uce is null)
  498. uce = new UserProfileCacheEntry();
  499. uce.classifiedsLists = classifieds;
  500. m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE);
  501. }
  502. remoteClient.SendAvatarClassifiedReply(targetID, classifieds);
  503. }
  504. public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient)
  505. {
  506. UUID target = remoteClient.AgentId;
  507. UserClassifiedAdd ad = new() { ClassifiedId = queryClassifiedID };
  508. lock (m_classifiedCache)
  509. {
  510. if (m_classifiedCache.ContainsKey(queryClassifiedID))
  511. {
  512. target = m_classifiedCache[queryClassifiedID];
  513. m_classifiedInterest[queryClassifiedID]--;
  514. if (m_classifiedInterest[queryClassifiedID] == 0)
  515. {
  516. m_classifiedInterest.Remove(queryClassifiedID);
  517. m_classifiedCache.Remove(queryClassifiedID);
  518. }
  519. }
  520. }
  521. UserProfileCacheEntry uce = null;
  522. lock(m_profilesCache)
  523. {
  524. if(m_profilesCache.TryGetValue(target, out uce) && uce is not null)
  525. {
  526. if(uce.classifieds is not null && uce.classifieds.ContainsKey(queryClassifiedID))
  527. {
  528. ad = uce.classifieds[queryClassifiedID];
  529. if(Vector3.TryParse(ad.GlobalPos, out Vector3 gPos))
  530. {
  531. remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate,
  532. (uint)ad.ExpirationDate, (uint)ad.Category, ad.Name, ad.Description,
  533. ad.ParcelId, (uint)ad.ParentEstate, ad.SnapshotId, ad.SimName,
  534. gPos, ad.ParcelName, ad.Flags, ad.Price);
  535. }
  536. return;
  537. }
  538. }
  539. }
  540. bool foreign = GetUserProfileServerURI(target, out string serverURI);
  541. if(string.IsNullOrWhiteSpace(serverURI))
  542. {
  543. return;
  544. }
  545. object Adobject = ad;
  546. if(!rpc.JsonRpcRequest(ref Adobject, "classifieds_info_query", serverURI, UUID.Random().ToString()))
  547. {
  548. remoteClient.SendAgentAlertMessage(
  549. "Error getting classified info", false);
  550. return;
  551. }
  552. ad = (UserClassifiedAdd) Adobject;
  553. if(ad.CreatorId.IsZero())
  554. return;
  555. if(foreign)
  556. cacheForeignImage(target, ad.SnapshotId);
  557. lock(m_profilesCache)
  558. {
  559. if(!m_profilesCache.TryGetValue(target, out uce) || uce is null)
  560. uce = new UserProfileCacheEntry();
  561. uce.classifieds ??= new Dictionary<UUID, UserClassifiedAdd>();
  562. uce.classifieds[ad.ClassifiedId] = ad;
  563. m_profilesCache.AddOrUpdate(target, uce, PROFILECACHEEXPIRE);
  564. }
  565. if(Vector3.TryParse(ad.GlobalPos, out Vector3 globalPos))
  566. remoteClient.SendClassifiedInfoReply(ad.ClassifiedId, ad.CreatorId, (uint)ad.CreationDate, (uint)ad.ExpirationDate,
  567. (uint)ad.Category, ad.Name, ad.Description, ad.ParcelId, (uint)ad.ParentEstate,
  568. ad.SnapshotId, ad.SimName, globalPos, ad.ParcelName, ad.Flags, ad.Price);
  569. }
  570. /// <summary>
  571. /// Classifieds info update.
  572. /// </summary>
  573. /// <param name='queryclassifiedID'>
  574. /// Queryclassified I.
  575. /// </param>
  576. /// <param name='queryCategory'>
  577. /// Query category.
  578. /// </param>
  579. /// <param name='queryName'>
  580. /// Query name.
  581. /// </param>
  582. /// <param name='queryDescription'>
  583. /// Query description.
  584. /// </param>
  585. /// <param name='queryParcelID'>
  586. /// Query parcel I.
  587. /// </param>
  588. /// <param name='queryParentEstate'>
  589. /// Query parent estate.
  590. /// </param>
  591. /// <param name='querySnapshotID'>
  592. /// Query snapshot I.
  593. /// </param>
  594. /// <param name='queryGlobalPos'>
  595. /// Query global position.
  596. /// </param>
  597. /// <param name='queryclassifiedFlags'>
  598. /// Queryclassified flags.
  599. /// </param>
  600. /// <param name='queryclassifiedPrice'>
  601. /// Queryclassified price.
  602. /// </param>
  603. /// <param name='remoteClient'>
  604. /// Remote client.
  605. /// </param>
  606. public void ClassifiedInfoUpdate(UUID queryclassifiedID, uint queryCategory, string queryName, string queryDescription, UUID queryParcelID,
  607. uint queryParentEstate, UUID querySnapshotID, Vector3 queryGlobalPos, byte queryclassifiedFlags,
  608. int queryclassifiedPrice, IClientAPI remoteClient)
  609. {
  610. Scene s = (Scene)remoteClient.Scene;
  611. Vector3 pos = remoteClient.SceneAgent.AbsolutePosition;
  612. ILandObject land = s.LandChannel.GetLandObject(pos.X, pos.Y);
  613. UUID creatorId = remoteClient.AgentId;
  614. ScenePresence p = FindPresence(creatorId);
  615. UserProfileCacheEntry uce;
  616. lock (m_profilesCache)
  617. m_profilesCache.TryGetValue(remoteClient.AgentId, out uce);
  618. bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  619. if(string.IsNullOrWhiteSpace(serverURI))
  620. return;
  621. if(foreign)
  622. {
  623. remoteClient.SendAgentAlertMessage("Please change classifieds on your home grid", true);
  624. if(uce is not null && uce.classifiedsLists is not null)
  625. remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
  626. return;
  627. }
  628. OSDMap parameters = new () { {"creatorId", OSD.FromUUID(creatorId)} };
  629. OSD osdtmp = parameters;
  630. if (!rpc.JsonRpcRequest(ref osdtmp, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
  631. {
  632. remoteClient.SendAgentAlertMessage("Error fetching classifieds", false);
  633. return;
  634. }
  635. parameters = (OSDMap)osdtmp;
  636. OSDArray list = (OSDArray)parameters["result"];
  637. bool exists = list.Cast<OSDMap>().Where(map => map.ContainsKey("classifieduuid"))
  638. .Any(map => map["classifieduuid"].AsUUID().Equals(queryclassifiedID));
  639. IMoneyModule money = null;
  640. if (!exists)
  641. {
  642. money = s.RequestModuleInterface<IMoneyModule>();
  643. if (money is not null)
  644. {
  645. if (!money.AmountCovered(remoteClient.AgentId, queryclassifiedPrice))
  646. {
  647. remoteClient.SendAgentAlertMessage("You do not have enough money to create this classified.", false);
  648. if(uce is not null && uce.classifiedsLists is not null)
  649. remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
  650. return;
  651. }
  652. }
  653. }
  654. UserClassifiedAdd ad = new()
  655. {
  656. ParcelName = land == null ? string.Empty : land.LandData.Name,
  657. CreatorId = remoteClient.AgentId,
  658. ClassifiedId = queryclassifiedID,
  659. Category = Convert.ToInt32(queryCategory),
  660. Name = queryName,
  661. Description = queryDescription,
  662. ParentEstate = Convert.ToInt32(queryParentEstate),
  663. SnapshotId = querySnapshotID,
  664. SimName = remoteClient.Scene.RegionInfo.RegionName,
  665. GlobalPos = queryGlobalPos.ToString(),
  666. Flags = queryclassifiedFlags,
  667. Price = queryclassifiedPrice,
  668. ParcelId = p.currentParcelUUID
  669. };
  670. object Ad = ad;
  671. if(!rpc.JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString()))
  672. {
  673. remoteClient.SendAgentAlertMessage("Error updating classified", false);
  674. if(uce is not null && uce.classifiedsLists is not null)
  675. remoteClient.SendAvatarClassifiedReply(remoteClient.AgentId, uce.classifiedsLists);
  676. return;
  677. }
  678. // only charge if it worked
  679. money?.ApplyCharge(remoteClient.AgentId, queryclassifiedPrice, MoneyTransactionType.ClassifiedCharge);
  680. // just flush cache for now
  681. lock(m_profilesCache)
  682. {
  683. if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce is not null)
  684. {
  685. uce.classifieds = null;
  686. uce.classifiedsLists = null;
  687. }
  688. }
  689. }
  690. /// <summary>
  691. /// Classifieds delete.
  692. /// </summary>
  693. /// <param name='queryClassifiedID'>
  694. /// Query classified I.
  695. /// </param>
  696. /// <param name='remoteClient'>
  697. /// Remote client.
  698. /// </param>
  699. public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient)
  700. {
  701. bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  702. if(string.IsNullOrWhiteSpace(serverURI))
  703. return;
  704. if(foreign)
  705. {
  706. remoteClient.SendAgentAlertMessage("Please change classifieds on your home grid", true);
  707. return;
  708. }
  709. if (!UUID.TryParse(queryClassifiedID.ToString(), out UUID classifiedId))
  710. return;
  711. OSD Params = new OSDMap() {{ "classifiedId", OSD.FromUUID(classifiedId) }};
  712. if(!rpc.JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString()))
  713. {
  714. remoteClient.SendAgentAlertMessage(
  715. "Error deleting classified", false);
  716. return;
  717. }
  718. // flush cache
  719. lock(m_profilesCache)
  720. {
  721. if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null)
  722. {
  723. uce.classifieds = null;
  724. uce.classifiedsLists = null;
  725. }
  726. }
  727. }
  728. #endregion Classified
  729. #region Picks
  730. /// <summary>
  731. /// Handles the avatar picks request.
  732. /// </summary>
  733. /// <param name='sender'>
  734. /// Sender.
  735. /// </param>
  736. /// <param name='method'>
  737. /// Method.
  738. /// </param>
  739. /// <param name='args'>
  740. /// Arguments.
  741. /// </param>
  742. public void PicksRequest(Object sender, string method, List<String> args)
  743. {
  744. if (sender is not IClientAPI remoteClient)
  745. return;
  746. if(!UUID.TryParse(args[0], out UUID targetId))
  747. return;
  748. Dictionary<UUID, string> picks = new();
  749. if (targetId.Equals(Constants.m_MrOpenSimID))
  750. {
  751. remoteClient.SendAvatarPicksReply(targetId, picks);
  752. return;
  753. }
  754. ScenePresence p = FindPresence(targetId);
  755. if (p is not null && p.IsNPC)
  756. {
  757. remoteClient.SendAvatarPicksReply(targetId, picks);
  758. return;
  759. }
  760. UserProfileCacheEntry uce = null;
  761. lock(m_profilesCache)
  762. {
  763. if(m_profilesCache.TryGetValue(targetId, out uce) && uce is not null)
  764. {
  765. if(uce.picksList is not null)
  766. {
  767. remoteClient.SendAvatarPicksReply(targetId, uce.picksList);
  768. return;
  769. }
  770. }
  771. }
  772. GetUserProfileServerURI(targetId, out string serverURI);
  773. if(string.IsNullOrWhiteSpace(serverURI))
  774. {
  775. remoteClient.SendAvatarPicksReply(targetId, picks);
  776. return;
  777. }
  778. OSDMap parameters= new()
  779. {
  780. {"creatorId", OSD.FromUUID(targetId)}
  781. };
  782. OSD osdtmp = parameters;
  783. if(!rpc.JsonRpcRequest(ref osdtmp, "avatarpicksrequest", serverURI, UUID.Random().ToString()))
  784. {
  785. remoteClient.SendAvatarPicksReply(targetId, picks);
  786. return;
  787. }
  788. parameters = (OSDMap)osdtmp;
  789. if(!parameters.TryGetValue("result", out osdtmp) || osdtmp is not OSDArray)
  790. {
  791. remoteClient.SendAvatarPicksReply(targetId, picks);
  792. return;
  793. }
  794. OSDArray list = (OSDArray)osdtmp;
  795. foreach(OSD map in list)
  796. {
  797. OSDMap m = (OSDMap)map;
  798. UUID cid = m["pickuuid"].AsUUID();
  799. string name = m["name"].AsString();
  800. picks[cid] = name;
  801. }
  802. lock(m_profilesCache)
  803. {
  804. if(!m_profilesCache.TryGetValue(targetId, out uce) || uce is null)
  805. uce = new UserProfileCacheEntry();
  806. uce.picksList = picks;
  807. m_profilesCache.AddOrUpdate(targetId, uce, PROFILECACHEEXPIRE);
  808. }
  809. remoteClient.SendAvatarPicksReply(targetId, picks);
  810. }
  811. /// <summary>
  812. /// Handles the pick info request.
  813. /// </summary>
  814. /// <param name='sender'>
  815. /// Sender.
  816. /// </param>
  817. /// <param name='method'>
  818. /// Method.
  819. /// </param>
  820. /// <param name='args'>
  821. /// Arguments.
  822. /// </param>
  823. public void PickInfoRequest(Object sender, string method, List<String> args)
  824. {
  825. if (sender is not IClientAPI)
  826. return;
  827. UserProfilePick pick = new();
  828. if(!UUID.TryParse(args [0], out UUID targetID))
  829. return;
  830. pick.CreatorId = targetID;
  831. if(!UUID.TryParse (args [1], out pick.PickId))
  832. return;
  833. IClientAPI remoteClient = (IClientAPI)sender;
  834. UserProfileCacheEntry uce = null;
  835. lock(m_profilesCache)
  836. {
  837. if(m_profilesCache.TryGetValue(targetID, out uce) && uce is not null)
  838. {
  839. if(uce.picks is not null && uce.picks.ContainsKey(pick.PickId))
  840. {
  841. pick = uce.picks[pick.PickId];
  842. if(Vector3.TryParse(pick.GlobalPos, out Vector3 gPos))
  843. remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
  844. pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
  845. gPos,pick.SortOrder,pick.Enabled);
  846. return;
  847. }
  848. }
  849. }
  850. bool foreign = GetUserProfileServerURI (targetID, out string serverURI);
  851. if(string.IsNullOrWhiteSpace(serverURI))
  852. {
  853. return;
  854. }
  855. object Pick = (object)pick;
  856. if (!rpc.JsonRpcRequest (ref Pick, "pickinforequest", serverURI, UUID.Random ().ToString ())) {
  857. remoteClient.SendAgentAlertMessage ("Error selecting pick", false);
  858. return;
  859. }
  860. pick = (UserProfilePick)Pick;
  861. if(foreign)
  862. cacheForeignImage(targetID, pick.SnapshotId);
  863. if(!Vector3.TryParse(pick.GlobalPos, out Vector3 globalPos))
  864. return;
  865. if (m_thisGridInfo.IsLocalGrid(pick.Gatekeeper, true) == 0)
  866. {
  867. // Setup the illusion
  868. string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName);
  869. GridRegion target = Scene.GridService.GetRegionByName(Scene.RegionInfo.ScopeID, region);
  870. if(target is null)
  871. {
  872. // This is a unreachable region
  873. }
  874. else
  875. {
  876. // we have a proxy on map
  877. if (Util.ParseFakeParcelID(pick.ParcelId, out ulong _, out uint oriX, out uint oriY))
  878. {
  879. pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, oriX, oriY);
  880. globalPos.X = target.RegionLocX + oriX;
  881. globalPos.Y = target.RegionLocY + oriY;
  882. pick.GlobalPos = globalPos.ToString();
  883. }
  884. else
  885. {
  886. // this is a fail on large regions
  887. uint gtmp = (uint)globalPos.X >> 8;
  888. globalPos.X -= (gtmp << 8);
  889. gtmp = (uint)globalPos.Y >> 8;
  890. globalPos.Y -= (gtmp << 8);
  891. pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, (uint)globalPos.X, (uint)globalPos.Y);
  892. globalPos.X += target.RegionLocX;
  893. globalPos.Y += target.RegionLocY;
  894. pick.GlobalPos = globalPos.ToString();
  895. }
  896. }
  897. }
  898. //m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());
  899. lock(m_profilesCache)
  900. {
  901. if(!m_profilesCache.TryGetValue(targetID, out uce) || uce is null)
  902. uce = new UserProfileCacheEntry();
  903. uce.picks ??= new Dictionary<UUID, UserProfilePick>();
  904. uce.picks[pick.PickId] = pick;
  905. m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE);
  906. }
  907. // Pull the rabbit out of the hat
  908. remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
  909. pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
  910. globalPos,pick.SortOrder,pick.Enabled);
  911. }
  912. /// <summary>
  913. /// Updates the userpicks
  914. /// </summary>
  915. /// <param name='remoteClient'>
  916. /// Remote client.
  917. /// </param>
  918. /// <param name='pickID'>
  919. /// Pick I.
  920. /// </param>
  921. /// <param name='creatorID'>
  922. /// the creator of the pick
  923. /// </param>
  924. /// <param name='topPick'>
  925. /// Top pick.
  926. /// </param>
  927. /// <param name='name'>
  928. /// Name.
  929. /// </param>
  930. /// <param name='desc'>
  931. /// Desc.
  932. /// </param>
  933. /// <param name='snapshotID'>
  934. /// Snapshot I.
  935. /// </param>
  936. /// <param name='sortOrder'>
  937. /// Sort order.
  938. /// </param>
  939. /// <param name='enabled'>
  940. /// Enabled.
  941. /// </param>
  942. public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
  943. {
  944. //m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());
  945. UserProfilePick pick = new();
  946. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  947. if(string.IsNullOrWhiteSpace(serverURI))
  948. return;
  949. ScenePresence p = FindPresence(remoteClient.AgentId);
  950. Vector3 avaPos = p.AbsolutePosition;
  951. // Getting the global position for the Avatar
  952. Vector3 posGlobal = new(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X,
  953. remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y,
  954. avaPos.Z);
  955. string landParcelName = "My Parcel";
  956. // to locate parcels we use a fake id that encodes the region handle
  957. // since we do not have a global locator
  958. // this fails on HG
  959. UUID landParcelID = Util.BuildFakeParcelID(remoteClient.Scene.RegionInfo.RegionHandle, (uint)avaPos.X, (uint)avaPos.Y);
  960. ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);
  961. if (land is not null)
  962. {
  963. // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved
  964. landParcelName = land.LandData.Name;
  965. }
  966. else
  967. {
  968. m_log.WarnFormat(
  969. "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}",
  970. avaPos.X, avaPos.Y, p.Scene.Name);
  971. }
  972. pick.PickId = pickID;
  973. pick.CreatorId = creatorID;
  974. pick.TopPick = topPick;
  975. pick.Name = name;
  976. pick.Desc = desc;
  977. pick.ParcelId = landParcelID;
  978. pick.SnapshotId = snapshotID;
  979. pick.ParcelName = landParcelName;
  980. pick.SimName = remoteClient.Scene.RegionInfo.RegionName;
  981. pick.Gatekeeper = m_thisGridInfo.GateKeeperURLNoEndSlash;
  982. pick.GlobalPos = posGlobal.ToString();
  983. pick.SortOrder = sortOrder;
  984. pick.Enabled = enabled;
  985. object Pick = (object)pick;
  986. if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
  987. {
  988. remoteClient.SendAgentAlertMessage(
  989. "Error updating pick", false);
  990. return;
  991. }
  992. UserProfileCacheEntry uce = null;
  993. lock(m_profilesCache)
  994. {
  995. if(!m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) || uce is null)
  996. uce = new UserProfileCacheEntry();
  997. uce.picks ??= new Dictionary<UUID, UserProfilePick>();
  998. uce.picksList ??= new Dictionary<UUID, string>();
  999. uce.picks[pick.PickId] = pick;
  1000. uce.picksList[pick.PickId] = pick.Name;
  1001. m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE);
  1002. }
  1003. remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList);
  1004. remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
  1005. pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
  1006. posGlobal,pick.SortOrder,pick.Enabled);
  1007. //m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
  1008. }
  1009. /// <summary>
  1010. /// Delete a Pick
  1011. /// </summary>
  1012. /// <param name='remoteClient'>
  1013. /// Remote client.
  1014. /// </param>
  1015. /// <param name='queryPickID'>
  1016. /// Query pick I.
  1017. /// </param>
  1018. public void PickDelete(IClientAPI remoteClient, UUID queryPickID)
  1019. {
  1020. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1021. if(string.IsNullOrWhiteSpace(serverURI))
  1022. {
  1023. return;
  1024. }
  1025. OSDMap parameters = new() { { "pickId", OSD.FromUUID(queryPickID) } };
  1026. OSD Params = (OSD)parameters;
  1027. if(!rpc.JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString()))
  1028. {
  1029. remoteClient.SendAgentAlertMessage(
  1030. "Error picks delete", false);
  1031. return;
  1032. }
  1033. UserProfileCacheEntry uce = null;
  1034. lock(m_profilesCache)
  1035. {
  1036. if(m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) && uce is not null)
  1037. {
  1038. uce.picks?.Remove(queryPickID);
  1039. uce.picksList?.Remove(queryPickID);
  1040. m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE);
  1041. }
  1042. }
  1043. if(uce is not null && uce.picksList is not null)
  1044. remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList);
  1045. else
  1046. remoteClient.SendAvatarPicksReply(remoteClient.AgentId, new Dictionary<UUID, string>());
  1047. }
  1048. #endregion Picks
  1049. #region Notes
  1050. /// <summary>
  1051. /// Handles the avatar notes request.
  1052. /// </summary>
  1053. /// <param name='sender'>
  1054. /// Sender.
  1055. /// </param>
  1056. /// <param name='method'>
  1057. /// Method.
  1058. /// </param>
  1059. /// <param name='args'>
  1060. /// Arguments.
  1061. /// </param>
  1062. public void NotesRequest(Object sender, string method, List<String> args)
  1063. {
  1064. if (sender is not IClientAPI remoteClient)
  1065. return;
  1066. UserProfileNotes note = new();
  1067. if (!UUID.TryParse(args[0], out note.TargetId))
  1068. return;
  1069. note.UserId = remoteClient.AgentId;
  1070. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1071. if(string.IsNullOrWhiteSpace(serverURI))
  1072. {
  1073. remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
  1074. return;
  1075. }
  1076. object Note = (object)note;
  1077. if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
  1078. {
  1079. remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
  1080. return;
  1081. }
  1082. note = (UserProfileNotes) Note;
  1083. remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
  1084. }
  1085. /// <summary>
  1086. /// Avatars the notes update.
  1087. /// </summary>
  1088. /// <param name='remoteClient'>
  1089. /// Remote client.
  1090. /// </param>
  1091. /// <param name='queryTargetID'>
  1092. /// Query target I.
  1093. /// </param>
  1094. /// <param name='queryNotes'>
  1095. /// Query notes.
  1096. /// </param>
  1097. public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
  1098. {
  1099. if (queryTargetID.Equals(Constants.m_MrOpenSimID))
  1100. return;
  1101. ScenePresence p = FindPresence(queryTargetID);
  1102. if (p is not null && p.IsNPC)
  1103. {
  1104. remoteClient.SendAgentAlertMessage("Notes for NPCs not available", false);
  1105. return;
  1106. }
  1107. UserProfileNotes note = new()
  1108. {
  1109. UserId = remoteClient.AgentId,
  1110. TargetId = queryTargetID,
  1111. Notes = queryNotes
  1112. };
  1113. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1114. if(string.IsNullOrWhiteSpace(serverURI))
  1115. return;
  1116. object Note = note;
  1117. if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
  1118. {
  1119. remoteClient.SendAgentAlertMessage(
  1120. "Error updating note", false);
  1121. return;
  1122. }
  1123. }
  1124. #endregion Notes
  1125. #region User Preferences
  1126. /// <summary>
  1127. /// Updates the user preferences.
  1128. /// </summary>
  1129. /// <param name='imViaEmail'>
  1130. /// Im via email.
  1131. /// </param>
  1132. /// <param name='visible'>
  1133. /// Visible.
  1134. /// </param>
  1135. /// <param name='remoteClient'>
  1136. /// Remote client.
  1137. /// </param>
  1138. public void UpdateUserPreferences(bool imViaEmail, bool visible, IClientAPI remoteClient)
  1139. {
  1140. UserPreferences pref = new()
  1141. {
  1142. UserId = remoteClient.AgentId,
  1143. IMViaEmail = imViaEmail,
  1144. Visible = visible
  1145. };
  1146. _ = GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1147. if(string.IsNullOrWhiteSpace(serverURI))
  1148. return;
  1149. object Pref = pref;
  1150. if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString()))
  1151. {
  1152. m_log.InfoFormat("[PROFILES]: UserPreferences update error");
  1153. remoteClient.SendAgentAlertMessage("Error updating preferences", false);
  1154. return;
  1155. }
  1156. }
  1157. /// <summary>
  1158. /// Users the preferences request.
  1159. /// </summary>
  1160. /// <param name='remoteClient'>
  1161. /// Remote client.
  1162. /// </param>
  1163. public void UserPreferencesRequest(IClientAPI remoteClient)
  1164. {
  1165. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1166. if(string.IsNullOrWhiteSpace(serverURI))
  1167. return;
  1168. UserPreferences pref = new() { UserId = remoteClient.AgentId };
  1169. object Pref = (object)pref;
  1170. if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString()))
  1171. {
  1172. //m_log.InfoFormat("[PROFILES]: UserPreferences request error");
  1173. //remoteClient.SendAgentAlertMessage("Error requesting preferences", false);
  1174. return;
  1175. }
  1176. pref = (UserPreferences) Pref;
  1177. remoteClient.SendUserInfoReply(pref.IMViaEmail, pref.Visible, pref.EMail);
  1178. }
  1179. #endregion User Preferences
  1180. #region Avatar Properties
  1181. /// <summary>
  1182. /// Update the avatars interests .
  1183. /// </summary>
  1184. /// <param name='remoteClient'>
  1185. /// Remote client.
  1186. /// </param>
  1187. /// <param name='wantmask'>
  1188. /// Wantmask.
  1189. /// </param>
  1190. /// <param name='wanttext'>
  1191. /// Wanttext.
  1192. /// </param>
  1193. /// <param name='skillsmask'>
  1194. /// Skillsmask.
  1195. /// </param>
  1196. /// <param name='skillstext'>
  1197. /// Skillstext.
  1198. /// </param>
  1199. /// <param name='languages'>
  1200. /// Languages.
  1201. /// </param>
  1202. public void AvatarInterestsUpdate(IClientAPI remoteClient, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages)
  1203. {
  1204. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1205. if (string.IsNullOrWhiteSpace(serverURI))
  1206. return;
  1207. object Param = new UserProfileProperties()
  1208. {
  1209. UserId = remoteClient.AgentId,
  1210. WantToMask = (int)wantmask,
  1211. WantToText = wanttext,
  1212. SkillsMask = (int)skillsmask,
  1213. SkillsText = skillstext,
  1214. Language = languages
  1215. };
  1216. if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString()))
  1217. {
  1218. remoteClient.SendAgentAlertMessage("Error updating interests", false);
  1219. return;
  1220. }
  1221. // flush cache
  1222. lock(m_profilesCache)
  1223. {
  1224. if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null)
  1225. {
  1226. uce.props = null;
  1227. uce.ClientsWaitingProps = null;
  1228. }
  1229. }
  1230. RequestAvatarProperties(remoteClient, remoteClient.AgentId);
  1231. }
  1232. public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
  1233. {
  1234. if (avatarID.IsZero())
  1235. {
  1236. // Looking for a reason that some viewers are sending null Id's
  1237. m_log.Debug("[PROFILES]: got request of null ID");
  1238. return;
  1239. }
  1240. if (avatarID.Equals(Constants.m_MrOpenSimID))
  1241. {
  1242. remoteClient.SendAvatarProperties(avatarID, "Creator of OpenSimulator shared assets library", Constants.m_MrOpenSimBorn.ToString(),
  1243. Utils.StringToBytes("System agent"), "MrOpenSim has no life", 0x10,
  1244. UUID.Zero, UUID.Zero, "", UUID.Zero);
  1245. remoteClient.SendAvatarInterestsReply(avatarID, 0, "",
  1246. 0, "Getting into trouble", "Droidspeak");
  1247. return;
  1248. }
  1249. ScenePresence p = FindPresence(avatarID);
  1250. if (p is not null && p.IsNPC)
  1251. {
  1252. remoteClient.SendAvatarProperties(avatarID, ((INPC)(p.ControllingClient)).profileAbout, ((INPC)(p.ControllingClient)).Born,
  1253. Utils.StringToBytes("Non Player Character (NPC)"), "NPCs have no life", 0x10,
  1254. UUID.Zero, ((INPC)(p.ControllingClient)).profileImage, "", UUID.Zero);
  1255. remoteClient.SendAvatarInterestsReply(avatarID, 0, "",
  1256. 0, "Getting into trouble", "Droidspeak");
  1257. return;
  1258. }
  1259. UserProfileProperties props;
  1260. lock(m_profilesCache)
  1261. {
  1262. if(m_profilesCache.TryGetValue(avatarID, out UserProfileCacheEntry uce) && uce is not null)
  1263. {
  1264. if(uce.props is not null)
  1265. {
  1266. props = uce.props;
  1267. uint cflags = uce.flags;
  1268. if (IsFriendOnline(remoteClient, avatarID))
  1269. cflags = (uint)ProfileFlags.Online;
  1270. else
  1271. cflags &= (uint)~ProfileFlags.Online;
  1272. remoteClient.SendAvatarProperties(props.UserId, props.AboutText,
  1273. uce.born, uce.membershipType , props.FirstLifeText, cflags,
  1274. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  1275. remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask,
  1276. props.WantToText, (uint)props.SkillsMask,
  1277. props.SkillsText, props.Language);
  1278. if(uce.avatarGroups is not null)
  1279. remoteClient.SendAvatarGroupsReply(avatarID, uce.avatarGroups);
  1280. return;
  1281. }
  1282. else
  1283. {
  1284. if(uce.ClientsWaitingProps == null)
  1285. uce.ClientsWaitingProps = new HashSet<IClientAPI>();
  1286. else if(uce.ClientsWaitingProps.Contains(remoteClient))
  1287. return;
  1288. uce.ClientsWaitingProps.Add(remoteClient);
  1289. }
  1290. }
  1291. else
  1292. {
  1293. uce = new UserProfileCacheEntry { ClientsWaitingProps = new HashSet<IClientAPI>() };
  1294. uce.ClientsWaitingProps.Add(remoteClient);
  1295. m_profilesCache.AddOrUpdate(avatarID, uce, PROFILECACHEEXPIRE);
  1296. }
  1297. }
  1298. AsyncPropsRequest req = new()
  1299. {
  1300. client = remoteClient,
  1301. presence = p,
  1302. agent = avatarID,
  1303. reqtype = 0
  1304. };
  1305. m_asyncRequests.Push(req);
  1306. if (Monitor.TryEnter(m_asyncRequestsLock))
  1307. {
  1308. if (!m_asyncRequestsRunning)
  1309. {
  1310. m_asyncRequestsRunning = true;
  1311. Util.FireAndForget(x => ProcessRequests());
  1312. }
  1313. Monitor.Exit(m_asyncRequestsLock);
  1314. }
  1315. /*
  1316. string serverURI = string.Empty;
  1317. bool foreign = GetUserProfileServerURI(avatarID, out serverURI);
  1318. UserAccount account = null;
  1319. Dictionary<string,object> userInfo;
  1320. if (!foreign)
  1321. {
  1322. account = Scene.UserAccountService.GetUserAccount(Scene.RegionInfo.ScopeID, avatarID);
  1323. }
  1324. else
  1325. {
  1326. userInfo = new Dictionary<string, object>();
  1327. }
  1328. Byte[] membershipType = new Byte[1];
  1329. string born = string.Empty;
  1330. uint flags = 0x00;
  1331. if (null != account)
  1332. {
  1333. if (account.UserTitle.Length == 0)
  1334. membershipType[0] = (Byte)((account.UserFlags & 0xf00) >> 8);
  1335. else
  1336. membershipType = Utils.StringToBytes(account.UserTitle);
  1337. born = Util.ToDateTime(account.Created).ToString(
  1338. "M/d/yyyy", CultureInfo.InvariantCulture);
  1339. flags = (uint)(account.UserFlags & 0xff);
  1340. }
  1341. else
  1342. {
  1343. if (GetUserAccountData(avatarID, out userInfo) == true)
  1344. {
  1345. if ((string)userInfo["user_title"].Length == 0)
  1346. membershipType[0] = (Byte)(((Byte)userInfo["user_flags"] & 0xf00) >> 8);
  1347. else
  1348. membershipType = Utils.StringToBytes((string)userInfo["user_title"]);
  1349. int val_born = (int)userInfo["user_created"];
  1350. if(val_born != 0)
  1351. born = Util.ToDateTime(val_born).ToString(
  1352. "M/d/yyyy", CultureInfo.InvariantCulture);
  1353. // picky, picky
  1354. int val_flags = (int)userInfo["user_flags"];
  1355. flags = (uint)(val_flags & 0xff);
  1356. }
  1357. }
  1358. props = new UserProfileProperties();
  1359. props.UserId = avatarID;
  1360. string result = string.Empty;
  1361. if(!GetProfileData(ref props, foreign, serverURI, out result))
  1362. {
  1363. props.AboutText ="Profile not available at this time. User may still be unknown to this grid";
  1364. }
  1365. if(!m_allowUserProfileWebURLs)
  1366. props.WebUrl ="";
  1367. HashSet<IClientAPI> clients;
  1368. lock(m_profilesCache)
  1369. {
  1370. if(!m_profilesCache.TryGetValue(props.UserId, out uce) || uce == null)
  1371. uce = new UserProfileCacheEntry();
  1372. uce.props = props;
  1373. uce.born = born;
  1374. uce.membershipType = membershipType;
  1375. uce.flags = flags;
  1376. clients = uce.ClientsWaitingProps;
  1377. uce.ClientsWaitingProps = null;
  1378. m_profilesCache.AddOrUpdate(props.UserId, uce, PROFILECACHEEXPIRE);
  1379. }
  1380. // if on same region force online
  1381. if(p != null && !p.IsDeleted)
  1382. flags |= 0x10;
  1383. if(clients == null)
  1384. {
  1385. remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType , props.FirstLifeText, flags,
  1386. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  1387. remoteClient.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
  1388. (uint)props.SkillsMask, props.SkillsText, props.Language);
  1389. }
  1390. else
  1391. {
  1392. if(!clients.Contains(remoteClient))
  1393. clients.Add(remoteClient);
  1394. foreach(IClientAPI cli in clients)
  1395. {
  1396. if(!cli.IsActive)
  1397. continue;
  1398. cli.SendAvatarProperties(props.UserId, props.AboutText, born, membershipType , props.FirstLifeText, flags,
  1399. props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);
  1400. cli.SendAvatarInterestsReply(props.UserId, (uint)props.WantToMask, props.WantToText,
  1401. (uint)props.SkillsMask, props.SkillsText, props.Language);
  1402. }
  1403. }
  1404. */
  1405. }
  1406. /// <summary>
  1407. /// Updates the avatar properties.
  1408. /// </summary>
  1409. /// <param name='remoteClient'>
  1410. /// Remote client.
  1411. /// </param>
  1412. /// <param name='newProfile'>
  1413. /// New profile.
  1414. /// </param>
  1415. public void AvatarPropertiesUpdate(IClientAPI remoteClient, UserProfileProperties newProfile)
  1416. {
  1417. GetUserProfileServerURI(remoteClient.AgentId, out string serverURI);
  1418. if (string.IsNullOrWhiteSpace(serverURI))
  1419. return;
  1420. if (!m_allowUserProfileWebURLs)
  1421. newProfile.WebUrl = string.Empty;
  1422. object Prop = newProfile;
  1423. if(!rpc.JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString()))
  1424. {
  1425. remoteClient.SendAgentAlertMessage("Error updating properties", false);
  1426. return;
  1427. }
  1428. // flush cache
  1429. lock(m_profilesCache)
  1430. {
  1431. if(m_profilesCache.TryGetValue(remoteClient.AgentId, out UserProfileCacheEntry uce) && uce is not null)
  1432. {
  1433. uce.props = null;
  1434. uce.ClientsWaitingProps = null;
  1435. }
  1436. }
  1437. RequestAvatarProperties(remoteClient, remoteClient.AgentId);
  1438. }
  1439. /// <summary>
  1440. /// Gets the profile data.
  1441. /// </summary>
  1442. /// <returns>
  1443. /// The profile data.
  1444. /// </returns>
  1445. bool GetProfileData(ref UserProfileProperties properties, bool foreign, string serverURI, out string message)
  1446. {
  1447. if (String.IsNullOrEmpty(serverURI))
  1448. {
  1449. message = "User profile service unknown at this time";
  1450. return false;
  1451. }
  1452. object Prop = properties;
  1453. if (!rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString()))
  1454. {
  1455. // If it's a foreign user then try again using OpenProfile, in case that's what the grid is using
  1456. bool secondChanceSuccess = false;
  1457. if (foreign)
  1458. {
  1459. try
  1460. {
  1461. OpenProfileClient client = new(serverURI);
  1462. if (client.RequestAvatarPropertiesUsingOpenProfile(ref properties))
  1463. secondChanceSuccess = true;
  1464. }
  1465. catch (Exception e)
  1466. {
  1467. m_log.Debug(
  1468. $"[PROFILES]: Request using the OpenProfile API for user {properties.UserId} to {serverURI} failed: {e.Message}");
  1469. // Allow the return 'message' to say "JsonRpcRequest" and not "OpenProfile", because
  1470. // the most likely reason that OpenProfile failed is that the remote server
  1471. // doesn't support OpenProfile, and that's not very interesting.
  1472. }
  1473. }
  1474. if (!secondChanceSuccess)
  1475. {
  1476. message = $"JsonRpcRequest for user {properties.UserId} to {serverURI} failed";
  1477. m_log.Debug($"[PROFILES]: {message}");
  1478. return false;
  1479. }
  1480. }
  1481. properties = (UserProfileProperties)Prop;
  1482. if(foreign)
  1483. {
  1484. cacheForeignImage(properties.UserId, properties.ImageId);
  1485. cacheForeignImage(properties.UserId, properties.FirstLifeImageId);
  1486. }
  1487. message = "Success";
  1488. return true;
  1489. }
  1490. #endregion Avatar Properties
  1491. #region Utils
  1492. /// <summary>
  1493. /// Gets the user account data.
  1494. /// </summary>
  1495. /// <returns>
  1496. /// The user profile data.
  1497. /// </returns>
  1498. /// <param name='userID'>
  1499. /// If set to <c>true</c> user I.
  1500. /// </param>
  1501. /// <param name='userInfo'>
  1502. /// If set to <c>true</c> user info.
  1503. /// </param>
  1504. bool GetUserAccountData(UUID userID, out UserAccount account)
  1505. {
  1506. account = null;
  1507. if (UserManagementModule.IsLocalGridUser(userID))
  1508. {
  1509. // Is local
  1510. IUserAccountService uas = Scene.UserAccountService;
  1511. account = uas.GetUserAccount(Scene.RegionInfo.ScopeID, userID);
  1512. return account is not null;
  1513. }
  1514. else
  1515. {
  1516. // Is Foreign
  1517. string home_url = UserManagementModule.GetUserServerURL(userID, "HomeURI", out bool recentFailedWeb);
  1518. if (recentFailedWeb || String.IsNullOrEmpty(home_url))
  1519. return false;
  1520. UserAgentServiceConnector uConn = new(home_url);
  1521. Dictionary<string, object> info;
  1522. try
  1523. {
  1524. info = uConn.GetUserInfo(userID);
  1525. }
  1526. catch (Exception e)
  1527. {
  1528. m_log.Debug("[PROFILES]: GetUserInfo call failed ", e);
  1529. UserManagementModule.UserWebFailed(userID);
  1530. return false;
  1531. }
  1532. if (info.Count == 0)
  1533. return false;
  1534. account = new UserAccount();
  1535. if (info.ContainsKey("user_flags"))
  1536. account.UserFlags = (int)info["user_flags"];
  1537. if (info.ContainsKey("user_created"))
  1538. account.Created = (int)info["user_created"];
  1539. account.UserTitle = "HG Visitor";
  1540. return true;
  1541. }
  1542. }
  1543. /// <summary>
  1544. /// Gets the user profile server UR.
  1545. /// </summary>
  1546. /// <returns>
  1547. /// The user profile server UR.
  1548. /// </returns>
  1549. /// <param name='userID'>
  1550. /// If set to <c>true</c> user I.
  1551. /// </param>
  1552. /// <param name='serverURI'>
  1553. /// If set to <c>true</c> server UR.
  1554. /// </param>
  1555. bool GetUserProfileServerURI(UUID userID, out string serverURI)
  1556. {
  1557. if (!UserManagementModule.IsLocalGridUser(userID))
  1558. {
  1559. serverURI = UserManagementModule.GetUserServerURL(userID, "ProfileServerURI", out bool failed);
  1560. if(failed)
  1561. serverURI = string.Empty;
  1562. // Is Foreign
  1563. return true;
  1564. }
  1565. else
  1566. {
  1567. serverURI = ProfileServerUri;
  1568. // Is local
  1569. return false;
  1570. }
  1571. }
  1572. void cacheForeignImage(UUID agent, UUID imageID)
  1573. {
  1574. if(imageID.IsZero())
  1575. return;
  1576. string assetServerURI = UserManagementModule.GetUserServerURL(agent, "AssetServerURI");
  1577. if(string.IsNullOrWhiteSpace(assetServerURI))
  1578. return;
  1579. Scene.AssetService.Get(imageID.ToString(), assetServerURI, false);
  1580. }
  1581. /// <summary>
  1582. /// Finds the presence.
  1583. /// </summary>
  1584. /// <returns>
  1585. /// The presence.
  1586. /// </returns>
  1587. /// <param name='clientID'>
  1588. /// Client I.
  1589. /// </param>
  1590. ScenePresence FindPresence(UUID clientID)
  1591. {
  1592. ScenePresence p = Scene.GetScenePresence(clientID);
  1593. if (p is not null && !p.IsChildAgent)
  1594. return p;
  1595. return null;
  1596. }
  1597. public virtual bool IsFriendOnline(IClientAPI client, UUID agent)
  1598. {
  1599. // if on same region force online
  1600. ScenePresence p = Scene.GetScenePresence(agent);
  1601. if (p is not null && !p.IsChildAgent && !p.IsDeleted)
  1602. return true;
  1603. IFriendsModule friendsModule = Scene.RequestModuleInterface<IFriendsModule>();
  1604. if (friendsModule is not null && friendsModule.IsFriendOnline(client.AgentId, agent))
  1605. return true;
  1606. if(client.SceneAgent is ScenePresence sp && sp.IsViewerUIGod)
  1607. {
  1608. Services.Interfaces.PresenceInfo[] pi = Scene.PresenceService?.GetAgents(new string[] { agent.ToString() });
  1609. return pi is not null && pi.Length > 0;
  1610. }
  1611. return false;
  1612. }
  1613. #endregion Util
  1614. #region Web Util
  1615. /// <summary>
  1616. /// Sends json-rpc request with a serializable type.
  1617. /// </summary>
  1618. /// <returns>
  1619. /// OSD Map.
  1620. /// </returns>
  1621. /// <param name='parameters'>
  1622. /// Serializable type .
  1623. /// </param>
  1624. /// <param name='method'>
  1625. /// Json-rpc method to call.
  1626. /// </param>
  1627. /// <param name='uri'>
  1628. /// URI of json-rpc service.
  1629. /// </param>
  1630. /// <param name='jsonId'>
  1631. /// Id for our call.
  1632. /// </param>
  1633. bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
  1634. {
  1635. return rpc?.JsonRpcRequest(ref parameters, method, uri, jsonId) ?? false;
  1636. }
  1637. /// <summary>
  1638. /// Sends json-rpc request with OSD parameter.
  1639. /// </summary>
  1640. /// <returns>
  1641. /// The rpc request.
  1642. /// </returns>
  1643. /// <param name='data'>
  1644. /// data - incoming as parameters, outgong as result/error
  1645. /// </param>
  1646. /// <param name='method'>
  1647. /// Json-rpc method to call.
  1648. /// </param>
  1649. /// <param name='uri'>
  1650. /// URI of json-rpc service.
  1651. /// </param>
  1652. /// <param name='jsonId'>
  1653. /// If set to <c>true</c> json identifier.
  1654. /// </param>
  1655. bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
  1656. {
  1657. return rpc?.JsonRpcRequest(ref data, method, uri, jsonId) ?? false;
  1658. }
  1659. #endregion Web Util
  1660. }
  1661. }