aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prim_manager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prim_manager.cs')
-rw-r--r--Prim_manager.cs310
1 files changed, 310 insertions, 0 deletions
diff --git a/Prim_manager.cs b/Prim_manager.cs
new file mode 100644
index 0000000..dff2d24
--- /dev/null
+++ b/Prim_manager.cs
@@ -0,0 +1,310 @@
1/*
2Copyright (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
30using System;
31using System.Collections.Generic;
32using libsecondlife;
33using libsecondlife.Packets;
34using libsecondlife.AssetSystem;
35using System.IO;
36using Axiom.MathLib;
37
38namespace Second_server
39{
40 /// <summary>
41 /// Description of Prim_manager.
42 /// </summary>
43 public class Prim_manager
44 {
45 private Server server;
46 public Agent_Manager agent_man;
47
48 private uint prim_count;
49
50 public libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock object_template;
51 public Dictionary<libsecondlife.LLUUID,prim_info> Prim_list;
52 public Prim_manager(Server serve)
53 {
54 server=serve;
55 Prim_list=new Dictionary<libsecondlife.LLUUID,prim_info> ();
56 this.setuptemplates("objectupate164.dat");
57 }
58
59
60 //*********************************************************************
61 public void create_prim(User_Agent_info User_info, libsecondlife.LLVector3 p1, ObjectAddPacket add_pack)
62 {
63 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
64 objupdate.RegionData.RegionHandle=1096213093147648;
65 objupdate.RegionData.TimeDilation=64096;
66 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
67
68 objupdate.ObjectData[0]=this.object_template;
69 objupdate.ObjectData[0].OwnerID=User_info.AgentID;
70 objupdate.ObjectData[0].PCode=add_pack.ObjectData.PCode;
71 objupdate.ObjectData[0].PathBegin=add_pack.ObjectData.PathBegin;
72 objupdate.ObjectData[0].PathEnd=add_pack.ObjectData.PathEnd;
73 objupdate.ObjectData[0].PathScaleX=add_pack.ObjectData.PathScaleX;
74 objupdate.ObjectData[0].PathScaleY=add_pack.ObjectData.PathScaleY;
75 objupdate.ObjectData[0].PathShearX=add_pack.ObjectData.PathShearX;
76 objupdate.ObjectData[0].PathShearY=add_pack.ObjectData.PathShearY;
77 objupdate.ObjectData[0].PathSkew=add_pack.ObjectData.PathSkew;
78 objupdate.ObjectData[0].ProfileBegin=add_pack.ObjectData.ProfileBegin;
79 objupdate.ObjectData[0].ProfileEnd=add_pack.ObjectData.ProfileEnd;
80 objupdate.ObjectData[0].Scale=add_pack.ObjectData.Scale;//new LLVector3(1,1,1);
81 objupdate.ObjectData[0].PathCurve=add_pack.ObjectData.PathCurve;
82 objupdate.ObjectData[0].ProfileCurve=add_pack.ObjectData.ProfileCurve;
83 objupdate.ObjectData[0].ParentID=0;
84 objupdate.ObjectData[0].ProfileHollow=add_pack.ObjectData.ProfileHollow;
85 //finish off copying rest of shape data
86
87 objupdate.ObjectData[0].ID=(uint)(702000+prim_count);
88 objupdate.ObjectData[0].FullID=new LLUUID("edba7151-5857-acc5-b30b-f01efefda"+prim_count.ToString("000"));
89
90 //update position
91 byte[] pb=p1.GetBytes();
92 Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,0,pb.Length);
93
94 prim_count++;
95 server.SendPacket(objupdate,true,User_info);
96
97 //should send to all users
98 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in agent_man.Agent_list)
99 {
100 if(kp.Value.Net_info.AgentID!=User_info.AgentID)
101 {
102 server.SendPacket(objupdate,true,kp.Value.Net_info);
103 }
104 }
105 //should store this infomation
106 prim_info n_prim=new prim_info();
107 n_prim.full_ID=objupdate.ObjectData[0].FullID;
108 n_prim.local_ID=objupdate.ObjectData[0].ID;
109 n_prim.pos=p1;
110
111 this.Prim_list.Add(n_prim.full_ID,n_prim);
112
113 //store rest of data
114
115 }
116 public void update_prim_position(User_Agent_info user,float x, float y, float z,uint l_id)
117 {
118 prim_info pri=null;
119 foreach (KeyValuePair<libsecondlife.LLUUID,prim_info> kp in this.Prim_list)
120 {
121 if(kp.Value.local_ID==l_id)
122 {
123 pri=kp.Value;
124 }
125 }
126 if(pri==null)
127 {
128 return;
129 }
130 uint ID=pri.local_ID;
131 byte[] bytes=new byte[60];
132
133 ImprovedTerseObjectUpdatePacket im=new ImprovedTerseObjectUpdatePacket();
134 im.RegionData.RegionHandle=1096213093147648;
135 im.RegionData.TimeDilation=64096;
136 im.ObjectData=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
137 int i=0;
138 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
139 im.ObjectData[0]=dat;
140 dat.TextureEntry=object_template.TextureEntry;
141 libsecondlife.LLVector3 pos2=new LLVector3(x,y,z);
142
143 bytes[i++] = (byte)(ID % 256);
144 bytes[i++] = (byte)((ID >> 8) % 256);
145 bytes[i++] = (byte)((ID >> 16) % 256);
146 bytes[i++] = (byte)((ID >> 24) % 256);
147 bytes[i++]=0;
148 bytes[i++]=0;//1;
149
150 // i+=14;
151 // bytes[i++]=128;
152 // bytes[i++]=63;
153 byte[] pb=pos2.GetBytes();
154 pri.pos=pos2;
155 Array.Copy(pb,0,bytes,i,pb.Length);
156 i+=12;
157 ushort ac=32767;
158
159 //vel
160 bytes[i++] = (byte)(ac % 256);
161 bytes[i++] = (byte)((ac >> 8) % 256);
162 bytes[i++] = (byte)(ac % 256);
163 bytes[i++] = (byte)((ac >> 8) % 256);
164 bytes[i++] = (byte)(ac % 256);
165 bytes[i++] = (byte)((ac >> 8) % 256);
166
167 //accel
168 bytes[i++] = (byte)(ac % 256);
169 bytes[i++] = (byte)((ac >> 8) % 256);
170 bytes[i++] = (byte)(ac % 256);
171 bytes[i++] = (byte)((ac >> 8) % 256);
172 bytes[i++] = (byte)(ac % 256);
173 bytes[i++] = (byte)((ac >> 8) % 256);
174
175 //rot
176 bytes[i++] = (byte)(ac % 256);
177 bytes[i++] = (byte)((ac >> 8) % 256);
178 bytes[i++] = (byte)(ac % 256);
179 bytes[i++] = (byte)((ac >> 8) % 256);
180 bytes[i++] = (byte)(ac % 256);
181 bytes[i++] = (byte)((ac >> 8) % 256);
182 bytes[i++] = (byte)(ac % 256);
183 bytes[i++] = (byte)((ac >> 8) % 256);
184
185 //rotation vel
186 bytes[i++] = (byte)(ac % 256);
187 bytes[i++] = (byte)((ac >> 8) % 256);
188 bytes[i++] = (byte)(ac % 256);
189 bytes[i++] = (byte)((ac >> 8) % 256);
190 bytes[i++] = (byte)(ac % 256);
191 bytes[i++] = (byte)((ac >> 8) % 256);
192
193 dat.Data=bytes;
194 //server.SendPacket(im,true,user);
195 //should send to all users.
196 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in agent_man.Agent_list)
197 {
198 if(kp.Value.Net_info.AgentID!=user.AgentID)
199 {
200 server.SendPacket(im,true,kp.Value.Net_info);
201 }
202 }
203 }
204 public void send_existing_prims(User_Agent_info user)
205 {
206 //send data for already created prims to a new joining user
207 }
208 //**************************************************************
209 public void setuptemplates(string name)
210 {
211 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
212 objupdate.RegionData.RegionHandle=1096213093147648;
213 objupdate.RegionData.TimeDilation=64096;
214 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
215
216 int i=0;
217 FileInfo fInfo = new FileInfo(name);
218 long numBytes = fInfo.Length;
219 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
220 BinaryReader br = new BinaryReader(fStream);
221 byte [] data1 = br.ReadBytes((int)numBytes);
222 br.Close();
223 fStream.Close();
224
225 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i);
226 objupdate.ObjectData[0]=objdata;
227 this.object_template=objdata;
228 objdata.UpdateFlags=objdata.UpdateFlags+12-16+32+256;
229 objdata.OwnerID=new LLUUID("00000000-0000-0000-0000-000000000000");
230 //test adding a new texture to object , to test image downloading
231 LLObject.TextureEntry te=new LLObject.TextureEntry(objdata.TextureEntry,0,objdata.TextureEntry.Length);
232 te.DefaultTexture.TextureID=new LLUUID("00000000-0000-0000-5005-000000000005");
233
234 LLObject.TextureEntry ntex=new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
235
236 objdata.TextureEntry=ntex.ToBytes();
237 }
238 //********************************************************************
239 public void Read_Prim_database(string name,User_Agent_info user)
240 {
241 StreamReader SR;
242 string line;
243 SR=File.OpenText(name);
244 string [] comp= new string[10];
245 string delimStr = " , ";
246 char [] delimiter = delimStr.ToCharArray();
247
248 line=SR.ReadLine();
249 while(line!="end")
250 {
251 comp=line.Split(delimiter);
252 if(comp[0]=="ObjPack"){
253 int num=Convert.ToInt32(comp[2]);
254 int start=Convert.ToInt32(comp[1]);
255 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
256 objupdate.RegionData.RegionHandle=1096213093147648;
257 objupdate.RegionData.TimeDilation=64096;
258 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[num];
259
260 // int count=0;
261 string data_path=System.Windows.Forms.Application.StartupPath + @"\data\";
262 for(int cc=0; cc<num; cc++)
263 {
264 string filenam=data_path+@"prim_updates"+start+".dat";
265 int i=0;
266 //FileInfo fInfo = new FileInfo("objectupate"+start+".dat");
267 FileInfo fInfo = new FileInfo(filenam);
268 long numBytes = fInfo.Length;
269 //FileStream fStream = new FileStream("objectupate"+start+".dat", FileMode.Open, FileAccess.Read);
270 FileStream fStream = new FileStream(filenam, FileMode.Open, FileAccess.Read);
271 BinaryReader br = new BinaryReader(fStream);
272 byte [] data1 = br.ReadBytes((int)numBytes);
273 br.Close();
274 fStream.Close();
275
276 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i);
277 objupdate.ObjectData[cc]=objdata;
278 start++;
279 }
280 server.SendPacket(objupdate,true,user);
281 line=SR.ReadLine();
282 }
283 }
284 SR.Close();
285 }
286 }
287
288 public class prim_info
289 {
290 public LLVector3 pos;
291 public LLVector3 vel;
292 public uint local_ID;
293 public LLUUID full_ID;
294 public prim_data data;
295
296 public prim_info()
297 {
298 pos=new LLVector3(0,0,0);
299 vel=new LLVector3(0,0,0);
300 data=new prim_data();
301 }
302 }
303 public class prim_data
304 {
305 public prim_data()
306 {
307
308 }
309 }
310}