aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs
diff options
context:
space:
mode:
Diffstat (limited to 'addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs')
-rw-r--r--addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs982
1 files changed, 0 insertions, 982 deletions
diff --git a/addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs b/addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs
deleted file mode 100644
index 775e8b1..0000000
--- a/addon-modules/OpenSimProfile/Modules/ProfileModule/OpenProfile.cs
+++ /dev/null
@@ -1,982 +0,0 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Globalization;
5using System.Net;
6using System.Net.Sockets;
7using System.Reflection;
8using System.Xml;
9using OpenMetaverse;
10using log4net;
11using Nini.Config;
12using Nwc.XmlRpc;
13using OpenSim.Framework;
14using OpenSim.Region.Framework.Interfaces;
15using OpenSim.Region.Framework.Scenes;
16using OpenSim.Services.Interfaces;
17using Mono.Addins;
18using OpenSim.Services.Connectors.Hypergrid;
19
20[assembly: Addin("OpenProfileModule", "0.1")]
21[assembly: AddinDependency("OpenSim", "0.5")]
22
23namespace OpenSimProfile.Modules.OpenProfile
24{
25 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
26 public class OpenProfileModule : IProfileModule, ISharedRegionModule
27 {
28 //
29 // Log module
30 //
31 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
32
33 //
34 // Module vars
35 //
36 private IConfigSource m_Config;
37 private List<Scene> m_Scenes = new List<Scene>();
38 private string m_ProfileServer = "";
39 private bool m_Enabled = true;
40
41 IUserManagement m_uMan;
42 IUserManagement UserManagementModule
43 {
44 get
45 {
46 if (m_uMan == null)
47 m_uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
48 return m_uMan;
49 }
50 }
51
52 #region IRegionModuleBase implementation
53 public void Initialise(IConfigSource source)
54 {
55 m_Config = source;
56
57 IConfig profileConfig = m_Config.Configs["Profile"];
58
59 if (profileConfig == null)
60 {
61 m_Enabled = false;
62 return;
63 }
64 m_ProfileServer = profileConfig.GetString("ProfileURL", "");
65 if (m_ProfileServer == "")
66 {
67 m_Enabled = false;
68 return;
69 }
70 else
71 {
72 m_log.Info("[PROFILE] OpenProfile module is activated");
73 m_Enabled = true;
74 }
75 }
76
77 public void AddRegion(Scene scene)
78 {
79 if (!m_Enabled)
80 return;
81
82 // Hook up events
83 scene.EventManager.OnNewClient += OnNewClient;
84
85 // Take ownership of the IProfileModule service
86 scene.RegisterModuleInterface<IProfileModule>(this);
87
88 // Add our scene to our list...
89 lock(m_Scenes)
90 {
91 m_Scenes.Add(scene);
92 }
93 }
94
95 public void RemoveRegion(Scene scene)
96 {
97 if (!m_Enabled)
98 return;
99
100 scene.UnregisterModuleInterface<IProfileModule>(this);
101 m_Scenes.Remove(scene);
102 }
103
104 public void RegionLoaded(Scene scene)
105 {
106 }
107
108 public Type ReplaceableInterface
109 {
110 get { return null; }
111 }
112
113 public void PostInitialise()
114 {
115 }
116
117 public void Close()
118 {
119 }
120
121 public string Name
122 {
123 get { return "ProfileModule"; }
124 }
125 #endregion
126
127 private ScenePresence FindPresence(UUID clientID)
128 {
129 ScenePresence p;
130
131 foreach (Scene s in m_Scenes)
132 {
133 p = s.GetScenePresence(clientID);
134 if (p != null && !p.IsChildAgent)
135 return p;
136 }
137 return null;
138 }
139
140 /// New Client Event Handler
141 private void OnNewClient(IClientAPI client)
142 {
143 // Subscribe to messages
144
145 // Classifieds
146 client.AddGenericPacketHandler("avatarclassifiedsrequest", HandleAvatarClassifiedsRequest);
147 client.OnClassifiedInfoUpdate += ClassifiedInfoUpdate;
148 client.OnClassifiedDelete += ClassifiedDelete;
149
150 // Picks
151 client.AddGenericPacketHandler("avatarpicksrequest", HandleAvatarPicksRequest);
152 client.AddGenericPacketHandler("pickinforequest", HandlePickInfoRequest);
153 client.OnPickInfoUpdate += PickInfoUpdate;
154 client.OnPickDelete += PickDelete;
155
156 // Notes
157 client.AddGenericPacketHandler("avatarnotesrequest", HandleAvatarNotesRequest);
158 client.OnAvatarNotesUpdate += AvatarNotesUpdate;
159
160 //Profile
161 client.OnRequestAvatarProperties += RequestAvatarProperties;
162 client.OnUpdateAvatarProperties += UpdateAvatarProperties;
163 client.OnAvatarInterestUpdate += AvatarInterestsUpdate;
164 client.OnUserInfoRequest += UserPreferencesRequest;
165 client.OnUpdateUserInfo += UpdateUserPreferences;
166 }
167
168 //
169 // Make external XMLRPC request
170 //
171 private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method, string server)
172 {
173 ArrayList SendParams = new ArrayList();
174 SendParams.Add(ReqParams);
175
176 // Send Request
177 XmlRpcResponse Resp;
178 try
179 {
180 XmlRpcRequest Req = new XmlRpcRequest(method, SendParams);
181 Resp = Req.Send(server, 30000);
182 }
183 catch (WebException ex)
184 {
185 m_log.ErrorFormat("[PROFILE]: Unable to connect to Profile " +
186 "Server {0}. Exception {1}", m_ProfileServer, ex);
187
188 Hashtable ErrorHash = new Hashtable();
189 ErrorHash["success"] = false;
190 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
191 ErrorHash["errorURI"] = "";
192
193 return ErrorHash;
194 }
195 catch (SocketException ex)
196 {
197 m_log.ErrorFormat(
198 "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " +
199 "Exception {3}", m_ProfileServer, method, ReqParams, ex);
200
201 Hashtable ErrorHash = new Hashtable();
202 ErrorHash["success"] = false;
203 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
204 ErrorHash["errorURI"] = "";
205
206 return ErrorHash;
207 }
208 catch (XmlException ex)
209 {
210 m_log.ErrorFormat(
211 "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " +
212 "Exception {3}", m_ProfileServer, method, ReqParams.ToString(), ex);
213 Hashtable ErrorHash = new Hashtable();
214 ErrorHash["success"] = false;
215 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
216 ErrorHash["errorURI"] = "";
217
218 return ErrorHash;
219 }
220 if (Resp.IsFault)
221 {
222 Hashtable ErrorHash = new Hashtable();
223 ErrorHash["success"] = false;
224 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
225 ErrorHash["errorURI"] = "";
226 return ErrorHash;
227 }
228 Hashtable RespData = (Hashtable)Resp.Value;
229
230 return RespData;
231 }
232
233 // Classifieds Handler
234 public void HandleAvatarClassifiedsRequest(Object sender, string method, List<String> args)
235 {
236 if (!(sender is IClientAPI))
237 return;
238
239 IClientAPI remoteClient = (IClientAPI)sender;
240
241 UUID targetID;
242 UUID.TryParse(args[0], out targetID);
243
244 // Can't handle NPC yet...
245 ScenePresence p = FindPresence(targetID);
246
247 if (null != p)
248 {
249 if (p.PresenceType == PresenceType.Npc)
250 return;
251 }
252
253 string serverURI = string.Empty;
254 bool foreign = GetUserProfileServerURI(targetID, out serverURI);
255
256 Hashtable ReqHash = new Hashtable();
257 ReqHash["uuid"] = args[0];
258
259 Hashtable result = GenericXMLRPCRequest(ReqHash,
260 method, serverURI);
261
262 if (!Convert.ToBoolean(result["success"]))
263 {
264 remoteClient.SendAgentAlertMessage(
265 result["errorMessage"].ToString(), false);
266 return;
267 }
268
269 ArrayList dataArray = (ArrayList)result["data"];
270
271 Dictionary<UUID, string> classifieds = new Dictionary<UUID, string>();
272
273 foreach (Object o in dataArray)
274 {
275 Hashtable d = (Hashtable)o;
276
277 classifieds[new UUID(d["classifiedid"].ToString())] = d["name"].ToString();
278 }
279
280 remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds);
281 }
282
283 // Classifieds Update
284 public void ClassifiedInfoUpdate(UUID queryclassifiedID, uint queryCategory, string queryName, string queryDescription, UUID queryParcelID,
285 uint queryParentEstate, UUID querySnapshotID, Vector3 queryGlobalPos, byte queryclassifiedFlags,
286 int queryclassifiedPrice, IClientAPI remoteClient)
287 {
288 Hashtable ReqHash = new Hashtable();
289
290 Scene s = (Scene) remoteClient.Scene;
291 Vector3 pos = remoteClient.SceneAgent.AbsolutePosition;
292 ILandObject land = s.LandChannel.GetLandObject(pos.X, pos.Y);
293
294 if (land == null)
295 ReqHash["parcelname"] = String.Empty;
296 else
297 ReqHash["parcelname"] = land.LandData.Name;
298
299 ReqHash["creatorUUID"] = remoteClient.AgentId.ToString();
300 ReqHash["classifiedUUID"] = queryclassifiedID.ToString();
301 ReqHash["category"] = queryCategory.ToString();
302 ReqHash["name"] = queryName;
303 ReqHash["description"] = queryDescription;
304 ReqHash["parentestate"] = queryParentEstate.ToString();
305 ReqHash["snapshotUUID"] = querySnapshotID.ToString();
306 ReqHash["sim_name"] = remoteClient.Scene.RegionInfo.RegionName;
307 ReqHash["globalpos"] = queryGlobalPos.ToString();
308 ReqHash["classifiedFlags"] = queryclassifiedFlags.ToString();
309 ReqHash["classifiedPrice"] = queryclassifiedPrice.ToString();
310
311 ScenePresence p = FindPresence(remoteClient.AgentId);
312
313
314 string serverURI = string.Empty;
315 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
316
317 Vector3 avaPos = p.AbsolutePosition;
318
319 // Getting the parceluuid for this parcel
320 ReqHash["parcelUUID"] = p.currentParcelUUID.ToString();
321
322 // Getting the global position for the Avatar
323 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionLocX * Constants.RegionSize + avaPos.X,
324 remoteClient.Scene.RegionInfo.RegionLocY * Constants.RegionSize + avaPos.Y,
325 avaPos.Z);
326
327 ReqHash["pos_global"] = posGlobal.ToString();
328
329 Hashtable result = GenericXMLRPCRequest(ReqHash,
330 "classified_update", serverURI);
331
332 if (!Convert.ToBoolean(result["success"]))
333 {
334 remoteClient.SendAgentAlertMessage(
335 result["errorMessage"].ToString(), false);
336 }
337 }
338
339 // Classifieds Delete
340 public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient)
341 {
342 Hashtable ReqHash = new Hashtable();
343
344 string serverURI = string.Empty;
345 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
346
347 ReqHash["classifiedID"] = queryClassifiedID.ToString();
348
349 Hashtable result = GenericXMLRPCRequest(ReqHash,
350 "classified_delete", serverURI);
351
352 if (!Convert.ToBoolean(result["success"]))
353 {
354 remoteClient.SendAgentAlertMessage(
355 result["errorMessage"].ToString(), false);
356 }
357 }
358
359 // Picks Handler
360 public void HandleAvatarPicksRequest(Object sender, string method, List<String> args)
361 {
362 if (!(sender is IClientAPI))
363 return;
364
365 IClientAPI remoteClient = (IClientAPI)sender;
366
367 UUID targetID;
368 UUID.TryParse(args[0], out targetID);
369
370 // Can't handle NPC yet...
371 ScenePresence p = FindPresence(targetID);
372
373 if (null != p)
374 {
375 if (p.PresenceType == PresenceType.Npc)
376 return;
377 }
378
379 string serverURI = string.Empty;
380 bool foreign = GetUserProfileServerURI(targetID, out serverURI);
381
382 Hashtable ReqHash = new Hashtable();
383 ReqHash["uuid"] = args[0];
384
385 Hashtable result = GenericXMLRPCRequest(ReqHash,
386 method, serverURI);
387
388 if (!Convert.ToBoolean(result["success"]))
389 {
390 remoteClient.SendAgentAlertMessage(
391 result["errorMessage"].ToString(), false);
392 return;
393 }
394
395 ArrayList dataArray = (ArrayList)result["data"];
396
397 Dictionary<UUID, string> picks = new Dictionary<UUID, string>();
398
399 if (dataArray != null)
400 {
401 foreach (Object o in dataArray)
402 {
403 Hashtable d = (Hashtable)o;
404
405 picks[new UUID(d["pickid"].ToString())] = d["name"].ToString();
406 }
407 }
408
409 remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks);
410 }
411
412 // Picks Request
413 public void HandlePickInfoRequest(Object sender, string method, List<String> args)
414 {
415 if (!(sender is IClientAPI))
416 return;
417
418 IClientAPI remoteClient = (IClientAPI)sender;
419
420 Hashtable ReqHash = new Hashtable();
421
422 UUID targetID;
423 UUID.TryParse(args[0], out targetID);
424
425 string serverURI = string.Empty;
426 bool foreign = GetUserProfileServerURI(targetID, out serverURI);
427
428 ReqHash["avatar_id"] = args[0];
429 ReqHash["pick_id"] = args[1];
430
431 Hashtable result = GenericXMLRPCRequest(ReqHash,
432 method, serverURI);
433
434 if (!Convert.ToBoolean(result["success"]))
435 {
436 remoteClient.SendAgentAlertMessage(
437 result["errorMessage"].ToString(), false);
438 return;
439 }
440
441 ArrayList dataArray = (ArrayList)result["data"];
442
443 Hashtable d = (Hashtable)dataArray[0];
444
445 Vector3 globalPos = new Vector3();
446 Vector3.TryParse(d["posglobal"].ToString(), out globalPos);
447
448 if (d["description"] == null)
449 d["description"] = String.Empty;
450
451 remoteClient.SendPickInfoReply(
452 new UUID(d["pickuuid"].ToString()),
453 new UUID(d["creatoruuid"].ToString()),
454 Convert.ToBoolean(d["toppick"]),
455 new UUID(d["parceluuid"].ToString()),
456 d["name"].ToString(),
457 d["description"].ToString(),
458 new UUID(d["snapshotuuid"].ToString()),
459 d["user"].ToString(),
460 d["originalname"].ToString(),
461 d["simname"].ToString(),
462 globalPos,
463 Convert.ToInt32(d["sortorder"]),
464 Convert.ToBoolean(d["enabled"]));
465 }
466
467 // Picks Update
468 public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
469 {
470 Hashtable ReqHash = new Hashtable();
471
472 ReqHash["agent_id"] = remoteClient.AgentId.ToString();
473 ReqHash["pick_id"] = pickID.ToString();
474 ReqHash["creator_id"] = creatorID.ToString();
475 ReqHash["top_pick"] = topPick.ToString();
476 ReqHash["name"] = name;
477 ReqHash["desc"] = desc;
478 ReqHash["snapshot_id"] = snapshotID.ToString();
479 ReqHash["sort_order"] = sortOrder.ToString();
480 ReqHash["enabled"] = enabled.ToString();
481 ReqHash["sim_name"] = remoteClient.Scene.RegionInfo.RegionName;
482
483 ScenePresence p = FindPresence(remoteClient.AgentId);
484
485 Vector3 avaPos = p.AbsolutePosition;
486
487 // Getting the parceluuid for this parcel
488 ReqHash["parcel_uuid"] = p.currentParcelUUID.ToString();
489
490 // Getting the global position for the Avatar
491 Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.RegionLocX*Constants.RegionSize + avaPos.X,
492 remoteClient.Scene.RegionInfo.RegionLocY*Constants.RegionSize + avaPos.Y,
493 avaPos.Z);
494
495 ReqHash["pos_global"] = posGlobal.ToString();
496
497 // Getting the owner of the parcel
498 ReqHash["user"] = ""; //FIXME: Get avatar/group who owns parcel
499
500 string serverURI = string.Empty;
501 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
502
503 // Do the request
504 Hashtable result = GenericXMLRPCRequest(ReqHash,
505 "picks_update", serverURI);
506
507 if (!Convert.ToBoolean(result["success"]))
508 {
509 remoteClient.SendAgentAlertMessage(
510 result["errorMessage"].ToString(), false);
511 }
512 }
513
514 // Picks Delete
515 public void PickDelete(IClientAPI remoteClient, UUID queryPickID)
516 {
517 Hashtable ReqHash = new Hashtable();
518
519 ReqHash["pick_id"] = queryPickID.ToString();
520
521 string serverURI = string.Empty;
522 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
523
524 Hashtable result = GenericXMLRPCRequest(ReqHash,
525 "picks_delete", serverURI);
526
527 if (!Convert.ToBoolean(result["success"]))
528 {
529 remoteClient.SendAgentAlertMessage(
530 result["errorMessage"].ToString(), false);
531 }
532 }
533
534 // Notes Handler
535 public void HandleAvatarNotesRequest(Object sender, string method, List<String> args)
536 {
537 string targetid;
538 string notes = "";
539
540 if (!(sender is IClientAPI))
541 return;
542
543 IClientAPI remoteClient = (IClientAPI)sender;
544
545 Hashtable ReqHash = new Hashtable();
546
547 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
548 ReqHash["uuid"] = args[0];
549
550 string serverURI = string.Empty;
551 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
552
553 Hashtable result = GenericXMLRPCRequest(ReqHash,
554 method, serverURI);
555
556 if (!Convert.ToBoolean(result["success"]))
557 {
558 remoteClient.SendAgentAlertMessage(
559 result["errorMessage"].ToString(), false);
560 return;
561 }
562
563 ArrayList dataArray = (ArrayList)result["data"];
564
565 if (dataArray != null && dataArray[0] != null)
566 {
567 Hashtable d = (Hashtable)dataArray[0];
568
569 targetid = d["targetid"].ToString();
570 if (d["notes"] != null)
571 notes = d["notes"].ToString();
572
573 remoteClient.SendAvatarNotesReply(new UUID(targetid), notes);
574 }
575 }
576
577 // Notes Update
578 public void AvatarNotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
579 {
580 Hashtable ReqHash = new Hashtable();
581
582 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
583 ReqHash["target_id"] = queryTargetID.ToString();
584 ReqHash["notes"] = queryNotes;
585
586 string serverURI = string.Empty;
587 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
588
589 Hashtable result = GenericXMLRPCRequest(ReqHash,
590 "avatar_notes_update", serverURI);
591
592 if (!Convert.ToBoolean(result["success"]))
593 {
594 remoteClient.SendAgentAlertMessage(
595 result["errorMessage"].ToString(), false);
596 }
597 }
598
599 // Standard Profile bits
600 public void AvatarInterestsUpdate(IClientAPI remoteClient, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages)
601 {
602 Hashtable ReqHash = new Hashtable();
603
604 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
605 ReqHash["wantmask"] = wantmask.ToString();
606 ReqHash["wanttext"] = wanttext;
607 ReqHash["skillsmask"] = skillsmask.ToString();
608 ReqHash["skillstext"] = skillstext;
609 ReqHash["languages"] = languages;
610
611 string serverURI = string.Empty;
612 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
613
614 Hashtable result = GenericXMLRPCRequest(ReqHash,
615 "avatar_interests_update", serverURI);
616
617 if (!Convert.ToBoolean(result["success"]))
618 {
619 remoteClient.SendAgentAlertMessage(
620 result["errorMessage"].ToString(), false);
621 }
622 }
623
624 public void UserPreferencesRequest(IClientAPI remoteClient)
625 {
626 Hashtable ReqHash = new Hashtable();
627
628 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
629
630 string serverURI = string.Empty;
631 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
632
633 Hashtable result = GenericXMLRPCRequest(ReqHash,
634 "user_preferences_request", serverURI);
635
636 if (!Convert.ToBoolean(result["success"]))
637 {
638 remoteClient.SendAgentAlertMessage(
639 result["errorMessage"].ToString(), false);
640 return;
641 }
642
643 ArrayList dataArray = (ArrayList)result["data"];
644
645 if (dataArray != null && dataArray[0] != null)
646 {
647 Hashtable d = (Hashtable)dataArray[0];
648 string mail = "";
649
650 if (d["email"] != null)
651 mail = d["email"].ToString();
652
653 remoteClient.SendUserInfoReply(
654 Convert.ToBoolean(d["imviaemail"]),
655 Convert.ToBoolean(d["visible"]),
656 mail);
657 }
658 }
659
660 public void UpdateUserPreferences(bool imViaEmail, bool visible, IClientAPI remoteClient)
661 {
662 Hashtable ReqHash = new Hashtable();
663
664 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
665 ReqHash["imViaEmail"] = imViaEmail.ToString();
666 ReqHash["visible"] = visible.ToString();
667
668 string serverURI = string.Empty;
669 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
670
671 Hashtable result = GenericXMLRPCRequest(ReqHash,
672 "user_preferences_update", serverURI);
673
674 if (!Convert.ToBoolean(result["success"]))
675 {
676 remoteClient.SendAgentAlertMessage(
677 result["errorMessage"].ToString(), false);
678 }
679 }
680
681 // Profile data like the WebURL
682 private Hashtable GetProfileData(UUID userID)
683 {
684 Hashtable ReqHash = new Hashtable();
685
686 // Can't handle NPC yet...
687 ScenePresence p = FindPresence(userID);
688
689 if (null != p)
690 {
691 if (p.PresenceType == PresenceType.Npc)
692 {
693 Hashtable npc =new Hashtable();
694 npc["success"] = "false";
695 npc["errorMessage"] = "Presence is NPC. ";
696 return npc;
697 }
698 }
699
700 ReqHash["avatar_id"] = userID.ToString();
701
702 string serverURI = string.Empty;
703 bool foreign = GetUserProfileServerURI(userID, out serverURI);
704
705 // This is checking a friend on the home grid
706 // Not HG friend
707 if ( String.IsNullOrEmpty(serverURI))
708 {
709 Hashtable nop =new Hashtable();
710 nop["success"] = "false";
711 nop["errorMessage"] = "No Presence - foreign friend";
712 return nop;
713
714 }
715
716 Hashtable result = GenericXMLRPCRequest(ReqHash,
717 "avatar_properties_request", serverURI);
718
719 ArrayList dataArray = (ArrayList)result["data"];
720
721 if (dataArray != null && dataArray[0] != null)
722 {
723 Hashtable d = (Hashtable)dataArray[0];
724 return d;
725 }
726 return result;
727 }
728
729 public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
730 {
731 if ( String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString()))
732 {
733 // Looking for a reason that some viewers are sending null Id's
734 m_log.InfoFormat("[PROFILE]: This should not happen remoteClient.AgentId {0} - avatarID {1}", remoteClient.AgentId, avatarID);
735 return;
736 }
737
738 // Can't handle NPC yet...
739 ScenePresence p = FindPresence(avatarID);
740
741 if (null != p)
742 {
743 if (p.PresenceType == PresenceType.Npc)
744 return;
745 }
746
747 IScene s = remoteClient.Scene;
748 if (!(s is Scene))
749 return;
750
751 Scene scene = (Scene)s;
752
753 string serverURI = string.Empty;
754 bool foreign = GetUserProfileServerURI(avatarID, out serverURI);
755
756 UserAccount account = null;
757 Dictionary<string,object> userInfo;
758
759 if (!foreign)
760 {
761 account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, avatarID);
762 }
763 else
764 {
765 userInfo = new Dictionary<string, object>();
766 }
767
768 Byte[] charterMember = new Byte[1];
769 string born = String.Empty;
770 uint flags = 0x00;
771
772 if (null != account)
773 {
774 if (account.UserTitle == "")
775 {
776 charterMember[0] = (Byte)((account.UserFlags & 0xf00) >> 8);
777 }
778 else
779 {
780 charterMember = Utils.StringToBytes(account.UserTitle);
781 }
782
783 born = Util.ToDateTime(account.Created).ToString(
784 "M/d/yyyy", CultureInfo.InvariantCulture);
785 flags = (uint)(account.UserFlags & 0xff);
786 }
787 else
788 {
789 if (GetUserProfileData(avatarID, out userInfo) == true)
790 {
791 if ((string)userInfo["user_title"] == "")
792 {
793 charterMember[0] = (Byte)(((Byte)userInfo["user_flags"] & 0xf00) >> 8);
794 }
795 else
796 {
797 charterMember = Utils.StringToBytes((string)userInfo["user_title"]);
798 }
799
800 int val_born = (int)userInfo["user_created"];
801 born = Util.ToDateTime(val_born).ToString(
802 "M/d/yyyy", CultureInfo.InvariantCulture);
803
804 // picky, picky
805 int val_flags = (int)userInfo["user_flags"];
806 flags = (uint)(val_flags & 0xff);
807 }
808 }
809
810 Hashtable profileData = GetProfileData(avatarID);
811 string profileUrl = string.Empty;
812 string aboutText = String.Empty;
813 string firstLifeAboutText = String.Empty;
814 UUID image = UUID.Zero;
815 UUID firstLifeImage = UUID.Zero;
816 UUID partner = UUID.Zero;
817 uint wantMask = 0;
818 string wantText = String.Empty;
819 uint skillsMask = 0;
820 string skillsText = String.Empty;
821 string languages = String.Empty;
822
823 if (profileData["ProfileUrl"] != null)
824 profileUrl = profileData["ProfileUrl"].ToString();
825 if (profileData["AboutText"] != null)
826 aboutText = profileData["AboutText"].ToString();
827 if (profileData["FirstLifeAboutText"] != null)
828 firstLifeAboutText = profileData["FirstLifeAboutText"].ToString();
829 if (profileData["Image"] != null)
830 image = new UUID(profileData["Image"].ToString());
831 if (profileData["FirstLifeImage"] != null)
832 firstLifeImage = new UUID(profileData["FirstLifeImage"].ToString());
833 if (profileData["Partner"] != null)
834 partner = new UUID(profileData["Partner"].ToString());
835
836 // The PROFILE information is no longer stored in the user
837 // account. It now needs to be taken from the XMLRPC
838 //
839 remoteClient.SendAvatarProperties(avatarID, aboutText,born,
840 charterMember, firstLifeAboutText,
841 flags,
842 firstLifeImage, image, profileUrl, partner);
843
844 //Viewer expects interest data when it asks for properties.
845 if (profileData["wantmask"] != null)
846 wantMask = Convert.ToUInt32(profileData["wantmask"].ToString());
847 if (profileData["wanttext"] != null)
848 wantText = profileData["wanttext"].ToString();
849
850 if (profileData["skillsmask"] != null)
851 skillsMask = Convert.ToUInt32(profileData["skillsmask"].ToString());
852 if (profileData["skillstext"] != null)
853 skillsText = profileData["skillstext"].ToString();
854
855 if (profileData["languages"] != null)
856 languages = profileData["languages"].ToString();
857
858 remoteClient.SendAvatarInterestsReply(avatarID, wantMask, wantText,
859 skillsMask, skillsText, languages);
860 }
861
862 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile)
863 {
864 // if it's the profile of the user requesting the update, then we change only a few things.
865 if (remoteClient.AgentId == newProfile.ID)
866 {
867 Hashtable ReqHash = new Hashtable();
868
869 ReqHash["avatar_id"] = remoteClient.AgentId.ToString();
870 ReqHash["ProfileUrl"] = newProfile.ProfileUrl;
871 ReqHash["Image"] = newProfile.Image.ToString();
872 ReqHash["AboutText"] = newProfile.AboutText;
873 ReqHash["FirstLifeImage"] = newProfile.FirstLifeImage.ToString();
874 ReqHash["FirstLifeAboutText"] = newProfile.FirstLifeAboutText;
875
876 string serverURI = string.Empty;
877 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
878
879 Hashtable result = GenericXMLRPCRequest(ReqHash,
880 "avatar_properties_update", serverURI);
881
882 if (!Convert.ToBoolean(result["success"]))
883 {
884 remoteClient.SendAgentAlertMessage(
885 result["errorMessage"].ToString(), false);
886 }
887
888 RequestAvatarProperties(remoteClient, newProfile.ID);
889 }
890 }
891
892 private bool GetUserProfileServerURI(UUID userID, out string serverURI)
893 {
894 IUserManagement uManage = UserManagementModule;
895
896 if (!uManage.IsLocalGridUser(userID))
897 {
898 serverURI = uManage.GetUserServerURL(userID, "ProfileServerURI");
899 // Is Foreign
900 return true;
901 }
902 else
903 {
904 serverURI = m_ProfileServer;
905 // Is local
906 return false;
907 }
908 }
909
910 //
911 // Get the UserAccountBits
912 //
913 private bool GetUserProfileData(UUID userID, out Dictionary<string, object> userInfo)
914 {
915 IUserManagement uManage = UserManagementModule;
916 Dictionary<string,object> info = new Dictionary<string, object>();
917
918
919 if (!uManage.IsLocalGridUser(userID))
920 {
921 // Is Foreign
922 string home_url = uManage.GetUserServerURL(userID, "HomeURI");
923
924 if (String.IsNullOrEmpty(home_url))
925 {
926 info["user_flags"] = 0;
927 info["user_created"] = 0;
928 info["user_title"] = "Unavailable";
929
930 userInfo = info;
931 return true;
932 }
933
934 UserAgentServiceConnector uConn = new UserAgentServiceConnector(home_url);
935
936 Dictionary<string, object> account = uConn.GetUserInfo(userID);
937
938 if (account.Count > 0)
939 {
940 if (account.ContainsKey("user_flags"))
941 info["user_flags"] = account["user_flags"];
942 else
943 info["user_flags"] = "";
944
945 if (account.ContainsKey("user_created"))
946 info["user_created"] = account["user_created"];
947 else
948 info["user_created"] = "";
949
950 info["user_title"] = "HG Visitor";
951 }
952 else
953 {
954 info["user_flags"] = 0;
955 info["user_created"] = 0;
956 info["user_title"] = "HG Visitor";
957 }
958 userInfo = info;
959 return true;
960 }
961 else
962 {
963 // Is local
964 Scene scene = m_Scenes[0];
965 IUserAccountService uas = scene.UserAccountService;
966 UserAccount account = uas.GetUserAccount(scene.RegionInfo.ScopeID, userID);
967
968 info["user_flags"] = account.UserFlags;
969 info["user_created"] = account.Created;
970
971 if (!String.IsNullOrEmpty(account.UserTitle))
972 info["user_title"] = account.UserTitle;
973 else
974 info["user_title"] = "";
975
976 userInfo = info;
977
978 return false;
979 }
980 }
981 }
982}