diff options
author | Justin Clark-Casey (justincc) | 2010-03-05 23:18:47 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-03-05 23:18:47 +0000 |
commit | 60553e62a3f576b8bf6ab88a83b2d4550bd69d2b (patch) | |
tree | 3e24624d846502dda17fdac827f070273fafba26 /OpenSim/Region/CoreModules | |
parent | automatically delete %temp% directory after running tests (diff) | |
download | opensim-SC_OLD-60553e62a3f576b8bf6ab88a83b2d4550bd69d2b.zip opensim-SC_OLD-60553e62a3f576b8bf6ab88a83b2d4550bd69d2b.tar.gz opensim-SC_OLD-60553e62a3f576b8bf6ab88a83b2d4550bd69d2b.tar.bz2 opensim-SC_OLD-60553e62a3f576b8bf6ab88a83b2d4550bd69d2b.tar.xz |
refactor: begin to move attachments code into a region module
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs new file mode 100644 index 0000000..103a813 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -0,0 +1,141 @@ | |||
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 | |||
28 | using System.Reflection; | ||
29 | using log4net; | ||
30 | using Nini.Config; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | |||
37 | namespace OpenSim.Region.CoreModules.Avatar.Attachments | ||
38 | { | ||
39 | public class AttachmentsModule : IAttachmentsModule, IRegionModule | ||
40 | { | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | protected Scene m_scene = null; | ||
44 | |||
45 | public void Initialise(Scene scene, IConfigSource source) | ||
46 | { | ||
47 | scene.RegisterModuleInterface<IAttachmentsModule>(this); | ||
48 | m_scene = scene; | ||
49 | } | ||
50 | |||
51 | public void PostInitialise() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public void Close() | ||
56 | { | ||
57 | } | ||
58 | |||
59 | public string Name | ||
60 | { | ||
61 | get { return "Attachments Module"; } | ||
62 | } | ||
63 | |||
64 | public bool IsSharedModule | ||
65 | { | ||
66 | get { return false; } | ||
67 | } | ||
68 | |||
69 | public bool AttachObject( | ||
70 | IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent) | ||
71 | { | ||
72 | SceneObjectGroup group = m_scene.GetGroupByPrim(objectLocalID); | ||
73 | if (group != null) | ||
74 | { | ||
75 | if (m_scene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId)) | ||
76 | { | ||
77 | // If the attachment point isn't the same as the one previously used | ||
78 | // set it's offset position = 0 so that it appears on the attachment point | ||
79 | // and not in a weird location somewhere unknown. | ||
80 | if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint()) | ||
81 | { | ||
82 | attachPos = Vector3.Zero; | ||
83 | } | ||
84 | |||
85 | // AttachmentPt 0 means the client chose to 'wear' the attachment. | ||
86 | if (AttachmentPt == 0) | ||
87 | { | ||
88 | // Check object for stored attachment point | ||
89 | AttachmentPt = (uint)group.GetAttachmentPoint(); | ||
90 | } | ||
91 | |||
92 | // if we still didn't find a suitable attachment point....... | ||
93 | if (AttachmentPt == 0) | ||
94 | { | ||
95 | // Stick it on left hand with Zero Offset from the attachment point. | ||
96 | AttachmentPt = (uint)AttachmentPoint.LeftHand; | ||
97 | attachPos = Vector3.Zero; | ||
98 | } | ||
99 | |||
100 | group.SetAttachmentPoint((byte)AttachmentPt); | ||
101 | group.AbsolutePosition = attachPos; | ||
102 | |||
103 | // Saves and gets itemID | ||
104 | UUID itemId; | ||
105 | |||
106 | if (group.GetFromItemID() == UUID.Zero) | ||
107 | { | ||
108 | m_scene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId); | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | itemId = group.GetFromItemID(); | ||
113 | } | ||
114 | |||
115 | m_scene.AttachObject(remoteClient, AttachmentPt, itemId, group); | ||
116 | |||
117 | group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos, silent); | ||
118 | |||
119 | // In case it is later dropped again, don't let | ||
120 | // it get cleaned up | ||
121 | group.RootPart.RemFlag(PrimFlags.TemporaryOnRez); | ||
122 | group.HasGroupChanged = false; | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | remoteClient.SendAgentAlertMessage( | ||
127 | "You don't have sufficient permissions to attach this object", false); | ||
128 | |||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID); | ||
135 | return false; | ||
136 | } | ||
137 | |||
138 | return true; | ||
139 | } | ||
140 | } | ||
141 | } \ No newline at end of file | ||