diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientView.API.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/ClientView.API.cs | 1122 |
1 files changed, 1122 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs new file mode 100644 index 0000000..225e906 --- /dev/null +++ b/OpenSim/Region/ClientStack/ClientView.API.cs | |||
@@ -0,0 +1,1122 @@ | |||
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 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using Axiom.Math; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | |||
39 | namespace OpenSim.Region.ClientStack | ||
40 | { | ||
41 | partial class ClientView | ||
42 | { | ||
43 | public event ImprovedInstantMessage OnInstantMessage; | ||
44 | public event ChatFromViewer OnChatFromViewer; | ||
45 | public event RezObject OnRezObject; | ||
46 | public event GenericCall4 OnDeRezObject; | ||
47 | public event ModifyTerrain OnModifyTerrain; | ||
48 | public event GenericCall OnRegionHandShakeReply; | ||
49 | public event GenericCall OnRequestWearables; | ||
50 | public event SetAppearance OnSetAppearance; | ||
51 | public event GenericCall2 OnCompleteMovementToRegion; | ||
52 | public event UpdateAgent OnAgentUpdate; | ||
53 | public event StartAnim OnStartAnim; | ||
54 | public event GenericCall OnRequestAvatarsData; | ||
55 | public event LinkObjects OnLinkObjects; | ||
56 | public event UpdateVector OnGrapObject; | ||
57 | public event ObjectSelect OnDeGrapObject; | ||
58 | public event ObjectDuplicate OnObjectDuplicate; | ||
59 | public event MoveObject OnGrapUpdate; | ||
60 | public event GenericCall4 OnAddPrim; | ||
61 | public event UpdateShape OnUpdatePrimShape; | ||
62 | public event ObjectSelect OnObjectSelect; | ||
63 | public event GenericCall7 OnObjectDescription; | ||
64 | public event GenericCall7 OnObjectName; | ||
65 | public event UpdatePrimFlags OnUpdatePrimFlags; | ||
66 | public event UpdatePrimTexture OnUpdatePrimTexture; | ||
67 | public event UpdateVector OnUpdatePrimGroupPosition; | ||
68 | public event UpdateVector OnUpdatePrimSinglePosition; | ||
69 | public event UpdatePrimRotation OnUpdatePrimGroupRotation; | ||
70 | public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation; | ||
71 | public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation; | ||
72 | public event UpdateVector OnUpdatePrimScale; | ||
73 | public event StatusChange OnChildAgentStatus; | ||
74 | public event GenericCall2 OnStopMovement; | ||
75 | public event NewAvatar OnNewAvatar; | ||
76 | public event GenericCall6 OnRemoveAvatar; | ||
77 | public event RequestMapBlocks OnRequestMapBlocks; | ||
78 | public event TeleportLocationRequest OnTeleportLocationRequest; | ||
79 | |||
80 | public event UUIDNameRequest OnNameFromUUIDRequest; | ||
81 | |||
82 | public event ParcelPropertiesRequest OnParcelPropertiesRequest; | ||
83 | public event ParcelDivideRequest OnParcelDivideRequest; | ||
84 | public event ParcelJoinRequest OnParcelJoinRequest; | ||
85 | public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest; | ||
86 | |||
87 | public event EstateOwnerMessageRequest OnEstateOwnerMessage; | ||
88 | /// <summary> | ||
89 | /// | ||
90 | /// </summary> | ||
91 | public LLVector3 StartPos | ||
92 | { | ||
93 | get | ||
94 | { | ||
95 | return startpos; | ||
96 | } | ||
97 | set | ||
98 | { | ||
99 | startpos = value; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /// <summary> | ||
104 | /// | ||
105 | /// </summary> | ||
106 | public LLUUID AgentId | ||
107 | { | ||
108 | get | ||
109 | { | ||
110 | return this.AgentID; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// | ||
116 | /// </summary> | ||
117 | public string FirstName | ||
118 | { | ||
119 | get | ||
120 | { | ||
121 | return this.firstName; | ||
122 | } | ||
123 | |||
124 | } | ||
125 | |||
126 | /// <summary> | ||
127 | /// | ||
128 | /// </summary> | ||
129 | public string LastName | ||
130 | { | ||
131 | get | ||
132 | { | ||
133 | return this.lastName; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | #region World/Avatar to Client | ||
138 | |||
139 | /// <summary> | ||
140 | /// | ||
141 | /// </summary> | ||
142 | /// <param name="regionInfo"></param> | ||
143 | public void SendRegionHandshake(RegionInfo regionInfo) | ||
144 | { | ||
145 | Encoding _enc = Encoding.ASCII; | ||
146 | RegionHandshakePacket handshake = new RegionHandshakePacket(); | ||
147 | |||
148 | handshake.RegionInfo.BillableFactor = regionInfo.estateSettings.billableFactor; | ||
149 | handshake.RegionInfo.IsEstateManager = false; | ||
150 | handshake.RegionInfo.TerrainHeightRange00 = regionInfo.estateSettings.terrainHeightRange0; | ||
151 | handshake.RegionInfo.TerrainHeightRange01 = regionInfo.estateSettings.terrainHeightRange1; | ||
152 | handshake.RegionInfo.TerrainHeightRange10 = regionInfo.estateSettings.terrainHeightRange2; | ||
153 | handshake.RegionInfo.TerrainHeightRange11 = regionInfo.estateSettings.terrainHeightRange3; | ||
154 | handshake.RegionInfo.TerrainStartHeight00 = regionInfo.estateSettings.terrainStartHeight0; | ||
155 | handshake.RegionInfo.TerrainStartHeight01 = regionInfo.estateSettings.terrainStartHeight1; | ||
156 | handshake.RegionInfo.TerrainStartHeight10 = regionInfo.estateSettings.terrainStartHeight2; | ||
157 | handshake.RegionInfo.TerrainStartHeight11 = regionInfo.estateSettings.terrainStartHeight3; | ||
158 | handshake.RegionInfo.SimAccess = (byte)regionInfo.estateSettings.simAccess; | ||
159 | handshake.RegionInfo.WaterHeight = regionInfo.estateSettings.waterHeight; | ||
160 | |||
161 | |||
162 | handshake.RegionInfo.RegionFlags = (uint)regionInfo.estateSettings.regionFlags; | ||
163 | |||
164 | handshake.RegionInfo.SimName = _enc.GetBytes(regionInfo.RegionName + "\0"); | ||
165 | handshake.RegionInfo.SimOwner = regionInfo.MasterAvatarAssignedUUID; | ||
166 | handshake.RegionInfo.TerrainBase0 = regionInfo.estateSettings.terrainBase0; | ||
167 | handshake.RegionInfo.TerrainBase1 = regionInfo.estateSettings.terrainBase1; | ||
168 | handshake.RegionInfo.TerrainBase2 = regionInfo.estateSettings.terrainBase2; | ||
169 | handshake.RegionInfo.TerrainBase3 = regionInfo.estateSettings.terrainBase3; | ||
170 | handshake.RegionInfo.TerrainDetail0 = regionInfo.estateSettings.terrainDetail0; | ||
171 | handshake.RegionInfo.TerrainDetail1 = regionInfo.estateSettings.terrainDetail1; | ||
172 | handshake.RegionInfo.TerrainDetail2 = regionInfo.estateSettings.terrainDetail2; | ||
173 | handshake.RegionInfo.TerrainDetail3 = regionInfo.estateSettings.terrainDetail3; | ||
174 | handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting? | ||
175 | |||
176 | this.OutPacket(handshake); | ||
177 | } | ||
178 | |||
179 | /// <summary> | ||
180 | /// | ||
181 | /// </summary> | ||
182 | /// <param name="regInfo"></param> | ||
183 | public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look) | ||
184 | { | ||
185 | AgentMovementCompletePacket mov = new AgentMovementCompletePacket(); | ||
186 | mov.AgentData.SessionID = this.SessionID; | ||
187 | mov.AgentData.AgentID = this.AgentID; | ||
188 | mov.Data.RegionHandle = regInfo.RegionHandle; | ||
189 | mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this | ||
190 | |||
191 | if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0)) | ||
192 | { | ||
193 | mov.Data.Position = this.startpos; | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | mov.Data.Position = pos; | ||
198 | } | ||
199 | mov.Data.LookAt = look; | ||
200 | |||
201 | OutPacket(mov); | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// | ||
206 | /// </summary> | ||
207 | /// <param name="message"></param> | ||
208 | /// <param name="type"></param> | ||
209 | /// <param name="fromPos"></param> | ||
210 | /// <param name="fromName"></param> | ||
211 | /// <param name="fromAgentID"></param> | ||
212 | public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) | ||
213 | { | ||
214 | SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID); | ||
215 | } | ||
216 | |||
217 | /// <summary> | ||
218 | /// | ||
219 | /// </summary> | ||
220 | /// <param name="message"></param> | ||
221 | /// <param name="type"></param> | ||
222 | /// <param name="fromPos"></param> | ||
223 | /// <param name="fromName"></param> | ||
224 | /// <param name="fromAgentID"></param> | ||
225 | public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) | ||
226 | { | ||
227 | Encoding enc = Encoding.ASCII; | ||
228 | ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); | ||
229 | reply.ChatData.Audible = 1; | ||
230 | reply.ChatData.Message = message; | ||
231 | reply.ChatData.ChatType = type; | ||
232 | reply.ChatData.SourceType = 1; | ||
233 | reply.ChatData.Position = fromPos; | ||
234 | reply.ChatData.FromName = enc.GetBytes(fromName + "\0"); | ||
235 | reply.ChatData.OwnerID = fromAgentID; | ||
236 | reply.ChatData.SourceID = fromAgentID; | ||
237 | |||
238 | this.OutPacket(reply); | ||
239 | } | ||
240 | |||
241 | /// <summary> | ||
242 | /// | ||
243 | /// </summary> | ||
244 | /// <remarks>TODO</remarks> | ||
245 | /// <param name="message"></param> | ||
246 | /// <param name="target"></param> | ||
247 | public void SendInstantMessage(string message, LLUUID target) | ||
248 | { | ||
249 | ImprovedInstantMessagePacket msg = new ImprovedInstantMessagePacket(); | ||
250 | msg.AgentData.AgentID = this.AgentID; | ||
251 | msg.AgentData.SessionID = this.SessionID; | ||
252 | |||
253 | msg.MessageBlock.Dialog = 0; | ||
254 | msg.MessageBlock.FromGroup = false; | ||
255 | msg.MessageBlock.ID = target.Combine(this.AgentID); | ||
256 | msg.MessageBlock.Offline = 0; | ||
257 | msg.MessageBlock.ParentEstateID = 0; | ||
258 | msg.MessageBlock.Position = new LLVector3(); | ||
259 | msg.MessageBlock.RegionID = new LLUUID(); | ||
260 | msg.MessageBlock.Timestamp = 0; | ||
261 | msg.MessageBlock.ToAgentID = target; | ||
262 | |||
263 | this.OutPacket(msg); | ||
264 | } | ||
265 | |||
266 | /// <summary> | ||
267 | /// Send the region heightmap to the client | ||
268 | /// </summary> | ||
269 | /// <param name="map">heightmap</param> | ||
270 | public virtual void SendLayerData(float[] map) | ||
271 | { | ||
272 | try | ||
273 | { | ||
274 | int[] patches = new int[4]; | ||
275 | |||
276 | for (int y = 0; y < 16; y++) | ||
277 | { | ||
278 | for (int x = 0; x < 16; x = x + 4) | ||
279 | { | ||
280 | patches[0] = x + 0 + y * 16; | ||
281 | patches[1] = x + 1 + y * 16; | ||
282 | patches[2] = x + 2 + y * 16; | ||
283 | patches[3] = x + 3 + y * 16; | ||
284 | |||
285 | Packet layerpack = TerrainManager.CreateLandPacket(map, patches); | ||
286 | OutPacket(layerpack); | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | catch (Exception e) | ||
291 | { | ||
292 | MainLog.Instance.Warn("ClientView API.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | /// <summary> | ||
297 | /// Sends a specified patch to a client | ||
298 | /// </summary> | ||
299 | /// <param name="px">Patch coordinate (x) 0..16</param> | ||
300 | /// <param name="py">Patch coordinate (y) 0..16</param> | ||
301 | /// <param name="map">heightmap</param> | ||
302 | public void SendLayerData(int px, int py, float[] map) | ||
303 | { | ||
304 | try | ||
305 | { | ||
306 | int[] patches = new int[1]; | ||
307 | int patchx, patchy; | ||
308 | patchx = px / 16; | ||
309 | patchy = py / 16; | ||
310 | |||
311 | patches[0] = patchx + 0 + patchy * 16; | ||
312 | |||
313 | Packet layerpack = TerrainManager.CreateLandPacket(map, patches); | ||
314 | OutPacket(layerpack); | ||
315 | } | ||
316 | catch (Exception e) | ||
317 | { | ||
318 | MainLog.Instance.Warn("ClientView API .cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
319 | } | ||
320 | } | ||
321 | |||
322 | /// <summary> | ||
323 | /// | ||
324 | /// </summary> | ||
325 | /// <param name="neighbourHandle"></param> | ||
326 | /// <param name="neighbourIP"></param> | ||
327 | /// <param name="neighbourPort"></param> | ||
328 | public void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint ) | ||
329 | { | ||
330 | IPAddress neighbourIP = neighbourEndPoint.Address; | ||
331 | ushort neighbourPort = (ushort) neighbourEndPoint.Port; | ||
332 | |||
333 | EnableSimulatorPacket enablesimpacket = new EnableSimulatorPacket(); | ||
334 | enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock(); | ||
335 | enablesimpacket.SimulatorInfo.Handle = neighbourHandle; | ||
336 | |||
337 | byte[] byteIP = neighbourIP.GetAddressBytes(); | ||
338 | enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24; | ||
339 | enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16; | ||
340 | enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8; | ||
341 | enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0]; | ||
342 | enablesimpacket.SimulatorInfo.Port = neighbourPort; | ||
343 | OutPacket(enablesimpacket); | ||
344 | } | ||
345 | |||
346 | /// <summary> | ||
347 | /// | ||
348 | /// </summary> | ||
349 | /// <returns></returns> | ||
350 | public AgentCircuitData RequestClientInfo() | ||
351 | { | ||
352 | AgentCircuitData agentData = new AgentCircuitData(); | ||
353 | agentData.AgentID = this.AgentId; | ||
354 | agentData.SessionID = this.SessionID; | ||
355 | agentData.SecureSessionID = this.SecureSessionID; | ||
356 | agentData.circuitcode = this.CircuitCode; | ||
357 | agentData.child = false; | ||
358 | agentData.firstname = this.firstName; | ||
359 | agentData.lastname = this.lastName; | ||
360 | |||
361 | return agentData; | ||
362 | } | ||
363 | |||
364 | public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint externalIPEndPoint) | ||
365 | { | ||
366 | LLVector3 look = new LLVector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10); | ||
367 | |||
368 | CrossedRegionPacket newSimPack = new CrossedRegionPacket(); | ||
369 | newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock(); | ||
370 | newSimPack.AgentData.AgentID = this.AgentID; | ||
371 | newSimPack.AgentData.SessionID = this.SessionID; | ||
372 | newSimPack.Info = new CrossedRegionPacket.InfoBlock(); | ||
373 | newSimPack.Info.Position = pos; | ||
374 | newSimPack.Info.LookAt = look; // new LLVector3(0.0f, 0.0f, 0.0f); // copied from Avatar.cs - SHOULD BE DYNAMIC!!!!!!!!!! | ||
375 | newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock(); | ||
376 | newSimPack.RegionData.RegionHandle = newRegionHandle; | ||
377 | byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes(); | ||
378 | newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24; | ||
379 | newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16; | ||
380 | newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8; | ||
381 | newSimPack.RegionData.SimIP += (uint)byteIP[0]; | ||
382 | newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port; | ||
383 | newSimPack.RegionData.SeedCapability = new byte[0]; | ||
384 | |||
385 | this.OutPacket(newSimPack); | ||
386 | //this.DowngradeClient(); | ||
387 | } | ||
388 | |||
389 | public void SendMapBlock(List<MapBlockData> mapBlocks) | ||
390 | { | ||
391 | Encoding _enc = Encoding.ASCII; | ||
392 | |||
393 | MapBlockReplyPacket mapReply = new MapBlockReplyPacket(); | ||
394 | mapReply.AgentData.AgentID = this.AgentID; | ||
395 | mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count]; | ||
396 | mapReply.AgentData.Flags = 0; | ||
397 | |||
398 | for (int i = 0; i < mapBlocks.Count; i++) | ||
399 | { | ||
400 | mapReply.Data[i] = new MapBlockReplyPacket.DataBlock(); | ||
401 | mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId; | ||
402 | mapReply.Data[i].X = mapBlocks[i].X; | ||
403 | mapReply.Data[i].Y = mapBlocks[i].Y; | ||
404 | mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight; | ||
405 | mapReply.Data[i].Name = _enc.GetBytes(mapBlocks[i].Name); | ||
406 | mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags; | ||
407 | mapReply.Data[i].Access = mapBlocks[i].Access; | ||
408 | mapReply.Data[i].Agents = mapBlocks[i].Agents; | ||
409 | } | ||
410 | this.OutPacket(mapReply); | ||
411 | } | ||
412 | |||
413 | public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags) | ||
414 | { | ||
415 | TeleportLocalPacket tpLocal = new TeleportLocalPacket(); | ||
416 | tpLocal.Info.AgentID = this.AgentID; | ||
417 | tpLocal.Info.TeleportFlags = flags; | ||
418 | tpLocal.Info.LocationID = 2; | ||
419 | tpLocal.Info.LookAt = lookAt; | ||
420 | tpLocal.Info.Position = position; | ||
421 | OutPacket(tpLocal); | ||
422 | } | ||
423 | |||
424 | public void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID, uint flags) | ||
425 | { | ||
426 | TeleportFinishPacket teleport = new TeleportFinishPacket(); | ||
427 | teleport.Info.AgentID = this.AgentID; | ||
428 | teleport.Info.RegionHandle = regionHandle; | ||
429 | teleport.Info.SimAccess = simAccess; | ||
430 | teleport.Info.SeedCapability = new byte[0]; | ||
431 | |||
432 | IPAddress oIP = newRegionEndPoint.Address; | ||
433 | byte[] byteIP = oIP.GetAddressBytes(); | ||
434 | uint ip = (uint)byteIP[3] << 24; | ||
435 | ip += (uint)byteIP[2] << 16; | ||
436 | ip += (uint)byteIP[1] << 8; | ||
437 | ip += (uint)byteIP[0]; | ||
438 | |||
439 | teleport.Info.SimIP = ip; | ||
440 | teleport.Info.SimPort = (ushort)newRegionEndPoint.Port; | ||
441 | teleport.Info.LocationID = 4; | ||
442 | teleport.Info.TeleportFlags = 1 << 4; | ||
443 | OutPacket(teleport); | ||
444 | } | ||
445 | |||
446 | /// <summary> | ||
447 | /// | ||
448 | /// </summary> | ||
449 | public void SendTeleportCancel() | ||
450 | { | ||
451 | TeleportCancelPacket tpCancel = new TeleportCancelPacket(); | ||
452 | tpCancel.Info.SessionID = this.SessionID; | ||
453 | tpCancel.Info.AgentID = this.AgentID; | ||
454 | |||
455 | OutPacket(tpCancel); | ||
456 | } | ||
457 | |||
458 | /// <summary> | ||
459 | /// | ||
460 | /// </summary> | ||
461 | public void SendTeleportLocationStart() | ||
462 | { | ||
463 | TeleportStartPacket tpStart = new TeleportStartPacket(); | ||
464 | tpStart.Info.TeleportFlags = 16; // Teleport via location | ||
465 | OutPacket(tpStart); | ||
466 | } | ||
467 | |||
468 | public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance) | ||
469 | { | ||
470 | MoneyBalanceReplyPacket money = new MoneyBalanceReplyPacket(); | ||
471 | money.MoneyData.AgentID = this.AgentID; | ||
472 | money.MoneyData.TransactionID = transaction; | ||
473 | money.MoneyData.TransactionSuccess = success; | ||
474 | money.MoneyData.Description = description; | ||
475 | money.MoneyData.MoneyBalance = balance; | ||
476 | OutPacket(money); | ||
477 | } | ||
478 | |||
479 | public void SendStartPingCheck(byte seq) | ||
480 | { | ||
481 | StartPingCheckPacket pc = new StartPingCheckPacket(); | ||
482 | pc.PingID.PingID = seq; | ||
483 | OutPacket(pc); | ||
484 | } | ||
485 | |||
486 | public void SendKillObject(ulong regionHandle, uint avatarLocalID) | ||
487 | { | ||
488 | KillObjectPacket kill = new KillObjectPacket(); | ||
489 | kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; | ||
490 | kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); | ||
491 | kill.ObjectData[0].ID = avatarLocalID; | ||
492 | OutPacket(kill); | ||
493 | } | ||
494 | |||
495 | |||
496 | #region Appearance/ Wearables Methods | ||
497 | |||
498 | /// <summary> | ||
499 | /// | ||
500 | /// </summary> | ||
501 | /// <param name="wearables"></param> | ||
502 | public void SendWearables(AvatarWearable[] wearables) | ||
503 | { | ||
504 | AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); | ||
505 | aw.AgentData.AgentID = this.AgentID; | ||
506 | aw.AgentData.SerialNum = 0; | ||
507 | aw.AgentData.SessionID = this.SessionID; | ||
508 | |||
509 | aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; | ||
510 | AgentWearablesUpdatePacket.WearableDataBlock awb; | ||
511 | for (int i = 0; i < wearables.Length; i++) | ||
512 | { | ||
513 | awb = new AgentWearablesUpdatePacket.WearableDataBlock(); | ||
514 | awb.WearableType = (byte)i; | ||
515 | awb.AssetID = wearables[i].AssetID; | ||
516 | awb.ItemID = wearables[i].ItemID; | ||
517 | aw.WearableData[i] = awb; | ||
518 | } | ||
519 | |||
520 | this.OutPacket(aw); | ||
521 | } | ||
522 | |||
523 | /// <summary> | ||
524 | /// | ||
525 | /// </summary> | ||
526 | /// <param name="agentID"></param> | ||
527 | /// <param name="visualParams"></param> | ||
528 | /// <param name="textureEntry"></param> | ||
529 | public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry) | ||
530 | { | ||
531 | AvatarAppearancePacket avp = new AvatarAppearancePacket(); | ||
532 | avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218]; | ||
533 | avp.ObjectData.TextureEntry = textureEntry; | ||
534 | |||
535 | AvatarAppearancePacket.VisualParamBlock avblock = null; | ||
536 | for (int i = 0; i < visualParams.Length; i++) | ||
537 | { | ||
538 | avblock = new AvatarAppearancePacket.VisualParamBlock(); | ||
539 | avblock.ParamValue = visualParams[i]; | ||
540 | avp.VisualParam[i] = avblock; | ||
541 | } | ||
542 | |||
543 | avp.Sender.IsTrial = false; | ||
544 | avp.Sender.ID = agentID; | ||
545 | OutPacket(avp); | ||
546 | } | ||
547 | |||
548 | public void SendAnimation(LLUUID animID, int seq, LLUUID sourceAgentId) | ||
549 | { | ||
550 | AvatarAnimationPacket ani = new AvatarAnimationPacket(); | ||
551 | ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1]; | ||
552 | ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock(); | ||
553 | ani.AnimationSourceList[0].ObjectID = sourceAgentId; | ||
554 | ani.Sender = new AvatarAnimationPacket.SenderBlock(); | ||
555 | ani.Sender.ID = sourceAgentId; | ||
556 | ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1]; | ||
557 | ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock(); | ||
558 | ani.AnimationList[0].AnimID = animID; | ||
559 | ani.AnimationList[0].AnimSequenceID = seq; | ||
560 | this.OutPacket(ani); | ||
561 | } | ||
562 | |||
563 | #endregion | ||
564 | |||
565 | #region Avatar Packet/data sending Methods | ||
566 | |||
567 | /// <summary> | ||
568 | /// | ||
569 | /// </summary> | ||
570 | /// <param name="regionInfo"></param> | ||
571 | /// <param name="firstName"></param> | ||
572 | /// <param name="lastName"></param> | ||
573 | /// <param name="avatarID"></param> | ||
574 | /// <param name="avatarLocalID"></param> | ||
575 | /// <param name="Pos"></param> | ||
576 | public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos, byte[] textureEntry) | ||
577 | { | ||
578 | Encoding _enc = Encoding.ASCII; | ||
579 | //send a objectupdate packet with information about the clients avatar | ||
580 | |||
581 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
582 | objupdate.RegionData.RegionHandle = regionHandle; | ||
583 | objupdate.RegionData.TimeDilation = 64096; | ||
584 | objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
585 | objupdate.ObjectData[0] = this.CreateDefaultAvatarPacket(textureEntry); | ||
586 | //give this avatar object a local id and assign the user a name | ||
587 | |||
588 | objupdate.ObjectData[0].ID = avatarLocalID; | ||
589 | objupdate.ObjectData[0].FullID = avatarID; | ||
590 | objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName + " \0"); | ||
591 | LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z); | ||
592 | byte[] pb = pos2.GetBytes(); | ||
593 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); | ||
594 | |||
595 | OutPacket(objupdate); | ||
596 | |||
597 | } | ||
598 | |||
599 | /// <summary> | ||
600 | /// | ||
601 | /// </summary> | ||
602 | /// <param name="regionHandle"></param> | ||
603 | /// <param name="timeDilation"></param> | ||
604 | /// <param name="localID"></param> | ||
605 | /// <param name="position"></param> | ||
606 | /// <param name="velocity"></param> | ||
607 | public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity) | ||
608 | { | ||
609 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = this.CreateAvatarImprovedBlock(localID, position, velocity); | ||
610 | ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); | ||
611 | terse.RegionData.RegionHandle = regionHandle; | ||
612 | terse.RegionData.TimeDilation = timeDilation; | ||
613 | terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
614 | terse.ObjectData[0] = terseBlock; | ||
615 | |||
616 | this.OutPacket(terse); | ||
617 | } | ||
618 | |||
619 | #endregion | ||
620 | |||
621 | #region Primitive Packet/data Sending Methods | ||
622 | |||
623 | /// <summary> | ||
624 | /// | ||
625 | /// </summary> | ||
626 | /// <param name="localID"></param> | ||
627 | /// <param name="rotation"></param> | ||
628 | /// <param name="attachPoint"></param> | ||
629 | public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint) | ||
630 | { | ||
631 | ObjectAttachPacket attach = new ObjectAttachPacket(); | ||
632 | attach.AgentData.AgentID = this.AgentID; | ||
633 | attach.AgentData.SessionID = this.SessionID; | ||
634 | attach.AgentData.AttachmentPoint = attachPoint; | ||
635 | attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1]; | ||
636 | attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock(); | ||
637 | attach.ObjectData[0].ObjectLocalID = localID; | ||
638 | attach.ObjectData[0].Rotation = rotation; | ||
639 | |||
640 | this.OutPacket(attach); | ||
641 | } | ||
642 | |||
643 | /// <summary> | ||
644 | /// Sends a full ObjectUpdatePacket to a client to inform it of a new primitive | ||
645 | /// or big changes to a existing primitive. | ||
646 | /// </summary> | ||
647 | /// <param name="regionHandle"></param> | ||
648 | /// <param name="timeDilation"></param> | ||
649 | /// <param name="localID"></param> | ||
650 | /// <param name="primData"></param> | ||
651 | /// <param name="pos"></param> | ||
652 | /// <param name="rotation"></param> | ||
653 | /// <param name="textureID"></param> | ||
654 | public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags) | ||
655 | { | ||
656 | ObjectUpdatePacket outPacket = new ObjectUpdatePacket(); | ||
657 | outPacket.RegionData.RegionHandle = regionHandle; | ||
658 | outPacket.RegionData.TimeDilation = timeDilation; | ||
659 | outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
660 | outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primData, textureID, flags); | ||
661 | outPacket.ObjectData[0].ID = localID; | ||
662 | outPacket.ObjectData[0].FullID = primData.FullID; | ||
663 | byte[] pb = pos.GetBytes(); | ||
664 | Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
665 | byte[] rot = rotation.GetBytes(); | ||
666 | Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 48, rot.Length); | ||
667 | OutPacket(outPacket); | ||
668 | } | ||
669 | |||
670 | /// <summary> | ||
671 | /// Sends a full ObjectUpdatePacket to a client to inform it of a new primitive | ||
672 | /// or big changes to a existing primitive. | ||
673 | /// Uses default rotation | ||
674 | /// </summary> | ||
675 | /// <param name="primData"></param> | ||
676 | /// <param name="pos"></param> | ||
677 | public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID , uint flags) | ||
678 | { | ||
679 | ObjectUpdatePacket outPacket = new ObjectUpdatePacket(); | ||
680 | outPacket.RegionData.RegionHandle = regionHandle; | ||
681 | outPacket.RegionData.TimeDilation = timeDilation; | ||
682 | outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
683 | outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primData, textureID, flags); | ||
684 | outPacket.ObjectData[0].ID = localID; | ||
685 | outPacket.ObjectData[0].FullID = primData.FullID; | ||
686 | byte[] pb = pos.GetBytes(); | ||
687 | Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
688 | |||
689 | OutPacket(outPacket); | ||
690 | } | ||
691 | |||
692 | |||
693 | public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) | ||
694 | { | ||
695 | ObjectUpdatePacket outPacket = new ObjectUpdatePacket(); | ||
696 | outPacket.RegionData.RegionHandle = regionHandle; | ||
697 | outPacket.RegionData.TimeDilation = timeDilation; | ||
698 | outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
699 | outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primShape, textureID, flags); | ||
700 | outPacket.ObjectData[0].ID = localID; | ||
701 | outPacket.ObjectData[0].FullID = objectID; | ||
702 | outPacket.ObjectData[0].OwnerID = ownerID; | ||
703 | outPacket.ObjectData[0].Text = enc.GetBytes(text); | ||
704 | outPacket.ObjectData[0].ParentID = parentID; | ||
705 | byte[] pb = pos.GetBytes(); | ||
706 | Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
707 | byte[] rot = rotation.GetBytes(); | ||
708 | Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length); | ||
709 | OutPacket(outPacket); | ||
710 | } | ||
711 | |||
712 | public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLUUID textureID, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) | ||
713 | { | ||
714 | ObjectUpdatePacket outPacket = new ObjectUpdatePacket(); | ||
715 | outPacket.RegionData.RegionHandle = regionHandle; | ||
716 | outPacket.RegionData.TimeDilation = timeDilation; | ||
717 | outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; | ||
718 | outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primShape, textureID, flags); | ||
719 | outPacket.ObjectData[0].ID = localID; | ||
720 | outPacket.ObjectData[0].FullID = objectID; | ||
721 | outPacket.ObjectData[0].OwnerID = ownerID; | ||
722 | outPacket.ObjectData[0].Text = enc.GetBytes(text); | ||
723 | outPacket.ObjectData[0].ParentID = parentID; | ||
724 | byte[] pb = pos.GetBytes(); | ||
725 | Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
726 | |||
727 | OutPacket(outPacket); | ||
728 | } | ||
729 | /// <summary> | ||
730 | /// | ||
731 | /// </summary> | ||
732 | /// <param name="regionHandle"></param> | ||
733 | /// <param name="timeDilation"></param> | ||
734 | /// <param name="localID"></param> | ||
735 | /// <param name="position"></param> | ||
736 | /// <param name="rotation"></param> | ||
737 | public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation) | ||
738 | { | ||
739 | ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); | ||
740 | terse.RegionData.RegionHandle = regionHandle; | ||
741 | terse.RegionData.TimeDilation = timeDilation; | ||
742 | terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
743 | terse.ObjectData[0] = this.CreatePrimImprovedBlock(localID, position, rotation); | ||
744 | |||
745 | this.OutPacket(terse); | ||
746 | } | ||
747 | |||
748 | #endregion | ||
749 | |||
750 | #endregion | ||
751 | |||
752 | #region Helper Methods | ||
753 | |||
754 | protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos, LLVector3 velocity) | ||
755 | { | ||
756 | byte[] bytes = new byte[60]; | ||
757 | int i = 0; | ||
758 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
759 | |||
760 | dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; | ||
761 | |||
762 | uint ID = localID; | ||
763 | |||
764 | bytes[i++] = (byte)(ID % 256); | ||
765 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
766 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
767 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
768 | bytes[i++] = 0; | ||
769 | bytes[i++] = 1; | ||
770 | i += 14; | ||
771 | bytes[i++] = 128; | ||
772 | bytes[i++] = 63; | ||
773 | |||
774 | byte[] pb = pos.GetBytes(); | ||
775 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
776 | i += 12; | ||
777 | ushort InternVelocityX; | ||
778 | ushort InternVelocityY; | ||
779 | ushort InternVelocityZ; | ||
780 | Vector3 internDirec = new Vector3(0, 0, 0); | ||
781 | |||
782 | internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z); | ||
783 | |||
784 | internDirec = internDirec / 128.0f; | ||
785 | internDirec.x += 1; | ||
786 | internDirec.y += 1; | ||
787 | internDirec.z += 1; | ||
788 | |||
789 | InternVelocityX = (ushort)(32768 * internDirec.x); | ||
790 | InternVelocityY = (ushort)(32768 * internDirec.y); | ||
791 | InternVelocityZ = (ushort)(32768 * internDirec.z); | ||
792 | |||
793 | ushort ac = 32767; | ||
794 | bytes[i++] = (byte)(InternVelocityX % 256); | ||
795 | bytes[i++] = (byte)((InternVelocityX >> 8) % 256); | ||
796 | bytes[i++] = (byte)(InternVelocityY % 256); | ||
797 | bytes[i++] = (byte)((InternVelocityY >> 8) % 256); | ||
798 | bytes[i++] = (byte)(InternVelocityZ % 256); | ||
799 | bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); | ||
800 | |||
801 | //accel | ||
802 | bytes[i++] = (byte)(ac % 256); | ||
803 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
804 | bytes[i++] = (byte)(ac % 256); | ||
805 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
806 | bytes[i++] = (byte)(ac % 256); | ||
807 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
808 | |||
809 | //rot | ||
810 | bytes[i++] = (byte)(ac % 256); | ||
811 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
812 | bytes[i++] = (byte)(ac % 256); | ||
813 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
814 | bytes[i++] = (byte)(ac % 256); | ||
815 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
816 | bytes[i++] = (byte)(ac % 256); | ||
817 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
818 | |||
819 | //rotation vel | ||
820 | bytes[i++] = (byte)(ac % 256); | ||
821 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
822 | bytes[i++] = (byte)(ac % 256); | ||
823 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
824 | bytes[i++] = (byte)(ac % 256); | ||
825 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
826 | |||
827 | dat.Data = bytes; | ||
828 | return (dat); | ||
829 | } | ||
830 | |||
831 | /// <summary> | ||
832 | /// | ||
833 | /// </summary> | ||
834 | /// <param name="localID"></param> | ||
835 | /// <param name="position"></param> | ||
836 | /// <param name="rotation"></param> | ||
837 | /// <returns></returns> | ||
838 | protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID, LLVector3 position, LLQuaternion rotation) | ||
839 | { | ||
840 | uint ID = localID; | ||
841 | byte[] bytes = new byte[60]; | ||
842 | |||
843 | int i = 0; | ||
844 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
845 | dat.TextureEntry = new byte[0]; | ||
846 | bytes[i++] = (byte)(ID % 256); | ||
847 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
848 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
849 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
850 | bytes[i++] = 0; | ||
851 | bytes[i++] = 0; | ||
852 | |||
853 | byte[] pb = position.GetBytes(); | ||
854 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
855 | i += 12; | ||
856 | ushort ac = 32767; | ||
857 | |||
858 | //vel | ||
859 | bytes[i++] = (byte)(ac % 256); | ||
860 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
861 | bytes[i++] = (byte)(ac % 256); | ||
862 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
863 | bytes[i++] = (byte)(ac % 256); | ||
864 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
865 | |||
866 | //accel | ||
867 | bytes[i++] = (byte)(ac % 256); | ||
868 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
869 | bytes[i++] = (byte)(ac % 256); | ||
870 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
871 | bytes[i++] = (byte)(ac % 256); | ||
872 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
873 | |||
874 | ushort rw, rx, ry, rz; | ||
875 | rw = (ushort)(32768 * (rotation.W + 1)); | ||
876 | rx = (ushort)(32768 * (rotation.X + 1)); | ||
877 | ry = (ushort)(32768 * (rotation.Y + 1)); | ||
878 | rz = (ushort)(32768 * (rotation.Z + 1)); | ||
879 | |||
880 | //rot | ||
881 | bytes[i++] = (byte)(rx % 256); | ||
882 | bytes[i++] = (byte)((rx >> 8) % 256); | ||
883 | bytes[i++] = (byte)(ry % 256); | ||
884 | bytes[i++] = (byte)((ry >> 8) % 256); | ||
885 | bytes[i++] = (byte)(rz % 256); | ||
886 | bytes[i++] = (byte)((rz >> 8) % 256); | ||
887 | bytes[i++] = (byte)(rw % 256); | ||
888 | bytes[i++] = (byte)((rw >> 8) % 256); | ||
889 | |||
890 | //rotation vel | ||
891 | bytes[i++] = (byte)(ac % 256); | ||
892 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
893 | bytes[i++] = (byte)(ac % 256); | ||
894 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
895 | bytes[i++] = (byte)(ac % 256); | ||
896 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
897 | |||
898 | dat.Data = bytes; | ||
899 | return dat; | ||
900 | } | ||
901 | |||
902 | |||
903 | /// <summary> | ||
904 | /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive) | ||
905 | /// </summary> | ||
906 | /// <param name="primData"></param> | ||
907 | /// <returns></returns> | ||
908 | protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimData primData, LLUUID textureID, uint flags) | ||
909 | { | ||
910 | ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock(); | ||
911 | this.SetDefaultPrimPacketValues(objupdate); | ||
912 | objupdate.UpdateFlags = flags; | ||
913 | this.SetPrimPacketShapeData(objupdate, primData, textureID); | ||
914 | |||
915 | return objupdate; | ||
916 | } | ||
917 | |||
918 | /// <summary> | ||
919 | /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive) | ||
920 | /// </summary> | ||
921 | /// <param name="primData"></param> | ||
922 | /// <returns></returns> | ||
923 | protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, LLUUID textureID, uint flags) | ||
924 | { | ||
925 | ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock(); | ||
926 | this.SetDefaultPrimPacketValues(objupdate); | ||
927 | objupdate.UpdateFlags = flags; | ||
928 | this.SetPrimPacketShapeData(objupdate, primShape, textureID); | ||
929 | |||
930 | return objupdate; | ||
931 | } | ||
932 | |||
933 | |||
934 | /// <summary> | ||
935 | /// Copy the data from a PrimData object to a ObjectUpdatePacket | ||
936 | /// </summary> | ||
937 | /// <param name="objectData"></param> | ||
938 | /// <param name="primData"></param> | ||
939 | protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimData primData, LLUUID textureID) | ||
940 | { | ||
941 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(textureID); | ||
942 | objectData.TextureEntry = ntex.ToBytes(); | ||
943 | objectData.OwnerID = primData.OwnerID; | ||
944 | objectData.ParentID = primData.ParentID; | ||
945 | objectData.PCode = primData.PCode; | ||
946 | objectData.PathBegin = primData.PathBegin; | ||
947 | objectData.PathEnd = primData.PathEnd; | ||
948 | objectData.PathScaleX = primData.PathScaleX; | ||
949 | objectData.PathScaleY = primData.PathScaleY; | ||
950 | objectData.PathShearX = primData.PathShearX; | ||
951 | objectData.PathShearY = primData.PathShearY; | ||
952 | objectData.PathSkew = primData.PathSkew; | ||
953 | objectData.ProfileBegin = primData.ProfileBegin; | ||
954 | objectData.ProfileEnd = primData.ProfileEnd; | ||
955 | objectData.Scale = primData.Scale; | ||
956 | objectData.PathCurve = primData.PathCurve; | ||
957 | objectData.ProfileCurve = primData.ProfileCurve; | ||
958 | objectData.ProfileHollow = primData.ProfileHollow; | ||
959 | objectData.PathRadiusOffset = primData.PathRadiusOffset; | ||
960 | objectData.PathRevolutions = primData.PathRevolutions; | ||
961 | objectData.PathTaperX = primData.PathTaperX; | ||
962 | objectData.PathTaperY = primData.PathTaperY; | ||
963 | objectData.PathTwist = primData.PathTwist; | ||
964 | objectData.PathTwistBegin = primData.PathTwistBegin; | ||
965 | } | ||
966 | |||
967 | protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData, LLUUID textureID) | ||
968 | { | ||
969 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(textureID); | ||
970 | objectData.TextureEntry = ntex.ToBytes(); | ||
971 | objectData.PCode = primData.PCode; | ||
972 | objectData.PathBegin = primData.PathBegin; | ||
973 | objectData.PathEnd = primData.PathEnd; | ||
974 | objectData.PathScaleX = primData.PathScaleX; | ||
975 | objectData.PathScaleY = primData.PathScaleY; | ||
976 | objectData.PathShearX = primData.PathShearX; | ||
977 | objectData.PathShearY = primData.PathShearY; | ||
978 | objectData.PathSkew = primData.PathSkew; | ||
979 | objectData.ProfileBegin = primData.ProfileBegin; | ||
980 | objectData.ProfileEnd = primData.ProfileEnd; | ||
981 | objectData.Scale = primData.Scale; | ||
982 | objectData.PathCurve = primData.PathCurve; | ||
983 | objectData.ProfileCurve = primData.ProfileCurve; | ||
984 | objectData.ProfileHollow = primData.ProfileHollow; | ||
985 | objectData.PathRadiusOffset = primData.PathRadiusOffset; | ||
986 | objectData.PathRevolutions = primData.PathRevolutions; | ||
987 | objectData.PathTaperX = primData.PathTaperX; | ||
988 | objectData.PathTaperY = primData.PathTaperY; | ||
989 | objectData.PathTwist = primData.PathTwist; | ||
990 | objectData.PathTwistBegin = primData.PathTwistBegin; | ||
991 | } | ||
992 | |||
993 | /// <summary> | ||
994 | /// Set some default values in a ObjectUpdatePacket | ||
995 | /// </summary> | ||
996 | /// <param name="objdata"></param> | ||
997 | protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata) | ||
998 | { | ||
999 | objdata.PSBlock = new byte[0]; | ||
1000 | objdata.ExtraParams = new byte[1]; | ||
1001 | objdata.MediaURL = new byte[0]; | ||
1002 | objdata.NameValue = new byte[0]; | ||
1003 | objdata.Text = new byte[0]; | ||
1004 | objdata.TextColor = new byte[4]; | ||
1005 | objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0); | ||
1006 | objdata.JointPivot = new LLVector3(0, 0, 0); | ||
1007 | objdata.Material = 3; | ||
1008 | objdata.TextureAnim = new byte[0]; | ||
1009 | objdata.Sound = LLUUID.Zero; | ||
1010 | objdata.State = 0; | ||
1011 | objdata.Data = new byte[0]; | ||
1012 | |||
1013 | objdata.ObjectData = new byte[60]; | ||
1014 | objdata.ObjectData[46] = 128; | ||
1015 | objdata.ObjectData[47] = 63; | ||
1016 | } | ||
1017 | |||
1018 | |||
1019 | /// <summary> | ||
1020 | /// | ||
1021 | /// </summary> | ||
1022 | /// <returns></returns> | ||
1023 | protected ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry) | ||
1024 | { | ||
1025 | ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i); | ||
1026 | |||
1027 | SetDefaultAvatarPacketValues(ref objdata); | ||
1028 | objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24); | ||
1029 | objdata.PathCurve = 16; | ||
1030 | objdata.ProfileCurve = 1; | ||
1031 | objdata.PathScaleX = 100; | ||
1032 | objdata.PathScaleY = 100; | ||
1033 | objdata.ParentID = 0; | ||
1034 | objdata.OwnerID = LLUUID.Zero; | ||
1035 | objdata.Scale = new LLVector3(1, 1, 1); | ||
1036 | objdata.PCode = 47; | ||
1037 | if (textureEntry != null) | ||
1038 | { | ||
1039 | objdata.TextureEntry = textureEntry; | ||
1040 | } | ||
1041 | Encoding enc = Encoding.ASCII; | ||
1042 | LLVector3 pos = new LLVector3(objdata.ObjectData, 16); | ||
1043 | pos.X = 100f; | ||
1044 | objdata.ID = 8880000; | ||
1045 | objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); | ||
1046 | LLVector3 pos2 = new LLVector3(100f, 100f, 23f); | ||
1047 | //objdata.FullID=user.AgentID; | ||
1048 | byte[] pb = pos.GetBytes(); | ||
1049 | Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length); | ||
1050 | |||
1051 | return objdata; | ||
1052 | } | ||
1053 | |||
1054 | /// <summary> | ||
1055 | /// | ||
1056 | /// </summary> | ||
1057 | /// <param name="objdata"></param> | ||
1058 | protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata) | ||
1059 | { | ||
1060 | objdata.PSBlock = new byte[0]; | ||
1061 | objdata.ExtraParams = new byte[1]; | ||
1062 | objdata.MediaURL = new byte[0]; | ||
1063 | objdata.NameValue = new byte[0]; | ||
1064 | objdata.Text = new byte[0]; | ||
1065 | objdata.TextColor = new byte[4]; | ||
1066 | objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0); | ||
1067 | objdata.JointPivot = new LLVector3(0, 0, 0); | ||
1068 | objdata.Material = 4; | ||
1069 | objdata.TextureAnim = new byte[0]; | ||
1070 | objdata.Sound = LLUUID.Zero; | ||
1071 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
1072 | objdata.TextureEntry = ntex.ToBytes(); | ||
1073 | objdata.State = 0; | ||
1074 | objdata.Data = new byte[0]; | ||
1075 | |||
1076 | objdata.ObjectData = new byte[76]; | ||
1077 | objdata.ObjectData[15] = 128; | ||
1078 | objdata.ObjectData[16] = 63; | ||
1079 | objdata.ObjectData[56] = 128; | ||
1080 | objdata.ObjectData[61] = 102; | ||
1081 | objdata.ObjectData[62] = 40; | ||
1082 | objdata.ObjectData[63] = 61; | ||
1083 | objdata.ObjectData[64] = 189; | ||
1084 | } | ||
1085 | |||
1086 | /// <summary> | ||
1087 | /// | ||
1088 | /// </summary> | ||
1089 | /// <param name="addPacket"></param> | ||
1090 | /// <returns></returns> | ||
1091 | protected PrimData CreatePrimFromObjectAdd(ObjectAddPacket addPacket) | ||
1092 | { | ||
1093 | PrimData PData = new PrimData(); | ||
1094 | PData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
1095 | PData.PCode = addPacket.ObjectData.PCode; | ||
1096 | PData.PathBegin = addPacket.ObjectData.PathBegin; | ||
1097 | PData.PathEnd = addPacket.ObjectData.PathEnd; | ||
1098 | PData.PathScaleX = addPacket.ObjectData.PathScaleX; | ||
1099 | PData.PathScaleY = addPacket.ObjectData.PathScaleY; | ||
1100 | PData.PathShearX = addPacket.ObjectData.PathShearX; | ||
1101 | PData.PathShearY = addPacket.ObjectData.PathShearY; | ||
1102 | PData.PathSkew = addPacket.ObjectData.PathSkew; | ||
1103 | PData.ProfileBegin = addPacket.ObjectData.ProfileBegin; | ||
1104 | PData.ProfileEnd = addPacket.ObjectData.ProfileEnd; | ||
1105 | PData.Scale = addPacket.ObjectData.Scale; | ||
1106 | PData.PathCurve = addPacket.ObjectData.PathCurve; | ||
1107 | PData.ProfileCurve = addPacket.ObjectData.ProfileCurve; | ||
1108 | PData.ParentID = 0; | ||
1109 | PData.ProfileHollow = addPacket.ObjectData.ProfileHollow; | ||
1110 | PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; | ||
1111 | PData.PathRevolutions = addPacket.ObjectData.PathRevolutions; | ||
1112 | PData.PathTaperX = addPacket.ObjectData.PathTaperX; | ||
1113 | PData.PathTaperY = addPacket.ObjectData.PathTaperY; | ||
1114 | PData.PathTwist = addPacket.ObjectData.PathTwist; | ||
1115 | PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin; | ||
1116 | |||
1117 | return PData; | ||
1118 | } | ||
1119 | #endregion | ||
1120 | |||
1121 | } | ||
1122 | } | ||