From ac60382599d8a2bfcf431c0eeafd65eebf865e21 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Wed, 20 Feb 2008 09:45:26 +0000 Subject: * Added a few more packets to ClientView. Added tendons to the Skeletal Groups Module, made it shared to save on threads. --- OpenSim/Region/Environment/Modules/GroupsModule.cs | 223 ++++++++++++++++++++- 1 file changed, 220 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/GroupsModule.cs b/OpenSim/Region/Environment/Modules/GroupsModule.cs index 50e9a39..6eb3cda 100644 --- a/OpenSim/Region/Environment/Modules/GroupsModule.cs +++ b/OpenSim/Region/Environment/Modules/GroupsModule.cs @@ -27,18 +27,182 @@ */ using Nini.Config; +using System; +using System.Collections; +using System.Collections.Generic; +using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; +using libsecondlife; namespace OpenSim.Region.Environment.Modules { public class GroupsModule : IRegionModule { - private Scene m_scene; + private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + private List m_scene = new List(); + private Dictionary m_iclientmap = new Dictionary(); + private Dictionary m_groupmap = new Dictionary(); + private Dictionary m_grouplistmap = new Dictionary(); public void Initialise(Scene scene, IConfigSource config) { - m_scene = scene; + lock (m_scene) + { + m_scene.Add(scene); + } + scene.EventManager.OnNewClient += OnNewClient; + scene.EventManager.OnClientClosed += OnClientClosed; + scene.EventManager.OnGridInstantMessageToGroupsModule += OnGridInstantMessage; + //scene.EventManager. + } + private void OnNewClient(IClientAPI client) + { + // All friends establishment protocol goes over instant message + // There's no way to send a message from the sim + // to a user to 'add a friend' without causing dialog box spam + // + // The base set of friends are added when the user signs on in their XMLRPC response + // Generated by LoginService. The friends are retreived from the database by the UserManager + + // Subscribe to instant messages + client.OnInstantMessage += OnInstantMessage; + client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest; + lock (m_iclientmap) + { + if (!m_iclientmap.ContainsKey(client.AgentId)) + { + m_iclientmap.Add(client.AgentId, client); + } + } + GroupData OpenSimulatorGroup = new GroupData(); + OpenSimulatorGroup.ActiveGroupTitle = "OpenSimulator Tester"; + OpenSimulatorGroup.GroupID = new LLUUID("00000000-68f9-1111-024e-222222111120"); + OpenSimulatorGroup.GroupMembers.Add(client.AgentId); + OpenSimulatorGroup.groupName = "OpenSimulator Testing"; + OpenSimulatorGroup.ActiveGroupPowers = GroupPowers.LandAllowSetHome; + OpenSimulatorGroup.GroupTitles.Add("OpenSimulator Tester"); + lock (m_groupmap) + { + if (!m_groupmap.ContainsKey(client.AgentId)) + { + m_groupmap.Add(client.AgentId, OpenSimulatorGroup); + } + } + GroupList testGroupList = new GroupList(); + testGroupList.m_GroupList.Add(new LLUUID("00000000-68f9-1111-024e-222222111120")); + + lock (m_grouplistmap) + { + if (!m_grouplistmap.ContainsKey(client.AgentId)) + { + m_grouplistmap.Add(client.AgentId, testGroupList); + } + } + m_log.Info("[GROUP]: Adding " + client.FirstName + " " + client.LastName + " to OpenSimulator Tester group"); + + + } + + private void OnAgentDataUpdateRequest(IClientAPI remoteClient, LLUUID AgentID, LLUUID SessionID) + { + string firstname = remoteClient.FirstName; + string lastname = remoteClient.LastName; + + LLUUID ActiveGroupID = LLUUID.Zero; + uint ActiveGroupPowers = 0; + string ActiveGroupName = ""; + string ActiveGroupTitle = ""; + + bool foundUser = false; + + lock (m_iclientmap) + { + if (m_iclientmap.ContainsKey(remoteClient.AgentId)) + { + foundUser = true; + } + } + if (foundUser) + { + lock (m_groupmap) + { + if (m_groupmap.ContainsKey(remoteClient.AgentId)) + { + GroupData grp = m_groupmap[remoteClient.AgentId]; + if (grp != null) + { + ActiveGroupID = grp.GroupID; + ActiveGroupName = grp.groupName; + ActiveGroupPowers = grp.groupPowers; + ActiveGroupTitle = grp.ActiveGroupTitle; + } + + //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle); + + } + } + } + + } + + private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, + LLUUID fromAgentSession, LLUUID toAgentID, + LLUUID imSessionID, uint timestamp, string fromAgentName, + string message, byte dialog, bool fromGroup, byte offline, + uint ParentEstateID, LLVector3 Position, LLUUID RegionID, + byte[] binaryBucket) + { + + } + + private void OnGridInstantMessage(GridInstantMessage msg) + { + // Trigger the above event handler + OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), + new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, + msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, + new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), + msg.binaryBucket); + } + + private void OnClientClosed(LLUUID agentID) + { + lock (m_iclientmap) + { + if (m_iclientmap.ContainsKey(agentID)) + { + IClientAPI cli = m_iclientmap[agentID]; + if (cli != null) + { + m_log.Info("[GROUP]: Removing all reference to groups for " + cli.FirstName + " " + cli.LastName); + } + else + { + m_log.Info("[GROUP]: Removing all reference to groups for " + agentID.ToString()); + } + m_iclientmap.Remove(agentID); + } + } + + lock (m_groupmap) + { + if (m_groupmap.ContainsKey(agentID)) + { + m_groupmap.Remove(agentID); + } + } + + lock (m_grouplistmap) + { + if (m_grouplistmap.ContainsKey(agentID)) + { + m_grouplistmap.Remove(agentID); + } + } + GC.Collect(); } public void PostInitialise() @@ -47,6 +211,22 @@ namespace OpenSim.Region.Environment.Modules public void Close() { + m_log.Info("[GROUP]: Shutting down group module."); + lock (m_iclientmap) + { + m_iclientmap.Clear(); + } + + lock (m_groupmap) + { + m_groupmap.Clear(); + } + + lock (m_grouplistmap) + { + m_grouplistmap.Clear(); + } + GC.Collect(); } public string Name @@ -56,7 +236,44 @@ namespace OpenSim.Region.Environment.Modules public bool IsSharedModule { - get { return false; } + get { return true; } + } + + } + public class GroupData + { + public LLUUID GroupID; + public string groupName; + public string ActiveGroupTitle; + public List GroupTitles; + public List GroupMembers; + public uint groupPowers = (uint)(GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome); + + public GroupPowers ActiveGroupPowers + { + set + { + groupPowers = (uint) value; + } + get + { + return (GroupPowers)groupPowers; + } + } + + public GroupData() + { + GroupTitles = new List(); + GroupMembers = new List(); + } + + } + public class GroupList + { + public List m_GroupList; + public GroupList() + { + m_GroupList = new List(); } } } \ No newline at end of file -- cgit v1.1