diff options
author | cw | 2007-01-31 22:09:20 +0000 |
---|---|---|
committer | cw | 2007-01-31 22:09:20 +0000 |
commit | a82950672860eedeaa23da75421c74e094b5c0a4 (patch) | |
tree | 6901851f8e1de03d5eadfbe05e03563126b879a2 /Agent_Manager.cs | |
download | opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.zip opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.gz opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.bz2 opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.xz |
Making trunk; applying appropriate license to each file
Diffstat (limited to 'Agent_Manager.cs')
-rw-r--r-- | Agent_Manager.cs | 618 |
1 files changed, 618 insertions, 0 deletions
diff --git a/Agent_Manager.cs b/Agent_Manager.cs new file mode 100644 index 0000000..934fb57 --- /dev/null +++ b/Agent_Manager.cs | |||
@@ -0,0 +1,618 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007 Michael Wright | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * Neither the name of the <organization> nor the | ||
12 | * names of its contributors may be used to endorse or promote products | ||
13 | * derived from this software without specific prior written permission. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
18 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | */ | ||
26 | |||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using libsecondlife; | ||
30 | using libsecondlife.Packets; | ||
31 | using libsecondlife.AssetSystem; | ||
32 | using System.IO; | ||
33 | using Axiom.MathLib; | ||
34 | |||
35 | namespace Second_server | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Description of Agent_Manager. | ||
39 | /// </summary> | ||
40 | public class Agent_Manager | ||
41 | { | ||
42 | public Dictionary<libsecondlife.LLUUID,Avatar_data> Agent_list; | ||
43 | //public uint number_agents=0; | ||
44 | private uint local_numer=0; | ||
45 | private Server server; | ||
46 | public Prim_manager prim_man; | ||
47 | private byte [] data1; | ||
48 | |||
49 | private libsecondlife.Packets.RegionHandshakePacket reg; | ||
50 | private System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
51 | public libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock avatar_template; | ||
52 | //private int appc=0; | ||
53 | |||
54 | public Agent_Manager(Server serve) | ||
55 | { | ||
56 | Agent_list=new Dictionary<libsecondlife.LLUUID,Avatar_data>(); | ||
57 | server=serve; | ||
58 | this.initialise(); | ||
59 | } | ||
60 | //*************************************************** | ||
61 | public Avatar_data Get_Agent(LLUUID id) | ||
62 | { | ||
63 | |||
64 | |||
65 | if(!this.Agent_list.ContainsKey(id)) | ||
66 | { | ||
67 | return null; | ||
68 | } | ||
69 | else | ||
70 | { | ||
71 | Avatar_data ad=this.Agent_list[id]; | ||
72 | return ad; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public void Add_Agent(Avatar_data agent) | ||
77 | { | ||
78 | this.Agent_list.Add(agent.Full_ID,agent); | ||
79 | } | ||
80 | |||
81 | public bool New_Agent(User_Agent_info User_info) | ||
82 | { | ||
83 | Avatar_data ad=new Avatar_data(); | ||
84 | ad.Full_ID=User_info.AgentID; | ||
85 | ad.Net_info=User_info; | ||
86 | ad.pos=new LLVector3(100,100,22); | ||
87 | this.Agent_list.Add(ad.Full_ID,ad); | ||
88 | return(true); | ||
89 | } | ||
90 | |||
91 | public void Agent_join(User_Agent_info User_info) | ||
92 | { | ||
93 | //send region data | ||
94 | server.SendPacket(reg,true,User_info); | ||
95 | |||
96 | //inform client of join comlete | ||
97 | libsecondlife.Packets.AgentMovementCompletePacket mov=new AgentMovementCompletePacket(); | ||
98 | mov.AgentData.SessionID=User_info.SessionID; | ||
99 | mov.AgentData.AgentID=User_info.AgentID; | ||
100 | mov.Data.RegionHandle=1096213093147648; | ||
101 | mov.Data.Timestamp=1169838966; | ||
102 | mov.Data.Position=new LLVector3(100f,100f,22f); | ||
103 | mov.Data.LookAt=new LLVector3(0.99f,0.042f,0); | ||
104 | server.SendPacket(mov,true,User_info); | ||
105 | } | ||
106 | public void tick() | ||
107 | { | ||
108 | //update positions | ||
109 | foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list) | ||
110 | { | ||
111 | |||
112 | kp.Value.pos.X+=(kp.Value.vel.X*0.2f); | ||
113 | kp.Value.pos.Y+=(kp.Value.vel.Y*0.2f); | ||
114 | kp.Value.pos.Z+=(kp.Value.vel.Z*0.2f); | ||
115 | } | ||
116 | } | ||
117 | //************************************************************** | ||
118 | private void initialise() | ||
119 | { | ||
120 | //Region data | ||
121 | reg=new RegionHandshakePacket(); | ||
122 | reg.RegionInfo.BillableFactor=0; | ||
123 | reg.RegionInfo.IsEstateManager=false; | ||
124 | reg.RegionInfo.TerrainHeightRange00=60; | ||
125 | reg.RegionInfo.TerrainHeightRange01=60; | ||
126 | reg.RegionInfo.TerrainHeightRange10=60; | ||
127 | reg.RegionInfo.TerrainHeightRange11=60; | ||
128 | reg.RegionInfo.TerrainStartHeight00=20; | ||
129 | reg.RegionInfo.TerrainStartHeight01=20; | ||
130 | reg.RegionInfo.TerrainStartHeight10=20; | ||
131 | reg.RegionInfo.TerrainStartHeight11=20; | ||
132 | reg.RegionInfo.SimAccess=13; | ||
133 | reg.RegionInfo.WaterHeight=5; | ||
134 | reg.RegionInfo.RegionFlags=72458694; | ||
135 | reg.RegionInfo.SimName=enc.GetBytes( "Test Sandbox\0"); | ||
136 | reg.RegionInfo.SimOwner=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
137 | reg.RegionInfo.TerrainBase0=new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975"); | ||
138 | reg.RegionInfo.TerrainBase1=new LLUUID("abb783e6-3e93-26c0-248a-247666855da3"); | ||
139 | reg.RegionInfo.TerrainBase2=new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f"); | ||
140 | reg.RegionInfo.TerrainBase3=new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2"); | ||
141 | reg.RegionInfo.TerrainDetail0=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
142 | reg.RegionInfo.TerrainDetail1=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
143 | reg.RegionInfo.TerrainDetail2=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
144 | reg.RegionInfo.TerrainDetail3=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
145 | reg.RegionInfo.CacheID=new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab33"); | ||
146 | |||
147 | this.setuptemplate("objectupate168.dat"); | ||
148 | } | ||
149 | |||
150 | public void setuptemplate(string name) | ||
151 | { | ||
152 | /*ObjectUpdatePacket objupdate=new ObjectUpdatePacket(); | ||
153 | objupdate.RegionData.RegionHandle=1096213093147648; | ||
154 | objupdate.RegionData.TimeDilation=64096; | ||
155 | objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
156 | */ | ||
157 | int i=0; | ||
158 | FileInfo fInfo = new FileInfo(name); | ||
159 | |||
160 | long numBytes = fInfo.Length; | ||
161 | |||
162 | FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); | ||
163 | |||
164 | BinaryReader br = new BinaryReader(fStream); | ||
165 | |||
166 | byte [] data1 = br.ReadBytes((int)numBytes); | ||
167 | |||
168 | br.Close(); | ||
169 | |||
170 | fStream.Close(); | ||
171 | |||
172 | libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i); | ||
173 | |||
174 | //objupdate.ObjectData[0]=objdata; | ||
175 | |||
176 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
177 | libsecondlife.LLVector3 pos=new LLVector3(objdata.ObjectData, 16); | ||
178 | pos.X=100f; | ||
179 | objdata.ID=8880000; | ||
180 | objdata.NameValue=enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); | ||
181 | libsecondlife.LLVector3 pos2=new LLVector3(13.981f,100.0f,20.0f); | ||
182 | //objdata.FullID=user.AgentID; | ||
183 | byte[] pb=pos.GetBytes(); | ||
184 | |||
185 | Array.Copy(pb,0,objdata.ObjectData,16,pb.Length); | ||
186 | |||
187 | avatar_template=objdata; | ||
188 | |||
189 | } | ||
190 | //********************************************************** | ||
191 | public void send_intial_data(User_Agent_info User_info) | ||
192 | { | ||
193 | |||
194 | //shouldn't really have to read all this in from disk for every new client? | ||
195 | string data_path=System.Windows.Forms.Application.StartupPath + @"\layer_data\"; | ||
196 | |||
197 | //send layerdata | ||
198 | LayerDataPacket layerpack=new LayerDataPacket(); | ||
199 | layerpack.LayerID.Type=76; | ||
200 | //layerpack.LayerData.ReadfromFile(data_path+@"layerdata0.dat"); | ||
201 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata0.dat"); | ||
202 | |||
203 | //server.SendPacket(layerpack,true,User_info); | ||
204 | |||
205 | LayerDataPacket layerpack1=new LayerDataPacket(); | ||
206 | layerpack1.LayerID.Type=76; | ||
207 | //layerpack1.LayerData.ReadfromFile(data_path+@"layerdata1.dat"); | ||
208 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata1.dat"); | ||
209 | //server.SendPacket(layerpack1,true,User_info); | ||
210 | |||
211 | LayerDataPacket layerpack2=new LayerDataPacket(); | ||
212 | layerpack2.LayerID.Type=56; | ||
213 | //layerpack2.LayerData.ReadfromFile(data_path+@"layerdata2.dat"); | ||
214 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata2.dat"); | ||
215 | //server.SendPacket(layerpack2,true,User_info); | ||
216 | |||
217 | LayerDataPacket layerpack3=new LayerDataPacket(); | ||
218 | layerpack3.LayerID.Type=55; | ||
219 | //layerpack3.LayerData.ReadfromFile(data_path+@"layerdata3.dat"); | ||
220 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata3.dat"); | ||
221 | //server.SendPacket(layerpack3,true,User_info); | ||
222 | |||
223 | LayerDataPacket layerpack4=new LayerDataPacket(); | ||
224 | layerpack4.LayerID.Type=56; | ||
225 | //layerpack4.LayerData.ReadfromFile(data_path+@"layerdata4.dat"); | ||
226 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata4.dat"); | ||
227 | //server.SendPacket(layerpack4,true,User_info); | ||
228 | |||
229 | LayerDataPacket layerpack5=new LayerDataPacket(); | ||
230 | layerpack5.LayerID.Type=55; | ||
231 | //layerpack5.LayerData.ReadfromFile(data_path+@"layerdata5.dat"); | ||
232 | this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata5.dat"); | ||
233 | //server.SendPacket(layerpack5,true,User_info); | ||
234 | |||
235 | |||
236 | //send intial set of captured prims data? | ||
237 | this.prim_man.Read_Prim_database( "objectdatabase.ini",User_info); | ||
238 | |||
239 | //send prims that have been created by users | ||
240 | //prim_man.send_existing_prims(User_info); | ||
241 | |||
242 | //send update about clients avatar | ||
243 | this.send_intial_avatar_position(User_info); | ||
244 | |||
245 | //send updates about all other users | ||
246 | //this.send_test_avatar_position(User_info); | ||
247 | foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list) | ||
248 | { | ||
249 | if(kp.Value.Net_info.AgentID!=User_info.AgentID) | ||
250 | { | ||
251 | this.send_other_avatar_position(User_info,kp.Value); | ||
252 | } | ||
253 | } | ||
254 | |||
255 | |||
256 | } | ||
257 | public void send_intial_avatar_position(User_Agent_info User_info) | ||
258 | { | ||
259 | //send a objectupdate packet with information about the clients avatar | ||
260 | ObjectUpdatePacket objupdate=new ObjectUpdatePacket(); | ||
261 | objupdate.RegionData.RegionHandle=1096213093147648; | ||
262 | objupdate.RegionData.TimeDilation=64096; | ||
263 | objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
264 | |||
265 | objupdate.ObjectData[0]=avatar_template; | ||
266 | //give this avatar object a local id and assign the user a name | ||
267 | objupdate.ObjectData[0].ID=8880000+this.local_numer; | ||
268 | User_info.localID=objupdate.ObjectData[0].ID; | ||
269 | //User_info.name="Test"+this.local_numer+" User"; | ||
270 | this.Get_Agent(User_info.AgentID).started=true; | ||
271 | objupdate.ObjectData[0].FullID=User_info.AgentID; | ||
272 | objupdate.ObjectData[0].NameValue=enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0"); | ||
273 | User_info.name="FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0"; | ||
274 | User_info.last_name="User"; | ||
275 | User_info.first_name="Test"+this.local_numer; | ||
276 | libsecondlife.LLVector3 pos2=new LLVector3(100f,100.0f,22.0f); | ||
277 | |||
278 | byte[] pb=pos2.GetBytes(); | ||
279 | |||
280 | Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length); | ||
281 | this.local_numer++; | ||
282 | |||
283 | server.SendPacket(objupdate,true,User_info); | ||
284 | |||
285 | //send this info to other existing clients | ||
286 | foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list) | ||
287 | { | ||
288 | if(kp.Value.Net_info.AgentID!=User_info.AgentID) | ||
289 | { | ||
290 | server.SendPacket(objupdate,true,kp.Value.Net_info); | ||
291 | this.send_other_apper(kp.Value.Net_info,objupdate.ObjectData[0].FullID); | ||
292 | } | ||
293 | } | ||
294 | |||
295 | } | ||
296 | public void send_intial_avatar_apper(User_Agent_info user) | ||
297 | { | ||
298 | |||
299 | //seems that we don't send a avatarapperance for ourself. | ||
300 | /*AvatarAppearancePacket avp=new AvatarAppearancePacket(); | ||
301 | |||
302 | avp.VisualParam=new AvatarAppearancePacket.VisualParamBlock[218]; | ||
303 | avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes); | ||
304 | |||
305 | AvatarAppearancePacket.VisualParamBlock avblock=null; | ||
306 | for(int i=0; i<218; i++) | ||
307 | { | ||
308 | avblock=new AvatarAppearancePacket.VisualParamBlock(); | ||
309 | avblock.ParamValue=(byte)100; | ||
310 | avp.VisualParam[i]=avblock; | ||
311 | } | ||
312 | |||
313 | avp.Sender.IsTrial=false; | ||
314 | avp.Sender.ID=user.AgentID; | ||
315 | */ | ||
316 | |||
317 | AgentWearablesUpdatePacket aw=new AgentWearablesUpdatePacket(); | ||
318 | aw.AgentData.AgentID=user.AgentID; | ||
319 | aw.AgentData.SerialNum=0;//(uint)appc; | ||
320 | //appc++; | ||
321 | aw.AgentData.SessionID=user.SessionID;//new LLUUID("00000000-0000-0000-0000-000000000000");//user.SessionID; | ||
322 | |||
323 | aw.WearableData= new AgentWearablesUpdatePacket.WearableDataBlock[13]; | ||
324 | AgentWearablesUpdatePacket.WearableDataBlock awb=null; | ||
325 | awb=new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
326 | awb.WearableType=(byte)0; | ||
327 | awb.AssetID=new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
328 | //awb.ItemID=new LLUUID("b7878000-0000-0000-0000-000000000000"); | ||
329 | awb.ItemID=new LLUUID("b7878441893b094917f791174bc8401c"); | ||
330 | //awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
331 | aw.WearableData[0]=awb; | ||
332 | |||
333 | |||
334 | /*awb=new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
335 | awb.WearableType=(byte)1; | ||
336 | awb.AssetID=new LLUUID("e0ee49b5a4184df8d3c9a65361fe7f49"); | ||
337 | awb.ItemID=new LLUUID("193f0876fc11d143797454352f9c9c26"); | ||
338 | //awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
339 | aw.WearableData[1]=awb;*/ | ||
340 | |||
341 | |||
342 | for(int i=1; i<13; i++) | ||
343 | { | ||
344 | awb=new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
345 | awb.WearableType=(byte)i; | ||
346 | awb.AssetID=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
347 | awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000"); | ||
348 | aw.WearableData[i]=awb; | ||
349 | } | ||
350 | |||
351 | //server.SendPacket(avp,true,user); | ||
352 | server.SendPacket(aw,true,user); | ||
353 | //System.Console.WriteLine(avp); | ||
354 | |||
355 | |||
356 | } | ||
357 | public void send_other_apper(User_Agent_info user,LLUUID id) | ||
358 | { | ||
359 | AvatarAppearancePacket avp=new AvatarAppearancePacket(); | ||
360 | |||
361 | |||
362 | avp.VisualParam=new AvatarAppearancePacket.VisualParamBlock[218]; | ||
363 | //avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes); | ||
364 | |||
365 | FileInfo fInfo = new FileInfo("Avatar_texture3.dat"); | ||
366 | |||
367 | long numBytes = fInfo.Length; | ||
368 | FileStream fStream = new FileStream("Avatar_texture3.dat", FileMode.Open, FileAccess.Read); | ||
369 | BinaryReader br = new BinaryReader(fStream); | ||
370 | avp.ObjectData.TextureEntry= br.ReadBytes((int)numBytes); | ||
371 | br.Close(); | ||
372 | fStream.Close(); | ||
373 | |||
374 | AvatarAppearancePacket.VisualParamBlock avblock=null; | ||
375 | for(int i=0; i<218; i++) | ||
376 | { | ||
377 | avblock=new AvatarAppearancePacket.VisualParamBlock(); | ||
378 | avblock.ParamValue=(byte)100; | ||
379 | avp.VisualParam[i]=avblock; | ||
380 | } | ||
381 | |||
382 | avp.Sender.IsTrial=false; | ||
383 | avp.Sender.ID=id; | ||
384 | server.SendPacket(avp,true,user); | ||
385 | |||
386 | } | ||
387 | |||
388 | public void send_test_avatar_position(User_Agent_info User_info) | ||
389 | { | ||
390 | //send a objectupdate packet with information about the clients avatar | ||
391 | ObjectUpdatePacket objupdate=new ObjectUpdatePacket(); | ||
392 | objupdate.RegionData.RegionHandle=1096213093147648; | ||
393 | objupdate.RegionData.TimeDilation=64500; | ||
394 | objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
395 | |||
396 | objupdate.ObjectData[0]=avatar_template; | ||
397 | //give this avatar object a local id and assign the user a name | ||
398 | objupdate.ObjectData[0].ID=8880000+this.local_numer; | ||
399 | objupdate.ObjectData[0].FullID=new LLUUID("00000000-0000-0000-5665-000000000034"); | ||
400 | objupdate.ObjectData[0].NameValue=enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0"); | ||
401 | libsecondlife.LLVector3 pos2=new LLVector3(120f,120.0f,22.0f); | ||
402 | |||
403 | byte[] pb=pos2.GetBytes(); | ||
404 | |||
405 | Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length); | ||
406 | this.local_numer++; | ||
407 | |||
408 | server.SendPacket(objupdate,true,User_info); | ||
409 | |||
410 | this.send_other_apper(User_info,new LLUUID("00000000-0000-0000-5665-000000000034")); | ||
411 | |||
412 | } | ||
413 | |||
414 | public void send_other_avatar_position(User_Agent_info User_info, Avatar_data avd) | ||
415 | { | ||
416 | //send a objectupdate packet with information about the clients avatar | ||
417 | ObjectUpdatePacket objupdate=new ObjectUpdatePacket(); | ||
418 | objupdate.RegionData.RegionHandle=1096213093147648; | ||
419 | objupdate.RegionData.TimeDilation=64500; | ||
420 | objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
421 | |||
422 | objupdate.ObjectData[0]=avatar_template; | ||
423 | //give this avatar object a local id and assign the user a name | ||
424 | objupdate.ObjectData[0].ID=avd.Net_info.localID; | ||
425 | objupdate.ObjectData[0].FullID=avd.Net_info.AgentID;//new LLUUID("00000000-0000-0000-5665-000000000034"); | ||
426 | objupdate.ObjectData[0].NameValue=enc.GetBytes(avd.Net_info.name);//enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0"); | ||
427 | libsecondlife.LLVector3 pos2=new LLVector3(avd.pos.X,avd.pos.Y,avd.pos.Z); | ||
428 | |||
429 | byte[] pb=pos2.GetBytes(); | ||
430 | |||
431 | Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length); | ||
432 | this.local_numer++; | ||
433 | |||
434 | server.SendPacket(objupdate,true,User_info); | ||
435 | |||
436 | this.send_other_apper(User_info,avd.Net_info.AgentID);//new LLUUID("00000000-0000-0000-5665-000000000034")); | ||
437 | |||
438 | } | ||
439 | //************************************************************* | ||
440 | public void send_chat_message(User_Agent_info User_info, string line) | ||
441 | { | ||
442 | libsecondlife.Packets.ChatFromSimulatorPacket reply=new ChatFromSimulatorPacket(); | ||
443 | reply.ChatData.Audible=1; | ||
444 | reply.ChatData.Message=enc.GetBytes(line); | ||
445 | reply.ChatData.ChatType=1; | ||
446 | reply.ChatData.SourceType=1; | ||
447 | reply.ChatData.Position=new LLVector3(120,100,21); //should set to actual position | ||
448 | reply.ChatData.FromName=enc.GetBytes(User_info.first_name +" "+User_info.last_name +"\0"); //enc.GetBytes("Echo: \0"); //and actual name | ||
449 | reply.ChatData.OwnerID=User_info.AgentID; | ||
450 | reply.ChatData.SourceID=User_info.AgentID; | ||
451 | //echo to sender | ||
452 | server.SendPacket(reply,true,User_info); | ||
453 | |||
454 | //send to all users | ||
455 | foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list) | ||
456 | { | ||
457 | if(kp.Value.Net_info.AgentID!=User_info.AgentID) | ||
458 | { | ||
459 | server.SendPacket(reply,true,kp.Value.Net_info); | ||
460 | } | ||
461 | } | ||
462 | } | ||
463 | //************************************************************* | ||
464 | public void send_move_command(User_Agent_info user, bool stop,float x, float y, float z, uint av_id, libsecondlife.LLQuaternion body) | ||
465 | { | ||
466 | uint ID=user.localID; | ||
467 | //ID=av_id; | ||
468 | byte[] bytes=new byte[60]; | ||
469 | |||
470 | ImprovedTerseObjectUpdatePacket im=new ImprovedTerseObjectUpdatePacket(); | ||
471 | im.RegionData.RegionHandle=1096213093147648; | ||
472 | im.RegionData.TimeDilation=64096; | ||
473 | |||
474 | im.ObjectData=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
475 | int i=0; | ||
476 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
477 | |||
478 | im.ObjectData[0]=dat; | ||
479 | |||
480 | dat.TextureEntry=avatar_template.TextureEntry; | ||
481 | libsecondlife.LLVector3 pos2=new LLVector3(x,y,z); | ||
482 | |||
483 | bytes[i++] = (byte)(ID % 256); | ||
484 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
485 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
486 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
487 | |||
488 | bytes[i++]=0; | ||
489 | bytes[i++]=1; | ||
490 | |||
491 | i+=14; | ||
492 | bytes[i++]=128; | ||
493 | bytes[i++]=63; | ||
494 | byte[] pb=pos2.GetBytes(); | ||
495 | |||
496 | Array.Copy(pb,0,bytes,i,pb.Length); | ||
497 | i+=12; | ||
498 | ushort ac=32767; | ||
499 | Axiom.MathLib.Vector3 v3=new Axiom.MathLib.Vector3(1,0,0); | ||
500 | Axiom.MathLib.Quaternion q=new Axiom.MathLib.Quaternion(body.W,body.X,body.Y,body.Z); | ||
501 | Axiom.MathLib.Vector3 direc=q*v3; | ||
502 | direc.Normalize(); | ||
503 | |||
504 | direc=direc*(0.03f); | ||
505 | direc.x+=1; | ||
506 | direc.y+=1; | ||
507 | direc.z+=1; | ||
508 | ushort dx,dy,dz; | ||
509 | dx=(ushort)(32768*direc.x); | ||
510 | dy=(ushort)(32768*direc.y); | ||
511 | dz=(ushort)(32768*direc.z); | ||
512 | |||
513 | //vel | ||
514 | if(!stop) | ||
515 | { | ||
516 | bytes[i++] = (byte)(dx % 256); | ||
517 | bytes[i++] = (byte)((dx >> 8) % 256); | ||
518 | |||
519 | bytes[i++] = (byte)(dy % 256); | ||
520 | bytes[i++] = (byte)((dy >> 8) % 256); | ||
521 | |||
522 | bytes[i++] = (byte)(dz % 256); | ||
523 | bytes[i++] = (byte)((dz >> 8) % 256); | ||
524 | } | ||
525 | else | ||
526 | { | ||
527 | bytes[i++] = (byte)(ac % 256); | ||
528 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
529 | |||
530 | bytes[i++] = (byte)(ac % 256); | ||
531 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
532 | |||
533 | bytes[i++] = (byte)(ac % 256); | ||
534 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
535 | } | ||
536 | //accel | ||
537 | bytes[i++] = (byte)(ac % 256); | ||
538 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
539 | |||
540 | bytes[i++] = (byte)(ac % 256); | ||
541 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
542 | |||
543 | bytes[i++] = (byte)(ac % 256); | ||
544 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
545 | |||
546 | //rot | ||
547 | bytes[i++] = (byte)(ac % 256); | ||
548 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
549 | |||
550 | bytes[i++] = (byte)(ac % 256); | ||
551 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
552 | |||
553 | bytes[i++] = (byte)(ac % 256); | ||
554 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
555 | |||
556 | bytes[i++] = (byte)(ac % 256); | ||
557 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
558 | |||
559 | //rotation vel | ||
560 | bytes[i++] = (byte)(ac % 256); | ||
561 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
562 | |||
563 | bytes[i++] = (byte)(ac % 256); | ||
564 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
565 | |||
566 | bytes[i++] = (byte)(ac % 256); | ||
567 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
568 | |||
569 | dat.Data=bytes; | ||
570 | |||
571 | server.SendPacket(im,true,user); | ||
572 | |||
573 | //should send to all users. | ||
574 | foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list) | ||
575 | { | ||
576 | if(kp.Value.Net_info.AgentID!=user.AgentID) | ||
577 | { | ||
578 | server.SendPacket(im,true,kp.Value.Net_info); | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | //************************************************************* | ||
583 | public void read_layerdata(User_Agent_info User_info,ref LayerDataPacket lay,string name) | ||
584 | { | ||
585 | FileInfo fInfo = new FileInfo(name); | ||
586 | |||
587 | long numBytes = fInfo.Length; | ||
588 | |||
589 | FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); | ||
590 | |||
591 | BinaryReader br = new BinaryReader(fStream); | ||
592 | |||
593 | data1 = br.ReadBytes((int)numBytes); | ||
594 | |||
595 | br.Close(); | ||
596 | |||
597 | fStream.Close(); | ||
598 | lay.LayerData.Data=data1; | ||
599 | server.SendPacket(lay,true,User_info); | ||
600 | //System.Console.WriteLine("sent"); | ||
601 | } | ||
602 | } | ||
603 | |||
604 | public class Avatar_data | ||
605 | { | ||
606 | public User_Agent_info Net_info; | ||
607 | public LLUUID Full_ID; | ||
608 | public LLVector3 pos; | ||
609 | public LLVector3 vel=new LLVector3(0,0,0); | ||
610 | public bool walk=false; | ||
611 | public bool started=false; | ||
612 | |||
613 | public Avatar_data() | ||
614 | { | ||
615 | |||
616 | } | ||
617 | } | ||
618 | } | ||