aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService
diff options
context:
space:
mode:
authorMelanie2009-10-02 08:23:38 +0100
committerMelanie2009-10-02 08:23:38 +0100
commit31d8cec0f8cd47ff445edc7771e5e73825a57927 (patch)
treea2d60604317739fa530502c40ffc71bab2a5c494 /OpenSim/Services/GridService
parentRestore the missing image handling to the image manager. The missing (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-31d8cec0f8cd47ff445edc7771e5e73825a57927.zip
opensim-SC_OLD-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.gz
opensim-SC_OLD-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.bz2
opensim-SC_OLD-31d8cec0f8cd47ff445edc7771e5e73825a57927.tar.xz
Merge branch 'master' into diva-textures
Diffstat (limited to 'OpenSim/Services/GridService')
-rw-r--r--OpenSim/Services/GridService/GridService.cs199
-rw-r--r--OpenSim/Services/GridService/GridServiceBase.cs84
2 files changed, 283 insertions, 0 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
new file mode 100644
index 0000000..991acf2
--- /dev/null
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -0,0 +1,199 @@
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 GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenMetaverse;
40
41namespace OpenSim.Services.GridService
42{
43 public class GridService : GridServiceBase, IGridService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 public GridService(IConfigSource config)
50 : base(config)
51 {
52 m_log.DebugFormat("[GRID SERVICE]: Starting...");
53 }
54
55 #region IGridService
56
57 public bool RegisterRegion(UUID scopeID, GridRegion regionInfos)
58 {
59 // This needs better sanity testing. What if regionInfo is registering in
60 // overlapping coords?
61 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
62 if ((region != null) && (region.RegionID != regionInfos.RegionID))
63 {
64 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
65 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
66 return false;
67 }
68 if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
69 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY)))
70 {
71 // Region reregistering in other coordinates. Delete the old entry
72 m_Database.Delete(regionInfos.RegionID);
73 }
74
75 // Everything is ok, let's register
76 RegionData rdata = RegionInfo2RegionData(regionInfos);
77 rdata.ScopeID = scopeID;
78 m_Database.Store(rdata);
79 return true;
80 }
81
82 public bool DeregisterRegion(UUID regionID)
83 {
84 return m_Database.Delete(regionID);
85 }
86
87 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
88 {
89 List<GridRegion> rinfos = new List<GridRegion>();
90 RegionData region = m_Database.Get(regionID, scopeID);
91 if (region != null)
92 {
93 // Not really? Maybe?
94 List<RegionData> rdatas = m_Database.Get(region.posX - (int)Constants.RegionSize, region.posY - (int)Constants.RegionSize,
95 region.posX + (int)Constants.RegionSize, region.posY + (int)Constants.RegionSize, scopeID);
96
97 foreach (RegionData rdata in rdatas)
98 if (rdata.RegionID != regionID)
99 rinfos.Add(RegionData2RegionInfo(rdata));
100
101 }
102 return rinfos;
103 }
104
105 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
106 {
107 RegionData rdata = m_Database.Get(regionID, scopeID);
108 if (rdata != null)
109 return RegionData2RegionInfo(rdata);
110
111 return null;
112 }
113
114 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
115 {
116 int snapX = (int)(x / Constants.RegionSize) * (int)Constants.RegionSize;
117 int snapY = (int)(y / Constants.RegionSize) * (int)Constants.RegionSize;
118 RegionData rdata = m_Database.Get(snapX, snapY, scopeID);
119 if (rdata != null)
120 return RegionData2RegionInfo(rdata);
121
122 return null;
123 }
124
125 public GridRegion GetRegionByName(UUID scopeID, string regionName)
126 {
127 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
128 if ((rdatas != null) && (rdatas.Count > 0))
129 return RegionData2RegionInfo(rdatas[0]); // get the first
130
131 return null;
132 }
133
134 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
135 {
136 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
137
138 int count = 0;
139 List<GridRegion> rinfos = new List<GridRegion>();
140
141 if (rdatas != null)
142 {
143 foreach (RegionData rdata in rdatas)
144 {
145 if (count++ < maxNumber)
146 rinfos.Add(RegionData2RegionInfo(rdata));
147 }
148 }
149
150 return rinfos;
151 }
152
153 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
154 {
155 int xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
156 int xmaxSnap = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
157 int yminSnap = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
158 int ymaxSnap = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
159
160 List<RegionData> rdatas = m_Database.Get(xminSnap, yminSnap, xmaxSnap, ymaxSnap, scopeID);
161 List<GridRegion> rinfos = new List<GridRegion>();
162 foreach (RegionData rdata in rdatas)
163 rinfos.Add(RegionData2RegionInfo(rdata));
164
165 return rinfos;
166 }
167
168 #endregion
169
170 #region Data structure conversions
171
172 protected RegionData RegionInfo2RegionData(GridRegion rinfo)
173 {
174 RegionData rdata = new RegionData();
175 rdata.posX = (int)rinfo.RegionLocX;
176 rdata.posY = (int)rinfo.RegionLocY;
177 rdata.RegionID = rinfo.RegionID;
178 rdata.RegionName = rinfo.RegionName;
179 rdata.Data = rinfo.ToKeyValuePairs();
180 rdata.Data["regionHandle"] = Utils.UIntsToLong((uint)rdata.posX, (uint)rdata.posY);
181 return rdata;
182 }
183
184 protected GridRegion RegionData2RegionInfo(RegionData rdata)
185 {
186 GridRegion rinfo = new GridRegion(rdata.Data);
187 rinfo.RegionLocX = rdata.posX;
188 rinfo.RegionLocY = rdata.posY;
189 rinfo.RegionID = rdata.RegionID;
190 rinfo.RegionName = rdata.RegionName;
191 rinfo.ScopeID = rdata.ScopeID;
192
193 return rinfo;
194 }
195
196 #endregion
197
198 }
199}
diff --git a/OpenSim/Services/GridService/GridServiceBase.cs b/OpenSim/Services/GridService/GridServiceBase.cs
new file mode 100644
index 0000000..444f79b
--- /dev/null
+++ b/OpenSim/Services/GridService/GridServiceBase.cs
@@ -0,0 +1,84 @@
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.Reflection;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base;
35
36namespace OpenSim.Services.GridService
37{
38 public class GridServiceBase : ServiceBase
39 {
40 protected IRegionData m_Database = null;
41
42 public GridServiceBase(IConfigSource config)
43 : base(config)
44 {
45 string dllName = String.Empty;
46 string connString = String.Empty;
47 string realm = "regions";
48
49 //
50 // Try reading the [DatabaseService] section, if it exists
51 //
52 IConfig dbConfig = config.Configs["DatabaseService"];
53 if (dbConfig != null)
54 {
55 if (dllName == String.Empty)
56 dllName = dbConfig.GetString("StorageProvider", String.Empty);
57 if (connString == String.Empty)
58 connString = dbConfig.GetString("ConnectionString", String.Empty);
59 }
60
61 //
62 // [GridService] section overrides [DatabaseService], if it exists
63 //
64 IConfig gridConfig = config.Configs["GridService"];
65 if (gridConfig != null)
66 {
67 dllName = gridConfig.GetString("StorageProvider", dllName);
68 connString = gridConfig.GetString("ConnectionString", connString);
69 realm = gridConfig.GetString("Realm", realm);
70 }
71
72 //
73 // We tried, but this doesn't exist. We can't proceed.
74 //
75 if (dllName.Equals(String.Empty))
76 throw new Exception("No StorageProvider configured");
77
78 m_Database = LoadPlugin<IRegionData>(dllName, new Object[] { connString, realm });
79 if (m_Database == null)
80 throw new Exception("Could not find a storage interface in the given module");
81
82 }
83 }
84}