aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Addons/Groups/GroupsModule.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/GroupsModule.cs
parentOffline IM: moved the Data and MySQL bits to the corresponding places in core... (diff)
downloadopensim-SC-9380d01976726885bd993573aa649f2cb0992909.zip
opensim-SC-9380d01976726885bd993573aa649f2cb0992909.tar.gz
opensim-SC-9380d01976726885bd993573aa649f2cb0992909.tar.bz2
opensim-SC-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/GroupsModule.cs')
-rw-r--r--OpenSim/Addons/Groups/GroupsModule.cs1467
1 files changed, 1467 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/GroupsModule.cs b/OpenSim/Addons/Groups/GroupsModule.cs
new file mode 100644
index 0000000..10bfa8f
--- /dev/null
+++ b/OpenSim/Addons/Groups/GroupsModule.cs
@@ -0,0 +1,1467 @@
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.Reflection;
31using System.Timers;
32using log4net;
33using Mono.Addins;
34using Nini.Config;
35using OpenMetaverse;
36using OpenMetaverse.StructuredData;
37using OpenSim.Framework;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Services.Interfaces;
41using DirFindFlags = OpenMetaverse.DirectoryManager.DirFindFlags;
42
43namespace OpenSim.Groups
44{
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsModule")]
46 public class GroupsModule : ISharedRegionModule, IGroupsModule
47 {
48 /// <summary>
49 /// </summary>
50
51 private static readonly ILog m_log =
52 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private List<Scene> m_sceneList = new List<Scene>();
55
56 private IMessageTransferModule m_msgTransferModule = null;
57
58 private IGroupsServicesConnector m_groupData = null;
59 private IUserManagement m_UserManagement;
60
61 // Configuration settings
62 private bool m_groupsEnabled = false;
63 private bool m_groupNoticesEnabled = true;
64 private bool m_debugEnabled = false;
65 private int m_levelGroupCreate = 0;
66
67 #region Region Module interfaceBase Members
68
69 public void Initialise(IConfigSource config)
70 {
71 IConfig groupsConfig = config.Configs["Groups"];
72
73 if (groupsConfig == null)
74 {
75 // Do not run this module by default.
76 return;
77 }
78 else
79 {
80 m_groupsEnabled = groupsConfig.GetBoolean("Enabled", false);
81 if (!m_groupsEnabled)
82 {
83 return;
84 }
85
86 if (groupsConfig.GetString("Module", "Default") != Name)
87 {
88 m_groupsEnabled = false;
89
90 return;
91 }
92
93 m_log.InfoFormat("[Groups]: Initializing {0}", this.Name);
94
95 m_groupNoticesEnabled = groupsConfig.GetBoolean("NoticesEnabled", true);
96 m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);
97 m_levelGroupCreate = groupsConfig.GetInt("LevelGroupCreate", 0);
98 }
99 }
100
101 public void AddRegion(Scene scene)
102 {
103 if (m_groupsEnabled)
104 {
105 scene.RegisterModuleInterface<IGroupsModule>(this);
106 scene.AddCommand(
107 "debug",
108 this,
109 "debug groups verbose",
110 "debug groups verbose <true|false>",
111 "This setting turns on very verbose groups debugging",
112 HandleDebugGroupsVerbose);
113 }
114 }
115
116 private void HandleDebugGroupsVerbose(object modules, string[] args)
117 {
118 if (args.Length < 4)
119 {
120 MainConsole.Instance.Output("Usage: debug groups verbose <true|false>");
121 return;
122 }
123
124 bool verbose = false;
125 if (!bool.TryParse(args[3], out verbose))
126 {
127 MainConsole.Instance.Output("Usage: debug groups verbose <true|false>");
128 return;
129 }
130
131 m_debugEnabled = verbose;
132
133 MainConsole.Instance.OutputFormat("{0} verbose logging set to {1}", Name, m_debugEnabled);
134 }
135
136 public void RegionLoaded(Scene scene)
137 {
138 if (!m_groupsEnabled)
139 return;
140
141 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
142
143 scene.EventManager.OnNewClient += OnNewClient;
144 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
145 // The InstantMessageModule itself doesn't do this,
146 // so lets see if things explode if we don't do it
147 // scene.EventManager.OnClientClosed += OnClientClosed;
148
149 if (m_groupData == null)
150 {
151 m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();
152
153 // No Groups Service Connector, then nothing works...
154 if (m_groupData == null)
155 {
156 m_groupsEnabled = false;
157 m_log.Error("[Groups]: Could not get IGroupsServicesConnector");
158 RemoveRegion(scene);
159 return;
160 }
161 }
162
163 if (m_msgTransferModule == null)
164 {
165 m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
166
167 // No message transfer module, no notices, group invites, rejects, ejects, etc
168 if (m_msgTransferModule == null)
169 {
170 m_log.Warn("[Groups]: Could not get MessageTransferModule");
171 }
172 }
173
174 if (m_UserManagement == null)
175 {
176 m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
177 if (m_UserManagement == null)
178 m_log.Warn("[Groups]: Could not get UserManagementModule");
179 }
180
181 lock (m_sceneList)
182 {
183 m_sceneList.Add(scene);
184 }
185
186
187 }
188
189 public void RemoveRegion(Scene scene)
190 {
191 if (!m_groupsEnabled)
192 return;
193
194 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
195
196 scene.EventManager.OnNewClient -= OnNewClient;
197 scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
198
199 lock (m_sceneList)
200 {
201 m_sceneList.Remove(scene);
202 }
203 }
204
205 public void Close()
206 {
207 if (!m_groupsEnabled)
208 return;
209
210 if (m_debugEnabled) m_log.Debug("[Groups]: Shutting down Groups module.");
211 }
212
213 public Type ReplaceableInterface
214 {
215 get { return null; }
216 }
217
218 public string Name
219 {
220 get { return "Groups Module V2"; }
221 }
222
223 public void PostInitialise()
224 {
225 // NoOp
226 }
227
228 #endregion
229
230 #region EventHandlers
231 private void OnNewClient(IClientAPI client)
232 {
233 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
234
235 client.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
236 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
237 client.OnDirFindQuery += OnDirFindQuery;
238 client.OnRequestAvatarProperties += OnRequestAvatarProperties;
239
240 // Used for Notices and Group Invites/Accept/Reject
241 client.OnInstantMessage += OnInstantMessage;
242
243 // Send client their groups information.
244 SendAgentGroupDataUpdate(client, client.AgentId);
245 }
246
247 private void OnRequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
248 {
249 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
250
251 //GroupMembershipData[] avatarGroups = m_groupData.GetAgentGroupMemberships(GetRequestingAgentID(remoteClient), avatarID).ToArray();
252 GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
253 remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
254 }
255
256 /*
257 * This becomes very problematic in a shared module. In a shared module you may have more then one
258 * reference to IClientAPI's, one for 0 or 1 root connections, and 0 or more child connections.
259 * The OnClientClosed event does not provide anything to indicate which one of those should be closed
260 * nor does it provide what scene it was from so that the specific reference can be looked up.
261 * The InstantMessageModule.cs does not currently worry about unregistering the handles,
262 * and it should be an issue, since it's the client that references us not the other way around
263 * , so as long as we don't keep a reference to the client laying around, the client can still be GC'ed
264 private void OnClientClosed(UUID AgentId)
265 {
266 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
267
268 lock (m_ActiveClients)
269 {
270 if (m_ActiveClients.ContainsKey(AgentId))
271 {
272 IClientAPI client = m_ActiveClients[AgentId];
273 client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
274 client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
275 client.OnDirFindQuery -= OnDirFindQuery;
276 client.OnInstantMessage -= OnInstantMessage;
277
278 m_ActiveClients.Remove(AgentId);
279 }
280 else
281 {
282 if (m_debugEnabled) m_log.WarnFormat("[Groups]: Client closed that wasn't registered here.");
283 }
284
285
286 }
287 }
288 */
289
290 void OnDirFindQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart)
291 {
292 if (((DirFindFlags)queryFlags & DirFindFlags.Groups) == DirFindFlags.Groups)
293 {
294 if (m_debugEnabled)
295 m_log.DebugFormat(
296 "[Groups]: {0} called with queryText({1}) queryFlags({2}) queryStart({3})",
297 System.Reflection.MethodBase.GetCurrentMethod().Name, queryText, (DirFindFlags)queryFlags, queryStart);
298
299 // TODO: This currently ignores pretty much all the query flags including Mature and sort order
300 remoteClient.SendDirGroupsReply(queryID, m_groupData.FindGroups(GetRequestingAgentIDStr(remoteClient), queryText).ToArray());
301 }
302
303 }
304
305 private void OnAgentDataUpdateRequest(IClientAPI remoteClient, UUID dataForAgentID, UUID sessionID)
306 {
307 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
308
309 UUID activeGroupID = UUID.Zero;
310 string activeGroupTitle = string.Empty;
311 string activeGroupName = string.Empty;
312 ulong activeGroupPowers = (ulong)GroupPowers.None;
313
314 GroupMembershipData membership = m_groupData.GetAgentActiveMembership(GetRequestingAgentIDStr(remoteClient), dataForAgentID.ToString());
315 if (membership != null)
316 {
317 activeGroupID = membership.GroupID;
318 activeGroupTitle = membership.GroupTitle;
319 activeGroupPowers = membership.GroupPowers;
320 }
321
322 SendAgentDataUpdate(remoteClient, dataForAgentID, activeGroupID, activeGroupName, activeGroupPowers, activeGroupTitle);
323
324 SendScenePresenceUpdate(dataForAgentID, activeGroupTitle);
325 }
326
327 private void HandleUUIDGroupNameRequest(UUID GroupID, IClientAPI remoteClient)
328 {
329 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
330
331 string GroupName;
332
333 GroupRecord group = m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), GroupID, null);
334 if (group != null)
335 {
336 GroupName = group.GroupName;
337 }
338 else
339 {
340 GroupName = "Unknown";
341 }
342
343 remoteClient.SendGroupNameReply(GroupID, GroupName);
344 }
345
346 private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
347 {
348 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
349
350 m_log.DebugFormat("[Groups]: IM From {0} to {1} msg {2} type {3}", im.fromAgentID, im.toAgentID, im.message, (InstantMessageDialog)im.dialog);
351 // Group invitations
352 if ((im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
353 {
354 UUID inviteID = new UUID(im.imSessionID);
355 GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
356
357 if (inviteInfo == null)
358 {
359 if (m_debugEnabled) m_log.WarnFormat("[Groups]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
360 return;
361 }
362
363 //m_log.DebugFormat("[XXX]: Invite is for Agent {0} to Group {1}.", inviteInfo.AgentID, inviteInfo.GroupID);
364
365 UUID fromAgentID = new UUID(im.fromAgentID);
366 UUID invitee = UUID.Zero;
367 string tmp = string.Empty;
368 Util.ParseUniversalUserIdentifier(inviteInfo.AgentID, out invitee, out tmp, out tmp, out tmp, out tmp);
369 if ((inviteInfo != null) && (fromAgentID == invitee))
370 {
371 // Accept
372 if (im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
373 {
374 //m_log.DebugFormat("[XXX]: Received an accept invite notice.");
375
376 // and the sessionid is the role
377 string reason = string.Empty;
378 if (!m_groupData.AddAgentToGroup(GetRequestingAgentIDStr(remoteClient), invitee.ToString(), inviteInfo.GroupID, inviteInfo.RoleID, string.Empty, out reason))
379 remoteClient.SendAgentAlertMessage("Unable to add you to the group: " + reason, false);
380 else
381 {
382 GridInstantMessage msg = new GridInstantMessage();
383 msg.imSessionID = UUID.Zero.Guid;
384 msg.fromAgentID = UUID.Zero.Guid;
385 msg.toAgentID = invitee.Guid;
386 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
387 msg.fromAgentName = "Groups";
388 msg.message = string.Format("You have been added to the group.");
389 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
390 msg.fromGroup = false;
391 msg.offline = (byte)0;
392 msg.ParentEstateID = 0;
393 msg.Position = Vector3.Zero;
394 msg.RegionID = UUID.Zero.Guid;
395 msg.binaryBucket = new byte[0];
396
397 OutgoingInstantMessage(msg, invitee);
398
399 UpdateAllClientsWithGroupInfo(invitee);
400 }
401
402 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
403
404 }
405
406 // Reject
407 if (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
408 {
409 if (m_debugEnabled) m_log.DebugFormat("[Groups]: Received a reject invite notice.");
410 m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);
411
412 m_groupData.RemoveAgentFromGroup(GetRequestingAgentIDStr(remoteClient), inviteInfo.AgentID, inviteInfo.GroupID);
413 }
414 }
415 }
416
417 // Group notices
418 if ((im.dialog == (byte)InstantMessageDialog.GroupNotice))
419 {
420 if (!m_groupNoticesEnabled)
421 {
422 return;
423 }
424
425 UUID GroupID = new UUID(im.toAgentID);
426 if (m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), GroupID, null) != null)
427 {
428 UUID NoticeID = UUID.Random();
429 string Subject = im.message.Substring(0, im.message.IndexOf('|'));
430 string Message = im.message.Substring(Subject.Length + 1);
431
432 InventoryItemBase item = null;
433 bool hasAttachment = false;
434
435 if (im.binaryBucket.Length >= 1 && im.binaryBucket[0] > 0)
436 {
437 hasAttachment = true;
438 string binBucket = OpenMetaverse.Utils.BytesToString(im.binaryBucket);
439 binBucket = binBucket.Remove(0, 14).Trim();
440
441 OSD binBucketOSD = OSDParser.DeserializeLLSDXml(binBucket);
442 if (binBucketOSD is OSDMap)
443 {
444 OSDMap binBucketMap = (OSDMap)binBucketOSD;
445
446 UUID itemID = binBucketMap["item_id"].AsUUID();
447 UUID ownerID = binBucketMap["owner_id"].AsUUID();
448 item = new InventoryItemBase(itemID, ownerID);
449 item = m_sceneList[0].InventoryService.GetItem(item);
450 }
451 else
452 m_log.DebugFormat("[Groups]: Received OSD with unexpected type: {0}", binBucketOSD.GetType());
453 }
454
455 if (m_groupData.AddGroupNotice(GetRequestingAgentIDStr(remoteClient), GroupID, NoticeID, im.fromAgentName, Subject, Message,
456 hasAttachment,
457 (byte)(item == null ? 0 : item.AssetType),
458 item == null ? null : item.Name,
459 item == null ? UUID.Zero : item.ID,
460 item == null ? UUID.Zero.ToString() : item.Owner.ToString()))
461 {
462 if (OnNewGroupNotice != null)
463 {
464 OnNewGroupNotice(GroupID, NoticeID);
465 }
466
467 // Send notice out to everyone that wants notices
468 // Build notice IIM
469 GridInstantMessage msg = CreateGroupNoticeIM(UUID.Zero, NoticeID, (byte)OpenMetaverse.InstantMessageDialog.GroupNotice);
470 foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentIDStr(remoteClient), GroupID))
471 {
472 if (member.AcceptNotices)
473 {
474 msg.toAgentID = member.AgentID.Guid;
475 OutgoingInstantMessage(msg, member.AgentID);
476 }
477 }
478 }
479 }
480 }
481
482 if (im.dialog == (byte)InstantMessageDialog.GroupNoticeInventoryAccepted)
483 {
484 if (im.binaryBucket.Length < 16) // Invalid
485 return;
486
487 //// 16 bytes are the UUID. Maybe.
488 UUID folderID = new UUID(im.binaryBucket, 0);
489 UUID noticeID = new UUID(im.imSessionID);
490
491 GroupNoticeInfo notice = m_groupData.GetGroupNotice(remoteClient.AgentId.ToString(), noticeID);
492 if (notice != null)
493 {
494 UUID giver = new UUID(im.toAgentID);
495 string tmp = string.Empty;
496 Util.ParseUniversalUserIdentifier(notice.noticeData.AttachmentOwnerID, out giver, out tmp, out tmp, out tmp, out tmp);
497
498 m_log.DebugFormat("[Groups]: Giving inventory from {0} to {1}", giver, remoteClient.AgentId);
499 InventoryItemBase itemCopy = ((Scene)(remoteClient.Scene)).GiveInventoryItem(remoteClient.AgentId,
500 giver, notice.noticeData.AttachmentItemID);
501
502 if (itemCopy == null)
503 {
504 remoteClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
505 return;
506 }
507
508 remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
509 }
510
511 }
512
513 // Interop, received special 210 code for ejecting a group member
514 // this only works within the comms servers domain, and won't work hypergrid
515 // TODO:FIXME: Use a presense server of some kind to find out where the
516 // client actually is, and try contacting that region directly to notify them,
517 // or provide the notification via xmlrpc update queue
518 if ((im.dialog == 210))
519 {
520 // This is sent from the region that the ejectee was ejected from
521 // if it's being delivered here, then the ejectee is here
522 // so we need to send local updates to the agent.
523
524 UUID ejecteeID = new UUID(im.toAgentID);
525
526 im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
527 OutgoingInstantMessage(im, ejecteeID);
528
529 IClientAPI ejectee = GetActiveClient(ejecteeID);
530 if (ejectee != null)
531 {
532 UUID groupID = new UUID(im.imSessionID);
533 ejectee.SendAgentDropGroup(groupID);
534 }
535 }
536 }
537
538 private void OnGridInstantMessage(GridInstantMessage msg)
539 {
540 if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
541
542 // Trigger the above event handler
543 OnInstantMessage(null, msg);
544
545 // If a message from a group arrives here, it may need to be forwarded to a local client
546 if (msg.fromGroup == true)
547 {
548 switch (msg.dialog)
549 {
550 case (byte)InstantMessageDialog.GroupInvitation:
551 case (byte)InstantMessageDialog.GroupNotice:
552 UUID toAgentID = new UUID(msg.toAgentID);
553 IClientAPI localClient = GetActiveClient(toAgentID);
554 if (localClient != null)
555 {
556 localClient.SendInstantMessage(msg);
557 }
558 break;
559 }
560 }
561 }
562
563 #endregion
564
565 #region IGroupsModule Members
566
567 public event NewGroupNotice OnNewGroupNotice;
568
569 public GroupRecord GetGroupRecord(UUID GroupID)
570 {
571 return m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null);
572 }
573
574 public GroupRecord GetGroupRecord(string name)
575 {
576 return m_groupData.GetGroupRecord(UUID.Zero.ToString(), UUID.Zero, name);
577 }
578
579 public void ActivateGroup(IClientAPI remoteClient, UUID groupID)
580 {
581 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
582
583 m_groupData.SetAgentActiveGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
584
585 // Changing active group changes title, active powers, all kinds of things
586 // anyone who is in any region that can see this client, should probably be
587 // updated with new group info. At a minimum, they should get ScenePresence
588 // updated with new title.
589 UpdateAllClientsWithGroupInfo(remoteClient.AgentId);
590 }
591
592 /// <summary>
593 /// Get the Role Titles for an Agent, for a specific group
594 /// </summary>
595 public List<GroupTitlesData> GroupTitlesRequest(IClientAPI remoteClient, UUID groupID)
596 {
597 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
598
599 List<GroupRolesData> agentRoles = m_groupData.GetAgentGroupRoles(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
600 GroupMembershipData agentMembership = m_groupData.GetAgentGroupMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
601
602 List<GroupTitlesData> titles = new List<GroupTitlesData>();
603 foreach (GroupRolesData role in agentRoles)
604 {
605 GroupTitlesData title = new GroupTitlesData();
606 title.Name = role.Name;
607 if (agentMembership != null)
608 {
609 title.Selected = agentMembership.ActiveRole == role.RoleID;
610 }
611 title.UUID = role.RoleID;
612
613 titles.Add(title);
614 }
615
616 return titles;
617 }
618
619 public List<GroupMembersData> GroupMembersRequest(IClientAPI remoteClient, UUID groupID)
620 {
621 if (m_debugEnabled)
622 m_log.DebugFormat(
623 "[Groups]: GroupMembersRequest called for {0} from client {1}", groupID, remoteClient.Name);
624
625 List<GroupMembersData> data = m_groupData.GetGroupMembers(GetRequestingAgentIDStr(remoteClient), groupID);
626
627 if (m_debugEnabled)
628 {
629 foreach (GroupMembersData member in data)
630 {
631 m_log.DebugFormat("[Groups]: Member({0}) - IsOwner({1})", member.AgentID, member.IsOwner);
632 }
633 }
634
635 return data;
636
637 }
638
639 public List<GroupRolesData> GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID)
640 {
641 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
642
643 List<GroupRolesData> data = m_groupData.GetGroupRoles(GetRequestingAgentIDStr(remoteClient), groupID);
644
645 return data;
646 }
647
648 public List<GroupRoleMembersData> GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID)
649 {
650 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
651
652 List<GroupRoleMembersData> data = m_groupData.GetGroupRoleMembers(GetRequestingAgentIDStr(remoteClient), groupID);
653
654 if (m_debugEnabled)
655 {
656 foreach (GroupRoleMembersData member in data)
657 {
658 m_log.DebugFormat("[Groups]: Member({0}) - Role({1})", member.MemberID, member.RoleID);
659 }
660 }
661 return data;
662 }
663
664 public GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID)
665 {
666 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
667
668 GroupProfileData profile = new GroupProfileData();
669
670 // just to get the OwnerRole...
671 ExtendedGroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), groupID, string.Empty);
672 GroupMembershipData memberInfo = m_groupData.GetAgentGroupMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
673 if (groupInfo != null)
674 {
675 profile.AllowPublish = groupInfo.AllowPublish;
676 profile.Charter = groupInfo.Charter;
677 profile.FounderID = groupInfo.FounderID;
678 profile.GroupID = groupID;
679 profile.GroupMembershipCount = groupInfo.MemberCount;
680 profile.GroupRolesCount = groupInfo.RoleCount;
681 profile.InsigniaID = groupInfo.GroupPicture;
682 profile.MaturePublish = groupInfo.MaturePublish;
683 profile.MembershipFee = groupInfo.MembershipFee;
684 profile.Money = 0;
685 profile.Name = groupInfo.GroupName;
686 profile.OpenEnrollment = groupInfo.OpenEnrollment;
687 profile.OwnerRole = groupInfo.OwnerRoleID;
688 profile.ShowInList = groupInfo.ShowInList;
689 }
690 if (memberInfo != null)
691 {
692 profile.MemberTitle = memberInfo.GroupTitle;
693 profile.PowersMask = memberInfo.GroupPowers;
694 }
695
696 return profile;
697 }
698
699 public GroupMembershipData[] GetMembershipData(UUID agentID)
700 {
701 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
702
703 return m_groupData.GetAgentGroupMemberships(UUID.Zero.ToString(), agentID.ToString()).ToArray();
704 }
705
706 public GroupMembershipData GetMembershipData(UUID groupID, UUID agentID)
707 {
708 if (m_debugEnabled)
709 m_log.DebugFormat(
710 "[Groups]: {0} called with groupID={1}, agentID={2}",
711 System.Reflection.MethodBase.GetCurrentMethod().Name, groupID, agentID);
712
713 return m_groupData.GetAgentGroupMembership(UUID.Zero.ToString(), agentID.ToString(), groupID);
714 }
715
716 public void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
717 {
718 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
719
720 // Note: Permissions checking for modification rights is handled by the Groups Server/Service
721 string reason = string.Empty;
722 if (!m_groupData.UpdateGroup(GetRequestingAgentIDStr(remoteClient), groupID, charter, showInList, insigniaID, membershipFee,
723 openEnrollment, allowPublish, maturePublish, out reason))
724 remoteClient.SendAgentAlertMessage(reason, false);
725 }
726
727 public void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile)
728 {
729 // Note: Permissions checking for modification rights is handled by the Groups Server/Service
730 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
731
732 m_groupData.UpdateMembership(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID, acceptNotices, listInProfile);
733 }
734
735 public UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
736 {
737 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called in {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.Scene.RegionInfo.RegionName);
738
739 if (m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), UUID.Zero, name) != null)
740 {
741 remoteClient.SendCreateGroupReply(UUID.Zero, false, "A group with the same name already exists.");
742 return UUID.Zero;
743 }
744
745 // check user level
746 ScenePresence avatar = null;
747 Scene scene = (Scene)remoteClient.Scene;
748 scene.TryGetScenePresence(remoteClient.AgentId, out avatar);
749
750 if (avatar != null)
751 {
752 if (avatar.UserLevel < m_levelGroupCreate)
753 {
754 remoteClient.SendCreateGroupReply(UUID.Zero, false, String.Format("Insufficient permissions to create a group. Requires level {0}", m_levelGroupCreate));
755 return UUID.Zero;
756 }
757 }
758
759 // check funds
760 // is there is a money module present ?
761 IMoneyModule money = scene.RequestModuleInterface<IMoneyModule>();
762 if (money != null)
763 {
764 // do the transaction, that is if the agent has got sufficient funds
765 if (!money.AmountCovered(remoteClient.AgentId, money.GroupCreationCharge)) {
766 remoteClient.SendCreateGroupReply(UUID.Zero, false, "Insufficient funds to create a group.");
767 return UUID.Zero;
768 }
769 money.ApplyCharge(remoteClient.AgentId, money.GroupCreationCharge, "Group Creation");
770 }
771 string reason = string.Empty;
772 UUID groupID = m_groupData.CreateGroup(remoteClient.AgentId, name, charter, showInList, insigniaID, membershipFee, openEnrollment,
773 allowPublish, maturePublish, remoteClient.AgentId, out reason);
774
775 if (groupID != UUID.Zero)
776 {
777 remoteClient.SendCreateGroupReply(groupID, true, "Group created successfullly");
778
779 // Update the founder with new group information.
780 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
781 }
782 else
783 remoteClient.SendCreateGroupReply(groupID, false, reason);
784
785 return groupID;
786 }
787
788 public GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID groupID)
789 {
790 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
791
792 // ToDo: check if agent is a member of group and is allowed to see notices?
793
794 List<ExtendedGroupNoticeData> notices = m_groupData.GetGroupNotices(GetRequestingAgentIDStr(remoteClient), groupID);
795 List<GroupNoticeData> os_notices = new List<GroupNoticeData>();
796 foreach (ExtendedGroupNoticeData n in notices)
797 {
798 GroupNoticeData osn = n.ToGroupNoticeData();
799 os_notices.Add(osn);
800 }
801
802 return os_notices.ToArray();
803 }
804
805 /// <summary>
806 /// Get the title of the agent's current role.
807 /// </summary>
808 public string GetGroupTitle(UUID avatarID)
809 {
810 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
811
812 GroupMembershipData membership = m_groupData.GetAgentActiveMembership(UUID.Zero.ToString(), avatarID.ToString());
813 if (membership != null)
814 {
815 return membership.GroupTitle;
816 }
817 return string.Empty;
818 }
819
820 /// <summary>
821 /// Change the current Active Group Role for Agent
822 /// </summary>
823 public void GroupTitleUpdate(IClientAPI remoteClient, UUID groupID, UUID titleRoleID)
824 {
825 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
826
827 m_groupData.SetAgentActiveGroupRole(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID, titleRoleID);
828
829 // TODO: Not sure what all is needed here, but if the active group role change is for the group
830 // the client currently has set active, then we need to do a scene presence update too
831 // if (m_groupData.GetAgentActiveMembership(GetRequestingAgentID(remoteClient)).GroupID == GroupID)
832
833 UpdateAllClientsWithGroupInfo(GetRequestingAgentID(remoteClient));
834 }
835
836
837 public void GroupRoleUpdate(IClientAPI remoteClient, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, byte updateType)
838 {
839 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
840
841 // Security Checks are handled in the Groups Service.
842
843 switch ((OpenMetaverse.GroupRoleUpdate)updateType)
844 {
845 case OpenMetaverse.GroupRoleUpdate.Create:
846 string reason = string.Empty;
847 if (!m_groupData.AddGroupRole(GetRequestingAgentIDStr(remoteClient), groupID, UUID.Random(), name, description, title, powers, out reason))
848 remoteClient.SendAgentAlertMessage("Unable to create role: " + reason, false);
849 break;
850
851 case OpenMetaverse.GroupRoleUpdate.Delete:
852 m_groupData.RemoveGroupRole(GetRequestingAgentIDStr(remoteClient), groupID, roleID);
853 break;
854
855 case OpenMetaverse.GroupRoleUpdate.UpdateAll:
856 case OpenMetaverse.GroupRoleUpdate.UpdateData:
857 case OpenMetaverse.GroupRoleUpdate.UpdatePowers:
858 if (m_debugEnabled)
859 {
860 GroupPowers gp = (GroupPowers)powers;
861 m_log.DebugFormat("[Groups]: Role ({0}) updated with Powers ({1}) ({2})", name, powers.ToString(), gp.ToString());
862 }
863 m_groupData.UpdateGroupRole(GetRequestingAgentIDStr(remoteClient), groupID, roleID, name, description, title, powers);
864 break;
865
866 case OpenMetaverse.GroupRoleUpdate.NoUpdate:
867 default:
868 // No Op
869 break;
870
871 }
872
873 // TODO: This update really should send out updates for everyone in the role that just got changed.
874 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
875 }
876
877 public void GroupRoleChanges(IClientAPI remoteClient, UUID groupID, UUID roleID, UUID memberID, uint changes)
878 {
879 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
880 // Todo: Security check
881
882 switch (changes)
883 {
884 case 0:
885 // Add
886 m_groupData.AddAgentToGroupRole(GetRequestingAgentIDStr(remoteClient), memberID.ToString(), groupID, roleID);
887
888 break;
889 case 1:
890 // Remove
891 m_groupData.RemoveAgentFromGroupRole(GetRequestingAgentIDStr(remoteClient), memberID.ToString(), groupID, roleID);
892
893 break;
894 default:
895 m_log.ErrorFormat("[Groups]: {0} does not understand changes == {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, changes);
896 break;
897 }
898
899 // TODO: This update really should send out updates for everyone in the role that just got changed.
900 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
901 }
902
903 public void GroupNoticeRequest(IClientAPI remoteClient, UUID groupNoticeID)
904 {
905 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called for notice {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, groupNoticeID);
906
907 //GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), data.GroupID, null);
908
909 GridInstantMessage msg = CreateGroupNoticeIM(remoteClient.AgentId, groupNoticeID, (byte)InstantMessageDialog.GroupNoticeRequested);
910 //GridInstantMessage msg = new GridInstantMessage();
911 //msg.imSessionID = UUID.Zero.Guid;
912 //msg.fromAgentID = data.GroupID.Guid;
913 //msg.toAgentID = GetRequestingAgentID(remoteClient).Guid;
914 //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
915 //msg.fromAgentName = "Group Notice : " + groupInfo == null ? "Unknown" : groupInfo.GroupName;
916 //msg.message = data.noticeData.Subject + "|" + data.Message;
917 //msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupNoticeRequested;
918 //msg.fromGroup = true;
919 //msg.offline = (byte)0;
920 //msg.ParentEstateID = 0;
921 //msg.Position = Vector3.Zero;
922 //msg.RegionID = UUID.Zero.Guid;
923 //msg.binaryBucket = data.BinaryBucket;
924
925 OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
926 }
927
928 public GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
929 {
930 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
931
932 GridInstantMessage msg = new GridInstantMessage();
933 byte[] bucket;
934
935 msg.imSessionID = groupNoticeID.Guid;
936 msg.toAgentID = agentID.Guid;
937 msg.dialog = dialog;
938 // msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupNotice;
939 msg.fromGroup = true;
940 msg.offline = (byte)0;
941 msg.ParentEstateID = 0;
942 msg.Position = Vector3.Zero;
943 msg.RegionID = UUID.Zero.Guid;
944
945 GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID.ToString(), groupNoticeID);
946 if (info != null)
947 {
948 msg.fromAgentID = info.GroupID.Guid;
949 msg.timestamp = info.noticeData.Timestamp;
950 msg.fromAgentName = info.noticeData.FromName;
951 msg.message = info.noticeData.Subject + "|" + info.Message;
952 if (info.noticeData.HasAttachment)
953 {
954 byte[] name = System.Text.Encoding.UTF8.GetBytes(info.noticeData.AttachmentName);
955 bucket = new byte[19 + name.Length];
956 bucket[0] = 1; // has attachment?
957 bucket[1] = info.noticeData.AttachmentType; // attachment type
958 name.CopyTo(bucket, 18);
959 }
960 else
961 {
962 bucket = new byte[19];
963 bucket[0] = 0; // Has att?
964 bucket[1] = 0; // type
965 bucket[18] = 0; // null terminated
966 }
967
968 info.GroupID.ToBytes(bucket, 2);
969 msg.binaryBucket = bucket;
970 }
971 else
972 {
973 m_log.DebugFormat("[Groups]: Group Notice {0} not found, composing empty message.", groupNoticeID);
974 msg.fromAgentID = UUID.Zero.Guid;
975 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); ;
976 msg.fromAgentName = string.Empty;
977 msg.message = string.Empty;
978 msg.binaryBucket = new byte[0];
979 }
980
981 return msg;
982 }
983
984 public void SendAgentGroupDataUpdate(IClientAPI remoteClient)
985 {
986 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
987
988 // Send agent information about his groups
989 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
990 }
991
992 public void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
993 {
994 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
995
996 string reason = string.Empty;
997 // Should check to see if OpenEnrollment, or if there's an outstanding invitation
998 if (m_groupData.AddAgentToGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID, UUID.Zero, string.Empty, out reason))
999 {
1000
1001 remoteClient.SendJoinGroupReply(groupID, true);
1002
1003 // Should this send updates to everyone in the group?
1004 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
1005 }
1006 else
1007 remoteClient.SendJoinGroupReply(groupID, false);
1008 }
1009
1010 public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
1011 {
1012 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1013
1014 m_groupData.RemoveAgentFromGroup(GetRequestingAgentIDStr(remoteClient), GetRequestingAgentIDStr(remoteClient), groupID);
1015
1016 remoteClient.SendLeaveGroupReply(groupID, true);
1017
1018 remoteClient.SendAgentDropGroup(groupID);
1019
1020 // SL sends out notifcations to the group messaging session that the person has left
1021 // Should this also update everyone who is in the group?
1022 SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
1023 }
1024
1025 public void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
1026 {
1027 EjectGroupMember(remoteClient, GetRequestingAgentID(remoteClient), groupID, ejecteeID);
1028 }
1029
1030 public void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
1031 {
1032 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1033
1034 // Todo: Security check?
1035 m_groupData.RemoveAgentFromGroup(agentID.ToString(), ejecteeID.ToString(), groupID);
1036
1037 string agentName;
1038 RegionInfo regionInfo;
1039
1040 // remoteClient provided or just agentID?
1041 if (remoteClient != null)
1042 {
1043 agentName = remoteClient.Name;
1044 regionInfo = remoteClient.Scene.RegionInfo;
1045 remoteClient.SendEjectGroupMemberReply(agentID, groupID, true);
1046 }
1047 else
1048 {
1049 IClientAPI client = GetActiveClient(agentID);
1050
1051 if (client != null)
1052 {
1053 agentName = client.Name;
1054 regionInfo = client.Scene.RegionInfo;
1055 client.SendEjectGroupMemberReply(agentID, groupID, true);
1056 }
1057 else
1058 {
1059 regionInfo = m_sceneList[0].RegionInfo;
1060 UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
1061
1062 if (acc != null)
1063 {
1064 agentName = acc.FirstName + " " + acc.LastName;
1065 }
1066 else
1067 {
1068 agentName = "Unknown member";
1069 }
1070 }
1071 }
1072
1073 GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);
1074
1075 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
1076 if ((groupInfo == null) || (account == null))
1077 {
1078 return;
1079 }
1080
1081 // Send Message to Ejectee
1082 GridInstantMessage msg = new GridInstantMessage();
1083
1084 msg.imSessionID = UUID.Zero.Guid;
1085 msg.fromAgentID = agentID.Guid;
1086 // msg.fromAgentID = info.GroupID;
1087 msg.toAgentID = ejecteeID.Guid;
1088 //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
1089 msg.timestamp = 0;
1090 msg.fromAgentName = agentName;
1091 msg.message = string.Format("You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
1092 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
1093 msg.fromGroup = false;
1094 msg.offline = (byte)0;
1095 msg.ParentEstateID = 0;
1096 msg.Position = Vector3.Zero;
1097 msg.RegionID = regionInfo.RegionID.Guid;
1098 msg.binaryBucket = new byte[0];
1099 OutgoingInstantMessage(msg, ejecteeID);
1100
1101 // Message to ejector
1102 // Interop, received special 210 code for ejecting a group member
1103 // this only works within the comms servers domain, and won't work hypergrid
1104 // TODO:FIXME: Use a presense server of some kind to find out where the
1105 // client actually is, and try contacting that region directly to notify them,
1106 // or provide the notification via xmlrpc update queue
1107
1108 msg = new GridInstantMessage();
1109 msg.imSessionID = UUID.Zero.Guid;
1110 msg.fromAgentID = agentID.Guid;
1111 msg.toAgentID = agentID.Guid;
1112 msg.timestamp = 0;
1113 msg.fromAgentName = agentName;
1114 if (account != null)
1115 {
1116 msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, account.FirstName + " " + account.LastName);
1117 }
1118 else
1119 {
1120 msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, "Unknown member");
1121 }
1122 msg.dialog = (byte)210; //interop
1123 msg.fromGroup = false;
1124 msg.offline = (byte)0;
1125 msg.ParentEstateID = 0;
1126 msg.Position = Vector3.Zero;
1127 msg.RegionID = regionInfo.RegionID.Guid;
1128 msg.binaryBucket = new byte[0];
1129 OutgoingInstantMessage(msg, agentID);
1130
1131
1132 // SL sends out messages to everyone in the group
1133 // Who all should receive updates and what should they be updated with?
1134 UpdateAllClientsWithGroupInfo(ejecteeID);
1135 }
1136
1137 public void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
1138 {
1139 InviteGroup(remoteClient, GetRequestingAgentID(remoteClient), groupID, invitedAgentID, roleID);
1140 }
1141
1142 public void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
1143 {
1144 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1145
1146 string agentName = m_UserManagement.GetUserName(agentID);
1147 RegionInfo regionInfo = m_sceneList[0].RegionInfo;
1148
1149 GroupRecord group = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);
1150 if (group == null)
1151 {
1152 m_log.DebugFormat("[Groups]: No such group {0}", groupID);
1153 return;
1154 }
1155
1156 // Todo: Security check, probably also want to send some kind of notification
1157 UUID InviteID = UUID.Random();
1158
1159 if (m_groupData.AddAgentToGroupInvite(agentID.ToString(), InviteID, groupID, roleID, invitedAgentID.ToString()))
1160 {
1161 if (m_msgTransferModule != null)
1162 {
1163 Guid inviteUUID = InviteID.Guid;
1164
1165 GridInstantMessage msg = new GridInstantMessage();
1166
1167 msg.imSessionID = inviteUUID;
1168
1169 // msg.fromAgentID = agentID.Guid;
1170 msg.fromAgentID = groupID.Guid;
1171 msg.toAgentID = invitedAgentID.Guid;
1172 //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
1173 msg.timestamp = 0;
1174 msg.fromAgentName = agentName;
1175 msg.message = string.Format("{0} has invited you to join a group called {1}. There is no cost to join this group.", agentName, group.GroupName);
1176 msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
1177 msg.fromGroup = true;
1178 msg.offline = (byte)0;
1179 msg.ParentEstateID = 0;
1180 msg.Position = Vector3.Zero;
1181 msg.RegionID = regionInfo.RegionID.Guid;
1182 msg.binaryBucket = new byte[20];
1183
1184 OutgoingInstantMessage(msg, invitedAgentID);
1185 }
1186 }
1187 }
1188
1189 #endregion
1190
1191 #region Client/Update Tools
1192
1193 /// <summary>
1194 /// Try to find an active IClientAPI reference for agentID giving preference to root connections
1195 /// </summary>
1196 private IClientAPI GetActiveClient(UUID agentID)
1197 {
1198 IClientAPI child = null;
1199
1200 // Try root avatar first
1201 foreach (Scene scene in m_sceneList)
1202 {
1203 ScenePresence sp = scene.GetScenePresence(agentID);
1204 if (sp != null)
1205 {
1206 if (!sp.IsChildAgent)
1207 {
1208 return sp.ControllingClient;
1209 }
1210 else
1211 {
1212 child = sp.ControllingClient;
1213 }
1214 }
1215 }
1216
1217 // If we didn't find a root, then just return whichever child we found, or null if none
1218 return child;
1219 }
1220
1221 /// <summary>
1222 /// Send 'remoteClient' the group membership 'data' for agent 'dataForAgentID'.
1223 /// </summary>
1224 private void SendGroupMembershipInfoViaCaps(IClientAPI remoteClient, UUID dataForAgentID, GroupMembershipData[] data)
1225 {
1226 if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1227
1228 OSDArray AgentData = new OSDArray(1);
1229 OSDMap AgentDataMap = new OSDMap(1);
1230 AgentDataMap.Add("AgentID", OSD.FromUUID(dataForAgentID));
1231 AgentData.Add(AgentDataMap);
1232
1233
1234 OSDArray GroupData = new OSDArray(data.Length);
1235 OSDArray NewGroupData = new OSDArray(data.Length);
1236
1237 foreach (GroupMembershipData membership in data)
1238 {
1239 if (GetRequestingAgentID(remoteClient) != dataForAgentID)
1240 {
1241 if (!membership.ListInProfile)
1242 {
1243 // If we're sending group info to remoteclient about another agent,
1244 // filter out groups the other agent doesn't want to share.
1245 continue;
1246 }
1247 }
1248
1249 OSDMap GroupDataMap = new OSDMap(6);
1250 OSDMap NewGroupDataMap = new OSDMap(1);
1251
1252 GroupDataMap.Add("GroupID", OSD.FromUUID(membership.GroupID));
1253 GroupDataMap.Add("GroupPowers", OSD.FromULong(membership.GroupPowers));
1254 GroupDataMap.Add("AcceptNotices", OSD.FromBoolean(membership.AcceptNotices));
1255 GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(membership.GroupPicture));
1256 GroupDataMap.Add("Contribution", OSD.FromInteger(membership.Contribution));
1257 GroupDataMap.Add("GroupName", OSD.FromString(membership.GroupName));
1258 NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(membership.ListInProfile));
1259
1260 GroupData.Add(GroupDataMap);
1261 NewGroupData.Add(NewGroupDataMap);
1262 }
1263
1264 OSDMap llDataStruct = new OSDMap(3);
1265 llDataStruct.Add("AgentData", AgentData);
1266 llDataStruct.Add("GroupData", GroupData);
1267 llDataStruct.Add("NewGroupData", NewGroupData);
1268
1269 if (m_debugEnabled)
1270 {
1271 m_log.InfoFormat("[Groups]: {0}", OSDParser.SerializeJsonString(llDataStruct));
1272 }
1273
1274 IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
1275
1276 if (queue != null)
1277 {
1278 queue.Enqueue(queue.BuildEvent("AgentGroupDataUpdate", llDataStruct), GetRequestingAgentID(remoteClient));
1279 }
1280
1281 }
1282
1283 private void SendScenePresenceUpdate(UUID AgentID, string Title)
1284 {
1285 if (m_debugEnabled) m_log.DebugFormat("[Groups]: Updating scene title for {0} with title: {1}", AgentID, Title);
1286
1287 ScenePresence presence = null;
1288
1289 foreach (Scene scene in m_sceneList)
1290 {
1291 presence = scene.GetScenePresence(AgentID);
1292 if (presence != null)
1293 {
1294 if (presence.Grouptitle != Title)
1295 {
1296 presence.Grouptitle = Title;
1297
1298 if (! presence.IsChildAgent)
1299 presence.SendAvatarDataToAllAgents();
1300 }
1301 }
1302 }
1303 }
1304
1305 /// <summary>
1306 /// Send updates to all clients who might be interested in groups data for dataForClientID
1307 /// </summary>
1308 private void UpdateAllClientsWithGroupInfo(UUID dataForClientID)
1309 {
1310 if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1311
1312 // TODO: Probably isn't nessesary to update every client in every scene.
1313 // Need to examine client updates and do only what's nessesary.
1314 lock (m_sceneList)
1315 {
1316 foreach (Scene scene in m_sceneList)
1317 {
1318 scene.ForEachClient(delegate(IClientAPI client) { SendAgentGroupDataUpdate(client, dataForClientID); });
1319 }
1320 }
1321 }
1322
1323 /// <summary>
1324 /// Update remoteClient with group information about dataForAgentID
1325 /// </summary>
1326 private void SendAgentGroupDataUpdate(IClientAPI remoteClient, UUID dataForAgentID)
1327 {
1328 if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.Name);
1329
1330 // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
1331
1332 OnAgentDataUpdateRequest(remoteClient, dataForAgentID, UUID.Zero);
1333
1334 // Need to send a group membership update to the client
1335 // UDP version doesn't seem to behave nicely. But we're going to send it out here
1336 // with an empty group membership to hopefully remove groups being displayed due
1337 // to the core Groups Stub
1338 //remoteClient.SendGroupMembership(new GroupMembershipData[0]);
1339
1340 GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, dataForAgentID);
1341 SendGroupMembershipInfoViaCaps(remoteClient, dataForAgentID, membershipArray);
1342 //remoteClient.SendAvatarGroupsReply(dataForAgentID, membershipArray);
1343 if (remoteClient.AgentId == dataForAgentID)
1344 remoteClient.RefreshGroupMembership();
1345 }
1346
1347 /// <summary>
1348 /// Get a list of groups memberships for the agent that are marked "ListInProfile"
1349 /// (unless that agent has a godLike aspect, in which case get all groups)
1350 /// </summary>
1351 /// <param name="dataForAgentID"></param>
1352 /// <returns></returns>
1353 private GroupMembershipData[] GetProfileListedGroupMemberships(IClientAPI requestingClient, UUID dataForAgentID)
1354 {
1355 List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId.ToString(), dataForAgentID.ToString());
1356 GroupMembershipData[] membershipArray;
1357
1358 // cScene and property accessor 'isGod' are in support of the opertions to bypass 'hidden' group attributes for
1359 // those with a GodLike aspect.
1360 Scene cScene = (Scene)requestingClient.Scene;
1361 bool isGod = cScene.Permissions.IsGod(requestingClient.AgentId);
1362
1363 if (isGod)
1364 {
1365 membershipArray = membershipData.ToArray();
1366 }
1367 else
1368 {
1369 if (requestingClient.AgentId != dataForAgentID)
1370 {
1371 Predicate<GroupMembershipData> showInProfile = delegate(GroupMembershipData membership)
1372 {
1373 return membership.ListInProfile;
1374 };
1375
1376 membershipArray = membershipData.FindAll(showInProfile).ToArray();
1377 }
1378 else
1379 {
1380 membershipArray = membershipData.ToArray();
1381 }
1382 }
1383
1384 if (m_debugEnabled)
1385 {
1386 m_log.InfoFormat("[Groups]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
1387 foreach (GroupMembershipData membership in membershipArray)
1388 {
1389 m_log.InfoFormat("[Groups]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
1390 }
1391 }
1392
1393 return membershipArray;
1394 }
1395
1396
1397 private void SendAgentDataUpdate(IClientAPI remoteClient, UUID dataForAgentID, UUID activeGroupID, string activeGroupName, ulong activeGroupPowers, string activeGroupTitle)
1398 {
1399 if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1400
1401 // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
1402 UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, dataForAgentID);
1403 string firstname, lastname;
1404 if (account != null)
1405 {
1406 firstname = account.FirstName;
1407 lastname = account.LastName;
1408 }
1409 else
1410 {
1411 firstname = "Unknown";
1412 lastname = "Unknown";
1413 }
1414
1415 remoteClient.SendAgentDataUpdate(dataForAgentID, activeGroupID, firstname,
1416 lastname, activeGroupPowers, activeGroupName,
1417 activeGroupTitle);
1418 }
1419
1420 #endregion
1421
1422 #region IM Backed Processes
1423
1424 private void OutgoingInstantMessage(GridInstantMessage msg, UUID msgTo)
1425 {
1426 if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
1427
1428 IClientAPI localClient = GetActiveClient(msgTo);
1429 if (localClient != null)
1430 {
1431 if (m_debugEnabled) m_log.InfoFormat("[Groups]: MsgTo ({0}) is local, delivering directly", localClient.Name);
1432 localClient.SendInstantMessage(msg);
1433 }
1434 else if (m_msgTransferModule != null)
1435 {
1436 if (m_debugEnabled) m_log.InfoFormat("[Groups]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
1437 m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { if (m_debugEnabled) m_log.DebugFormat("[Groups]: Message Sent: {0}", success?"Succeeded":"Failed"); });
1438 }
1439 }
1440
1441 public void NotifyChange(UUID groupID)
1442 {
1443 // Notify all group members of a chnge in group roles and/or
1444 // permissions
1445 //
1446 }
1447
1448 #endregion
1449
1450 private string GetRequestingAgentIDStr(IClientAPI client)
1451 {
1452 return GetRequestingAgentID(client).ToString();
1453 }
1454
1455 private UUID GetRequestingAgentID(IClientAPI client)
1456 {
1457 UUID requestingAgentID = UUID.Zero;
1458 if (client != null)
1459 {
1460 requestingAgentID = client.AgentId;
1461 }
1462 return requestingAgentID;
1463 }
1464
1465 }
1466
1467}