From 968b7310f4e8cc1d582ee0b734d60052dcf0324b Mon Sep 17 00:00:00 2001 From: "Teravus Ovares (Dan Olivares)" Date: Sun, 22 Nov 2009 03:48:56 -0500 Subject: [PATCH] * Moved 13 more packet type handlers to PacketHandler Delegates.. and out of of that giant 5000 line switch, ProcessInPacket. --- .../ClientStack/LindenUDP/LLClientView.cs | 379 +++++++++++++++++- 1 file changed, 373 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index d1781873cf..5cf59d8d88 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4300,6 +4300,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP AddLocalPacketHandler(PacketType.AvatarPropertiesRequest, HandleAvatarPropertiesRequest); AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); AddLocalPacketHandler(PacketType.AvatarPropertiesUpdate, HandlerAvatarPropertiesUpdate); + AddLocalPacketHandler(PacketType.ScriptDialogReply, HandlerScriptDialogReply); + AddLocalPacketHandler(PacketType.ImprovedInstantMessage, HandlerImprovedInstantMessage); + AddLocalPacketHandler(PacketType.AcceptFriendship, HandlerAcceptFriendship); + AddLocalPacketHandler(PacketType.DeclineFriendship, HandlerDeclineFriendship); + AddLocalPacketHandler(PacketType.TerminateFriendship, HandlerTerminateFrendship); + AddLocalPacketHandler(PacketType.RezObject, HandlerRezObject); + AddLocalPacketHandler(PacketType.DeRezObject, HandlerDeRezObject); + AddLocalPacketHandler(PacketType.ModifyLand, HandlerModifyLand); + AddLocalPacketHandler(PacketType.RegionHandshakeReply, HandlerRegionHandshakeReply); + AddLocalPacketHandler(PacketType.AgentWearablesRequest, HandlerAgentWearablesRequest); + AddLocalPacketHandler(PacketType.AgentSetAppearance, HandlerAgentSetAppearance); + AddLocalPacketHandler(PacketType.AgentIsNowWearing, HandlerAgentIsNowWearing); + //AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); + //AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); + //AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); //AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); //AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer); } @@ -4609,6 +4624,356 @@ namespace OpenSim.Region.ClientStack.LindenUDP return true; } + private bool HandlerScriptDialogReply(IClientAPI sender, Packet Pack) + { + ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (rdialog.AgentData.SessionID != SessionId || + rdialog.AgentData.AgentID != AgentId) + return true; + } + #endregion + + int ch = rdialog.Data.ChatChannel; + byte[] msg = rdialog.Data.ButtonLabel; + if (OnChatFromClient != null) + { + OSChatMessage args = new OSChatMessage(); + args.Channel = ch; + args.From = String.Empty; + args.Message = Utils.BytesToString(msg); + args.Type = ChatTypeEnum.Shout; + args.Position = new Vector3(); + args.Scene = Scene; + args.Sender = this; + ChatMessage handlerChatFromClient2 = OnChatFromClient; + if (handlerChatFromClient2 != null) + handlerChatFromClient2(this, args); + } + + return true; + } + + private bool HandlerImprovedInstantMessage(IClientAPI sender, Packet Pack) + { + ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (msgpack.AgentData.SessionID != SessionId || + msgpack.AgentData.AgentID != AgentId) + return true; + } + #endregion + + string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName); + string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message); + ImprovedInstantMessage handlerInstantMessage = OnInstantMessage; + + if (handlerInstantMessage != null) + { + GridInstantMessage im = new GridInstantMessage(Scene, + msgpack.AgentData.AgentID, + IMfromName, + msgpack.MessageBlock.ToAgentID, + msgpack.MessageBlock.Dialog, + msgpack.MessageBlock.FromGroup, + IMmessage, + msgpack.MessageBlock.ID, + msgpack.MessageBlock.Offline != 0 ? true : false, + msgpack.MessageBlock.Position, + msgpack.MessageBlock.BinaryBucket); + + handlerInstantMessage(this, im); + } + return true; + + } + + private bool HandlerAcceptFriendship(IClientAPI sender, Packet Pack) + { + AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (afriendpack.AgentData.SessionID != SessionId || + afriendpack.AgentData.AgentID != AgentId) + return true; + } + #endregion + + // My guess is this is the folder to stick the calling card into + List callingCardFolders = new List(); + + UUID agentID = afriendpack.AgentData.AgentID; + UUID transactionID = afriendpack.TransactionBlock.TransactionID; + + for (int fi = 0; fi < afriendpack.FolderData.Length; fi++) + { + callingCardFolders.Add(afriendpack.FolderData[fi].FolderID); + } + + FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest; + if (handlerApproveFriendRequest != null) + { + handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders); + } + return true; + + } + + private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack) + { + DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (dfriendpack.AgentData.SessionID != SessionId || + dfriendpack.AgentData.AgentID != AgentId) + return true; + } + #endregion + + if (OnDenyFriendRequest != null) + { + OnDenyFriendRequest(this, + dfriendpack.AgentData.AgentID, + dfriendpack.TransactionBlock.TransactionID, + null); + } + return true; + } + + private bool HandlerTerminateFrendship(IClientAPI sender, Packet Pack) + { + TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (tfriendpack.AgentData.SessionID != SessionId || + tfriendpack.AgentData.AgentID != AgentId) + return true; + } + #endregion + + UUID listOwnerAgentID = tfriendpack.AgentData.AgentID; + UUID exFriendID = tfriendpack.ExBlock.OtherID; + + FriendshipTermination handlerTerminateFriendship = OnTerminateFriendship; + if (handlerTerminateFriendship != null) + { + handlerTerminateFriendship(this, listOwnerAgentID, exFriendID); + } + return true; + } + + private bool HandlerRezObject(IClientAPI sender, Packet Pack) + { + RezObjectPacket rezPacket = (RezObjectPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (rezPacket.AgentData.SessionID != SessionId || + rezPacket.AgentData.AgentID != AgentId) + return true; + } + #endregion + + RezObject handlerRezObject = OnRezObject; + if (handlerRezObject != null) + { + handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd, + rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID, + rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection, + rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem, + rezPacket.RezData.FromTaskID); + } + return true; + } + + private bool HandlerDeRezObject(IClientAPI sender, Packet Pack) + { + DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (DeRezPacket.AgentData.SessionID != SessionId || + DeRezPacket.AgentData.AgentID != AgentId) + return true; + } + #endregion + + DeRezObject handlerDeRezObject = OnDeRezObject; + if (handlerDeRezObject != null) + { + List deRezIDs = new List(); + + foreach (DeRezObjectPacket.ObjectDataBlock data in + DeRezPacket.ObjectData) + { + deRezIDs.Add(data.ObjectLocalID); + } + // It just so happens that the values on the DeRezAction enumerator match the Destination + // values given by a Second Life client + handlerDeRezObject(this, deRezIDs, + DeRezPacket.AgentBlock.GroupID, + (DeRezAction)DeRezPacket.AgentBlock.Destination, + DeRezPacket.AgentBlock.DestinationID); + + } + return true; + } + + private bool HandlerModifyLand(IClientAPI sender, Packet Pack) + { + ModifyLandPacket modify = (ModifyLandPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (modify.AgentData.SessionID != SessionId || + modify.AgentData.AgentID != AgentId) + return true; + } + + #endregion + //m_log.Info("[LAND]: LAND:" + modify.ToString()); + if (modify.ParcelData.Length > 0) + { + if (OnModifyTerrain != null) + { + for (int i = 0; i < modify.ParcelData.Length; i++) + { + ModifyTerrain handlerModifyTerrain = OnModifyTerrain; + if (handlerModifyTerrain != null) + { + handlerModifyTerrain(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds, + modify.ModifyBlock.BrushSize, + modify.ModifyBlock.Action, modify.ParcelData[i].North, + modify.ParcelData[i].West, modify.ParcelData[i].South, + modify.ParcelData[i].East, AgentId); + } + } + } + } + + return true; + } + + private bool HandlerRegionHandshakeReply(IClientAPI sender, Packet Pack) + { + Action handlerRegionHandShakeReply = OnRegionHandShakeReply; + if (handlerRegionHandShakeReply != null) + { + handlerRegionHandShakeReply(this); + } + + return true; + } + + private bool HandlerAgentWearablesRequest(IClientAPI sender, Packet Pack) + { + GenericCall2 handlerRequestWearables = OnRequestWearables; + + if (handlerRequestWearables != null) + { + handlerRequestWearables(); + } + + Action handlerRequestAvatarsData = OnRequestAvatarsData; + + if (handlerRequestAvatarsData != null) + { + handlerRequestAvatarsData(this); + } + + return true; + } + + private bool HandlerAgentSetAppearance(IClientAPI sender, Packet Pack) + { + AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (appear.AgentData.SessionID != SessionId || + appear.AgentData.AgentID != AgentId) + return true; + } + #endregion + + SetAppearance handlerSetAppearance = OnSetAppearance; + if (handlerSetAppearance != null) + { + // Temporarily protect ourselves from the mantis #951 failure. + // However, we could do this for several other handlers where a failure isn't terminal + // for the client session anyway, in order to protect ourselves against bad code in plugins + try + { + byte[] visualparams = new byte[appear.VisualParam.Length]; + for (int i = 0; i < appear.VisualParam.Length; i++) + visualparams[i] = appear.VisualParam[i].ParamValue; + + Primitive.TextureEntry te = null; + if (appear.ObjectData.TextureEntry.Length > 1) + te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); + + handlerSetAppearance(te, visualparams); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}", + e); + } + } + + return true; + } + + private bool HandlerAgentIsNowWearing(IClientAPI sender, Packet Pack) + { + if (OnAvatarNowWearing != null) + { + AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack; + + #region Packet Session and User Check + if (m_checkPackets) + { + if (nowWearing.AgentData.SessionID != SessionId || + nowWearing.AgentData.AgentID != AgentId) + return true; + } + #endregion + + AvatarWearingArgs wearingArgs = new AvatarWearingArgs(); + for (int i = 0; i < nowWearing.WearableData.Length; i++) + { + AvatarWearingArgs.Wearable wearable = + new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID, + nowWearing.WearableData[i].WearableType); + wearingArgs.NowWearing.Add(wearable); + } + + AvatarNowWearing handlerAvatarNowWearing = OnAvatarNowWearing; + if (handlerAvatarNowWearing != null) + { + handlerAvatarNowWearing(this, wearingArgs); + } + } + return true; + } + #endregion Packet Handlers public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question) @@ -5106,6 +5471,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP switch (Pack.Type) { #region Scene/Avatar + #region CommentedOut /* case PacketType.AvatarPropertiesRequest: AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; @@ -5193,7 +5559,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP handlerUpdateAvatarProperties(this, UserProfile); } break; - */ + case PacketType.ScriptDialogReply: ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack; @@ -5224,7 +5590,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } break; - + case PacketType.ImprovedInstantMessage: ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack; @@ -5258,7 +5624,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP handlerInstantMessage(this, im); } break; - + case PacketType.AcceptFriendship: AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack; @@ -5331,7 +5697,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP handlerTerminateFriendship(this, listOwnerAgentID, exFriendID); } break; - + case PacketType.RezObject: RezObjectPacket rezPacket = (RezObjectPacket)Pack; @@ -5386,7 +5752,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } break; - + case PacketType.ModifyLand: ModifyLandPacket modify = (ModifyLandPacket)Pack; @@ -5518,7 +5884,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } break; - +*/ + #endregion case PacketType.RezSingleAttachmentFromInv: RezSingleAttachmentFromInv handlerRezSingleAttachment = OnRezSingleAttachmentFromInv; if (handlerRezSingleAttachment != null)