diff options
Diffstat (limited to 'src/Prim_manager.cs')
-rw-r--r-- | src/Prim_manager.cs | 382 |
1 files changed, 382 insertions, 0 deletions
diff --git a/src/Prim_manager.cs b/src/Prim_manager.cs new file mode 100644 index 0000000..72eae35 --- /dev/null +++ b/src/Prim_manager.cs | |||
@@ -0,0 +1,382 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | * All rights reserved. | ||
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 <organization> 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 <copyright holder> ``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 <copyright holder> 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using libsecondlife; | ||
31 | using libsecondlife.Packets; | ||
32 | using libsecondlife.AssetSystem; | ||
33 | using System.IO; | ||
34 | using Axiom.MathLib; | ||
35 | |||
36 | namespace OpenSim | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Description of Prim_manager. | ||
40 | /// </summary> | ||
41 | public class PrimManager | ||
42 | { | ||
43 | private Server _server; | ||
44 | private uint _primCount; | ||
45 | |||
46 | public AgentManager AgentManagement; | ||
47 | public libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock PrimTemplate; | ||
48 | public Dictionary<libsecondlife.LLUUID,PrimInfo> PrimList; | ||
49 | |||
50 | /// <summary> | ||
51 | /// | ||
52 | /// </summary> | ||
53 | /// <param name="serve"></param> | ||
54 | public PrimManager(Server server) | ||
55 | { | ||
56 | _server = server; | ||
57 | PrimList = new Dictionary<libsecondlife.LLUUID,PrimInfo> (); | ||
58 | //this.SetupTemplates("objectupate164.dat"); | ||
59 | |||
60 | } | ||
61 | |||
62 | /// <summary> | ||
63 | /// | ||
64 | /// </summary> | ||
65 | /// <param name="User_info"></param> | ||
66 | /// <param name="p1"></param> | ||
67 | /// <param name="add_pack"></param> | ||
68 | public void CreatePrim(UserAgentInfo userInfo, libsecondlife.LLVector3 pos1, ObjectAddPacket addPacket) | ||
69 | { | ||
70 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
71 | objupdate.RegionData.RegionHandle = Globals.Instance.RegionHandle; | ||
72 | objupdate.RegionData.TimeDilation = 64096; | ||
73 | |||
74 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
75 | PrimData PData = new PrimData(); | ||
76 | objupdate.ObjectData[0] = this.PrimTemplate; | ||
77 | PData.OwnerID=objupdate.ObjectData[0].OwnerID = userInfo.AgentID; | ||
78 | PData.PCode=objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode; | ||
79 | PData.PathBegin=objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin; | ||
80 | PData.PathEnd=objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd; | ||
81 | PData.PathScaleX=objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX; | ||
82 | PData.PathScaleY=objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY; | ||
83 | PData.PathShearX=objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX; | ||
84 | PData.PathShearY=objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY; | ||
85 | PData.PathSkew=objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew; | ||
86 | PData.ProfileBegin=objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin; | ||
87 | PData.ProfileEnd=objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd; | ||
88 | PData.Scale=objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale; | ||
89 | PData.PathCurve=objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve; | ||
90 | PData.ProfileCurve=objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve; | ||
91 | PData.ParentID=objupdate.ObjectData[0].ParentID = 0; | ||
92 | PData.ProfileHollow=objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow; | ||
93 | //finish off copying rest of shape data | ||
94 | |||
95 | objupdate.ObjectData[0].ID = (uint)(702000 + _primCount); | ||
96 | objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efefda"+_primCount.ToString("000")); | ||
97 | |||
98 | //update position | ||
99 | byte[] pb = pos1.GetBytes(); | ||
100 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); | ||
101 | |||
102 | _primCount++; | ||
103 | _server.SendPacket(objupdate, true, userInfo); | ||
104 | |||
105 | //should send to all users | ||
106 | foreach (KeyValuePair<libsecondlife.LLUUID, AvatarData> kp in AgentManagement.AgentList) | ||
107 | { | ||
108 | if(kp.Value.NetInfo.AgentID != userInfo.AgentID) | ||
109 | { | ||
110 | _server.SendPacket(objupdate, true, kp.Value.NetInfo); | ||
111 | } | ||
112 | } | ||
113 | //should store this infomation | ||
114 | PrimInfo NewPrim = new PrimInfo(); | ||
115 | NewPrim.FullID = objupdate.ObjectData[0].FullID; | ||
116 | NewPrim.LocalID = objupdate.ObjectData[0].ID; | ||
117 | NewPrim.Position = pos1; | ||
118 | NewPrim.Data = PData; | ||
119 | |||
120 | this.PrimList.Add(NewPrim.FullID, NewPrim); | ||
121 | |||
122 | //store rest of data | ||
123 | |||
124 | } | ||
125 | |||
126 | /// <summary> | ||
127 | /// | ||
128 | /// </summary> | ||
129 | /// <param name="User"></param> | ||
130 | /// <param name="position"></param> | ||
131 | /// <param name="LocalID"></param> | ||
132 | /// <param name="setRotation"></param> | ||
133 | /// <param name="rotation"></param> | ||
134 | public void UpdatePrimPosition(UserAgentInfo userInfo, LLVector3 position, uint localID, bool setRotation, LLQuaternion rotation) | ||
135 | { | ||
136 | PrimInfo pri = null; | ||
137 | foreach (KeyValuePair<libsecondlife.LLUUID,PrimInfo> kp in this.PrimList) | ||
138 | { | ||
139 | if(kp.Value.LocalID == localID) | ||
140 | { | ||
141 | pri = kp.Value; | ||
142 | } | ||
143 | } | ||
144 | if(pri == null) | ||
145 | { | ||
146 | return; | ||
147 | } | ||
148 | uint ID = pri.LocalID; | ||
149 | libsecondlife.LLVector3 pos2 = new LLVector3(position.X, position.Y, position.Z); | ||
150 | libsecondlife.LLQuaternion rotation2; | ||
151 | if(!setRotation) | ||
152 | { | ||
153 | pri.Position = pos2; | ||
154 | rotation2 = new LLQuaternion(pri.Rotation.X, pri.Rotation.Y, pri.Rotation.Z, pri.Rotation.W); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | rotation2=new LLQuaternion(rotation.X, rotation.Y, rotation.Z, rotation.W); | ||
159 | pos2 = pri.Position; | ||
160 | pri.Rotation = rotation; | ||
161 | } | ||
162 | rotation2.W += 1; | ||
163 | rotation2.X += 1; | ||
164 | rotation2.Y += 1; | ||
165 | rotation2.Z += 1; | ||
166 | |||
167 | byte[] bytes = new byte[60]; | ||
168 | |||
169 | ImprovedTerseObjectUpdatePacket im = new ImprovedTerseObjectUpdatePacket(); | ||
170 | im.RegionData.RegionHandle = Globals.Instance.RegionHandle; | ||
171 | im.RegionData.TimeDilation = 64096; | ||
172 | im.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
173 | int i = 0; | ||
174 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
175 | im.ObjectData[0] = dat; | ||
176 | dat.TextureEntry = PrimTemplate.TextureEntry; | ||
177 | |||
178 | bytes[i++] = (byte)(ID % 256); | ||
179 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
180 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
181 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
182 | bytes[i++]= 0; | ||
183 | bytes[i++]= 0; | ||
184 | |||
185 | byte[] pb = pos2.GetBytes(); | ||
186 | pri.Position = pos2; | ||
187 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
188 | i += 12; | ||
189 | ushort ac = 32767; | ||
190 | |||
191 | //vel | ||
192 | bytes[i++] = (byte)(ac % 256); | ||
193 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
194 | bytes[i++] = (byte)(ac % 256); | ||
195 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
196 | bytes[i++] = (byte)(ac % 256); | ||
197 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
198 | |||
199 | //accel | ||
200 | bytes[i++] = (byte)(ac % 256); | ||
201 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
202 | bytes[i++] = (byte)(ac % 256); | ||
203 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
204 | bytes[i++] = (byte)(ac % 256); | ||
205 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
206 | |||
207 | ushort rw, rx,ry,rz; | ||
208 | rw = (ushort)(32768 * rotation2.W); | ||
209 | rx = (ushort)(32768 * rotation2.X); | ||
210 | ry = (ushort)(32768 * rotation2.Y); | ||
211 | rz = (ushort)(32768 * rotation2.Z); | ||
212 | |||
213 | //rot | ||
214 | bytes[i++] = (byte)(rx % 256); | ||
215 | bytes[i++] = (byte)((rx >> 8) % 256); | ||
216 | bytes[i++] = (byte)(ry % 256); | ||
217 | bytes[i++] = (byte)((ry >> 8) % 256); | ||
218 | bytes[i++] = (byte)(rz % 256); | ||
219 | bytes[i++] = (byte)((rz >> 8) % 256); | ||
220 | bytes[i++] = (byte)(rw % 256); | ||
221 | bytes[i++] = (byte)((rw >> 8) % 256); | ||
222 | |||
223 | //rotation vel | ||
224 | bytes[i++] = (byte)(ac % 256); | ||
225 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
226 | bytes[i++] = (byte)(ac % 256); | ||
227 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
228 | bytes[i++] = (byte)(ac % 256); | ||
229 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
230 | |||
231 | dat.Data=bytes; | ||
232 | |||
233 | foreach (KeyValuePair<libsecondlife.LLUUID,AvatarData> kp in AgentManagement.AgentList) | ||
234 | { | ||
235 | if(kp.Value.NetInfo.AgentID!=userInfo.AgentID) | ||
236 | { | ||
237 | _server.SendPacket(im, true, kp.Value.NetInfo); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | /// <summary> | ||
243 | /// | ||
244 | /// </summary> | ||
245 | /// <param name="user"></param> | ||
246 | public void SendExistingPrims(UserAgentInfo userInfo) | ||
247 | { | ||
248 | //send data for already created prims to a new joining user | ||
249 | } | ||
250 | |||
251 | /// <summary> | ||
252 | /// | ||
253 | /// </summary> | ||
254 | /// <param name="name"></param> | ||
255 | public void SetupTemplates(string name) | ||
256 | { | ||
257 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
258 | objupdate.RegionData.RegionHandle = Globals.Instance.RegionHandle; | ||
259 | objupdate.RegionData.TimeDilation = 64096; | ||
260 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
261 | |||
262 | int i = 0; | ||
263 | FileInfo fInfo = new FileInfo(name); | ||
264 | long numBytes = fInfo.Length; | ||
265 | FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); | ||
266 | BinaryReader br = new BinaryReader(fStream); | ||
267 | byte [] data1 = br.ReadBytes((int)numBytes); | ||
268 | br.Close(); | ||
269 | fStream.Close(); | ||
270 | |||
271 | libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i); | ||
272 | objupdate.ObjectData[0] = objdata; | ||
273 | this.PrimTemplate = objdata; | ||
274 | objdata.UpdateFlags = objdata.UpdateFlags + 12 - 16 + 32 + 256; | ||
275 | objdata.OwnerID = new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
276 | //test adding a new texture to object , to test image downloading | ||
277 | LLObject.TextureEntry te = new LLObject.TextureEntry(objdata.TextureEntry, 0, objdata.TextureEntry.Length); | ||
278 | te.DefaultTexture.TextureID = new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
279 | |||
280 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
281 | |||
282 | objdata.TextureEntry = ntex.ToBytes(); | ||
283 | } | ||
284 | |||
285 | /// <summary> | ||
286 | /// | ||
287 | /// </summary> | ||
288 | /// <param name="name"></param> | ||
289 | /// <param name="user"></param> | ||
290 | public void ReadPrimDatabase(string name, UserAgentInfo userInfo) | ||
291 | { | ||
292 | StreamReader SR; | ||
293 | string line; | ||
294 | SR=File.OpenText(name); | ||
295 | string [] comp = new string[10]; | ||
296 | string delimStr = " , "; | ||
297 | char [] delimiter = delimStr.ToCharArray(); | ||
298 | |||
299 | line=SR.ReadLine(); | ||
300 | while(line != "end") | ||
301 | { | ||
302 | comp = line.Split(delimiter); | ||
303 | if(comp[0] == "ObjPack") | ||
304 | { | ||
305 | int num = Convert.ToInt32(comp[2]); | ||
306 | int start = Convert.ToInt32(comp[1]); | ||
307 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
308 | objupdate.RegionData.RegionHandle = Globals.Instance.RegionHandle; | ||
309 | objupdate.RegionData.TimeDilation = 64096; | ||
310 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[num]; | ||
311 | |||
312 | // int count=0; | ||
313 | string data_path = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, @"data"); | ||
314 | for(int cc = 0; cc < num; cc++) | ||
315 | { | ||
316 | string filenam = System.IO.Path.Combine(data_path, @"prim_updates"+start+".dat"); | ||
317 | int i = 0; | ||
318 | //FileInfo fInfo = new FileInfo("objectupate"+start+".dat"); | ||
319 | FileInfo fInfo = new FileInfo(filenam); | ||
320 | long numBytes = fInfo.Length; | ||
321 | //FileStream fStream = new FileStream("objectupate"+start+".dat", FileMode.Open, FileAccess.Read); | ||
322 | FileStream fStream = new FileStream(filenam, FileMode.Open, FileAccess.Read); | ||
323 | BinaryReader br = new BinaryReader(fStream); | ||
324 | byte [] data1 = br.ReadBytes((int)numBytes); | ||
325 | br.Close(); | ||
326 | fStream.Close(); | ||
327 | |||
328 | libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i); | ||
329 | objupdate.ObjectData[cc] = objdata; | ||
330 | start++; | ||
331 | } | ||
332 | _server.SendPacket(objupdate, true, userInfo); | ||
333 | line = SR.ReadLine(); | ||
334 | } | ||
335 | } | ||
336 | SR.Close(); | ||
337 | } | ||
338 | } | ||
339 | |||
340 | public class PrimInfo | ||
341 | { | ||
342 | public LLVector3 Position; | ||
343 | public LLVector3 Velocity; | ||
344 | public LLQuaternion Rotation=LLQuaternion.Identity; | ||
345 | public uint LocalID; | ||
346 | public LLUUID FullID; | ||
347 | public PrimData Data; | ||
348 | |||
349 | public PrimInfo() | ||
350 | { | ||
351 | Position=new LLVector3(0,0,0); | ||
352 | Velocity=new LLVector3(0,0,0); | ||
353 | //data=new PrimData(); | ||
354 | } | ||
355 | } | ||
356 | public class PrimData | ||
357 | { | ||
358 | public LLUUID OwnerID; | ||
359 | public byte PCode; | ||
360 | public byte PathBegin; | ||
361 | public byte PathEnd; | ||
362 | public byte PathScaleX; | ||
363 | public byte PathScaleY; | ||
364 | public byte PathShearX; | ||
365 | public byte PathShearY; | ||
366 | public sbyte PathSkew; | ||
367 | public byte ProfileBegin; | ||
368 | public byte ProfileEnd; | ||
369 | public LLVector3 Scale; | ||
370 | public byte PathCurve; | ||
371 | public byte ProfileCurve; | ||
372 | public uint ParentID=0; | ||
373 | public byte ProfileHollow; | ||
374 | |||
375 | public bool DataBaseStorage=false; | ||
376 | |||
377 | public PrimData() | ||
378 | { | ||
379 | |||
380 | } | ||
381 | } | ||
382 | } | ||