From ac60382599d8a2bfcf431c0eeafd65eebf865e21 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Wed, 20 Feb 2008 09:45:26 +0000 Subject: [PATCH] * Added a few more packets to ClientView. Added tendons to the Skeletal Groups Module, made it shared to save on threads. --- OpenSim/Framework/IClientAPI.cs | 6 + OpenSim/Region/ClientStack/ClientView.cs | 81 ++++++- .../Environment/Modules/GroupsModule.cs | 223 +++++++++++++++++- .../Examples/SimpleApp/MyNpcCharacter.cs | 8 + 4 files changed, 303 insertions(+), 15 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index bdddc33b7e..0563f6b7ac 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -451,6 +451,10 @@ namespace OpenSim.Framework event Action OnRequestAvatarsData; event AddNewPrim OnAddPrim; + event FetchInventory OnAgentDataUpdateRequest; + event FetchInventory OnUserInfoRequest; + event TeleportLocationRequest OnSetStartLocationRequest; + event RequestGodlikePowers OnRequestGodlikePowers; event GodKickUser OnGodKickUser; @@ -620,6 +624,8 @@ namespace OpenSim.Framework void SendXferPacket(ulong xferID, uint packet, byte[] data); void SendAvatarPickerReply(AvatarPickerReplyPacket Pack); + void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle); + void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID); void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags); void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain); diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index ff1bac45d7..47cb582113 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -561,6 +561,11 @@ namespace OpenSim.Region.ClientStack public event RequestAvatarProperties OnRequestAvatarProperties; public event SetAlwaysRun OnSetAlwaysRun; + public event FetchInventory OnAgentDataUpdateRequest; + public event FetchInventory OnUserInfoRequest; + public event TeleportLocationRequest OnSetStartLocationRequest; + + public event CreateNewInventoryItem OnCreateNewInventoryItem; public event CreateInventoryFolder OnCreateNewInventoryFolder; public event UpdateInventoryFolder OnUpdateInventoryFolder; @@ -1301,6 +1306,19 @@ namespace OpenSim.Region.ClientStack OutPacket(replyPacket, ThrottleOutPacketType.Task); } + public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname,string grouptitle) + { + AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate); + sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid; + sendAgentDataUpdate.AgentData.AgentID = agentid; + sendAgentDataUpdate.AgentData.FirstName = Helpers.StringToField(firstname); + sendAgentDataUpdate.AgentData.GroupName = Helpers.StringToField(groupname); + sendAgentDataUpdate.AgentData.GroupPowers = grouppowers; + sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle); + sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname); + OutPacket(sendAgentDataUpdate,ThrottleOutPacketType.Task); + } + /// /// /// @@ -2795,6 +2813,7 @@ namespace OpenSim.Region.ClientStack //rezPacket.RezData.RezSelected; //rezPacket.RezData.FromTaskID; //m_log.Info("[REZData]: " + rezPacket.ToString()); + OnRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd, rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID, rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection, @@ -2949,6 +2968,41 @@ namespace OpenSim.Region.ClientStack Helpers.FieldToUTF8String(querydata.Name)); } break; + case PacketType.AgentDataUpdateRequest: + AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack; + + if (OnAgentDataUpdateRequest != null) + { + OnAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID); + } + + break; + case PacketType.UserInfoRequest: + UserInfoRequestPacket avUserInfoRequestPacket = (UserInfoRequestPacket)Pack; + if (OnUserInfoRequest != null) + { + OnUserInfoRequest(this,avUserInfoRequestPacket.AgentData.AgentID,avUserInfoRequestPacket.AgentData.SessionID); + + } + break; + + case PacketType.SetStartLocationRequest: + SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack; + if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId) + { + if (OnSetStartLocationRequest != null) + { + OnSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos, + avSetStartLocationRequestPacket.StartLocationData.LocationLookAt, + avSetStartLocationRequestPacket.StartLocationData.LocationID); + } + } + break; + + case PacketType.AgentThrottle: + AgentThrottlePacket atpack = (AgentThrottlePacket)Pack; + m_packetQueue.SetThrottleFromClient(atpack.Throttle.Throttles); + break; #endregion @@ -3654,14 +3708,11 @@ namespace OpenSim.Region.ClientStack OnEstateCovenantRequest(this, epack.SessionID); } break; - case PacketType.AgentThrottle: - AgentThrottlePacket atpack = (AgentThrottlePacket)Pack; - m_packetQueue.SetThrottleFromClient(atpack.Throttle.Throttles); - break; + #endregion - #region unimplemented handlers + #region GodPackets case PacketType.RequestGodlikePowers: RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack; @@ -3699,6 +3750,12 @@ namespace OpenSim.Region.ClientStack //OutPacket(kupack, ThrottleOutPacketType.Task); break; + + #endregion + + #region unimplemented handlers + + case PacketType.StartPingCheck: // Send the client the ping response back // Pass the same PingID in the matching packet @@ -3746,17 +3803,17 @@ namespace OpenSim.Region.ClientStack // TODO: handle this packet m_log.Warn("[CLIENT]: unhandled MuteListRequest packet"); break; - case PacketType.AgentDataUpdateRequest: + //case PacketType.AgentDataUpdateRequest: // TODO: handle this packet - m_log.Warn("[CLIENT]: unhandled AgentDataUpdateRequest packet"); - break; + //m_log.Warn("[CLIENT]: unhandled AgentDataUpdateRequest packet"); + //break; case PacketType.ParcelDwellRequest: // TODO: handle this packet m_log.Warn("[CLIENT]: unhandled ParcelDwellRequest packet"); break; case PacketType.UseCircuitCode: - // TODO: handle this packet + // TODO: Don't display this one, we handle it at a lower level //m_log.Warn("[CLIENT]: unhandled UseCircuitCode packet"); break; case PacketType.EconomyDataRequest: @@ -3775,10 +3832,10 @@ namespace OpenSim.Region.ClientStack // TODO: handle this packet m_log.Warn("[CLIENT]: unhandled SoundTrigger packet"); break; - case PacketType.UserInfoRequest: + //case PacketType.UserInfoRequest: // TODO: handle this packet - m_log.Warn("[CLIENT]: unhandled UserInfoRequest packet"); - break; + //m_log.Warn("[CLIENT]: unhandled UserInfoRequest packet"); + //break; case PacketType.InventoryDescendents: // TODO: handle this packet m_log.Warn("[CLIENT]: unhandled InventoryDescent packet"); diff --git a/OpenSim/Region/Environment/Modules/GroupsModule.cs b/OpenSim/Region/Environment/Modules/GroupsModule.cs index 50e9a39aef..6eb3cdac44 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 diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 0258c61c2a..089dee71f0 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -89,6 +89,9 @@ namespace SimpleApp public event MoveObject OnGrabUpdate; public event ViewerEffectEventHandler OnViewerEffect; + public event FetchInventory OnAgentDataUpdateRequest; + public event FetchInventory OnUserInfoRequest; + public event TeleportLocationRequest OnSetStartLocationRequest; public event UpdateShape OnUpdatePrimShape; public event ObjectExtraParams OnUpdateExtraParams; @@ -226,6 +229,11 @@ namespace SimpleApp { } + public virtual void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle) + { + + } + public virtual void SendKillObject(ulong regionHandle, uint localID) { }