diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs | 254 |
1 files changed, 254 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs new file mode 100644 index 0000000..1f099c6 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs | |||
@@ -0,0 +1,254 @@ | |||
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; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using Nwc.XmlRpc; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Communications; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Server.Base; | ||
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using Mono.Addins; | ||
45 | |||
46 | namespace OpenSim.Region.CoreModules.World.Estate | ||
47 | { | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XEstate")] | ||
49 | public class XEstateModule : ISharedRegionModule | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | protected List<Scene> m_Scenes = new List<Scene>(); | ||
54 | protected bool m_InInfoUpdate = false; | ||
55 | |||
56 | public bool InInfoUpdate | ||
57 | { | ||
58 | get { return m_InInfoUpdate; } | ||
59 | set { m_InInfoUpdate = value; } | ||
60 | } | ||
61 | |||
62 | public List<Scene> Scenes | ||
63 | { | ||
64 | get { return m_Scenes; } | ||
65 | } | ||
66 | |||
67 | protected EstateConnector m_EstateConnector; | ||
68 | |||
69 | public void Initialise(IConfigSource config) | ||
70 | { | ||
71 | int port = 0; | ||
72 | |||
73 | IConfig estateConfig = config.Configs["Estate"]; | ||
74 | if (estateConfig != null) | ||
75 | { | ||
76 | port = estateConfig.GetInt("Port", 0); | ||
77 | } | ||
78 | |||
79 | m_EstateConnector = new EstateConnector(this); | ||
80 | |||
81 | // Instantiate the request handler | ||
82 | IHttpServer server = MainServer.GetHttpServer((uint)port); | ||
83 | server.AddStreamHandler(new EstateRequestHandler(this)); | ||
84 | } | ||
85 | |||
86 | public void PostInitialise() | ||
87 | { | ||
88 | } | ||
89 | |||
90 | public void Close() | ||
91 | { | ||
92 | } | ||
93 | |||
94 | public void AddRegion(Scene scene) | ||
95 | { | ||
96 | m_Scenes.Add(scene); | ||
97 | |||
98 | scene.EventManager.OnNewClient += OnNewClient; | ||
99 | } | ||
100 | |||
101 | public void RegionLoaded(Scene scene) | ||
102 | { | ||
103 | IEstateModule em = scene.RequestModuleInterface<IEstateModule>(); | ||
104 | |||
105 | em.OnRegionInfoChange += OnRegionInfoChange; | ||
106 | em.OnEstateInfoChange += OnEstateInfoChange; | ||
107 | em.OnEstateMessage += OnEstateMessage; | ||
108 | } | ||
109 | |||
110 | public void RemoveRegion(Scene scene) | ||
111 | { | ||
112 | scene.EventManager.OnNewClient -= OnNewClient; | ||
113 | |||
114 | m_Scenes.Remove(scene); | ||
115 | } | ||
116 | |||
117 | public string Name | ||
118 | { | ||
119 | get { return "EstateModule"; } | ||
120 | } | ||
121 | |||
122 | public Type ReplaceableInterface | ||
123 | { | ||
124 | get { return null; } | ||
125 | } | ||
126 | |||
127 | private Scene FindScene(UUID RegionID) | ||
128 | { | ||
129 | foreach (Scene s in Scenes) | ||
130 | { | ||
131 | if (s.RegionInfo.RegionID == RegionID) | ||
132 | return s; | ||
133 | } | ||
134 | |||
135 | return null; | ||
136 | } | ||
137 | |||
138 | private void OnRegionInfoChange(UUID RegionID) | ||
139 | { | ||
140 | Scene s = FindScene(RegionID); | ||
141 | if (s == null) | ||
142 | return; | ||
143 | |||
144 | if (!m_InInfoUpdate) | ||
145 | m_EstateConnector.SendUpdateCovenant(s.RegionInfo.EstateSettings.EstateID, s.RegionInfo.RegionSettings.Covenant); | ||
146 | } | ||
147 | |||
148 | private void OnEstateInfoChange(UUID RegionID) | ||
149 | { | ||
150 | Scene s = FindScene(RegionID); | ||
151 | if (s == null) | ||
152 | return; | ||
153 | |||
154 | if (!m_InInfoUpdate) | ||
155 | m_EstateConnector.SendUpdateEstate(s.RegionInfo.EstateSettings.EstateID); | ||
156 | } | ||
157 | |||
158 | private void OnEstateMessage(UUID RegionID, UUID FromID, string FromName, string Message) | ||
159 | { | ||
160 | Scene senderScenes = FindScene(RegionID); | ||
161 | if (senderScenes == null) | ||
162 | return; | ||
163 | |||
164 | uint estateID = senderScenes.RegionInfo.EstateSettings.EstateID; | ||
165 | |||
166 | foreach (Scene s in Scenes) | ||
167 | { | ||
168 | if (s.RegionInfo.EstateSettings.EstateID == estateID) | ||
169 | { | ||
170 | IDialogModule dm = s.RequestModuleInterface<IDialogModule>(); | ||
171 | |||
172 | if (dm != null) | ||
173 | { | ||
174 | dm.SendNotificationToUsersInRegion(FromID, FromName, | ||
175 | Message); | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | if (!m_InInfoUpdate) | ||
180 | m_EstateConnector.SendEstateMessage(estateID, FromID, FromName, Message); | ||
181 | } | ||
182 | |||
183 | private void OnNewClient(IClientAPI client) | ||
184 | { | ||
185 | client.OnEstateTeleportOneUserHomeRequest += OnEstateTeleportOneUserHomeRequest; | ||
186 | client.OnEstateTeleportAllUsersHomeRequest += OnEstateTeleportAllUsersHomeRequest; | ||
187 | |||
188 | } | ||
189 | |||
190 | private void OnEstateTeleportOneUserHomeRequest(IClientAPI client, UUID invoice, UUID senderID, UUID prey) | ||
191 | { | ||
192 | if (prey == UUID.Zero) | ||
193 | return; | ||
194 | |||
195 | if (!(client.Scene is Scene)) | ||
196 | return; | ||
197 | |||
198 | Scene scene = (Scene)client.Scene; | ||
199 | |||
200 | uint estateID = scene.RegionInfo.EstateSettings.EstateID; | ||
201 | |||
202 | if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false)) | ||
203 | return; | ||
204 | |||
205 | foreach (Scene s in Scenes) | ||
206 | { | ||
207 | if (s == scene) | ||
208 | continue; // Already handles by estate module | ||
209 | if (s.RegionInfo.EstateSettings.EstateID != estateID) | ||
210 | continue; | ||
211 | |||
212 | ScenePresence p = scene.GetScenePresence(prey); | ||
213 | if (p != null && !p.IsChildAgent) | ||
214 | { | ||
215 | p.ControllingClient.SendTeleportStart(16); | ||
216 | scene.TeleportClientHome(prey, p.ControllingClient); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | m_EstateConnector.SendTeleportHomeOneUser(estateID, prey); | ||
221 | } | ||
222 | |||
223 | private void OnEstateTeleportAllUsersHomeRequest(IClientAPI client, UUID invoice, UUID senderID) | ||
224 | { | ||
225 | if (!(client.Scene is Scene)) | ||
226 | return; | ||
227 | |||
228 | Scene scene = (Scene)client.Scene; | ||
229 | |||
230 | uint estateID = scene.RegionInfo.EstateSettings.EstateID; | ||
231 | |||
232 | if (!scene.Permissions.CanIssueEstateCommand(client.AgentId, false)) | ||
233 | return; | ||
234 | |||
235 | foreach (Scene s in Scenes) | ||
236 | { | ||
237 | if (s == scene) | ||
238 | continue; // Already handles by estate module | ||
239 | if (s.RegionInfo.EstateSettings.EstateID != estateID) | ||
240 | continue; | ||
241 | |||
242 | scene.ForEachScenePresence(delegate(ScenePresence p) { | ||
243 | if (p != null && !p.IsChildAgent) | ||
244 | { | ||
245 | p.ControllingClient.SendTeleportStart(16); | ||
246 | scene.TeleportClientHome(p.ControllingClient.AgentId, p.ControllingClient); | ||
247 | } | ||
248 | }); | ||
249 | } | ||
250 | |||
251 | m_EstateConnector.SendTeleportHomeAllUsers(estateID); | ||
252 | } | ||
253 | } | ||
254 | } | ||