aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/world/Avatar.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Avatar.cs482
1 files changed, 0 insertions, 482 deletions
diff --git a/OpenSim/OpenSim.RegionServer/world/Avatar.cs b/OpenSim/OpenSim.RegionServer/world/Avatar.cs
deleted file mode 100644
index 30999fc..0000000
--- a/OpenSim/OpenSim.RegionServer/world/Avatar.cs
+++ /dev/null
@@ -1,482 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
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 OpenSim Project 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 THE DEVELOPERS ``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 THE CONTRIBUTORS 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*/
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Text;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Physics.Manager;
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Interfaces;
37using Axiom.MathLib;
38
39namespace OpenSim.world
40{
41 public partial class Avatar : Entity
42 {
43 public static bool PhysicsEngineFlying = false;
44 public static AvatarAnimations Animations;
45 public string firstname;
46 public string lastname;
47 public ClientView ControllingClient;
48 public LLUUID current_anim;
49 public int anim_seq;
50 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
51 private bool updateflag = false;
52 private byte movementflag = 0;
53 private List<NewForce> forcesList = new List<NewForce>();
54 private short _updateCount = 0;
55 private Axiom.MathLib.Quaternion bodyRot;
56 private LLObject.TextureEntry avatarAppearanceTexture = null;
57 private byte[] visualParams;
58 private AvatarWearable[] Wearables;
59 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
60 private LLVector3 positionFrameBeforeLast = new LLVector3(0, 0, 0);
61
62 private int positionRoundedX = 0;
63 private int positionRoundedY = 0;
64
65 private int positionParcelHoverLocalID = -1; //Local ID of the last parcel they were over
66 private int parcelUpdateSequenceIncrement = 1;
67 private ulong m_regionHandle;
68 //private Dictionary<uint, ClientView> m_clientThreads;
69 private string m_regionName;
70 private ushort m_regionWaterHeight;
71 private bool m_regionTerraform;
72 private bool childAvatar = false;
73
74 public Avatar(ClientView TheClient, World world, string regionName, Dictionary<uint, ClientView> clientThreads, ulong regionHandle, bool regionTerraform, ushort regionWater)
75 {
76 m_world = world;
77 // m_clientThreads = clientThreads;
78 m_regionName = regionName;
79 m_regionHandle = regionHandle;
80 m_regionTerraform = regionTerraform;
81 m_regionWaterHeight = regionWater;
82
83 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs - Loading details from grid (DUMMY)");
84 ControllingClient = TheClient;
85 localid = 8880000 + (this.m_world._localNumber++);
86 Pos = ControllingClient.startpos;
87 visualParams = new byte[218];
88 for (int i = 0; i < 218; i++)
89 {
90 visualParams[i] = 100;
91 }
92 Wearables = new AvatarWearable[13]; //should be 13 of these
93 for (int i = 0; i < 13; i++)
94 {
95 Wearables[i] = new AvatarWearable();
96 }
97 this.Wearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
98 this.Wearables[0].ItemID = LLUUID.Random();
99
100 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
101
102 //register for events
103 ControllingClient.OnRequestWearables += new ClientView.GenericCall(this.SendOurAppearance);
104 ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
105 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.CompleteMovement);
106 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.SendInitialPosition);
107 ControllingClient.OnAgentUpdate += new ClientView.GenericCall3(this.HandleAgentUpdate);
108 ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
109 ControllingClient.OnChildAgentStatus += new ClientView.StatusChange(this.ChildStatusChange);
110
111 }
112
113 public PhysicsActor PhysActor
114 {
115 set
116 {
117 this._physActor = value;
118 }
119 get
120 {
121 return _physActor;
122 }
123 }
124
125 public void ChildStatusChange(bool status)
126 {
127 this.childAvatar = status;
128
129 if (this.childAvatar == true)
130 {
131 this._physActor.Velocity = new PhysicsVector(0, 0, 0);
132 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
133 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
134 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
135 terse.RegionData.TimeDilation = 64096;
136 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
137 terse.ObjectData[0] = terseBlock;
138 List<Avatar> avList = this.m_world.RequestAvatarList();
139 foreach (Avatar client in avList)
140 {
141 client.SendPacketToViewer(terse);
142 }
143 }
144 else
145 {
146 LLVector3 startp = ControllingClient.StartPos;
147 lock (m_world.LockPhysicsEngine)
148 {
149 this._physActor.Position = new PhysicsVector(startp.X, startp.Y, startp.Z);
150 }
151 }
152 }
153
154 public override void addForces()
155 {
156 lock (this.forcesList)
157 {
158 if (this.forcesList.Count > 0)
159 {
160 for (int i = 0; i < this.forcesList.Count; i++)
161 {
162 NewForce force = this.forcesList[i];
163 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
164 lock (m_world.LockPhysicsEngine)
165 {
166 this._physActor.Velocity = phyVector;
167 }
168 this.updateflag = true;
169 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
170 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
171 }
172 for (int i = 0; i < this.forcesList.Count; i++)
173 {
174 this.forcesList.RemoveAt(0);
175 }
176 }
177 }
178 }
179
180 public static void SetupTemplate(string name)
181 {
182 FileInfo fInfo = new FileInfo(name);
183 long numBytes = fInfo.Length;
184 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
185 BinaryReader br = new BinaryReader(fStream);
186 byte[] data1 = br.ReadBytes((int)numBytes);
187 br.Close();
188 fStream.Close();
189
190 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
191
192 SetDefaultPacketValues(objdata);
193 objdata.TextureEntry = data1;
194 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
195 objdata.PathCurve = 16;
196 objdata.ProfileCurve = 1;
197 objdata.PathScaleX = 100;
198 objdata.PathScaleY = 100;
199 objdata.ParentID = 0;
200 objdata.OwnerID = LLUUID.Zero;
201 objdata.Scale = new LLVector3(1, 1, 1);
202 objdata.PCode = 47;
203 System.Text.Encoding enc = System.Text.Encoding.ASCII;
204 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
205 pos.X = 100f;
206 objdata.ID = 8880000;
207 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
208 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
209 //objdata.FullID=user.AgentID;
210 byte[] pb = pos.GetBytes();
211 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
212
213 Avatar.AvatarTemplate = objdata;
214 }
215
216 protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
217 {
218 objdata.PSBlock = new byte[0];
219 objdata.ExtraParams = new byte[1];
220 objdata.MediaURL = new byte[0];
221 objdata.NameValue = new byte[0];
222 objdata.Text = new byte[0];
223 objdata.TextColor = new byte[4];
224 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
225 objdata.JointPivot = new LLVector3(0, 0, 0);
226 objdata.Material = 4;
227 objdata.TextureAnim = new byte[0];
228 objdata.Sound = LLUUID.Zero;
229 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
230 objdata.TextureEntry = ntex.ToBytes();
231 objdata.State = 0;
232 objdata.Data = new byte[0];
233
234 objdata.ObjectData = new byte[76];
235 objdata.ObjectData[15] = 128;
236 objdata.ObjectData[16] = 63;
237 objdata.ObjectData[56] = 128;
238 objdata.ObjectData[61] = 102;
239 objdata.ObjectData[62] = 40;
240 objdata.ObjectData[63] = 61;
241 objdata.ObjectData[64] = 189;
242
243
244 }
245
246 public void CompleteMovement()
247 {
248 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
249 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
250 mov.AgentData.SessionID = this.ControllingClient.SessionID;
251 mov.AgentData.AgentID = this.ControllingClient.AgentID;
252 mov.Data.RegionHandle = this.m_regionHandle;
253 // TODO - dynamicalise this stuff
254 mov.Data.Timestamp = 1172750370;
255 mov.Data.Position = this.ControllingClient.startpos;
256 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
257
258 ControllingClient.OutPacket(mov);
259 }
260
261 public void HandleAgentUpdate(Packet pack)
262 {
263 this.HandleUpdate((AgentUpdatePacket)pack);
264 }
265
266 public void HandleUpdate(AgentUpdatePacket pack)
267 {
268 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0)
269 {
270 if (this._physActor.Flying == false)
271 {
272 this.current_anim = Animations.AnimsLLUUID["FLY"];
273 this.anim_seq = 1;
274 this.SendAnimPack();
275 }
276 this._physActor.Flying = true;
277
278 }
279 else
280 {
281 if (this._physActor.Flying == true)
282 {
283 this.current_anim = Animations.AnimsLLUUID["STAND"];
284 this.anim_seq = 1;
285 this.SendAnimPack();
286 }
287 this._physActor.Flying = false;
288 }
289 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
290 {
291 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
292 if (((movementflag & 1) == 0) || (q != this.bodyRot))
293 {
294
295 if (((movementflag & 1) == 0) && (!this._physActor.Flying))
296 {
297 this.current_anim = Animations.AnimsLLUUID["WALK"];
298 this.anim_seq = 1;
299 this.SendAnimPack();
300 }
301
302
303 //we should add a new force to the list
304 // but for now we will deal with velocities
305 NewForce newVelocity = new NewForce();
306 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
307 Axiom.MathLib.Vector3 direc = q * v3;
308 direc.Normalize();
309
310 //work out velocity for sim physics system
311 direc = direc * ((0.03f) * 128f);
312 if (this._physActor.Flying)
313 direc *= 4;
314
315 newVelocity.X = direc.x;
316 newVelocity.Y = direc.y;
317 newVelocity.Z = direc.z;
318 this.forcesList.Add(newVelocity);
319 movementflag = 1;
320 this.bodyRot = q;
321 }
322 }
323 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
324 {
325 if (((movementflag & 2) == 0) && this._physActor.Flying)
326 {
327 //we should add a new force to the list
328 // but for now we will deal with velocities
329 NewForce newVelocity = new NewForce();
330 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
331 Axiom.MathLib.Vector3 direc = v3;
332 direc.Normalize();
333
334 //work out velocity for sim physics system
335 direc = direc * ((0.03f) * 128f * 2);
336 newVelocity.X = direc.x;
337 newVelocity.Y = direc.y;
338 newVelocity.Z = direc.z;
339 this.forcesList.Add(newVelocity);
340 movementflag = 2;
341 }
342 }
343 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
344 {
345 if (((movementflag & 4) == 0) && this._physActor.Flying)
346 {
347 //we should add a new force to the list
348 // but for now we will deal with velocities
349 NewForce newVelocity = new NewForce();
350 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
351 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
352 Axiom.MathLib.Vector3 direc = v3;
353 direc.Normalize();
354
355 //work out velocity for sim physics system
356 direc = direc * ((0.03f) * 128f * 2);
357 newVelocity.X = direc.x;
358 newVelocity.Y = direc.y;
359 newVelocity.Z = direc.z;
360 this.forcesList.Add(newVelocity);
361 movementflag = 4;
362 }
363 }
364 else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
365 {
366 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
367 if (((movementflag & 8) == 0) || (q != this.bodyRot))
368 {
369 //we should add a new force to the list
370 // but for now we will deal with velocities
371 NewForce newVelocity = new NewForce();
372 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
373 Axiom.MathLib.Vector3 direc = q * v3;
374 direc.Normalize();
375
376 //work out velocity for sim physics system
377 direc = direc * ((0.03f) * 128f);
378 if (this._physActor.Flying)
379 direc *= 2;
380
381 newVelocity.X = direc.x;
382 newVelocity.Y = direc.y;
383 newVelocity.Z = direc.z;
384 this.forcesList.Add(newVelocity);
385 movementflag = 8;
386 this.bodyRot = q;
387 }
388 }
389 else
390 {
391 if (movementflag == 16)
392 {
393 movementflag = 0;
394 }
395 if ((movementflag) != 0)
396 {
397 NewForce newVelocity = new NewForce();
398 newVelocity.X = 0;
399 newVelocity.Y = 0;
400 newVelocity.Z = 0;
401 this.forcesList.Add(newVelocity);
402 movementflag = 0;
403 // We're standing still, so make it show!
404 if (this._physActor.Flying == false)
405 {
406 this.current_anim = Animations.AnimsLLUUID["STAND"];
407 this.anim_seq = 1;
408 this.SendAnimPack();
409 }
410 this.movementflag = 16;
411
412 }
413 }
414 }
415
416 //really really should be moved somewhere else (RegionInfo.cs ?)
417 public void SendRegionHandshake(World regionInfo)
418 {
419 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
420 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
421 RegionHandshakePacket handshake = new RegionHandshakePacket();
422
423 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
424 handshake.RegionInfo.BillableFactor = 0;
425 handshake.RegionInfo.IsEstateManager = false;
426 handshake.RegionInfo.TerrainHeightRange00 = regionInfo.m_regInfo.TerrainHeightRange00;
427 handshake.RegionInfo.TerrainHeightRange01 = regionInfo.m_regInfo.TerrainHeightRange01;
428 handshake.RegionInfo.TerrainHeightRange10 = regionInfo.m_regInfo.TerrainHeightRange10;
429 handshake.RegionInfo.TerrainHeightRange11 = regionInfo.m_regInfo.TerrainHeightRange11;
430 handshake.RegionInfo.TerrainStartHeight00 = regionInfo.m_regInfo.TerrainStartHeight00;
431 handshake.RegionInfo.TerrainStartHeight01 = regionInfo.m_regInfo.TerrainStartHeight01;
432 handshake.RegionInfo.TerrainStartHeight10 = regionInfo.m_regInfo.TerrainStartHeight10;
433 handshake.RegionInfo.TerrainStartHeight11 = regionInfo.m_regInfo.TerrainStartHeight11;
434 handshake.RegionInfo.SimAccess = 13;
435 handshake.RegionInfo.WaterHeight = m_regionWaterHeight;
436 uint regionFlags = 72458694;
437 if (this.m_regionTerraform)
438 {
439 regionFlags -= 64;
440 }
441 handshake.RegionInfo.RegionFlags = regionFlags;
442 handshake.RegionInfo.SimName = _enc.GetBytes(m_regionName + "\0");
443 handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
444 handshake.RegionInfo.TerrainBase0 = regionInfo.m_regInfo.TerrainBase0;
445 handshake.RegionInfo.TerrainBase1 = regionInfo.m_regInfo.TerrainBase1;
446 handshake.RegionInfo.TerrainBase2 = regionInfo.m_regInfo.TerrainBase2;
447 handshake.RegionInfo.TerrainBase3 = regionInfo.m_regInfo.TerrainBase3;
448 handshake.RegionInfo.TerrainDetail0 = regionInfo.m_regInfo.TerrainDetail0;
449 handshake.RegionInfo.TerrainDetail1 = regionInfo.m_regInfo.TerrainDetail1;
450 handshake.RegionInfo.TerrainDetail2 = regionInfo.m_regInfo.TerrainDetail2;
451 handshake.RegionInfo.TerrainDetail3 = regionInfo.m_regInfo.TerrainDetail3;
452 handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
453
454 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
455 this.ControllingClient.OutPacket(handshake);
456 }
457
458 public static void LoadAnims()
459 {
460 Avatar.Animations = new AvatarAnimations();
461 Avatar.Animations.LoadAnims();
462 }
463
464 public override void LandRenegerated()
465 {
466 Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f);
467 }
468 }
469
470 public class NewForce
471 {
472 public float X;
473 public float Y;
474 public float Z;
475
476 public NewForce()
477 {
478
479 }
480 }
481
482}