aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer.Modules/GridDBService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/GridServer.Modules/GridDBService.cs284
1 files changed, 0 insertions, 284 deletions
diff --git a/OpenSim/Grid/GridServer.Modules/GridDBService.cs b/OpenSim/Grid/GridServer.Modules/GridDBService.cs
deleted file mode 100644
index fd5a09a..0000000
--- a/OpenSim/Grid/GridServer.Modules/GridDBService.cs
+++ /dev/null
@@ -1,284 +0,0 @@
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;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using System.Xml;
34using log4net;
35using Nwc.XmlRpc;
36using OpenMetaverse;
37using OpenSim.Data;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Framework.Servers;
41
42
43namespace OpenSim.Grid.GridServer.Modules
44{
45 public class GridDBService : IRegionProfileService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private List<IGridDataPlugin> _plugins = new List<IGridDataPlugin>();
50 private List<ILogDataPlugin> _logplugins = new List<ILogDataPlugin>();
51
52 /// <summary>
53 /// Adds a list of grid and log data plugins, as described by
54 /// `provider' and `connect', to `_plugins' and `_logplugins',
55 /// respectively.
56 /// </summary>
57 /// <param name="provider">
58 /// The filename of the inventory server plugin DLL.
59 /// </param>
60 /// <param name="connect">
61 /// The connection string for the storage backend.
62 /// </param>
63 public void AddPlugin(string provider, string connect)
64 {
65 _plugins = DataPluginFactory.LoadDataPlugins<IGridDataPlugin>(provider, connect);
66 _logplugins = DataPluginFactory.LoadDataPlugins<ILogDataPlugin>(provider, connect);
67 }
68
69 public int GetNumberOfPlugins()
70 {
71 return _plugins.Count;
72 }
73
74 /// <summary>
75 /// Logs a piece of information to the database
76 /// </summary>
77 /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param>
78 /// <param name="method">Which method is being called?</param>
79 /// <param name="args">What arguments are being passed?</param>
80 /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param>
81 /// <param name="message">The message to log</param>
82 private void logToDB(string target, string method, string args, int priority, string message)
83 {
84 foreach (ILogDataPlugin plugin in _logplugins)
85 {
86 try
87 {
88 plugin.saveLog("Gridserver", target, method, args, priority, message);
89 }
90 catch (Exception)
91 {
92 m_log.Warn("[storage]: Unable to write log via " + plugin.Name);
93 }
94 }
95 }
96
97 /// <summary>
98 /// Returns a region by argument
99 /// </summary>
100 /// <param name="uuid">A UUID key of the region to return</param>
101 /// <returns>A SimProfileData for the region</returns>
102 public RegionProfileData GetRegion(UUID uuid)
103 {
104 foreach (IGridDataPlugin plugin in _plugins)
105 {
106 try
107 {
108 return plugin.GetProfileByUUID(uuid);
109 }
110 catch (Exception e)
111 {
112 m_log.Warn("[storage]: GetRegion - " + e.Message);
113 }
114 }
115 return null;
116 }
117
118 /// <summary>
119 /// Returns a region by argument
120 /// </summary>
121 /// <param name="uuid">A regionHandle of the region to return</param>
122 /// <returns>A SimProfileData for the region</returns>
123 public RegionProfileData GetRegion(ulong handle)
124 {
125 foreach (IGridDataPlugin plugin in _plugins)
126 {
127 try
128 {
129 return plugin.GetProfileByHandle(handle);
130 }
131 catch (Exception ex)
132 {
133 m_log.Debug("[storage]: " + ex.Message);
134 m_log.Warn("[storage]: Unable to find region " + handle.ToString() + " via " + plugin.Name);
135 }
136 }
137 return null;
138 }
139
140 /// <summary>
141 /// Returns a region by argument
142 /// </summary>
143 /// <param name="regionName">A partial regionName of the region to return</param>
144 /// <returns>A SimProfileData for the region</returns>
145 public RegionProfileData GetRegion(string regionName)
146 {
147 foreach (IGridDataPlugin plugin in _plugins)
148 {
149 try
150 {
151 return plugin.GetProfileByString(regionName);
152 }
153 catch
154 {
155 m_log.Warn("[storage]: Unable to find region " + regionName + " via " + plugin.Name);
156 }
157 }
158 return null;
159 }
160
161 public List<RegionProfileData> GetRegions(uint xmin, uint ymin, uint xmax, uint ymax)
162 {
163 List<RegionProfileData> regions = new List<RegionProfileData>();
164
165 foreach (IGridDataPlugin plugin in _plugins)
166 {
167 try
168 {
169 regions.AddRange(plugin.GetProfilesInRange(xmin, ymin, xmax, ymax));
170 }
171 catch
172 {
173 m_log.Warn("[storage]: Unable to query regionblock via " + plugin.Name);
174 }
175 }
176
177 return regions;
178 }
179
180 public List<RegionProfileData> GetRegions(string name, int maxNum)
181 {
182 List<RegionProfileData> regions = new List<RegionProfileData>();
183 foreach (IGridDataPlugin plugin in _plugins)
184 {
185 try
186 {
187 int num = maxNum - regions.Count;
188 List<RegionProfileData> profiles = plugin.GetRegionsByName(name, (uint)num);
189 if (profiles != null) regions.AddRange(profiles);
190 }
191 catch
192 {
193 m_log.Warn("[storage]: Unable to query regionblock via " + plugin.Name);
194 }
195 }
196
197 return regions;
198 }
199
200 public DataResponse AddUpdateRegion(RegionProfileData sim, RegionProfileData existingSim)
201 {
202 DataResponse insertResponse = DataResponse.RESPONSE_ERROR;
203 foreach (IGridDataPlugin plugin in _plugins)
204 {
205 try
206 {
207 if (existingSim == null)
208 {
209 insertResponse = plugin.StoreProfile(sim);
210 }
211 else
212 {
213 insertResponse = plugin.StoreProfile(sim);
214 }
215 }
216 catch (Exception e)
217 {
218 m_log.Warn("[LOGIN END]: " +
219 "Unable to login region " + sim.ToString() + " via " + plugin.Name);
220 m_log.Warn("[LOGIN END]: " + e.ToString());
221 }
222 }
223 return insertResponse;
224 }
225
226 public DataResponse DeleteRegion(string uuid)
227 {
228 DataResponse insertResponse = DataResponse.RESPONSE_ERROR;
229 foreach (IGridDataPlugin plugin in _plugins)
230 {
231 //OpenSim.Data.MySQL.MySQLGridData dbengine = new OpenSim.Data.MySQL.MySQLGridData();
232 try
233 {
234 //Nice are we not using multiple databases?
235 //MySQLGridData mysqldata = (MySQLGridData)(plugin);
236
237 //DataResponse insertResponse = mysqldata.DeleteProfile(TheSim);
238 insertResponse = plugin.DeleteProfile(uuid);
239 }
240 catch (Exception)
241 {
242 m_log.Error("storage Unable to delete region " + uuid + " via " + plugin.Name);
243 //MainLog.Instance.Warn("storage", e.ToString());
244 insertResponse = DataResponse.RESPONSE_ERROR;
245 }
246 }
247 return insertResponse;
248 }
249
250 public string CheckReservations(RegionProfileData theSim, XmlNode authkeynode)
251 {
252 foreach (IGridDataPlugin plugin in _plugins)
253 {
254 try
255 {
256 //Check reservations
257 ReservationData reserveData =
258 plugin.GetReservationAtPoint(theSim.regionLocX, theSim.regionLocY);
259 if ((reserveData != null && reserveData.gridRecvKey == theSim.regionRecvKey) ||
260 (reserveData == null && authkeynode.InnerText != theSim.regionRecvKey))
261 {
262 plugin.StoreProfile(theSim);
263 m_log.Info("[grid]: New sim added to grid (" + theSim.regionName + ")");
264 logToDB(theSim.ToString(), "RestSetSimMethod", String.Empty, 5,
265 "Region successfully updated and connected to grid.");
266 }
267 else
268 {
269 m_log.Warn("[grid]: " +
270 "Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");
271 // Wanted: " + reserveData.gridRecvKey + ", Got: " + theSim.regionRecvKey + ".");
272 return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
273 }
274 }
275 catch (Exception e)
276 {
277 m_log.Warn("[GRID]: GetRegionPlugin Handle " + plugin.Name + " unable to add new sim: " +
278 e.ToString());
279 }
280 }
281 return "OK";
282 }
283 }
284}