aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer/GridDBService.cs
diff options
context:
space:
mode:
authorMW2009-02-21 13:44:03 +0000
committerMW2009-02-21 13:44:03 +0000
commit25661b611d241534e5e8d7ce1731de8506481a7d (patch)
treed61ae89bcb909225c6aef295bf6bddb21668b718 /OpenSim/Grid/GridServer/GridDBService.cs
parentAllow entry of '?' in http URIs. If the field being typed begins with (diff)
downloadopensim-SC-25661b611d241534e5e8d7ce1731de8506481a7d.zip
opensim-SC-25661b611d241534e5e8d7ce1731de8506481a7d.tar.gz
opensim-SC-25661b611d241534e5e8d7ce1731de8506481a7d.tar.bz2
opensim-SC-25661b611d241534e5e8d7ce1731de8506481a7d.tar.xz
Refactored the GridServer into a GridDBService and a set of "modules".
Currently they aren't plugin modules as the support for dynamically loading them isn't complete.
Diffstat (limited to 'OpenSim/Grid/GridServer/GridDBService.cs')
-rw-r--r--OpenSim/Grid/GridServer/GridDBService.cs303
1 files changed, 303 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/GridDBService.cs b/OpenSim/Grid/GridServer/GridDBService.cs
new file mode 100644
index 0000000..389cf69
--- /dev/null
+++ b/OpenSim/Grid/GridServer/GridDBService.cs
@@ -0,0 +1,303 @@
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 OpenSim 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
44{
45 public class GridDBService
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 void LoginRegion(RegionProfileData sim, RegionProfileData existingSim)
201 {
202 foreach (IGridDataPlugin plugin in _plugins)
203 {
204 try
205 {
206 DataResponse insertResponse;
207
208 if (existingSim == null)
209 {
210 insertResponse = plugin.AddProfile(sim);
211 }
212 else
213 {
214 insertResponse = plugin.UpdateProfile(sim);
215 }
216
217 switch (insertResponse)
218 {
219 case DataResponse.RESPONSE_OK:
220 m_log.Info("[LOGIN END]: " + (existingSim == null ? "New" : "Existing") + " sim login successful: " + sim.regionName);
221 break;
222 case DataResponse.RESPONSE_ERROR:
223 m_log.Warn("[LOGIN END]: Sim login failed (Error): " + sim.regionName);
224 break;
225 case DataResponse.RESPONSE_INVALIDCREDENTIALS:
226 m_log.Warn("[LOGIN END]: " +
227 "Sim login failed (Invalid Credentials): " + sim.regionName);
228 break;
229 case DataResponse.RESPONSE_AUTHREQUIRED:
230 m_log.Warn("[LOGIN END]: " +
231 "Sim login failed (Authentication Required): " +
232 sim.regionName);
233 break;
234 }
235 }
236 catch (Exception e)
237 {
238 m_log.Warn("[LOGIN END]: " +
239 "Unable to login region " + sim.ToString() + " via " + plugin.Name);
240 m_log.Warn("[LOGIN END]: " + e.ToString());
241 }
242 }
243 }
244
245 public DataResponse DeleteRegion(string uuid)
246 {
247 DataResponse insertResponse = DataResponse.RESPONSE_ERROR;
248 foreach (IGridDataPlugin plugin in _plugins)
249 {
250 //OpenSim.Data.MySQL.MySQLGridData dbengine = new OpenSim.Data.MySQL.MySQLGridData();
251 try
252 {
253 //Nice are we not using multiple databases?
254 //MySQLGridData mysqldata = (MySQLGridData)(plugin);
255
256 //DataResponse insertResponse = mysqldata.DeleteProfile(TheSim);
257 insertResponse = plugin.DeleteProfile(uuid);
258 }
259 catch (Exception)
260 {
261 m_log.Error("storage Unable to delete region " + uuid + " via " + plugin.Name);
262 //MainLog.Instance.Warn("storage", e.ToString());
263 insertResponse = DataResponse.RESPONSE_ERROR;
264 }
265 }
266 return insertResponse;
267 }
268
269 public string CheckReservations(RegionProfileData theSim, XmlNode authkeynode)
270 {
271 foreach (IGridDataPlugin plugin in _plugins)
272 {
273 try
274 {
275 //Check reservations
276 ReservationData reserveData =
277 plugin.GetReservationAtPoint(theSim.regionLocX, theSim.regionLocY);
278 if ((reserveData != null && reserveData.gridRecvKey == theSim.regionRecvKey) ||
279 (reserveData == null && authkeynode.InnerText != theSim.regionRecvKey))
280 {
281 plugin.AddProfile(theSim);
282 m_log.Info("[grid]: New sim added to grid (" + theSim.regionName + ")");
283 logToDB(theSim.ToString(), "RestSetSimMethod", String.Empty, 5,
284 "Region successfully updated and connected to grid.");
285 }
286 else
287 {
288 m_log.Warn("[grid]: " +
289 "Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");
290 // Wanted: " + reserveData.gridRecvKey + ", Got: " + theSim.regionRecvKey + ".");
291 return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
292 }
293 }
294 catch (Exception e)
295 {
296 m_log.Warn("[GRID]: GetRegionPlugin Handle " + plugin.Name + " unable to add new sim: " +
297 e.ToString());
298 }
299 }
300 return "OK";
301 }
302 }
303}