aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
diff options
context:
space:
mode:
authorDiva Canto2013-02-19 07:26:40 -0800
committerDiva Canto2013-02-19 07:26:40 -0800
commit9380d01976726885bd993573aa649f2cb0992909 (patch)
treee34fd4278fe75f1b01e3f16346bc83f15a16b383 /OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
parentOffline IM: moved the Data and MySQL bits to the corresponding places in core... (diff)
downloadopensim-SC_OLD-9380d01976726885bd993573aa649f2cb0992909.zip
opensim-SC_OLD-9380d01976726885bd993573aa649f2cb0992909.tar.gz
opensim-SC_OLD-9380d01976726885bd993573aa649f2cb0992909.tar.bz2
opensim-SC_OLD-9380d01976726885bd993573aa649f2cb0992909.tar.xz
First commit of Diva Groups. The Data bits went to OpenSim.Data core, the rest to Addons.Groups.dll.
Diffstat (limited to 'OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs')
-rw-r--r--OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs717
1 files changed, 717 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
new file mode 100644
index 0000000..f670272
--- /dev/null
+++ b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
@@ -0,0 +1,717 @@
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
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Services.Interfaces;
39
40using OpenMetaverse;
41using Mono.Addins;
42using log4net;
43using Nini.Config;
44
45namespace OpenSim.Groups
46{
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceHGConnectorModule")]
48 public class GroupsServiceHGConnectorModule : ISharedRegionModule, IGroupsServicesConnector
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private bool m_Enabled = false;
53 private IGroupsServicesConnector m_LocalGroupsConnector;
54 private string m_LocalGroupsServiceLocation;
55 private IUserManagement m_UserManagement;
56 private IOfflineIMService m_OfflineIM;
57 private IMessageTransferModule m_Messaging;
58 private List<Scene> m_Scenes;
59 private ForeignImporter m_ForeignImporter;
60 private string m_ServiceLocation;
61 private IConfigSource m_Config;
62
63 private Dictionary<string, GroupsServiceHGConnector> m_NetworkConnectors = new Dictionary<string, GroupsServiceHGConnector>();
64 private RemoteConnectorCacheWrapper m_CacheWrapper; // for caching info of external group services
65
66 #region ISharedRegionModule
67
68 public void Initialise(IConfigSource config)
69 {
70 IConfig groupsConfig = config.Configs["Groups"];
71 if (groupsConfig == null)
72 return;
73
74 if ((groupsConfig.GetBoolean("Enabled", false) == false)
75 || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
76 {
77 return;
78 }
79
80 m_Config = config;
81 m_ServiceLocation = groupsConfig.GetString("LocalService", "local"); // local or remote
82 m_LocalGroupsServiceLocation = groupsConfig.GetString("GroupsExternalURI", "http://127.0.0.1");
83 m_Scenes = new List<Scene>();
84
85 m_Enabled = true;
86
87 m_log.DebugFormat("[Groups]: Initializing {0} with LocalService {1}", this.Name, m_ServiceLocation);
88 }
89
90 public string Name
91 {
92 get { return "Groups HG Service Connector"; }
93 }
94
95 public Type ReplaceableInterface
96 {
97 get { return null; }
98 }
99
100 public void AddRegion(Scene scene)
101 {
102 if (!m_Enabled)
103 return;
104
105 m_log.DebugFormat("[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
106 scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
107 m_Scenes.Add(scene);
108
109 scene.EventManager.OnNewClient += OnNewClient;
110 }
111
112 public void RemoveRegion(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
118 m_Scenes.Remove(scene);
119 }
120
121 public void RegionLoaded(Scene scene)
122 {
123 if (!m_Enabled)
124 return;
125
126 if (m_UserManagement == null)
127 {
128 m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
129 m_OfflineIM = scene.RequestModuleInterface<IOfflineIMService>();
130 m_Messaging = scene.RequestModuleInterface<IMessageTransferModule>();
131 m_ForeignImporter = new ForeignImporter(m_UserManagement);
132
133 if (m_ServiceLocation.Equals("local"))
134 {
135 m_LocalGroupsConnector = new GroupsServiceLocalConnectorModule(m_Config, m_UserManagement);
136 // Also, if local, create the endpoint for the HGGroupsService
137 new HGGroupsServiceRobustConnector(m_Config, MainServer.Instance, string.Empty,
138 scene.RequestModuleInterface<IOfflineIMService>(), scene.RequestModuleInterface<IUserAccountService>());
139
140 }
141 else
142 m_LocalGroupsConnector = new GroupsServiceRemoteConnectorModule(m_Config, m_UserManagement);
143
144 m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
145 }
146
147 }
148
149 public void PostInitialise()
150 {
151 }
152
153 public void Close()
154 {
155 }
156
157 #endregion
158
159 private void OnNewClient(IClientAPI client)
160 {
161 client.OnCompleteMovementToRegion += OnCompleteMovementToRegion;
162 }
163
164 void OnCompleteMovementToRegion(IClientAPI client, bool arg2)
165 {
166 object sp = null;
167 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
168 {
169 if (sp is ScenePresence && ((ScenePresence)sp).PresenceType != PresenceType.Npc)
170 {
171 AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId);
172 if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 &&
173 m_OfflineIM != null && m_Messaging != null)
174 {
175 List<GridInstantMessage> ims = m_OfflineIM.GetMessages(aCircuit.AgentID);
176 if (ims != null && ims.Count > 0)
177 foreach (GridInstantMessage im in ims)
178 m_Messaging.SendInstantMessage(im, delegate(bool success) { });
179 }
180 }
181 }
182 }
183
184 #region IGroupsServicesConnector
185
186 public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
187 bool allowPublish, bool maturePublish, UUID founderID, out string reason)
188 {
189 m_log.DebugFormat("[Groups]: Creating group {0}", name);
190 reason = string.Empty;
191 if (m_UserManagement.IsLocalGridUser(RequestingAgentID))
192 return m_LocalGroupsConnector.CreateGroup(RequestingAgentID, name, charter, showInList, insigniaID,
193 membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
194 else
195 {
196 reason = "Only local grid users are allowed to create a new group";
197 return UUID.Zero;
198 }
199 }
200
201 public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
202 bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
203 {
204 reason = string.Empty;
205 string url = string.Empty;
206 string name = string.Empty;
207 if (IsLocal(groupID, out url, out name))
208 return m_LocalGroupsConnector.UpdateGroup(AgentUUI(RequestingAgentID), groupID, charter, showInList, insigniaID, membershipFee,
209 openEnrollment, allowPublish, maturePublish, out reason);
210 else
211 {
212 reason = "Changes to remote group not allowed. Please go to the group's original world.";
213 return false;
214 }
215 }
216
217 public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
218 {
219 string url = string.Empty;
220 string name = string.Empty;
221 if (IsLocal(GroupID, out url, out name))
222 return m_LocalGroupsConnector.GetGroupRecord(AgentUUI(RequestingAgentID), GroupID, GroupName);
223 else if (url != string.Empty)
224 {
225 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
226 string accessToken = string.Empty;
227 if (membership != null)
228 accessToken = membership.AccessToken;
229 else
230 return null;
231
232 GroupsServiceHGConnector c = GetConnector(url);
233 if (c != null)
234 {
235 ExtendedGroupRecord grec = m_CacheWrapper.GetGroupRecord(RequestingAgentID, GroupID, GroupName, delegate
236 {
237 return c.GetGroupRecord(AgentUUIForOutside(RequestingAgentID), GroupID, GroupName, accessToken);
238 });
239
240 if (grec != null)
241 ImportForeigner(grec.FounderUUI);
242 return grec;
243 }
244 }
245
246 return null;
247 }
248
249 public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string search)
250 {
251 return m_LocalGroupsConnector.FindGroups(AgentUUI(RequestingAgentID), search);
252 }
253
254 public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
255 {
256 string url = string.Empty, gname = string.Empty;
257 if (IsLocal(GroupID, out url, out gname))
258 return m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), GroupID);
259 else if (!string.IsNullOrEmpty(url))
260 {
261 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
262 string accessToken = string.Empty;
263 if (membership != null)
264 accessToken = membership.AccessToken;
265 else
266 return null;
267
268 GroupsServiceHGConnector c = GetConnector(url);
269 if (c != null)
270 {
271 return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
272 {
273 return c.GetGroupMembers(AgentUUIForOutside(RequestingAgentID), GroupID, accessToken);
274 });
275
276 }
277 }
278 return new List<GroupMembersData>();
279 }
280
281 public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
282 {
283 reason = string.Empty;
284 string url = string.Empty, gname = string.Empty;
285
286 if (IsLocal(groupID, out url, out gname))
287 return m_LocalGroupsConnector.AddGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers, out reason);
288 else
289 {
290 reason = "Operation not allowed outside this group's origin world.";
291 return false;
292 }
293 }
294
295 public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
296 {
297 string url = string.Empty, gname = string.Empty;
298
299 if (IsLocal(groupID, out url, out gname))
300 return m_LocalGroupsConnector.UpdateGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers);
301 else
302 {
303 return false;
304 }
305
306 }
307
308 public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
309 {
310 string url = string.Empty, gname = string.Empty;
311
312 if (IsLocal(groupID, out url, out gname))
313 m_LocalGroupsConnector.RemoveGroupRole(AgentUUI(RequestingAgentID), groupID, roleID);
314 else
315 {
316 return;
317 }
318 }
319
320 public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID groupID)
321 {
322 string url = string.Empty, gname = string.Empty;
323
324 if (IsLocal(groupID, out url, out gname))
325 return m_LocalGroupsConnector.GetGroupRoles(AgentUUI(RequestingAgentID), groupID);
326 else if (!string.IsNullOrEmpty(url))
327 {
328 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
329 string accessToken = string.Empty;
330 if (membership != null)
331 accessToken = membership.AccessToken;
332 else
333 return null;
334
335 GroupsServiceHGConnector c = GetConnector(url);
336 if (c != null)
337 {
338 return m_CacheWrapper.GetGroupRoles(RequestingAgentID, groupID, delegate
339 {
340 return c.GetGroupRoles(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
341 });
342
343 }
344 }
345
346 return new List<GroupRolesData>();
347 }
348
349 public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID groupID)
350 {
351 string url = string.Empty, gname = string.Empty;
352
353 if (IsLocal(groupID, out url, out gname))
354 return m_LocalGroupsConnector.GetGroupRoleMembers(AgentUUI(RequestingAgentID), groupID);
355 else if (!string.IsNullOrEmpty(url))
356 {
357 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
358 string accessToken = string.Empty;
359 if (membership != null)
360 accessToken = membership.AccessToken;
361 else
362 return null;
363
364 GroupsServiceHGConnector c = GetConnector(url);
365 if (c != null)
366 {
367 return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, groupID, delegate
368 {
369 return c.GetGroupRoleMembers(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
370 });
371
372 }
373 }
374
375 return new List<GroupRoleMembersData>();
376 }
377
378 public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
379 {
380 string url = string.Empty;
381 string name = string.Empty;
382 reason = string.Empty;
383
384 UUID uid = new UUID(AgentID);
385 if (IsLocal(GroupID, out url, out name))
386 {
387 if (m_UserManagement.IsLocalGridUser(uid)) // local user
388 {
389 // normal case: local group, local user
390 return m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
391 }
392 else // local group, foreign user
393 {
394 // the user is accepting the invitation, or joining, where the group resides
395 token = UUID.Random().ToString();
396 bool success = m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
397
398 if (success)
399 {
400 url = m_UserManagement.GetUserServerURL(uid, "GroupsServerURI");
401 if (url == string.Empty)
402 {
403 reason = "User doesn't have a groups server";
404 return false;
405 }
406
407 GroupsServiceHGConnector c = GetConnector(url);
408 if (c != null)
409 return c.CreateProxy(AgentUUI(RequestingAgentID), AgentID, token, GroupID, m_LocalGroupsServiceLocation, name, out reason);
410 }
411 }
412 }
413 else if (m_UserManagement.IsLocalGridUser(uid)) // local user
414 {
415 // foreign group, local user. She's been added already by the HG service.
416 // Let's just check
417 if (m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID) != null)
418 return true;
419 }
420
421 reason = "Operation not allowed outside this group's origin world";
422 return false;
423 }
424
425
426 public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
427 {
428 string url = string.Empty, name = string.Empty;
429 if (!IsLocal(GroupID, out url, out name) && url != string.Empty)
430 {
431 ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
432 if (membership != null)
433 {
434 GroupsServiceHGConnector c = GetConnector(url);
435 if (c != null)
436 c.RemoveAgentFromGroup(AgentUUIForOutside(AgentID), GroupID, membership.AccessToken);
437 }
438 }
439
440 // remove from local service
441 m_LocalGroupsConnector.RemoveAgentFromGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
442 }
443
444 public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
445 {
446 string url = string.Empty, gname = string.Empty;
447
448 if (IsLocal(groupID, out url, out gname))
449 return m_LocalGroupsConnector.AddAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID, groupID, roleID, AgentUUI(agentID));
450 else
451 return false;
452 }
453
454 public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
455 {
456 return m_LocalGroupsConnector.GetAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID); ;
457 }
458
459 public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
460 {
461 m_LocalGroupsConnector.RemoveAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID);
462 }
463
464 public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
465 {
466 string url = string.Empty, gname = string.Empty;
467
468 if (IsLocal(GroupID, out url, out gname))
469 m_LocalGroupsConnector.AddAgentToGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
470
471 }
472
473 public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
474 {
475 string url = string.Empty, gname = string.Empty;
476
477 if (IsLocal(GroupID, out url, out gname))
478 m_LocalGroupsConnector.RemoveAgentFromGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
479 }
480
481 public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
482 {
483 string url = string.Empty, gname = string.Empty;
484
485 if (IsLocal(GroupID, out url, out gname))
486 return m_LocalGroupsConnector.GetAgentGroupRoles(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
487 else
488 return new List<GroupRolesData>();
489 }
490
491 public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
492 {
493 string url = string.Empty, gname = string.Empty;
494
495 if (IsLocal(GroupID, out url, out gname))
496 m_LocalGroupsConnector.SetAgentActiveGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
497 }
498
499 public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
500 {
501 return m_LocalGroupsConnector.GetAgentActiveMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
502 }
503
504 public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
505 {
506 string url = string.Empty, gname = string.Empty;
507
508 if (IsLocal(GroupID, out url, out gname))
509 m_LocalGroupsConnector.SetAgentActiveGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
510 }
511
512 public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
513 {
514 m_LocalGroupsConnector.UpdateMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, AcceptNotices, ListInProfile);
515 }
516
517 public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
518 {
519 string url = string.Empty, gname = string.Empty;
520
521 if (IsLocal(GroupID, out url, out gname))
522 return m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
523 else
524 return null;
525 }
526
527 public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
528 {
529 return m_LocalGroupsConnector.GetAgentGroupMemberships(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
530 }
531
532 public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
533 bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
534 {
535 string url = string.Empty, gname = string.Empty;
536
537 if (IsLocal(groupID, out url, out gname))
538 {
539 if (m_LocalGroupsConnector.AddGroupNotice(AgentUUI(RequestingAgentID), groupID, noticeID, fromName, subject, message,
540 hasAttachment, attType, attName, attItemID, AgentUUI(attOwnerID)))
541 {
542 // then send the notice to every grid for which there are members in this group
543 List<GroupMembersData> members = m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), groupID);
544 List<string> urls = new List<string>();
545 foreach (GroupMembersData m in members)
546 {
547 UUID userID = UUID.Zero;
548 if (!m_UserManagement.IsLocalGridUser(m.AgentID))
549 {
550 string gURL = m_UserManagement.GetUserServerURL(m.AgentID, "GroupsServerURI");
551 if (!urls.Contains(gURL))
552 urls.Add(gURL);
553 }
554 }
555
556 // so we have the list of urls to send the notice to
557 // this may take a long time...
558 Util.FireAndForget(delegate
559 {
560 foreach (string u in urls)
561 {
562 GroupsServiceHGConnector c = GetConnector(u);
563 if (c != null)
564 {
565 c.AddNotice(AgentUUIForOutside(RequestingAgentID), groupID, noticeID, fromName, subject, message,
566 hasAttachment, attType, attName, attItemID, AgentUUIForOutside(attOwnerID));
567 }
568 }
569 });
570
571 return true;
572 }
573
574 return false;
575 }
576 else
577 return false;
578 }
579
580 public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
581 {
582 GroupNoticeInfo notice = m_LocalGroupsConnector.GetGroupNotice(AgentUUI(RequestingAgentID), noticeID);
583
584 if (notice != null && notice.noticeData.HasAttachment && notice.noticeData.AttachmentOwnerID != null)
585 ImportForeigner(notice.noticeData.AttachmentOwnerID);
586
587 return notice;
588 }
589
590 public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
591 {
592 return m_LocalGroupsConnector.GetGroupNotices(AgentUUI(RequestingAgentID), GroupID);
593 }
594
595 public void ResetAgentGroupChatSessions(string agentID)
596 {
597 }
598
599 public bool hasAgentBeenInvitedToGroupChatSession(string agentID, UUID groupID)
600 {
601 return false;
602 }
603
604 public bool hasAgentDroppedGroupChatSession(string agentID, UUID groupID)
605 {
606 return false;
607 }
608
609 public void AgentDroppedFromGroupChatSession(string agentID, UUID groupID)
610 {
611 }
612
613 public void AgentInvitedToGroupChatSession(string agentID, UUID groupID)
614 {
615 }
616
617 #endregion
618
619 #region hypergrid groups
620
621 private string AgentUUI(string AgentIDStr)
622 {
623 UUID AgentID = UUID.Zero;
624 try
625 {
626 AgentID = new UUID(AgentIDStr);
627 }
628 catch (FormatException)
629 {
630 return AgentID.ToString();
631 }
632
633 if (m_UserManagement.IsLocalGridUser(AgentID))
634 return AgentID.ToString();
635
636 AgentCircuitData agent = null;
637 foreach (Scene scene in m_Scenes)
638 {
639 agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
640 if (agent != null)
641 break;
642 }
643 if (agent == null) // oops
644 return AgentID.ToString();
645
646 return Util.ProduceUserUniversalIdentifier(agent);
647 }
648
649 private string AgentUUIForOutside(string AgentIDStr)
650 {
651 UUID AgentID = UUID.Zero;
652 try
653 {
654 AgentID = new UUID(AgentIDStr);
655 }
656 catch (FormatException)
657 {
658 return AgentID.ToString();
659 }
660
661 AgentCircuitData agent = null;
662 foreach (Scene scene in m_Scenes)
663 {
664 agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
665 if (agent != null)
666 break;
667 }
668 if (agent == null) // oops
669 return AgentID.ToString();
670
671 return Util.ProduceUserUniversalIdentifier(agent);
672 }
673
674 private UUID ImportForeigner(string uID)
675 {
676 UUID userID = UUID.Zero;
677 string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
678 if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp))
679 m_UserManagement.AddUser(userID, first, last, url);
680
681 return userID;
682 }
683
684 private bool IsLocal(UUID groupID, out string serviceLocation, out string name)
685 {
686 serviceLocation = string.Empty;
687 name = string.Empty;
688 ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID, string.Empty);
689 if (group == null)
690 {
691 //m_log.DebugFormat("[XXX]: IsLocal? group {0} not found -- no.", groupID);
692 return false;
693 }
694
695 serviceLocation = group.ServiceLocation;
696 name = group.GroupName;
697 bool isLocal = (group.ServiceLocation == string.Empty);
698 //m_log.DebugFormat("[XXX]: IsLocal? {0}", isLocal);
699 return isLocal;
700 }
701
702 private GroupsServiceHGConnector GetConnector(string url)
703 {
704 lock (m_NetworkConnectors)
705 {
706 if (m_NetworkConnectors.ContainsKey(url))
707 return m_NetworkConnectors[url];
708
709 GroupsServiceHGConnector c = new GroupsServiceHGConnector(url);
710 m_NetworkConnectors[url] = c;
711 }
712
713 return m_NetworkConnectors[url];
714 }
715 #endregion
716 }
717}