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.cs145
1 files changed, 45 insertions, 100 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 2229421..991acf2 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using OpenMetaverse; 39using OpenMetaverse;
39 40
40namespace OpenSim.Services.GridService 41namespace OpenSim.Services.GridService
@@ -48,33 +49,28 @@ namespace OpenSim.Services.GridService
48 public GridService(IConfigSource config) 49 public GridService(IConfigSource config)
49 : base(config) 50 : base(config)
50 { 51 {
51 MainConsole.Instance.Commands.AddCommand("kfs", false, 52 m_log.DebugFormat("[GRID SERVICE]: Starting...");
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 } 53 }
62 54
63 #region IGridService 55 #region IGridService
64 56
65 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos) 57 public bool RegisterRegion(UUID scopeID, GridRegion regionInfos)
66 { 58 {
67 if (m_Database.Get(regionInfos.RegionID, scopeID) != null) 59 // This needs better sanity testing. What if regionInfo is registering in
68 { 60 // overlapping coords?
69 m_log.WarnFormat("[GRID SERVICE]: Region {0} already registered in scope {1}.", regionInfos.RegionID, scopeID); 61 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
70 return false; 62 if ((region != null) && (region.RegionID != regionInfos.RegionID))
71 }
72 if (m_Database.Get((int)regionInfos.RegionLocX, (int)regionInfos.RegionLocY, scopeID) != null)
73 { 63 {
74 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 64 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); 65 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
76 return false; 66 return false;
77 } 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 }
78 74
79 // Everything is ok, let's register 75 // Everything is ok, let's register
80 RegionData rdata = RegionInfo2RegionData(regionInfos); 76 RegionData rdata = RegionInfo2RegionData(regionInfos);
@@ -88,22 +84,25 @@ namespace OpenSim.Services.GridService
88 return m_Database.Delete(regionID); 84 return m_Database.Delete(regionID);
89 } 85 }
90 86
91 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) 87 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
92 { 88 {
93 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 89 List<GridRegion> rinfos = new List<GridRegion>();
94 RegionData region = m_Database.Get(regionID, scopeID); 90 RegionData region = m_Database.Get(regionID, scopeID);
95 if (region != null) 91 if (region != null)
96 { 92 {
97 // Not really? Maybe? 93 // Not really? Maybe?
98 List<RegionData> rdatas = m_Database.Get(region.posX - 1, region.posY - 1, region.posX + 1, region.posY + 1, scopeID); 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
99 foreach (RegionData rdata in rdatas) 97 foreach (RegionData rdata in rdatas)
100 rinfos.Add(RegionData2RegionInfo(rdata)); 98 if (rdata.RegionID != regionID)
99 rinfos.Add(RegionData2RegionInfo(rdata));
101 100
102 } 101 }
103 return rinfos; 102 return rinfos;
104 } 103 }
105 104
106 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 105 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
107 { 106 {
108 RegionData rdata = m_Database.Get(regionID, scopeID); 107 RegionData rdata = m_Database.Get(regionID, scopeID);
109 if (rdata != null) 108 if (rdata != null)
@@ -112,16 +111,18 @@ namespace OpenSim.Services.GridService
112 return null; 111 return null;
113 } 112 }
114 113
115 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) 114 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
116 { 115 {
117 RegionData rdata = m_Database.Get(x, y, scopeID); 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);
118 if (rdata != null) 119 if (rdata != null)
119 return RegionData2RegionInfo(rdata); 120 return RegionData2RegionInfo(rdata);
120 121
121 return null; 122 return null;
122 } 123 }
123 124
124 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) 125 public GridRegion GetRegionByName(UUID scopeID, string regionName)
125 { 126 {
126 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID); 127 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
127 if ((rdatas != null) && (rdatas.Count > 0)) 128 if ((rdatas != null) && (rdatas.Count > 0))
@@ -130,12 +131,12 @@ namespace OpenSim.Services.GridService
130 return null; 131 return null;
131 } 132 }
132 133
133 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) 134 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
134 { 135 {
135 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID); 136 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
136 137
137 int count = 0; 138 int count = 0;
138 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 139 List<GridRegion> rinfos = new List<GridRegion>();
139 140
140 if (rdatas != null) 141 if (rdatas != null)
141 { 142 {
@@ -149,10 +150,15 @@ namespace OpenSim.Services.GridService
149 return rinfos; 150 return rinfos;
150 } 151 }
151 152
152 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) 153 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
153 { 154 {
154 List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID); 155 int xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
155 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 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>();
156 foreach (RegionData rdata in rdatas) 162 foreach (RegionData rdata in rdatas)
157 rinfos.Add(RegionData2RegionInfo(rdata)); 163 rinfos.Add(RegionData2RegionInfo(rdata));
158 164
@@ -163,92 +169,31 @@ namespace OpenSim.Services.GridService
163 169
164 #region Data structure conversions 170 #region Data structure conversions
165 171
166 protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo) 172 protected RegionData RegionInfo2RegionData(GridRegion rinfo)
167 { 173 {
168 RegionData rdata = new RegionData(); 174 RegionData rdata = new RegionData();
169 rdata.posX = (int)rinfo.RegionLocX; 175 rdata.posX = (int)rinfo.RegionLocX;
170 rdata.posY = (int)rinfo.RegionLocY; 176 rdata.posY = (int)rinfo.RegionLocY;
171 rdata.RegionID = rinfo.RegionID; 177 rdata.RegionID = rinfo.RegionID;
178 rdata.RegionName = rinfo.RegionName;
172 rdata.Data = rinfo.ToKeyValuePairs(); 179 rdata.Data = rinfo.ToKeyValuePairs();
173 //rdata.RegionName = rinfo.RegionName; 180 rdata.Data["regionHandle"] = Utils.UIntsToLong((uint)rdata.posX, (uint)rdata.posY);
174
175 return rdata; 181 return rdata;
176 } 182 }
177 183
178 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) 184 protected GridRegion RegionData2RegionInfo(RegionData rdata)
179 { 185 {
180 SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data); 186 GridRegion rinfo = new GridRegion(rdata.Data);
181 rinfo.RegionLocX = (uint)rdata.posX; 187 rinfo.RegionLocX = rdata.posX;
182 rinfo.RegionLocY = (uint)rdata.posY; 188 rinfo.RegionLocY = rdata.posY;
183 rinfo.RegionID = rdata.RegionID; 189 rinfo.RegionID = rdata.RegionID;
184 //rinfo.RegionName = rdata.RegionName; 190 rinfo.RegionName = rdata.RegionName;
191 rinfo.ScopeID = rdata.ScopeID;
185 192
186 return rinfo; 193 return rinfo;
187 } 194 }
188 195
189 #endregion 196 #endregion
190 197
191 void HandleShowDigest(string module, string[] args)
192 {
193 //if (args.Length < 3)
194 //{
195 // MainConsole.Instance.Output("Syntax: show digest <ID>");
196 // return;
197 //}
198
199 //AssetBase asset = Get(args[2]);
200
201 //if (asset == null || asset.Data.Length == 0)
202 //{
203 // MainConsole.Instance.Output("Asset not found");
204 // return;
205 //}
206
207 //int i;
208
209 //MainConsole.Instance.Output(String.Format("Name: {0}", asset.Name));
210 //MainConsole.Instance.Output(String.Format("Description: {0}", asset.Description));
211 //MainConsole.Instance.Output(String.Format("Type: {0}", asset.Type));
212 //MainConsole.Instance.Output(String.Format("Content-type: {0}", asset.Metadata.ContentType));
213
214 //for (i = 0 ; i < 5 ; i++)
215 //{
216 // int off = i * 16;
217 // if (asset.Data.Length <= off)
218 // break;
219 // int len = 16;
220 // if (asset.Data.Length < off + len)
221 // len = asset.Data.Length - off;
222
223 // byte[] line = new byte[len];
224 // Array.Copy(asset.Data, off, line, 0, len);
225
226 // string text = BitConverter.ToString(line);
227 // MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text));
228 //}
229 }
230
231 void HandleDeleteAsset(string module, string[] args)
232 {
233 //if (args.Length < 3)
234 //{
235 // MainConsole.Instance.Output("Syntax: delete asset <ID>");
236 // return;
237 //}
238
239 //AssetBase asset = Get(args[2]);
240
241 //if (asset == null || asset.Data.Length == 0)
242 // MainConsole.Instance.Output("Asset not found");
243 // return;
244 //}
245
246 //Delete(args[2]);
247
248 ////MainConsole.Instance.Output("Asset deleted");
249 //// TODO: Implement this
250
251 //MainConsole.Instance.Output("Asset deletion not supported by database");
252 }
253 } 198 }
254} 199}