diff options
Diffstat (limited to 'OpenSim/Region')
3 files changed, 767 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs new file mode 100644 index 0000000..948c893 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs | |||
@@ -0,0 +1,215 @@ | |||
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.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using OpenSim.Services.Interfaces; | ||
33 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using log4net; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.World.Estate | ||
43 | { | ||
44 | public class EstateConnector | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected XEstateModule m_EstateModule; | ||
49 | |||
50 | public EstateConnector(XEstateModule module) | ||
51 | { | ||
52 | m_EstateModule = module; | ||
53 | } | ||
54 | |||
55 | public void SendTeleportHomeOneUser(uint EstateID, UUID PreyID) | ||
56 | { | ||
57 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
58 | sendData["METHOD"] = "teleport_home_one_user"; | ||
59 | |||
60 | sendData["EstateID"] = EstateID.ToString(); | ||
61 | sendData["PreyID"] = PreyID.ToString(); | ||
62 | |||
63 | SendToEstate(EstateID, sendData); | ||
64 | } | ||
65 | |||
66 | public void SendTeleportHomeAllUsers(uint EstateID) | ||
67 | { | ||
68 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
69 | sendData["METHOD"] = "teleport_home_all_users"; | ||
70 | |||
71 | sendData["EstateID"] = EstateID.ToString(); | ||
72 | |||
73 | SendToEstate(EstateID, sendData); | ||
74 | } | ||
75 | |||
76 | public bool SendUpdateCovenant(uint EstateID, UUID CovenantID) | ||
77 | { | ||
78 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
79 | sendData["METHOD"] = "update_covenant"; | ||
80 | |||
81 | sendData["CovenantID"] = CovenantID.ToString(); | ||
82 | sendData["EstateID"] = EstateID.ToString(); | ||
83 | |||
84 | // Handle local regions locally | ||
85 | // | ||
86 | foreach (Scene s in m_EstateModule.Scenes) | ||
87 | { | ||
88 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
89 | s.RegionInfo.RegionSettings.Covenant = CovenantID; | ||
90 | // s.ReloadEstateData(); | ||
91 | } | ||
92 | |||
93 | SendToEstate(EstateID, sendData); | ||
94 | |||
95 | return true; | ||
96 | } | ||
97 | |||
98 | public bool SendUpdateEstate(uint EstateID) | ||
99 | { | ||
100 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
101 | sendData["METHOD"] = "update_estate"; | ||
102 | |||
103 | sendData["EstateID"] = EstateID.ToString(); | ||
104 | |||
105 | // Handle local regions locally | ||
106 | // | ||
107 | foreach (Scene s in m_EstateModule.Scenes) | ||
108 | { | ||
109 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
110 | s.ReloadEstateData(); | ||
111 | } | ||
112 | |||
113 | SendToEstate(EstateID, sendData); | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | public void SendEstateMessage(uint EstateID, UUID FromID, string FromName, string Message) | ||
119 | { | ||
120 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
121 | sendData["METHOD"] = "estate_message"; | ||
122 | |||
123 | sendData["EstateID"] = EstateID.ToString(); | ||
124 | sendData["FromID"] = FromID.ToString(); | ||
125 | sendData["FromName"] = FromName; | ||
126 | sendData["Message"] = Message; | ||
127 | |||
128 | SendToEstate(EstateID, sendData); | ||
129 | } | ||
130 | |||
131 | private void SendToEstate(uint EstateID, Dictionary<string, object> sendData) | ||
132 | { | ||
133 | List<UUID> regions = m_EstateModule.Scenes[0].GetEstateRegions((int)EstateID); | ||
134 | |||
135 | UUID ScopeID = UUID.Zero; | ||
136 | |||
137 | // Handle local regions locally | ||
138 | // | ||
139 | foreach (Scene s in m_EstateModule.Scenes) | ||
140 | { | ||
141 | if (regions.Contains(s.RegionInfo.RegionID)) | ||
142 | { | ||
143 | // All regions in one estate are in the same scope. | ||
144 | // Use that scope. | ||
145 | // | ||
146 | ScopeID = s.RegionInfo.ScopeID; | ||
147 | regions.Remove(s.RegionInfo.RegionID); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | // Our own region should always be in the above list. | ||
152 | // In a standalone this would not be true. But then, | ||
153 | // Scope ID is not relevat there. Use first scope. | ||
154 | // | ||
155 | if (ScopeID == UUID.Zero) | ||
156 | ScopeID = m_EstateModule.Scenes[0].RegionInfo.ScopeID; | ||
157 | |||
158 | // Don't send to the same instance twice | ||
159 | // | ||
160 | List<string> done = new List<string>(); | ||
161 | |||
162 | // Send to remote regions | ||
163 | // | ||
164 | foreach (UUID regionID in regions) | ||
165 | { | ||
166 | GridRegion region = m_EstateModule.Scenes[0].GridService.GetRegionByUUID(ScopeID, regionID); | ||
167 | if (region != null) | ||
168 | { | ||
169 | string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; | ||
170 | if (done.Contains(url)) | ||
171 | continue; | ||
172 | |||
173 | Call(region, sendData); | ||
174 | done.Add(url); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | private bool Call(GridRegion region, Dictionary<string, object> sendData) | ||
180 | { | ||
181 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
182 | // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString); | ||
183 | try | ||
184 | { | ||
185 | string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; | ||
186 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
187 | url + "/estate", | ||
188 | reqString); | ||
189 | if (reply != string.Empty) | ||
190 | { | ||
191 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
192 | |||
193 | if (replyData.ContainsKey("RESULT")) | ||
194 | { | ||
195 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
196 | return true; | ||
197 | else | ||
198 | return false; | ||
199 | } | ||
200 | else | ||
201 | m_log.DebugFormat("[XESTATE CONNECTOR]: reply data does not contain result field"); | ||
202 | |||
203 | } | ||
204 | else | ||
205 | m_log.DebugFormat("[XESTATE CONNECTOR]: received empty reply"); | ||
206 | } | ||
207 | catch (Exception e) | ||
208 | { | ||
209 | m_log.DebugFormat("[XESTATE CONNECTOR]: Exception when contacting remote sim: {0}", e.Message); | ||
210 | } | ||
211 | |||
212 | return false; | ||
213 | } | ||
214 | } | ||
215 | } | ||
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 | } | ||
diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs new file mode 100644 index 0000000..eb74cda --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs | |||
@@ -0,0 +1,298 @@ | |||
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.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using log4net; | ||
42 | |||
43 | namespace OpenSim.Region.CoreModules.World.Estate | ||
44 | { | ||
45 | public class EstateRequestHandler : BaseStreamHandler | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected XEstateModule m_EstateModule; | ||
50 | protected Object m_RequestLock = new Object(); | ||
51 | |||
52 | public EstateRequestHandler(XEstateModule fmodule) | ||
53 | : base("POST", "/estate") | ||
54 | { | ||
55 | m_EstateModule = fmodule; | ||
56 | } | ||
57 | |||
58 | public override byte[] Handle(string path, Stream requestData, | ||
59 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
60 | { | ||
61 | StreamReader sr = new StreamReader(requestData); | ||
62 | string body = sr.ReadToEnd(); | ||
63 | sr.Close(); | ||
64 | body = body.Trim(); | ||
65 | |||
66 | m_log.DebugFormat("[XESTATE HANDLER]: query String: {0}", body); | ||
67 | |||
68 | try | ||
69 | { | ||
70 | lock (m_RequestLock) | ||
71 | { | ||
72 | Dictionary<string, object> request = | ||
73 | ServerUtils.ParseQueryString(body); | ||
74 | |||
75 | if (!request.ContainsKey("METHOD")) | ||
76 | return FailureResult(); | ||
77 | |||
78 | string method = request["METHOD"].ToString(); | ||
79 | request.Remove("METHOD"); | ||
80 | |||
81 | try | ||
82 | { | ||
83 | m_EstateModule.InInfoUpdate = false; | ||
84 | |||
85 | switch (method) | ||
86 | { | ||
87 | case "update_covenant": | ||
88 | return UpdateCovenant(request); | ||
89 | case "update_estate": | ||
90 | return UpdateEstate(request); | ||
91 | case "estate_message": | ||
92 | return EstateMessage(request); | ||
93 | case "teleport_home_one_user": | ||
94 | return TeleportHomeOneUser(request); | ||
95 | case "teleport_home_all_users": | ||
96 | return TeleportHomeAllUsers(request); | ||
97 | } | ||
98 | } | ||
99 | finally | ||
100 | { | ||
101 | m_EstateModule.InInfoUpdate = false; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | catch (Exception e) | ||
106 | { | ||
107 | m_log.Debug("[XESTATE]: Exception {0}" + e.ToString()); | ||
108 | } | ||
109 | |||
110 | return FailureResult(); | ||
111 | } | ||
112 | |||
113 | byte[] TeleportHomeAllUsers(Dictionary<string, object> request) | ||
114 | { | ||
115 | UUID PreyID = UUID.Zero; | ||
116 | int EstateID = 0; | ||
117 | |||
118 | if (!request.ContainsKey("EstateID")) | ||
119 | return FailureResult(); | ||
120 | |||
121 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
122 | return FailureResult(); | ||
123 | |||
124 | foreach (Scene s in m_EstateModule.Scenes) | ||
125 | { | ||
126 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
127 | { | ||
128 | s.ForEachScenePresence(delegate(ScenePresence p) { | ||
129 | if (p != null && !p.IsChildAgent) | ||
130 | { | ||
131 | p.ControllingClient.SendTeleportStart(16); | ||
132 | s.TeleportClientHome(p.ControllingClient.AgentId, p.ControllingClient); | ||
133 | } | ||
134 | }); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | return SuccessResult(); | ||
139 | } | ||
140 | |||
141 | byte[] TeleportHomeOneUser(Dictionary<string, object> request) | ||
142 | { | ||
143 | UUID PreyID = UUID.Zero; | ||
144 | int EstateID = 0; | ||
145 | |||
146 | if (!request.ContainsKey("PreyID") || | ||
147 | !request.ContainsKey("EstateID")) | ||
148 | { | ||
149 | return FailureResult(); | ||
150 | } | ||
151 | |||
152 | if (!UUID.TryParse(request["PreyID"].ToString(), out PreyID)) | ||
153 | return FailureResult(); | ||
154 | |||
155 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
156 | return FailureResult(); | ||
157 | |||
158 | foreach (Scene s in m_EstateModule.Scenes) | ||
159 | { | ||
160 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
161 | { | ||
162 | ScenePresence p = s.GetScenePresence(PreyID); | ||
163 | if (p != null && !p.IsChildAgent) | ||
164 | { | ||
165 | p.ControllingClient.SendTeleportStart(16); | ||
166 | s.TeleportClientHome(PreyID, p.ControllingClient); | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | |||
171 | return SuccessResult(); | ||
172 | } | ||
173 | |||
174 | byte[] EstateMessage(Dictionary<string, object> request) | ||
175 | { | ||
176 | UUID FromID = UUID.Zero; | ||
177 | string FromName = String.Empty; | ||
178 | string Message = String.Empty; | ||
179 | int EstateID = 0; | ||
180 | |||
181 | if (!request.ContainsKey("FromID") || | ||
182 | !request.ContainsKey("FromName") || | ||
183 | !request.ContainsKey("Message") || | ||
184 | !request.ContainsKey("EstateID")) | ||
185 | { | ||
186 | return FailureResult(); | ||
187 | } | ||
188 | |||
189 | if (!UUID.TryParse(request["FromID"].ToString(), out FromID)) | ||
190 | return FailureResult(); | ||
191 | |||
192 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
193 | return FailureResult(); | ||
194 | |||
195 | FromName = request["FromName"].ToString(); | ||
196 | Message = request["Message"].ToString(); | ||
197 | |||
198 | foreach (Scene s in m_EstateModule.Scenes) | ||
199 | { | ||
200 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
201 | { | ||
202 | IDialogModule dm = s.RequestModuleInterface<IDialogModule>(); | ||
203 | |||
204 | if (dm != null) | ||
205 | { | ||
206 | dm.SendNotificationToUsersInRegion(FromID, FromName, | ||
207 | Message); | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | return SuccessResult(); | ||
213 | } | ||
214 | |||
215 | byte[] UpdateCovenant(Dictionary<string, object> request) | ||
216 | { | ||
217 | UUID CovenantID = UUID.Zero; | ||
218 | int EstateID = 0; | ||
219 | |||
220 | if (!request.ContainsKey("CovenantID") || !request.ContainsKey("EstateID")) | ||
221 | return FailureResult(); | ||
222 | |||
223 | if (!UUID.TryParse(request["CovenantID"].ToString(), out CovenantID)) | ||
224 | return FailureResult(); | ||
225 | |||
226 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
227 | return FailureResult(); | ||
228 | |||
229 | foreach (Scene s in m_EstateModule.Scenes) | ||
230 | { | ||
231 | if (s.RegionInfo.EstateSettings.EstateID == (uint)EstateID) | ||
232 | s.RegionInfo.RegionSettings.Covenant = CovenantID; | ||
233 | } | ||
234 | |||
235 | return SuccessResult(); | ||
236 | } | ||
237 | |||
238 | byte[] UpdateEstate(Dictionary<string, object> request) | ||
239 | { | ||
240 | int EstateID = 0; | ||
241 | |||
242 | if (!request.ContainsKey("EstateID")) | ||
243 | return FailureResult(); | ||
244 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
245 | return FailureResult(); | ||
246 | |||
247 | foreach (Scene s in m_EstateModule.Scenes) | ||
248 | { | ||
249 | if (s.RegionInfo.EstateSettings.EstateID == (uint)EstateID) | ||
250 | s.ReloadEstateData(); | ||
251 | } | ||
252 | return SuccessResult(); | ||
253 | } | ||
254 | |||
255 | private byte[] FailureResult() | ||
256 | { | ||
257 | return BoolResult(false); | ||
258 | } | ||
259 | |||
260 | private byte[] SuccessResult() | ||
261 | { | ||
262 | return BoolResult(true); | ||
263 | } | ||
264 | |||
265 | private byte[] BoolResult(bool value) | ||
266 | { | ||
267 | XmlDocument doc = new XmlDocument(); | ||
268 | |||
269 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
270 | "", ""); | ||
271 | |||
272 | doc.AppendChild(xmlnode); | ||
273 | |||
274 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
275 | ""); | ||
276 | |||
277 | doc.AppendChild(rootElement); | ||
278 | |||
279 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
280 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
281 | |||
282 | rootElement.AppendChild(result); | ||
283 | |||
284 | return DocToBytes(doc); | ||
285 | } | ||
286 | |||
287 | private byte[] DocToBytes(XmlDocument doc) | ||
288 | { | ||
289 | MemoryStream ms = new MemoryStream(); | ||
290 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
291 | xw.Formatting = Formatting.Indented; | ||
292 | doc.WriteTo(xw); | ||
293 | xw.Flush(); | ||
294 | |||
295 | return ms.ToArray(); | ||
296 | } | ||
297 | } | ||
298 | } | ||