aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientView.API.cs
diff options
context:
space:
mode:
authorSean Dague2007-11-28 13:33:57 +0000
committerSean Dague2007-11-28 13:33:57 +0000
commit5fb81ab881adedb139369ef0bad19a80453ea129 (patch)
treecbb8f832b90f809457b2d4a9ded0b9b3a508b4f7 /OpenSim/Region/ClientStack/ClientView.API.cs
parentMoved the m_sceneGridService.RegisterRegion(RegionInfo); call out of LoadWorl... (diff)
downloadopensim-SC-5fb81ab881adedb139369ef0bad19a80453ea129.zip
opensim-SC-5fb81ab881adedb139369ef0bad19a80453ea129.tar.gz
opensim-SC-5fb81ab881adedb139369ef0bad19a80453ea129.tar.bz2
opensim-SC-5fb81ab881adedb139369ef0bad19a80453ea129.tar.xz
merged ClientView into a non partial class. Will
make it easier to start breaking this up into more discreet functional classes
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientView.API.cs')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.API.cs1442
1 files changed, 0 insertions, 1442 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs
deleted file mode 100644
index 25d23be..0000000
--- a/OpenSim/Region/ClientStack/ClientView.API.cs
+++ /dev/null
@@ -1,1442 +0,0 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.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.Net;
31using System.Text;
32using Axiom.Math;
33using libsecondlife;
34using libsecondlife.Packets;
35using OpenSim.Framework;
36using OpenSim.Framework.Console;
37
38namespace OpenSim.Region.ClientStack
39{
40 partial class ClientView
41 {
42 public event Action<IClientAPI> OnLogout;
43 public event Action<IClientAPI> OnConnectionClosed;
44 public event ViewerEffectEventHandler OnViewerEffect;
45 public event ImprovedInstantMessage OnInstantMessage;
46 public event ChatFromViewer OnChatFromViewer;
47 public event TextureRequest OnRequestTexture;
48 public event RezObject OnRezObject;
49 public event GenericCall4 OnDeRezObject;
50 public event ModifyTerrain OnModifyTerrain;
51 public event Action<IClientAPI> OnRegionHandShakeReply;
52 public event GenericCall2 OnRequestWearables;
53 public event SetAppearance OnSetAppearance;
54 public event GenericCall2 OnCompleteMovementToRegion;
55 public event UpdateAgent OnAgentUpdate;
56 public event AgentRequestSit OnAgentRequestSit;
57 public event AgentSit OnAgentSit;
58 public event AvatarPickerRequest OnAvatarPickerRequest;
59 public event StartAnim OnStartAnim;
60 public event Action<IClientAPI> OnRequestAvatarsData;
61 public event LinkObjects OnLinkObjects;
62 public event DelinkObjects OnDelinkObjects;
63 public event UpdateVector OnGrabObject;
64 public event ObjectSelect OnDeGrabObject;
65 public event ObjectDuplicate OnObjectDuplicate;
66 public event MoveObject OnGrabUpdate;
67 public event AddNewPrim OnAddPrim;
68 public event RequestGodlikePowers OnRequestGodlikePowers;
69 public event GodKickUser OnGodKickUser;
70 public event ObjectExtraParams OnUpdateExtraParams;
71 public event UpdateShape OnUpdatePrimShape;
72 public event ObjectSelect OnObjectSelect;
73 public event ObjectDeselect OnObjectDeselect;
74 public event GenericCall7 OnObjectDescription;
75 public event GenericCall7 OnObjectName;
76 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
77 public event UpdatePrimFlags OnUpdatePrimFlags;
78 public event UpdatePrimTexture OnUpdatePrimTexture;
79 public event UpdateVector OnUpdatePrimGroupPosition;
80 public event UpdateVector OnUpdatePrimSinglePosition;
81 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
82 public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
83 public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
84 public event UpdateVector OnUpdatePrimScale;
85 public event StatusChange OnChildAgentStatus;
86 public event GenericCall2 OnStopMovement;
87 public event Action<LLUUID> OnRemoveAvatar;
88 public event RequestMapBlocks OnRequestMapBlocks;
89 public event RequestMapName OnMapNameRequest;
90 public event TeleportLocationRequest OnTeleportLocationRequest;
91 public event DisconnectUser OnDisconnectUser;
92 public event RequestAvatarProperties OnRequestAvatarProperties;
93 public event SetAlwaysRun OnSetAlwaysRun;
94
95 public event CreateNewInventoryItem OnCreateNewInventoryItem;
96 public event CreateInventoryFolder OnCreateNewInventoryFolder;
97 public event FetchInventoryDescendents OnFetchInventoryDescendents;
98 public event FetchInventory OnFetchInventory;
99 public event RequestTaskInventory OnRequestTaskInventory;
100 public event UpdateInventoryItemTransaction OnUpdateInventoryItem;
101 public event CopyInventoryItem OnCopyInventoryItem;
102 public event UDPAssetUploadRequest OnAssetUploadRequest;
103 public event XferReceive OnXferReceive;
104 public event RequestXfer OnRequestXfer;
105 public event ConfirmXfer OnConfirmXfer;
106 public event RezScript OnRezScript;
107 public event UpdateTaskInventory OnUpdateTaskInventory;
108 public event RemoveTaskInventory OnRemoveTaskItem;
109
110 public event UUIDNameRequest OnNameFromUUIDRequest;
111
112 public event ParcelPropertiesRequest OnParcelPropertiesRequest;
113 public event ParcelDivideRequest OnParcelDivideRequest;
114 public event ParcelJoinRequest OnParcelJoinRequest;
115 public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
116 public event ParcelSelectObjects OnParcelSelectObjects;
117 public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
118 public event EstateOwnerMessageRequest OnEstateOwnerMessage;
119
120 /// <summary>
121 ///
122 /// </summary>
123 public LLVector3 StartPos
124 {
125 get { return startpos; }
126 set { startpos = value; }
127 }
128
129 /// <summary>
130 ///
131 /// </summary>
132 private LLUUID m_agentId;
133
134 public LLUUID AgentId
135 {
136 get { return m_agentId; }
137 }
138
139 /// <summary>
140 ///
141 /// </summary>
142 public string FirstName
143 {
144 get { return firstName; }
145 }
146
147 /// <summary>
148 ///
149 /// </summary>
150 public string LastName
151 {
152 get { return lastName; }
153 }
154
155 #region Scene/Avatar to Client
156
157 /// <summary>
158 ///
159 /// </summary>
160 /// <param name="regionInfo"></param>
161 public void SendRegionHandshake(RegionInfo regionInfo)
162 {
163 Encoding _enc = Encoding.ASCII;
164 RegionHandshakePacket handshake = new RegionHandshakePacket();
165
166 handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor;
167 handshake.RegionInfo.IsEstateManager = false;
168 handshake.RegionInfo.TerrainHeightRange00 = regionInfo.EstateSettings.terrainHeightRange0;
169 handshake.RegionInfo.TerrainHeightRange01 = regionInfo.EstateSettings.terrainHeightRange1;
170 handshake.RegionInfo.TerrainHeightRange10 = regionInfo.EstateSettings.terrainHeightRange2;
171 handshake.RegionInfo.TerrainHeightRange11 = regionInfo.EstateSettings.terrainHeightRange3;
172 handshake.RegionInfo.TerrainStartHeight00 = regionInfo.EstateSettings.terrainStartHeight0;
173 handshake.RegionInfo.TerrainStartHeight01 = regionInfo.EstateSettings.terrainStartHeight1;
174 handshake.RegionInfo.TerrainStartHeight10 = regionInfo.EstateSettings.terrainStartHeight2;
175 handshake.RegionInfo.TerrainStartHeight11 = regionInfo.EstateSettings.terrainStartHeight3;
176 handshake.RegionInfo.SimAccess = (byte) regionInfo.EstateSettings.simAccess;
177 handshake.RegionInfo.WaterHeight = regionInfo.EstateSettings.waterHeight;
178
179
180 handshake.RegionInfo.RegionFlags = (uint) regionInfo.EstateSettings.regionFlags;
181
182 handshake.RegionInfo.SimName = _enc.GetBytes(regionInfo.RegionName + "\0");
183 handshake.RegionInfo.SimOwner = regionInfo.MasterAvatarAssignedUUID;
184 handshake.RegionInfo.TerrainBase0 = regionInfo.EstateSettings.terrainBase0;
185 handshake.RegionInfo.TerrainBase1 = regionInfo.EstateSettings.terrainBase1;
186 handshake.RegionInfo.TerrainBase2 = regionInfo.EstateSettings.terrainBase2;
187 handshake.RegionInfo.TerrainBase3 = regionInfo.EstateSettings.terrainBase3;
188 handshake.RegionInfo.TerrainDetail0 = regionInfo.EstateSettings.terrainDetail0;
189 handshake.RegionInfo.TerrainDetail1 = regionInfo.EstateSettings.terrainDetail1;
190 handshake.RegionInfo.TerrainDetail2 = regionInfo.EstateSettings.terrainDetail2;
191 handshake.RegionInfo.TerrainDetail3 = regionInfo.EstateSettings.terrainDetail3;
192 handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting?
193
194 OutPacket(handshake, ThrottleOutPacketType.Task);
195 }
196
197 /// <summary>
198 ///
199 /// </summary>
200 /// <param name="regInfo"></param>
201 public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
202 {
203 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
204 mov.AgentData.SessionID = m_sessionId;
205 mov.AgentData.AgentID = AgentId;
206 mov.Data.RegionHandle = regInfo.RegionHandle;
207 mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this
208
209 if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
210 {
211 mov.Data.Position = startpos;
212 }
213 else
214 {
215 mov.Data.Position = pos;
216 }
217 mov.Data.LookAt = look;
218
219 OutPacket(mov, ThrottleOutPacketType.Task);
220 }
221
222 /// <summary>
223 ///
224 /// </summary>
225 /// <param name="message"></param>
226 /// <param name="type"></param>
227 /// <param name="fromPos"></param>
228 /// <param name="fromName"></param>
229 /// <param name="fromAgentID"></param>
230 public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
231 {
232 SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID);
233 }
234
235
236 public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
237 {
238 Encoding enc = Encoding.ASCII;
239 ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
240 reply.ChatData.Audible = 1;
241 reply.ChatData.Message = message;
242 reply.ChatData.ChatType = type;
243 reply.ChatData.SourceType = 1;
244 reply.ChatData.Position = fromPos;
245 reply.ChatData.FromName = enc.GetBytes(fromName + "\0");
246 reply.ChatData.OwnerID = fromAgentID;
247 reply.ChatData.SourceID = fromAgentID;
248
249 OutPacket(reply, ThrottleOutPacketType.Task);
250 }
251
252 /// <summary>
253 ///
254 /// </summary>
255 /// <remarks>TODO</remarks>
256 /// <param name="message"></param>
257 /// <param name="target"></param>
258 public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
259 LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
260 {
261 Encoding enc = Encoding.ASCII;
262 Encoding encUTF8 = Encoding.UTF8;
263 ImprovedInstantMessagePacket msg = new ImprovedInstantMessagePacket();
264 msg.AgentData.AgentID = fromAgent;
265 msg.AgentData.SessionID = fromAgentSession;
266 msg.MessageBlock.FromAgentName = enc.GetBytes(fromName + " \0");
267 msg.MessageBlock.Dialog = dialog;
268 msg.MessageBlock.FromGroup = false;
269 msg.MessageBlock.ID = imSessionID;
270 msg.MessageBlock.Offline = 0;
271 msg.MessageBlock.ParentEstateID = 0;
272 msg.MessageBlock.Position = new LLVector3();
273 msg.MessageBlock.RegionID = LLUUID.Random();
274 msg.MessageBlock.Timestamp = timeStamp;
275 msg.MessageBlock.ToAgentID = toAgent;
276 msg.MessageBlock.Message = encUTF8.GetBytes(message + "\0");
277 msg.MessageBlock.BinaryBucket = new byte[0];
278
279 OutPacket(msg, ThrottleOutPacketType.Task);
280 }
281
282 /// <summary>
283 /// Send the region heightmap to the client
284 /// </summary>
285 /// <param name="map">heightmap</param>
286 public virtual void SendLayerData(float[] map)
287 {
288 try
289 {
290 int[] patches = new int[4];
291
292 for (int y = 0; y < 16; y++)
293 {
294 for (int x = 0; x < 16; x = x + 4)
295 {
296 patches[0] = x + 0 + y*16;
297 patches[1] = x + 1 + y*16;
298 patches[2] = x + 2 + y*16;
299 patches[3] = x + 3 + y*16;
300
301 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
302 OutPacket(layerpack, ThrottleOutPacketType.Land);
303 }
304 }
305 }
306 catch (Exception e)
307 {
308 MainLog.Instance.Warn("client",
309 "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
310 }
311 }
312
313 /// <summary>
314 /// Sends a specified patch to a client
315 /// </summary>
316 /// <param name="px">Patch coordinate (x) 0..16</param>
317 /// <param name="py">Patch coordinate (y) 0..16</param>
318 /// <param name="map">heightmap</param>
319 public void SendLayerData(int px, int py, float[] map)
320 {
321 try
322 {
323 int[] patches = new int[1];
324 int patchx, patchy;
325 patchx = px;
326 patchy = py;
327
328 patches[0] = patchx + 0 + patchy*16;
329
330 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
331 OutPacket(layerpack, ThrottleOutPacketType.Land);
332 }
333 catch (Exception e)
334 {
335 MainLog.Instance.Warn("client",
336 "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
337 }
338 }
339
340 /// <summary>
341 ///
342 /// </summary>
343 /// <param name="neighbourHandle"></param>
344 /// <param name="neighbourIP"></param>
345 /// <param name="neighbourPort"></param>
346 public void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
347 {
348 IPAddress neighbourIP = neighbourEndPoint.Address;
349 ushort neighbourPort = (ushort) neighbourEndPoint.Port;
350
351 EnableSimulatorPacket enablesimpacket = new EnableSimulatorPacket();
352 enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
353 enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
354
355 byte[] byteIP = neighbourIP.GetAddressBytes();
356 enablesimpacket.SimulatorInfo.IP = (uint) byteIP[3] << 24;
357 enablesimpacket.SimulatorInfo.IP += (uint) byteIP[2] << 16;
358 enablesimpacket.SimulatorInfo.IP += (uint) byteIP[1] << 8;
359 enablesimpacket.SimulatorInfo.IP += (uint) byteIP[0];
360 enablesimpacket.SimulatorInfo.Port = neighbourPort;
361 OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
362 }
363
364 /// <summary>
365 ///
366 /// </summary>
367 /// <returns></returns>
368 public AgentCircuitData RequestClientInfo()
369 {
370 AgentCircuitData agentData = new AgentCircuitData();
371 agentData.AgentID = AgentId;
372 agentData.SessionID = m_sessionId;
373 agentData.SecureSessionID = SecureSessionID;
374 agentData.circuitcode = m_circuitCode;
375 agentData.child = false;
376 agentData.firstname = firstName;
377 agentData.lastname = lastName;
378 agentData.CapsPath = "";
379 return agentData;
380 }
381
382 public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint externalIPEndPoint,
383 string capsURL)
384 {
385 LLVector3 look = new LLVector3(lookAt.X*10, lookAt.Y*10, lookAt.Z*10);
386
387 CrossedRegionPacket newSimPack = new CrossedRegionPacket();
388 newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
389 newSimPack.AgentData.AgentID = AgentId;
390 newSimPack.AgentData.SessionID = m_sessionId;
391 newSimPack.Info = new CrossedRegionPacket.InfoBlock();
392 newSimPack.Info.Position = pos;
393 newSimPack.Info.LookAt = look;
394 // new LLVector3(0.0f, 0.0f, 0.0f); // copied from Avatar.cs - SHOULD BE DYNAMIC!!!!!!!!!!
395 newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
396 newSimPack.RegionData.RegionHandle = newRegionHandle;
397 byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
398 newSimPack.RegionData.SimIP = (uint) byteIP[3] << 24;
399 newSimPack.RegionData.SimIP += (uint) byteIP[2] << 16;
400 newSimPack.RegionData.SimIP += (uint) byteIP[1] << 8;
401 newSimPack.RegionData.SimIP += (uint) byteIP[0];
402 newSimPack.RegionData.SimPort = (ushort) externalIPEndPoint.Port;
403 //newSimPack.RegionData.SeedCapability = new byte[0];
404 newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL);
405
406 OutPacket(newSimPack, ThrottleOutPacketType.Task);
407 }
408
409 public void SendMapBlock(List<MapBlockData> mapBlocks)
410 {
411 MapBlockReplyPacket mapReply = new MapBlockReplyPacket();
412 mapReply.AgentData.AgentID = AgentId;
413 mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count];
414 mapReply.AgentData.Flags = 0;
415
416 for (int i = 0; i < mapBlocks.Count; i++)
417 {
418 mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
419 mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId;
420 mapReply.Data[i].X = mapBlocks[i].X;
421 mapReply.Data[i].Y = mapBlocks[i].Y;
422 mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight;
423 mapReply.Data[i].Name = Helpers.StringToField(mapBlocks[i].Name);
424 mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags;
425 mapReply.Data[i].Access = mapBlocks[i].Access;
426 mapReply.Data[i].Agents = mapBlocks[i].Agents;
427 }
428 OutPacket(mapReply, ThrottleOutPacketType.Land);
429 }
430
431 public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
432 {
433 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
434 tpLocal.Info.AgentID = AgentId;
435 tpLocal.Info.TeleportFlags = flags;
436 tpLocal.Info.LocationID = 2;
437 tpLocal.Info.LookAt = lookAt;
438 tpLocal.Info.Position = position;
439 OutPacket(tpLocal, ThrottleOutPacketType.Task);
440 }
441
442 public void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
443 uint flags, string capsURL)
444 {
445 TeleportFinishPacket teleport = new TeleportFinishPacket();
446 teleport.Info.AgentID = AgentId;
447 teleport.Info.RegionHandle = regionHandle;
448 teleport.Info.SimAccess = simAccess;
449
450 teleport.Info.SeedCapability = Helpers.StringToField(capsURL);
451 //teleport.Info.SeedCapability = new byte[0];
452
453 IPAddress oIP = newRegionEndPoint.Address;
454 byte[] byteIP = oIP.GetAddressBytes();
455 uint ip = (uint) byteIP[3] << 24;
456 ip += (uint) byteIP[2] << 16;
457 ip += (uint) byteIP[1] << 8;
458 ip += (uint) byteIP[0];
459
460 teleport.Info.SimIP = ip;
461 teleport.Info.SimPort = (ushort) newRegionEndPoint.Port;
462 teleport.Info.LocationID = 4;
463 teleport.Info.TeleportFlags = 1 << 4;
464 OutPacket(teleport, ThrottleOutPacketType.Task);
465 }
466
467 /// <summary>
468 ///
469 /// </summary>
470 public void SendTeleportFailed()
471 {
472 TeleportFailedPacket tpFailed = new TeleportFailedPacket();
473 tpFailed.Info.AgentID = this.AgentId;
474 tpFailed.Info.Reason = Helpers.StringToField("unknown failure of teleport");
475
476 OutPacket(tpFailed, ThrottleOutPacketType.Task);
477 }
478
479 /// <summary>
480 ///
481 /// </summary>
482 public void SendTeleportLocationStart()
483 {
484 TeleportStartPacket tpStart = new TeleportStartPacket();
485 tpStart.Info.TeleportFlags = 16; // Teleport via location
486 OutPacket(tpStart, ThrottleOutPacketType.Task);
487 }
488
489 public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
490 {
491 MoneyBalanceReplyPacket money = new MoneyBalanceReplyPacket();
492 money.MoneyData.AgentID = AgentId;
493 money.MoneyData.TransactionID = transaction;
494 money.MoneyData.TransactionSuccess = success;
495 money.MoneyData.Description = description;
496 money.MoneyData.MoneyBalance = balance;
497 OutPacket(money, ThrottleOutPacketType.Task);
498 }
499
500 public void SendStartPingCheck(byte seq)
501 {
502 StartPingCheckPacket pc = new StartPingCheckPacket();
503 pc.PingID.PingID = seq;
504 pc.Header.Reliable = false;
505 OutPacket(pc, ThrottleOutPacketType.Task);
506 }
507
508 public void SendKillObject(ulong regionHandle, uint localID)
509 {
510 KillObjectPacket kill = new KillObjectPacket();
511 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
512 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
513 kill.ObjectData[0].ID = localID;
514 OutPacket(kill, ThrottleOutPacketType.Task);
515 }
516
517 public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items)
518 {
519 Encoding enc = Encoding.ASCII;
520 uint FULL_MASK_PERMISSIONS = 2147483647;
521 InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
522
523 int count = 0;
524 if (items.Count < 40)
525 {
526 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
527 descend.AgentData.Descendents = items.Count;
528 }
529 else
530 {
531 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[40];
532 descend.AgentData.Descendents = 40;
533 }
534 int i = 0;
535 foreach (InventoryItemBase item in items)
536 {
537 descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
538 descend.ItemData[i].ItemID = item.inventoryID;
539 descend.ItemData[i].AssetID = item.assetID;
540 descend.ItemData[i].CreatorID = item.creatorsID;
541 descend.ItemData[i].BaseMask = item.inventoryBasePermissions;
542 descend.ItemData[i].CreationDate = 1000;
543 descend.ItemData[i].Description = enc.GetBytes(item.inventoryDescription + "\0");
544 descend.ItemData[i].EveryoneMask = item.inventoryEveryOnePermissions;
545 descend.ItemData[i].Flags = 1;
546 descend.ItemData[i].FolderID = item.parentFolderID;
547 descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
548 descend.ItemData[i].GroupMask = 0;
549 descend.ItemData[i].InvType = (sbyte) item.invType;
550 descend.ItemData[i].Name = enc.GetBytes(item.inventoryName + "\0");
551 descend.ItemData[i].NextOwnerMask = item.inventoryNextPermissions;
552 descend.ItemData[i].OwnerID = item.avatarID;
553 descend.ItemData[i].OwnerMask = item.inventoryCurrentPermissions;
554 descend.ItemData[i].SalePrice = 0;
555 descend.ItemData[i].SaleType = 0;
556 descend.ItemData[i].Type = (sbyte) item.assetType;
557 descend.ItemData[i].CRC =
558 Helpers.InventoryCRC(1000, 0, descend.ItemData[i].InvType, descend.ItemData[i].Type,
559 descend.ItemData[i].AssetID, descend.ItemData[i].GroupID, 100,
560 descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
561 descend.ItemData[i].ItemID, descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS,
562 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
563
564 i++;
565 count++;
566 if (i == 40)
567 {
568 OutPacket(descend, ThrottleOutPacketType.Asset);
569
570 if ((items.Count - count) > 0)
571 {
572 descend = CreateInventoryDescendentsPacket(ownerID, folderID);
573 if ((items.Count - count) < 40)
574 {
575 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
576 descend.AgentData.Descendents = items.Count - count;
577 }
578 else
579 {
580 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[40];
581 descend.AgentData.Descendents = 40;
582 }
583 i = 0;
584 }
585 }
586 }
587
588 if (i < 40)
589 {
590 OutPacket(descend, ThrottleOutPacketType.Asset);
591 }
592 }
593
594 private InventoryDescendentsPacket CreateInventoryDescendentsPacket(LLUUID ownerID, LLUUID folderID)
595 {
596 InventoryDescendentsPacket descend = new InventoryDescendentsPacket();
597 descend.AgentData.AgentID = AgentId;
598 descend.AgentData.OwnerID = ownerID;
599 descend.AgentData.FolderID = folderID;
600 descend.AgentData.Version = 0;
601
602 return descend;
603 }
604
605 public void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
606 {
607 Encoding enc = Encoding.ASCII;
608 uint FULL_MASK_PERMISSIONS = 2147483647;
609 FetchInventoryReplyPacket inventoryReply = new FetchInventoryReplyPacket();
610 inventoryReply.AgentData.AgentID = AgentId;
611 inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
612 inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
613 inventoryReply.InventoryData[0].ItemID = item.inventoryID;
614 inventoryReply.InventoryData[0].AssetID = item.assetID;
615 inventoryReply.InventoryData[0].CreatorID = item.creatorsID;
616 inventoryReply.InventoryData[0].BaseMask = item.inventoryBasePermissions;
617 inventoryReply.InventoryData[0].CreationDate =
618 (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
619 inventoryReply.InventoryData[0].Description = enc.GetBytes(item.inventoryDescription + "\0");
620 inventoryReply.InventoryData[0].EveryoneMask = item.inventoryEveryOnePermissions;
621 inventoryReply.InventoryData[0].Flags = 0;
622 inventoryReply.InventoryData[0].FolderID = item.parentFolderID;
623 inventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
624 inventoryReply.InventoryData[0].GroupMask = 0;
625 inventoryReply.InventoryData[0].InvType = (sbyte) item.invType;
626 inventoryReply.InventoryData[0].Name = enc.GetBytes(item.inventoryName + "\0");
627 inventoryReply.InventoryData[0].NextOwnerMask = item.inventoryNextPermissions;
628 inventoryReply.InventoryData[0].OwnerID = item.avatarID;
629 inventoryReply.InventoryData[0].OwnerMask = item.inventoryCurrentPermissions;
630 inventoryReply.InventoryData[0].SalePrice = 0;
631 inventoryReply.InventoryData[0].SaleType = 0;
632 inventoryReply.InventoryData[0].Type = (sbyte) item.assetType;
633 inventoryReply.InventoryData[0].CRC =
634 Helpers.InventoryCRC(1000, 0, inventoryReply.InventoryData[0].InvType,
635 inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
636 inventoryReply.InventoryData[0].GroupID, 100,
637 inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
638 inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
639 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
640 FULL_MASK_PERMISSIONS);
641
642 OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
643 }
644
645 public void SendInventoryItemUpdate(InventoryItemBase Item)
646 {
647 Encoding enc = Encoding.ASCII;
648 uint FULL_MASK_PERMISSIONS = 2147483647;
649 UpdateCreateInventoryItemPacket InventoryReply = new UpdateCreateInventoryItemPacket();
650 InventoryReply.AgentData.AgentID = AgentId;
651 InventoryReply.AgentData.SimApproved = true;
652 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
653 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
654 InventoryReply.InventoryData[0].ItemID = Item.inventoryID;
655 InventoryReply.InventoryData[0].AssetID = Item.assetID;
656 InventoryReply.InventoryData[0].CreatorID = Item.creatorsID;
657 InventoryReply.InventoryData[0].BaseMask = Item.inventoryBasePermissions;
658 InventoryReply.InventoryData[0].CreationDate = 1000;
659 InventoryReply.InventoryData[0].Description = enc.GetBytes(Item.inventoryDescription + "\0");
660 InventoryReply.InventoryData[0].EveryoneMask = Item.inventoryEveryOnePermissions;
661 InventoryReply.InventoryData[0].Flags = 0;
662 InventoryReply.InventoryData[0].FolderID = Item.parentFolderID;
663 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
664 InventoryReply.InventoryData[0].GroupMask = 0;
665 InventoryReply.InventoryData[0].InvType = (sbyte) Item.invType;
666 InventoryReply.InventoryData[0].Name = enc.GetBytes(Item.inventoryName + "\0");
667 InventoryReply.InventoryData[0].NextOwnerMask = Item.inventoryNextPermissions;
668 InventoryReply.InventoryData[0].OwnerID = Item.avatarID;
669 InventoryReply.InventoryData[0].OwnerMask = Item.inventoryCurrentPermissions;
670 InventoryReply.InventoryData[0].SalePrice = 100;
671 InventoryReply.InventoryData[0].SaleType = 0;
672 InventoryReply.InventoryData[0].Type = (sbyte) Item.assetType;
673 InventoryReply.InventoryData[0].CRC =
674 Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
675 InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
676 InventoryReply.InventoryData[0].GroupID, 100,
677 InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
678 InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
679 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
680 FULL_MASK_PERMISSIONS);
681
682 OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
683 }
684
685 public void SendRemoveInventoryItem(LLUUID itemID)
686 {
687 RemoveInventoryItemPacket remove = new RemoveInventoryItemPacket();
688 remove.AgentData.AgentID = AgentId;
689 remove.AgentData.SessionID = m_sessionId;
690 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
691 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
692 remove.InventoryData[0].ItemID = itemID;
693
694 OutPacket(remove, ThrottleOutPacketType.Asset);
695 }
696
697 public void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
698 {
699 ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket();
700 replytask.InventoryData.TaskID = taskID;
701 replytask.InventoryData.Serial = serial;
702 replytask.InventoryData.Filename = fileName;
703 OutPacket(replytask, ThrottleOutPacketType.Asset);
704 }
705
706 public void SendXferPacket(ulong xferID, uint packet, byte[] data)
707 {
708 SendXferPacketPacket sendXfer = new SendXferPacketPacket();
709 sendXfer.XferID.ID = xferID;
710 sendXfer.XferID.Packet = packet;
711 sendXfer.DataPacket.Data = data;
712 OutPacket(sendXfer, ThrottleOutPacketType.Task);
713 }
714 public void SendAvatarPickerReply(AvatarPickerReplyPacket replyPacket)
715 {
716 OutPacket(replyPacket, ThrottleOutPacketType.Task);
717 }
718
719 /// <summary>
720 ///
721 /// </summary>
722 /// <param name="message"></param>
723 public void SendAlertMessage(string message)
724 {
725 AlertMessagePacket alertPack = new AlertMessagePacket();
726 alertPack.AlertData.Message = Helpers.StringToField(message);
727 OutPacket(alertPack, ThrottleOutPacketType.Task);
728 }
729
730 /// <summary>
731 ///
732 /// </summary>
733 /// <param name="message"></param>
734 /// <param name="modal"></param>
735 public void SendAgentAlertMessage(string message, bool modal)
736 {
737 AgentAlertMessagePacket alertPack = new AgentAlertMessagePacket();
738 alertPack.AgentData.AgentID = AgentId;
739 alertPack.AlertData.Message = Helpers.StringToField(message);
740 alertPack.AlertData.Modal = modal;
741 OutPacket(alertPack, ThrottleOutPacketType.Task);
742 }
743
744 public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
745 string url)
746 {
747 LoadURLPacket loadURL = new LoadURLPacket();
748 loadURL.Data.ObjectName = Helpers.StringToField(objectname);
749 loadURL.Data.ObjectID = objectID;
750 loadURL.Data.OwnerID = ownerID;
751 loadURL.Data.OwnerIsGroup = groupOwned;
752 loadURL.Data.Message = Helpers.StringToField(message);
753 loadURL.Data.URL = Helpers.StringToField(url);
754
755 OutPacket(loadURL, ThrottleOutPacketType.Task);
756 }
757
758
759 public void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
760 {
761 PreloadSoundPacket preSound = new PreloadSoundPacket();
762 preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
763 preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
764 preSound.DataBlock[0].ObjectID = objectID;
765 preSound.DataBlock[0].OwnerID = ownerID;
766 preSound.DataBlock[0].SoundID = soundID;
767 OutPacket(preSound, ThrottleOutPacketType.Task);
768 }
769
770 public void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags)
771 {
772 AttachedSoundPacket sound = new AttachedSoundPacket();
773 sound.DataBlock.SoundID = soundID;
774 sound.DataBlock.ObjectID = objectID;
775 sound.DataBlock.OwnerID = ownerID;
776 sound.DataBlock.Gain = gain;
777 sound.DataBlock.Flags = flags;
778
779 OutPacket(sound, ThrottleOutPacketType.Task);
780 }
781
782 public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel)
783 {
784 SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
785 viewertime.TimeInfo.SunDirection = sunPos;
786 viewertime.TimeInfo.SunAngVelocity = sunVel;
787 viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
788 OutPacket(viewertime, ThrottleOutPacketType.Task);
789 }
790
791 public void SendViewerTime(int phase)
792 {
793 Console.WriteLine("SunPhase: {0}", phase);
794 SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
795 //viewertime.TimeInfo.SecPerDay = 86400;
796 // viewertime.TimeInfo.SecPerYear = 31536000;
797 viewertime.TimeInfo.SecPerDay = 1000;
798 viewertime.TimeInfo.SecPerYear = 365000;
799 viewertime.TimeInfo.SunPhase = 1;
800 int sunPhase = (phase + 2)/2;
801 if ((sunPhase < 6) || (sunPhase > 36))
802 {
803 viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
804 Console.WriteLine("sending night");
805 }
806 else
807 {
808 if (sunPhase < 12)
809 {
810 sunPhase = 12;
811 }
812 sunPhase = sunPhase - 12;
813
814 float yValue = 0.1f*(sunPhase);
815 Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
816 if (yValue > 1.2f)
817 {
818 yValue = yValue - 1.2f;
819 }
820 if (yValue > 1)
821 {
822 yValue = 1;
823 }
824 if (yValue < 0)
825 {
826 yValue = 0;
827 }
828 if (sunPhase < 14)
829 {
830 yValue = 1 - yValue;
831 }
832 if (sunPhase < 12)
833 {
834 yValue *= -1;
835 }
836 viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
837 Console.WriteLine("sending sun update " + yValue);
838 }
839 viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
840 viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
841 OutPacket(viewertime, ThrottleOutPacketType.Task);
842 }
843
844 public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
845 string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
846 LLUUID partnerID)
847 {
848 AvatarPropertiesReplyPacket avatarReply = new AvatarPropertiesReplyPacket();
849 avatarReply.AgentData.AgentID = AgentId;
850 avatarReply.AgentData.AvatarID = avatarID;
851 avatarReply.PropertiesData.AboutText = Helpers.StringToField(aboutText);
852 avatarReply.PropertiesData.BornOn = Helpers.StringToField(bornOn);
853 avatarReply.PropertiesData.CharterMember = Helpers.StringToField(charterMember);
854 avatarReply.PropertiesData.FLAboutText = Helpers.StringToField(flAbout);
855 avatarReply.PropertiesData.Flags = 0;
856 avatarReply.PropertiesData.FLImageID = flImageID;
857 avatarReply.PropertiesData.ImageID = imageID;
858 avatarReply.PropertiesData.ProfileURL = Helpers.StringToField(profileURL);
859 avatarReply.PropertiesData.PartnerID = partnerID;
860 OutPacket(avatarReply, ThrottleOutPacketType.Task);
861 }
862
863 #endregion
864
865 #region Appearance/ Wearables Methods
866
867 /// <summary>
868 ///
869 /// </summary>
870 /// <param name="wearables"></param>
871 public void SendWearables(AvatarWearable[] wearables, int serial)
872 {
873 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
874 aw.AgentData.AgentID = AgentId;
875 aw.AgentData.SerialNum = (uint) serial;
876 aw.AgentData.SessionID = m_sessionId;
877
878 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
879 AgentWearablesUpdatePacket.WearableDataBlock awb;
880 for (int i = 0; i < wearables.Length; i++)
881 {
882 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
883 awb.WearableType = (byte) i;
884 awb.AssetID = wearables[i].AssetID;
885 awb.ItemID = wearables[i].ItemID;
886 aw.WearableData[i] = awb;
887 }
888
889 OutPacket(aw, ThrottleOutPacketType.Task);
890 }
891
892 /// <summary>
893 ///
894 /// </summary>
895 /// <param name="agentID"></param>
896 /// <param name="visualParams"></param>
897 /// <param name="textureEntry"></param>
898 public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
899 {
900 AvatarAppearancePacket avp = new AvatarAppearancePacket();
901 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
902 avp.ObjectData.TextureEntry = textureEntry;
903
904 AvatarAppearancePacket.VisualParamBlock avblock = null;
905 for (int i = 0; i < visualParams.Length; i++)
906 {
907 avblock = new AvatarAppearancePacket.VisualParamBlock();
908 avblock.ParamValue = visualParams[i];
909 avp.VisualParam[i] = avblock;
910 }
911
912 avp.Sender.IsTrial = false;
913 avp.Sender.ID = agentID;
914 OutPacket(avp, ThrottleOutPacketType.Task);
915 }
916
917 public void SendAnimation(LLUUID animID, int seq, LLUUID sourceAgentId)
918 {
919 AvatarAnimationPacket ani = new AvatarAnimationPacket();
920 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
921 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
922 ani.AnimationSourceList[0].ObjectID = sourceAgentId;
923 ani.Sender = new AvatarAnimationPacket.SenderBlock();
924 ani.Sender.ID = sourceAgentId;
925 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1];
926 ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock();
927 ani.AnimationList[0].AnimID = animID;
928 ani.AnimationList[0].AnimSequenceID = seq;
929 OutPacket(ani, ThrottleOutPacketType.Task);
930 }
931
932 #endregion
933
934 #region Avatar Packet/data sending Methods
935
936 /// <summary>
937 /// send a objectupdate packet with information about the clients avatar
938 /// </summary>
939 /// <param name="regionInfo"></param>
940 /// <param name="firstName"></param>
941 /// <param name="lastName"></param>
942 /// <param name="avatarID"></param>
943 /// <param name="avatarLocalID"></param>
944 /// <param name="Pos"></param>
945 public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
946 uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
947 {
948 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
949 objupdate.RegionData.RegionHandle = regionHandle;
950 objupdate.RegionData.TimeDilation = 64096;
951 objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
952 objupdate.ObjectData[0] = CreateDefaultAvatarPacket(textureEntry);
953
954 //give this avatar object a local id and assign the user a name
955 objupdate.ObjectData[0].ID = avatarLocalID;
956 objupdate.ObjectData[0].FullID = avatarID;
957 objupdate.ObjectData[0].ParentID = parentID;
958 objupdate.ObjectData[0].NameValue =
959 Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName);
960 LLVector3 pos2 = new LLVector3((float) Pos.X, (float) Pos.Y, (float) Pos.Z);
961 byte[] pb = pos2.GetBytes();
962 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
963
964 OutPacket(objupdate, ThrottleOutPacketType.Task);
965 }
966
967 /// <summary>
968 ///
969 /// </summary>
970 /// <param name="regionHandle"></param>
971 /// <param name="timeDilation"></param>
972 /// <param name="localID"></param>
973 /// <param name="position"></param>
974 /// <param name="velocity"></param>
975 public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
976 LLVector3 velocity, LLQuaternion rotation)
977 {
978 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock =
979 CreateAvatarImprovedBlock(localID, position, velocity, rotation);
980 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
981 terse.RegionData.RegionHandle = regionHandle;
982 terse.RegionData.TimeDilation = timeDilation;
983 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
984 terse.ObjectData[0] = terseBlock;
985
986 OutPacket(terse, ThrottleOutPacketType.Task);
987 }
988
989 public void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
990 {
991 CoarseLocationUpdatePacket loc = new CoarseLocationUpdatePacket();
992 int total = CoarseLocations.Count;
993 CoarseLocationUpdatePacket.IndexBlock ib =
994 new CoarseLocationUpdatePacket.IndexBlock();
995 loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
996 for (int i = 0; i < total; i++)
997 {
998 CoarseLocationUpdatePacket.LocationBlock lb =
999 new CoarseLocationUpdatePacket.LocationBlock();
1000 lb.X = (byte) CoarseLocations[i].X;
1001 lb.Y = (byte) CoarseLocations[i].Y;
1002 lb.Z = (byte) (CoarseLocations[i].Z/4);
1003 loc.Location[i] = lb;
1004 }
1005 ib.You = -1;
1006 ib.Prey = -1;
1007 loc.Index = ib;
1008 OutPacket(loc, ThrottleOutPacketType.Task);
1009 }
1010
1011 #endregion
1012
1013 #region Primitive Packet/data Sending Methods
1014
1015 /// <summary>
1016 ///
1017 /// </summary>
1018 /// <param name="localID"></param>
1019 /// <param name="rotation"></param>
1020 /// <param name="attachPoint"></param>
1021 public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
1022 {
1023 ObjectAttachPacket attach = new ObjectAttachPacket();
1024 attach.AgentData.AgentID = AgentId;
1025 attach.AgentData.SessionID = m_sessionId;
1026 attach.AgentData.AttachmentPoint = attachPoint;
1027 attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
1028 attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
1029 attach.ObjectData[0].ObjectLocalID = localID;
1030 attach.ObjectData[0].Rotation = rotation;
1031
1032 OutPacket(attach, ThrottleOutPacketType.Task);
1033 }
1034
1035 public void SendPrimitiveToClient(
1036 ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos,
1037 uint flags,
1038 LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem, LLQuaternion rotation, byte clickAction)
1039 {
1040 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
1041 outPacket.RegionData.RegionHandle = regionHandle;
1042 outPacket.RegionData.TimeDilation = timeDilation;
1043 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
1044
1045 outPacket.ObjectData[0] = CreatePrimUpdateBlock(primShape, flags);
1046
1047 outPacket.ObjectData[0].ID = localID;
1048 outPacket.ObjectData[0].FullID = objectID;
1049 outPacket.ObjectData[0].OwnerID = ownerID;
1050 outPacket.ObjectData[0].Text = Helpers.StringToField(text);
1051 outPacket.ObjectData[0].TextColor[0] = color[0];
1052 outPacket.ObjectData[0].TextColor[1] = color[1];
1053 outPacket.ObjectData[0].TextColor[2] = color[2];
1054 outPacket.ObjectData[0].TextColor[3] = color[3];
1055 outPacket.ObjectData[0].ParentID = parentID;
1056 outPacket.ObjectData[0].PSBlock = particleSystem;
1057 outPacket.ObjectData[0].ClickAction = clickAction;
1058 //outPacket.ObjectData[0].Flags = 0;
1059 outPacket.ObjectData[0].Radius = 20;
1060
1061 byte[] pb = pos.GetBytes();
1062 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
1063
1064 byte[] rot = rotation.GetBytes();
1065 Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length);
1066
1067 OutPacket(outPacket, ThrottleOutPacketType.Task);
1068 }
1069
1070 /// <summary>
1071 ///
1072 /// </summary>
1073 /// <param name="regionHandle"></param>
1074 /// <param name="timeDilation"></param>
1075 /// <param name="localID"></param>
1076 /// <param name="position"></param>
1077 /// <param name="rotation"></param>
1078 public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
1079 LLQuaternion rotation)
1080 {
1081 LLVector3 velocity = new LLVector3(0f,0f,0f);
1082 LLVector3 rotationalvelocity = new LLVector3(0f,0f,0f);
1083 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
1084 terse.RegionData.RegionHandle = regionHandle;
1085 terse.RegionData.TimeDilation = timeDilation;
1086 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
1087 terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity);
1088
1089 OutPacket(terse, ThrottleOutPacketType.Task);
1090 }
1091 public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
1092 LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity)
1093 {
1094
1095 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
1096 terse.RegionData.RegionHandle = regionHandle;
1097 terse.RegionData.TimeDilation = timeDilation;
1098 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
1099 terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity);
1100
1101 OutPacket(terse, ThrottleOutPacketType.Task);
1102 }
1103
1104
1105 #endregion
1106
1107 #region Helper Methods
1108
1109 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos,
1110 LLVector3 velocity,
1111 LLQuaternion rotation)
1112 {
1113 byte[] bytes = new byte[60];
1114 int i = 0;
1115 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
1116
1117 dat.TextureEntry = new byte[0]; // AvatarTemplate.TextureEntry;
1118
1119 uint ID = localID;
1120
1121 bytes[i++] = (byte) (ID%256);
1122 bytes[i++] = (byte) ((ID >> 8)%256);
1123 bytes[i++] = (byte) ((ID >> 16)%256);
1124 bytes[i++] = (byte) ((ID >> 24)%256);
1125 bytes[i++] = 0;
1126 bytes[i++] = 1;
1127 i += 14;
1128 bytes[i++] = 128;
1129 bytes[i++] = 63;
1130
1131 byte[] pb = pos.GetBytes();
1132 Array.Copy(pb, 0, bytes, i, pb.Length);
1133 i += 12;
1134 ushort InternVelocityX;
1135 ushort InternVelocityY;
1136 ushort InternVelocityZ;
1137 Vector3 internDirec = new Vector3(0, 0, 0);
1138
1139 internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z);
1140
1141 internDirec = internDirec/128.0f;
1142 internDirec.x += 1;
1143 internDirec.y += 1;
1144 internDirec.z += 1;
1145
1146 InternVelocityX = (ushort) (32768*internDirec.x);
1147 InternVelocityY = (ushort) (32768*internDirec.y);
1148 InternVelocityZ = (ushort) (32768*internDirec.z);
1149
1150 ushort ac = 32767;
1151 bytes[i++] = (byte) (InternVelocityX%256);
1152 bytes[i++] = (byte) ((InternVelocityX >> 8)%256);
1153 bytes[i++] = (byte) (InternVelocityY%256);
1154 bytes[i++] = (byte) ((InternVelocityY >> 8)%256);
1155 bytes[i++] = (byte) (InternVelocityZ%256);
1156 bytes[i++] = (byte) ((InternVelocityZ >> 8)%256);
1157
1158 //accel
1159 bytes[i++] = (byte) (ac%256);
1160 bytes[i++] = (byte) ((ac >> 8)%256);
1161 bytes[i++] = (byte) (ac%256);
1162 bytes[i++] = (byte) ((ac >> 8)%256);
1163 bytes[i++] = (byte) (ac%256);
1164 bytes[i++] = (byte) ((ac >> 8)%256);
1165
1166 //rotation
1167 ushort rw, rx, ry, rz;
1168 rw = (ushort) (32768*(rotation.W + 1));
1169 rx = (ushort) (32768*(rotation.X + 1));
1170 ry = (ushort) (32768*(rotation.Y + 1));
1171 rz = (ushort) (32768*(rotation.Z + 1));
1172
1173 //rot
1174 bytes[i++] = (byte) (rx%256);
1175 bytes[i++] = (byte) ((rx >> 8)%256);
1176 bytes[i++] = (byte) (ry%256);
1177 bytes[i++] = (byte) ((ry >> 8)%256);
1178 bytes[i++] = (byte) (rz%256);
1179 bytes[i++] = (byte) ((rz >> 8)%256);
1180 bytes[i++] = (byte) (rw%256);
1181 bytes[i++] = (byte) ((rw >> 8)%256);
1182
1183 //rotation vel
1184 bytes[i++] = (byte) (ac%256);
1185 bytes[i++] = (byte) ((ac >> 8)%256);
1186 bytes[i++] = (byte) (ac%256);
1187 bytes[i++] = (byte) ((ac >> 8)%256);
1188 bytes[i++] = (byte) (ac%256);
1189 bytes[i++] = (byte) ((ac >> 8)%256);
1190
1191 dat.Data = bytes;
1192
1193 return (dat);
1194 }
1195
1196 /// <summary>
1197 ///
1198 /// </summary>
1199 /// <param name="localID"></param>
1200 /// <param name="position"></param>
1201 /// <param name="rotation"></param>
1202 /// <returns></returns>
1203 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID,
1204 LLVector3 position,
1205 LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity)
1206 {
1207 uint ID = localID;
1208 byte[] bytes = new byte[60];
1209
1210 int i = 0;
1211 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
1212 dat.TextureEntry = new byte[0];
1213 bytes[i++] = (byte) (ID%256);
1214 bytes[i++] = (byte) ((ID >> 8)%256);
1215 bytes[i++] = (byte) ((ID >> 16)%256);
1216 bytes[i++] = (byte) ((ID >> 24)%256);
1217 bytes[i++] = 0;
1218 bytes[i++] = 0;
1219
1220 byte[] pb = position.GetBytes();
1221 Array.Copy(pb, 0, bytes, i, pb.Length);
1222 i += 12;
1223 ushort ac = 32767;
1224
1225 ushort velx, vely, velz;
1226 Vector3 vel = new Vector3(velocity.X, velocity.Y, velocity.Z);
1227
1228 vel = vel/128.0f;
1229 vel.x += 1;
1230 vel.y += 1;
1231 vel.z += 1;
1232 //vel
1233 velx = (ushort)(32768 * (vel.x));
1234 vely = (ushort)(32768 * (vel.y));
1235 velz = (ushort)(32768 * (vel.z));
1236
1237 bytes[i++] = (byte) (velx % 256);
1238 bytes[i++] = (byte) ((velx >> 8) % 256);
1239 bytes[i++] = (byte) (vely % 256);
1240 bytes[i++] = (byte) ((vely >> 8) % 256);
1241 bytes[i++] = (byte) (velz % 256);
1242 bytes[i++] = (byte) ((velz >> 8) % 256);
1243
1244 //accel
1245 bytes[i++] = (byte) (ac%256);
1246 bytes[i++] = (byte) ((ac >> 8)%256);
1247 bytes[i++] = (byte) (ac%256);
1248 bytes[i++] = (byte) ((ac >> 8)%256);
1249 bytes[i++] = (byte) (ac%256);
1250 bytes[i++] = (byte) ((ac >> 8)%256);
1251
1252 ushort rw, rx, ry, rz;
1253 rw = (ushort) (32768*(rotation.W + 1));
1254 rx = (ushort) (32768*(rotation.X + 1));
1255 ry = (ushort) (32768*(rotation.Y + 1));
1256 rz = (ushort) (32768*(rotation.Z + 1));
1257
1258 //rot
1259 bytes[i++] = (byte) (rx%256);
1260 bytes[i++] = (byte) ((rx >> 8)%256);
1261 bytes[i++] = (byte) (ry%256);
1262 bytes[i++] = (byte) ((ry >> 8)%256);
1263 bytes[i++] = (byte) (rz%256);
1264 bytes[i++] = (byte) ((rz >> 8)%256);
1265 bytes[i++] = (byte) (rw%256);
1266 bytes[i++] = (byte) ((rw >> 8)%256);
1267
1268 //rotation vel
1269 ushort rvelx, rvely, rvelz;
1270 Vector3 rvel = new Vector3(rotationalvelocity.X, rotationalvelocity.Y, rotationalvelocity.Z);
1271
1272 rvel = rvel / 128.0f;
1273 rvel.x += 1;
1274 rvel.y += 1;
1275 rvel.z += 1;
1276 //vel
1277 rvelx = (ushort)(32768 * (rvel.x));
1278 rvely = (ushort)(32768 * (rvel.y));
1279 rvelz = (ushort)(32768 * (rvel.z));
1280
1281 bytes[i++] = (byte)(rvelx % 256);
1282 bytes[i++] = (byte)((rvelx >> 8) % 256);
1283 bytes[i++] = (byte)(rvely % 256);
1284 bytes[i++] = (byte)((rvely >> 8) % 256);
1285 bytes[i++] = (byte)(rvelz % 256);
1286 bytes[i++] = (byte)((rvelz >> 8) % 256);
1287
1288 dat.Data = bytes;
1289 return dat;
1290 }
1291
1292 /// <summary>
1293 /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
1294 /// </summary>
1295 /// <param name="primData"></param>
1296 /// <returns></returns>
1297 protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, uint flags)
1298 {
1299 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
1300 SetDefaultPrimPacketValues(objupdate);
1301 objupdate.UpdateFlags = flags;
1302 SetPrimPacketShapeData(objupdate, primShape);
1303
1304 return objupdate;
1305 }
1306
1307 protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData)
1308 {
1309 objectData.TextureEntry = primData.TextureEntry;
1310 objectData.PCode = primData.PCode;
1311 objectData.PathBegin = primData.PathBegin;
1312 objectData.PathEnd = primData.PathEnd;
1313 objectData.PathScaleX = primData.PathScaleX;
1314 objectData.PathScaleY = primData.PathScaleY;
1315 objectData.PathShearX = primData.PathShearX;
1316 objectData.PathShearY = primData.PathShearY;
1317 objectData.PathSkew = primData.PathSkew;
1318 objectData.ProfileBegin = primData.ProfileBegin;
1319 objectData.ProfileEnd = primData.ProfileEnd;
1320 objectData.Scale = primData.Scale;
1321 objectData.PathCurve = primData.PathCurve;
1322 objectData.ProfileCurve = primData.ProfileCurve;
1323 objectData.ProfileHollow = primData.ProfileHollow;
1324 objectData.PathRadiusOffset = primData.PathRadiusOffset;
1325 objectData.PathRevolutions = primData.PathRevolutions;
1326 objectData.PathTaperX = primData.PathTaperX;
1327 objectData.PathTaperY = primData.PathTaperY;
1328 objectData.PathTwist = primData.PathTwist;
1329 objectData.PathTwistBegin = primData.PathTwistBegin;
1330 objectData.ExtraParams = primData.ExtraParams;
1331 }
1332
1333 /// <summary>
1334 /// Set some default values in a ObjectUpdatePacket
1335 /// </summary>
1336 /// <param name="objdata"></param>
1337 protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
1338 {
1339 objdata.PSBlock = new byte[0];
1340 objdata.ExtraParams = new byte[1];
1341 objdata.MediaURL = new byte[0];
1342 objdata.NameValue = new byte[0];
1343 objdata.Text = new byte[0];
1344 objdata.TextColor = new byte[4];
1345 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
1346 objdata.JointPivot = new LLVector3(0, 0, 0);
1347 objdata.Material = 3;
1348 objdata.TextureAnim = new byte[0];
1349 objdata.Sound = LLUUID.Zero;
1350 objdata.State = 0;
1351 objdata.Data = new byte[0];
1352
1353 objdata.ObjectData = new byte[60];
1354 objdata.ObjectData[46] = 128;
1355 objdata.ObjectData[47] = 63;
1356 }
1357
1358
1359 /// <summary>
1360 ///
1361 /// </summary>
1362 /// <returns></returns>
1363 protected ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
1364 {
1365 ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock();
1366 // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
1367
1368 SetDefaultAvatarPacketValues(ref objdata);
1369 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
1370 objdata.PathCurve = 16;
1371 objdata.ProfileCurve = 1;
1372 objdata.PathScaleX = 100;
1373 objdata.PathScaleY = 100;
1374 objdata.ParentID = 0;
1375 objdata.OwnerID = LLUUID.Zero;
1376 objdata.Scale = new LLVector3(1, 1, 1);
1377 objdata.PCode = 47;
1378 if (textureEntry != null)
1379 {
1380 objdata.TextureEntry = textureEntry;
1381 }
1382 Encoding enc = Encoding.ASCII;
1383 LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
1384 pos.X = 100f;
1385 objdata.ID = 8880000;
1386 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
1387 //LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
1388 //objdata.FullID=user.AgentId;
1389 byte[] pb = pos.GetBytes();
1390 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
1391
1392 return objdata;
1393 }
1394
1395 /// <summary>
1396 ///
1397 /// </summary>
1398 /// <param name="objdata"></param>
1399 protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
1400 {
1401 objdata.PSBlock = new byte[0];
1402 objdata.ExtraParams = new byte[1];
1403 objdata.MediaURL = new byte[0];
1404 objdata.NameValue = new byte[0];
1405 objdata.Text = new byte[0];
1406 objdata.TextColor = new byte[4];
1407 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
1408 objdata.JointPivot = new LLVector3(0, 0, 0);
1409 objdata.Material = 4;
1410 objdata.TextureAnim = new byte[0];
1411 objdata.Sound = LLUUID.Zero;
1412 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
1413 objdata.TextureEntry = ntex.ToBytes();
1414 objdata.State = 0;
1415 objdata.Data = new byte[0];
1416
1417 objdata.ObjectData = new byte[76];
1418 objdata.ObjectData[15] = 128;
1419 objdata.ObjectData[16] = 63;
1420 objdata.ObjectData[56] = 128;
1421 objdata.ObjectData[61] = 102;
1422 objdata.ObjectData[62] = 40;
1423 objdata.ObjectData[63] = 61;
1424 objdata.ObjectData[64] = 189;
1425 }
1426
1427 public void SendNameReply(LLUUID profileId, string firstname, string lastname)
1428 {
1429 UUIDNameReplyPacket packet = new UUIDNameReplyPacket();
1430
1431 packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
1432 packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
1433 packet.UUIDNameBlock[0].ID = profileId;
1434 packet.UUIDNameBlock[0].FirstName = Helpers.StringToField(firstname);
1435 packet.UUIDNameBlock[0].LastName = Helpers.StringToField(lastname);
1436
1437 OutPacket(packet, ThrottleOutPacketType.Task);
1438 }
1439
1440 #endregion
1441 }
1442}