diff options
author | MW | 2007-02-02 17:24:44 +0000 |
---|---|---|
committer | MW | 2007-02-02 17:24:44 +0000 |
commit | a7a1e85da0ee5dd6d57c0bde97bc620a286900a2 (patch) | |
tree | eda37da016e9cef43f74676a7c7d1d95499ecadb /GridManager.cs | |
parent | Clean up. Added GridManager and teleport between regions/sims. (diff) | |
download | opensim-SC_OLD-a7a1e85da0ee5dd6d57c0bde97bc620a286900a2.zip opensim-SC_OLD-a7a1e85da0ee5dd6d57c0bde97bc620a286900a2.tar.gz opensim-SC_OLD-a7a1e85da0ee5dd6d57c0bde97bc620a286900a2.tar.bz2 opensim-SC_OLD-a7a1e85da0ee5dd6d57c0bde97bc620a286900a2.tar.xz |
Fixed missing files
Diffstat (limited to 'GridManager.cs')
-rw-r--r-- | GridManager.cs | 372 |
1 files changed, 372 insertions, 0 deletions
diff --git a/GridManager.cs b/GridManager.cs new file mode 100644 index 0000000..52ac789 --- /dev/null +++ b/GridManager.cs | |||
@@ -0,0 +1,372 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007 Michael Wright | ||
3 | |||
4 | * Copyright (c) <year>, <copyright holder> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using libsecondlife; | ||
33 | using System.Collections; | ||
34 | using libsecondlife.Packets; | ||
35 | using libsecondlife.AssetSystem; | ||
36 | using System.IO; | ||
37 | using System.Xml; | ||
38 | |||
39 | |||
40 | namespace OpenSim | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Description of GridManager. | ||
44 | /// </summary> | ||
45 | public class GridManager | ||
46 | { | ||
47 | private Server server; | ||
48 | private System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
49 | private AgentManager AgentManager; | ||
50 | private Dictionary<ulong,RegionInfo> Grid; | ||
51 | |||
52 | /// <summary> | ||
53 | /// | ||
54 | /// </summary> | ||
55 | /// <param name="serve"></param> | ||
56 | /// <param name="agentManager"></param> | ||
57 | public GridManager(Server serve, AgentManager agentManager) | ||
58 | { | ||
59 | Grid=new Dictionary<ulong, RegionInfo>(); | ||
60 | server=serve; | ||
61 | AgentManager=agentManager; | ||
62 | LoadGrid(); | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | /// <param name="UserInfo"></param> | ||
69 | public void RequestMapLayer(User_Agent_info UserInfo) | ||
70 | { | ||
71 | //send a layer covering the 800,800 - 1200,1200 area | ||
72 | MapLayerReplyPacket MapReply=new MapLayerReplyPacket(); | ||
73 | MapReply.AgentData.AgentID=UserInfo.AgentID; | ||
74 | MapReply.AgentData.Flags=0; | ||
75 | MapReply.LayerData=new MapLayerReplyPacket.LayerDataBlock[1]; | ||
76 | MapReply.LayerData[0]=new MapLayerReplyPacket.LayerDataBlock(); | ||
77 | MapReply.LayerData[0].Bottom=800; | ||
78 | MapReply.LayerData[0].Left=800; | ||
79 | MapReply.LayerData[0].Top=1200; | ||
80 | MapReply.LayerData[0].Right=1200; | ||
81 | MapReply.LayerData[0].ImageID=new LLUUID("00000000-0000-0000-7007-000000000006"); | ||
82 | server.SendPacket(MapReply,true,UserInfo); | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// | ||
87 | /// </summary> | ||
88 | /// <param name="UserInfo"></param> | ||
89 | /// <param name="MinX"></param> | ||
90 | /// <param name="MinY"></param> | ||
91 | /// <param name="MaxX"></param> | ||
92 | /// <param name="MaxY"></param> | ||
93 | public void RequestMapBlock(User_Agent_info UserInfo, int MinX, int MinY,int MaxX,int MaxY) | ||
94 | { | ||
95 | foreach (KeyValuePair<ulong,RegionInfo> RegionPair in this.Grid) | ||
96 | { | ||
97 | //check Region is inside the requested area | ||
98 | RegionInfo Region=RegionPair.Value; | ||
99 | if(((Region.X>MinX) && (Region.X<MaxX)) && ((Region.Y>MinY) && (Region.Y<MaxY))) | ||
100 | { | ||
101 | MapBlockReplyPacket MapReply=new MapBlockReplyPacket(); | ||
102 | MapReply.AgentData.AgentID=UserInfo.AgentID; | ||
103 | MapReply.AgentData.Flags=0; | ||
104 | MapReply.Data=new MapBlockReplyPacket.DataBlock[1]; | ||
105 | MapReply.Data[0]=new MapBlockReplyPacket.DataBlock(); | ||
106 | MapReply.Data[0].MapImageID=Region.ImageID; | ||
107 | MapReply.Data[0].X=Region.X; | ||
108 | MapReply.Data[0].Y=Region.Y; | ||
109 | MapReply.Data[0].WaterHeight=Region.WaterHeight; | ||
110 | MapReply.Data[0].Name=enc.GetBytes( Region.Name); | ||
111 | MapReply.Data[0].RegionFlags=72458694; | ||
112 | MapReply.Data[0].Access=13; | ||
113 | MapReply.Data[0].Agents=1; | ||
114 | server.SendPacket(MapReply,true,UserInfo); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// | ||
122 | /// </summary> | ||
123 | /// <param name="UserInfo"></param> | ||
124 | /// <param name="Request"></param> | ||
125 | public void RequestTeleport(User_Agent_info UserInfo, TeleportLocationRequestPacket Request) | ||
126 | { | ||
127 | if(Grid.ContainsKey(Request.Info.RegionHandle)) | ||
128 | { | ||
129 | RegionInfo Region=Grid[Request.Info.RegionHandle]; | ||
130 | libsecondlife.Packets.TeleportStartPacket TeleportStart=new TeleportStartPacket(); | ||
131 | TeleportStart.Info.TeleportFlags=16; | ||
132 | server.SendPacket(TeleportStart,true,UserInfo); | ||
133 | |||
134 | libsecondlife.Packets.TeleportFinishPacket Teleport=new TeleportFinishPacket(); | ||
135 | Teleport.Info.AgentID=UserInfo.AgentID; | ||
136 | Teleport.Info.RegionHandle=Request.Info.RegionHandle; | ||
137 | Teleport.Info.SimAccess=13; | ||
138 | Teleport.Info.SeedCapability=new byte[0]; | ||
139 | |||
140 | System.Net.IPAddress oIP=System.Net.IPAddress.Parse(Region.IPAddress.Address); | ||
141 | byte[] byteIP=oIP.GetAddressBytes(); | ||
142 | uint ip=(uint)byteIP[3]<<24; | ||
143 | ip+=(uint)byteIP[2]<<16; | ||
144 | ip+=(uint)byteIP[1]<<8; | ||
145 | ip+=(uint)byteIP[0]; | ||
146 | |||
147 | Teleport.Info.SimIP=ip; | ||
148 | Teleport.Info.SimPort=Region.IPAddress.Port; | ||
149 | Teleport.Info.LocationID=4; | ||
150 | Teleport.Info.TeleportFlags= 1 << 4;; | ||
151 | server.SendPacket(Teleport,true,UserInfo); | ||
152 | |||
153 | this.AgentManager.RemoveAgent(UserInfo); | ||
154 | } | ||
155 | |||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// | ||
160 | /// </summary> | ||
161 | private void LoadGrid() | ||
162 | { | ||
163 | //should connect to a space server to see what grids there are | ||
164 | //but for now we read static xml files | ||
165 | ulong CurrentHandle=0; | ||
166 | bool Login=true; | ||
167 | |||
168 | XmlDocument doc = new XmlDocument(); | ||
169 | |||
170 | try { | ||
171 | doc.Load(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"Grid.ini" )); | ||
172 | } | ||
173 | catch ( Exception e) | ||
174 | { | ||
175 | Console.WriteLine(e.Message); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | try | ||
180 | { | ||
181 | XmlNode root = doc.FirstChild; | ||
182 | if (root.Name != "Root") | ||
183 | throw new Exception("Error: Invalid File. Missing <Root>"); | ||
184 | |||
185 | XmlNode nodes = root.FirstChild; | ||
186 | if (nodes.Name != "Grid") | ||
187 | throw new Exception("Error: Invalid File. <project> first child should be <Grid>"); | ||
188 | |||
189 | if (nodes.HasChildNodes) { | ||
190 | foreach( XmlNode xmlnc in nodes.ChildNodes) | ||
191 | { | ||
192 | if(xmlnc.Name=="Region") | ||
193 | { | ||
194 | string xmlAttri; | ||
195 | RegionInfo Region=new RegionInfo(); | ||
196 | if(xmlnc.Attributes["Name"]!=null) | ||
197 | { | ||
198 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("Name")).Value; | ||
199 | Region.Name=xmlAttri+" \0"; | ||
200 | } | ||
201 | if(xmlnc.Attributes["ImageID"]!=null) | ||
202 | { | ||
203 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("ImageID")).Value; | ||
204 | Region.ImageID=new LLUUID(xmlAttri); | ||
205 | } | ||
206 | if(xmlnc.Attributes["IP_Address"]!=null) | ||
207 | { | ||
208 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("IP_Address")).Value; | ||
209 | Region.IPAddress.Address=xmlAttri; | ||
210 | } | ||
211 | if(xmlnc.Attributes["IP_Port"]!=null) | ||
212 | { | ||
213 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("IP_Port")).Value; | ||
214 | Region.IPAddress.Port=Convert.ToUInt16(xmlAttri); | ||
215 | } | ||
216 | if(xmlnc.Attributes["Location_X"]!=null) | ||
217 | { | ||
218 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("Location_X")).Value; | ||
219 | Region.X=Convert.ToUInt16(xmlAttri); | ||
220 | } | ||
221 | if(xmlnc.Attributes["Location_Y"]!=null) | ||
222 | { | ||
223 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("Location_Y")).Value; | ||
224 | Region.Y=Convert.ToUInt16(xmlAttri); | ||
225 | } | ||
226 | |||
227 | this.Grid.Add(Region.Handle,Region); | ||
228 | |||
229 | } | ||
230 | if(xmlnc.Name=="CurrentRegion") | ||
231 | { | ||
232 | |||
233 | string xmlAttri; | ||
234 | uint Rx=0,Ry=0; | ||
235 | if(xmlnc.Attributes["RegionHandle"]!=null) | ||
236 | { | ||
237 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("RegionHandle")).Value; | ||
238 | CurrentHandle=Convert.ToUInt64(xmlAttri); | ||
239 | |||
240 | } | ||
241 | else | ||
242 | { | ||
243 | if(xmlnc.Attributes["Region_X"]!=null) | ||
244 | { | ||
245 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("Region_X")).Value; | ||
246 | Rx=Convert.ToUInt32(xmlAttri); | ||
247 | } | ||
248 | if(xmlnc.Attributes["Region_Y"]!=null) | ||
249 | { | ||
250 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("Region_Y")).Value; | ||
251 | Ry=Convert.ToUInt32(xmlAttri); | ||
252 | } | ||
253 | } | ||
254 | if(xmlnc.Attributes["LoginServer"]!=null) | ||
255 | { | ||
256 | xmlAttri=((XmlAttribute)xmlnc.Attributes.GetNamedItem("LoginServer")).Value; | ||
257 | Login=Convert.ToBoolean(xmlAttri); | ||
258 | |||
259 | } | ||
260 | if(CurrentHandle==0) | ||
261 | { | ||
262 | //no RegionHandle set | ||
263 | //so check for Region X and Y | ||
264 | if((Rx >0) && (Ry>0)) | ||
265 | { | ||
266 | CurrentHandle=Helpers.UIntsToLong((Rx*256),(Ry*256)); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | //seems to be no Region location set | ||
271 | // so set default | ||
272 | CurrentHandle=1096213093147648; | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | //finished loading grid, now set Globals to current region | ||
279 | if(CurrentHandle!=0) | ||
280 | { | ||
281 | if(Grid.ContainsKey(CurrentHandle)) | ||
282 | { | ||
283 | RegionInfo Region=Grid[CurrentHandle]; | ||
284 | Globals.Instance.RegionHandle=Region.Handle; | ||
285 | Globals.Instance.RegionName=Region.Name; | ||
286 | Globals.Instance.IpPort=Region.IPAddress.Port; | ||
287 | Globals.Instance.LoginSever=Login; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | } | ||
292 | } | ||
293 | catch ( Exception e) | ||
294 | { | ||
295 | Console.WriteLine(e.Message); | ||
296 | return; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | |||
301 | public class RegionInfo | ||
302 | { | ||
303 | public RegionIP IPAddress; | ||
304 | public string Name; | ||
305 | public ushort x; | ||
306 | public ushort y; | ||
307 | public ulong handle; | ||
308 | public LLUUID ImageID; | ||
309 | public uint Flags; | ||
310 | public byte WaterHeight; | ||
311 | |||
312 | public ushort X | ||
313 | { | ||
314 | get | ||
315 | { | ||
316 | return(x); | ||
317 | } | ||
318 | set | ||
319 | { | ||
320 | x=value; | ||
321 | Handle=Helpers.UIntsToLong((((uint)x)*256),(((uint)y)*256)); | ||
322 | } | ||
323 | } | ||
324 | public ushort Y | ||
325 | { | ||
326 | get | ||
327 | { | ||
328 | return(y); | ||
329 | } | ||
330 | set | ||
331 | { | ||
332 | y=value; | ||
333 | Handle=Helpers.UIntsToLong((((uint)x)*256),(((uint)y)*256)); | ||
334 | } | ||
335 | } | ||
336 | public ulong Handle | ||
337 | { | ||
338 | get | ||
339 | { | ||
340 | if(handle>0) | ||
341 | { | ||
342 | return(handle); | ||
343 | } | ||
344 | else | ||
345 | { | ||
346 | return(Helpers.UIntsToLong((((uint)x)*256),(((uint)y)*256))); | ||
347 | } | ||
348 | } | ||
349 | set | ||
350 | { | ||
351 | handle=value; | ||
352 | } | ||
353 | |||
354 | } | ||
355 | |||
356 | public RegionInfo() | ||
357 | { | ||
358 | this.IPAddress=new RegionIP(); | ||
359 | } | ||
360 | } | ||
361 | public class RegionIP | ||
362 | { | ||
363 | public string Address; | ||
364 | public ushort Port; | ||
365 | |||
366 | public RegionIP() | ||
367 | { | ||
368 | |||
369 | } | ||
370 | |||
371 | } | ||
372 | } | ||