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