aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/world/AvatarUpdate.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.RegionServer/world/AvatarUpdate.cs')
-rw-r--r--OpenSim.RegionServer/world/AvatarUpdate.cs279
1 files changed, 279 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/AvatarUpdate.cs b/OpenSim.RegionServer/world/AvatarUpdate.cs
new file mode 100644
index 0000000..d20ba28
--- /dev/null
+++ b/OpenSim.RegionServer/world/AvatarUpdate.cs
@@ -0,0 +1,279 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using libsecondlife.Packets;
6
7namespace OpenSim.world
8{
9 partial class Avatar
10 {
11 public override void update()
12 {
13 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
14 if (this.updateflag)
15 {
16 //need to send movement info
17 //so create the improvedterseobjectupdate packet
18 //use CreateTerseBlock()
19 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
20 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
21 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
22 terse.RegionData.TimeDilation = 64096;
23 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
24 terse.ObjectData[0] = terseBlock;
25 foreach (SimClient client in m_clientThreads.Values)
26 {
27 client.OutPacket(terse);
28 }
29
30 updateflag = false;
31 //this._updateCount = 0;
32 }
33 else
34 {
35
36 if ((pos2 != this.positionLastFrame) || (this.movementflag == 16))
37 {
38 _updateCount++;
39 if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0))
40 {
41 //It has been a while since last update was sent so lets send one.
42 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
43 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
44 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
45 terse.RegionData.TimeDilation = 64096;
46 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
47 terse.ObjectData[0] = terseBlock;
48 foreach (SimClient client in m_clientThreads.Values)
49 {
50 client.OutPacket(terse);
51 }
52 _updateCount = 0;
53 }
54
55 if (this.movementflag == 16)
56 {
57 movementflag = 0;
58 }
59 }
60
61 }
62 this.positionLastFrame = pos2;
63 }
64
65 public ObjectUpdatePacket CreateUpdatePacket()
66 {
67 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
68 //send a objectupdate packet with information about the clients avatar
69 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
70 objupdate.RegionData.RegionHandle = m_regionHandle;
71 objupdate.RegionData.TimeDilation = 64096;
72 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
73
74 objupdate.ObjectData[0] = AvatarTemplate;
75 //give this avatar object a local id and assign the user a name
76 objupdate.ObjectData[0].ID = this.localid;
77 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
78 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
79
80 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
81
82 byte[] pb = pos2.GetBytes();
83
84 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
85 return objupdate;
86 }
87
88 public void SendInitialPosition()
89 {
90 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
91 //send a objectupdate packet with information about the clients avatar
92 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
93 objupdate.RegionData.RegionHandle = m_regionHandle;
94 objupdate.RegionData.TimeDilation = 64096;
95 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
96
97 objupdate.ObjectData[0] = AvatarTemplate;
98 //give this avatar object a local id and assign the user a name
99 objupdate.ObjectData[0].ID = this.localid;
100 this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
101 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
102 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z);
103 byte[] pb = pos2.GetBytes();
104 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
105 m_world._localNumber++;
106
107 foreach (SimClient client in m_clientThreads.Values)
108 {
109 client.OutPacket(objupdate);
110 if (client.AgentID != ControllingClient.AgentID)
111 {
112 SendAppearanceToOtherAgent(client);
113 }
114 }
115 }
116
117 public void SendInitialAppearance()
118 {
119 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
120 aw.AgentData.AgentID = this.ControllingClient.AgentID;
121 aw.AgentData.SerialNum = 0;
122 aw.AgentData.SessionID = ControllingClient.SessionID;
123
124 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
125 AgentWearablesUpdatePacket.WearableDataBlock awb;
126 for (int i = 0; i < 13; i++)
127 {
128 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
129 awb.WearableType = (byte)i;
130 awb.AssetID = this.Wearables[i].AssetID;
131 awb.ItemID = this.Wearables[i].ItemID;
132 aw.WearableData[i] = awb;
133 }
134
135 ControllingClient.OutPacket(aw);
136 }
137
138 public void SendAppearanceToOtherAgent(SimClient userInfo)
139 {
140 AvatarAppearancePacket avp = new AvatarAppearancePacket();
141 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
142 avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes();
143
144 AvatarAppearancePacket.VisualParamBlock avblock = null;
145 for (int i = 0; i < 218; i++)
146 {
147 avblock = new AvatarAppearancePacket.VisualParamBlock();
148 avblock.ParamValue = visualParams[i];
149 avp.VisualParam[i] = avblock;
150 }
151
152 avp.Sender.IsTrial = false;
153 avp.Sender.ID = ControllingClient.AgentID;
154 userInfo.OutPacket(avp);
155 }
156
157 public void SetAppearance(AgentSetAppearancePacket appear)
158 {
159 LLObject.TextureEntry tex = new LLObject.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
160 this.avatarAppearanceTexture = tex;
161 for (int i = 0; i < appear.VisualParam.Length; i++)
162 {
163 this.visualParams[i] = appear.VisualParam[i].ParamValue;
164 }
165 foreach (SimClient client in m_clientThreads.Values)
166 {
167 if (client.AgentID != ControllingClient.AgentID)
168 {
169 SendAppearanceToOtherAgent(client);
170 }
171 }
172 }
173
174 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
175 {
176 byte[] bytes = new byte[60];
177 int i = 0;
178 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
179
180 dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry;
181 libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0);
182 lock (m_world.LockPhysicsEngine)
183 {
184 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
185 }
186
187 uint ID = this.localid;
188
189 bytes[i++] = (byte)(ID % 256);
190 bytes[i++] = (byte)((ID >> 8) % 256);
191 bytes[i++] = (byte)((ID >> 16) % 256);
192 bytes[i++] = (byte)((ID >> 24) % 256);
193 bytes[i++] = 0;
194 bytes[i++] = 1;
195 i += 14;
196 bytes[i++] = 128;
197 bytes[i++] = 63;
198
199 byte[] pb = pos2.GetBytes();
200 Array.Copy(pb, 0, bytes, i, pb.Length);
201 i += 12;
202 ushort InternVelocityX;
203 ushort InternVelocityY;
204 ushort InternVelocityZ;
205 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0);
206 lock (m_world.LockPhysicsEngine)
207 {
208 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
209 }
210 internDirec = internDirec / 128.0f;
211 internDirec.x += 1;
212 internDirec.y += 1;
213 internDirec.z += 1;
214
215 InternVelocityX = (ushort)(32768 * internDirec.x);
216 InternVelocityY = (ushort)(32768 * internDirec.y);
217 InternVelocityZ = (ushort)(32768 * internDirec.z);
218
219 ushort ac = 32767;
220 bytes[i++] = (byte)(InternVelocityX % 256);
221 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
222 bytes[i++] = (byte)(InternVelocityY % 256);
223 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
224 bytes[i++] = (byte)(InternVelocityZ % 256);
225 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
226
227 //accel
228 bytes[i++] = (byte)(ac % 256);
229 bytes[i++] = (byte)((ac >> 8) % 256);
230 bytes[i++] = (byte)(ac % 256);
231 bytes[i++] = (byte)((ac >> 8) % 256);
232 bytes[i++] = (byte)(ac % 256);
233 bytes[i++] = (byte)((ac >> 8) % 256);
234
235 //rot
236 bytes[i++] = (byte)(ac % 256);
237 bytes[i++] = (byte)((ac >> 8) % 256);
238 bytes[i++] = (byte)(ac % 256);
239 bytes[i++] = (byte)((ac >> 8) % 256);
240 bytes[i++] = (byte)(ac % 256);
241 bytes[i++] = (byte)((ac >> 8) % 256);
242 bytes[i++] = (byte)(ac % 256);
243 bytes[i++] = (byte)((ac >> 8) % 256);
244
245 //rotation vel
246 bytes[i++] = (byte)(ac % 256);
247 bytes[i++] = (byte)((ac >> 8) % 256);
248 bytes[i++] = (byte)(ac % 256);
249 bytes[i++] = (byte)((ac >> 8) % 256);
250 bytes[i++] = (byte)(ac % 256);
251 bytes[i++] = (byte)((ac >> 8) % 256);
252
253 dat.Data = bytes;
254 return (dat);
255 }
256
257 // Sends animation update
258 public void SendAnimPack()
259 {
260 AvatarAnimationPacket ani = new AvatarAnimationPacket();
261 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
262 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
263 ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID;
264 ani.Sender = new AvatarAnimationPacket.SenderBlock();
265 ani.Sender.ID = ControllingClient.AgentID;
266 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1];
267 ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock();
268 ani.AnimationList[0].AnimID = this.current_anim;
269 ani.AnimationList[0].AnimSequenceID = this.anim_seq;
270
271 //ControllingClient.OutPacket(ani);
272 foreach (SimClient client in m_clientThreads.Values)
273 {
274 client.OutPacket(ani);
275 }
276 }
277
278 }
279}