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.cs202
1 files changed, 52 insertions, 150 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 6aa1c4f..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,17 +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, int x, int y) 87 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
92 { 88 {
93 List<RegionData> rdatas = m_Database.Get(x - 1, y - 1, x + 1, y + 1, scopeID); 89 List<GridRegion> rinfos = new List<GridRegion>();
94 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 90 RegionData region = m_Database.Get(regionID, scopeID);
95 foreach (RegionData rdata in rdatas) 91 if (region != null)
96 rinfos.Add(RegionData2RegionInfo(rdata)); 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));
97 100
101 }
98 return rinfos; 102 return rinfos;
99 } 103 }
100 104
101 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 105 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
102 { 106 {
103 RegionData rdata = m_Database.Get(regionID, scopeID); 107 RegionData rdata = m_Database.Get(regionID, scopeID);
104 if (rdata != null) 108 if (rdata != null)
@@ -107,16 +111,18 @@ namespace OpenSim.Services.GridService
107 return null; 111 return null;
108 } 112 }
109 113
110 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) 114 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
111 { 115 {
112 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);
113 if (rdata != null) 119 if (rdata != null)
114 return RegionData2RegionInfo(rdata); 120 return RegionData2RegionInfo(rdata);
115 121
116 return null; 122 return null;
117 } 123 }
118 124
119 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) 125 public GridRegion GetRegionByName(UUID scopeID, string regionName)
120 { 126 {
121 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID); 127 List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
122 if ((rdatas != null) && (rdatas.Count > 0)) 128 if ((rdatas != null) && (rdatas.Count > 0))
@@ -125,12 +131,12 @@ namespace OpenSim.Services.GridService
125 return null; 131 return null;
126 } 132 }
127 133
128 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) 134 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
129 { 135 {
130 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID); 136 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
131 137
132 int count = 0; 138 int count = 0;
133 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 139 List<GridRegion> rinfos = new List<GridRegion>();
134 140
135 if (rdatas != null) 141 if (rdatas != null)
136 { 142 {
@@ -144,10 +150,15 @@ namespace OpenSim.Services.GridService
144 return rinfos; 150 return rinfos;
145 } 151 }
146 152
147 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)
148 { 154 {
149 List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID); 155 int xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
150 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>();
151 foreach (RegionData rdata in rdatas) 162 foreach (RegionData rdata in rdatas)
152 rinfos.Add(RegionData2RegionInfo(rdata)); 163 rinfos.Add(RegionData2RegionInfo(rdata));
153 164
@@ -158,140 +169,31 @@ namespace OpenSim.Services.GridService
158 169
159 #region Data structure conversions 170 #region Data structure conversions
160 171
161 protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo) 172 protected RegionData RegionInfo2RegionData(GridRegion rinfo)
162 { 173 {
163 RegionData rdata = new RegionData(); 174 RegionData rdata = new RegionData();
164 rdata.posX = (int)rinfo.RegionLocX; 175 rdata.posX = (int)rinfo.RegionLocX;
165 rdata.posY = (int)rinfo.RegionLocY; 176 rdata.posY = (int)rinfo.RegionLocY;
166 rdata.RegionID = rinfo.RegionID; 177 rdata.RegionID = rinfo.RegionID;
167 //rdata.RegionName = rinfo.RegionName; 178 rdata.RegionName = rinfo.RegionName;
168 rdata.Data["external_ip_address"] = rinfo.ExternalEndPoint.Address.ToString(); 179 rdata.Data = rinfo.ToKeyValuePairs();
169 rdata.Data["external_port"] = rinfo.ExternalEndPoint.Port.ToString(); 180 rdata.Data["regionHandle"] = Utils.UIntsToLong((uint)rdata.posX, (uint)rdata.posY);
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; 181 return rdata;
178 } 182 }
179 183
180 protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata) 184 protected GridRegion RegionData2RegionInfo(RegionData rdata)
181 { 185 {
182 SimpleRegionInfo rinfo = new SimpleRegionInfo(); 186 GridRegion rinfo = new GridRegion(rdata.Data);
183 rinfo.RegionLocX = (uint)rdata.posX; 187 rinfo.RegionLocX = rdata.posX;
184 rinfo.RegionLocY = (uint)rdata.posY; 188 rinfo.RegionLocY = rdata.posY;
185 rinfo.RegionID = rdata.RegionID; 189 rinfo.RegionID = rdata.RegionID;
186 //rinfo.RegionName = rdata.RegionName; 190 rinfo.RegionName = rdata.RegionName;
187 191 rinfo.ScopeID = rdata.ScopeID;
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 192
229 return rinfo; 193 return rinfo;
230 } 194 }
231 195
232 #endregion 196 #endregion
233 197
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 } 198 }
297} 199}