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