aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/world/Avatar.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/world/Avatar.cs487
1 files changed, 0 insertions, 487 deletions
diff --git a/src/world/Avatar.cs b/src/world/Avatar.cs
deleted file mode 100644
index facfeee..0000000
--- a/src/world/Avatar.cs
+++ /dev/null
@@ -1,487 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Text;
5using libsecondlife;
6using libsecondlife.Packets;
7using PhysicsSystem;
8using Axiom.MathLib;
9
10namespace OpenSim.world
11{
12 public class Avatar : Entity
13 {
14 public static bool PhysicsEngineFlying;
15 public string firstname;
16 public string lastname;
17 public OpenSimClient ControllingClient;
18 private PhysicsActor _physActor;
19 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
20 private bool updateflag;
21 private byte movementflag;
22 private List<NewForce> forcesList = new List<NewForce>();
23 private short _updateCount;
24 private Axiom.MathLib.Quaternion bodyRot;
25
26 public Avatar(OpenSimClient TheClient) {
27 ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
28 ControllingClient=TheClient;
29 position = new LLVector3(100.0f,100.0f,30.0f);
30 position.Z = OpenSim_Main.local_world.LandMap[(int)position.Y * 256 + (int)position.X]+1;
31 }
32
33 public PhysicsActor PhysActor
34 {
35 set
36 {
37 this._physActor = value;
38 }
39 }
40 public override void addForces()
41 {
42 lock(this.forcesList)
43 {
44 if(this.forcesList.Count>0)
45 {
46 for(int i=0 ; i < this.forcesList.Count; i++)
47 {
48 NewForce force = this.forcesList[i];
49 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
50 this._physActor.Velocity = phyVector;
51 this.updateflag = true;
52 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
53 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
54 }
55 for(int i=0 ; i < this.forcesList.Count; i++)
56 {
57 this.forcesList.RemoveAt(0);
58 }
59 }
60 }
61 }
62
63 public override void update()
64 {
65
66 if(this.updateflag)
67 {
68 //need to send movement info
69 //so create the improvedterseobjectupdate packet
70 //use CreateTerseBlock()
71 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
72 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
73 terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
74 terse.RegionData.TimeDilation = 64096;
75 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
76 terse.ObjectData[0] = terseBlock;
77 foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
78 client.OutPacket(terse);
79 }
80
81 updateflag =false;
82 //this._updateCount = 0;
83 }
84 else
85 {
86 //if((movementflag & 1) !=0)
87 //{
88 _updateCount++;
89 if(( (!PhysicsEngineFlying) && (_updateCount>3)) || (_updateCount>0))
90 {
91 //It has been a while since last update was sent so lets send one.
92 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
93 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
94 terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
95 terse.RegionData.TimeDilation = 64096;
96 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
97 terse.ObjectData[0] = terseBlock;
98 foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
99 client.OutPacket(terse);
100 }
101 _updateCount = 0;
102 }
103 //}
104 }
105 }
106
107 public static void SetupTemplate(string name)
108 {
109 int i = 0;
110 FileInfo fInfo = new FileInfo(name);
111 long numBytes = fInfo.Length;
112 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
113 BinaryReader br = new BinaryReader(fStream);
114 byte [] data1 = br.ReadBytes((int)numBytes);
115 br.Close();
116 fStream.Close();
117
118 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
119
120 System.Text.Encoding enc = System.Text.Encoding.ASCII;
121 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
122 pos.X = 100f;
123 objdata.ID = 8880000;
124 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
125 libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
126 //objdata.FullID=user.AgentID;
127 byte[] pb = pos.GetBytes();
128 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
129
130 Avatar.AvatarTemplate = objdata;
131 }
132
133 public void CompleteMovement(World RegionInfo) {
134 ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
135 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
136 mov.AgentData.SessionID = this.ControllingClient.SessionID;
137 mov.AgentData.AgentID = this.ControllingClient.AgentID;
138 mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle;
139 // TODO - dynamicalise this stuff
140 mov.Data.Timestamp = 1172750370;
141 mov.Data.Position = new LLVector3(100f, 100f, 23f);
142 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
143
144 ControllingClient.OutPacket(mov);
145 }
146
147 public void SendInitialPosition() {
148
149 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
150 //send a objectupdate packet with information about the clients avatar
151 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
152 objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle;
153 objupdate.RegionData.TimeDilation = 64096;
154 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
155
156 objupdate.ObjectData[0] = AvatarTemplate;
157 //give this avatar object a local id and assign the user a name
158 objupdate.ObjectData[0].ID = this.localid;
159 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
160 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
161
162 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
163
164 byte[] pb = pos2.GetBytes();
165
166 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
167 OpenSim_Main.local_world._localNumber++;
168
169 foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values)
170 {
171 client.OutPacket(objupdate);
172 if(client.AgentID != ControllingClient.AgentID)
173 {
174 SendAppearanceToOtherAgent(client);
175 }
176 }
177 //this.ControllingClient.OutPacket(objupdate);
178 }
179
180 public void SendInitialAppearance() {
181 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
182 aw.AgentData.AgentID = this.ControllingClient.AgentID;
183 aw.AgentData.SerialNum = 0;
184 aw.AgentData.SessionID = ControllingClient.SessionID;
185
186 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
187 AgentWearablesUpdatePacket.WearableDataBlock awb = new AgentWearablesUpdatePacket.WearableDataBlock();
188 awb.WearableType = (byte)0;
189 awb.AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
190 awb.ItemID = LLUUID.Random();
191 aw.WearableData[0] = awb;
192
193 for(int i=1; i<13; i++)
194 {
195 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
196 awb.WearableType = (byte)i;
197 awb.AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
198 awb.ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
199 aw.WearableData[i] = awb;
200 }
201
202 ControllingClient.OutPacket(aw);
203 }
204
205 public ObjectUpdatePacket CreateUpdatePacket()
206 {
207 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
208 //send a objectupdate packet with information about the clients avatar
209 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
210 objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle;
211 objupdate.RegionData.TimeDilation = 64096;
212 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
213
214 objupdate.ObjectData[0] = AvatarTemplate;
215 //give this avatar object a local id and assign the user a name
216 objupdate.ObjectData[0].ID = this.localid;
217 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
218 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
219
220 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
221
222 byte[] pb = pos2.GetBytes();
223
224 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
225 return objupdate;
226 }
227
228 public void SendAppearanceToOtherAgent(OpenSimClient userInfo)
229 {
230 AvatarAppearancePacket avp = new AvatarAppearancePacket();
231
232
233 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
234 //avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes);
235
236 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-0000-000000000005"));
237 avp.ObjectData.TextureEntry = ntex.ToBytes();
238
239 AvatarAppearancePacket.VisualParamBlock avblock = null;
240 for(int i = 0; i < 218; i++)
241 {
242 avblock = new AvatarAppearancePacket.VisualParamBlock();
243 avblock.ParamValue = (byte)100;
244 avp.VisualParam[i] = avblock;
245 }
246
247 avp.Sender.IsTrial = false;
248 avp.Sender.ID = ControllingClient.AgentID;
249 userInfo.OutPacket(avp);
250
251 }
252
253 public void HandleUpdate(AgentUpdatePacket pack) {
254 if(((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_FLY) !=0)
255 {
256 this._physActor.Flying = true;
257 }
258 else
259 {
260 this._physActor.Flying = false;
261 }
262 if(((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) !=0) {
263 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
264 if(((movementflag & 1) ==0) || (q!= this.bodyRot))
265 {
266 //we should add a new force to the list
267 // but for now we will deal with velocities
268 NewForce newVelocity = new NewForce();
269 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
270 Axiom.MathLib.Vector3 direc = q * v3;
271 direc.Normalize();
272
273 //work out velocity for sim physics system
274 direc = direc * ((0.03f) * 128f);
275 if(this._physActor.Flying)
276 direc *=2;
277
278 newVelocity.X = direc.x;
279 newVelocity.Y = direc.y;
280 newVelocity.Z = direc.z;
281 this.forcesList.Add(newVelocity);
282 movementflag = 1;
283 this.bodyRot = q;
284 }
285 }
286 else if((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_POS) !=0) &&(PhysicsEngineFlying)) {
287 if(((movementflag & 2) ==0) && this._physActor.Flying)
288 {
289 //we should add a new force to the list
290 // but for now we will deal with velocities
291 NewForce newVelocity = new NewForce();
292 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
293 Axiom.MathLib.Vector3 direc = v3;
294 direc.Normalize();
295
296 //work out velocity for sim physics system
297 direc = direc * ((0.03f) * 128f *2);
298 newVelocity.X = direc.x;
299 newVelocity.Y = direc.y;
300 newVelocity.Z = direc.z;
301 this.forcesList.Add(newVelocity);
302 movementflag = 2;
303 }
304 }
305 else if((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_NEG) !=0) && (PhysicsEngineFlying)) {
306 if(((movementflag & 4) ==0) && this._physActor.Flying)
307 {
308 //we should add a new force to the list
309 // but for now we will deal with velocities
310 NewForce newVelocity = new NewForce();
311 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
312 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
313 Axiom.MathLib.Vector3 direc = v3;
314 direc.Normalize();
315
316 //work out velocity for sim physics system
317 direc = direc * ((0.03f) * 128f *2);
318 newVelocity.X = direc.x;
319 newVelocity.Y = direc.y;
320 newVelocity.Z = direc.z;
321 this.forcesList.Add(newVelocity);
322 movementflag = 4;
323 }
324 }
325 else if(((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_NEG) !=0) {
326 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
327 if(((movementflag & 8) ==0) || (q!= this.bodyRot))
328 {
329 //we should add a new force to the list
330 // but for now we will deal with velocities
331 NewForce newVelocity = new NewForce();
332 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
333 Axiom.MathLib.Vector3 direc = q * v3;
334 direc.Normalize();
335
336 //work out velocity for sim physics system
337 direc = direc * ((0.03f) * 128f);
338 if(this._physActor.Flying)
339 direc *=2;
340
341 newVelocity.X = direc.x;
342 newVelocity.Y = direc.y;
343 newVelocity.Z = direc.z;
344 this.forcesList.Add(newVelocity);
345 movementflag = 8;
346 this.bodyRot = q;
347 }
348 }
349 else
350 {
351 if((movementflag) !=0)
352 {
353 NewForce newVelocity = new NewForce();
354 newVelocity.X = 0;
355 newVelocity.Y = 0;
356 newVelocity.Z = 0;
357 this.forcesList.Add(newVelocity);
358 movementflag = 0;
359 }
360 }
361 }
362
363 //should be moved somewhere else
364 public void SendRegionHandshake(World RegionInfo) {
365 ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
366 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
367 RegionHandshakePacket handshake = new RegionHandshakePacket();
368
369 ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
370 handshake.RegionInfo.BillableFactor = 0;
371 handshake.RegionInfo.IsEstateManager = false;
372 handshake.RegionInfo.TerrainHeightRange00 = 60;
373 handshake.RegionInfo.TerrainHeightRange01 = 60;
374 handshake.RegionInfo.TerrainHeightRange10 = 60;
375 handshake.RegionInfo.TerrainHeightRange11 = 60;
376 handshake.RegionInfo.TerrainStartHeight00 = 10;
377 handshake.RegionInfo.TerrainStartHeight01 = 10;
378 handshake.RegionInfo.TerrainStartHeight10 = 10;
379 handshake.RegionInfo.TerrainStartHeight11 = 10;
380 handshake.RegionInfo.SimAccess = 13;
381 handshake.RegionInfo.WaterHeight = 20;
382 handshake.RegionInfo.RegionFlags = 72458694;
383 handshake.RegionInfo.SimName = _enc.GetBytes(OpenSim_Main.cfg.RegionName + "\0");
384 handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
385 handshake.RegionInfo.TerrainBase0 = new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975");
386 handshake.RegionInfo.TerrainBase1 = new LLUUID("abb783e6-3e93-26c0-248a-247666855da3");
387 handshake.RegionInfo.TerrainBase2 = new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f");
388 handshake.RegionInfo.TerrainBase3 = new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2");
389 handshake.RegionInfo.TerrainDetail0 = new LLUUID("00000000-0000-0000-0000-000000000000");
390 handshake.RegionInfo.TerrainDetail1 = new LLUUID("00000000-0000-0000-0000-000000000000");
391 handshake.RegionInfo.TerrainDetail2 = new LLUUID("00000000-0000-0000-0000-000000000000");
392 handshake.RegionInfo.TerrainDetail3 = new LLUUID("00000000-0000-0000-0000-000000000000");
393 handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
394
395 ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
396 this.ControllingClient.OutPacket(handshake);
397 }
398
399 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
400 {
401 byte[] bytes = new byte[60];
402 int i=0;
403 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
404
405 dat.TextureEntry = AvatarTemplate.TextureEntry;
406 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
407
408 uint ID = this.localid;
409
410 bytes[i++] = (byte)(ID % 256);
411 bytes[i++] = (byte)((ID >> 8) % 256);
412 bytes[i++] = (byte)((ID >> 16) % 256);
413 bytes[i++] = (byte)((ID >> 24) % 256);
414 bytes[i++] = 0;
415 bytes[i++] = 1;
416 i += 14;
417 bytes[i++] = 128;
418 bytes[i++] = 63;
419
420 byte[] pb = pos2.GetBytes();
421 Array.Copy(pb, 0, bytes, i, pb.Length);
422 i += 12;
423 ushort InternVelocityX;
424 ushort InternVelocityY;
425 ushort InternVelocityZ;
426
427 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
428 internDirec = internDirec /128.0f;
429 internDirec.x += 1;
430 internDirec.y += 1;
431 internDirec.z += 1;
432
433 InternVelocityX = (ushort)(32768 * internDirec.x);
434 InternVelocityY = (ushort)(32768 * internDirec.y);
435 InternVelocityZ = (ushort)(32768 * internDirec.z);
436
437 ushort ac = 32767;
438 bytes[i++] = (byte)(InternVelocityX % 256);
439 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
440 bytes[i++] = (byte)(InternVelocityY % 256);
441 bytes[i++] = (byte)((InternVelocityY>> 8) % 256);
442 bytes[i++] = (byte)(InternVelocityZ % 256);
443 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
444
445 //accel
446 bytes[i++] = (byte)(ac % 256);
447 bytes[i++] = (byte)((ac >> 8) % 256);
448 bytes[i++] = (byte)(ac % 256);
449 bytes[i++] = (byte)((ac >> 8) % 256);
450 bytes[i++] = (byte)(ac % 256);
451 bytes[i++] = (byte)((ac >> 8) % 256);
452
453 //rot
454 bytes[i++] = (byte)(ac % 256);
455 bytes[i++] = (byte)((ac >> 8) % 256);
456 bytes[i++] = (byte)(ac % 256);
457 bytes[i++] = (byte)((ac >> 8) % 256);
458 bytes[i++] = (byte)(ac % 256);
459 bytes[i++] = (byte)((ac >> 8) % 256);
460 bytes[i++] = (byte)(ac % 256);
461 bytes[i++] = (byte)((ac >> 8) % 256);
462
463 //rotation vel
464 bytes[i++] = (byte)(ac % 256);
465 bytes[i++] = (byte)((ac >> 8) % 256);
466 bytes[i++] = (byte)(ac % 256);
467 bytes[i++] = (byte)((ac >> 8) % 256);
468 bytes[i++] = (byte)(ac % 256);
469 bytes[i++] = (byte)((ac >> 8) % 256);
470
471 dat.Data=bytes;
472 return(dat);
473 }
474 }
475
476 public class NewForce
477 {
478 public float X;
479 public float Y;
480 public float Z;
481
482 public NewForce()
483 {
484
485 }
486 }
487}