OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XEstateConnector.cs
Go to the documentation of this file.
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;
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 
49 
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  lock (m_EstateModule.Scenes)
140  {
141  foreach (Scene s in m_EstateModule.Scenes)
142  {
143  if (regions.Contains(s.RegionInfo.RegionID))
144  {
145  // All regions in one estate are in the same scope.
146  // Use that scope.
147  //
148  ScopeID = s.RegionInfo.ScopeID;
149  regions.Remove(s.RegionInfo.RegionID);
150  }
151  }
152  }
153 
154  // Our own region should always be in the above list.
155  // In a standalone this would not be true. But then,
156  // Scope ID is not relevat there. Use first scope.
157  //
158  if (ScopeID == UUID.Zero)
159  ScopeID = m_EstateModule.Scenes[0].RegionInfo.ScopeID;
160 
161  // Don't send to the same instance twice
162  //
163  List<string> done = new List<string>();
164 
165  // Send to remote regions
166  //
167  foreach (UUID regionID in regions)
168  {
169  GridRegion region = m_EstateModule.Scenes[0].GridService.GetRegionByUUID(ScopeID, regionID);
170  if (region != null)
171  {
172  string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
173  if (done.Contains(url))
174  continue;
175 
176  Call(region, sendData);
177  done.Add(url);
178  }
179  }
180  }
181 
182  private bool Call(GridRegion region, Dictionary<string, object> sendData)
183  {
184  string reqString = ServerUtils.BuildQueryString(sendData);
185  // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString);
186  try
187  {
188  string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
189  string reply = SynchronousRestFormsRequester.MakeRequest("POST",
190  url + "/estate",
191  reqString);
192  if (reply != string.Empty)
193  {
194  Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
195 
196  if (replyData.ContainsKey("RESULT"))
197  {
198  if (replyData["RESULT"].ToString().ToLower() == "true")
199  return true;
200  else
201  return false;
202  }
203  else
204  m_log.DebugFormat("[XESTATE CONNECTOR]: reply data does not contain result field");
205 
206  }
207  else
208  m_log.DebugFormat("[XESTATE CONNECTOR]: received empty reply");
209  }
210  catch (Exception e)
211  {
212  m_log.DebugFormat("[XESTATE CONNECTOR]: Exception when contacting remote sim: {0}", e.Message);
213  }
214 
215  return false;
216  }
217  }
218 }
EstateSettings EstateSettings
Definition: RegionInfo.cs:275
void SendEstateMessage(uint EstateID, UUID FromID, string FromName, string Message)
OpenSim.Services.Interfaces.GridRegion GridRegion
void SendTeleportHomeOneUser(uint EstateID, UUID PreyID)
bool SendUpdateCovenant(uint EstateID, UUID CovenantID)