aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService/GridService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/GridService/GridService.cs')
-rw-r--r--OpenSim/Services/GridService/GridService.cs297
1 files changed, 297 insertions, 0 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
new file mode 100644
index 0000000..6aa1c4f
--- /dev/null
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -0,0 +1,297 @@
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.Net;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using OpenSim.Data;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace OpenSim.Services.GridService
41{
42 public class GridService : GridServiceBase, IGridService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47
48 public GridService(IConfigSource config)
49 : base(config)
50 {
51 MainConsole.Instance.Commands.AddCommand("kfs", false,
52 "show digest",
53 "show digest <ID>",
54 "Show asset digest", HandleShowDigest);
55
56 MainConsole.Instance.Commands.AddCommand("kfs", false,
57 "delete asset",
58 "delete asset <ID>",
59 "Delete asset from database", HandleDeleteAsset);
60
61 }
62
63 #region IGridService
64
65 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos)
66 {
67 if (m_Database.Get(regionInfos.RegionID, scopeID) != null)
68 {
69 m_log.WarnFormat("[GRID SERVICE]: Region {0} already registered in scope {1}.", regionInfos.RegionID, scopeID);
70 return false;
71 }
72 if (m_Database.Get((int)regionInfos.RegionLocX, (int)regionInfos.RegionLocY, scopeID) != null)
73 {
74 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
75 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
76 return false;
77 }
78
79 // Everything is ok, let's register
80 RegionData rdata = RegionInfo2RegionData(regionInfos);
81 rdata.ScopeID = scopeID;
82 m_Database.Store(rdata);
83 return true;
84 }
85
86 public bool DeregisterRegion(UUID regionID)
87 {
88 return m_Database.Delete(regionID);
89 }
90
91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, int x, int y)
92 {
93 List<RegionData> rdatas = m_Database.Get(x - 1, y - 1, x + 1, y + 1, scopeID);
94 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
95 foreach (RegionData rdata in rdatas)
96 rinfos.Add(RegionData2RegionInfo(rdata));
97
98 return rinfos;
99 }
100
101 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
102 {
103 RegionData rdata = m_Database.Get(regionID, scopeID);
104 if (rdata != null)
105 return RegionData2RegionInfo(rdata);
106
107 return null;
108 }
109
110 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
111 {
112 RegionData rdata = m_Database.Get(x, y, scopeID);
113 if (rdata != null)
114 return RegionData2RegionInfo(rdata);
115
116 return null;
117 }
118
119 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
120 {
121 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
122 if ((rdatas != null) && (rdatas.Count > 0))
123 return RegionData2RegionInfo(rdatas[0]); // get the first
124
125 return null;
126 }
127
128 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
129 {
130 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
131
132 int count = 0;
133 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
134
135 if (rdatas != null)
136 {
137 foreach (RegionData rdata in rdatas)
138 {
139 if (count++ < maxNumber)
140 rinfos.Add(RegionData2RegionInfo(rdata));
141 }
142 }
143
144 return rinfos;
145 }
146
147 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
148 {
149 List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID);
150 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
151 foreach (RegionData rdata in rdatas)
152 rinfos.Add(RegionData2RegionInfo(rdata));
153
154 return rinfos;
155 }
156
157 #endregion
158
159 #region Data structure conversions
160
161 protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo)
162 {
163 RegionData rdata = new RegionData();
164 rdata.posX = (int)rinfo.RegionLocX;
165 rdata.posY = (int)rinfo.RegionLocY;
166 rdata.RegionID = rinfo.RegionID;
167 //rdata.RegionName = rinfo.RegionName;
168 rdata.Data["external_ip_address"] = rinfo.ExternalEndPoint.Address.ToString();
169 rdata.Data["external_port"] = rinfo.ExternalEndPoint.Port.ToString();
170 rdata.Data["external_host_name"] = rinfo.ExternalHostName;
171 rdata.Data["http_port"] = rinfo.HttpPort.ToString();
172 rdata.Data["internal_ip_address"] = rinfo.InternalEndPoint.Address.ToString();
173 rdata.Data["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
174 rdata.Data["alternate_ports"] = rinfo.m_allow_alternate_ports.ToString();
175 rdata.Data["server_uri"] = rinfo.ServerURI;
176
177 return rdata;
178 }
179
180 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata)
181 {
182 SimpleRegionInfo rinfo = new SimpleRegionInfo();
183 rinfo.RegionLocX = (uint)rdata.posX;
184 rinfo.RegionLocY = (uint)rdata.posY;
185 rinfo.RegionID = rdata.RegionID;
186 //rinfo.RegionName = rdata.RegionName;
187
188 // Now for the variable data
189 if ((rdata.Data["external_ip_address"] != null) && (rdata.Data["external_port"] != null))
190 {
191 int port = 0;
192 Int32.TryParse((string)rdata.Data["external_port"], out port);
193 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["external_ip_address"]), port);
194 rinfo.ExternalEndPoint = ep;
195 }
196 else
197 rinfo.ExternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
198
199 if (rdata.Data["external_host_name"] != null)
200 rinfo.ExternalHostName = (string)rdata.Data["external_host_name"] ;
201
202 if (rdata.Data["http_port"] != null)
203 {
204 UInt32 port = 0;
205 UInt32.TryParse((string)rdata.Data["http_port"], out port);
206 rinfo.HttpPort = port;
207 }
208
209 if ((rdata.Data["internal_ip_address"] != null) && (rdata.Data["internal_port"] != null))
210 {
211 int port = 0;
212 Int32.TryParse((string)rdata.Data["internal_port"], out port);
213 IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)rdata.Data["internal_ip_address"]), port);
214 rinfo.InternalEndPoint = ep;
215 }
216 else
217 rinfo.InternalEndPoint = new IPEndPoint(new IPAddress(0), 0);
218
219 if (rdata.Data["alternate_ports"] != null)
220 {
221 bool alts = false;
222 Boolean.TryParse((string)rdata.Data["alternate_ports"], out alts);
223 rinfo.m_allow_alternate_ports = alts;
224 }
225
226 if (rdata.Data["server_uri"] != null)
227 rinfo.ServerURI = (string)rdata.Data["server_uri"];
228
229 return rinfo;
230 }
231
232 #endregion
233
234 void HandleShowDigest(string module, string[] args)
235 {
236 //if (args.Length < 3)
237 //{
238 // MainConsole.Instance.Output("Syntax: show digest <ID>");
239 // return;
240 //}
241
242 //AssetBase asset = Get(args[2]);
243
244 //if (asset == null || asset.Data.Length == 0)
245 //{
246 // MainConsole.Instance.Output("Asset not found");
247 // return;
248 //}
249
250 //int i;
251
252 //MainConsole.Instance.Output(String.Format("Name: {0}", asset.Name));
253 //MainConsole.Instance.Output(String.Format("Description: {0}", asset.Description));
254 //MainConsole.Instance.Output(String.Format("Type: {0}", asset.Type));
255 //MainConsole.Instance.Output(String.Format("Content-type: {0}", asset.Metadata.ContentType));
256
257 //for (i = 0 ; i < 5 ; i++)
258 //{
259 // int off = i * 16;
260 // if (asset.Data.Length <= off)
261 // break;
262 // int len = 16;
263 // if (asset.Data.Length < off + len)
264 // len = asset.Data.Length - off;
265
266 // byte[] line = new byte[len];
267 // Array.Copy(asset.Data, off, line, 0, len);
268
269 // string text = BitConverter.ToString(line);
270 // MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text));
271 //}
272 }
273
274 void HandleDeleteAsset(string module, string[] args)
275 {
276 //if (args.Length < 3)
277 //{
278 // MainConsole.Instance.Output("Syntax: delete asset <ID>");
279 // return;
280 //}
281
282 //AssetBase asset = Get(args[2]);
283
284 //if (asset == null || asset.Data.Length == 0)
285 // MainConsole.Instance.Output("Asset not found");
286 // return;
287 //}
288
289 //Delete(args[2]);
290
291 ////MainConsole.Instance.Output("Asset deleted");
292 //// TODO: Implement this
293
294 //MainConsole.Instance.Output("Asset deletion not supported by database");
295 }
296 }
297}