aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server
diff options
context:
space:
mode:
authorMelanie Thielker2014-08-23 17:33:14 +0200
committerMelanie Thielker2014-08-23 17:33:14 +0200
commit1a7efc2c64ac70b4ea77a370964c7a3df2c283e2 (patch)
treee45e0c0f579743ceaa83b92b7b0347d606c11e84 /OpenSim/Server
parentFix a condition check (diff)
downloadopensim-SC_OLD-1a7efc2c64ac70b4ea77a370964c7a3df2c283e2.zip
opensim-SC_OLD-1a7efc2c64ac70b4ea77a370964c7a3df2c283e2.tar.gz
opensim-SC_OLD-1a7efc2c64ac70b4ea77a370964c7a3df2c283e2.tar.bz2
opensim-SC_OLD-1a7efc2c64ac70b4ea77a370964c7a3df2c283e2.tar.xz
Change the map tile system to be multi-grid hosting compatible
Conflicts: OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/Map/MapGetServerConnector.cs12
-rw-r--r--OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs252
3 files changed, 267 insertions, 2 deletions
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
index 4a61969..c2c575c 100644
--- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
@@ -117,8 +117,11 @@ namespace OpenSim.Server.Handlers.MapImage
117 return FailureResult("Bad request."); 117 return FailureResult("Bad request.");
118 } 118 }
119 int x = 0, y = 0; 119 int x = 0, y = 0;
120 UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
120 Int32.TryParse(request["X"].ToString(), out x); 121 Int32.TryParse(request["X"].ToString(), out x);
121 Int32.TryParse(request["Y"].ToString(), out y); 122 Int32.TryParse(request["Y"].ToString(), out y);
123 if (request.ContainsKey("SCOPE"))
124 UUID.TryParse(request["SCOPE"].ToString(), out scopeID);
122 125
123 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); 126 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y);
124 127
@@ -151,7 +154,7 @@ namespace OpenSim.Server.Handlers.MapImage
151 byte[] data = Convert.FromBase64String(request["DATA"].ToString()); 154 byte[] data = Convert.FromBase64String(request["DATA"].ToString());
152 155
153 string reason = string.Empty; 156 string reason = string.Empty;
154 bool result = m_MapService.AddMapTile(x, y, data, out reason); 157 bool result = m_MapService.AddMapTile(x, y, data, scopeID, out reason);
155 158
156 if (result) 159 if (result)
157 return SuccessResult(); 160 return SuccessResult();
diff --git a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
index 4502b7d..5454c6f 100644
--- a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
@@ -38,6 +38,7 @@ using OpenSim.Server.Base;
38using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
39using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Server.Handlers.Base; 40using OpenSim.Server.Handlers.Base;
41using OpenMetaverse;
41 42
42namespace OpenSim.Server.Handlers.MapImage 43namespace OpenSim.Server.Handlers.MapImage
43{ 44{
@@ -93,7 +94,16 @@ namespace OpenSim.Server.Handlers.MapImage
93 94
94 byte[] result = new byte[0]; 95 byte[] result = new byte[0];
95 string format = string.Empty; 96 string format = string.Empty;
96 result = m_MapService.GetMapTile(path.Trim('/'), out format); 97
98 UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
99
100 string[] bits = path.Trim('/').Split(new char[] {'/'});
101 if (bits.Length > 1)
102 {
103 scopeID = new UUID(bits[0]);
104 path = bits[1];
105 }
106 result = m_MapService.GetMapTile(path.Trim('/'), scopeID, out format);
97 if (result.Length > 0) 107 if (result.Length > 0)
98 { 108 {
99 httpResponse.StatusCode = (int)HttpStatusCode.OK; 109 httpResponse.StatusCode = (int)HttpStatusCode.OK;
diff --git a/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs b/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs
new file mode 100644
index 0000000..8a31579
--- /dev/null
+++ b/OpenSim/Server/Handlers/Map/MapRemoveServerConnector.cs
@@ -0,0 +1,252 @@
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.Generic;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33
34using Nini.Config;
35using log4net;
36using OpenMetaverse;
37
38using OpenSim.Framework;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Server.Handlers.Base;
43
44using GridRegion = OpenSim.Services.Interfaces.GridRegion;
45
46namespace OpenSim.Server.Handlers.MapImage
47{
48 public class MapRemoveServiceConnector : ServiceConnector
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IMapImageService m_MapService;
53 private IGridService m_GridService;
54 private string m_ConfigName = "MapImageService";
55
56 public MapRemoveServiceConnector(IConfigSource config, IHttpServer server, string configName) :
57 base(config, server, configName)
58 {
59 IConfig serverConfig = config.Configs[m_ConfigName];
60 if (serverConfig == null)
61 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
62
63 string mapService = serverConfig.GetString("LocalServiceModule",
64 String.Empty);
65
66 if (mapService == String.Empty)
67 throw new Exception("No LocalServiceModule in config file");
68
69 Object[] args = new Object[] { config };
70 m_MapService = ServerUtils.LoadPlugin<IMapImageService>(mapService, args);
71
72 string gridService = serverConfig.GetString("GridService", String.Empty);
73 if (gridService != string.Empty)
74 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
75
76 if (m_GridService != null)
77 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is ON");
78 else
79 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF");
80
81 bool proxy = serverConfig.GetBoolean("HasProxy", false);
82 server.AddStreamHandler(new MapServerRemoveHandler(m_MapService, m_GridService, proxy));
83
84 }
85 }
86
87 class MapServerRemoveHandler : BaseStreamHandler
88 {
89 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
90 private IMapImageService m_MapService;
91 private IGridService m_GridService;
92 bool m_Proxy;
93
94 public MapServerRemoveHandler(IMapImageService service, IGridService grid, bool proxy) :
95 base("POST", "/removemap")
96 {
97 m_MapService = service;
98 m_GridService = grid;
99 m_Proxy = proxy;
100 }
101
102 public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
103 {
104// m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path);
105 StreamReader sr = new StreamReader(requestData);
106 string body = sr.ReadToEnd();
107 sr.Close();
108 body = body.Trim();
109
110 try
111 {
112 Dictionary<string, object> request = ServerUtils.ParseQueryString(body);
113
114 if (!request.ContainsKey("X") || !request.ContainsKey("Y"))
115 {
116 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest;
117 return FailureResult("Bad request.");
118 }
119 int x = 0, y = 0;
120 Int32.TryParse(request["X"].ToString(), out x);
121 Int32.TryParse(request["Y"].ToString(), out y);
122 UUID scopeID = new UUID("07f8d88e-cd5e-4239-a0ed-843f75d09992");
123 if (request.ContainsKey("SCOPE"))
124 UUID.TryParse(request["SCOPE"].ToString(), out scopeID);
125
126 m_log.DebugFormat("[MAP REMOVE SERVER CONNECTOR]: Received position data for region at {0}-{1}", x, y);
127
128 if (m_GridService != null)
129 {
130 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
131 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize);
132 if (r != null)
133 {
134 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString())
135 {
136 m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address);
137 return FailureResult("IP address of caller does not match IP address of registered region");
138 }
139
140 }
141 else
142 {
143 m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}",
144 ipAddr, x, y);
145 return FailureResult("Region not found at given coordinates");
146 }
147 }
148
149 string reason = string.Empty;
150 bool result = m_MapService.RemoveMapTile(x, y, scopeID, out reason);
151
152 if (result)
153 return SuccessResult();
154 else
155 return FailureResult(reason);
156
157 }
158 catch (Exception e)
159 {
160 m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
161 }
162
163 return FailureResult("Unexpected server error");
164 }
165
166 private byte[] SuccessResult()
167 {
168 XmlDocument doc = new XmlDocument();
169
170 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
171 "", "");
172
173 doc.AppendChild(xmlnode);
174
175 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
176 "");
177
178 doc.AppendChild(rootElement);
179
180 XmlElement result = doc.CreateElement("", "Result", "");
181 result.AppendChild(doc.CreateTextNode("Success"));
182
183 rootElement.AppendChild(result);
184
185 return DocToBytes(doc);
186 }
187
188 private byte[] FailureResult(string msg)
189 {
190 XmlDocument doc = new XmlDocument();
191
192 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
193 "", "");
194
195 doc.AppendChild(xmlnode);
196
197 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
198 "");
199
200 doc.AppendChild(rootElement);
201
202 XmlElement result = doc.CreateElement("", "Result", "");
203 result.AppendChild(doc.CreateTextNode("Failure"));
204
205 rootElement.AppendChild(result);
206
207 XmlElement message = doc.CreateElement("", "Message", "");
208 message.AppendChild(doc.CreateTextNode(msg));
209
210 rootElement.AppendChild(message);
211
212 return DocToBytes(doc);
213 }
214
215 private byte[] DocToBytes(XmlDocument doc)
216 {
217 MemoryStream ms = new MemoryStream();
218 XmlTextWriter xw = new XmlTextWriter(ms, null);
219 xw.Formatting = Formatting.Indented;
220 doc.WriteTo(xw);
221 xw.Flush();
222
223 return ms.ToArray();
224 }
225
226 private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)
227 {
228 if (!m_Proxy)
229 return request.RemoteIPEndPoint.Address;
230
231 // We're behind a proxy
232 string xff = "X-Forwarded-For";
233 string xffValue = request.Headers[xff.ToLower()];
234 if (xffValue == null || (xffValue != null && xffValue == string.Empty))
235 xffValue = request.Headers[xff];
236
237 if (xffValue == null || (xffValue != null && xffValue == string.Empty))
238 {
239 m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header");
240 return request.RemoteIPEndPoint.Address;
241 }
242
243 System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue);
244 if (ep != null)
245 return ep.Address;
246
247 // Oops
248 return request.RemoteIPEndPoint.Address;
249 }
250
251 }
252}