diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Estate/EstateConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Estate/EstateConnector.cs | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateConnector.cs b/OpenSim/Region/CoreModules/World/Estate/EstateConnector.cs new file mode 100644 index 0000000..8001c3c --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Estate/EstateConnector.cs | |||
@@ -0,0 +1,228 @@ | |||
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 EstateModule m_EstateModule; | ||
49 | private string token; | ||
50 | uint port = 0; | ||
51 | |||
52 | public EstateConnector(EstateModule module, string _token, uint _port) | ||
53 | { | ||
54 | m_EstateModule = module; | ||
55 | token = _token; | ||
56 | port = _port; | ||
57 | } | ||
58 | |||
59 | public void SendTeleportHomeOneUser(uint EstateID, UUID PreyID) | ||
60 | { | ||
61 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
62 | sendData["METHOD"] = "teleport_home_one_user"; | ||
63 | sendData["TOKEN"] = token; | ||
64 | |||
65 | sendData["EstateID"] = EstateID.ToString(); | ||
66 | sendData["PreyID"] = PreyID.ToString(); | ||
67 | |||
68 | SendToEstate(EstateID, sendData); | ||
69 | } | ||
70 | |||
71 | public void SendTeleportHomeAllUsers(uint EstateID) | ||
72 | { | ||
73 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
74 | sendData["METHOD"] = "teleport_home_all_users"; | ||
75 | sendData["TOKEN"] = token; | ||
76 | |||
77 | sendData["EstateID"] = EstateID.ToString(); | ||
78 | |||
79 | SendToEstate(EstateID, sendData); | ||
80 | } | ||
81 | |||
82 | public bool SendUpdateCovenant(uint EstateID, UUID CovenantID) | ||
83 | { | ||
84 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
85 | sendData["METHOD"] = "update_covenant"; | ||
86 | sendData["TOKEN"] = token; | ||
87 | |||
88 | sendData["CovenantID"] = CovenantID.ToString(); | ||
89 | sendData["EstateID"] = EstateID.ToString(); | ||
90 | |||
91 | // Handle local regions locally | ||
92 | // | ||
93 | foreach (Scene s in m_EstateModule.Scenes) | ||
94 | { | ||
95 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
96 | s.RegionInfo.RegionSettings.Covenant = CovenantID; | ||
97 | // s.ReloadEstateData(); | ||
98 | } | ||
99 | |||
100 | SendToEstate(EstateID, sendData); | ||
101 | |||
102 | return true; | ||
103 | } | ||
104 | |||
105 | public bool SendUpdateEstate(uint EstateID) | ||
106 | { | ||
107 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
108 | sendData["METHOD"] = "update_estate"; | ||
109 | sendData["TOKEN"] = token; | ||
110 | |||
111 | sendData["EstateID"] = EstateID.ToString(); | ||
112 | |||
113 | // Handle local regions locally | ||
114 | // | ||
115 | foreach (Scene s in m_EstateModule.Scenes) | ||
116 | { | ||
117 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
118 | s.ReloadEstateData(); | ||
119 | } | ||
120 | |||
121 | SendToEstate(EstateID, sendData); | ||
122 | |||
123 | return true; | ||
124 | } | ||
125 | |||
126 | public void SendEstateMessage(uint EstateID, UUID FromID, string FromName, string Message) | ||
127 | { | ||
128 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
129 | sendData["METHOD"] = "estate_message"; | ||
130 | sendData["TOKEN"] = token; | ||
131 | |||
132 | sendData["EstateID"] = EstateID.ToString(); | ||
133 | sendData["FromID"] = FromID.ToString(); | ||
134 | sendData["FromName"] = FromName; | ||
135 | sendData["Message"] = Message; | ||
136 | |||
137 | SendToEstate(EstateID, sendData); | ||
138 | } | ||
139 | |||
140 | private void SendToEstate(uint EstateID, Dictionary<string, object> sendData) | ||
141 | { | ||
142 | List<UUID> regions = m_EstateModule.Scenes[0].GetEstateRegions((int)EstateID); | ||
143 | |||
144 | // Don't send to the same instance twice | ||
145 | List<string> done = new List<string>(); | ||
146 | |||
147 | // Handle local regions locally | ||
148 | lock (m_EstateModule.Scenes) | ||
149 | { | ||
150 | foreach (Scene s in m_EstateModule.Scenes) | ||
151 | { | ||
152 | RegionInfo sreg = s.RegionInfo; | ||
153 | if (regions.Contains(sreg.RegionID)) | ||
154 | { | ||
155 | string url = sreg.ExternalHostName + ":" + sreg.HttpPort; | ||
156 | regions.Remove(sreg.RegionID); | ||
157 | if(!done.Contains(url)) // we may have older regs with same url lost in dbs | ||
158 | done.Add(url); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | if(regions.Count == 0) | ||
164 | return; | ||
165 | |||
166 | Scene baseScene = m_EstateModule.Scenes[0]; | ||
167 | UUID ScopeID = baseScene.RegionInfo.ScopeID; | ||
168 | IGridService gridService = baseScene.GridService; | ||
169 | if(gridService == null) | ||
170 | return; | ||
171 | |||
172 | // Send to remote regions | ||
173 | foreach (UUID regionID in regions) | ||
174 | { | ||
175 | GridRegion region = gridService.GetRegionByUUID(ScopeID, regionID); | ||
176 | if (region != null) | ||
177 | { | ||
178 | string url = region.ExternalHostName + ":" + region.HttpPort; | ||
179 | if(done.Contains(url)) | ||
180 | continue; | ||
181 | Call(region, sendData); | ||
182 | done.Add(url); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | private bool Call(GridRegion region, Dictionary<string, object> sendData) | ||
188 | { | ||
189 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
190 | // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString); | ||
191 | try | ||
192 | { | ||
193 | string url = ""; | ||
194 | if(port != 0) | ||
195 | url = "http://" + region.ExternalHostName + ":" + port + "/"; | ||
196 | else | ||
197 | url = region.ServerURI; | ||
198 | |||
199 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
200 | url + "estate", | ||
201 | reqString); | ||
202 | if (reply != string.Empty) | ||
203 | { | ||
204 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
205 | |||
206 | if (replyData.ContainsKey("RESULT")) | ||
207 | { | ||
208 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
209 | return true; | ||
210 | else | ||
211 | return false; | ||
212 | } | ||
213 | else | ||
214 | m_log.DebugFormat("[XESTATE CONNECTOR]: reply data does not contain result field"); | ||
215 | |||
216 | } | ||
217 | else | ||
218 | m_log.DebugFormat("[XESTATE CONNECTOR]: received empty reply"); | ||
219 | } | ||
220 | catch (Exception e) | ||
221 | { | ||
222 | m_log.DebugFormat("[XESTATE CONNECTOR]: Exception when contacting remote sim: {0}", e.Message); | ||
223 | } | ||
224 | |||
225 | return false; | ||
226 | } | ||
227 | } | ||
228 | } | ||