clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 OpenSimulator 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;
30 using System.Collections.Generic;
31 using System.Net;
32 using System.Reflection;
33 using System.Text;
34 using System.Threading;
35 using System.Timers;
36 using System.Xml;
37  
38 using log4net;
39 using OpenMetaverse;
40 using OpenMetaverse.Packets;
41 using OpenMetaverse.Messages.Linden;
42 using OpenMetaverse.StructuredData;
43  
44 using OpenSim.Framework;
45 using OpenSim.Framework.Client;
46 using OpenSim.Framework.Monitoring;
47 using OpenSim.Region.Framework.Interfaces;
48 using OpenSim.Region.Framework.Scenes;
49 using OpenSim.Services.Interfaces;
50 using Timer = System.Timers.Timer;
51 using AssetLandmark = OpenSim.Framework.AssetLandmark;
52 using RegionFlags = OpenMetaverse.RegionFlags;
53  
54 using System.IO;
55 using PermissionMask = OpenSim.Framework.PermissionMask;
56  
57 namespace OpenSim.Region.ClientStack.LindenUDP
58 {
59 public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
60  
61 /// <summary>
62 /// Handles new client connections
63 /// Constructor takes a single Packet and authenticates everything
64 /// </summary>
65 public class LLClientView : IClientAPI, IClientCore, IClientIM, IClientChat, IClientInventory, IStatsCollector
66 {
67 /// <value>
68 /// Debug packet level. See OpenSim.RegisterConsoleCommands() for more details.
69 /// </value>
70 public int DebugPacketLevel { get; set; }
71  
72 #region Events
73  
74 public event BinaryGenericMessage OnBinaryGenericMessage;
75 public event Action<IClientAPI> OnLogout;
76 public event ObjectPermissions OnObjectPermissions;
77 public event Action<IClientAPI> OnConnectionClosed;
78 public event ViewerEffectEventHandler OnViewerEffect;
79 public event ImprovedInstantMessage OnInstantMessage;
80 public event ChatMessage OnChatFromClient;
81 public event RezObject OnRezObject;
82 public event DeRezObject OnDeRezObject;
83 public event ModifyTerrain OnModifyTerrain;
84 public event Action<IClientAPI> OnRegionHandShakeReply;
85 public event GenericCall1 OnRequestWearables;
86 public event SetAppearance OnSetAppearance;
87 public event AvatarNowWearing OnAvatarNowWearing;
88 public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
89 public event RezMultipleAttachmentsFromInv OnRezMultipleAttachmentsFromInv;
90 public event UUIDNameRequest OnDetachAttachmentIntoInv;
91 public event ObjectAttach OnObjectAttach;
92 public event ObjectDeselect OnObjectDetach;
93 public event ObjectDrop OnObjectDrop;
94 public event Action<IClientAPI, bool> OnCompleteMovementToRegion;
95 public event UpdateAgent OnPreAgentUpdate;
96 public event UpdateAgent OnAgentUpdate;
97 public event UpdateAgent OnAgentCameraUpdate;
98 public event AgentRequestSit OnAgentRequestSit;
99 public event AgentSit OnAgentSit;
100 public event AvatarPickerRequest OnAvatarPickerRequest;
101 public event StartAnim OnStartAnim;
102 public event StopAnim OnStopAnim;
103 public event Action<IClientAPI> OnRequestAvatarsData;
104 public event LinkObjects OnLinkObjects;
105 public event DelinkObjects OnDelinkObjects;
106 public event GrabObject OnGrabObject;
107 public event DeGrabObject OnDeGrabObject;
108 public event SpinStart OnSpinStart;
109 public event SpinStop OnSpinStop;
110 public event ObjectDuplicate OnObjectDuplicate;
111 public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
112 public event MoveObject OnGrabUpdate;
113 public event SpinObject OnSpinUpdate;
114 public event AddNewPrim OnAddPrim;
115 public event RequestGodlikePowers OnRequestGodlikePowers;
116 public event GodKickUser OnGodKickUser;
117 public event ObjectExtraParams OnUpdateExtraParams;
118 public event UpdateShape OnUpdatePrimShape;
119 public event ObjectRequest OnObjectRequest;
120 public event ObjectSelect OnObjectSelect;
121 public event ObjectDeselect OnObjectDeselect;
122 public event GenericCall7 OnObjectDescription;
123 public event GenericCall7 OnObjectName;
124 public event GenericCall7 OnObjectClickAction;
125 public event GenericCall7 OnObjectMaterial;
126 public event ObjectIncludeInSearch OnObjectIncludeInSearch;
127 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
128 public event UpdatePrimFlags OnUpdatePrimFlags;
129 public event UpdatePrimTexture OnUpdatePrimTexture;
130 public event UpdateVector OnUpdatePrimGroupPosition;
131 public event UpdateVector OnUpdatePrimSinglePosition;
132 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
133 public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
134 public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
135 public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
136 public event UpdateVector OnUpdatePrimScale;
137 public event UpdateVector OnUpdatePrimGroupScale;
138 public event RequestMapBlocks OnRequestMapBlocks;
139 public event RequestMapName OnMapNameRequest;
140 public event TeleportLocationRequest OnTeleportLocationRequest;
141 public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
142 public event TeleportCancel OnTeleportCancel;
143 public event RequestAvatarProperties OnRequestAvatarProperties;
144 public event SetAlwaysRun OnSetAlwaysRun;
145 public event FetchInventory OnAgentDataUpdateRequest;
146 public event TeleportLocationRequest OnSetStartLocationRequest;
147 public event UpdateAvatarProperties OnUpdateAvatarProperties;
148 public event CreateNewInventoryItem OnCreateNewInventoryItem;
149 public event LinkInventoryItem OnLinkInventoryItem;
150 public event CreateInventoryFolder OnCreateNewInventoryFolder;
151 public event UpdateInventoryFolder OnUpdateInventoryFolder;
152 public event MoveInventoryFolder OnMoveInventoryFolder;
153 public event FetchInventoryDescendents OnFetchInventoryDescendents;
154 public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
155 public event FetchInventory OnFetchInventory;
156 public event RequestTaskInventory OnRequestTaskInventory;
157 public event UpdateInventoryItem OnUpdateInventoryItem;
158 public event CopyInventoryItem OnCopyInventoryItem;
159 public event MoveInventoryItem OnMoveInventoryItem;
160 public event RemoveInventoryItem OnRemoveInventoryItem;
161 public event RemoveInventoryFolder OnRemoveInventoryFolder;
162 public event UDPAssetUploadRequest OnAssetUploadRequest;
163 public event XferReceive OnXferReceive;
164 public event RequestXfer OnRequestXfer;
165 public event ConfirmXfer OnConfirmXfer;
166 public event AbortXfer OnAbortXfer;
167 public event RequestTerrain OnRequestTerrain;
168 public event RezScript OnRezScript;
169 public event UpdateTaskInventory OnUpdateTaskInventory;
170 public event MoveTaskInventory OnMoveTaskItem;
171 public event RemoveTaskInventory OnRemoveTaskItem;
172 public event UUIDNameRequest OnNameFromUUIDRequest;
173 public event ParcelAccessListRequest OnParcelAccessListRequest;
174 public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
175 public event ParcelPropertiesRequest OnParcelPropertiesRequest;
176 public event ParcelDivideRequest OnParcelDivideRequest;
177 public event ParcelJoinRequest OnParcelJoinRequest;
178 public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
179 public event ParcelSelectObjects OnParcelSelectObjects;
180 public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
181 public event ParcelAbandonRequest OnParcelAbandonRequest;
182 public event ParcelGodForceOwner OnParcelGodForceOwner;
183 public event ParcelReclaim OnParcelReclaim;
184 public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
185 public event ParcelDeedToGroup OnParcelDeedToGroup;
186 public event RegionInfoRequest OnRegionInfoRequest;
187 public event EstateCovenantRequest OnEstateCovenantRequest;
188 public event FriendActionDelegate OnApproveFriendRequest;
189 public event FriendActionDelegate OnDenyFriendRequest;
190 public event FriendshipTermination OnTerminateFriendship;
191 public event GrantUserFriendRights OnGrantUserRights;
192 public event MoneyTransferRequest OnMoneyTransferRequest;
193 public event EconomyDataRequest OnEconomyDataRequest;
194 public event MoneyBalanceRequest OnMoneyBalanceRequest;
195 public event ParcelBuy OnParcelBuy;
196 public event UUIDNameRequest OnTeleportHomeRequest;
197 public event UUIDNameRequest OnUUIDGroupNameRequest;
198 public event ScriptAnswer OnScriptAnswer;
199 public event RequestPayPrice OnRequestPayPrice;
200 public event ObjectSaleInfo OnObjectSaleInfo;
201 public event ObjectBuy OnObjectBuy;
202 public event AgentSit OnUndo;
203 public event AgentSit OnRedo;
204 public event LandUndo OnLandUndo;
205 public event ForceReleaseControls OnForceReleaseControls;
206 public event GodLandStatRequest OnLandStatRequest;
207 public event RequestObjectPropertiesFamily OnObjectGroupRequest;
208 public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
209 public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
210 public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
211 public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
212 public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
213 public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
214 public event BakeTerrain OnBakeTerrain;
215 public event RequestTerrain OnUploadTerrain;
216 public event EstateChangeInfo OnEstateChangeInfo;
217 public event EstateManageTelehub OnEstateManageTelehub;
218 public event EstateRestartSimRequest OnEstateRestartSimRequest;
219 public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
220 public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
221 public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
222 public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
223 public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
224 public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
225 public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
226 public event RegionHandleRequest OnRegionHandleRequest;
227 public event ParcelInfoRequest OnParcelInfoRequest;
228 public event ScriptReset OnScriptReset;
229 public event GetScriptRunning OnGetScriptRunning;
230 public event SetScriptRunning OnSetScriptRunning;
231 public event Action<Vector3, bool, bool> OnAutoPilotGo;
232 public event ActivateGesture OnActivateGesture;
233 public event DeactivateGesture OnDeactivateGesture;
234 public event ObjectOwner OnObjectOwner;
235 public event DirPlacesQuery OnDirPlacesQuery;
236 public event DirFindQuery OnDirFindQuery;
237 public event DirLandQuery OnDirLandQuery;
238 public event DirPopularQuery OnDirPopularQuery;
239 public event DirClassifiedQuery OnDirClassifiedQuery;
240 public event EventInfoRequest OnEventInfoRequest;
241 public event ParcelSetOtherCleanTime OnParcelSetOtherCleanTime;
242 public event MapItemRequest OnMapItemRequest;
243 public event OfferCallingCard OnOfferCallingCard;
244 public event AcceptCallingCard OnAcceptCallingCard;
245 public event DeclineCallingCard OnDeclineCallingCard;
246 public event SoundTrigger OnSoundTrigger;
247 public event StartLure OnStartLure;
248 public event TeleportLureRequest OnTeleportLureRequest;
249 public event NetworkStats OnNetworkStatsUpdate;
250 public event ClassifiedInfoRequest OnClassifiedInfoRequest;
251 public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
252 public event ClassifiedDelete OnClassifiedDelete;
253 public event ClassifiedDelete OnClassifiedGodDelete;
254 public event EventNotificationAddRequest OnEventNotificationAddRequest;
255 public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
256 public event EventGodDelete OnEventGodDelete;
257 public event ParcelDwellRequest OnParcelDwellRequest;
258 public event UserInfoRequest OnUserInfoRequest;
259 public event UpdateUserInfo OnUpdateUserInfo;
260 public event RetrieveInstantMessages OnRetrieveInstantMessages;
261 public event PickDelete OnPickDelete;
262 public event PickGodDelete OnPickGodDelete;
263 public event PickInfoUpdate OnPickInfoUpdate;
264 public event AvatarNotesUpdate OnAvatarNotesUpdate;
265 public event MuteListRequest OnMuteListRequest;
266 public event AvatarInterestUpdate OnAvatarInterestUpdate;
267 public event PlacesQuery OnPlacesQuery;
268 public event AgentFOV OnAgentFOV;
269 public event FindAgentUpdate OnFindAgent;
270 public event TrackAgentUpdate OnTrackAgent;
271 public event NewUserReport OnUserReport;
272 public event SaveStateHandler OnSaveState;
273 public event GroupAccountSummaryRequest OnGroupAccountSummaryRequest;
274 public event GroupAccountDetailsRequest OnGroupAccountDetailsRequest;
275 public event GroupAccountTransactionsRequest OnGroupAccountTransactionsRequest;
276 public event FreezeUserUpdate OnParcelFreezeUser;
277 public event EjectUserUpdate OnParcelEjectUser;
278 public event ParcelBuyPass OnParcelBuyPass;
279 public event ParcelGodMark OnParcelGodMark;
280 public event GroupActiveProposalsRequest OnGroupActiveProposalsRequest;
281 public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
282 public event SimWideDeletesDelegate OnSimWideDeletes;
283 public event SendPostcard OnSendPostcard;
284 public event MuteListEntryUpdate OnUpdateMuteListEntry;
285 public event MuteListEntryRemove OnRemoveMuteListEntry;
286 public event GodlikeMessage onGodlikeMessage;
287 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
288  
289 #pragma warning disable 0067
290 public event GenericMessage OnGenericMessage;
291 public event TextureRequest OnRequestTexture;
292 public event StatusChange OnChildAgentStatus;
293 public event GenericCall2 OnStopMovement;
294 public event Action<UUID> OnRemoveAvatar;
295 public event DisconnectUser OnDisconnectUser;
296 public event RequestAsset OnRequestAsset;
297 public event BuyObjectInventory OnBuyObjectInventory;
298 public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
299 public event TerrainUnacked OnUnackedTerrain;
300 public event CachedTextureRequest OnCachedTextureRequest;
301 #pragma warning restore 0067
302  
303 #endregion Events
304  
305 #region Class Members
306  
307 // LLClientView Only
308 public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
309  
310 /// <summary>Used to adjust Sun Orbit values so Linden based viewers properly position sun</summary>
311 private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
312  
313 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
314 private static string LogHeader = "[LLCLIENTVIEW]";
315 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
316  
317 /// <summary>
318 /// Handles UDP texture download.
319 /// </summary>
320 public LLImageManager ImageManager { get; private set; }
321  
322 private readonly LLUDPServer m_udpServer;
323 private readonly LLUDPClient m_udpClient;
324 private readonly UUID m_sessionId;
325 private readonly UUID m_secureSessionId;
326 protected readonly UUID m_agentId;
327 private readonly uint m_circuitCode;
328 private readonly byte[] m_channelVersion = Utils.EmptyBytes;
329 private readonly IGroupsModule m_GroupsModule;
330  
331 private int m_cachedTextureSerial;
332 private PriorityQueue m_entityUpdates;
333 private PriorityQueue m_entityProps;
334 private Prioritizer m_prioritizer;
335 private bool m_disableFacelights = false;
336 private volatile bool m_justEditedTerrain = false;
337 /// <value>
338 /// List used in construction of data blocks for an object update packet. This is to stop us having to
339 /// continually recreate it.
340 /// </value>
341 protected List<ObjectUpdatePacket.ObjectDataBlock> m_fullUpdateDataBlocksBuilder;
342  
343 /// <value>
344 /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the
345 /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
346 /// ownerless phantom.
347 ///
348 /// All manipulation of this set has to occur under a lock
349 ///
350 /// </value>
351 protected HashSet<uint> m_killRecord;
352  
353 // protected HashSet<uint> m_attachmentsSent;
354  
355 private int m_animationSequenceNumber = 1;
356 private bool m_SendLogoutPacketWhenClosing = true;
357  
358 /// <summary>
359 /// We retain a single AgentUpdateArgs so that we can constantly reuse it rather than construct a new one for
360 /// every single incoming AgentUpdate. Every client sends 10 AgentUpdate UDP messages per second, even if it
361 /// is doing absolutely nothing.
362 /// </summary>
363 /// <remarks>
364 /// This does mean that agent updates must be processed synchronously, at least for each client, and called methods
365 /// cannot retain a reference to it outside of that method.
366 /// </remarks>
367 private AgentUpdateArgs m_thisAgentUpdateArgs = new AgentUpdateArgs();
368  
369 protected Dictionary<PacketType, PacketProcessor> m_packetHandlers = new Dictionary<PacketType, PacketProcessor>();
370 protected Dictionary<string, GenericMessage> m_genericPacketHandlers = new Dictionary<string, GenericMessage>(); //PauPaw:Local Generic Message handlers
371 protected Scene m_scene;
372 protected string m_firstName;
373 protected string m_lastName;
374 protected Thread m_clientThread;
375 protected Vector3 m_startpos;
376 protected UUID m_activeGroupID;
377 protected string m_activeGroupName = String.Empty;
378 protected ulong m_activeGroupPowers;
379 protected Dictionary<UUID, ulong> m_groupPowers = new Dictionary<UUID, ulong>();
380 protected int m_terrainCheckerCount;
381 protected uint m_agentFOVCounter;
382  
383 protected IAssetService m_assetService;
384 private const bool m_checkPackets = true;
385  
386 #endregion Class Members
387  
388 #region Properties
389  
390 public LLUDPClient UDPClient { get { return m_udpClient; } }
391 public LLUDPServer UDPServer { get { return m_udpServer; } }
392 public IPEndPoint RemoteEndPoint { get { return m_udpClient.RemoteEndPoint; } }
393 public UUID SecureSessionId { get { return m_secureSessionId; } }
394 public IScene Scene { get { return m_scene; } }
395 public UUID SessionId { get { return m_sessionId; } }
396 public Vector3 StartPos
397 {
398 get { return m_startpos; }
399 set { m_startpos = value; }
400 }
401 public UUID AgentId { get { return m_agentId; } }
402 public ISceneAgent SceneAgent { get; set; }
403 public UUID ActiveGroupId { get { return m_activeGroupID; } private set { m_activeGroupID = value; } }
404 public string ActiveGroupName { get { return m_activeGroupName; } private set { m_activeGroupName = value; } }
405 public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } private set { m_activeGroupPowers = value; } }
406 public bool IsGroupMember(UUID groupID) { return m_groupPowers.ContainsKey(groupID); }
407  
408 /// <summary>
409 /// Entity update queues
410 /// </summary>
411 public PriorityQueue EntityUpdateQueue { get { return m_entityUpdates; } }
412  
413 /// <summary>
414 /// First name of the agent/avatar represented by the client
415 /// </summary>
416 public string FirstName { get { return m_firstName; } }
417  
418 /// <summary>
419 /// Last name of the agent/avatar represented by the client
420 /// </summary>
421 public string LastName { get { return m_lastName; } }
422  
423 /// <summary>
424 /// Full name of the client (first name and last name)
425 /// </summary>
426 public string Name { get { return FirstName + " " + LastName; } }
427  
428 public uint CircuitCode { get { return m_circuitCode; } }
429 public int NextAnimationSequenceNumber { get { return m_animationSequenceNumber++; } }
430  
431 /// <summary>
432 /// As well as it's function in IClientAPI, in LLClientView we are locking on this property in order to
433 /// prevent race conditions by different threads calling Close().
434 /// </summary>
435 public bool IsActive { get; set; }
436  
437 /// <summary>
438 /// Used to synchronise threads when client is being closed.
439 /// </summary>
440 public Object CloseSyncLock { get; private set; }
441  
442 public bool IsLoggingOut { get; set; }
443  
444 public bool DisableFacelights
445 {
446 get { return m_disableFacelights; }
447 set { m_disableFacelights = value; }
448 }
449  
450 public bool SendLogoutPacketWhenClosing { set { m_SendLogoutPacketWhenClosing = value; } }
451  
452 #endregion Properties
453  
454 // ~LLClientView()
455 // {
456 // m_log.DebugFormat("{0} Destructor called for {1}, circuit code {2}", LogHeader, Name, CircuitCode);
457 // }
458  
459 /// <summary>
460 /// Constructor
461 /// </summary>
462 public LLClientView(Scene scene, LLUDPServer udpServer, LLUDPClient udpClient, AuthenticateResponse sessionInfo,
463 UUID agentId, UUID sessionId, uint circuitCode)
464 {
465 // DebugPacketLevel = 1;
466  
467 CloseSyncLock = new Object();
468  
469 RegisterInterface<IClientIM>(this);
470 RegisterInterface<IClientInventory>(this);
471 RegisterInterface<IClientChat>(this);
472  
473 m_scene = scene;
474 m_entityUpdates = new PriorityQueue(m_scene.Entities.Count);
475 m_entityProps = new PriorityQueue(m_scene.Entities.Count);
476 m_fullUpdateDataBlocksBuilder = new List<ObjectUpdatePacket.ObjectDataBlock>();
477 m_killRecord = new HashSet<uint>();
478 // m_attachmentsSent = new HashSet<uint>();
479  
480 m_assetService = m_scene.RequestModuleInterface<IAssetService>();
481 m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
482 ImageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
483 m_channelVersion = Util.StringToBytes256(scene.GetSimulatorVersion());
484 m_agentId = agentId;
485 m_sessionId = sessionId;
486 m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
487 m_circuitCode = circuitCode;
488 m_firstName = sessionInfo.LoginInfo.First;
489 m_lastName = sessionInfo.LoginInfo.Last;
490 m_startpos = sessionInfo.LoginInfo.StartPos;
491  
492 m_udpServer = udpServer;
493 m_udpClient = udpClient;
494 m_udpClient.OnQueueEmpty += HandleQueueEmpty;
495 m_udpClient.HasUpdates += HandleHasUpdates;
496 m_udpClient.OnPacketStats += PopulateStats;
497  
498 m_prioritizer = new Prioritizer(m_scene);
499  
500 RegisterLocalPacketHandlers();
501  
502 IsActive = true;
503 }
504  
505 #region Client Methods
506  
507 public void Close()
508 {
509 Close(false);
510 }
511  
512 public void Close(bool force)
513 {
514 // We lock here to prevent race conditions between two threads calling close simultaneously (e.g.
515 // a simultaneous relog just as a client is being closed out due to no packet ack from the old connection.
516 lock (CloseSyncLock)
517 {
518 // We still perform a force close inside the sync lock since this is intended to attempt close where
519 // there is some unidentified connection problem, not where we have issues due to deadlock
520 if (!IsActive && !force)
521 {
522 m_log.DebugFormat( "{0} Not attempting to close inactive client {1} in {2} since force flag is not set",
523 LogHeader, Name, m_scene.Name);
524  
525 return;
526 }
527  
528 IsActive = false;
529 CloseWithoutChecks();
530 }
531 }
532  
533 /// <summary>
534 /// Closes down the client view without first checking whether it is active.
535 /// </summary>
536 /// <remarks>
537 /// This exists because LLUDPServer has to set IsActive = false in earlier synchronous code before calling
538 /// CloseWithoutIsActiveCheck asynchronously.
539 ///
540 /// Callers must lock ClosingSyncLock before calling.
541 /// </remarks>
542 public void CloseWithoutChecks()
543 {
544 m_log.DebugFormat(
545 "[CLIENT]: Close has been called for {0} attached to scene {1}",
546 Name, m_scene.RegionInfo.RegionName);
547  
548 // Shutdown the image manager
549 ImageManager.Close();
550  
551 // Fire the callback for this connection closing
552 if (OnConnectionClosed != null)
553 OnConnectionClosed(this);
554  
555 // Flush all of the packets out of the UDP server for this client
556 if (m_udpServer != null)
557 m_udpServer.Flush(m_udpClient);
558  
559 // Remove ourselves from the scene
560 m_scene.RemoveClient(AgentId, true);
561 SceneAgent = null;
562  
563 // We can't reach into other scenes and close the connection
564 // We need to do this over grid communications
565 //m_scene.CloseAllAgents(CircuitCode);
566  
567 // Disable UDP handling for this client
568 m_udpClient.Shutdown();
569  
570 //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
571 //GC.Collect();
572 //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
573 }
574  
575 public void Kick(string message)
576 {
577 if (!SceneAgent.IsChildAgent)
578 {
579 KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
580 kupack.UserInfo.AgentID = AgentId;
581 kupack.UserInfo.SessionID = SessionId;
582 kupack.TargetBlock.TargetIP = 0;
583 kupack.TargetBlock.TargetPort = 0;
584 kupack.UserInfo.Reason = Util.StringToBytes256(message);
585 OutPacket(kupack, ThrottleOutPacketType.Task);
586 // You must sleep here or users get no message!
587 Thread.Sleep(500);
588 }
589 }
590  
591 public void Stop()
592 {
593  
594 }
595  
596 #endregion Client Methods
597  
598 #region Packet Handling
599  
600 public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
601 {
602 NetworkStats handlerNetworkStatsUpdate = OnNetworkStatsUpdate;
603 if (handlerNetworkStatsUpdate != null)
604 {
605 handlerNetworkStatsUpdate(inPackets, outPackets, unAckedBytes);
606 }
607 }
608  
609 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
610 {
611 bool result = false;
612 lock (PacketHandlers)
613 {
614 if (!PacketHandlers.ContainsKey(packetType))
615 {
616 PacketHandlers.Add(packetType, handler);
617 result = true;
618 }
619 }
620 return result;
621 }
622  
623 /// <summary>
624 /// Add a handler for the given packet type.
625 /// </summary>
626 /// <remarks>
627 /// The packet is handled on its own thread. If packets must be handled in the order in which they
628 /// are received then please use the synchronous version of this method.
629 /// </remarks>
630 /// <param name="packetType"></param>
631 /// <param name="handler"></param>
632 /// <returns>true if the handler was added. This is currently always the case.</returns>
633 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
634 {
635 return AddLocalPacketHandler(packetType, handler, true);
636 }
637  
638 /// <summary>
639 /// Add a handler for the given packet type.
640 /// </summary>
641 /// <param name="packetType"></param>
642 /// <param name="handler"></param>
643 /// <param name="doAsync">
644 /// If true, when the packet is received it is handled on its own thread rather than on the main inward bound
645 /// packet handler thread. This vastly increases respnosiveness but some packets need to be handled
646 /// synchronously.
647 /// </param>
648 /// <returns>true if the handler was added. This is currently always the case.</returns>
649 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler, bool doAsync)
650 {
651 bool result = false;
652 lock (m_packetHandlers)
653 {
654 if (!m_packetHandlers.ContainsKey(packetType))
655 {
656 m_packetHandlers.Add(packetType, new PacketProcessor() { method = handler, Async = doAsync });
657 result = true;
658 }
659 }
660  
661 return result;
662 }
663  
664 public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
665 {
666 MethodName = MethodName.ToLower().Trim();
667  
668 bool result = false;
669 lock (m_genericPacketHandlers)
670 {
671 if (!m_genericPacketHandlers.ContainsKey(MethodName))
672 {
673 m_genericPacketHandlers.Add(MethodName, handler);
674 result = true;
675 }
676 }
677 return result;
678 }
679  
680 /// <summary>
681 /// Try to process a packet using registered packet handlers
682 /// </summary>
683 /// <param name="packet"></param>
684 /// <returns>True if a handler was found which successfully processed the packet.</returns>
685 protected virtual bool ProcessPacketMethod(Packet packet)
686 {
687 bool result = false;
688 PacketProcessor pprocessor;
689 if (m_packetHandlers.TryGetValue(packet.Type, out pprocessor))
690 {
691 //there is a local handler for this packet type
692 if (pprocessor.Async)
693 {
694 ClientInfo cinfo = UDPClient.GetClientInfo();
695 if (!cinfo.AsyncRequests.ContainsKey(packet.Type.ToString()))
696 cinfo.AsyncRequests[packet.Type.ToString()] = 0;
697 cinfo.AsyncRequests[packet.Type.ToString()]++;
698  
699 object obj = new AsyncPacketProcess(this, pprocessor.method, packet);
700 Util.FireAndForget(ProcessSpecificPacketAsync, obj, packet.Type.ToString());
701 result = true;
702 }
703 else
704 {
705 ClientInfo cinfo = UDPClient.GetClientInfo();
706 if (!cinfo.SyncRequests.ContainsKey(packet.Type.ToString()))
707 cinfo.SyncRequests[packet.Type.ToString()] = 0;
708 cinfo.SyncRequests[packet.Type.ToString()]++;
709  
710 result = pprocessor.method(this, packet);
711 }
712 }
713 else
714 {
715 //there is not a local handler so see if there is a Global handler
716 PacketMethod method = null;
717 bool found;
718 lock (PacketHandlers)
719 {
720 found = PacketHandlers.TryGetValue(packet.Type, out method);
721 }
722 if (found)
723 {
724 ClientInfo cinfo = UDPClient.GetClientInfo();
725 if (!cinfo.GenericRequests.ContainsKey(packet.Type.ToString()))
726 cinfo.GenericRequests[packet.Type.ToString()] = 0;
727 cinfo.GenericRequests[packet.Type.ToString()]++;
728  
729 result = method(this, packet);
730 }
731 }
732 return result;
733 }
734  
735 public void ProcessSpecificPacketAsync(object state)
736 {
737 AsyncPacketProcess packetObject = (AsyncPacketProcess)state;
738  
739 try
740 {
741 packetObject.result = packetObject.Method(packetObject.ClientView, packetObject.Pack);
742 }
743 catch (Exception e)
744 {
745 // Make sure that we see any exception caused by the asynchronous operation.
746 m_log.ErrorFormat(
747 "[LLCLIENTVIEW]: Caught exception while processing {0} for {1}, {2} {3}",
748 packetObject.Pack, Name, e.Message, e.StackTrace);
749 }
750 }
751  
752 #endregion Packet Handling
753  
754 # region Setup
755  
756 public virtual void Start()
757 {
758 m_scene.AddNewAgent(this, PresenceType.User);
759  
760 RefreshGroupMembership();
761 }
762  
763 # endregion
764  
765 public void ActivateGesture(UUID assetId, UUID gestureId)
766 {
767 }
768  
769 public void DeactivateGesture(UUID assetId, UUID gestureId)
770 {
771 }
772  
773 // Sound
774 public void SoundTrigger(UUID soundId, UUID owerid, UUID Objectid, UUID ParentId, float Gain, Vector3 Position, UInt64 Handle)
775 {
776 }
777  
778 #region Scene/Avatar to Client
779  
780 public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
781 {
782 RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
783 handshake.RegionInfo = new RegionHandshakePacket.RegionInfoBlock();
784 handshake.RegionInfo.BillableFactor = args.billableFactor;
785 handshake.RegionInfo.IsEstateManager = args.isEstateManager;
786 handshake.RegionInfo.TerrainHeightRange00 = args.terrainHeightRange0;
787 handshake.RegionInfo.TerrainHeightRange01 = args.terrainHeightRange1;
788 handshake.RegionInfo.TerrainHeightRange10 = args.terrainHeightRange2;
789 handshake.RegionInfo.TerrainHeightRange11 = args.terrainHeightRange3;
790 handshake.RegionInfo.TerrainStartHeight00 = args.terrainStartHeight0;
791 handshake.RegionInfo.TerrainStartHeight01 = args.terrainStartHeight1;
792 handshake.RegionInfo.TerrainStartHeight10 = args.terrainStartHeight2;
793 handshake.RegionInfo.TerrainStartHeight11 = args.terrainStartHeight3;
794 handshake.RegionInfo.SimAccess = args.simAccess;
795 handshake.RegionInfo.WaterHeight = args.waterHeight;
796  
797 handshake.RegionInfo.RegionFlags = args.regionFlags;
798 handshake.RegionInfo.SimName = Util.StringToBytes256(args.regionName);
799 handshake.RegionInfo.SimOwner = args.SimOwner;
800 handshake.RegionInfo.TerrainBase0 = args.terrainBase0;
801 handshake.RegionInfo.TerrainBase1 = args.terrainBase1;
802 handshake.RegionInfo.TerrainBase2 = args.terrainBase2;
803 handshake.RegionInfo.TerrainBase3 = args.terrainBase3;
804 handshake.RegionInfo.TerrainDetail0 = args.terrainDetail0;
805 handshake.RegionInfo.TerrainDetail1 = args.terrainDetail1;
806 handshake.RegionInfo.TerrainDetail2 = args.terrainDetail2;
807 handshake.RegionInfo.TerrainDetail3 = args.terrainDetail3;
808 handshake.RegionInfo.CacheID = UUID.Random(); //I guess this is for the client to remember an old setting?
809 handshake.RegionInfo2 = new RegionHandshakePacket.RegionInfo2Block();
810 handshake.RegionInfo2.RegionID = regionInfo.RegionID;
811  
812 handshake.RegionInfo3 = new RegionHandshakePacket.RegionInfo3Block();
813 handshake.RegionInfo3.CPUClassID = 9;
814 handshake.RegionInfo3.CPURatio = 1;
815  
816 handshake.RegionInfo3.ColoName = Utils.EmptyBytes;
817 handshake.RegionInfo3.ProductName = Util.StringToBytes256(regionInfo.RegionType);
818 handshake.RegionInfo3.ProductSKU = Utils.EmptyBytes;
819  
820 handshake.RegionInfo4 = new RegionHandshakePacket.RegionInfo4Block[1];
821 handshake.RegionInfo4[0] = new RegionHandshakePacket.RegionInfo4Block();
822 handshake.RegionInfo4[0].RegionFlagsExtended = args.regionFlags;
823 handshake.RegionInfo4[0].RegionProtocols = 0; // 1 here would indicate that SSB is supported
824  
825 OutPacket(handshake, ThrottleOutPacketType.Unknown);
826 }
827  
828  
829 public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
830 {
831 AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
832 mov.SimData.ChannelVersion = m_channelVersion;
833 mov.AgentData.SessionID = m_sessionId;
834 mov.AgentData.AgentID = AgentId;
835 mov.Data.RegionHandle = regInfo.RegionHandle;
836 mov.Data.Timestamp = (uint)Util.UnixTimeSinceEpoch();
837  
838 if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
839 {
840 mov.Data.Position = m_startpos;
841 }
842 else
843 {
844 mov.Data.Position = pos;
845 }
846 mov.Data.LookAt = look;
847  
848 // Hack to get this out immediately and skip the throttles
849 OutPacket(mov, ThrottleOutPacketType.Unknown);
850 }
851  
852 public void SendChatMessage(
853 string message, byte type, Vector3 fromPos, string fromName,
854 UUID fromAgentID, UUID ownerID, byte source, byte audible)
855 {
856 ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
857 reply.ChatData.Audible = audible;
858 reply.ChatData.Message = Util.StringToBytes1024(message);
859 reply.ChatData.ChatType = type;
860 reply.ChatData.SourceType = source;
861 reply.ChatData.Position = fromPos;
862 reply.ChatData.FromName = Util.StringToBytes256(fromName);
863 reply.ChatData.OwnerID = ownerID;
864 reply.ChatData.SourceID = fromAgentID;
865  
866 OutPacket(reply, ThrottleOutPacketType.Task);
867 }
868  
869 /// <summary>
870 /// Send an instant message to this client
871 /// </summary>
872 //
873 // Don't remove transaction ID! Groups and item gives need to set it!
874 public void SendInstantMessage(GridInstantMessage im)
875 {
876 if (((Scene)(m_scene)).Permissions.CanInstantMessage(new UUID(im.fromAgentID), new UUID(im.toAgentID)))
877 {
878 ImprovedInstantMessagePacket msg
879 = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
880  
881 msg.AgentData.AgentID = new UUID(im.fromAgentID);
882 msg.AgentData.SessionID = UUID.Zero;
883 msg.MessageBlock.FromAgentName = Util.StringToBytes256(im.fromAgentName);
884 msg.MessageBlock.Dialog = im.dialog;
885 msg.MessageBlock.FromGroup = im.fromGroup;
886 if (im.imSessionID == UUID.Zero.Guid)
887 msg.MessageBlock.ID = new UUID(im.fromAgentID) ^ new UUID(im.toAgentID);
888 else
889 msg.MessageBlock.ID = new UUID(im.imSessionID);
890 msg.MessageBlock.Offline = im.offline;
891 msg.MessageBlock.ParentEstateID = im.ParentEstateID;
892 msg.MessageBlock.Position = im.Position;
893 msg.MessageBlock.RegionID = new UUID(im.RegionID);
894 msg.MessageBlock.Timestamp = im.timestamp;
895 msg.MessageBlock.ToAgentID = new UUID(im.toAgentID);
896 msg.MessageBlock.Message = Util.StringToBytes1024(im.message);
897 msg.MessageBlock.BinaryBucket = im.binaryBucket;
898  
899 if (im.message.StartsWith("[grouptest]"))
900 { // this block is test code for implementing group IM - delete when group IM is finished
901 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
902 if (eq != null)
903 {
904 im.dialog = 17;
905  
906 //eq.ChatterboxInvitation(
907 // new UUID("00000000-68f9-1111-024e-222222111123"),
908 // "OpenSimulator Testing", im.fromAgentID, im.message, im.toAgentID, im.fromAgentName, im.dialog, 0,
909 // false, 0, new Vector3(), 1, im.imSessionID, im.fromGroup, im.binaryBucket);
910  
911 eq.ChatterboxInvitation(
912 new UUID("00000000-68f9-1111-024e-222222111123"),
913 "OpenSimulator Testing", new UUID(im.fromAgentID), im.message, new UUID(im.toAgentID), im.fromAgentName, im.dialog, 0,
914 false, 0, new Vector3(), 1, new UUID(im.imSessionID), im.fromGroup, Util.StringToBytes256("OpenSimulator Testing"));
915  
916 eq.ChatterBoxSessionAgentListUpdates(
917 new UUID("00000000-68f9-1111-024e-222222111123"),
918 new UUID(im.fromAgentID), new UUID(im.toAgentID), false, false, false);
919 }
920  
921 Console.WriteLine("SendInstantMessage: " + msg);
922 }
923 else
924 OutPacket(msg, ThrottleOutPacketType.Task);
925 }
926 }
927  
928 public void SendGenericMessage(string method, UUID invoice, List<string> message)
929 {
930 GenericMessagePacket gmp = new GenericMessagePacket();
931  
932 gmp.AgentData.AgentID = AgentId;
933 gmp.AgentData.SessionID = m_sessionId;
934 gmp.AgentData.TransactionID = invoice;
935  
936 gmp.MethodData.Method = Util.StringToBytes256(method);
937 gmp.ParamList = new GenericMessagePacket.ParamListBlock[message.Count];
938 int i = 0;
939 foreach (string val in message)
940 {
941 gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
942 gmp.ParamList[i++].Parameter = Util.StringToBytes256(val);
943 }
944  
945 OutPacket(gmp, ThrottleOutPacketType.Task);
946 }
947  
948 public void SendGenericMessage(string method, UUID invoice, List<byte[]> message)
949 {
950 GenericMessagePacket gmp = new GenericMessagePacket();
951  
952 gmp.AgentData.AgentID = AgentId;
953 gmp.AgentData.SessionID = m_sessionId;
954 gmp.AgentData.TransactionID = invoice;
955  
956 gmp.MethodData.Method = Util.StringToBytes256(method);
957 gmp.ParamList = new GenericMessagePacket.ParamListBlock[message.Count];
958 int i = 0;
959 foreach (byte[] val in message)
960 {
961 gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
962 gmp.ParamList[i++].Parameter = val;
963 }
964  
965 OutPacket(gmp, ThrottleOutPacketType.Task);
966 }
967  
968 public void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals)
969 {
970 int i = 0;
971 foreach (GroupActiveProposals Proposal in Proposals)
972 {
973 GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
974  
975 GAPIRP.AgentData.AgentID = AgentId;
976 GAPIRP.AgentData.GroupID = groupID;
977 GAPIRP.TransactionData.TransactionID = transactionID;
978 GAPIRP.TransactionData.TotalNumItems = ((uint)i+1);
979 GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
980 GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
981 ProposalData.VoteCast = Utils.StringToBytes("false");
982 ProposalData.VoteID = new UUID(Proposal.VoteID);
983 ProposalData.VoteInitiator = new UUID(Proposal.VoteInitiator);
984 ProposalData.Majority = (float)Convert.ToInt32(Proposal.Majority);
985 ProposalData.Quorum = Convert.ToInt32(Proposal.Quorum);
986 ProposalData.TerseDateID = Utils.StringToBytes(Proposal.TerseDateID);
987 ProposalData.StartDateTime = Utils.StringToBytes(Proposal.StartDateTime);
988 ProposalData.EndDateTime = Utils.StringToBytes(Proposal.EndDateTime);
989 ProposalData.ProposalText = Utils.StringToBytes(Proposal.ProposalText);
990 ProposalData.AlreadyVoted = false;
991 GAPIRP.ProposalData[i] = ProposalData;
992 OutPacket(GAPIRP, ThrottleOutPacketType.Task);
993 i++;
994 }
995 if (Proposals.Length == 0)
996 {
997 GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket();
998  
999 GAPIRP.AgentData.AgentID = AgentId;
1000 GAPIRP.AgentData.GroupID = groupID;
1001 GAPIRP.TransactionData.TransactionID = transactionID;
1002 GAPIRP.TransactionData.TotalNumItems = 1;
1003 GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock();
1004 GAPIRP.ProposalData = new GroupActiveProposalItemReplyPacket.ProposalDataBlock[1];
1005 ProposalData.VoteCast = Utils.StringToBytes("false");
1006 ProposalData.VoteID = UUID.Zero;
1007 ProposalData.VoteInitiator = UUID.Zero;
1008 ProposalData.Majority = 0;
1009 ProposalData.Quorum = 0;
1010 ProposalData.TerseDateID = Utils.StringToBytes("");
1011 ProposalData.StartDateTime = Utils.StringToBytes("");
1012 ProposalData.EndDateTime = Utils.StringToBytes("");
1013 ProposalData.ProposalText = Utils.StringToBytes("");
1014 ProposalData.AlreadyVoted = false;
1015 GAPIRP.ProposalData[0] = ProposalData;
1016 OutPacket(GAPIRP, ThrottleOutPacketType.Task);
1017 }
1018 }
1019  
1020 public void SendGroupVoteHistory(UUID groupID, UUID transactionID, GroupVoteHistory[] Votes)
1021 {
1022 int i = 0;
1023 foreach (GroupVoteHistory Vote in Votes)
1024 {
1025 GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
1026  
1027 GVHIRP.AgentData.AgentID = AgentId;
1028 GVHIRP.AgentData.GroupID = groupID;
1029 GVHIRP.TransactionData.TransactionID = transactionID;
1030 GVHIRP.TransactionData.TotalNumItems = ((uint)i+1);
1031 GVHIRP.HistoryItemData.VoteID = new UUID(Vote.VoteID);
1032 GVHIRP.HistoryItemData.VoteInitiator = new UUID(Vote.VoteInitiator);
1033 GVHIRP.HistoryItemData.Majority = (float)Convert.ToInt32(Vote.Majority);
1034 GVHIRP.HistoryItemData.Quorum = Convert.ToInt32(Vote.Quorum);
1035 GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes(Vote.TerseDateID);
1036 GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes(Vote.StartDateTime);
1037 GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes(Vote.EndDateTime);
1038 GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes(Vote.VoteType);
1039 GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes(Vote.VoteResult);
1040 GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes(Vote.ProposalText);
1041 GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
1042 GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
1043 VoteItem.CandidateID = UUID.Zero;
1044 VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
1045 VoteItem.VoteCast = Utils.StringToBytes("Yes");
1046 GVHIRP.VoteItem[i] = VoteItem;
1047 OutPacket(GVHIRP, ThrottleOutPacketType.Task);
1048 i++;
1049 }
1050 if (Votes.Length == 0)
1051 {
1052 GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket();
1053  
1054 GVHIRP.AgentData.AgentID = AgentId;
1055 GVHIRP.AgentData.GroupID = groupID;
1056 GVHIRP.TransactionData.TransactionID = transactionID;
1057 GVHIRP.TransactionData.TotalNumItems = 0;
1058 GVHIRP.HistoryItemData.VoteID = UUID.Zero;
1059 GVHIRP.HistoryItemData.VoteInitiator = UUID.Zero;
1060 GVHIRP.HistoryItemData.Majority = 0;
1061 GVHIRP.HistoryItemData.Quorum = 0;
1062 GVHIRP.HistoryItemData.TerseDateID = Utils.StringToBytes("");
1063 GVHIRP.HistoryItemData.StartDateTime = Utils.StringToBytes("");
1064 GVHIRP.HistoryItemData.EndDateTime = Utils.StringToBytes("");
1065 GVHIRP.HistoryItemData.VoteType = Utils.StringToBytes("");
1066 GVHIRP.HistoryItemData.VoteResult = Utils.StringToBytes("");
1067 GVHIRP.HistoryItemData.ProposalText = Utils.StringToBytes("");
1068 GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock();
1069 GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[1];
1070 VoteItem.CandidateID = UUID.Zero;
1071 VoteItem.NumVotes = 0; //TODO: FIX THIS!!!
1072 VoteItem.VoteCast = Utils.StringToBytes("No");
1073 GVHIRP.VoteItem[0] = VoteItem;
1074 OutPacket(GVHIRP, ThrottleOutPacketType.Task);
1075 }
1076 }
1077  
1078 public void SendGroupAccountingDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
1079 {
1080 GroupAccountDetailsReplyPacket GADRP = new GroupAccountDetailsReplyPacket();
1081 GADRP.AgentData = new GroupAccountDetailsReplyPacket.AgentDataBlock();
1082 GADRP.AgentData.AgentID = sender.AgentId;
1083 GADRP.AgentData.GroupID = groupID;
1084 GADRP.HistoryData = new GroupAccountDetailsReplyPacket.HistoryDataBlock[1];
1085 GroupAccountDetailsReplyPacket.HistoryDataBlock History = new GroupAccountDetailsReplyPacket.HistoryDataBlock();
1086 GADRP.MoneyData = new GroupAccountDetailsReplyPacket.MoneyDataBlock();
1087 GADRP.MoneyData.CurrentInterval = 0;
1088 GADRP.MoneyData.IntervalDays = 7;
1089 GADRP.MoneyData.RequestID = transactionID;
1090 GADRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
1091 History.Amount = amt;
1092 History.Description = Utils.StringToBytes("");
1093 GADRP.HistoryData[0] = History;
1094 OutPacket(GADRP, ThrottleOutPacketType.Task);
1095 }
1096  
1097 public void SendGroupAccountingSummary(IClientAPI sender,UUID groupID, uint moneyAmt, int totalTier, int usedTier)
1098 {
1099 GroupAccountSummaryReplyPacket GASRP =
1100 (GroupAccountSummaryReplyPacket)PacketPool.Instance.GetPacket(
1101 PacketType.GroupAccountSummaryReply);
1102  
1103 GASRP.AgentData = new GroupAccountSummaryReplyPacket.AgentDataBlock();
1104 GASRP.AgentData.AgentID = sender.AgentId;
1105 GASRP.AgentData.GroupID = groupID;
1106 GASRP.MoneyData = new GroupAccountSummaryReplyPacket.MoneyDataBlock();
1107 GASRP.MoneyData.Balance = (int)moneyAmt;
1108 GASRP.MoneyData.TotalCredits = totalTier;
1109 GASRP.MoneyData.TotalDebits = usedTier;
1110 GASRP.MoneyData.StartDate = new byte[1];
1111 GASRP.MoneyData.CurrentInterval = 1;
1112 GASRP.MoneyData.GroupTaxCurrent = 0;
1113 GASRP.MoneyData.GroupTaxEstimate = 0;
1114 GASRP.MoneyData.IntervalDays = 0;
1115 GASRP.MoneyData.LandTaxCurrent = 0;
1116 GASRP.MoneyData.LandTaxEstimate = 0;
1117 GASRP.MoneyData.LastTaxDate = new byte[1];
1118 GASRP.MoneyData.LightTaxCurrent = 0;
1119 GASRP.MoneyData.TaxDate = new byte[1];
1120 GASRP.MoneyData.RequestID = sender.AgentId;
1121 GASRP.MoneyData.ParcelDirFeeEstimate = 0;
1122 GASRP.MoneyData.ParcelDirFeeCurrent = 0;
1123 GASRP.MoneyData.ObjectTaxEstimate = 0;
1124 GASRP.MoneyData.NonExemptMembers = 0;
1125 GASRP.MoneyData.ObjectTaxCurrent = 0;
1126 GASRP.MoneyData.LightTaxEstimate = 0;
1127 OutPacket(GASRP, ThrottleOutPacketType.Task);
1128 }
1129  
1130 public void SendGroupTransactionsSummaryDetails(IClientAPI sender,UUID groupID, UUID transactionID, UUID sessionID, int amt)
1131 {
1132 GroupAccountTransactionsReplyPacket GATRP =
1133 (GroupAccountTransactionsReplyPacket)PacketPool.Instance.GetPacket(
1134 PacketType.GroupAccountTransactionsReply);
1135  
1136 GATRP.AgentData = new GroupAccountTransactionsReplyPacket.AgentDataBlock();
1137 GATRP.AgentData.AgentID = sender.AgentId;
1138 GATRP.AgentData.GroupID = groupID;
1139 GATRP.MoneyData = new GroupAccountTransactionsReplyPacket.MoneyDataBlock();
1140 GATRP.MoneyData.CurrentInterval = 0;
1141 GATRP.MoneyData.IntervalDays = 7;
1142 GATRP.MoneyData.RequestID = transactionID;
1143 GATRP.MoneyData.StartDate = Utils.StringToBytes(DateTime.Today.ToString());
1144 GATRP.HistoryData = new GroupAccountTransactionsReplyPacket.HistoryDataBlock[1];
1145 GroupAccountTransactionsReplyPacket.HistoryDataBlock History = new GroupAccountTransactionsReplyPacket.HistoryDataBlock();
1146 History.Amount = 0;
1147 History.Item = Utils.StringToBytes("");
1148 History.Time = Utils.StringToBytes("");
1149 History.Type = 0;
1150 History.User = Utils.StringToBytes("");
1151 GATRP.HistoryData[0] = History;
1152 OutPacket(GATRP, ThrottleOutPacketType.Task);
1153 }
1154  
1155 /// <summary>
1156 /// Send the region heightmap to the client
1157 /// This method is only called when not doing intellegent terrain patch sending and
1158 /// is only called when the scene presence is initially created and sends all of the
1159 /// region's patches to the client.
1160 /// </summary>
1161 /// <param name="map">heightmap</param>
1162 public virtual void SendLayerData(float[] map)
1163 {
1164 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData());
1165 }
1166  
1167 /// <summary>
1168 /// Send terrain layer information to the client.
1169 /// </summary>
1170 /// <param name="o"></param>
1171 private void DoSendLayerData(object o)
1172 {
1173 TerrainData map = (TerrainData)o;
1174  
1175 try
1176 {
1177 // Send LayerData in typerwriter pattern
1178 //for (int y = 0; y < 16; y++)
1179 //{
1180 // for (int x = 0; x < 16; x++)
1181 // {
1182 // SendLayerData(x, y, map);
1183 // }
1184 //}
1185  
1186 // Send LayerData in a spiral pattern. Fun!
1187 SendLayerTopRight(map, 0, 0, map.SizeX/Constants.TerrainPatchSize-1, map.SizeY/Constants.TerrainPatchSize-1);
1188 }
1189 catch (Exception e)
1190 {
1191 m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
1192 }
1193 }
1194  
1195 private void SendLayerTopRight(TerrainData map, int x1, int y1, int x2, int y2)
1196 {
1197 // Row
1198 for (int i = x1; i <= x2; i++)
1199 SendLayerData(i, y1, map);
1200  
1201 // Column
1202 for (int j = y1 + 1; j <= y2; j++)
1203 SendLayerData(x2, j, map);
1204  
1205 if (x2 - x1 > 0 && y2 - y1 > 0)
1206 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2);
1207 }
1208  
1209 void SendLayerBottomLeft(TerrainData map, int x1, int y1, int x2, int y2)
1210 {
1211 // Row in reverse
1212 for (int i = x2; i >= x1; i--)
1213 SendLayerData(i, y2, map);
1214  
1215 // Column in reverse
1216 for (int j = y2 - 1; j >= y1; j--)
1217 SendLayerData(x1, j, map);
1218  
1219 if (x2 - x1 > 0 && y2 - y1 > 0)
1220 SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1);
1221 }
1222  
1223 /// <summary>
1224 /// Sends a set of four patches (x, x+1, ..., x+3) to the client
1225 /// </summary>
1226 /// <param name="map">heightmap</param>
1227 /// <param name="px">X coordinate for patches 0..12</param>
1228 /// <param name="py">Y coordinate for patches 0..15</param>
1229 // private void SendLayerPacket(float[] map, int y, int x)
1230 // {
1231 // int[] patches = new int[4];
1232 // patches[0] = x + 0 + y * 16;
1233 // patches[1] = x + 1 + y * 16;
1234 // patches[2] = x + 2 + y * 16;
1235 // patches[3] = x + 3 + y * 16;
1236  
1237 // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches);
1238 // OutPacket(layerpack, ThrottleOutPacketType.Land);
1239 // }
1240  
1241 // Legacy form of invocation that passes around a bare data array.
1242 // Just ignore what was passed and use the real terrain info that is part of the scene.
1243 // As a HORRIBLE kludge in an attempt to not change the definition of IClientAPI,
1244 // there is a special form for specifying multiple terrain patches to send.
1245 // The form is to pass 'px' as negative the number of patches to send and to
1246 // pass the float array as pairs of patch X and Y coordinates. So, passing 'px'
1247 // as -2 and map= [3, 5, 8, 4] would mean to send two terrain heightmap patches
1248 // and the patches to send are <3,5> and <8,4>.
1249 public void SendLayerData(int px, int py, float[] map)
1250 {
1251 if (px >= 0)
1252 {
1253 SendLayerData(px, py, m_scene.Heightmap.GetTerrainData());
1254 }
1255 else
1256 {
1257 int numPatches = -px;
1258 int[] xPatches = new int[numPatches];
1259 int[] yPatches = new int[numPatches];
1260 for (int pp = 0; pp < numPatches; pp++)
1261 {
1262 xPatches[pp] = (int)map[pp * 2];
1263 yPatches[pp] = (int)map[pp * 2 + 1];
1264 }
1265  
1266 // DebugSendingPatches("SendLayerData", xPatches, yPatches);
1267  
1268 SendLayerData(xPatches, yPatches, m_scene.Heightmap.GetTerrainData());
1269 }
1270 }
1271  
1272 private void DebugSendingPatches(string pWho, int[] pX, int[] pY)
1273 {
1274 if (m_log.IsDebugEnabled)
1275 {
1276 int numPatches = pX.Length;
1277 string Xs = "";
1278 string Ys = "";
1279 for (int pp = 0; pp < numPatches; pp++)
1280 {
1281 Xs += String.Format("{0}", (int)pX[pp]) + ",";
1282 Ys += String.Format("{0}", (int)pY[pp]) + ",";
1283 }
1284 m_log.DebugFormat("{0} {1}: numPatches={2}, X={3}, Y={4}", LogHeader, pWho, numPatches, Xs, Ys);
1285 }
1286 }
1287  
1288 /// <summary>
1289 /// Sends a terrain packet for the point specified.
1290 /// This is a legacy call that has refarbed the terrain into a flat map of floats.
1291 /// We just use the terrain from the region we know about.
1292 /// </summary>
1293 /// <param name="px">Patch coordinate (x) 0..15</param>
1294 /// <param name="py">Patch coordinate (y) 0..15</param>
1295 /// <param name="map">heightmap</param>
1296 public void SendLayerData(int px, int py, TerrainData terrData)
1297 {
1298 int[] xPatches = new[] { px };
1299 int[] yPatches = new[] { py };
1300 SendLayerData(xPatches, yPatches, terrData);
1301 }
1302  
1303 private void SendLayerData(int[] px, int[] py, TerrainData terrData)
1304 {
1305 try
1306 {
1307 /* test code using the terrain compressor in libOpenMetaverse
1308 int[] patchInd = new int[1];
1309 patchInd[0] = px + (py * Constants.TerrainPatchSize);
1310 LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(terrData.GetFloatsSerialized(), patchInd);
1311 */
1312 // Many, many patches could have been passed to us. Since the patches will be compressed
1313 // into variable sized blocks, we cannot pre-compute how many will fit into one
1314 // packet. While some fancy packing algorithm is possible, 4 seems to always fit.
1315 int PatchesAssumedToFit = 4;
1316 for (int pcnt = 0; pcnt < px.Length; pcnt += PatchesAssumedToFit)
1317 {
1318 int remaining = Math.Min(px.Length - pcnt, PatchesAssumedToFit);
1319 int[] xPatches = new int[remaining];
1320 int[] yPatches = new int[remaining];
1321 for (int ii = 0; ii < remaining; ii++)
1322 {
1323 xPatches[ii] = px[pcnt + ii];
1324 yPatches[ii] = py[pcnt + ii];
1325 }
1326 LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(terrData, xPatches, yPatches);
1327 // DebugSendingPatches("SendLayerDataInternal", xPatches, yPatches);
1328  
1329 SendTheLayerPacket(layerpack);
1330 }
1331 // LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLandPacket(terrData, px, py);
1332  
1333 }
1334 catch (Exception e)
1335 {
1336 m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
1337 }
1338 }
1339  
1340 // When a user edits the terrain, so much data is sent, the data queues up fast and presents a
1341 // sub optimal editing experience. To alleviate this issue, when the user edits the terrain, we
1342 // start skipping the queues until they're done editing the terrain. We also make them
1343 // unreliable because it's extremely likely that multiple packets will be sent for a terrain patch
1344 // area invalidating previous packets for that area.
1345  
1346 // It's possible for an editing user to flood themselves with edited packets but the majority
1347 // of use cases are such that only a tiny percentage of users will be editing the terrain.
1348 // Other, non-editing users will see the edits much slower.
1349  
1350 // One last note on this topic, by the time users are going to be editing the terrain, it's
1351 // extremely likely that the sim will have rezzed already and therefore this is not likely going
1352 // to cause any additional issues with lost packets, objects or terrain patches.
1353  
1354 // m_justEditedTerrain is volatile, so test once and duplicate two affected statements so we
1355 // only have one cache miss.
1356 private void SendTheLayerPacket(LayerDataPacket layerpack)
1357 {
1358 if (m_justEditedTerrain)
1359 {
1360 layerpack.Header.Reliable = false;
1361 OutPacket(layerpack, ThrottleOutPacketType.Unknown );
1362 }
1363 else
1364 {
1365 layerpack.Header.Reliable = true;
1366 OutPacket(layerpack, ThrottleOutPacketType.Land);
1367 }
1368 }
1369  
1370 /// <summary>
1371 /// Send the wind matrix to the client
1372 /// </summary>
1373 /// <param name="windSpeeds">16x16 array of wind speeds</param>
1374 public virtual void SendWindData(Vector2[] windSpeeds)
1375 {
1376 Util.FireAndForget(DoSendWindData, windSpeeds);
1377 }
1378  
1379 /// <summary>
1380 /// Send the cloud matrix to the client
1381 /// </summary>
1382 /// <param name="windSpeeds">16x16 array of cloud densities</param>
1383 public virtual void SendCloudData(float[] cloudDensity)
1384 {
1385 Util.FireAndForget(DoSendCloudData, cloudDensity);
1386 }
1387  
1388 /// <summary>
1389 /// Send wind layer information to the client.
1390 /// </summary>
1391 /// <param name="o"></param>
1392 private void DoSendWindData(object o)
1393 {
1394 Vector2[] windSpeeds = (Vector2[])o;
1395 TerrainPatch[] patches = new TerrainPatch[2];
1396 patches[0] = new TerrainPatch { Data = new float[16 * 16] };
1397 patches[1] = new TerrainPatch { Data = new float[16 * 16] };
1398  
1399 for (int x = 0; x < 16 * 16; x++)
1400 {
1401 patches[0].Data[x] = windSpeeds[x].X;
1402 patches[1].Data[x] = windSpeeds[x].Y;
1403 }
1404  
1405 byte layerType = (byte)TerrainPatch.LayerType.Wind;
1406 if (m_scene.RegionInfo.RegionSizeX > Constants.RegionSize || m_scene.RegionInfo.RegionSizeY > Constants.RegionSize)
1407 layerType = (byte)TerrainPatch.LayerType.WindExtended;
1408  
1409 // LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, (TerrainPatch.LayerType)layerType);
1410 LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacket(patches, layerType,
1411 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY);
1412 layerpack.Header.Zerocoded = true;
1413 OutPacket(layerpack, ThrottleOutPacketType.Wind);
1414 }
1415  
1416 /// <summary>
1417 /// Send cloud layer information to the client.
1418 /// </summary>
1419 /// <param name="o"></param>
1420 private void DoSendCloudData(object o)
1421 {
1422 float[] cloudCover = (float[])o;
1423 TerrainPatch[] patches = new TerrainPatch[1];
1424 patches[0] = new TerrainPatch();
1425 patches[0].Data = new float[16 * 16];
1426  
1427 for (int y = 0; y < 16; y++)
1428 {
1429 for (int x = 0; x < 16; x++)
1430 {
1431 patches[0].Data[y * 16 + x] = cloudCover[y * 16 + x];
1432 }
1433 }
1434  
1435 byte layerType = (byte)TerrainPatch.LayerType.Cloud;
1436 if (m_scene.RegionInfo.RegionSizeX > Constants.RegionSize || m_scene.RegionInfo.RegionSizeY > Constants.RegionSize)
1437 layerType = (byte)TerrainPatch.LayerType.CloudExtended;
1438  
1439 // LayerDataPacket layerpack = TerrainCompressor.CreateLayerDataPacket(patches, (TerrainPatch.LayerType)layerType);
1440 LayerDataPacket layerpack = OpenSimTerrainCompressor.CreateLayerDataPacket(patches, layerType,
1441 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY);
1442 layerpack.Header.Zerocoded = true;
1443 OutPacket(layerpack, ThrottleOutPacketType.Cloud);
1444 }
1445  
1446 /// <summary>
1447 /// Tell the client that the given neighbour region is ready to receive a child agent.
1448 /// </summary>
1449 public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
1450 {
1451 IPAddress neighbourIP = neighbourEndPoint.Address;
1452 ushort neighbourPort = (ushort)neighbourEndPoint.Port;
1453  
1454 EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
1455 // TODO: don't create new blocks if recycling an old packet
1456 enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
1457 enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
1458  
1459 byte[] byteIP = neighbourIP.GetAddressBytes();
1460 enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
1461 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
1462 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
1463 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
1464 enablesimpacket.SimulatorInfo.Port = neighbourPort;
1465  
1466 enablesimpacket.Header.Reliable = true; // ESP's should be reliable.
1467  
1468 OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
1469 }
1470  
1471 public AgentCircuitData RequestClientInfo()
1472 {
1473 AgentCircuitData agentData = new AgentCircuitData();
1474 agentData.AgentID = AgentId;
1475 agentData.SessionID = m_sessionId;
1476 agentData.SecureSessionID = SecureSessionId;
1477 agentData.circuitcode = m_circuitCode;
1478 agentData.child = false;
1479 agentData.firstname = m_firstName;
1480 agentData.lastname = m_lastName;
1481  
1482 ICapabilitiesModule capsModule = m_scene.RequestModuleInterface<ICapabilitiesModule>();
1483  
1484 if (capsModule == null) // can happen when shutting down.
1485 return agentData;
1486  
1487 agentData.CapsPath = capsModule.GetCapsPath(m_agentId);
1488 agentData.ChildrenCapSeeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(m_agentId));
1489  
1490 return agentData;
1491 }
1492  
1493 public virtual void CrossRegion(ulong newRegionHandle, Vector3 pos, Vector3 lookAt, IPEndPoint externalIPEndPoint,
1494 string capsURL)
1495 {
1496 Vector3 look = new Vector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
1497  
1498 //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
1499 CrossedRegionPacket newSimPack = new CrossedRegionPacket();
1500 // TODO: don't create new blocks if recycling an old packet
1501 newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
1502 newSimPack.AgentData.AgentID = AgentId;
1503 newSimPack.AgentData.SessionID = m_sessionId;
1504 newSimPack.Info = new CrossedRegionPacket.InfoBlock();
1505 newSimPack.Info.Position = pos;
1506 newSimPack.Info.LookAt = look;
1507 newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
1508 newSimPack.RegionData.RegionHandle = newRegionHandle;
1509 byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
1510 newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
1511 newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
1512 newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
1513 newSimPack.RegionData.SimIP += (uint)byteIP[0];
1514 newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
1515 newSimPack.RegionData.SeedCapability = Util.StringToBytes256(capsURL);
1516  
1517 // Hack to get this out immediately and skip throttles
1518 OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
1519 }
1520  
1521 internal void SendMapBlockSplit(List<MapBlockData> mapBlocks, uint flag)
1522 {
1523 MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
1524 // TODO: don't create new blocks if recycling an old packet
1525  
1526 MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
1527  
1528 mapReply.AgentData.AgentID = AgentId;
1529 mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks2.Length];
1530 mapReply.Size = new MapBlockReplyPacket.SizeBlock[mapBlocks2.Length];
1531 mapReply.AgentData.Flags = flag;
1532  
1533 for (int i = 0; i < mapBlocks2.Length; i++)
1534 {
1535 mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
1536 mapReply.Data[i].MapImageID = mapBlocks2[i].MapImageId;
1537 //m_log.Warn(mapBlocks2[i].MapImageId.ToString());
1538 mapReply.Data[i].X = mapBlocks2[i].X;
1539 mapReply.Data[i].Y = mapBlocks2[i].Y;
1540 mapReply.Data[i].WaterHeight = mapBlocks2[i].WaterHeight;
1541 mapReply.Data[i].Name = Utils.StringToBytes(mapBlocks2[i].Name);
1542 mapReply.Data[i].RegionFlags = mapBlocks2[i].RegionFlags;
1543 mapReply.Data[i].Access = mapBlocks2[i].Access;
1544 mapReply.Data[i].Agents = mapBlocks2[i].Agents;
1545  
1546 mapReply.Size[i] = new MapBlockReplyPacket.SizeBlock();
1547 mapReply.Size[i].SizeX = mapBlocks2[i].SizeX;
1548 mapReply.Size[i].SizeY = mapBlocks2[i].SizeY;
1549 }
1550 OutPacket(mapReply, ThrottleOutPacketType.Land);
1551 }
1552  
1553 public void SendMapBlock(List<MapBlockData> mapBlocks, uint flag)
1554 {
1555 MapBlockData[] mapBlocks2 = mapBlocks.ToArray();
1556  
1557 int maxsend = 10;
1558  
1559 //int packets = Math.Ceiling(mapBlocks2.Length / maxsend);
1560  
1561 List<MapBlockData> sendingBlocks = new List<MapBlockData>();
1562  
1563 for (int i = 0; i < mapBlocks2.Length; i++)
1564 {
1565 sendingBlocks.Add(mapBlocks2[i]);
1566 if (((i + 1) == mapBlocks2.Length) || (((i + 1) % maxsend) == 0))
1567 {
1568 SendMapBlockSplit(sendingBlocks, flag);
1569 sendingBlocks = new List<MapBlockData>();
1570 }
1571 }
1572 }
1573  
1574 public void SendLocalTeleport(Vector3 position, Vector3 lookAt, uint flags)
1575 {
1576 TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
1577 tpLocal.Info.AgentID = AgentId;
1578 tpLocal.Info.TeleportFlags = flags;
1579 tpLocal.Info.LocationID = 2;
1580 tpLocal.Info.LookAt = lookAt;
1581 tpLocal.Info.Position = position;
1582  
1583 // Hack to get this out immediately and skip throttles
1584 OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
1585 }
1586  
1587 public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
1588 uint flags, string capsURL)
1589 {
1590 //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
1591  
1592 TeleportFinishPacket teleport = new TeleportFinishPacket();
1593 teleport.Info.AgentID = AgentId;
1594 teleport.Info.RegionHandle = regionHandle;
1595 teleport.Info.SimAccess = simAccess;
1596  
1597 teleport.Info.SeedCapability = Util.StringToBytes256(capsURL);
1598  
1599 IPAddress oIP = newRegionEndPoint.Address;
1600 byte[] byteIP = oIP.GetAddressBytes();
1601 uint ip = (uint)byteIP[3] << 24;
1602 ip += (uint)byteIP[2] << 16;
1603 ip += (uint)byteIP[1] << 8;
1604 ip += (uint)byteIP[0];
1605  
1606 teleport.Info.SimIP = ip;
1607 teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
1608 teleport.Info.LocationID = 4;
1609 teleport.Info.TeleportFlags = 1 << 4;
1610  
1611 // Hack to get this out immediately and skip throttles.
1612 OutPacket(teleport, ThrottleOutPacketType.Unknown);
1613 }
1614  
1615 /// <summary>
1616 /// Inform the client that a teleport attempt has failed
1617 /// </summary>
1618 public void SendTeleportFailed(string reason)
1619 {
1620 TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
1621 tpFailed.Info.AgentID = AgentId;
1622 tpFailed.Info.Reason = Util.StringToBytes256(reason);
1623 tpFailed.AlertInfo = new TeleportFailedPacket.AlertInfoBlock[0];
1624  
1625 // Hack to get this out immediately and skip throttles
1626 OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
1627 }
1628  
1629 /// <summary>
1630 ///
1631 /// </summary>
1632 public void SendTeleportStart(uint flags)
1633 {
1634 TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
1635 //TeleportStartPacket tpStart = new TeleportStartPacket();
1636 tpStart.Info.TeleportFlags = flags; //16; // Teleport via location
1637  
1638 // Hack to get this out immediately and skip throttles
1639 OutPacket(tpStart, ThrottleOutPacketType.Unknown);
1640 }
1641  
1642 public void SendTeleportProgress(uint flags, string message)
1643 {
1644 TeleportProgressPacket tpProgress = (TeleportProgressPacket)PacketPool.Instance.GetPacket(PacketType.TeleportProgress);
1645 tpProgress.AgentData.AgentID = this.AgentId;
1646 tpProgress.Info.TeleportFlags = flags;
1647 tpProgress.Info.Message = Util.StringToBytes256(message);
1648  
1649 // Hack to get this out immediately and skip throttles
1650 OutPacket(tpProgress, ThrottleOutPacketType.Unknown);
1651 }
1652  
1653 public void SendMoneyBalance(UUID transaction, bool success, byte[] description, int balance, int transactionType, UUID sourceID, bool sourceIsGroup, UUID destID, bool destIsGroup, int amount, string item)
1654 {
1655 MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
1656 money.MoneyData.AgentID = AgentId;
1657 money.MoneyData.TransactionID = transaction;
1658 money.MoneyData.TransactionSuccess = success;
1659 money.MoneyData.Description = description;
1660 money.MoneyData.MoneyBalance = balance;
1661 money.TransactionInfo.TransactionType = transactionType;
1662 money.TransactionInfo.SourceID = sourceID;
1663 money.TransactionInfo.IsSourceGroup = sourceIsGroup;
1664 money.TransactionInfo.DestID = destID;
1665 money.TransactionInfo.IsDestGroup = destIsGroup;
1666 money.TransactionInfo.Amount = amount;
1667 money.TransactionInfo.ItemDescription = Util.StringToBytes256(item);
1668  
1669 OutPacket(money, ThrottleOutPacketType.Task);
1670 }
1671  
1672 public void SendPayPrice(UUID objectID, int[] payPrice)
1673 {
1674 if (payPrice[0] == 0 &&
1675 payPrice[1] == 0 &&
1676 payPrice[2] == 0 &&
1677 payPrice[3] == 0 &&
1678 payPrice[4] == 0)
1679 return;
1680  
1681 PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
1682 payPriceReply.ObjectData.ObjectID = objectID;
1683 payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
1684  
1685 payPriceReply.ButtonData = new PayPriceReplyPacket.ButtonDataBlock[4];
1686 payPriceReply.ButtonData[0] = new PayPriceReplyPacket.ButtonDataBlock();
1687 payPriceReply.ButtonData[0].PayButton = payPrice[1];
1688 payPriceReply.ButtonData[1] = new PayPriceReplyPacket.ButtonDataBlock();
1689 payPriceReply.ButtonData[1].PayButton = payPrice[2];
1690 payPriceReply.ButtonData[2] = new PayPriceReplyPacket.ButtonDataBlock();
1691 payPriceReply.ButtonData[2].PayButton = payPrice[3];
1692 payPriceReply.ButtonData[3] = new PayPriceReplyPacket.ButtonDataBlock();
1693 payPriceReply.ButtonData[3].PayButton = payPrice[4];
1694  
1695 OutPacket(payPriceReply, ThrottleOutPacketType.Task);
1696 }
1697  
1698 public void SendStartPingCheck(byte seq)
1699 {
1700 StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
1701 pc.Header.Reliable = false;
1702  
1703 pc.PingID.PingID = seq;
1704 // We *could* get OldestUnacked, but it would hurt performance and not provide any benefit
1705 pc.PingID.OldestUnacked = 0;
1706  
1707 OutPacket(pc, ThrottleOutPacketType.Unknown);
1708 }
1709  
1710 public void SendKillObject(List<uint> localIDs)
1711 {
1712 // m_log.DebugFormat("[CLIENT]: Sending KillObjectPacket to {0} for {1} in {2}", Name, localID, regionHandle);
1713  
1714 KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
1715 // TODO: don't create new blocks if recycling an old packet
1716 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[localIDs.Count];
1717 for (int i = 0 ; i < localIDs.Count ; i++ )
1718 {
1719 kill.ObjectData[i] = new KillObjectPacket.ObjectDataBlock();
1720 kill.ObjectData[i].ID = localIDs[i];
1721 }
1722 kill.Header.Reliable = true;
1723 kill.Header.Zerocoded = true;
1724  
1725 if (localIDs.Count == 1 && m_scene.GetScenePresence(localIDs[0]) != null)
1726 {
1727 OutPacket(kill, ThrottleOutPacketType.Task);
1728 }
1729 else
1730 {
1731 // We MUST lock for both manipulating the kill record and sending the packet, in order to avoid a race
1732 // condition where a kill can be processed before an out-of-date update for the same object.
1733 // ProcessEntityUpdates() also takes the m_killRecord lock.
1734 lock (m_killRecord)
1735 {
1736 foreach (uint localID in localIDs)
1737 m_killRecord.Add(localID);
1738  
1739 // The throttle queue used here must match that being used for updates. Otherwise, there is a
1740 // chance that a kill packet put on a separate queue will be sent to the client before an existing
1741 // update packet on another queue. Receiving updates after kills results in unowned and undeletable
1742 // scene objects in a viewer until that viewer is relogged in.
1743 OutPacket(kill, ThrottleOutPacketType.Task);
1744 }
1745 }
1746 }
1747  
1748 /// <summary>
1749 /// Send information about the items contained in a folder to the client.
1750 /// </summary>
1751 /// <remarks>
1752 /// XXX This method needs some refactoring loving
1753 /// </remarks>
1754 /// <param name="ownerID">The owner of the folder</param>
1755 /// <param name="folderID">The id of the folder</param>
1756 /// <param name="items">The items contained in the folder identified by folderID</param>
1757 /// <param name="folders"></param>
1758 /// <param name="fetchFolders">Do we need to send folder information?</param>
1759 /// <param name="fetchItems">Do we need to send item information?</param>
1760 public void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List<InventoryItemBase> items,
1761 List<InventoryFolderBase> folders, int version,
1762 bool fetchFolders, bool fetchItems)
1763 {
1764 // An inventory descendents packet consists of a single agent section and an inventory details
1765 // section for each inventory item. The size of each inventory item is approximately 550 bytes.
1766 // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
1767 // packets containing metadata for in excess of 100 items. But in practice, there may be other
1768 // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
1769 //
1770 // http://opensimulator.org/mantis/view.php?id=226
1771 //
1772 // for one example of this kind of thing. In fact, the Linden servers appear to only send about
1773 // 6 to 7 items at a time, so let's stick with 6
1774 int MAX_ITEMS_PER_PACKET = 5;
1775 int MAX_FOLDERS_PER_PACKET = 6;
1776  
1777 int totalItems = fetchItems ? items.Count : 0;
1778 int totalFolders = fetchFolders ? folders.Count : 0;
1779 int itemsSent = 0;
1780 int foldersSent = 0;
1781 int foldersToSend = 0;
1782 int itemsToSend = 0;
1783  
1784 InventoryDescendentsPacket currentPacket = null;
1785  
1786 // Handle empty folders
1787 //
1788 if (totalItems == 0 && totalFolders == 0)
1789 currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, 0, 0);
1790  
1791 // To preserve SL compatibility, we will NOT combine folders and items in one packet
1792 //
1793 while (itemsSent < totalItems || foldersSent < totalFolders)
1794 {
1795 if (currentPacket == null) // Start a new packet
1796 {
1797 foldersToSend = totalFolders - foldersSent;
1798 if (foldersToSend > MAX_FOLDERS_PER_PACKET)
1799 foldersToSend = MAX_FOLDERS_PER_PACKET;
1800  
1801 if (foldersToSend == 0)
1802 {
1803 itemsToSend = totalItems - itemsSent;
1804 if (itemsToSend > MAX_ITEMS_PER_PACKET)
1805 itemsToSend = MAX_ITEMS_PER_PACKET;
1806 }
1807  
1808 currentPacket = CreateInventoryDescendentsPacket(ownerID, folderID, version, items.Count + folders.Count, foldersToSend, itemsToSend);
1809 }
1810  
1811 if (foldersToSend-- > 0)
1812 currentPacket.FolderData[foldersSent % MAX_FOLDERS_PER_PACKET] = CreateFolderDataBlock(folders[foldersSent++]);
1813 else if (itemsToSend-- > 0)
1814 currentPacket.ItemData[itemsSent % MAX_ITEMS_PER_PACKET] = CreateItemDataBlock(items[itemsSent++]);
1815 else
1816 {
1817 // m_log.DebugFormat(
1818 // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
1819 OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
1820 currentPacket = null;
1821 }
1822 }
1823  
1824 if (currentPacket != null)
1825 {
1826 // m_log.DebugFormat(
1827 // "[LLCLIENTVIEW]: Sending inventory folder details packet to {0} for folder {1}", Name, folderID);
1828 OutPacket(currentPacket, ThrottleOutPacketType.Asset, false);
1829 }
1830 }
1831  
1832 private InventoryDescendentsPacket.FolderDataBlock CreateFolderDataBlock(InventoryFolderBase folder)
1833 {
1834 InventoryDescendentsPacket.FolderDataBlock newBlock = new InventoryDescendentsPacket.FolderDataBlock();
1835 newBlock.FolderID = folder.ID;
1836 newBlock.Name = Util.StringToBytes256(folder.Name);
1837 newBlock.ParentID = folder.ParentID;
1838 newBlock.Type = (sbyte)folder.Type;
1839 if (newBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
1840 newBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
1841  
1842 return newBlock;
1843 }
1844  
1845 private InventoryDescendentsPacket.ItemDataBlock CreateItemDataBlock(InventoryItemBase item)
1846 {
1847 InventoryDescendentsPacket.ItemDataBlock newBlock = new InventoryDescendentsPacket.ItemDataBlock();
1848 newBlock.ItemID = item.ID;
1849 newBlock.AssetID = item.AssetID;
1850 newBlock.CreatorID = item.CreatorIdAsUuid;
1851 newBlock.BaseMask = item.BasePermissions;
1852 newBlock.Description = Util.StringToBytes256(item.Description);
1853 newBlock.EveryoneMask = item.EveryOnePermissions;
1854 newBlock.OwnerMask = item.CurrentPermissions;
1855 newBlock.FolderID = item.Folder;
1856 newBlock.InvType = (sbyte)item.InvType;
1857 newBlock.Name = Util.StringToBytes256(item.Name);
1858 newBlock.NextOwnerMask = item.NextPermissions;
1859 newBlock.OwnerID = item.Owner;
1860 newBlock.Type = (sbyte)item.AssetType;
1861  
1862 newBlock.GroupID = item.GroupID;
1863 newBlock.GroupOwned = item.GroupOwned;
1864 newBlock.GroupMask = item.GroupPermissions;
1865 newBlock.CreationDate = item.CreationDate;
1866 newBlock.SalePrice = item.SalePrice;
1867 newBlock.SaleType = item.SaleType;
1868 newBlock.Flags = item.Flags;
1869  
1870 newBlock.CRC =
1871 Helpers.InventoryCRC(newBlock.CreationDate, newBlock.SaleType,
1872 newBlock.InvType, newBlock.Type,
1873 newBlock.AssetID, newBlock.GroupID,
1874 newBlock.SalePrice,
1875 newBlock.OwnerID, newBlock.CreatorID,
1876 newBlock.ItemID, newBlock.FolderID,
1877 newBlock.EveryoneMask,
1878 newBlock.Flags, newBlock.OwnerMask,
1879 newBlock.GroupMask, newBlock.NextOwnerMask);
1880  
1881 return newBlock;
1882 }
1883  
1884 private void AddNullFolderBlockToDecendentsPacket(ref InventoryDescendentsPacket packet)
1885 {
1886 packet.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1];
1887 packet.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock();
1888 packet.FolderData[0].FolderID = UUID.Zero;
1889 packet.FolderData[0].ParentID = UUID.Zero;
1890 packet.FolderData[0].Type = -1;
1891 packet.FolderData[0].Name = new byte[0];
1892 }
1893  
1894 private void AddNullItemBlockToDescendentsPacket(ref InventoryDescendentsPacket packet)
1895 {
1896 packet.ItemData = new InventoryDescendentsPacket.ItemDataBlock[1];
1897 packet.ItemData[0] = new InventoryDescendentsPacket.ItemDataBlock();
1898 packet.ItemData[0].ItemID = UUID.Zero;
1899 packet.ItemData[0].AssetID = UUID.Zero;
1900 packet.ItemData[0].CreatorID = UUID.Zero;
1901 packet.ItemData[0].BaseMask = 0;
1902 packet.ItemData[0].Description = new byte[0];
1903 packet.ItemData[0].EveryoneMask = 0;
1904 packet.ItemData[0].OwnerMask = 0;
1905 packet.ItemData[0].FolderID = UUID.Zero;
1906 packet.ItemData[0].InvType = (sbyte)0;
1907 packet.ItemData[0].Name = new byte[0];
1908 packet.ItemData[0].NextOwnerMask = 0;
1909 packet.ItemData[0].OwnerID = UUID.Zero;
1910 packet.ItemData[0].Type = -1;
1911  
1912 packet.ItemData[0].GroupID = UUID.Zero;
1913 packet.ItemData[0].GroupOwned = false;
1914 packet.ItemData[0].GroupMask = 0;
1915 packet.ItemData[0].CreationDate = 0;
1916 packet.ItemData[0].SalePrice = 0;
1917 packet.ItemData[0].SaleType = 0;
1918 packet.ItemData[0].Flags = 0;
1919  
1920 // No need to add CRC
1921 }
1922  
1923 private InventoryDescendentsPacket CreateInventoryDescendentsPacket(UUID ownerID, UUID folderID, int version, int descendents, int folders, int items)
1924 {
1925 InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
1926 descend.Header.Zerocoded = true;
1927 descend.AgentData.AgentID = AgentId;
1928 descend.AgentData.OwnerID = ownerID;
1929 descend.AgentData.FolderID = folderID;
1930 descend.AgentData.Version = version;
1931 descend.AgentData.Descendents = descendents;
1932  
1933 if (folders > 0)
1934 descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders];
1935 else
1936 AddNullFolderBlockToDecendentsPacket(ref descend);
1937  
1938 if (items > 0)
1939 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items];
1940 else
1941 AddNullItemBlockToDescendentsPacket(ref descend);
1942  
1943 return descend;
1944 }
1945  
1946 public void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item)
1947 {
1948 // Fudge this value. It's only needed to make the CRC anyway
1949 const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
1950  
1951 FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
1952 // TODO: don't create new blocks if recycling an old packet
1953 inventoryReply.AgentData.AgentID = AgentId;
1954 inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
1955 inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
1956 inventoryReply.InventoryData[0].ItemID = item.ID;
1957 inventoryReply.InventoryData[0].AssetID = item.AssetID;
1958 inventoryReply.InventoryData[0].CreatorID = item.CreatorIdAsUuid;
1959 inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
1960 inventoryReply.InventoryData[0].CreationDate = item.CreationDate;
1961  
1962 inventoryReply.InventoryData[0].Description = Util.StringToBytes256(item.Description);
1963 inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
1964 inventoryReply.InventoryData[0].FolderID = item.Folder;
1965 inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
1966 inventoryReply.InventoryData[0].Name = Util.StringToBytes256(item.Name);
1967 inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
1968 inventoryReply.InventoryData[0].OwnerID = item.Owner;
1969 inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
1970 inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
1971  
1972 inventoryReply.InventoryData[0].GroupID = item.GroupID;
1973 inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
1974 inventoryReply.InventoryData[0].GroupMask = item.GroupPermissions;
1975 inventoryReply.InventoryData[0].Flags = item.Flags;
1976 inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
1977 inventoryReply.InventoryData[0].SaleType = item.SaleType;
1978  
1979 inventoryReply.InventoryData[0].CRC =
1980 Helpers.InventoryCRC(
1981 1000, 0, inventoryReply.InventoryData[0].InvType,
1982 inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
1983 inventoryReply.InventoryData[0].GroupID, 100,
1984 inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
1985 inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
1986 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
1987 FULL_MASK_PERMISSIONS);
1988 inventoryReply.Header.Zerocoded = true;
1989 OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
1990 }
1991  
1992 protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase)
1993 {
1994 // We will use the same transaction id for all the separate packets to be sent out in this update.
1995 UUID transactionId = UUID.Random();
1996  
1997 List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks
1998 = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
1999  
2000 SendBulkUpdateInventoryFolderRecursive(folderBase, ref folderDataBlocks, transactionId);
2001  
2002 if (folderDataBlocks.Count > 0)
2003 {
2004 // We'll end up with some unsent folder blocks if there were some empty folders at the end of the list
2005 // Send these now
2006 BulkUpdateInventoryPacket bulkUpdate
2007 = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
2008 bulkUpdate.Header.Zerocoded = true;
2009  
2010 bulkUpdate.AgentData.AgentID = AgentId;
2011 bulkUpdate.AgentData.TransactionID = transactionId;
2012 bulkUpdate.FolderData = folderDataBlocks.ToArray();
2013 List<BulkUpdateInventoryPacket.ItemDataBlock> foo = new List<BulkUpdateInventoryPacket.ItemDataBlock>();
2014 bulkUpdate.ItemData = foo.ToArray();
2015  
2016 //m_log.Debug("SendBulkUpdateInventory :" + bulkUpdate);
2017 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
2018 }
2019 }
2020  
2021 /// <summary>
2022 /// Recursively construct bulk update packets to send folders and items
2023 /// </summary>
2024 /// <param name="folder"></param>
2025 /// <param name="folderDataBlocks"></param>
2026 /// <param name="transactionId"></param>
2027 private void SendBulkUpdateInventoryFolderRecursive(
2028 InventoryFolderBase folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
2029 UUID transactionId)
2030 {
2031 folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
2032  
2033 const int MAX_ITEMS_PER_PACKET = 5;
2034  
2035 IInventoryService invService = m_scene.RequestModuleInterface<IInventoryService>();
2036 // If there are any items then we have to start sending them off in this packet - the next folder will have
2037 // to be in its own bulk update packet. Also, we can only fit 5 items in a packet (at least this was the limit
2038 // being used on the Linden grid at 20081203).
2039 InventoryCollection contents = invService.GetFolderContent(AgentId, folder.ID); // folder.RequestListOfItems();
2040 List<InventoryItemBase> items = contents.Items;
2041 while (items.Count > 0)
2042 {
2043 BulkUpdateInventoryPacket bulkUpdate
2044 = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
2045 bulkUpdate.Header.Zerocoded = true;
2046  
2047 bulkUpdate.AgentData.AgentID = AgentId;
2048 bulkUpdate.AgentData.TransactionID = transactionId;
2049 bulkUpdate.FolderData = folderDataBlocks.ToArray();
2050  
2051 int itemsToSend = (items.Count > MAX_ITEMS_PER_PACKET ? MAX_ITEMS_PER_PACKET : items.Count);
2052 bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[itemsToSend];
2053  
2054 for (int i = 0; i < itemsToSend; i++)
2055 {
2056 // Remove from the end of the list so that we don't incur a performance penalty
2057 bulkUpdate.ItemData[i] = GenerateBulkUpdateItemDataBlock(items[items.Count - 1]);
2058 items.RemoveAt(items.Count - 1);
2059 }
2060  
2061 //m_log.Debug("SendBulkUpdateInventoryRecursive :" + bulkUpdate);
2062 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
2063  
2064 folderDataBlocks = new List<BulkUpdateInventoryPacket.FolderDataBlock>();
2065  
2066 // If we're going to be sending another items packet then it needs to contain just the folder to which those
2067 // items belong.
2068 if (items.Count > 0)
2069 folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
2070 }
2071  
2072 List<InventoryFolderBase> subFolders = contents.Folders;
2073 foreach (InventoryFolderBase subFolder in subFolders)
2074 {
2075 SendBulkUpdateInventoryFolderRecursive(subFolder, ref folderDataBlocks, transactionId);
2076 }
2077 }
2078  
2079 /// <summary>
2080 /// Generate a bulk update inventory data block for the given folder
2081 /// </summary>
2082 /// <param name="folder"></param>
2083 /// <returns></returns>
2084 private BulkUpdateInventoryPacket.FolderDataBlock GenerateBulkUpdateFolderDataBlock(InventoryFolderBase folder)
2085 {
2086 BulkUpdateInventoryPacket.FolderDataBlock folderBlock = new BulkUpdateInventoryPacket.FolderDataBlock();
2087  
2088 folderBlock.FolderID = folder.ID;
2089 folderBlock.ParentID = folder.ParentID;
2090 folderBlock.Type = (sbyte)folder.Type;
2091 if (folderBlock.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
2092 folderBlock.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
2093 folderBlock.Name = Util.StringToBytes256(folder.Name);
2094  
2095 return folderBlock;
2096 }
2097  
2098 /// <summary>
2099 /// Generate a bulk update inventory data block for the given item
2100 /// </summary>
2101 /// <param name="item"></param>
2102 /// <returns></returns>
2103 private BulkUpdateInventoryPacket.ItemDataBlock GenerateBulkUpdateItemDataBlock(InventoryItemBase item)
2104 {
2105 BulkUpdateInventoryPacket.ItemDataBlock itemBlock = new BulkUpdateInventoryPacket.ItemDataBlock();
2106  
2107 itemBlock.ItemID = item.ID;
2108 itemBlock.AssetID = item.AssetID;
2109 itemBlock.CreatorID = item.CreatorIdAsUuid;
2110 itemBlock.BaseMask = item.BasePermissions;
2111 itemBlock.Description = Util.StringToBytes256(item.Description);
2112 itemBlock.EveryoneMask = item.EveryOnePermissions;
2113 itemBlock.FolderID = item.Folder;
2114 itemBlock.InvType = (sbyte)item.InvType;
2115 itemBlock.Name = Util.StringToBytes256(item.Name);
2116 itemBlock.NextOwnerMask = item.NextPermissions;
2117 itemBlock.OwnerID = item.Owner;
2118 itemBlock.OwnerMask = item.CurrentPermissions;
2119 itemBlock.Type = (sbyte)item.AssetType;
2120 itemBlock.GroupID = item.GroupID;
2121 itemBlock.GroupOwned = item.GroupOwned;
2122 itemBlock.GroupMask = item.GroupPermissions;
2123 itemBlock.Flags = item.Flags;
2124 itemBlock.SalePrice = item.SalePrice;
2125 itemBlock.SaleType = item.SaleType;
2126 itemBlock.CreationDate = item.CreationDate;
2127  
2128 itemBlock.CRC =
2129 Helpers.InventoryCRC(
2130 1000, 0, itemBlock.InvType,
2131 itemBlock.Type, itemBlock.AssetID,
2132 itemBlock.GroupID, 100,
2133 itemBlock.OwnerID, itemBlock.CreatorID,
2134 itemBlock.ItemID, itemBlock.FolderID,
2135 (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
2136 (uint)PermissionMask.All);
2137  
2138 return itemBlock;
2139 }
2140  
2141 public void SendBulkUpdateInventory(InventoryNodeBase node)
2142 {
2143 if (node is InventoryItemBase)
2144 SendBulkUpdateInventoryItem((InventoryItemBase)node);
2145 else if (node is InventoryFolderBase)
2146 SendBulkUpdateInventoryFolder((InventoryFolderBase)node);
2147 else if (node != null)
2148 m_log.ErrorFormat("[CLIENT]: {0} sent unknown inventory node named {1}", Name, node.Name);
2149 else
2150 m_log.ErrorFormat("[CLIENT]: {0} sent null inventory node", Name);
2151 }
2152  
2153 protected void SendBulkUpdateInventoryItem(InventoryItemBase item)
2154 {
2155 const uint FULL_MASK_PERMISSIONS = (uint)0x7ffffff;
2156  
2157 BulkUpdateInventoryPacket bulkUpdate
2158 = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
2159  
2160 bulkUpdate.AgentData.AgentID = AgentId;
2161 bulkUpdate.AgentData.TransactionID = UUID.Random();
2162  
2163 bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
2164 bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
2165 bulkUpdate.FolderData[0].FolderID = UUID.Zero;
2166 bulkUpdate.FolderData[0].ParentID = UUID.Zero;
2167 bulkUpdate.FolderData[0].Type = -1;
2168 bulkUpdate.FolderData[0].Name = new byte[0];
2169  
2170 bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
2171 bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
2172 bulkUpdate.ItemData[0].ItemID = item.ID;
2173 bulkUpdate.ItemData[0].AssetID = item.AssetID;
2174 bulkUpdate.ItemData[0].CreatorID = item.CreatorIdAsUuid;
2175 bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
2176 bulkUpdate.ItemData[0].CreationDate = item.CreationDate;
2177 bulkUpdate.ItemData[0].Description = Util.StringToBytes256(item.Description);
2178 bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
2179 bulkUpdate.ItemData[0].FolderID = item.Folder;
2180 bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
2181 bulkUpdate.ItemData[0].Name = Util.StringToBytes256(item.Name);
2182 bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
2183 bulkUpdate.ItemData[0].OwnerID = item.Owner;
2184 bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
2185 bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
2186  
2187 bulkUpdate.ItemData[0].GroupID = item.GroupID;
2188 bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
2189 bulkUpdate.ItemData[0].GroupMask = item.GroupPermissions;
2190 bulkUpdate.ItemData[0].Flags = item.Flags;
2191 bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
2192 bulkUpdate.ItemData[0].SaleType = item.SaleType;
2193  
2194 bulkUpdate.ItemData[0].CRC =
2195 Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
2196 bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
2197 bulkUpdate.ItemData[0].GroupID, 100,
2198 bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
2199 bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
2200 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
2201 FULL_MASK_PERMISSIONS);
2202 bulkUpdate.Header.Zerocoded = true;
2203 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
2204 }
2205  
2206 /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
2207 public void SendInventoryItemCreateUpdate(InventoryItemBase Item, uint callbackId)
2208 {
2209 const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
2210  
2211 UpdateCreateInventoryItemPacket InventoryReply
2212 = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
2213 PacketType.UpdateCreateInventoryItem);
2214  
2215 // TODO: don't create new blocks if recycling an old packet
2216 InventoryReply.AgentData.AgentID = AgentId;
2217 InventoryReply.AgentData.SimApproved = true;
2218 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
2219 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
2220 InventoryReply.InventoryData[0].ItemID = Item.ID;
2221 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
2222 InventoryReply.InventoryData[0].CreatorID = Item.CreatorIdAsUuid;
2223 InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
2224 InventoryReply.InventoryData[0].Description = Util.StringToBytes256(Item.Description);
2225 InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
2226 InventoryReply.InventoryData[0].FolderID = Item.Folder;
2227 InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
2228 InventoryReply.InventoryData[0].Name = Util.StringToBytes256(Item.Name);
2229 InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
2230 InventoryReply.InventoryData[0].OwnerID = Item.Owner;
2231 InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
2232 InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
2233 InventoryReply.InventoryData[0].CallbackID = callbackId;
2234  
2235 InventoryReply.InventoryData[0].GroupID = Item.GroupID;
2236 InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
2237 InventoryReply.InventoryData[0].GroupMask = Item.GroupPermissions;
2238 InventoryReply.InventoryData[0].Flags = Item.Flags;
2239 InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
2240 InventoryReply.InventoryData[0].SaleType = Item.SaleType;
2241 InventoryReply.InventoryData[0].CreationDate = Item.CreationDate;
2242  
2243 InventoryReply.InventoryData[0].CRC =
2244 Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
2245 InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
2246 InventoryReply.InventoryData[0].GroupID, 100,
2247 InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
2248 InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
2249 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
2250 FULL_MASK_PERMISSIONS);
2251 InventoryReply.Header.Zerocoded = true;
2252 OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
2253 }
2254  
2255 public void SendRemoveInventoryItem(UUID itemID)
2256 {
2257 RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
2258 // TODO: don't create new blocks if recycling an old packet
2259 remove.AgentData.AgentID = AgentId;
2260 remove.AgentData.SessionID = m_sessionId;
2261 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
2262 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
2263 remove.InventoryData[0].ItemID = itemID;
2264 remove.Header.Zerocoded = true;
2265 OutPacket(remove, ThrottleOutPacketType.Asset);
2266 }
2267  
2268 public void SendTakeControls(int controls, bool passToAgent, bool TakeControls)
2269 {
2270 ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange);
2271 ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1];
2272 ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock();
2273 ddata.Controls = (uint)controls;
2274 ddata.PassToAgent = passToAgent;
2275 ddata.TakeControls = TakeControls;
2276 data[0] = ddata;
2277 scriptcontrol.Data = data;
2278 OutPacket(scriptcontrol, ThrottleOutPacketType.Task);
2279 }
2280  
2281 public void SendTaskInventory(UUID taskID, short serial, byte[] fileName)
2282 {
2283 ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
2284 replytask.InventoryData.TaskID = taskID;
2285 replytask.InventoryData.Serial = serial;
2286 replytask.InventoryData.Filename = fileName;
2287 OutPacket(replytask, ThrottleOutPacketType.Asset);
2288 }
2289  
2290 public void SendXferPacket(ulong xferID, uint packet, byte[] data)
2291 {
2292 SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
2293 sendXfer.XferID.ID = xferID;
2294 sendXfer.XferID.Packet = packet;
2295 sendXfer.DataPacket.Data = data;
2296 OutPacket(sendXfer, ThrottleOutPacketType.Asset);
2297 }
2298  
2299 public void SendAbortXferPacket(ulong xferID)
2300 {
2301 AbortXferPacket xferItem = (AbortXferPacket)PacketPool.Instance.GetPacket(PacketType.AbortXfer);
2302 xferItem.XferID.ID = xferID;
2303 OutPacket(xferItem, ThrottleOutPacketType.Asset);
2304 }
2305  
2306 public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
2307 int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
2308 int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
2309 int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
2310 {
2311 EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
2312 economyData.Info.EnergyEfficiency = EnergyEfficiency;
2313 economyData.Info.ObjectCapacity = ObjectCapacity;
2314 economyData.Info.ObjectCount = ObjectCount;
2315 economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
2316 economyData.Info.PriceGroupCreate = PriceGroupCreate;
2317 economyData.Info.PriceObjectClaim = PriceObjectClaim;
2318 economyData.Info.PriceObjectRent = PriceObjectRent;
2319 economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
2320 economyData.Info.PriceParcelClaim = PriceParcelClaim;
2321 economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
2322 economyData.Info.PriceParcelRent = PriceParcelRent;
2323 economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
2324 economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
2325 economyData.Info.PriceRentLight = PriceRentLight;
2326 economyData.Info.PriceUpload = PriceUpload;
2327 economyData.Info.TeleportMinPrice = TeleportMinPrice;
2328 economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
2329 economyData.Header.Reliable = true;
2330 OutPacket(economyData, ThrottleOutPacketType.Task);
2331 }
2332  
2333 public void SendAvatarPickerReply(AvatarPickerReplyAgentDataArgs AgentData, List<AvatarPickerReplyDataArgs> Data)
2334 {
2335 //construct the AvatarPickerReply packet.
2336 AvatarPickerReplyPacket replyPacket = new AvatarPickerReplyPacket();
2337 replyPacket.AgentData.AgentID = AgentData.AgentID;
2338 replyPacket.AgentData.QueryID = AgentData.QueryID;
2339 //int i = 0;
2340 List<AvatarPickerReplyPacket.DataBlock> data_block = new List<AvatarPickerReplyPacket.DataBlock>();
2341 foreach (AvatarPickerReplyDataArgs arg in Data)
2342 {
2343 AvatarPickerReplyPacket.DataBlock db = new AvatarPickerReplyPacket.DataBlock();
2344 db.AvatarID = arg.AvatarID;
2345 db.FirstName = arg.FirstName;
2346 db.LastName = arg.LastName;
2347 data_block.Add(db);
2348 }
2349 replyPacket.Data = data_block.ToArray();
2350 OutPacket(replyPacket, ThrottleOutPacketType.Task);
2351 }
2352  
2353 public void SendAgentDataUpdate(UUID agentid, UUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
2354 {
2355 if (agentid == AgentId)
2356 {
2357 ActiveGroupId = activegroupid;
2358 ActiveGroupName = groupname;
2359 ActiveGroupPowers = grouppowers;
2360 }
2361  
2362 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
2363 sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
2364 sendAgentDataUpdate.AgentData.AgentID = agentid;
2365 sendAgentDataUpdate.AgentData.FirstName = Util.StringToBytes256(firstname);
2366 sendAgentDataUpdate.AgentData.GroupName = Util.StringToBytes256(groupname);
2367 sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
2368 sendAgentDataUpdate.AgentData.GroupTitle = Util.StringToBytes256(grouptitle);
2369 sendAgentDataUpdate.AgentData.LastName = Util.StringToBytes256(lastname);
2370 OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
2371 }
2372  
2373 /// <summary>
2374 /// Send an alert message to the client. On the Linden client (tested 1.19.1.4), this pops up a brief duration
2375 /// blue information box in the bottom right hand corner.
2376 /// </summary>
2377 /// <param name="message"></param>
2378 public void SendAlertMessage(string message)
2379 {
2380 AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
2381 alertPack.AlertData = new AlertMessagePacket.AlertDataBlock();
2382 alertPack.AlertData.Message = Util.StringToBytes256(message);
2383 alertPack.AlertInfo = new AlertMessagePacket.AlertInfoBlock[0];
2384 OutPacket(alertPack, ThrottleOutPacketType.Task);
2385 }
2386  
2387 /// <summary>
2388 /// Send an agent alert message to the client.
2389 /// </summary>
2390 /// <param name="message"></param>
2391 /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
2392 /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
2393 /// the AlertMessage packet).</param>
2394 public void SendAgentAlertMessage(string message, bool modal)
2395 {
2396 OutPacket(BuildAgentAlertPacket(message, modal), ThrottleOutPacketType.Task);
2397 }
2398  
2399 /// <summary>
2400 /// Construct an agent alert packet
2401 /// </summary>
2402 /// <param name="message"></param>
2403 /// <param name="modal"></param>
2404 /// <returns></returns>
2405 public AgentAlertMessagePacket BuildAgentAlertPacket(string message, bool modal)
2406 {
2407 // Prepend a slash to make the message come up in the top right
2408 // again.
2409 // Allow special formats to be sent from aware modules.
2410 if (!modal && !message.StartsWith("ALERT: ") && !message.StartsWith("NOTIFY: ") && message != "Home position set." && message != "You died and have been teleported to your home location")
2411 message = "/" + message;
2412 AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
2413 alertPack.AgentData.AgentID = AgentId;
2414 alertPack.AlertData.Message = Util.StringToBytes256(message);
2415 alertPack.AlertData.Modal = modal;
2416  
2417 return alertPack;
2418 }
2419  
2420 public void SendLoadURL(string objectname, UUID objectID, UUID ownerID, bool groupOwned, string message,
2421 string url)
2422 {
2423 LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
2424 loadURL.Data.ObjectName = Util.StringToBytes256(objectname);
2425 loadURL.Data.ObjectID = objectID;
2426 loadURL.Data.OwnerID = ownerID;
2427 loadURL.Data.OwnerIsGroup = groupOwned;
2428 loadURL.Data.Message = Util.StringToBytes256(message);
2429 loadURL.Data.URL = Util.StringToBytes256(url);
2430 OutPacket(loadURL, ThrottleOutPacketType.Task);
2431 }
2432  
2433 public void SendDialog(
2434 string objectname, UUID objectID, UUID ownerID, string ownerFirstName, string ownerLastName, string msg,
2435 UUID textureID, int ch, string[] buttonlabels)
2436 {
2437 ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
2438 dialog.Data.ObjectID = objectID;
2439 dialog.Data.ObjectName = Util.StringToBytes256(objectname);
2440 // this is the username of the *owner*
2441 dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
2442 dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
2443 dialog.Data.Message = Util.StringToBytes1024(msg);
2444 dialog.Data.ImageID = textureID;
2445 dialog.Data.ChatChannel = ch;
2446 ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
2447 for (int i = 0; i < buttonlabels.Length; i++)
2448 {
2449 buttons[i] = new ScriptDialogPacket.ButtonsBlock();
2450 buttons[i].ButtonLabel = Util.StringToBytes256(buttonlabels[i]);
2451 }
2452 dialog.Buttons = buttons;
2453  
2454 dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
2455 dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
2456 dialog.OwnerData[0].OwnerID = ownerID;
2457  
2458 OutPacket(dialog, ThrottleOutPacketType.Task);
2459 }
2460  
2461 public void SendPreLoadSound(UUID objectID, UUID ownerID, UUID soundID)
2462 {
2463 PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
2464 // TODO: don't create new blocks if recycling an old packet
2465 preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
2466 preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
2467 preSound.DataBlock[0].ObjectID = objectID;
2468 preSound.DataBlock[0].OwnerID = ownerID;
2469 preSound.DataBlock[0].SoundID = soundID;
2470 preSound.Header.Zerocoded = true;
2471 OutPacket(preSound, ThrottleOutPacketType.Task);
2472 }
2473  
2474 public void SendPlayAttachedSound(UUID soundID, UUID objectID, UUID ownerID, float gain, byte flags)
2475 {
2476 AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
2477 sound.DataBlock.SoundID = soundID;
2478 sound.DataBlock.ObjectID = objectID;
2479 sound.DataBlock.OwnerID = ownerID;
2480 sound.DataBlock.Gain = gain;
2481 sound.DataBlock.Flags = flags;
2482  
2483 OutPacket(sound, ThrottleOutPacketType.Task);
2484 }
2485  
2486 public void SendTriggeredSound(UUID soundID, UUID ownerID, UUID objectID, UUID parentID, ulong handle, Vector3 position, float gain)
2487 {
2488 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
2489 sound.SoundData.SoundID = soundID;
2490 sound.SoundData.OwnerID = ownerID;
2491 sound.SoundData.ObjectID = objectID;
2492 sound.SoundData.ParentID = parentID;
2493 sound.SoundData.Handle = handle;
2494 sound.SoundData.Position = position;
2495 sound.SoundData.Gain = gain;
2496  
2497 OutPacket(sound, ThrottleOutPacketType.Task);
2498 }
2499  
2500 public void SendAttachedSoundGainChange(UUID objectID, float gain)
2501 {
2502 AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
2503 sound.DataBlock.ObjectID = objectID;
2504 sound.DataBlock.Gain = gain;
2505  
2506 OutPacket(sound, ThrottleOutPacketType.Task);
2507 }
2508  
2509 public void SendSunPos(Vector3 Position, Vector3 Velocity, ulong CurrentTime, uint SecondsPerSunCycle, uint SecondsPerYear, float OrbitalPosition)
2510 {
2511 // Viewers based on the Linden viwer code, do wacky things for oribital positions from Midnight to Sunrise
2512 // So adjust for that
2513 // Contributed by: Godfrey
2514  
2515 if (OrbitalPosition > m_sunPainDaHalfOrbitalCutoff) // things get weird from midnight to sunrise
2516 {
2517 OrbitalPosition = (OrbitalPosition - m_sunPainDaHalfOrbitalCutoff) * 0.6666666667f + m_sunPainDaHalfOrbitalCutoff;
2518 }
2519  
2520 SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
2521 viewertime.TimeInfo.SunDirection = Position;
2522 viewertime.TimeInfo.SunAngVelocity = Velocity;
2523  
2524 // Sun module used to add 6 hours to adjust for linden sun hour, adding here
2525 // to prevent existing code from breaking if it assumed that 6 hours were included.
2526 // 21600 == 6 hours * 60 minutes * 60 Seconds
2527 viewertime.TimeInfo.UsecSinceStart = CurrentTime + 21600;
2528  
2529 viewertime.TimeInfo.SecPerDay = SecondsPerSunCycle;
2530 viewertime.TimeInfo.SecPerYear = SecondsPerYear;
2531 viewertime.TimeInfo.SunPhase = OrbitalPosition;
2532 viewertime.Header.Reliable = false;
2533 viewertime.Header.Zerocoded = true;
2534 OutPacket(viewertime, ThrottleOutPacketType.Task);
2535 }
2536  
2537 // Currently Deprecated
2538 public void SendViewerTime(int phase)
2539 {
2540 /*
2541 Console.WriteLine("SunPhase: {0}", phase);
2542 SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
2543 //viewertime.TimeInfo.SecPerDay = 86400;
2544 //viewertime.TimeInfo.SecPerYear = 31536000;
2545 viewertime.TimeInfo.SecPerDay = 1000;
2546 viewertime.TimeInfo.SecPerYear = 365000;
2547 viewertime.TimeInfo.SunPhase = 1;
2548 int sunPhase = (phase + 2) / 2;
2549 if ((sunPhase < 6) || (sunPhase > 36))
2550 {
2551 viewertime.TimeInfo.SunDirection = new Vector3(0f, 0.8f, -0.8f);
2552 Console.WriteLine("sending night");
2553 }
2554 else
2555 {
2556 if (sunPhase < 12)
2557 {
2558 sunPhase = 12;
2559 }
2560 sunPhase = sunPhase - 12;
2561  
2562 float yValue = 0.1f * (sunPhase);
2563 Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
2564 if (yValue > 1.2f)
2565 {
2566 yValue = yValue - 1.2f;
2567 }
2568  
2569 yValue = Util.Clip(yValue, 0, 1);
2570  
2571 if (sunPhase < 14)
2572 {
2573 yValue = 1 - yValue;
2574 }
2575 if (sunPhase < 12)
2576 {
2577 yValue *= -1;
2578 }
2579 viewertime.TimeInfo.SunDirection = new Vector3(0f, yValue, 0.3f);
2580 Console.WriteLine("sending sun update " + yValue);
2581 }
2582 viewertime.TimeInfo.SunAngVelocity = new Vector3(0, 0.0f, 10.0f);
2583 viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
2584 viewertime.Header.Reliable = false;
2585 OutPacket(viewertime, ThrottleOutPacketType.Task);
2586 */
2587 }
2588  
2589 public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks)
2590 {
2591 ViewerEffectPacket packet = (ViewerEffectPacket)PacketPool.Instance.GetPacket(PacketType.ViewerEffect);
2592 packet.Header.Reliable = false;
2593 packet.Header.Zerocoded = true;
2594  
2595 packet.AgentData.AgentID = AgentId;
2596 packet.AgentData.SessionID = SessionId;
2597  
2598 packet.Effect = effectBlocks;
2599  
2600 // OutPacket(packet, ThrottleOutPacketType.State);
2601 OutPacket(packet, ThrottleOutPacketType.Task);
2602 }
2603  
2604 public void SendAvatarProperties(UUID avatarID, string aboutText, string bornOn, Byte[] charterMember,
2605 string flAbout, uint flags, UUID flImageID, UUID imageID, string profileURL,
2606 UUID partnerID)
2607 {
2608 AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
2609 avatarReply.AgentData.AgentID = AgentId;
2610 avatarReply.AgentData.AvatarID = avatarID;
2611 if (aboutText != null)
2612 avatarReply.PropertiesData.AboutText = Util.StringToBytes1024(aboutText);
2613 else
2614 avatarReply.PropertiesData.AboutText = Utils.EmptyBytes;
2615 avatarReply.PropertiesData.BornOn = Util.StringToBytes256(bornOn);
2616 avatarReply.PropertiesData.CharterMember = charterMember;
2617 if (flAbout != null)
2618 avatarReply.PropertiesData.FLAboutText = Util.StringToBytes256(flAbout);
2619 else
2620 avatarReply.PropertiesData.FLAboutText = Utils.EmptyBytes;
2621 avatarReply.PropertiesData.Flags = flags;
2622 avatarReply.PropertiesData.FLImageID = flImageID;
2623 avatarReply.PropertiesData.ImageID = imageID;
2624 avatarReply.PropertiesData.ProfileURL = Util.StringToBytes256(profileURL);
2625 avatarReply.PropertiesData.PartnerID = partnerID;
2626 OutPacket(avatarReply, ThrottleOutPacketType.Task);
2627 }
2628  
2629 /// <summary>
2630 /// Send the client an Estate message blue box pop-down with a single OK button
2631 /// </summary>
2632 /// <param name="FromAvatarID"></param>
2633 /// <param name="fromSessionID"></param>
2634 /// <param name="FromAvatarName"></param>
2635 /// <param name="Message"></param>
2636 public void SendBlueBoxMessage(UUID FromAvatarID, String FromAvatarName, String Message)
2637 {
2638 if (!SceneAgent.IsChildAgent)
2639 SendInstantMessage(new GridInstantMessage(null, FromAvatarID, FromAvatarName, AgentId, 1, Message, false, new Vector3()));
2640  
2641 //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
2642 }
2643  
2644 public void SendLogoutPacket()
2645 {
2646 // I know this is a bit of a hack, however there are times when you don't
2647 // want to send this, but still need to do the rest of the shutdown process
2648 // this method gets called from the packet server.. which makes it practically
2649 // impossible to do any other way.
2650  
2651 if (m_SendLogoutPacketWhenClosing)
2652 {
2653 LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
2654 // TODO: don't create new blocks if recycling an old packet
2655 logReply.AgentData.AgentID = AgentId;
2656 logReply.AgentData.SessionID = SessionId;
2657 logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
2658 logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
2659 logReply.InventoryData[0].ItemID = UUID.Zero;
2660  
2661 OutPacket(logReply, ThrottleOutPacketType.Task);
2662 }
2663 }
2664  
2665 public void SendHealth(float health)
2666 {
2667 HealthMessagePacket healthpacket = (HealthMessagePacket)PacketPool.Instance.GetPacket(PacketType.HealthMessage);
2668 healthpacket.HealthData.Health = health;
2669 OutPacket(healthpacket, ThrottleOutPacketType.Task);
2670 }
2671  
2672 public void SendAgentOnline(UUID[] agentIDs)
2673 {
2674 OnlineNotificationPacket onp = new OnlineNotificationPacket();
2675 OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[agentIDs.Length];
2676 for (int i = 0; i < agentIDs.Length; i++)
2677 {
2678 OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
2679 onpbl.AgentID = agentIDs[i];
2680 onpb[i] = onpbl;
2681 }
2682 onp.AgentBlock = onpb;
2683 onp.Header.Reliable = true;
2684 OutPacket(onp, ThrottleOutPacketType.Task);
2685 }
2686  
2687 public void SendAgentOffline(UUID[] agentIDs)
2688 {
2689 OfflineNotificationPacket offp = new OfflineNotificationPacket();
2690 OfflineNotificationPacket.AgentBlockBlock[] offpb = new OfflineNotificationPacket.AgentBlockBlock[agentIDs.Length];
2691 for (int i = 0; i < agentIDs.Length; i++)
2692 {
2693 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
2694 onpbl.AgentID = agentIDs[i];
2695 offpb[i] = onpbl;
2696 }
2697 offp.AgentBlock = offpb;
2698 offp.Header.Reliable = true;
2699 OutPacket(offp, ThrottleOutPacketType.Task);
2700 }
2701  
2702 public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, Quaternion SitOrientation, bool autopilot,
2703 Vector3 CameraAtOffset, Vector3 CameraEyeOffset, bool ForceMouseLook)
2704 {
2705 AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
2706 avatarSitResponse.SitObject.ID = TargetID;
2707 avatarSitResponse.SitTransform.CameraAtOffset = CameraAtOffset;
2708 avatarSitResponse.SitTransform.CameraEyeOffset = CameraEyeOffset;
2709 avatarSitResponse.SitTransform.ForceMouselook = ForceMouseLook;
2710 avatarSitResponse.SitTransform.AutoPilot = autopilot;
2711 avatarSitResponse.SitTransform.SitPosition = OffsetPos;
2712 avatarSitResponse.SitTransform.SitRotation = SitOrientation;
2713  
2714 OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
2715 }
2716  
2717 public void SendAdminResponse(UUID Token, uint AdminLevel)
2718 {
2719 GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
2720 GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
2721 GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
2722  
2723 adb.AgentID = AgentId;
2724 adb.SessionID = SessionId; // More security
2725 gdb.GodLevel = (byte)AdminLevel;
2726 gdb.Token = Token;
2727 //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
2728 respondPacket.GrantData = gdb;
2729 respondPacket.AgentData = adb;
2730 OutPacket(respondPacket, ThrottleOutPacketType.Task);
2731 }
2732  
2733 public void SendGroupMembership(GroupMembershipData[] GroupMembership)
2734 {
2735 m_groupPowers.Clear();
2736  
2737 AgentGroupDataUpdatePacket Groupupdate = new AgentGroupDataUpdatePacket();
2738 AgentGroupDataUpdatePacket.GroupDataBlock[] Groups = new AgentGroupDataUpdatePacket.GroupDataBlock[GroupMembership.Length];
2739 for (int i = 0; i < GroupMembership.Length; i++)
2740 {
2741 m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
2742  
2743 AgentGroupDataUpdatePacket.GroupDataBlock Group = new AgentGroupDataUpdatePacket.GroupDataBlock();
2744 Group.AcceptNotices = GroupMembership[i].AcceptNotices;
2745 Group.Contribution = GroupMembership[i].Contribution;
2746 Group.GroupID = GroupMembership[i].GroupID;
2747 Group.GroupInsigniaID = GroupMembership[i].GroupPicture;
2748 Group.GroupName = Util.StringToBytes256(GroupMembership[i].GroupName);
2749 Group.GroupPowers = GroupMembership[i].GroupPowers;
2750 Groups[i] = Group;
2751  
2752  
2753 }
2754 Groupupdate.GroupData = Groups;
2755 Groupupdate.AgentData = new AgentGroupDataUpdatePacket.AgentDataBlock();
2756 Groupupdate.AgentData.AgentID = AgentId;
2757 OutPacket(Groupupdate, ThrottleOutPacketType.Task);
2758  
2759 try
2760 {
2761 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
2762 if (eq != null)
2763 {
2764 eq.GroupMembership(Groupupdate, this.AgentId);
2765 }
2766 }
2767 catch (Exception ex)
2768 {
2769 m_log.Error("Unable to send group membership data via eventqueue - exception: " + ex.ToString());
2770 m_log.Warn("sending group membership data via UDP");
2771 OutPacket(Groupupdate, ThrottleOutPacketType.Task);
2772 }
2773 }
2774  
2775 public void SendPartPhysicsProprieties(ISceneEntity entity)
2776 {
2777 SceneObjectPart part = (SceneObjectPart)entity;
2778 if (part != null && AgentId != UUID.Zero)
2779 {
2780 try
2781 {
2782 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
2783 if (eq != null)
2784 {
2785 uint localid = part.LocalId;
2786 byte physshapetype = part.PhysicsShapeType;
2787 float density = part.Density;
2788 float friction = part.Friction;
2789 float bounce = part.Restitution;
2790 float gravmod = part.GravityModifier;
2791 eq.partPhysicsProperties(localid, physshapetype, density, friction, bounce, gravmod,AgentId);
2792 }
2793 }
2794 catch (Exception ex)
2795 {
2796 m_log.Error("Unable to send part Physics Proprieties - exception: " + ex.ToString());
2797 }
2798 part.UpdatePhysRequired = false;
2799 }
2800 }
2801  
2802  
2803  
2804 public void SendGroupNameReply(UUID groupLLUID, string GroupName)
2805 {
2806 UUIDGroupNameReplyPacket pack = new UUIDGroupNameReplyPacket();
2807 UUIDGroupNameReplyPacket.UUIDNameBlockBlock[] uidnameblock = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock[1];
2808 UUIDGroupNameReplyPacket.UUIDNameBlockBlock uidnamebloc = new UUIDGroupNameReplyPacket.UUIDNameBlockBlock();
2809 uidnamebloc.ID = groupLLUID;
2810 uidnamebloc.GroupName = Util.StringToBytes256(GroupName);
2811 uidnameblock[0] = uidnamebloc;
2812 pack.UUIDNameBlock = uidnameblock;
2813 OutPacket(pack, ThrottleOutPacketType.Task);
2814 }
2815  
2816 public void SendLandStatReply(uint reportType, uint requestFlags, uint resultCount, LandStatReportItem[] lsrpia)
2817 {
2818 LandStatReplyPacket lsrp = new LandStatReplyPacket();
2819 // LandStatReplyPacket.RequestDataBlock lsreqdpb = new LandStatReplyPacket.RequestDataBlock();
2820 LandStatReplyPacket.ReportDataBlock[] lsrepdba = new LandStatReplyPacket.ReportDataBlock[lsrpia.Length];
2821 //LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
2822 // lsrepdb.
2823 lsrp.RequestData.ReportType = reportType;
2824 lsrp.RequestData.RequestFlags = requestFlags;
2825 lsrp.RequestData.TotalObjectCount = resultCount;
2826 for (int i = 0; i < lsrpia.Length; i++)
2827 {
2828 LandStatReplyPacket.ReportDataBlock lsrepdb = new LandStatReplyPacket.ReportDataBlock();
2829 lsrepdb.LocationX = lsrpia[i].LocationX;
2830 lsrepdb.LocationY = lsrpia[i].LocationY;
2831 lsrepdb.LocationZ = lsrpia[i].LocationZ;
2832 lsrepdb.Score = lsrpia[i].Score;
2833 lsrepdb.TaskID = lsrpia[i].TaskID;
2834 lsrepdb.TaskLocalID = lsrpia[i].TaskLocalID;
2835 lsrepdb.TaskName = Util.StringToBytes256(lsrpia[i].TaskName);
2836 lsrepdb.OwnerName = Util.StringToBytes256(lsrpia[i].OwnerName);
2837 lsrepdba[i] = lsrepdb;
2838 }
2839 lsrp.ReportData = lsrepdba;
2840 OutPacket(lsrp, ThrottleOutPacketType.Task);
2841 }
2842  
2843 public void SendScriptRunningReply(UUID objectID, UUID itemID, bool running)
2844 {
2845 ScriptRunningReplyPacket scriptRunningReply = new ScriptRunningReplyPacket();
2846 scriptRunningReply.Script.ObjectID = objectID;
2847 scriptRunningReply.Script.ItemID = itemID;
2848 scriptRunningReply.Script.Running = running;
2849  
2850 OutPacket(scriptRunningReply, ThrottleOutPacketType.Task);
2851 }
2852  
2853 public void SendAsset(AssetRequestToClient req)
2854 {
2855 if (req.AssetInf.Data == null)
2856 {
2857 m_log.ErrorFormat("{0} Cannot send asset {1} ({2}), asset data is null",
2858 LogHeader, req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
2859 return;
2860 }
2861  
2862 //m_log.Debug("sending asset " + req.RequestAssetID);
2863 TransferInfoPacket Transfer = new TransferInfoPacket();
2864 Transfer.TransferInfo.ChannelType = 2;
2865 Transfer.TransferInfo.Status = 0;
2866 Transfer.TransferInfo.TargetType = 0;
2867 if (req.AssetRequestSource == 2)
2868 {
2869 Transfer.TransferInfo.Params = new byte[20];
2870 Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
2871 int assType = req.AssetInf.Type;
2872 Array.Copy(Utils.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
2873 }
2874 else if (req.AssetRequestSource == 3)
2875 {
2876 Transfer.TransferInfo.Params = req.Params;
2877 // Transfer.TransferInfo.Params = new byte[100];
2878 //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
2879 //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
2880 }
2881 Transfer.TransferInfo.Size = req.AssetInf.Data.Length;
2882 Transfer.TransferInfo.TransferID = req.TransferRequestID;
2883 Transfer.Header.Zerocoded = true;
2884 OutPacket(Transfer, ThrottleOutPacketType.Asset);
2885  
2886 if (req.NumPackets == 1)
2887 {
2888 TransferPacketPacket TransferPacket = new TransferPacketPacket();
2889 TransferPacket.TransferData.Packet = 0;
2890 TransferPacket.TransferData.ChannelType = 2;
2891 TransferPacket.TransferData.TransferID = req.TransferRequestID;
2892 TransferPacket.TransferData.Data = req.AssetInf.Data;
2893 TransferPacket.TransferData.Status = 1;
2894 TransferPacket.Header.Zerocoded = true;
2895 OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
2896 }
2897 else
2898 {
2899 int processedLength = 0;
2900 int maxChunkSize = Settings.MAX_PACKET_SIZE - 100;
2901 int packetNumber = 0;
2902  
2903 while (processedLength < req.AssetInf.Data.Length)
2904 {
2905 TransferPacketPacket TransferPacket = new TransferPacketPacket();
2906 TransferPacket.TransferData.Packet = packetNumber;
2907 TransferPacket.TransferData.ChannelType = 2;
2908 TransferPacket.TransferData.TransferID = req.TransferRequestID;
2909  
2910 int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize);
2911 byte[] chunk = new byte[chunkSize];
2912 Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length);
2913  
2914 TransferPacket.TransferData.Data = chunk;
2915  
2916 // 0 indicates more packets to come, 1 indicates last packet
2917 if (req.AssetInf.Data.Length - processedLength > maxChunkSize)
2918 {
2919 TransferPacket.TransferData.Status = 0;
2920 }
2921 else
2922 {
2923 TransferPacket.TransferData.Status = 1;
2924 }
2925 TransferPacket.Header.Zerocoded = true;
2926 OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
2927  
2928 processedLength += chunkSize;
2929 packetNumber++;
2930 }
2931 }
2932 }
2933  
2934 public void SendAssetNotFound(AssetRequestToClient req)
2935 {
2936 TransferInfoPacket Transfer = new TransferInfoPacket();
2937 Transfer.TransferInfo.ChannelType = 2;
2938 Transfer.TransferInfo.Status = -2;
2939 Transfer.TransferInfo.TargetType = 0;
2940 Transfer.TransferInfo.Params = req.Params;
2941 Transfer.TransferInfo.Size = 0;
2942 Transfer.TransferInfo.TransferID = req.TransferRequestID;
2943 Transfer.Header.Zerocoded = true;
2944 OutPacket(Transfer, ThrottleOutPacketType.Asset);
2945 }
2946  
2947 public void SendTexture(AssetBase TextureAsset)
2948 {
2949  
2950 }
2951  
2952 public void SendRegionHandle(UUID regionID, ulong handle)
2953 {
2954 RegionIDAndHandleReplyPacket reply = (RegionIDAndHandleReplyPacket)PacketPool.Instance.GetPacket(PacketType.RegionIDAndHandleReply);
2955 reply.ReplyBlock.RegionID = regionID;
2956 reply.ReplyBlock.RegionHandle = handle;
2957 OutPacket(reply, ThrottleOutPacketType.Land);
2958 }
2959  
2960 public void SendParcelInfo(RegionInfo info, LandData land, UUID parcelID, uint x, uint y)
2961 {
2962 float dwell = 0.0f;
2963 IDwellModule dwellModule = m_scene.RequestModuleInterface<IDwellModule>();
2964 if (dwellModule != null)
2965 dwell = dwellModule.GetDwell(land.GlobalID);
2966 ParcelInfoReplyPacket reply = (ParcelInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelInfoReply);
2967 reply.AgentData.AgentID = m_agentId;
2968 reply.Data.ParcelID = parcelID;
2969 reply.Data.OwnerID = land.OwnerID;
2970 reply.Data.Name = Utils.StringToBytes(land.Name);
2971 reply.Data.Desc = Utils.StringToBytes(land.Description);
2972 reply.Data.ActualArea = land.Area;
2973 reply.Data.BillableArea = land.Area; // TODO: what is this?
2974  
2975 // Bit 0: Mature, bit 7: on sale, other bits: no idea
2976 reply.Data.Flags = (byte)(
2977 (info.AccessLevel > 13 ? (1 << 0) : 0) +
2978 ((land.Flags & (uint)ParcelFlags.ForSale) != 0 ? (1 << 7) : 0));
2979  
2980 Vector3 pos = land.UserLocation;
2981 if (pos.Equals(Vector3.Zero))
2982 {
2983 pos = (land.AABBMax + land.AABBMin) * 0.5f;
2984 }
2985 reply.Data.GlobalX = info.RegionLocX + x;
2986 reply.Data.GlobalY = info.RegionLocY + y;
2987 reply.Data.GlobalZ = pos.Z;
2988 reply.Data.SimName = Utils.StringToBytes(info.RegionName);
2989 reply.Data.SnapshotID = land.SnapshotID;
2990 reply.Data.Dwell = dwell;
2991 reply.Data.SalePrice = land.SalePrice;
2992 reply.Data.AuctionID = (int)land.AuctionID;
2993  
2994 OutPacket(reply, ThrottleOutPacketType.Land);
2995 }
2996  
2997 public void SendScriptTeleportRequest(string objName, string simName, Vector3 pos, Vector3 lookAt)
2998 {
2999 ScriptTeleportRequestPacket packet = (ScriptTeleportRequestPacket)PacketPool.Instance.GetPacket(PacketType.ScriptTeleportRequest);
3000  
3001 packet.Data.ObjectName = Utils.StringToBytes(objName);
3002 packet.Data.SimName = Utils.StringToBytes(simName);
3003 packet.Data.SimPosition = pos;
3004 packet.Data.LookAt = lookAt;
3005  
3006 OutPacket(packet, ThrottleOutPacketType.Task);
3007 }
3008  
3009 public void SendDirPlacesReply(UUID queryID, DirPlacesReplyData[] data)
3010 {
3011 DirPlacesReplyPacket packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
3012  
3013 packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
3014  
3015 packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
3016 packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
3017  
3018 packet.AgentData.AgentID = AgentId;
3019  
3020 packet.QueryData[0].QueryID = queryID;
3021  
3022 DirPlacesReplyPacket.QueryRepliesBlock[] replies =
3023 new DirPlacesReplyPacket.QueryRepliesBlock[0];
3024 DirPlacesReplyPacket.StatusDataBlock[] status =
3025 new DirPlacesReplyPacket.StatusDataBlock[0];
3026  
3027 packet.QueryReplies = replies;
3028 packet.StatusData = status;
3029  
3030 foreach (DirPlacesReplyData d in data)
3031 {
3032 int idx = replies.Length;
3033 Array.Resize(ref replies, idx + 1);
3034 Array.Resize(ref status, idx + 1);
3035  
3036 replies[idx] = new DirPlacesReplyPacket.QueryRepliesBlock();
3037 status[idx] = new DirPlacesReplyPacket.StatusDataBlock();
3038 replies[idx].ParcelID = d.parcelID;
3039 replies[idx].Name = Utils.StringToBytes(d.name);
3040 replies[idx].ForSale = d.forSale;
3041 replies[idx].Auction = d.auction;
3042 replies[idx].Dwell = d.dwell;
3043 status[idx].Status = d.Status;
3044  
3045 packet.QueryReplies = replies;
3046 packet.StatusData = status;
3047  
3048 if (packet.Length >= 1000)
3049 {
3050 OutPacket(packet, ThrottleOutPacketType.Task);
3051  
3052 packet = (DirPlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPlacesReply);
3053  
3054 packet.AgentData = new DirPlacesReplyPacket.AgentDataBlock();
3055  
3056 packet.QueryData = new DirPlacesReplyPacket.QueryDataBlock[1];
3057 packet.QueryData[0] = new DirPlacesReplyPacket.QueryDataBlock();
3058  
3059 packet.AgentData.AgentID = AgentId;
3060  
3061 packet.QueryData[0].QueryID = queryID;
3062  
3063 replies = new DirPlacesReplyPacket.QueryRepliesBlock[0];
3064 status = new DirPlacesReplyPacket.StatusDataBlock[0];
3065 }
3066 }
3067  
3068 if (replies.Length > 0 || data.Length == 0)
3069 OutPacket(packet, ThrottleOutPacketType.Task);
3070 }
3071  
3072 public void SendDirPeopleReply(UUID queryID, DirPeopleReplyData[] data)
3073 {
3074 DirPeopleReplyPacket packet = (DirPeopleReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPeopleReply);
3075  
3076 packet.AgentData = new DirPeopleReplyPacket.AgentDataBlock();
3077 packet.AgentData.AgentID = AgentId;
3078  
3079 packet.QueryData = new DirPeopleReplyPacket.QueryDataBlock();
3080 packet.QueryData.QueryID = queryID;
3081  
3082 packet.QueryReplies = new DirPeopleReplyPacket.QueryRepliesBlock[
3083 data.Length];
3084  
3085 int i = 0;
3086 foreach (DirPeopleReplyData d in data)
3087 {
3088 packet.QueryReplies[i] = new DirPeopleReplyPacket.QueryRepliesBlock();
3089 packet.QueryReplies[i].AgentID = d.agentID;
3090 packet.QueryReplies[i].FirstName =
3091 Utils.StringToBytes(d.firstName);
3092 packet.QueryReplies[i].LastName =
3093 Utils.StringToBytes(d.lastName);
3094 packet.QueryReplies[i].Group =
3095 Utils.StringToBytes(d.group);
3096 packet.QueryReplies[i].Online = d.online;
3097 packet.QueryReplies[i].Reputation = d.reputation;
3098 i++;
3099 }
3100  
3101 OutPacket(packet, ThrottleOutPacketType.Task);
3102 }
3103  
3104 public void SendDirEventsReply(UUID queryID, DirEventsReplyData[] data)
3105 {
3106 DirEventsReplyPacket packet = (DirEventsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirEventsReply);
3107  
3108 packet.AgentData = new DirEventsReplyPacket.AgentDataBlock();
3109 packet.AgentData.AgentID = AgentId;
3110  
3111 packet.QueryData = new DirEventsReplyPacket.QueryDataBlock();
3112 packet.QueryData.QueryID = queryID;
3113  
3114 packet.QueryReplies = new DirEventsReplyPacket.QueryRepliesBlock[
3115 data.Length];
3116  
3117 packet.StatusData = new DirEventsReplyPacket.StatusDataBlock[
3118 data.Length];
3119  
3120 int i = 0;
3121 foreach (DirEventsReplyData d in data)
3122 {
3123 packet.QueryReplies[i] = new DirEventsReplyPacket.QueryRepliesBlock();
3124 packet.StatusData[i] = new DirEventsReplyPacket.StatusDataBlock();
3125 packet.QueryReplies[i].OwnerID = d.ownerID;
3126 packet.QueryReplies[i].Name =
3127 Utils.StringToBytes(d.name);
3128 packet.QueryReplies[i].EventID = d.eventID;
3129 packet.QueryReplies[i].Date =
3130 Utils.StringToBytes(d.date);
3131 packet.QueryReplies[i].UnixTime = d.unixTime;
3132 packet.QueryReplies[i].EventFlags = d.eventFlags;
3133 packet.StatusData[i].Status = d.Status;
3134 i++;
3135 }
3136  
3137 OutPacket(packet, ThrottleOutPacketType.Task);
3138 }
3139  
3140 public void SendDirGroupsReply(UUID queryID, DirGroupsReplyData[] data)
3141 {
3142 DirGroupsReplyPacket packet = (DirGroupsReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirGroupsReply);
3143  
3144 packet.AgentData = new DirGroupsReplyPacket.AgentDataBlock();
3145 packet.AgentData.AgentID = AgentId;
3146  
3147 packet.QueryData = new DirGroupsReplyPacket.QueryDataBlock();
3148 packet.QueryData.QueryID = queryID;
3149  
3150 packet.QueryReplies = new DirGroupsReplyPacket.QueryRepliesBlock[
3151 data.Length];
3152  
3153 int i = 0;
3154 foreach (DirGroupsReplyData d in data)
3155 {
3156 packet.QueryReplies[i] = new DirGroupsReplyPacket.QueryRepliesBlock();
3157 packet.QueryReplies[i].GroupID = d.groupID;
3158 packet.QueryReplies[i].GroupName =
3159 Utils.StringToBytes(d.groupName);
3160 packet.QueryReplies[i].Members = d.members;
3161 packet.QueryReplies[i].SearchOrder = d.searchOrder;
3162 i++;
3163 }
3164  
3165 OutPacket(packet, ThrottleOutPacketType.Task);
3166 }
3167  
3168 public void SendDirClassifiedReply(UUID queryID, DirClassifiedReplyData[] data)
3169 {
3170 DirClassifiedReplyPacket packet = (DirClassifiedReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirClassifiedReply);
3171  
3172 packet.AgentData = new DirClassifiedReplyPacket.AgentDataBlock();
3173 packet.AgentData.AgentID = AgentId;
3174  
3175 packet.QueryData = new DirClassifiedReplyPacket.QueryDataBlock();
3176 packet.QueryData.QueryID = queryID;
3177  
3178 packet.QueryReplies = new DirClassifiedReplyPacket.QueryRepliesBlock[
3179 data.Length];
3180 packet.StatusData = new DirClassifiedReplyPacket.StatusDataBlock[
3181 data.Length];
3182  
3183 int i = 0;
3184 foreach (DirClassifiedReplyData d in data)
3185 {
3186 packet.QueryReplies[i] = new DirClassifiedReplyPacket.QueryRepliesBlock();
3187 packet.StatusData[i] = new DirClassifiedReplyPacket.StatusDataBlock();
3188 packet.QueryReplies[i].ClassifiedID = d.classifiedID;
3189 packet.QueryReplies[i].Name =
3190 Utils.StringToBytes(d.name);
3191 packet.QueryReplies[i].ClassifiedFlags = d.classifiedFlags;
3192 packet.QueryReplies[i].CreationDate = d.creationDate;
3193 packet.QueryReplies[i].ExpirationDate = d.expirationDate;
3194 packet.QueryReplies[i].PriceForListing = d.price;
3195 packet.StatusData[i].Status = d.Status;
3196 i++;
3197 }
3198  
3199 OutPacket(packet, ThrottleOutPacketType.Task);
3200 }
3201  
3202 public void SendDirLandReply(UUID queryID, DirLandReplyData[] data)
3203 {
3204 DirLandReplyPacket packet = (DirLandReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirLandReply);
3205  
3206 packet.AgentData = new DirLandReplyPacket.AgentDataBlock();
3207 packet.AgentData.AgentID = AgentId;
3208  
3209 packet.QueryData = new DirLandReplyPacket.QueryDataBlock();
3210 packet.QueryData.QueryID = queryID;
3211  
3212 packet.QueryReplies = new DirLandReplyPacket.QueryRepliesBlock[
3213 data.Length];
3214  
3215 int i = 0;
3216 foreach (DirLandReplyData d in data)
3217 {
3218 packet.QueryReplies[i] = new DirLandReplyPacket.QueryRepliesBlock();
3219 packet.QueryReplies[i].ParcelID = d.parcelID;
3220 packet.QueryReplies[i].Name =
3221 Utils.StringToBytes(d.name);
3222 packet.QueryReplies[i].Auction = d.auction;
3223 packet.QueryReplies[i].ForSale = d.forSale;
3224 packet.QueryReplies[i].SalePrice = d.salePrice;
3225 packet.QueryReplies[i].ActualArea = d.actualArea;
3226 i++;
3227 }
3228  
3229 OutPacket(packet, ThrottleOutPacketType.Task);
3230 }
3231  
3232 public void SendDirPopularReply(UUID queryID, DirPopularReplyData[] data)
3233 {
3234 DirPopularReplyPacket packet = (DirPopularReplyPacket)PacketPool.Instance.GetPacket(PacketType.DirPopularReply);
3235  
3236 packet.AgentData = new DirPopularReplyPacket.AgentDataBlock();
3237 packet.AgentData.AgentID = AgentId;
3238  
3239 packet.QueryData = new DirPopularReplyPacket.QueryDataBlock();
3240 packet.QueryData.QueryID = queryID;
3241  
3242 packet.QueryReplies = new DirPopularReplyPacket.QueryRepliesBlock[
3243 data.Length];
3244  
3245 int i = 0;
3246 foreach (DirPopularReplyData d in data)
3247 {
3248 packet.QueryReplies[i] = new DirPopularReplyPacket.QueryRepliesBlock();
3249 packet.QueryReplies[i].ParcelID = d.parcelID;
3250 packet.QueryReplies[i].Name =
3251 Utils.StringToBytes(d.name);
3252 packet.QueryReplies[i].Dwell = d.dwell;
3253 i++;
3254 }
3255  
3256 OutPacket(packet, ThrottleOutPacketType.Task);
3257 }
3258  
3259 public void SendEventInfoReply(EventData data)
3260 {
3261 EventInfoReplyPacket packet = (EventInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.EventInfoReply);
3262  
3263 packet.AgentData = new EventInfoReplyPacket.AgentDataBlock();
3264 packet.AgentData.AgentID = AgentId;
3265  
3266 packet.EventData = new EventInfoReplyPacket.EventDataBlock();
3267 packet.EventData.EventID = data.eventID;
3268 packet.EventData.Creator = Utils.StringToBytes(data.creator);
3269 packet.EventData.Name = Utils.StringToBytes(data.name);
3270 packet.EventData.Category = Utils.StringToBytes(data.category);
3271 packet.EventData.Desc = Utils.StringToBytes(data.description);
3272 packet.EventData.Date = Utils.StringToBytes(data.date);
3273 packet.EventData.DateUTC = data.dateUTC;
3274 packet.EventData.Duration = data.duration;
3275 packet.EventData.Cover = data.cover;
3276 packet.EventData.Amount = data.amount;
3277 packet.EventData.SimName = Utils.StringToBytes(data.simName);
3278 packet.EventData.GlobalPos = new Vector3d(data.globalPos);
3279 packet.EventData.EventFlags = data.eventFlags;
3280  
3281 OutPacket(packet, ThrottleOutPacketType.Task);
3282 }
3283  
3284 public void SendMapItemReply(mapItemReply[] replies, uint mapitemtype, uint flags)
3285 {
3286 MapItemReplyPacket mirplk = new MapItemReplyPacket();
3287 mirplk.AgentData.AgentID = AgentId;
3288 mirplk.RequestData.ItemType = mapitemtype;
3289 mirplk.Data = new MapItemReplyPacket.DataBlock[replies.Length];
3290 for (int i = 0; i < replies.Length; i++)
3291 {
3292 MapItemReplyPacket.DataBlock mrdata = new MapItemReplyPacket.DataBlock();
3293 mrdata.X = replies[i].x;
3294 mrdata.Y = replies[i].y;
3295 mrdata.ID = replies[i].id;
3296 mrdata.Extra = replies[i].Extra;
3297 mrdata.Extra2 = replies[i].Extra2;
3298 mrdata.Name = Utils.StringToBytes(replies[i].name);
3299 mirplk.Data[i] = mrdata;
3300 }
3301 //m_log.Debug(mirplk.ToString());
3302 OutPacket(mirplk, ThrottleOutPacketType.Task);
3303  
3304 }
3305  
3306 public void SendOfferCallingCard(UUID srcID, UUID transactionID)
3307 {
3308 // a bit special, as this uses AgentID to store the source instead
3309 // of the destination. The destination (the receiver) goes into destID
3310 OfferCallingCardPacket p = (OfferCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.OfferCallingCard);
3311 p.AgentData.AgentID = srcID;
3312 p.AgentData.SessionID = UUID.Zero;
3313 p.AgentBlock.DestID = AgentId;
3314 p.AgentBlock.TransactionID = transactionID;
3315 OutPacket(p, ThrottleOutPacketType.Task);
3316 }
3317  
3318 public void SendAcceptCallingCard(UUID transactionID)
3319 {
3320 AcceptCallingCardPacket p = (AcceptCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.AcceptCallingCard);
3321 p.AgentData.AgentID = AgentId;
3322 p.AgentData.SessionID = UUID.Zero;
3323 p.FolderData = new AcceptCallingCardPacket.FolderDataBlock[1];
3324 p.FolderData[0] = new AcceptCallingCardPacket.FolderDataBlock();
3325 p.FolderData[0].FolderID = UUID.Zero;
3326 OutPacket(p, ThrottleOutPacketType.Task);
3327 }
3328  
3329 public void SendDeclineCallingCard(UUID transactionID)
3330 {
3331 DeclineCallingCardPacket p = (DeclineCallingCardPacket)PacketPool.Instance.GetPacket(PacketType.DeclineCallingCard);
3332 p.AgentData.AgentID = AgentId;
3333 p.AgentData.SessionID = UUID.Zero;
3334 p.TransactionBlock.TransactionID = transactionID;
3335 OutPacket(p, ThrottleOutPacketType.Task);
3336 }
3337  
3338 public void SendTerminateFriend(UUID exFriendID)
3339 {
3340 TerminateFriendshipPacket p = (TerminateFriendshipPacket)PacketPool.Instance.GetPacket(PacketType.TerminateFriendship);
3341 p.AgentData.AgentID = AgentId;
3342 p.AgentData.SessionID = SessionId;
3343 p.ExBlock.OtherID = exFriendID;
3344 OutPacket(p, ThrottleOutPacketType.Task);
3345 }
3346  
3347 public void SendAvatarGroupsReply(UUID avatarID, GroupMembershipData[] data)
3348 {
3349 OSDMap llsd = new OSDMap(3);
3350 OSDArray AgentData = new OSDArray(1);
3351 OSDMap AgentDataMap = new OSDMap(1);
3352 AgentDataMap.Add("AgentID", OSD.FromUUID(this.AgentId));
3353 AgentDataMap.Add("AvatarID", OSD.FromUUID(avatarID));
3354 AgentData.Add(AgentDataMap);
3355 llsd.Add("AgentData", AgentData);
3356 OSDArray GroupData = new OSDArray(data.Length);
3357 OSDArray NewGroupData = new OSDArray(data.Length);
3358 foreach (GroupMembershipData m in data)
3359 {
3360 OSDMap GroupDataMap = new OSDMap(6);
3361 OSDMap NewGroupDataMap = new OSDMap(1);
3362 GroupDataMap.Add("GroupPowers", OSD.FromULong(m.GroupPowers));
3363 GroupDataMap.Add("AcceptNotices", OSD.FromBoolean(m.AcceptNotices));
3364 GroupDataMap.Add("GroupTitle", OSD.FromString(m.GroupTitle));
3365 GroupDataMap.Add("GroupID", OSD.FromUUID(m.GroupID));
3366 GroupDataMap.Add("GroupName", OSD.FromString(m.GroupName));
3367 GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(m.GroupPicture));
3368 NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(m.ListInProfile));
3369 GroupData.Add(GroupDataMap);
3370 NewGroupData.Add(NewGroupDataMap);
3371 }
3372 llsd.Add("GroupData", GroupData);
3373 llsd.Add("NewGroupData", NewGroupData);
3374  
3375 IEventQueue eq = this.Scene.RequestModuleInterface<IEventQueue>();
3376 if (eq != null)
3377 {
3378 eq.Enqueue(BuildEvent("AvatarGroupsReply", llsd), this.AgentId);
3379 }
3380 }
3381  
3382 public void SendJoinGroupReply(UUID groupID, bool success)
3383 {
3384 JoinGroupReplyPacket p = (JoinGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.JoinGroupReply);
3385  
3386 p.AgentData = new JoinGroupReplyPacket.AgentDataBlock();
3387 p.AgentData.AgentID = AgentId;
3388  
3389 p.GroupData = new JoinGroupReplyPacket.GroupDataBlock();
3390 p.GroupData.GroupID = groupID;
3391 p.GroupData.Success = success;
3392  
3393 OutPacket(p, ThrottleOutPacketType.Task);
3394 }
3395  
3396 public void SendEjectGroupMemberReply(UUID agentID, UUID groupID, bool success)
3397 {
3398 EjectGroupMemberReplyPacket p = (EjectGroupMemberReplyPacket)PacketPool.Instance.GetPacket(PacketType.EjectGroupMemberReply);
3399  
3400 p.AgentData = new EjectGroupMemberReplyPacket.AgentDataBlock();
3401 p.AgentData.AgentID = agentID;
3402  
3403 p.GroupData = new EjectGroupMemberReplyPacket.GroupDataBlock();
3404 p.GroupData.GroupID = groupID;
3405  
3406 p.EjectData = new EjectGroupMemberReplyPacket.EjectDataBlock();
3407 p.EjectData.Success = success;
3408  
3409 OutPacket(p, ThrottleOutPacketType.Task);
3410 }
3411  
3412 public void SendLeaveGroupReply(UUID groupID, bool success)
3413 {
3414 LeaveGroupReplyPacket p = (LeaveGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.LeaveGroupReply);
3415  
3416 p.AgentData = new LeaveGroupReplyPacket.AgentDataBlock();
3417 p.AgentData.AgentID = AgentId;
3418  
3419 p.GroupData = new LeaveGroupReplyPacket.GroupDataBlock();
3420 p.GroupData.GroupID = groupID;
3421 p.GroupData.Success = success;
3422  
3423 OutPacket(p, ThrottleOutPacketType.Task);
3424 }
3425  
3426 public void SendAvatarClassifiedReply(UUID targetID, UUID[] classifiedID, string[] name)
3427 {
3428 if (classifiedID.Length != name.Length)
3429 return;
3430  
3431 AvatarClassifiedReplyPacket ac =
3432 (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
3433 PacketType.AvatarClassifiedReply);
3434  
3435 ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
3436 ac.AgentData.AgentID = AgentId;
3437 ac.AgentData.TargetID = targetID;
3438  
3439 ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifiedID.Length];
3440 int i;
3441 for (i = 0; i < classifiedID.Length; i++)
3442 {
3443 ac.Data[i].ClassifiedID = classifiedID[i];
3444 ac.Data[i].Name = Utils.StringToBytes(name[i]);
3445 }
3446  
3447 OutPacket(ac, ThrottleOutPacketType.Task);
3448 }
3449  
3450 public void SendClassifiedInfoReply(UUID classifiedID, UUID creatorID, uint creationDate, uint expirationDate, uint category, string name, string description, UUID parcelID, uint parentEstate, UUID snapshotID, string simName, Vector3 globalPos, string parcelName, byte classifiedFlags, int price)
3451 {
3452 ClassifiedInfoReplyPacket cr =
3453 (ClassifiedInfoReplyPacket)PacketPool.Instance.GetPacket(
3454 PacketType.ClassifiedInfoReply);
3455  
3456 cr.AgentData = new ClassifiedInfoReplyPacket.AgentDataBlock();
3457 cr.AgentData.AgentID = AgentId;
3458  
3459 cr.Data = new ClassifiedInfoReplyPacket.DataBlock();
3460 cr.Data.ClassifiedID = classifiedID;
3461 cr.Data.CreatorID = creatorID;
3462 cr.Data.CreationDate = creationDate;
3463 cr.Data.ExpirationDate = expirationDate;
3464 cr.Data.Category = category;
3465 cr.Data.Name = Utils.StringToBytes(name);
3466 cr.Data.Desc = Utils.StringToBytes(description);
3467 cr.Data.ParcelID = parcelID;
3468 cr.Data.ParentEstate = parentEstate;
3469 cr.Data.SnapshotID = snapshotID;
3470 cr.Data.SimName = Utils.StringToBytes(simName);
3471 cr.Data.PosGlobal = new Vector3d(globalPos);
3472 cr.Data.ParcelName = Utils.StringToBytes(parcelName);
3473 cr.Data.ClassifiedFlags = classifiedFlags;
3474 cr.Data.PriceForListing = price;
3475  
3476 OutPacket(cr, ThrottleOutPacketType.Task);
3477 }
3478  
3479 public void SendAgentDropGroup(UUID groupID)
3480 {
3481 AgentDropGroupPacket dg =
3482 (AgentDropGroupPacket)PacketPool.Instance.GetPacket(
3483 PacketType.AgentDropGroup);
3484  
3485 dg.AgentData = new AgentDropGroupPacket.AgentDataBlock();
3486 dg.AgentData.AgentID = AgentId;
3487 dg.AgentData.GroupID = groupID;
3488  
3489 OutPacket(dg, ThrottleOutPacketType.Task);
3490 }
3491  
3492 public void SendAvatarNotesReply(UUID targetID, string text)
3493 {
3494 AvatarNotesReplyPacket an =
3495 (AvatarNotesReplyPacket)PacketPool.Instance.GetPacket(
3496 PacketType.AvatarNotesReply);
3497  
3498 an.AgentData = new AvatarNotesReplyPacket.AgentDataBlock();
3499 an.AgentData.AgentID = AgentId;
3500  
3501 an.Data = new AvatarNotesReplyPacket.DataBlock();
3502 an.Data.TargetID = targetID;
3503 an.Data.Notes = Utils.StringToBytes(text);
3504  
3505 OutPacket(an, ThrottleOutPacketType.Task);
3506 }
3507  
3508 public void SendAvatarPicksReply(UUID targetID, Dictionary<UUID, string> picks)
3509 {
3510 AvatarPicksReplyPacket ap =
3511 (AvatarPicksReplyPacket)PacketPool.Instance.GetPacket(
3512 PacketType.AvatarPicksReply);
3513  
3514 ap.AgentData = new AvatarPicksReplyPacket.AgentDataBlock();
3515 ap.AgentData.AgentID = AgentId;
3516 ap.AgentData.TargetID = targetID;
3517  
3518 ap.Data = new AvatarPicksReplyPacket.DataBlock[picks.Count];
3519  
3520 int i = 0;
3521 foreach (KeyValuePair<UUID, string> pick in picks)
3522 {
3523 ap.Data[i] = new AvatarPicksReplyPacket.DataBlock();
3524 ap.Data[i].PickID = pick.Key;
3525 ap.Data[i].PickName = Utils.StringToBytes(pick.Value);
3526 i++;
3527 }
3528  
3529 OutPacket(ap, ThrottleOutPacketType.Task);
3530 }
3531  
3532 public void SendAvatarClassifiedReply(UUID targetID, Dictionary<UUID, string> classifieds)
3533 {
3534 AvatarClassifiedReplyPacket ac =
3535 (AvatarClassifiedReplyPacket)PacketPool.Instance.GetPacket(
3536 PacketType.AvatarClassifiedReply);
3537  
3538 ac.AgentData = new AvatarClassifiedReplyPacket.AgentDataBlock();
3539 ac.AgentData.AgentID = AgentId;
3540 ac.AgentData.TargetID = targetID;
3541  
3542 ac.Data = new AvatarClassifiedReplyPacket.DataBlock[classifieds.Count];
3543  
3544 int i = 0;
3545 foreach (KeyValuePair<UUID, string> classified in classifieds)
3546 {
3547 ac.Data[i] = new AvatarClassifiedReplyPacket.DataBlock();
3548 ac.Data[i].ClassifiedID = classified.Key;
3549 ac.Data[i].Name = Utils.StringToBytes(classified.Value);
3550 i++;
3551 }
3552  
3553 OutPacket(ac, ThrottleOutPacketType.Task);
3554 }
3555  
3556 public void SendParcelDwellReply(int localID, UUID parcelID, float dwell)
3557 {
3558 ParcelDwellReplyPacket pd =
3559 (ParcelDwellReplyPacket)PacketPool.Instance.GetPacket(
3560 PacketType.ParcelDwellReply);
3561  
3562 pd.AgentData = new ParcelDwellReplyPacket.AgentDataBlock();
3563 pd.AgentData.AgentID = AgentId;
3564  
3565 pd.Data = new ParcelDwellReplyPacket.DataBlock();
3566 pd.Data.LocalID = localID;
3567 pd.Data.ParcelID = parcelID;
3568 pd.Data.Dwell = dwell;
3569  
3570 OutPacket(pd, ThrottleOutPacketType.Land);
3571 }
3572  
3573 public void SendUserInfoReply(bool imViaEmail, bool visible, string email)
3574 {
3575 UserInfoReplyPacket ur =
3576 (UserInfoReplyPacket)PacketPool.Instance.GetPacket(
3577 PacketType.UserInfoReply);
3578  
3579 string Visible = "hidden";
3580 if (visible)
3581 Visible = "default";
3582  
3583 ur.AgentData = new UserInfoReplyPacket.AgentDataBlock();
3584 ur.AgentData.AgentID = AgentId;
3585  
3586 ur.UserData = new UserInfoReplyPacket.UserDataBlock();
3587 ur.UserData.IMViaEMail = imViaEmail;
3588 ur.UserData.DirectoryVisibility = Utils.StringToBytes(Visible);
3589 ur.UserData.EMail = Utils.StringToBytes(email);
3590  
3591 OutPacket(ur, ThrottleOutPacketType.Task);
3592 }
3593  
3594 public void SendCreateGroupReply(UUID groupID, bool success, string message)
3595 {
3596 CreateGroupReplyPacket createGroupReply = (CreateGroupReplyPacket)PacketPool.Instance.GetPacket(PacketType.CreateGroupReply);
3597  
3598 createGroupReply.AgentData =
3599 new CreateGroupReplyPacket.AgentDataBlock();
3600 createGroupReply.ReplyData =
3601 new CreateGroupReplyPacket.ReplyDataBlock();
3602  
3603 createGroupReply.AgentData.AgentID = AgentId;
3604 createGroupReply.ReplyData.GroupID = groupID;
3605  
3606 createGroupReply.ReplyData.Success = success;
3607 createGroupReply.ReplyData.Message = Utils.StringToBytes(message);
3608 OutPacket(createGroupReply, ThrottleOutPacketType.Task);
3609 }
3610  
3611 public void SendUseCachedMuteList()
3612 {
3613 UseCachedMuteListPacket useCachedMuteList = (UseCachedMuteListPacket)PacketPool.Instance.GetPacket(PacketType.UseCachedMuteList);
3614  
3615 useCachedMuteList.AgentData = new UseCachedMuteListPacket.AgentDataBlock();
3616 useCachedMuteList.AgentData.AgentID = AgentId;
3617  
3618 OutPacket(useCachedMuteList, ThrottleOutPacketType.Task);
3619 }
3620  
3621 public void SendMuteListUpdate(string filename)
3622 {
3623 MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate);
3624  
3625 muteListUpdate.MuteData = new MuteListUpdatePacket.MuteDataBlock();
3626 muteListUpdate.MuteData.AgentID = AgentId;
3627 muteListUpdate.MuteData.Filename = Utils.StringToBytes(filename);
3628  
3629 OutPacket(muteListUpdate, ThrottleOutPacketType.Task);
3630 }
3631  
3632 public void SendPickInfoReply(UUID pickID, UUID creatorID, bool topPick, UUID parcelID, string name, string desc, UUID snapshotID, string user, string originalName, string simName, Vector3 posGlobal, int sortOrder, bool enabled)
3633 {
3634 PickInfoReplyPacket pickInfoReply = (PickInfoReplyPacket)PacketPool.Instance.GetPacket(PacketType.PickInfoReply);
3635  
3636 pickInfoReply.AgentData = new PickInfoReplyPacket.AgentDataBlock();
3637 pickInfoReply.AgentData.AgentID = AgentId;
3638  
3639 pickInfoReply.Data = new PickInfoReplyPacket.DataBlock();
3640 pickInfoReply.Data.PickID = pickID;
3641 pickInfoReply.Data.CreatorID = creatorID;
3642 pickInfoReply.Data.TopPick = topPick;
3643 pickInfoReply.Data.ParcelID = parcelID;
3644 pickInfoReply.Data.Name = Utils.StringToBytes(name);
3645 pickInfoReply.Data.Desc = Utils.StringToBytes(desc);
3646 pickInfoReply.Data.SnapshotID = snapshotID;
3647 pickInfoReply.Data.User = Utils.StringToBytes(user);
3648 pickInfoReply.Data.OriginalName = Utils.StringToBytes(originalName);
3649 pickInfoReply.Data.SimName = Utils.StringToBytes(simName);
3650 pickInfoReply.Data.PosGlobal = new Vector3d(posGlobal);
3651 pickInfoReply.Data.SortOrder = sortOrder;
3652 pickInfoReply.Data.Enabled = enabled;
3653  
3654 OutPacket(pickInfoReply, ThrottleOutPacketType.Task);
3655 }
3656  
3657 #endregion Scene/Avatar to Client
3658  
3659 // Gesture
3660  
3661 #region Appearance/ Wearables Methods
3662  
3663 public void SendWearables(AvatarWearable[] wearables, int serial)
3664 {
3665 AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
3666 aw.AgentData.AgentID = AgentId;
3667 aw.AgentData.SerialNum = (uint)serial;
3668 aw.AgentData.SessionID = m_sessionId;
3669  
3670 int count = 0;
3671 for (int i = 0; i < wearables.Length; i++)
3672 count += wearables[i].Count;
3673  
3674 // TODO: don't create new blocks if recycling an old packet
3675 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[count];
3676 AgentWearablesUpdatePacket.WearableDataBlock awb;
3677 int idx = 0;
3678 for (int i = 0; i < wearables.Length; i++)
3679 {
3680 for (int j = 0; j < wearables[i].Count; j++)
3681 {
3682 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
3683 awb.WearableType = (byte)i;
3684 awb.AssetID = wearables[i][j].AssetID;
3685 awb.ItemID = wearables[i][j].ItemID;
3686 aw.WearableData[idx] = awb;
3687 idx++;
3688  
3689 // m_log.DebugFormat(
3690 // "[APPEARANCE]: Sending wearable item/asset {0} {1} (index {2}) for {3}",
3691 // awb.ItemID, awb.AssetID, i, Name);
3692 }
3693 }
3694  
3695 OutPacket(aw, ThrottleOutPacketType.Task);
3696 }
3697  
3698 public void SendAppearance(UUID agentID, byte[] visualParams, byte[] textureEntry)
3699 {
3700 // m_log.DebugFormat(
3701 // "[LLCLIENTVIEW]: Sending avatar appearance for {0} with {1} bytes to {2} {3}",
3702 // agentID, textureEntry.Length, Name, AgentId);
3703  
3704 AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
3705 // TODO: don't create new blocks if recycling an old packet
3706 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[visualParams.Length];
3707 avp.ObjectData.TextureEntry = textureEntry;
3708  
3709 AvatarAppearancePacket.VisualParamBlock avblock = null;
3710 for (int i = 0; i < visualParams.Length; i++)
3711 {
3712 avblock = new AvatarAppearancePacket.VisualParamBlock();
3713 avblock.ParamValue = visualParams[i];
3714 avp.VisualParam[i] = avblock;
3715 }
3716  
3717 avp.Sender.IsTrial = false;
3718 avp.Sender.ID = agentID;
3719 avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0];
3720 //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString());
3721 OutPacket(avp, ThrottleOutPacketType.Task);
3722 }
3723  
3724 public void SendAnimations(UUID[] animations, int[] seqs, UUID sourceAgentId, UUID[] objectIDs)
3725 {
3726 // m_log.DebugFormat("[LLCLIENTVIEW]: Sending animations for {0} to {1}", sourceAgentId, Name);
3727  
3728 AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
3729 // TODO: don't create new blocks if recycling an old packet
3730 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[animations.Length];
3731 ani.Sender = new AvatarAnimationPacket.SenderBlock();
3732 ani.Sender.ID = sourceAgentId;
3733 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
3734 ani.PhysicalAvatarEventList = new AvatarAnimationPacket.PhysicalAvatarEventListBlock[0];
3735  
3736 for (int i = 0; i < animations.Length; ++i)
3737 {
3738 ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
3739 ani.AnimationList[i].AnimID = animations[i];
3740 ani.AnimationList[i].AnimSequenceID = seqs[i];
3741  
3742 ani.AnimationSourceList[i] = new AvatarAnimationPacket.AnimationSourceListBlock();
3743 if (objectIDs[i].Equals(sourceAgentId))
3744 ani.AnimationSourceList[i].ObjectID = UUID.Zero;
3745 else
3746 ani.AnimationSourceList[i].ObjectID = objectIDs[i];
3747 }
3748 ani.Header.Reliable = false;
3749 OutPacket(ani, ThrottleOutPacketType.Task);
3750 }
3751  
3752 #endregion
3753  
3754 #region Avatar Packet/Data Sending Methods
3755  
3756 /// <summary>
3757 /// Send an ObjectUpdate packet with information about an avatar
3758 /// </summary>
3759 public void SendAvatarDataImmediate(ISceneEntity avatar)
3760 {
3761 // m_log.DebugFormat(
3762 // "[LLCLIENTVIEW]: Sending immediate object update for avatar {0} {1} to {2} {3}",
3763 // avatar.Name, avatar.UUID, Name, AgentId);
3764  
3765 ScenePresence presence = avatar as ScenePresence;
3766 if (presence == null)
3767 return;
3768  
3769 ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
3770 objupdate.Header.Zerocoded = true;
3771  
3772 objupdate.RegionData.RegionHandle = presence.RegionHandle;
3773 objupdate.RegionData.TimeDilation = ushort.MaxValue;
3774  
3775 objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
3776 objupdate.ObjectData[0] = CreateAvatarUpdateBlock(presence);
3777  
3778 OutPacket(objupdate, ThrottleOutPacketType.Task);
3779  
3780 // We need to record the avatar local id since the root prim of an attachment points to this.
3781 // m_attachmentsSent.Add(avatar.LocalId);
3782 }
3783  
3784 public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
3785 {
3786 // We don't need to update inactive clients.
3787 if (!IsActive)
3788 return;
3789  
3790 CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
3791 loc.Header.Reliable = false;
3792  
3793 // Each packet can only hold around 60 avatar positions and the client clears the mini-map each time
3794 // a CoarseLocationUpdate packet is received. Oh well.
3795 int total = Math.Min(CoarseLocations.Count, 60);
3796  
3797 CoarseLocationUpdatePacket.IndexBlock ib = new CoarseLocationUpdatePacket.IndexBlock();
3798  
3799 loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
3800 loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total];
3801  
3802 int selfindex = -1;
3803 for (int i = 0; i < total; i++)
3804 {
3805 CoarseLocationUpdatePacket.LocationBlock lb =
3806 new CoarseLocationUpdatePacket.LocationBlock();
3807  
3808 lb.X = (byte)CoarseLocations[i].X;
3809 lb.Y = (byte)CoarseLocations[i].Y;
3810  
3811 lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f);
3812 loc.Location[i] = lb;
3813 loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock();
3814 loc.AgentData[i].AgentID = users[i];
3815 if (users[i] == AgentId)
3816 selfindex = i;
3817 }
3818  
3819 ib.You = (short)selfindex;
3820 ib.Prey = -1;
3821 loc.Index = ib;
3822  
3823 OutPacket(loc, ThrottleOutPacketType.Task);
3824 }
3825  
3826 #endregion Avatar Packet/Data Sending Methods
3827  
3828 #region Primitive Packet/Data Sending Methods
3829  
3830  
3831 /// <summary>
3832 /// Generate one of the object update packets based on PrimUpdateFlags
3833 /// and broadcast the packet to clients
3834 /// </summary>
3835 public void SendEntityUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
3836 {
3837 //double priority = m_prioritizer.GetUpdatePriority(this, entity);
3838 uint priority = m_prioritizer.GetUpdatePriority(this, entity);
3839  
3840 lock (m_entityUpdates.SyncRoot)
3841 m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags, m_scene.TimeDilation));
3842 }
3843  
3844 /// <summary>
3845 /// Requeue an EntityUpdate when it was not acknowledged by the client.
3846 /// We will update the priority and put it in the correct queue, merging update flags
3847 /// with any other updates that may be queued for the same entity.
3848 /// The original update time is used for the merged update.
3849 /// </summary>
3850 private void ResendPrimUpdate(EntityUpdate update)
3851 {
3852 // If the update exists in priority queue, it will be updated.
3853 // If it does not exist then it will be added with the current (rather than its original) priority
3854 uint priority = m_prioritizer.GetUpdatePriority(this, update.Entity);
3855  
3856 lock (m_entityUpdates.SyncRoot)
3857 m_entityUpdates.Enqueue(priority, update);
3858 }
3859  
3860 /// <summary>
3861 /// Requeue a list of EntityUpdates when they were not acknowledged by the client.
3862 /// We will update the priority and put it in the correct queue, merging update flags
3863 /// with any other updates that may be queued for the same entity.
3864 /// The original update time is used for the merged update.
3865 /// </summary>
3866 private void ResendPrimUpdates(List<EntityUpdate> updates, OutgoingPacket oPacket)
3867 {
3868 // m_log.WarnFormat("[CLIENT] resending prim updates {0}, packet sequence number {1}", updates[0].UpdateTime, oPacket.SequenceNumber);
3869  
3870 // Remove the update packet from the list of packets waiting for acknowledgement
3871 // because we are requeuing the list of updates. They will be resent in new packets
3872 // with the most recent state and priority.
3873 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
3874  
3875 // Count this as a resent packet since we are going to requeue all of the updates contained in it
3876 Interlocked.Increment(ref m_udpClient.PacketsResent);
3877  
3878 // We're not going to worry about interlock yet since its not currently critical that this total count
3879 // is 100% correct
3880 m_udpServer.PacketsResentCount++;
3881  
3882 foreach (EntityUpdate update in updates)
3883 ResendPrimUpdate(update);
3884 }
3885  
3886 // OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>();
3887 // OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>> compressedUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>>();
3888 // OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3889 // OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3890 //
3891 // OpenSim.Framework.Lazy<List<EntityUpdate>> objectUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3892 // OpenSim.Framework.Lazy<List<EntityUpdate>> compressedUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3893 // OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3894 // OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3895  
3896  
3897 private void ProcessEntityUpdates(int maxUpdates)
3898 {
3899 OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>> objectUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdatePacket.ObjectDataBlock>>();
3900 OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>> compressedUpdateBlocks = new OpenSim.Framework.Lazy<List<ObjectUpdateCompressedPacket.ObjectDataBlock>>();
3901 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3902 OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>> terseAgentUpdateBlocks = new OpenSim.Framework.Lazy<List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>>();
3903  
3904 OpenSim.Framework.Lazy<List<EntityUpdate>> objectUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3905 OpenSim.Framework.Lazy<List<EntityUpdate>> compressedUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3906 OpenSim.Framework.Lazy<List<EntityUpdate>> terseUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3907 OpenSim.Framework.Lazy<List<EntityUpdate>> terseAgentUpdates = new OpenSim.Framework.Lazy<List<EntityUpdate>>();
3908  
3909 // objectUpdateBlocks.Value.Clear();
3910 // compressedUpdateBlocks.Value.Clear();
3911 // terseUpdateBlocks.Value.Clear();
3912 // terseAgentUpdateBlocks.Value.Clear();
3913 // objectUpdates.Value.Clear();
3914 // compressedUpdates.Value.Clear();
3915 // terseUpdates.Value.Clear();
3916 // terseAgentUpdates.Value.Clear();
3917  
3918 // Check to see if this is a flush
3919 if (maxUpdates <= 0)
3920 {
3921 maxUpdates = Int32.MaxValue;
3922 }
3923  
3924 int updatesThisCall = 0;
3925  
3926 // We must lock for both manipulating the kill record and sending the packet, in order to avoid a race
3927 // condition where a kill can be processed before an out-of-date update for the same object.
3928 lock (m_killRecord)
3929 {
3930 float avgTimeDilation = 1.0f;
3931 IEntityUpdate iupdate;
3932 Int32 timeinqueue; // this is just debugging code & can be dropped later
3933  
3934 while (updatesThisCall < maxUpdates)
3935 {
3936 lock (m_entityUpdates.SyncRoot)
3937 if (!m_entityUpdates.TryDequeue(out iupdate, out timeinqueue))
3938 break;
3939  
3940 EntityUpdate update = (EntityUpdate)iupdate;
3941  
3942 avgTimeDilation += update.TimeDilation;
3943 avgTimeDilation *= 0.5f;
3944  
3945 if (update.Entity is SceneObjectPart)
3946 {
3947 SceneObjectPart part = (SceneObjectPart)update.Entity;
3948  
3949 // Please do not remove this unless you can demonstrate on the OpenSim mailing list that a client
3950 // will never receive an update after a prim kill. Even then, keeping the kill record may be a good
3951 // safety measure.
3952 //
3953 // If a Linden Lab 1.23.5 client (and possibly later and earlier) receives an object update
3954 // after a kill, it will keep displaying the deleted object until relog. OpenSim currently performs
3955 // updates and kills on different threads with different scheduling strategies, hence this protection.
3956 //
3957 // This doesn't appear to apply to child prims - a client will happily ignore these updates
3958 // after the root prim has been deleted.
3959 if (m_killRecord.Contains(part.LocalId))
3960 {
3961 // m_log.WarnFormat(
3962 // "[CLIENT]: Preventing update for prim with local id {0} after client for user {1} told it was deleted",
3963 // part.LocalId, Name);
3964 continue;
3965 }
3966  
3967 if (part.ParentGroup.IsAttachment && m_disableFacelights)
3968 {
3969 if (part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.LeftHand &&
3970 part.ParentGroup.RootPart.Shape.State != (byte)AttachmentPoint.RightHand)
3971 {
3972 part.Shape.LightEntry = false;
3973 }
3974 }
3975  
3976 if (part.Shape != null && (part.Shape.SculptType == (byte)SculptType.Mesh))
3977 {
3978 // Ensure that mesh has at least 8 valid faces
3979 part.Shape.ProfileBegin = 12500;
3980 part.Shape.ProfileEnd = 0;
3981 part.Shape.ProfileHollow = 27500;
3982 }
3983 }
3984  
3985 #region UpdateFlags to packet type conversion
3986  
3987 PrimUpdateFlags updateFlags = (PrimUpdateFlags)update.Flags;
3988  
3989 bool canUseCompressed = true;
3990 bool canUseImproved = true;
3991  
3992 // Compressed object updates only make sense for LL primitives
3993 if (!(update.Entity is SceneObjectPart))
3994 {
3995 canUseCompressed = false;
3996 }
3997  
3998 if (updateFlags.HasFlag(PrimUpdateFlags.FullUpdate))
3999 {
4000 canUseCompressed = false;
4001 canUseImproved = false;
4002 }
4003 else
4004 {
4005 if (updateFlags.HasFlag(PrimUpdateFlags.Velocity) ||
4006 updateFlags.HasFlag(PrimUpdateFlags.Acceleration) ||
4007 updateFlags.HasFlag(PrimUpdateFlags.CollisionPlane) ||
4008 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4009 {
4010 canUseCompressed = false;
4011 }
4012  
4013 if (updateFlags.HasFlag(PrimUpdateFlags.PrimFlags) ||
4014 updateFlags.HasFlag(PrimUpdateFlags.ParentID) ||
4015 updateFlags.HasFlag(PrimUpdateFlags.Scale) ||
4016 updateFlags.HasFlag(PrimUpdateFlags.PrimData) ||
4017 updateFlags.HasFlag(PrimUpdateFlags.Text) ||
4018 updateFlags.HasFlag(PrimUpdateFlags.NameValue) ||
4019 updateFlags.HasFlag(PrimUpdateFlags.ExtraData) ||
4020 updateFlags.HasFlag(PrimUpdateFlags.TextureAnim) ||
4021 updateFlags.HasFlag(PrimUpdateFlags.Sound) ||
4022 updateFlags.HasFlag(PrimUpdateFlags.Particles) ||
4023 updateFlags.HasFlag(PrimUpdateFlags.Material) ||
4024 updateFlags.HasFlag(PrimUpdateFlags.ClickAction) ||
4025 updateFlags.HasFlag(PrimUpdateFlags.MediaURL) ||
4026 updateFlags.HasFlag(PrimUpdateFlags.Joint))
4027 {
4028 canUseImproved = false;
4029 }
4030 }
4031  
4032 #endregion UpdateFlags to packet type conversion
4033  
4034 #region Block Construction
4035  
4036 // TODO: Remove this once we can build compressed updates
4037 canUseCompressed = false;
4038  
4039 if (!canUseImproved && !canUseCompressed)
4040 {
4041 ObjectUpdatePacket.ObjectDataBlock updateBlock;
4042  
4043 if (update.Entity is ScenePresence)
4044 {
4045 updateBlock = CreateAvatarUpdateBlock((ScenePresence)update.Entity);
4046 }
4047 else
4048 {
4049 SceneObjectPart part = (SceneObjectPart)update.Entity;
4050 updateBlock = CreatePrimUpdateBlock(part, AgentId);
4051  
4052 // If the part has become a private hud since the update was scheduled then we do not
4053 // want to send it to other avatars.
4054 if (part.ParentGroup.IsAttachment
4055 && part.ParentGroup.HasPrivateAttachmentPoint
4056 && part.ParentGroup.AttachedAvatar != AgentId)
4057 continue;
4058  
4059 // If the part has since been deleted, then drop the update. In the case of attachments,
4060 // this is to avoid spurious updates to other viewers since post-processing of attachments
4061 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4062 // of the test above).
4063 //
4064 // Actual deletions (kills) happen in another method.
4065 if (part.ParentGroup.IsDeleted)
4066 continue;
4067 }
4068  
4069 objectUpdateBlocks.Value.Add(updateBlock);
4070 objectUpdates.Value.Add(update);
4071 }
4072 else if (!canUseImproved)
4073 {
4074 SceneObjectPart part = (SceneObjectPart)update.Entity;
4075 ObjectUpdateCompressedPacket.ObjectDataBlock compressedBlock
4076 = CreateCompressedUpdateBlock(part, updateFlags);
4077  
4078 // If the part has since been deleted, then drop the update. In the case of attachments,
4079 // this is to avoid spurious updates to other viewers since post-processing of attachments
4080 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4081 // of the test above).
4082 //
4083 // Actual deletions (kills) happen in another method.
4084 if (part.ParentGroup.IsDeleted)
4085 continue;
4086  
4087 compressedUpdateBlocks.Value.Add(compressedBlock);
4088 compressedUpdates.Value.Add(update);
4089 }
4090 else
4091 {
4092 if (update.Entity is ScenePresence && ((ScenePresence)update.Entity).UUID == AgentId)
4093 {
4094 // Self updates go into a special list
4095 terseAgentUpdateBlocks.Value.Add(CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures)));
4096 terseAgentUpdates.Value.Add(update);
4097 }
4098 else
4099 {
4100 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseUpdateBlock
4101 = CreateImprovedTerseBlock(update.Entity, updateFlags.HasFlag(PrimUpdateFlags.Textures));
4102  
4103 // Everything else goes here
4104 if (update.Entity is SceneObjectPart)
4105 {
4106 SceneObjectPart part = (SceneObjectPart)update.Entity;
4107  
4108 // If the part has become a private hud since the update was scheduled then we do not
4109 // want to send it to other avatars.
4110 if (part.ParentGroup.IsAttachment
4111 && part.ParentGroup.HasPrivateAttachmentPoint
4112 && part.ParentGroup.AttachedAvatar != AgentId)
4113 continue;
4114  
4115 // If the part has since been deleted, then drop the update. In the case of attachments,
4116 // this is to avoid spurious updates to other viewers since post-processing of attachments
4117 // has to change the IsAttachment flag for various reasons (which will end up in a pass
4118 // of the test above).
4119 //
4120 // Actual deletions (kills) happen in another method.
4121 if (part.ParentGroup.IsDeleted)
4122 continue;
4123 }
4124  
4125 terseUpdateBlocks.Value.Add(terseUpdateBlock);
4126 terseUpdates.Value.Add(update);
4127 }
4128 }
4129  
4130 ++updatesThisCall;
4131  
4132 #endregion Block Construction
4133 }
4134  
4135 #region Packet Sending
4136 ushort timeDilation = Utils.FloatToUInt16(avgTimeDilation, 0.0f, 1.0f);
4137  
4138 if (terseAgentUpdateBlocks.IsValueCreated)
4139 {
4140 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseAgentUpdateBlocks.Value;
4141  
4142 ImprovedTerseObjectUpdatePacket packet
4143 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
4144  
4145 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4146 packet.RegionData.TimeDilation = timeDilation;
4147 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4148  
4149 for (int i = 0; i < blocks.Count; i++)
4150 packet.ObjectData[i] = blocks[i];
4151 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4152 OutPacket(packet, ThrottleOutPacketType.Unknown, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseAgentUpdates.Value, oPacket); });
4153 }
4154  
4155 if (objectUpdateBlocks.IsValueCreated)
4156 {
4157 List<ObjectUpdatePacket.ObjectDataBlock> blocks = objectUpdateBlocks.Value;
4158  
4159 ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
4160 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4161 packet.RegionData.TimeDilation = timeDilation;
4162 packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4163  
4164 for (int i = 0; i < blocks.Count; i++)
4165 packet.ObjectData[i] = blocks[i];
4166 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4167 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(objectUpdates.Value, oPacket); });
4168 }
4169  
4170 if (compressedUpdateBlocks.IsValueCreated)
4171 {
4172 List<ObjectUpdateCompressedPacket.ObjectDataBlock> blocks = compressedUpdateBlocks.Value;
4173  
4174 ObjectUpdateCompressedPacket packet = (ObjectUpdateCompressedPacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdateCompressed);
4175 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4176 packet.RegionData.TimeDilation = timeDilation;
4177 packet.ObjectData = new ObjectUpdateCompressedPacket.ObjectDataBlock[blocks.Count];
4178  
4179 for (int i = 0; i < blocks.Count; i++)
4180 packet.ObjectData[i] = blocks[i];
4181 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4182 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(compressedUpdates.Value, oPacket); });
4183 }
4184  
4185 if (terseUpdateBlocks.IsValueCreated)
4186 {
4187 List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> blocks = terseUpdateBlocks.Value;
4188  
4189 ImprovedTerseObjectUpdatePacket packet
4190 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(
4191 PacketType.ImprovedTerseObjectUpdate);
4192  
4193 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
4194 packet.RegionData.TimeDilation = timeDilation;
4195 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[blocks.Count];
4196  
4197 for (int i = 0; i < blocks.Count; i++)
4198 packet.ObjectData[i] = blocks[i];
4199 // If any of the packets created from this call go unacknowledged, all of the updates will be resent
4200 OutPacket(packet, ThrottleOutPacketType.Task, true, delegate(OutgoingPacket oPacket) { ResendPrimUpdates(terseUpdates.Value, oPacket); });
4201 }
4202 }
4203  
4204 // m_log.DebugFormat(
4205 // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}",
4206 // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name);
4207 //
4208 #endregion Packet Sending
4209 }
4210  
4211 public void ReprioritizeUpdates()
4212 {
4213 lock (m_entityUpdates.SyncRoot)
4214 m_entityUpdates.Reprioritize(UpdatePriorityHandler);
4215 }
4216  
4217 private bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity)
4218 {
4219 if (entity != null)
4220 {
4221 priority = m_prioritizer.GetUpdatePriority(this, entity);
4222 return true;
4223 }
4224  
4225 return false;
4226 }
4227  
4228 public void FlushPrimUpdates()
4229 {
4230 m_log.WarnFormat("[CLIENT]: Flushing prim updates to " + m_firstName + " " + m_lastName);
4231  
4232 while (m_entityUpdates.Count > 0)
4233 ProcessEntityUpdates(-1);
4234 }
4235  
4236 #endregion Primitive Packet/Data Sending Methods
4237  
4238 // These are used to implement an adaptive backoff in the number
4239 // of updates converted to packets. Since we don't want packets
4240 // to sit in the queue with old data, only convert enough updates
4241 // to packets that can be sent in 200ms.
4242 private Int32 m_LastQueueFill = 0;
4243 private Int32 m_maxUpdates = 0;
4244  
4245 void HandleQueueEmpty(ThrottleOutPacketTypeFlags categories)
4246 {
4247 // if (!m_udpServer.IsRunningOutbound)
4248 // return;
4249  
4250 if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
4251 {
4252 // if (!m_udpServer.IsRunningOutbound)
4253 // return;
4254  
4255 if (m_maxUpdates == 0 || m_LastQueueFill == 0)
4256 {
4257 m_maxUpdates = m_udpServer.PrimUpdatesPerCallback;
4258 }
4259 else
4260 {
4261 if (Util.EnvironmentTickCountSubtract(m_LastQueueFill) < 200)
4262 m_maxUpdates += 5;
4263 else
4264 m_maxUpdates = m_maxUpdates >> 1;
4265 }
4266 m_maxUpdates = Util.Clamp<Int32>(m_maxUpdates,10,500);
4267 m_LastQueueFill = Util.EnvironmentTickCount();
4268  
4269 if (m_entityUpdates.Count > 0)
4270 ProcessEntityUpdates(m_maxUpdates);
4271  
4272 if (m_entityProps.Count > 0)
4273 ProcessEntityPropertyRequests(m_maxUpdates);
4274 }
4275  
4276 if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
4277 ImageManager.ProcessImageQueue(m_udpServer.TextureSendLimit);
4278 }
4279  
4280 internal bool HandleHasUpdates(ThrottleOutPacketTypeFlags categories)
4281 {
4282 bool hasUpdates = false;
4283  
4284 if ((categories & ThrottleOutPacketTypeFlags.Task) != 0)
4285 {
4286 if (m_entityUpdates.Count > 0)
4287 hasUpdates = true;
4288 else if (m_entityProps.Count > 0)
4289 hasUpdates = true;
4290 }
4291  
4292 if ((categories & ThrottleOutPacketTypeFlags.Texture) != 0)
4293 {
4294 if (ImageManager.HasUpdates())
4295 hasUpdates = true;
4296 }
4297  
4298 return hasUpdates;
4299 }
4300  
4301 public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
4302 {
4303 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
4304 newPack.AssetBlock.Type = AssetType;
4305 newPack.AssetBlock.Success = Success;
4306 newPack.AssetBlock.UUID = AssetFullID;
4307 newPack.Header.Zerocoded = true;
4308 OutPacket(newPack, ThrottleOutPacketType.Asset);
4309 }
4310  
4311 public void SendXferRequest(ulong XferID, short AssetType, UUID vFileID, byte FilePath, byte[] FileName)
4312 {
4313 RequestXferPacket newPack = new RequestXferPacket();
4314 newPack.XferID.ID = XferID;
4315 newPack.XferID.VFileType = AssetType;
4316 newPack.XferID.VFileID = vFileID;
4317 newPack.XferID.FilePath = FilePath;
4318 newPack.XferID.Filename = FileName;
4319 newPack.Header.Zerocoded = true;
4320 OutPacket(newPack, ThrottleOutPacketType.Asset);
4321 }
4322  
4323 public void SendConfirmXfer(ulong xferID, uint PacketID)
4324 {
4325 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
4326 newPack.XferID.ID = xferID;
4327 newPack.XferID.Packet = PacketID;
4328 newPack.Header.Zerocoded = true;
4329 OutPacket(newPack, ThrottleOutPacketType.Asset);
4330 }
4331  
4332 public void SendInitiateDownload(string simFileName, string clientFileName)
4333 {
4334 InitiateDownloadPacket newPack = new InitiateDownloadPacket();
4335 newPack.AgentData.AgentID = AgentId;
4336 newPack.FileData.SimFilename = Utils.StringToBytes(simFileName);
4337 newPack.FileData.ViewerFilename = Utils.StringToBytes(clientFileName);
4338 OutPacket(newPack, ThrottleOutPacketType.Asset);
4339 }
4340  
4341 public void SendImageFirstPart(
4342 ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
4343 {
4344 ImageDataPacket im = new ImageDataPacket();
4345 im.Header.Reliable = false;
4346 im.ImageID.Packets = numParts;
4347 im.ImageID.ID = ImageUUID;
4348  
4349 if (ImageSize > 0)
4350 im.ImageID.Size = ImageSize;
4351  
4352 im.ImageData.Data = ImageData;
4353 im.ImageID.Codec = imageCodec;
4354 im.Header.Zerocoded = true;
4355 OutPacket(im, ThrottleOutPacketType.Texture);
4356 }
4357  
4358 public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
4359 {
4360 ImagePacketPacket im = new ImagePacketPacket();
4361 im.Header.Reliable = false;
4362 im.ImageID.Packet = partNumber;
4363 im.ImageID.ID = imageUuid;
4364 im.ImageData.Data = imageData;
4365  
4366 OutPacket(im, ThrottleOutPacketType.Texture);
4367 }
4368  
4369 public void SendImageNotFound(UUID imageid)
4370 {
4371 ImageNotInDatabasePacket notFoundPacket
4372 = (ImageNotInDatabasePacket)PacketPool.Instance.GetPacket(PacketType.ImageNotInDatabase);
4373  
4374 notFoundPacket.ImageID.ID = imageid;
4375  
4376 OutPacket(notFoundPacket, ThrottleOutPacketType.Texture);
4377 }
4378  
4379 public void SendShutdownConnectionNotice()
4380 {
4381 OutPacket(PacketPool.Instance.GetPacket(PacketType.DisableSimulator), ThrottleOutPacketType.Unknown);
4382 }
4383  
4384 public void SendSimStats(SimStats stats)
4385 {
4386 SimStatsPacket pack = new SimStatsPacket();
4387 pack.Region = new SimStatsPacket.RegionBlock();
4388 pack.Region.RegionX = stats.RegionX;
4389 pack.Region.RegionY = stats.RegionY;
4390 pack.Region.RegionFlags = stats.RegionFlags;
4391 pack.Region.ObjectCapacity = stats.ObjectCapacity;
4392 //pack.Region = //stats.RegionBlock;
4393 pack.Stat = stats.StatsBlock;
4394  
4395 pack.Header.Reliable = false;
4396 pack.RegionInfo = new SimStatsPacket.RegionInfoBlock[0];
4397 OutPacket(pack, ThrottleOutPacketType.Task);
4398 }
4399  
4400 private class ObjectPropertyUpdate : IEntityUpdate
4401 {
4402 internal bool SendFamilyProps;
4403 internal bool SendObjectProps;
4404  
4405 public ObjectPropertyUpdate(ISceneEntity entity, uint flags, bool sendfam, bool sendobj)
4406 : base(entity,flags)
4407 {
4408 SendFamilyProps = sendfam;
4409 SendObjectProps = sendobj;
4410 }
4411 public void Update(ObjectPropertyUpdate update)
4412 {
4413 SendFamilyProps = SendFamilyProps || update.SendFamilyProps;
4414 SendObjectProps = SendObjectProps || update.SendObjectProps;
4415 // other properties may need to be updated by base class
4416 base.Update(update);
4417 }
4418 }
4419  
4420 public void SendObjectPropertiesFamilyData(ISceneEntity entity, uint requestFlags)
4421 {
4422 uint priority = 0; // time based ordering only
4423 lock (m_entityProps.SyncRoot)
4424 m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity,requestFlags,true,false));
4425 }
4426  
4427 private void ResendPropertyUpdate(ObjectPropertyUpdate update)
4428 {
4429 uint priority = 0;
4430 lock (m_entityProps.SyncRoot)
4431 m_entityProps.Enqueue(priority, update);
4432 }
4433  
4434 private void ResendPropertyUpdates(List<ObjectPropertyUpdate> updates, OutgoingPacket oPacket)
4435 {
4436 // m_log.WarnFormat("[CLIENT] resending object property {0}",updates[0].UpdateTime);
4437  
4438 // Remove the update packet from the list of packets waiting for acknowledgement
4439 // because we are requeuing the list of updates. They will be resent in new packets
4440 // with the most recent state.
4441 m_udpClient.NeedAcks.Remove(oPacket.SequenceNumber);
4442  
4443 // Count this as a resent packet since we are going to requeue all of the updates contained in it
4444 Interlocked.Increment(ref m_udpClient.PacketsResent);
4445  
4446 // We're not going to worry about interlock yet since its not currently critical that this total count
4447 // is 100% correct
4448 m_udpServer.PacketsResentCount++;
4449  
4450 foreach (ObjectPropertyUpdate update in updates)
4451 ResendPropertyUpdate(update);
4452 }
4453  
4454 public void SendObjectPropertiesReply(ISceneEntity entity)
4455 {
4456 uint priority = 0; // time based ordering only
4457 lock (m_entityProps.SyncRoot)
4458 m_entityProps.Enqueue(priority, new ObjectPropertyUpdate(entity,0,false,true));
4459 }
4460  
4461 private void ProcessEntityPropertyRequests(int maxUpdates)
4462 {
4463 OpenSim.Framework.Lazy<List<ObjectPropertiesFamilyPacket.ObjectDataBlock>> objectFamilyBlocks =
4464 new OpenSim.Framework.Lazy<List<ObjectPropertiesFamilyPacket.ObjectDataBlock>>();
4465  
4466 OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>> objectPropertiesBlocks =
4467 new OpenSim.Framework.Lazy<List<ObjectPropertiesPacket.ObjectDataBlock>>();
4468  
4469 OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>> familyUpdates =
4470 new OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>>();
4471  
4472 OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>> propertyUpdates =
4473 new OpenSim.Framework.Lazy<List<ObjectPropertyUpdate>>();
4474  
4475 IEntityUpdate iupdate;
4476 Int32 timeinqueue; // this is just debugging code & can be dropped later
4477  
4478 int updatesThisCall = 0;
4479 while (updatesThisCall < m_maxUpdates)
4480 {
4481 lock (m_entityProps.SyncRoot)
4482 if (!m_entityProps.TryDequeue(out iupdate, out timeinqueue))
4483 break;
4484  
4485 ObjectPropertyUpdate update = (ObjectPropertyUpdate)iupdate;
4486 if (update.SendFamilyProps)
4487 {
4488 if (update.Entity is SceneObjectPart)
4489 {
4490 SceneObjectPart sop = (SceneObjectPart)update.Entity;
4491 ObjectPropertiesFamilyPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesFamilyBlock(sop,update.Flags);
4492 objectFamilyBlocks.Value.Add(objPropDB);
4493 familyUpdates.Value.Add(update);
4494 }
4495 }
4496  
4497 if (update.SendObjectProps)
4498 {
4499 if (update.Entity is SceneObjectPart)
4500 {
4501 SceneObjectPart sop = (SceneObjectPart)update.Entity;
4502 ObjectPropertiesPacket.ObjectDataBlock objPropDB = CreateObjectPropertiesBlock(sop);
4503 objectPropertiesBlocks.Value.Add(objPropDB);
4504 propertyUpdates.Value.Add(update);
4505 }
4506 }
4507  
4508 updatesThisCall++;
4509 }
4510  
4511  
4512 // Int32 ppcnt = 0;
4513 // Int32 pbcnt = 0;
4514  
4515 if (objectPropertiesBlocks.IsValueCreated)
4516 {
4517 List<ObjectPropertiesPacket.ObjectDataBlock> blocks = objectPropertiesBlocks.Value;
4518 List<ObjectPropertyUpdate> updates = propertyUpdates.Value;
4519  
4520 ObjectPropertiesPacket packet = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
4521 packet.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[blocks.Count];
4522 for (int i = 0; i < blocks.Count; i++)
4523 packet.ObjectData[i] = blocks[i];
4524  
4525 packet.Header.Zerocoded = true;
4526  
4527 // Pass in the delegate so that if this packet needs to be resent, we send the current properties
4528 // of the object rather than the properties when the packet was created
4529 OutPacket(packet, ThrottleOutPacketType.Task, true,
4530 delegate(OutgoingPacket oPacket)
4531 {
4532 ResendPropertyUpdates(updates, oPacket);
4533 });
4534  
4535 // pbcnt += blocks.Count;
4536 // ppcnt++;
4537 }
4538  
4539 // Int32 fpcnt = 0;
4540 // Int32 fbcnt = 0;
4541  
4542 if (objectFamilyBlocks.IsValueCreated)
4543 {
4544 List<ObjectPropertiesFamilyPacket.ObjectDataBlock> blocks = objectFamilyBlocks.Value;
4545  
4546 // one packet per object block... uggh...
4547 for (int i = 0; i < blocks.Count; i++)
4548 {
4549 ObjectPropertiesFamilyPacket packet =
4550 (ObjectPropertiesFamilyPacket)PacketPool.Instance.GetPacket(PacketType.ObjectPropertiesFamily);
4551  
4552 packet.ObjectData = blocks[i];
4553 packet.Header.Zerocoded = true;
4554  
4555 // Pass in the delegate so that if this packet needs to be resent, we send the current properties
4556 // of the object rather than the properties when the packet was created
4557 List<ObjectPropertyUpdate> updates = new List<ObjectPropertyUpdate>();
4558 updates.Add(familyUpdates.Value[i]);
4559 OutPacket(packet, ThrottleOutPacketType.Task, true,
4560 delegate(OutgoingPacket oPacket)
4561 {
4562 ResendPropertyUpdates(updates, oPacket);
4563 });
4564  
4565 // fpcnt++;
4566 // fbcnt++;
4567 }
4568  
4569 }
4570  
4571 // m_log.WarnFormat("[PACKETCOUNTS] queued {0} property packets with {1} blocks",ppcnt,pbcnt);
4572 // m_log.WarnFormat("[PACKETCOUNTS] queued {0} family property packets with {1} blocks",fpcnt,fbcnt);
4573 }
4574  
4575 private ObjectPropertiesFamilyPacket.ObjectDataBlock CreateObjectPropertiesFamilyBlock(SceneObjectPart sop, uint requestFlags)
4576 {
4577 ObjectPropertiesFamilyPacket.ObjectDataBlock block = new ObjectPropertiesFamilyPacket.ObjectDataBlock();
4578  
4579 block.RequestFlags = requestFlags;
4580 block.ObjectID = sop.UUID;
4581 if (sop.OwnerID == sop.GroupID)
4582 block.OwnerID = UUID.Zero;
4583 else
4584 block.OwnerID = sop.OwnerID;
4585 block.GroupID = sop.GroupID;
4586 block.BaseMask = sop.BaseMask;
4587 block.OwnerMask = sop.OwnerMask;
4588 block.GroupMask = sop.GroupMask;
4589 block.EveryoneMask = sop.EveryoneMask;
4590 block.NextOwnerMask = sop.NextOwnerMask;
4591  
4592 // TODO: More properties are needed in SceneObjectPart!
4593 block.OwnershipCost = sop.OwnershipCost;
4594 block.SaleType = sop.ObjectSaleType;
4595 block.SalePrice = sop.SalePrice;
4596 block.Category = sop.Category;
4597 block.LastOwnerID = sop.CreatorID; // copied from old SOG call... is this right?
4598 block.Name = Util.StringToBytes256(sop.Name);
4599 block.Description = Util.StringToBytes256(sop.Description);
4600  
4601 return block;
4602 }
4603  
4604 private ObjectPropertiesPacket.ObjectDataBlock CreateObjectPropertiesBlock(SceneObjectPart sop)
4605 {
4606 //ObjectPropertiesPacket proper = (ObjectPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ObjectProperties);
4607 // TODO: don't create new blocks if recycling an old packet
4608  
4609 ObjectPropertiesPacket.ObjectDataBlock block =
4610 new ObjectPropertiesPacket.ObjectDataBlock();
4611  
4612 block.ObjectID = sop.UUID;
4613 block.Name = Util.StringToBytes256(sop.Name);
4614 block.Description = Util.StringToBytes256(sop.Description);
4615  
4616 block.CreationDate = (ulong)sop.CreationDate * 1000000; // viewer wants date in microseconds
4617 block.CreatorID = sop.CreatorID;
4618 block.GroupID = sop.GroupID;
4619 block.LastOwnerID = sop.LastOwnerID;
4620 if (sop.OwnerID == sop.GroupID)
4621 block.OwnerID = UUID.Zero;
4622 else
4623 block.OwnerID = sop.OwnerID;
4624  
4625 block.ItemID = sop.FromUserInventoryItemID;
4626 block.FolderID = UUID.Zero; // sog.FromFolderID ??
4627 block.FromTaskID = UUID.Zero; // ???
4628 block.InventorySerial = (short)sop.InventorySerial;
4629  
4630 SceneObjectPart root = sop.ParentGroup.RootPart;
4631  
4632 block.TouchName = Util.StringToBytes256(root.TouchName);
4633  
4634 // SL 3.3.4, at least, appears to read this information as a concatenated byte[] stream of UUIDs but
4635 // it's not yet clear whether this is actually used. If this is done in the future then a pre-cached
4636 // copy is really needed since it's less efficient to be constantly recreating this byte array.
4637 // using (MemoryStream memStream = new MemoryStream())
4638 // {
4639 // using (BinaryWriter binWriter = new BinaryWriter(memStream))
4640 // {
4641 // for (int i = 0; i < sop.GetNumberOfSides(); i++)
4642 // {
4643 // Primitive.TextureEntryFace teFace = sop.Shape.Textures.FaceTextures[i];
4644 //
4645 // UUID textureID;
4646 //
4647 // if (teFace != null)
4648 // textureID = teFace.TextureID;
4649 // else
4650 // textureID = sop.Shape.Textures.DefaultTexture.TextureID;
4651 //
4652 // binWriter.Write(textureID.GetBytes());
4653 // }
4654 //
4655 // block.TextureID = memStream.ToArray();
4656 // }
4657 // }
4658  
4659 block.TextureID = new byte[0]; // TextureID ???
4660 block.SitName = Util.StringToBytes256(root.SitName);
4661 block.OwnerMask = root.OwnerMask;
4662 block.NextOwnerMask = root.NextOwnerMask;
4663 block.GroupMask = root.GroupMask;
4664 block.EveryoneMask = root.EveryoneMask;
4665 block.BaseMask = root.BaseMask;
4666 block.SaleType = root.ObjectSaleType;
4667 block.SalePrice = root.SalePrice;
4668  
4669 return block;
4670 }
4671  
4672 #region Estate Data Sending Methods
4673  
4674 private static bool convertParamStringToBool(byte[] field)
4675 {
4676 string s = Utils.BytesToString(field);
4677 if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
4678 {
4679 return true;
4680 }
4681 return false;
4682 }
4683  
4684 public void SendEstateList(UUID invoice, int code, UUID[] Data, uint estateID)
4685  
4686 {
4687 EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
4688 packet.AgentData.TransactionID = UUID.Random();
4689 packet.AgentData.AgentID = AgentId;
4690 packet.AgentData.SessionID = SessionId;
4691 packet.MethodData.Invoice = invoice;
4692 packet.MethodData.Method = Utils.StringToBytes("setaccess");
4693  
4694 EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + Data.Length];
4695  
4696 for (int i = 0; i < (6 + Data.Length); i++)
4697 {
4698 returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
4699 }
4700 int j = 0;
4701  
4702 returnblock[j].Parameter = Utils.StringToBytes(estateID.ToString()); j++;
4703 returnblock[j].Parameter = Utils.StringToBytes(code.ToString()); j++;
4704 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4705 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4706 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4707 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4708  
4709 j = 2; // Agents
4710 if ((code & 2) != 0)
4711 j = 3; // Groups
4712 if ((code & 8) != 0)
4713 j = 5; // Managers
4714  
4715 returnblock[j].Parameter = Utils.StringToBytes(Data.Length.ToString());
4716 j = 6;
4717  
4718 for (int i = 0; i < Data.Length; i++)
4719 {
4720 returnblock[j].Parameter = Data[i].GetBytes(); j++;
4721 }
4722 packet.ParamList = returnblock;
4723 packet.Header.Reliable = true;
4724 OutPacket(packet, ThrottleOutPacketType.Task);
4725 }
4726  
4727 public void SendBannedUserList(UUID invoice, EstateBan[] bl, uint estateID)
4728 {
4729 List<UUID> BannedUsers = new List<UUID>();
4730  
4731 for (int i = 0; i < bl.Length; i++)
4732 {
4733 if (bl[i] == null)
4734 continue;
4735 if (bl[i].BannedUserID == UUID.Zero)
4736 continue;
4737 BannedUsers.Add(bl[i].BannedUserID);
4738  
4739 if (BannedUsers.Count >= 50 || (i == (bl.Length - 1) && BannedUsers.Count > 0))
4740 {
4741 EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
4742 packet.AgentData.TransactionID = UUID.Random();
4743 packet.AgentData.AgentID = AgentId;
4744 packet.AgentData.SessionID = SessionId;
4745 packet.MethodData.Invoice = invoice;
4746 packet.MethodData.Method = Utils.StringToBytes("setaccess");
4747  
4748 EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[6 + BannedUsers.Count];
4749  
4750 int j;
4751 for (j = 0; j < (6 + BannedUsers.Count); j++)
4752 {
4753 returnblock[j] = new EstateOwnerMessagePacket.ParamListBlock();
4754 }
4755 j = 0;
4756  
4757 returnblock[j].Parameter = Utils.StringToBytes(estateID.ToString()); j++;
4758 returnblock[j].Parameter = Utils.StringToBytes(((int)Constants.EstateAccessCodex.EstateBans).ToString()); j++;
4759 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4760 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4761 returnblock[j].Parameter = Utils.StringToBytes(BannedUsers.Count.ToString()); j++;
4762 returnblock[j].Parameter = Utils.StringToBytes("0"); j++;
4763  
4764 foreach (UUID banned in BannedUsers)
4765 {
4766 returnblock[j].Parameter = banned.GetBytes(); j++;
4767 }
4768 packet.ParamList = returnblock;
4769 packet.Header.Reliable = true;
4770 OutPacket(packet, ThrottleOutPacketType.Task);
4771  
4772 BannedUsers.Clear();
4773 }
4774 }
4775  
4776 }
4777  
4778 public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
4779 {
4780 RegionInfoPacket rinfopack = new RegionInfoPacket();
4781 RegionInfoPacket.RegionInfoBlock rinfoblk = new RegionInfoPacket.RegionInfoBlock();
4782 rinfopack.AgentData.AgentID = AgentId;
4783 rinfopack.AgentData.SessionID = SessionId;
4784 rinfoblk.BillableFactor = args.billableFactor;
4785 rinfoblk.EstateID = args.estateID;
4786 rinfoblk.MaxAgents = args.maxAgents;
4787 rinfoblk.ObjectBonusFactor = args.objectBonusFactor;
4788 rinfoblk.ParentEstateID = args.parentEstateID;
4789 rinfoblk.PricePerMeter = args.pricePerMeter;
4790 rinfoblk.RedirectGridX = args.redirectGridX;
4791 rinfoblk.RedirectGridY = args.redirectGridY;
4792 rinfoblk.RegionFlags = args.regionFlags;
4793 rinfoblk.SimAccess = args.simAccess;
4794 rinfoblk.SunHour = args.sunHour;
4795 rinfoblk.TerrainLowerLimit = args.terrainLowerLimit;
4796 rinfoblk.TerrainRaiseLimit = args.terrainRaiseLimit;
4797 rinfoblk.UseEstateSun = args.useEstateSun;
4798 rinfoblk.WaterHeight = args.waterHeight;
4799 rinfoblk.SimName = Utils.StringToBytes(args.simName);
4800  
4801 rinfopack.RegionInfo2 = new RegionInfoPacket.RegionInfo2Block();
4802 rinfopack.RegionInfo2.HardMaxAgents = uint.MaxValue;
4803 rinfopack.RegionInfo2.HardMaxObjects = uint.MaxValue;
4804 rinfopack.RegionInfo2.MaxAgents32 = uint.MaxValue;
4805 rinfopack.RegionInfo2.ProductName = Util.StringToBytes256(args.regionType);
4806 rinfopack.RegionInfo2.ProductSKU = Utils.EmptyBytes;
4807  
4808 rinfopack.HasVariableBlocks = true;
4809 rinfopack.RegionInfo = rinfoblk;
4810 rinfopack.AgentData = new RegionInfoPacket.AgentDataBlock();
4811 rinfopack.AgentData.AgentID = AgentId;
4812 rinfopack.AgentData.SessionID = SessionId;
4813 rinfopack.RegionInfo3 = new RegionInfoPacket.RegionInfo3Block[0];
4814  
4815 OutPacket(rinfopack, ThrottleOutPacketType.Task);
4816 }
4817  
4818 public void SendEstateCovenantInformation(UUID covenant)
4819 {
4820 // m_log.DebugFormat("[LLCLIENTVIEW]: Sending estate covenant asset id of {0} to {1}", covenant, Name);
4821  
4822 EstateCovenantReplyPacket einfopack = new EstateCovenantReplyPacket();
4823 EstateCovenantReplyPacket.DataBlock edata = new EstateCovenantReplyPacket.DataBlock();
4824 edata.CovenantID = covenant;
4825 edata.CovenantTimestamp = (uint) m_scene.RegionInfo.RegionSettings.CovenantChangedDateTime;
4826 edata.EstateOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
4827 edata.EstateName = Utils.StringToBytes(m_scene.RegionInfo.EstateSettings.EstateName);
4828 einfopack.Data = edata;
4829 OutPacket(einfopack, ThrottleOutPacketType.Task);
4830 }
4831  
4832 public void SendDetailedEstateData(
4833 UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition,
4834 UUID covenant, uint covenantChanged, string abuseEmail, UUID estateOwner)
4835 {
4836 // m_log.DebugFormat(
4837 // "[LLCLIENTVIEW]: Sending detailed estate data to {0} with covenant asset id {1}", Name, covenant);
4838  
4839 EstateOwnerMessagePacket packet = new EstateOwnerMessagePacket();
4840 packet.MethodData.Invoice = invoice;
4841 packet.AgentData.TransactionID = UUID.Random();
4842 packet.MethodData.Method = Utils.StringToBytes("estateupdateinfo");
4843 EstateOwnerMessagePacket.ParamListBlock[] returnblock = new EstateOwnerMessagePacket.ParamListBlock[10];
4844  
4845 for (int i = 0; i < 10; i++)
4846 {
4847 returnblock[i] = new EstateOwnerMessagePacket.ParamListBlock();
4848 }
4849  
4850 //Sending Estate Settings
4851 returnblock[0].Parameter = Utils.StringToBytes(estateName);
4852 returnblock[1].Parameter = Utils.StringToBytes(estateOwner.ToString());
4853 returnblock[2].Parameter = Utils.StringToBytes(estateID.ToString());
4854  
4855 returnblock[3].Parameter = Utils.StringToBytes(estateFlags.ToString());
4856 returnblock[4].Parameter = Utils.StringToBytes(sunPosition.ToString());
4857 returnblock[5].Parameter = Utils.StringToBytes(parentEstate.ToString());
4858 returnblock[6].Parameter = Utils.StringToBytes(covenant.ToString());
4859 returnblock[7].Parameter = Utils.StringToBytes(covenantChanged.ToString());
4860 returnblock[8].Parameter = Utils.StringToBytes("1"); // what is this?
4861 returnblock[9].Parameter = Utils.StringToBytes(abuseEmail);
4862  
4863 packet.ParamList = returnblock;
4864 packet.Header.Reliable = false;
4865 //m_log.Debug("[ESTATE]: SIM--->" + packet.ToString());
4866 OutPacket(packet, ThrottleOutPacketType.Task);
4867 }
4868  
4869 public void SendTelehubInfo(UUID ObjectID, string ObjectName, Vector3 ObjectPos, Quaternion ObjectRot, List<Vector3> SpawnPoint)
4870 {
4871 TelehubInfoPacket packet = (TelehubInfoPacket)PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
4872 packet.TelehubBlock.ObjectID = ObjectID;
4873 packet.TelehubBlock.ObjectName = Utils.StringToBytes(ObjectName);
4874 packet.TelehubBlock.TelehubPos = ObjectPos;
4875 packet.TelehubBlock.TelehubRot = ObjectRot;
4876  
4877 packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
4878 for (int n = 0; n < SpawnPoint.Count; n++)
4879 {
4880 packet.SpawnPointBlock[n] = new TelehubInfoPacket.SpawnPointBlockBlock{SpawnPointPos = SpawnPoint[n]};
4881 }
4882  
4883 OutPacket(packet, ThrottleOutPacketType.Task);
4884 }
4885  
4886 #endregion
4887  
4888 #region Land Data Sending Methods
4889  
4890 public void SendLandParcelOverlay(byte[] data, int sequence_id)
4891 {
4892 ParcelOverlayPacket packet = (ParcelOverlayPacket)PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
4893 packet.ParcelData.Data = data;
4894 packet.ParcelData.SequenceID = sequence_id;
4895 packet.Header.Zerocoded = true;
4896 OutPacket(packet, ThrottleOutPacketType.Task);
4897 }
4898  
4899 public void SendLandProperties(
4900 int sequence_id, bool snap_selection, int request_result, ILandObject lo,
4901 float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
4902 {
4903 // m_log.DebugFormat("[LLCLIENTVIEW]: Sending land properties for {0} to {1}", lo.LandData.GlobalID, Name);
4904  
4905 LandData landData = lo.LandData;
4906  
4907 ParcelPropertiesMessage updateMessage = new ParcelPropertiesMessage();
4908  
4909 updateMessage.AABBMax = landData.AABBMax;
4910 updateMessage.AABBMin = landData.AABBMin;
4911 updateMessage.Area = landData.Area;
4912 updateMessage.AuctionID = landData.AuctionID;
4913 updateMessage.AuthBuyerID = landData.AuthBuyerID;
4914 updateMessage.Bitmap = landData.Bitmap;
4915 updateMessage.Desc = landData.Description;
4916 updateMessage.Category = landData.Category;
4917 updateMessage.ClaimDate = Util.ToDateTime(landData.ClaimDate);
4918 updateMessage.ClaimPrice = landData.ClaimPrice;
4919 updateMessage.GroupID = landData.GroupID;
4920 updateMessage.IsGroupOwned = landData.IsGroupOwned;
4921 updateMessage.LandingType = (LandingType) landData.LandingType;
4922 updateMessage.LocalID = landData.LocalID;
4923  
4924 if (landData.Area > 0)
4925 {
4926 updateMessage.MaxPrims = parcelObjectCapacity;
4927 }
4928 else
4929 {
4930 updateMessage.MaxPrims = 0;
4931 }
4932  
4933 updateMessage.MediaAutoScale = Convert.ToBoolean(landData.MediaAutoScale);
4934 updateMessage.MediaID = landData.MediaID;
4935 updateMessage.MediaURL = landData.MediaURL;
4936 updateMessage.MusicURL = landData.MusicURL;
4937 updateMessage.Name = landData.Name;
4938 updateMessage.OtherCleanTime = landData.OtherCleanTime;
4939 updateMessage.OtherCount = 0; //TODO: Unimplemented
4940 updateMessage.OwnerID = landData.OwnerID;
4941 updateMessage.ParcelFlags = (ParcelFlags) landData.Flags;
4942 updateMessage.ParcelPrimBonus = simObjectBonusFactor;
4943 updateMessage.PassHours = landData.PassHours;
4944 updateMessage.PassPrice = landData.PassPrice;
4945 updateMessage.PublicCount = 0; //TODO: Unimplemented
4946  
4947 updateMessage.RegionPushOverride = (regionFlags & (uint)RegionFlags.RestrictPushObject) > 0;
4948 updateMessage.RegionDenyAnonymous = (regionFlags & (uint)RegionFlags.DenyAnonymous) > 0;
4949  
4950 //updateMessage.RegionDenyIdentified = (regionFlags & (uint)RegionFlags.DenyIdentified) > 0;
4951 //updateMessage.RegionDenyTransacted = (regionFlags & (uint)RegionFlags.DenyTransacted) > 0;
4952  
4953 updateMessage.RentPrice = 0;
4954 updateMessage.RequestResult = (ParcelResult) request_result;
4955 updateMessage.SalePrice = landData.SalePrice;
4956 updateMessage.SelfCount = 0; //TODO: Unimplemented
4957 updateMessage.SequenceID = sequence_id;
4958  
4959 if (landData.SimwideArea > 0)
4960 {
4961 int simulatorCapacity = (int)(((float)landData.SimwideArea / 65536.0f) * (float)m_scene.RegionInfo.ObjectCapacity * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
4962 updateMessage.SimWideMaxPrims = simulatorCapacity;
4963 }
4964 else
4965 {
4966 updateMessage.SimWideMaxPrims = 0;
4967 }
4968  
4969 updateMessage.SnapSelection = snap_selection;
4970 updateMessage.SnapshotID = landData.SnapshotID;
4971 updateMessage.Status = (ParcelStatus) landData.Status;
4972 updateMessage.UserLocation = landData.UserLocation;
4973 updateMessage.UserLookAt = landData.UserLookAt;
4974  
4975 updateMessage.MediaType = landData.MediaType;
4976 updateMessage.MediaDesc = landData.MediaDescription;
4977 updateMessage.MediaWidth = landData.MediaWidth;
4978 updateMessage.MediaHeight = landData.MediaHeight;
4979 updateMessage.MediaLoop = landData.MediaLoop;
4980 updateMessage.ObscureMusic = landData.ObscureMusic;
4981 updateMessage.ObscureMedia = landData.ObscureMedia;
4982  
4983 IPrimCounts pc = lo.PrimCounts;
4984 updateMessage.OwnerPrims = pc.Owner;
4985 updateMessage.GroupPrims = pc.Group;
4986 updateMessage.OtherPrims = pc.Others;
4987 updateMessage.SelectedPrims = pc.Selected;
4988 updateMessage.TotalPrims = pc.Total;
4989 updateMessage.SimWideTotalPrims = pc.Simulator;
4990  
4991 try
4992 {
4993 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
4994 if (eq != null)
4995 {
4996 eq.ParcelProperties(updateMessage, this.AgentId);
4997 }
4998 else
4999 {
5000 m_log.Warn("[LLCLIENTVIEW]: No EQ Interface when sending parcel data.");
5001 }
5002 }
5003 catch (Exception ex)
5004 {
5005 m_log.Error("[LLCLIENTVIEW]: Unable to send parcel data via eventqueue - exception: " + ex.ToString());
5006 }
5007 }
5008  
5009 public void SendLandAccessListData(List<LandAccessEntry> accessList, uint accessFlag, int localLandID)
5010 {
5011 ParcelAccessListReplyPacket replyPacket = (ParcelAccessListReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelAccessListReply);
5012 replyPacket.Data.AgentID = AgentId;
5013 replyPacket.Data.Flags = accessFlag;
5014 replyPacket.Data.LocalID = localLandID;
5015 replyPacket.Data.SequenceID = 0;
5016  
5017 List<ParcelAccessListReplyPacket.ListBlock> list = new List<ParcelAccessListReplyPacket.ListBlock>();
5018 foreach (LandAccessEntry entry in accessList)
5019 {
5020 ParcelAccessListReplyPacket.ListBlock block = new ParcelAccessListReplyPacket.ListBlock();
5021 block.Flags = accessFlag;
5022 block.ID = entry.AgentID;
5023 block.Time = entry.Expires;
5024 list.Add(block);
5025 }
5026  
5027 replyPacket.List = list.ToArray();
5028 replyPacket.Header.Zerocoded = true;
5029 OutPacket(replyPacket, ThrottleOutPacketType.Task);
5030 }
5031  
5032 public void SendForceClientSelectObjects(List<uint> ObjectIDs)
5033 {
5034 // m_log.DebugFormat("[LLCLIENTVIEW] sending select with {0} objects", ObjectIDs.Count);
5035  
5036 bool firstCall = true;
5037 const int MAX_OBJECTS_PER_PACKET = 251;
5038 ForceObjectSelectPacket pack = (ForceObjectSelectPacket)PacketPool.Instance.GetPacket(PacketType.ForceObjectSelect);
5039 ForceObjectSelectPacket.DataBlock[] data;
5040 while (ObjectIDs.Count > 0)
5041 {
5042 if (firstCall)
5043 {
5044 pack._Header.ResetList = true;
5045 firstCall = false;
5046 }
5047 else
5048 {
5049 pack._Header.ResetList = false;
5050 }
5051  
5052 if (ObjectIDs.Count > MAX_OBJECTS_PER_PACKET)
5053 {
5054 data = new ForceObjectSelectPacket.DataBlock[MAX_OBJECTS_PER_PACKET];
5055 }
5056 else
5057 {
5058 data = new ForceObjectSelectPacket.DataBlock[ObjectIDs.Count];
5059 }
5060  
5061 int i;
5062 for (i = 0; i < MAX_OBJECTS_PER_PACKET && ObjectIDs.Count > 0; i++)
5063 {
5064 data[i] = new ForceObjectSelectPacket.DataBlock();
5065 data[i].LocalID = Convert.ToUInt32(ObjectIDs[0]);
5066 ObjectIDs.RemoveAt(0);
5067 }
5068 pack.Data = data;
5069 pack.Header.Zerocoded = true;
5070 OutPacket(pack, ThrottleOutPacketType.Task);
5071 }
5072 }
5073  
5074 public void SendCameraConstraint(Vector4 ConstraintPlane)
5075 {
5076 CameraConstraintPacket cpack = (CameraConstraintPacket)PacketPool.Instance.GetPacket(PacketType.CameraConstraint);
5077 cpack.CameraCollidePlane = new CameraConstraintPacket.CameraCollidePlaneBlock();
5078 cpack.CameraCollidePlane.Plane = ConstraintPlane;
5079 //m_log.DebugFormat("[CLIENTVIEW]: Constraint {0}", ConstraintPlane);
5080 OutPacket(cpack, ThrottleOutPacketType.Task);
5081 }
5082  
5083 public void SendLandObjectOwners(LandData land, List<UUID> groups, Dictionary<UUID, int> ownersAndCount)
5084 {
5085 int notifyCount = ownersAndCount.Count;
5086 ParcelObjectOwnersReplyPacket pack = (ParcelObjectOwnersReplyPacket)PacketPool.Instance.GetPacket(PacketType.ParcelObjectOwnersReply);
5087  
5088 if (notifyCount > 0)
5089 {
5090 if (notifyCount > 32)
5091 {
5092 m_log.InfoFormat(
5093 "[LAND]: More than {0} avatars own prims on this parcel. Only sending back details of first {0}"
5094 + " - a developer might want to investigate whether this is a hard limit", 32);
5095  
5096 notifyCount = 32;
5097 }
5098  
5099 ParcelObjectOwnersReplyPacket.DataBlock[] dataBlock
5100 = new ParcelObjectOwnersReplyPacket.DataBlock[notifyCount];
5101  
5102 int num = 0;
5103 foreach (UUID owner in ownersAndCount.Keys)
5104 {
5105 dataBlock[num] = new ParcelObjectOwnersReplyPacket.DataBlock();
5106 dataBlock[num].Count = ownersAndCount[owner];
5107  
5108 if (land.GroupID == owner || groups.Contains(owner))
5109 dataBlock[num].IsGroupOwned = true;
5110  
5111 dataBlock[num].OnlineStatus = true; //TODO: fix me later
5112 dataBlock[num].OwnerID = owner;
5113  
5114 num++;
5115  
5116 if (num >= notifyCount)
5117 {
5118 break;
5119 }
5120 }
5121  
5122 pack.Data = dataBlock;
5123 }
5124 else
5125 {
5126 pack.Data = new ParcelObjectOwnersReplyPacket.DataBlock[0];
5127 }
5128 pack.Header.Zerocoded = true;
5129 this.OutPacket(pack, ThrottleOutPacketType.Task);
5130 }
5131  
5132 #endregion
5133  
5134 #region Helper Methods
5135  
5136 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedTerseBlock(ISceneEntity entity, bool sendTexture)
5137 {
5138 #region ScenePresence/SOP Handling
5139  
5140 bool avatar = (entity is ScenePresence);
5141 uint localID = entity.LocalId;
5142 uint attachPoint;
5143 Vector4 collisionPlane;
5144 Vector3 position, velocity, acceleration, angularVelocity;
5145 Quaternion rotation;
5146 byte[] textureEntry;
5147  
5148 if (entity is ScenePresence)
5149 {
5150 ScenePresence presence = (ScenePresence)entity;
5151  
5152 // m_log.DebugFormat(
5153 // "[LLCLIENTVIEW]: Sending terse update to {0} with position {1} in {2}", Name, presence.OffsetPosition, m_scene.Name);
5154  
5155 attachPoint = presence.State;
5156 collisionPlane = presence.CollisionPlane;
5157 position = presence.OffsetPosition;
5158 velocity = presence.Velocity;
5159 acceleration = Vector3.Zero;
5160  
5161 // Interestingly, sending this to non-zero will cause the client's avatar to start moving & accelerating
5162 // in that direction, even though we don't model this on the server. Implementing this in the future
5163 // may improve movement smoothness.
5164 // acceleration = new Vector3(1, 0, 0);
5165  
5166 angularVelocity = presence.AngularVelocity;
5167  
5168 // Whilst not in mouselook, an avatar will transmit only the Z rotation as this is the only axis
5169 // it rotates around.
5170 // In mouselook, X and Y co-ordinate will also be sent but when used in Rotation, these cause unwanted
5171 // excessive up and down movements of the camera when looking up and down.
5172 // See http://opensimulator.org/mantis/view.php?id=3274
5173 // This does not affect head movement, since this is controlled entirely by camera movement rather than
5174 // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change
5175 // the rotation in this case.
5176 rotation = presence.Rotation;
5177  
5178 if (!presence.IsSatOnObject)
5179 {
5180 rotation.X = 0;
5181 rotation.Y = 0;
5182 }
5183  
5184 if (sendTexture)
5185 textureEntry = presence.Appearance.Texture.GetBytes();
5186 else
5187 textureEntry = null;
5188 }
5189 else
5190 {
5191 SceneObjectPart part = (SceneObjectPart)entity;
5192  
5193 attachPoint = part.ParentGroup.AttachmentPoint;
5194 attachPoint = ((attachPoint % 16) * 16 + (attachPoint / 16));
5195 // m_log.DebugFormat(
5196 // "[LLCLIENTVIEW]: Sending attachPoint {0} for {1} {2} to {3}",
5197 // attachPoint, part.Name, part.LocalId, Name);
5198  
5199 collisionPlane = Vector4.Zero;
5200 position = part.RelativePosition;
5201 velocity = part.Velocity;
5202 acceleration = part.Acceleration;
5203 angularVelocity = part.AngularVelocity;
5204 rotation = part.RotationOffset;
5205  
5206 if (sendTexture)
5207 textureEntry = part.Shape.TextureEntry;
5208 else
5209 textureEntry = null;
5210 }
5211  
5212 #endregion ScenePresence/SOP Handling
5213  
5214 int pos = 0;
5215 byte[] data = new byte[(avatar ? 60 : 44)];
5216  
5217 // LocalID
5218 Utils.UIntToBytes(localID, data, pos);
5219 pos += 4;
5220  
5221 // Avatar/CollisionPlane
5222 data[pos++] = (byte) attachPoint;
5223 if (avatar)
5224 {
5225 data[pos++] = 1;
5226  
5227 if (collisionPlane == Vector4.Zero)
5228 collisionPlane = Vector4.UnitW;
5229 //m_log.DebugFormat("CollisionPlane: {0}",collisionPlane);
5230 collisionPlane.ToBytes(data, pos);
5231 pos += 16;
5232 }
5233 else
5234 {
5235 ++pos;
5236 }
5237  
5238 // Position
5239 position.ToBytes(data, pos);
5240 pos += 12;
5241  
5242 // Velocity
5243 Utils.UInt16ToBytes(Utils.FloatToUInt16(velocity.X, -128.0f, 128.0f), data, pos); pos += 2;
5244 Utils.UInt16ToBytes(Utils.FloatToUInt16(velocity.Y, -128.0f, 128.0f), data, pos); pos += 2;
5245 Utils.UInt16ToBytes(Utils.FloatToUInt16(velocity.Z, -128.0f, 128.0f), data, pos); pos += 2;
5246  
5247 // Acceleration
5248 Utils.UInt16ToBytes(Utils.FloatToUInt16(acceleration.X, -64.0f, 64.0f), data, pos); pos += 2;
5249 Utils.UInt16ToBytes(Utils.FloatToUInt16(acceleration.Y, -64.0f, 64.0f), data, pos); pos += 2;
5250 Utils.UInt16ToBytes(Utils.FloatToUInt16(acceleration.Z, -64.0f, 64.0f), data, pos); pos += 2;
5251  
5252 // Rotation
5253 Utils.UInt16ToBytes(Utils.FloatToUInt16(rotation.X, -1.0f, 1.0f), data, pos); pos += 2;
5254 Utils.UInt16ToBytes(Utils.FloatToUInt16(rotation.Y, -1.0f, 1.0f), data, pos); pos += 2;
5255 Utils.UInt16ToBytes(Utils.FloatToUInt16(rotation.Z, -1.0f, 1.0f), data, pos); pos += 2;
5256 Utils.UInt16ToBytes(Utils.FloatToUInt16(rotation.W, -1.0f, 1.0f), data, pos); pos += 2;
5257  
5258 // Angular Velocity
5259 Utils.UInt16ToBytes(Utils.FloatToUInt16(angularVelocity.X, -64.0f, 64.0f), data, pos); pos += 2;
5260 Utils.UInt16ToBytes(Utils.FloatToUInt16(angularVelocity.Y, -64.0f, 64.0f), data, pos); pos += 2;
5261 Utils.UInt16ToBytes(Utils.FloatToUInt16(angularVelocity.Z, -64.0f, 64.0f), data, pos); pos += 2;
5262  
5263 ImprovedTerseObjectUpdatePacket.ObjectDataBlock block
5264 = PacketPool.Instance.GetDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
5265  
5266 block.Data = data;
5267  
5268 if (textureEntry != null && textureEntry.Length > 0)
5269 {
5270 byte[] teBytesFinal = new byte[textureEntry.Length + 4];
5271  
5272 // Texture Length
5273 Utils.IntToBytes(textureEntry.Length, textureEntry, 0);
5274 // Texture
5275 Buffer.BlockCopy(textureEntry, 0, teBytesFinal, 4, textureEntry.Length);
5276  
5277 block.TextureEntry = teBytesFinal;
5278 }
5279 else
5280 {
5281 block.TextureEntry = Utils.EmptyBytes;
5282 }
5283  
5284 return block;
5285 }
5286  
5287 protected ObjectUpdatePacket.ObjectDataBlock CreateAvatarUpdateBlock(ScenePresence data)
5288 {
5289 // m_log.DebugFormat(
5290 // "[LLCLIENTVIEW]: Sending full update to {0} with position {1} in {2}", Name, data.OffsetPosition, m_scene.Name);
5291  
5292 byte[] objectData = new byte[76];
5293  
5294 data.CollisionPlane.ToBytes(objectData, 0);
5295 data.OffsetPosition.ToBytes(objectData, 16);
5296 // data.Velocity.ToBytes(objectData, 28);
5297 // data.Acceleration.ToBytes(objectData, 40);
5298  
5299 // Whilst not in mouselook, an avatar will transmit only the Z rotation as this is the only axis
5300 // it rotates around.
5301 // In mouselook, X and Y co-ordinate will also be sent but when used in Rotation, these cause unwanted
5302 // excessive up and down movements of the camera when looking up and down.
5303 // See http://opensimulator.org/mantis/view.php?id=3274
5304 // This does not affect head movement, since this is controlled entirely by camera movement rather than
5305 // body rotation. We still need to transmit X and Y for sitting avatars but mouselook does not change
5306 // the rotation in this case.
5307 Quaternion rot = data.Rotation;
5308  
5309 if (!data.IsSatOnObject)
5310 {
5311 rot.X = 0;
5312 rot.Y = 0;
5313 }
5314  
5315 rot.ToBytes(objectData, 52);
5316 //data.AngularVelocity.ToBytes(objectData, 64);
5317  
5318 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
5319  
5320 update.Data = Utils.EmptyBytes;
5321 update.ExtraParams = new byte[1];
5322 update.FullID = data.UUID;
5323 update.ID = data.LocalId;
5324 update.Material = (byte)Material.Flesh;
5325 update.MediaURL = Utils.EmptyBytes;
5326 update.NameValue = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " +
5327 data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle);
5328 update.ObjectData = objectData;
5329  
5330 SceneObjectPart parentPart = data.ParentPart;
5331 if (parentPart != null)
5332 update.ParentID = parentPart.ParentGroup.LocalId;
5333 else
5334 update.ParentID = 0;
5335  
5336 update.PathCurve = 16;
5337 update.PathScaleX = 100;
5338 update.PathScaleY = 100;
5339 update.PCode = (byte)PCode.Avatar;
5340 update.ProfileCurve = 1;
5341 update.PSBlock = Utils.EmptyBytes;
5342 update.Scale = new Vector3(0.45f, 0.6f, 1.9f);
5343 update.Text = Utils.EmptyBytes;
5344 update.TextColor = new byte[4];
5345  
5346 // Don't send texture anim for avatars - this has no meaning for them.
5347 update.TextureAnim = Utils.EmptyBytes;
5348  
5349 // Don't send texture entry for avatars here - this is accomplished via the AvatarAppearance packet
5350 update.TextureEntry = Utils.EmptyBytes;
5351 // update.TextureEntry = (data.Appearance.Texture != null) ? data.Appearance.Texture.GetBytes() : Utils.EmptyBytes;
5352  
5353 update.UpdateFlags = (uint)(
5354 PrimFlags.Physics | PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner |
5355 PrimFlags.ObjectYouOwner | PrimFlags.ObjectMove | PrimFlags.InventoryEmpty | PrimFlags.ObjectTransfer |
5356 PrimFlags.ObjectOwnerModify);
5357  
5358 return update;
5359 }
5360  
5361 protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart data, UUID recipientID)
5362 {
5363 byte[] objectData = new byte[60];
5364 data.RelativePosition.ToBytes(objectData, 0);
5365 data.Velocity.ToBytes(objectData, 12);
5366 data.Acceleration.ToBytes(objectData, 24);
5367 try
5368 {
5369 data.RotationOffset.ToBytes(objectData, 36);
5370 }
5371 catch (Exception e)
5372 {
5373 m_log.Warn("[LLClientView]: exception converting quaternion to bytes, using Quaternion.Identity. Exception: " + e.ToString());
5374 OpenMetaverse.Quaternion.Identity.ToBytes(objectData, 36);
5375 }
5376 data.AngularVelocity.ToBytes(objectData, 48);
5377  
5378 ObjectUpdatePacket.ObjectDataBlock update = new ObjectUpdatePacket.ObjectDataBlock();
5379 update.ClickAction = (byte)data.ClickAction;
5380 update.CRC = 0;
5381 update.ExtraParams = data.Shape.ExtraParams ?? Utils.EmptyBytes;
5382 update.FullID = data.UUID;
5383 update.ID = data.LocalId;
5384 //update.JointAxisOrAnchor = Vector3.Zero; // These are deprecated
5385 //update.JointPivot = Vector3.Zero;
5386 //update.JointType = 0;
5387 update.Material = data.Material;
5388 update.MediaURL = Utils.EmptyBytes; // FIXME: Support this in OpenSim
5389  
5390 if (data.ParentGroup.IsAttachment)
5391 {
5392 update.NameValue
5393 = Util.StringToBytes256(
5394 string.Format("AttachItemID STRING RW SV {0}", data.ParentGroup.FromItemID));
5395  
5396 update.State = (byte)((data.ParentGroup.AttachmentPoint % 16) * 16 + (data.ParentGroup.AttachmentPoint / 16));
5397  
5398 // m_log.DebugFormat(
5399 // "[LLCLIENTVIEW]: Sending NameValue {0} for {1} {2} to {3}",
5400 // Util.UTF8.GetString(update.NameValue), data.Name, data.LocalId, Name);
5401 //
5402 // m_log.DebugFormat(
5403 // "[LLCLIENTVIEW]: Sending state {0} for {1} {2} to {3}",
5404 // update.State, data.Name, data.LocalId, Name);
5405 }
5406 else
5407 {
5408 update.NameValue = Utils.EmptyBytes;
5409  
5410 // The root part state is the canonical state for all parts of the object. The other part states in the
5411 // case for attachments may contain conflicting values that can end up crashing the viewer.
5412 update.State = data.ParentGroup.RootPart.Shape.State;
5413 }
5414  
5415 update.ObjectData = objectData;
5416 update.ParentID = data.ParentID;
5417 update.PathBegin = data.Shape.PathBegin;
5418 update.PathCurve = data.Shape.PathCurve;
5419 update.PathEnd = data.Shape.PathEnd;
5420 update.PathRadiusOffset = data.Shape.PathRadiusOffset;
5421 update.PathRevolutions = data.Shape.PathRevolutions;
5422 update.PathScaleX = data.Shape.PathScaleX;
5423 update.PathScaleY = data.Shape.PathScaleY;
5424 update.PathShearX = data.Shape.PathShearX;
5425 update.PathShearY = data.Shape.PathShearY;
5426 update.PathSkew = data.Shape.PathSkew;
5427 update.PathTaperX = data.Shape.PathTaperX;
5428 update.PathTaperY = data.Shape.PathTaperY;
5429 update.PathTwist = data.Shape.PathTwist;
5430 update.PathTwistBegin = data.Shape.PathTwistBegin;
5431 update.PCode = data.Shape.PCode;
5432 update.ProfileBegin = data.Shape.ProfileBegin;
5433 update.ProfileCurve = data.Shape.ProfileCurve;
5434 update.ProfileEnd = data.Shape.ProfileEnd;
5435 update.ProfileHollow = data.Shape.ProfileHollow;
5436 update.PSBlock = data.ParticleSystem ?? Utils.EmptyBytes;
5437 update.TextColor = data.GetTextColor().GetBytes(false);
5438 update.TextureAnim = data.TextureAnimation ?? Utils.EmptyBytes;
5439 update.TextureEntry = data.Shape.TextureEntry ?? Utils.EmptyBytes;
5440 update.Scale = data.Shape.Scale;
5441 update.Text = Util.StringToBytes256(data.Text);
5442 update.MediaURL = Util.StringToBytes256(data.MediaUrl);
5443  
5444 #region PrimFlags
5445  
5446 PrimFlags flags = (PrimFlags)m_scene.Permissions.GenerateClientFlags(recipientID, data.UUID);
5447  
5448 // Don't send the CreateSelected flag to everyone
5449 flags &= ~PrimFlags.CreateSelected;
5450  
5451 if (recipientID == data.OwnerID)
5452 {
5453 if (data.CreateSelected)
5454 {
5455 // Only send this flag once, then unset it
5456 flags |= PrimFlags.CreateSelected;
5457 data.CreateSelected = false;
5458 }
5459 }
5460  
5461 // m_log.DebugFormat(
5462 // "[LLCLIENTVIEW]: Constructing client update for part {0} {1} with flags {2}, localId {3}",
5463 // data.Name, update.FullID, flags, update.ID);
5464  
5465 update.UpdateFlags = (uint)flags;
5466  
5467 #endregion PrimFlags
5468  
5469 if (data.Sound != UUID.Zero)
5470 {
5471 update.Sound = data.Sound;
5472 update.OwnerID = data.OwnerID;
5473 update.Gain = (float)data.SoundGain;
5474 update.Radius = (float)data.SoundRadius;
5475 update.Flags = data.SoundFlags;
5476 }
5477  
5478 switch ((PCode)data.Shape.PCode)
5479 {
5480 case PCode.Grass:
5481 case PCode.Tree:
5482 case PCode.NewTree:
5483 update.Data = new byte[] { data.Shape.State };
5484 break;
5485 default:
5486 update.Data = Utils.EmptyBytes;
5487 break;
5488 }
5489  
5490 return update;
5491 }
5492  
5493 protected ObjectUpdateCompressedPacket.ObjectDataBlock CreateCompressedUpdateBlock(SceneObjectPart part, PrimUpdateFlags updateFlags)
5494 {
5495 // TODO: Implement this
5496 return null;
5497 }
5498  
5499 public void SendNameReply(UUID profileId, string firstname, string lastname)
5500 {
5501 UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
5502 // TODO: don't create new blocks if recycling an old packet
5503 packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
5504 packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
5505 packet.UUIDNameBlock[0].ID = profileId;
5506 packet.UUIDNameBlock[0].FirstName = Util.StringToBytes256(firstname);
5507 packet.UUIDNameBlock[0].LastName = Util.StringToBytes256(lastname);
5508  
5509 OutPacket(packet, ThrottleOutPacketType.Task);
5510 }
5511  
5512 public ulong GetGroupPowers(UUID groupID)
5513 {
5514 if (groupID == ActiveGroupId)
5515 return ActiveGroupPowers;
5516  
5517 if (m_groupPowers.ContainsKey(groupID))
5518 return m_groupPowers[groupID];
5519  
5520 return 0;
5521 }
5522  
5523 #endregion
5524  
5525 /// <summary>
5526 /// This is a different way of processing packets then ProcessInPacket
5527 /// </summary>
5528 protected virtual void RegisterLocalPacketHandlers()
5529 {
5530 AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
5531  
5532 // If AgentUpdate is ever handled asynchronously, then we will also need to construct a new AgentUpdateArgs
5533 // for each AgentUpdate packet.
5534 AddLocalPacketHandler(PacketType.AgentUpdate, HandleAgentUpdate, false);
5535  
5536 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect, false);
5537 AddLocalPacketHandler(PacketType.AgentCachedTexture, HandleAgentTextureCached, false);
5538 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, HandleMultipleObjUpdate, false);
5539 AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest, false);
5540 AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest, false);
5541 AddLocalPacketHandler(PacketType.UUIDGroupNameRequest, HandleUUIDGroupNameRequest);
5542 AddLocalPacketHandler(PacketType.ObjectGroup, HandleObjectGroupRequest);
5543 AddLocalPacketHandler(PacketType.GenericMessage, HandleGenericMessage);
5544 AddLocalPacketHandler(PacketType.AvatarPropertiesRequest, HandleAvatarPropertiesRequest);
5545 AddLocalPacketHandler(PacketType.ChatFromViewer, HandleChatFromViewer);
5546 AddLocalPacketHandler(PacketType.AvatarPropertiesUpdate, HandlerAvatarPropertiesUpdate);
5547 AddLocalPacketHandler(PacketType.ScriptDialogReply, HandlerScriptDialogReply);
5548 AddLocalPacketHandler(PacketType.ImprovedInstantMessage, HandlerImprovedInstantMessage);
5549 AddLocalPacketHandler(PacketType.AcceptFriendship, HandlerAcceptFriendship);
5550 AddLocalPacketHandler(PacketType.DeclineFriendship, HandlerDeclineFriendship);
5551 AddLocalPacketHandler(PacketType.TerminateFriendship, HandlerTerminateFriendship);
5552 AddLocalPacketHandler(PacketType.RezObject, HandlerRezObject);
5553 AddLocalPacketHandler(PacketType.DeRezObject, HandlerDeRezObject);
5554 AddLocalPacketHandler(PacketType.ModifyLand, HandlerModifyLand);
5555 AddLocalPacketHandler(PacketType.RegionHandshakeReply, HandlerRegionHandshakeReply, false);
5556 AddLocalPacketHandler(PacketType.AgentWearablesRequest, HandlerAgentWearablesRequest);
5557 AddLocalPacketHandler(PacketType.AgentSetAppearance, HandlerAgentSetAppearance);
5558 AddLocalPacketHandler(PacketType.AgentIsNowWearing, HandlerAgentIsNowWearing);
5559 AddLocalPacketHandler(PacketType.RezSingleAttachmentFromInv, HandlerRezSingleAttachmentFromInv);
5560 AddLocalPacketHandler(PacketType.RezMultipleAttachmentsFromInv, HandleRezMultipleAttachmentsFromInv);
5561 AddLocalPacketHandler(PacketType.DetachAttachmentIntoInv, HandleDetachAttachmentIntoInv);
5562 AddLocalPacketHandler(PacketType.ObjectAttach, HandleObjectAttach);
5563 AddLocalPacketHandler(PacketType.ObjectDetach, HandleObjectDetach);
5564 AddLocalPacketHandler(PacketType.ObjectDrop, HandleObjectDrop);
5565 AddLocalPacketHandler(PacketType.SetAlwaysRun, HandleSetAlwaysRun, false);
5566 AddLocalPacketHandler(PacketType.CompleteAgentMovement, HandleCompleteAgentMovement);
5567 AddLocalPacketHandler(PacketType.AgentAnimation, HandleAgentAnimation, false);
5568 AddLocalPacketHandler(PacketType.AgentRequestSit, HandleAgentRequestSit);
5569 AddLocalPacketHandler(PacketType.AgentSit, HandleAgentSit);
5570 AddLocalPacketHandler(PacketType.SoundTrigger, HandleSoundTrigger);
5571 AddLocalPacketHandler(PacketType.AvatarPickerRequest, HandleAvatarPickerRequest);
5572 AddLocalPacketHandler(PacketType.AgentDataUpdateRequest, HandleAgentDataUpdateRequest);
5573 AddLocalPacketHandler(PacketType.UserInfoRequest, HandleUserInfoRequest);
5574 AddLocalPacketHandler(PacketType.UpdateUserInfo, HandleUpdateUserInfo);
5575 AddLocalPacketHandler(PacketType.SetStartLocationRequest, HandleSetStartLocationRequest);
5576 AddLocalPacketHandler(PacketType.AgentThrottle, HandleAgentThrottle, false);
5577 AddLocalPacketHandler(PacketType.AgentPause, HandleAgentPause, false);
5578 AddLocalPacketHandler(PacketType.AgentResume, HandleAgentResume, false);
5579 AddLocalPacketHandler(PacketType.ForceScriptControlRelease, HandleForceScriptControlRelease);
5580 AddLocalPacketHandler(PacketType.ObjectLink, HandleObjectLink);
5581 AddLocalPacketHandler(PacketType.ObjectDelink, HandleObjectDelink);
5582 AddLocalPacketHandler(PacketType.ObjectAdd, HandleObjectAdd);
5583 AddLocalPacketHandler(PacketType.ObjectShape, HandleObjectShape);
5584 AddLocalPacketHandler(PacketType.ObjectExtraParams, HandleObjectExtraParams);
5585 AddLocalPacketHandler(PacketType.ObjectDuplicate, HandleObjectDuplicate);
5586 AddLocalPacketHandler(PacketType.RequestMultipleObjects, HandleRequestMultipleObjects);
5587 AddLocalPacketHandler(PacketType.ObjectSelect, HandleObjectSelect);
5588 AddLocalPacketHandler(PacketType.ObjectDeselect, HandleObjectDeselect);
5589 AddLocalPacketHandler(PacketType.ObjectPosition, HandleObjectPosition);
5590 AddLocalPacketHandler(PacketType.ObjectScale, HandleObjectScale);
5591 AddLocalPacketHandler(PacketType.ObjectRotation, HandleObjectRotation);
5592 AddLocalPacketHandler(PacketType.ObjectFlagUpdate, HandleObjectFlagUpdate);
5593  
5594 // Handle ObjectImage (TextureEntry) updates synchronously, since when updating multiple prim faces at once,
5595 // some clients will send out a separate ObjectImage packet for each face
5596 AddLocalPacketHandler(PacketType.ObjectImage, HandleObjectImage, false);
5597  
5598 AddLocalPacketHandler(PacketType.ObjectGrab, HandleObjectGrab, false);
5599 AddLocalPacketHandler(PacketType.ObjectGrabUpdate, HandleObjectGrabUpdate, false);
5600 AddLocalPacketHandler(PacketType.ObjectDeGrab, HandleObjectDeGrab);
5601 AddLocalPacketHandler(PacketType.ObjectSpinStart, HandleObjectSpinStart, false);
5602 AddLocalPacketHandler(PacketType.ObjectSpinUpdate, HandleObjectSpinUpdate, false);
5603 AddLocalPacketHandler(PacketType.ObjectSpinStop, HandleObjectSpinStop, false);
5604 AddLocalPacketHandler(PacketType.ObjectDescription, HandleObjectDescription, false);
5605 AddLocalPacketHandler(PacketType.ObjectName, HandleObjectName, false);
5606 AddLocalPacketHandler(PacketType.ObjectPermissions, HandleObjectPermissions, false);
5607 AddLocalPacketHandler(PacketType.Undo, HandleUndo, false);
5608 AddLocalPacketHandler(PacketType.UndoLand, HandleLandUndo, false);
5609 AddLocalPacketHandler(PacketType.Redo, HandleRedo, false);
5610 AddLocalPacketHandler(PacketType.ObjectDuplicateOnRay, HandleObjectDuplicateOnRay);
5611 AddLocalPacketHandler(PacketType.RequestObjectPropertiesFamily, HandleRequestObjectPropertiesFamily, false);
5612 AddLocalPacketHandler(PacketType.ObjectIncludeInSearch, HandleObjectIncludeInSearch);
5613 AddLocalPacketHandler(PacketType.ScriptAnswerYes, HandleScriptAnswerYes, false);
5614 AddLocalPacketHandler(PacketType.ObjectClickAction, HandleObjectClickAction, false);
5615 AddLocalPacketHandler(PacketType.ObjectMaterial, HandleObjectMaterial, false);
5616 AddLocalPacketHandler(PacketType.RequestImage, HandleRequestImage, false);
5617 AddLocalPacketHandler(PacketType.TransferRequest, HandleTransferRequest, false);
5618 AddLocalPacketHandler(PacketType.AssetUploadRequest, HandleAssetUploadRequest);
5619 AddLocalPacketHandler(PacketType.RequestXfer, HandleRequestXfer);
5620 AddLocalPacketHandler(PacketType.SendXferPacket, HandleSendXferPacket);
5621 AddLocalPacketHandler(PacketType.ConfirmXferPacket, HandleConfirmXferPacket);
5622 AddLocalPacketHandler(PacketType.AbortXfer, HandleAbortXfer);
5623 AddLocalPacketHandler(PacketType.CreateInventoryFolder, HandleCreateInventoryFolder);
5624 AddLocalPacketHandler(PacketType.UpdateInventoryFolder, HandleUpdateInventoryFolder);
5625 AddLocalPacketHandler(PacketType.MoveInventoryFolder, HandleMoveInventoryFolder);
5626 AddLocalPacketHandler(PacketType.CreateInventoryItem, HandleCreateInventoryItem);
5627 AddLocalPacketHandler(PacketType.LinkInventoryItem, HandleLinkInventoryItem);
5628 AddLocalPacketHandler(PacketType.FetchInventory, HandleFetchInventory);
5629 AddLocalPacketHandler(PacketType.FetchInventoryDescendents, HandleFetchInventoryDescendents);
5630 AddLocalPacketHandler(PacketType.PurgeInventoryDescendents, HandlePurgeInventoryDescendents);
5631 AddLocalPacketHandler(PacketType.UpdateInventoryItem, HandleUpdateInventoryItem);
5632 AddLocalPacketHandler(PacketType.CopyInventoryItem, HandleCopyInventoryItem);
5633 AddLocalPacketHandler(PacketType.MoveInventoryItem, HandleMoveInventoryItem);
5634 AddLocalPacketHandler(PacketType.RemoveInventoryItem, HandleRemoveInventoryItem);
5635 AddLocalPacketHandler(PacketType.RemoveInventoryFolder, HandleRemoveInventoryFolder);
5636 AddLocalPacketHandler(PacketType.RemoveInventoryObjects, HandleRemoveInventoryObjects);
5637 AddLocalPacketHandler(PacketType.RequestTaskInventory, HandleRequestTaskInventory);
5638 AddLocalPacketHandler(PacketType.UpdateTaskInventory, HandleUpdateTaskInventory);
5639 AddLocalPacketHandler(PacketType.RemoveTaskInventory, HandleRemoveTaskInventory);
5640 AddLocalPacketHandler(PacketType.MoveTaskInventory, HandleMoveTaskInventory);
5641 AddLocalPacketHandler(PacketType.RezScript, HandleRezScript);
5642 AddLocalPacketHandler(PacketType.MapLayerRequest, HandleMapLayerRequest);
5643 AddLocalPacketHandler(PacketType.MapBlockRequest, HandleMapBlockRequest);
5644 AddLocalPacketHandler(PacketType.MapNameRequest, HandleMapNameRequest);
5645 AddLocalPacketHandler(PacketType.TeleportLandmarkRequest, HandleTeleportLandmarkRequest);
5646 AddLocalPacketHandler(PacketType.TeleportCancel, HandleTeleportCancel);
5647 AddLocalPacketHandler(PacketType.TeleportLocationRequest, HandleTeleportLocationRequest);
5648 AddLocalPacketHandler(PacketType.UUIDNameRequest, HandleUUIDNameRequest, false);
5649 AddLocalPacketHandler(PacketType.RegionHandleRequest, HandleRegionHandleRequest, false);
5650 AddLocalPacketHandler(PacketType.ParcelInfoRequest, HandleParcelInfoRequest);
5651 AddLocalPacketHandler(PacketType.ParcelAccessListRequest, HandleParcelAccessListRequest, false);
5652 AddLocalPacketHandler(PacketType.ParcelAccessListUpdate, HandleParcelAccessListUpdate, false);
5653 AddLocalPacketHandler(PacketType.ParcelPropertiesRequest, HandleParcelPropertiesRequest, false);
5654 AddLocalPacketHandler(PacketType.ParcelDivide, HandleParcelDivide);
5655 AddLocalPacketHandler(PacketType.ParcelJoin, HandleParcelJoin);
5656 AddLocalPacketHandler(PacketType.ParcelPropertiesUpdate, HandleParcelPropertiesUpdate);
5657 AddLocalPacketHandler(PacketType.ParcelSelectObjects, HandleParcelSelectObjects);
5658 AddLocalPacketHandler(PacketType.ParcelObjectOwnersRequest, HandleParcelObjectOwnersRequest);
5659 AddLocalPacketHandler(PacketType.ParcelGodForceOwner, HandleParcelGodForceOwner);
5660 AddLocalPacketHandler(PacketType.ParcelRelease, HandleParcelRelease);
5661 AddLocalPacketHandler(PacketType.ParcelReclaim, HandleParcelReclaim);
5662 AddLocalPacketHandler(PacketType.ParcelReturnObjects, HandleParcelReturnObjects);
5663 AddLocalPacketHandler(PacketType.ParcelSetOtherCleanTime, HandleParcelSetOtherCleanTime);
5664 AddLocalPacketHandler(PacketType.LandStatRequest, HandleLandStatRequest);
5665 AddLocalPacketHandler(PacketType.ParcelDwellRequest, HandleParcelDwellRequest);
5666 AddLocalPacketHandler(PacketType.EstateOwnerMessage, HandleEstateOwnerMessage);
5667 AddLocalPacketHandler(PacketType.RequestRegionInfo, HandleRequestRegionInfo, false);
5668 AddLocalPacketHandler(PacketType.EstateCovenantRequest, HandleEstateCovenantRequest);
5669 AddLocalPacketHandler(PacketType.RequestGodlikePowers, HandleRequestGodlikePowers);
5670 AddLocalPacketHandler(PacketType.GodKickUser, HandleGodKickUser);
5671 AddLocalPacketHandler(PacketType.MoneyBalanceRequest, HandleMoneyBalanceRequest);
5672 AddLocalPacketHandler(PacketType.EconomyDataRequest, HandleEconomyDataRequest);
5673 AddLocalPacketHandler(PacketType.RequestPayPrice, HandleRequestPayPrice);
5674 AddLocalPacketHandler(PacketType.ObjectSaleInfo, HandleObjectSaleInfo);
5675 AddLocalPacketHandler(PacketType.ObjectBuy, HandleObjectBuy);
5676 AddLocalPacketHandler(PacketType.GetScriptRunning, HandleGetScriptRunning);
5677 AddLocalPacketHandler(PacketType.SetScriptRunning, HandleSetScriptRunning);
5678 AddLocalPacketHandler(PacketType.ScriptReset, HandleScriptReset);
5679 AddLocalPacketHandler(PacketType.ActivateGestures, HandleActivateGestures);
5680 AddLocalPacketHandler(PacketType.DeactivateGestures, HandleDeactivateGestures);
5681 AddLocalPacketHandler(PacketType.ObjectOwner, HandleObjectOwner);
5682 AddLocalPacketHandler(PacketType.AgentFOV, HandleAgentFOV, false);
5683 AddLocalPacketHandler(PacketType.ViewerStats, HandleViewerStats);
5684 AddLocalPacketHandler(PacketType.MapItemRequest, HandleMapItemRequest, false);
5685 AddLocalPacketHandler(PacketType.TransferAbort, HandleTransferAbort, false);
5686 AddLocalPacketHandler(PacketType.MuteListRequest, HandleMuteListRequest, false);
5687 AddLocalPacketHandler(PacketType.UseCircuitCode, HandleUseCircuitCode);
5688 AddLocalPacketHandler(PacketType.AgentHeightWidth, HandleAgentHeightWidth, false);
5689 AddLocalPacketHandler(PacketType.InventoryDescendents, HandleInventoryDescendents);
5690 AddLocalPacketHandler(PacketType.DirPlacesQuery, HandleDirPlacesQuery);
5691 AddLocalPacketHandler(PacketType.DirFindQuery, HandleDirFindQuery);
5692 AddLocalPacketHandler(PacketType.DirLandQuery, HandleDirLandQuery);
5693 AddLocalPacketHandler(PacketType.DirPopularQuery, HandleDirPopularQuery);
5694 AddLocalPacketHandler(PacketType.DirClassifiedQuery, HandleDirClassifiedQuery);
5695 AddLocalPacketHandler(PacketType.EventInfoRequest, HandleEventInfoRequest);
5696 AddLocalPacketHandler(PacketType.OfferCallingCard, HandleOfferCallingCard);
5697 AddLocalPacketHandler(PacketType.AcceptCallingCard, HandleAcceptCallingCard);
5698 AddLocalPacketHandler(PacketType.DeclineCallingCard, HandleDeclineCallingCard);
5699 AddLocalPacketHandler(PacketType.ActivateGroup, HandleActivateGroup);
5700 AddLocalPacketHandler(PacketType.GroupTitlesRequest, HandleGroupTitlesRequest);
5701 AddLocalPacketHandler(PacketType.GroupProfileRequest, HandleGroupProfileRequest);
5702 AddLocalPacketHandler(PacketType.GroupMembersRequest, HandleGroupMembersRequest);
5703 AddLocalPacketHandler(PacketType.GroupRoleDataRequest, HandleGroupRoleDataRequest);
5704 AddLocalPacketHandler(PacketType.GroupRoleMembersRequest, HandleGroupRoleMembersRequest);
5705 AddLocalPacketHandler(PacketType.CreateGroupRequest, HandleCreateGroupRequest);
5706 AddLocalPacketHandler(PacketType.UpdateGroupInfo, HandleUpdateGroupInfo);
5707 AddLocalPacketHandler(PacketType.SetGroupAcceptNotices, HandleSetGroupAcceptNotices);
5708 AddLocalPacketHandler(PacketType.GroupTitleUpdate, HandleGroupTitleUpdate);
5709 AddLocalPacketHandler(PacketType.ParcelDeedToGroup, HandleParcelDeedToGroup);
5710 AddLocalPacketHandler(PacketType.GroupNoticesListRequest, HandleGroupNoticesListRequest);
5711 AddLocalPacketHandler(PacketType.GroupNoticeRequest, HandleGroupNoticeRequest);
5712 AddLocalPacketHandler(PacketType.GroupRoleUpdate, HandleGroupRoleUpdate);
5713 AddLocalPacketHandler(PacketType.GroupRoleChanges, HandleGroupRoleChanges);
5714 AddLocalPacketHandler(PacketType.JoinGroupRequest, HandleJoinGroupRequest);
5715 AddLocalPacketHandler(PacketType.LeaveGroupRequest, HandleLeaveGroupRequest);
5716 AddLocalPacketHandler(PacketType.EjectGroupMemberRequest, HandleEjectGroupMemberRequest);
5717 AddLocalPacketHandler(PacketType.InviteGroupRequest, HandleInviteGroupRequest);
5718 AddLocalPacketHandler(PacketType.StartLure, HandleStartLure);
5719 AddLocalPacketHandler(PacketType.TeleportLureRequest, HandleTeleportLureRequest);
5720 AddLocalPacketHandler(PacketType.ClassifiedInfoRequest, HandleClassifiedInfoRequest);
5721 AddLocalPacketHandler(PacketType.ClassifiedInfoUpdate, HandleClassifiedInfoUpdate);
5722 AddLocalPacketHandler(PacketType.ClassifiedDelete, HandleClassifiedDelete);
5723 AddLocalPacketHandler(PacketType.ClassifiedGodDelete, HandleClassifiedGodDelete);
5724 AddLocalPacketHandler(PacketType.EventGodDelete, HandleEventGodDelete);
5725 AddLocalPacketHandler(PacketType.EventNotificationAddRequest, HandleEventNotificationAddRequest);
5726 AddLocalPacketHandler(PacketType.EventNotificationRemoveRequest, HandleEventNotificationRemoveRequest);
5727 AddLocalPacketHandler(PacketType.RetrieveInstantMessages, HandleRetrieveInstantMessages);
5728 AddLocalPacketHandler(PacketType.PickDelete, HandlePickDelete);
5729 AddLocalPacketHandler(PacketType.PickGodDelete, HandlePickGodDelete);
5730 AddLocalPacketHandler(PacketType.PickInfoUpdate, HandlePickInfoUpdate);
5731 AddLocalPacketHandler(PacketType.AvatarNotesUpdate, HandleAvatarNotesUpdate);
5732 AddLocalPacketHandler(PacketType.AvatarInterestsUpdate, HandleAvatarInterestsUpdate);
5733 AddLocalPacketHandler(PacketType.GrantUserRights, HandleGrantUserRights);
5734 AddLocalPacketHandler(PacketType.PlacesQuery, HandlePlacesQuery);
5735 AddLocalPacketHandler(PacketType.UpdateMuteListEntry, HandleUpdateMuteListEntry);
5736 AddLocalPacketHandler(PacketType.RemoveMuteListEntry, HandleRemoveMuteListEntry);
5737 AddLocalPacketHandler(PacketType.UserReport, HandleUserReport);
5738 AddLocalPacketHandler(PacketType.FindAgent, HandleFindAgent);
5739 AddLocalPacketHandler(PacketType.TrackAgent, HandleTrackAgent);
5740 AddLocalPacketHandler(PacketType.GodUpdateRegionInfo, HandleGodUpdateRegionInfoUpdate);
5741 AddLocalPacketHandler(PacketType.GodlikeMessage, HandleGodlikeMessage);
5742 AddLocalPacketHandler(PacketType.StateSave, HandleSaveStatePacket);
5743 AddLocalPacketHandler(PacketType.GroupAccountDetailsRequest, HandleGroupAccountDetailsRequest);
5744 AddLocalPacketHandler(PacketType.GroupAccountSummaryRequest, HandleGroupAccountSummaryRequest);
5745 AddLocalPacketHandler(PacketType.GroupAccountTransactionsRequest, HandleGroupTransactionsDetailsRequest);
5746 AddLocalPacketHandler(PacketType.FreezeUser, HandleFreezeUser);
5747 AddLocalPacketHandler(PacketType.EjectUser, HandleEjectUser);
5748 AddLocalPacketHandler(PacketType.ParcelBuyPass, HandleParcelBuyPass);
5749 AddLocalPacketHandler(PacketType.ParcelGodMarkAsContent, HandleParcelGodMarkAsContent);
5750 AddLocalPacketHandler(PacketType.GroupActiveProposalsRequest, HandleGroupActiveProposalsRequest);
5751 AddLocalPacketHandler(PacketType.GroupVoteHistoryRequest, HandleGroupVoteHistoryRequest);
5752 AddLocalPacketHandler(PacketType.SimWideDeletes, HandleSimWideDeletes);
5753 AddLocalPacketHandler(PacketType.SendPostcard, HandleSendPostcard);
5754  
5755 AddGenericPacketHandler("autopilot", HandleAutopilot);
5756 }
5757  
5758 #region Packet Handlers
5759  
5760 public int TotalAgentUpdates { get; set; }
5761  
5762 #region Scene/Avatar
5763  
5764 // Threshold for body rotation to be a significant agent update
5765 private const float QDELTA = 0.000001f;
5766 // Threshold for camera rotation to be a significant agent update
5767 private const float VDELTA = 0.01f;
5768  
5769 /// <summary>
5770 /// This checks the update significance against the last update made.
5771 /// </summary>
5772 /// <remarks>Can only be called by one thread at a time</remarks>
5773 /// <returns></returns>
5774 /// <param name='x'></param>
5775 public bool CheckAgentUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
5776 {
5777 return CheckAgentMovementUpdateSignificance(x) || CheckAgentCameraUpdateSignificance(x);
5778 }
5779  
5780 /// <summary>
5781 /// This checks the movement/state update significance against the last update made.
5782 /// </summary>
5783 /// <remarks>Can only be called by one thread at a time</remarks>
5784 /// <returns></returns>
5785 /// <param name='x'></param>
5786 private bool CheckAgentMovementUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
5787 {
5788 float qdelta1 = 1 - (float)Math.Pow(Quaternion.Dot(x.BodyRotation, m_thisAgentUpdateArgs.BodyRotation), 2);
5789 //qdelta2 = 1 - (float)Math.Pow(Quaternion.Dot(x.HeadRotation, m_thisAgentUpdateArgs.HeadRotation), 2);
5790  
5791 bool movementSignificant =
5792 (qdelta1 > QDELTA) // significant if body rotation above threshold
5793 // Ignoring head rotation altogether, because it's not being used for anything interesting up the stack
5794 // || (qdelta2 > QDELTA * 10) // significant if head rotation above threshold
5795 || (x.ControlFlags != m_thisAgentUpdateArgs.ControlFlags) // significant if control flags changed
5796 || (x.ControlFlags != (byte)AgentManager.ControlFlags.NONE) // significant if user supplying any movement update commands
5797 || (x.Far != m_thisAgentUpdateArgs.Far) // significant if far distance changed
5798 || (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
5799 || (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
5800 ;
5801 //if (movementSignificant)
5802 //{
5803 //m_log.DebugFormat("[LLCLIENTVIEW]: Bod {0} {1}",
5804 // qdelta1, qdelta2);
5805 //m_log.DebugFormat("[LLCLIENTVIEW]: St {0} {1} {2} {3}",
5806 // x.ControlFlags, x.Flags, x.Far, x.State);
5807 //}
5808 return movementSignificant;
5809 }
5810  
5811 /// <summary>
5812 /// This checks the camera update significance against the last update made.
5813 /// </summary>
5814 /// <remarks>Can only be called by one thread at a time</remarks>
5815 /// <returns></returns>
5816 /// <param name='x'></param>
5817 private bool CheckAgentCameraUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
5818 {
5819 float vdelta1 = Vector3.Distance(x.CameraAtAxis, m_thisAgentUpdateArgs.CameraAtAxis);
5820 float vdelta2 = Vector3.Distance(x.CameraCenter, m_thisAgentUpdateArgs.CameraCenter);
5821 float vdelta3 = Vector3.Distance(x.CameraLeftAxis, m_thisAgentUpdateArgs.CameraLeftAxis);
5822 float vdelta4 = Vector3.Distance(x.CameraUpAxis, m_thisAgentUpdateArgs.CameraUpAxis);
5823  
5824 bool cameraSignificant =
5825 (vdelta1 > VDELTA) ||
5826 (vdelta2 > VDELTA) ||
5827 (vdelta3 > VDELTA) ||
5828 (vdelta4 > VDELTA)
5829 ;
5830  
5831 //if (cameraSignificant)
5832 //{
5833 //m_log.DebugFormat("[LLCLIENTVIEW]: Cam1 {0} {1}",
5834 // x.CameraAtAxis, x.CameraCenter);
5835 //m_log.DebugFormat("[LLCLIENTVIEW]: Cam2 {0} {1}",
5836 // x.CameraLeftAxis, x.CameraUpAxis);
5837 //}
5838  
5839 return cameraSignificant;
5840 }
5841  
5842 private bool HandleAgentUpdate(IClientAPI sener, Packet packet)
5843 {
5844 // We got here, which means that something in agent update was significant
5845  
5846 AgentUpdatePacket agentUpdate = (AgentUpdatePacket)packet;
5847 AgentUpdatePacket.AgentDataBlock x = agentUpdate.AgentData;
5848  
5849 if (x.AgentID != AgentId || x.SessionID != SessionId)
5850 return false;
5851  
5852 // Before we update the current m_thisAgentUpdateArgs, let's check this again
5853 // to see what exactly changed
5854 bool movement = CheckAgentMovementUpdateSignificance(x);
5855 bool camera = CheckAgentCameraUpdateSignificance(x);
5856  
5857 m_thisAgentUpdateArgs.AgentID = x.AgentID;
5858 m_thisAgentUpdateArgs.BodyRotation = x.BodyRotation;
5859 m_thisAgentUpdateArgs.CameraAtAxis = x.CameraAtAxis;
5860 m_thisAgentUpdateArgs.CameraCenter = x.CameraCenter;
5861 m_thisAgentUpdateArgs.CameraLeftAxis = x.CameraLeftAxis;
5862 m_thisAgentUpdateArgs.CameraUpAxis = x.CameraUpAxis;
5863 m_thisAgentUpdateArgs.ControlFlags = x.ControlFlags;
5864 m_thisAgentUpdateArgs.Far = x.Far;
5865 m_thisAgentUpdateArgs.Flags = x.Flags;
5866 m_thisAgentUpdateArgs.HeadRotation = x.HeadRotation;
5867 m_thisAgentUpdateArgs.SessionID = x.SessionID;
5868 m_thisAgentUpdateArgs.State = x.State;
5869  
5870 UpdateAgent handlerAgentUpdate = OnAgentUpdate;
5871 UpdateAgent handlerPreAgentUpdate = OnPreAgentUpdate;
5872 UpdateAgent handlerAgentCameraUpdate = OnAgentCameraUpdate;
5873  
5874 // Was there a significant movement/state change?
5875 if (movement)
5876 {
5877 if (handlerPreAgentUpdate != null)
5878 OnPreAgentUpdate(this, m_thisAgentUpdateArgs);
5879  
5880 if (handlerAgentUpdate != null)
5881 OnAgentUpdate(this, m_thisAgentUpdateArgs);
5882 }
5883 // Was there a significant camera(s) change?
5884 if (camera)
5885 if (handlerAgentCameraUpdate != null)
5886 handlerAgentCameraUpdate(this, m_thisAgentUpdateArgs);
5887  
5888 handlerAgentUpdate = null;
5889 handlerPreAgentUpdate = null;
5890 handlerAgentCameraUpdate = null;
5891  
5892 PacketPool.Instance.ReturnPacket(packet);
5893  
5894 return true;
5895 }
5896  
5897 private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
5898 {
5899 MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
5900 // validate the agent owns the agentID and sessionID
5901 if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId &&
5902 money.AgentData.SessionID == sender.SessionId)
5903 {
5904 MoneyTransferRequest handlerMoneyTransferRequest = OnMoneyTransferRequest;
5905 if (handlerMoneyTransferRequest != null)
5906 {
5907 handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
5908 money.MoneyData.Amount, money.MoneyData.TransactionType,
5909 Util.FieldToString(money.MoneyData.Description));
5910 }
5911  
5912 return true;
5913 }
5914  
5915 return false;
5916 }
5917  
5918 private bool HandleParcelGodMarkAsContent(IClientAPI client, Packet Packet)
5919 {
5920 ParcelGodMarkAsContentPacket ParcelGodMarkAsContent =
5921 (ParcelGodMarkAsContentPacket)Packet;
5922  
5923 ParcelGodMark ParcelGodMarkAsContentHandler = OnParcelGodMark;
5924 if (ParcelGodMarkAsContentHandler != null)
5925 {
5926 ParcelGodMarkAsContentHandler(this,
5927 ParcelGodMarkAsContent.AgentData.AgentID,
5928 ParcelGodMarkAsContent.ParcelData.LocalID);
5929 return true;
5930 }
5931 return false;
5932 }
5933  
5934 private bool HandleFreezeUser(IClientAPI client, Packet Packet)
5935 {
5936 FreezeUserPacket FreezeUser = (FreezeUserPacket)Packet;
5937  
5938 FreezeUserUpdate FreezeUserHandler = OnParcelFreezeUser;
5939 if (FreezeUserHandler != null)
5940 {
5941 FreezeUserHandler(this,
5942 FreezeUser.AgentData.AgentID,
5943 FreezeUser.Data.Flags,
5944 FreezeUser.Data.TargetID);
5945 return true;
5946 }
5947 return false;
5948 }
5949  
5950 private bool HandleEjectUser(IClientAPI client, Packet Packet)
5951 {
5952 EjectUserPacket EjectUser =
5953 (EjectUserPacket)Packet;
5954  
5955 EjectUserUpdate EjectUserHandler = OnParcelEjectUser;
5956 if (EjectUserHandler != null)
5957 {
5958 EjectUserHandler(this,
5959 EjectUser.AgentData.AgentID,
5960 EjectUser.Data.Flags,
5961 EjectUser.Data.TargetID);
5962 return true;
5963 }
5964 return false;
5965 }
5966  
5967 private bool HandleParcelBuyPass(IClientAPI client, Packet Packet)
5968 {
5969 ParcelBuyPassPacket ParcelBuyPass =
5970 (ParcelBuyPassPacket)Packet;
5971  
5972 ParcelBuyPass ParcelBuyPassHandler = OnParcelBuyPass;
5973 if (ParcelBuyPassHandler != null)
5974 {
5975 ParcelBuyPassHandler(this,
5976 ParcelBuyPass.AgentData.AgentID,
5977 ParcelBuyPass.ParcelData.LocalID);
5978 return true;
5979 }
5980 return false;
5981 }
5982  
5983 private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
5984 {
5985 ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
5986 if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == SessionId)
5987 {
5988 ParcelBuy handlerParcelBuy = OnParcelBuy;
5989 if (handlerParcelBuy != null)
5990 {
5991 handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final,
5992 parcel.Data.IsGroupOwned,
5993 parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area,
5994 parcel.ParcelData.Price,
5995 false);
5996 }
5997 return true;
5998 }
5999 return false;
6000 }
6001  
6002 private bool HandleUUIDGroupNameRequest(IClientAPI sender, Packet Pack)
6003 {
6004 UUIDGroupNameRequestPacket upack = (UUIDGroupNameRequestPacket)Pack;
6005  
6006  
6007 for (int i = 0; i < upack.UUIDNameBlock.Length; i++)
6008 {
6009 UUIDNameRequest handlerUUIDGroupNameRequest = OnUUIDGroupNameRequest;
6010 if (handlerUUIDGroupNameRequest != null)
6011 {
6012 handlerUUIDGroupNameRequest(upack.UUIDNameBlock[i].ID, this);
6013 }
6014 }
6015  
6016 return true;
6017 }
6018  
6019 public bool HandleGenericMessage(IClientAPI sender, Packet pack)
6020 {
6021 GenericMessagePacket gmpack = (GenericMessagePacket)pack;
6022 if (m_genericPacketHandlers.Count == 0) return false;
6023 if (gmpack.AgentData.SessionID != SessionId) return false;
6024  
6025 GenericMessage handlerGenericMessage = null;
6026  
6027 string method = Util.FieldToString(gmpack.MethodData.Method).ToLower().Trim();
6028  
6029 if (m_genericPacketHandlers.TryGetValue(method, out handlerGenericMessage))
6030 {
6031 List<string> msg = new List<string>();
6032 List<byte[]> msgBytes = new List<byte[]>();
6033  
6034 if (handlerGenericMessage != null)
6035 {
6036 foreach (GenericMessagePacket.ParamListBlock block in gmpack.ParamList)
6037 {
6038 msg.Add(Util.FieldToString(block.Parameter));
6039 msgBytes.Add(block.Parameter);
6040 }
6041 try
6042 {
6043 if (OnBinaryGenericMessage != null)
6044 {
6045 OnBinaryGenericMessage(this, method, msgBytes.ToArray());
6046 }
6047 handlerGenericMessage(sender, method, msg);
6048 return true;
6049 }
6050 catch (Exception e)
6051 {
6052 m_log.ErrorFormat(
6053 "[LLCLIENTVIEW]: Exeception when handling generic message {0}{1}", e.Message, e.StackTrace);
6054 }
6055 }
6056 }
6057  
6058 //m_log.Debug("[LLCLIENTVIEW]: Not handling GenericMessage with method-type of: " + method);
6059 return false;
6060 }
6061  
6062 public bool HandleObjectGroupRequest(IClientAPI sender, Packet Pack)
6063 {
6064 ObjectGroupPacket ogpack = (ObjectGroupPacket)Pack;
6065 if (ogpack.AgentData.SessionID != SessionId) return false;
6066  
6067 RequestObjectPropertiesFamily handlerObjectGroupRequest = OnObjectGroupRequest;
6068 if (handlerObjectGroupRequest != null)
6069 {
6070 for (int i = 0; i < ogpack.ObjectData.Length; i++)
6071 {
6072 handlerObjectGroupRequest(this, ogpack.AgentData.GroupID, ogpack.ObjectData[i].ObjectLocalID, UUID.Zero);
6073 }
6074 }
6075 return true;
6076 }
6077  
6078 private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
6079 {
6080 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
6081 if (viewer.AgentData.SessionID != SessionId) return false;
6082 ViewerEffectEventHandler handlerViewerEffect = OnViewerEffect;
6083 if (handlerViewerEffect != null)
6084 {
6085 int length = viewer.Effect.Length;
6086 List<ViewerEffectEventHandlerArg> args = new List<ViewerEffectEventHandlerArg>(length);
6087 for (int i = 0; i < length; i++)
6088 {
6089 //copy the effects block arguments into the event handler arg.
6090 ViewerEffectEventHandlerArg argument = new ViewerEffectEventHandlerArg();
6091 argument.AgentID = viewer.Effect[i].AgentID;
6092 argument.Color = viewer.Effect[i].Color;
6093 argument.Duration = viewer.Effect[i].Duration;
6094 argument.ID = viewer.Effect[i].ID;
6095 argument.Type = viewer.Effect[i].Type;
6096 argument.TypeData = viewer.Effect[i].TypeData;
6097 args.Add(argument);
6098 }
6099  
6100 handlerViewerEffect(sender, args);
6101 }
6102  
6103 return true;
6104 }
6105  
6106 private bool HandleAvatarPropertiesRequest(IClientAPI sender, Packet Pack)
6107 {
6108 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
6109  
6110 #region Packet Session and User Check
6111 if (m_checkPackets)
6112 {
6113 if (avatarProperties.AgentData.SessionID != SessionId ||
6114 avatarProperties.AgentData.AgentID != AgentId)
6115 return true;
6116 }
6117 #endregion
6118  
6119 RequestAvatarProperties handlerRequestAvatarProperties = OnRequestAvatarProperties;
6120 if (handlerRequestAvatarProperties != null)
6121 {
6122 handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
6123 }
6124 return true;
6125 }
6126  
6127 private bool HandleChatFromViewer(IClientAPI sender, Packet Pack)
6128 {
6129 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
6130  
6131 #region Packet Session and User Check
6132 if (m_checkPackets)
6133 {
6134 if (inchatpack.AgentData.SessionID != SessionId ||
6135 inchatpack.AgentData.AgentID != AgentId)
6136 return true;
6137 }
6138 #endregion
6139  
6140 string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
6141 byte[] message = inchatpack.ChatData.Message;
6142 byte type = inchatpack.ChatData.Type;
6143 Vector3 fromPos = new Vector3(); // ClientAvatar.Pos;
6144 // UUID fromAgentID = AgentId;
6145  
6146 int channel = inchatpack.ChatData.Channel;
6147  
6148 if (OnChatFromClient != null)
6149 {
6150 OSChatMessage args = new OSChatMessage();
6151 args.Channel = channel;
6152 args.From = fromName;
6153 args.Message = Utils.BytesToString(message);
6154 args.Type = (ChatTypeEnum)type;
6155 args.Position = fromPos;
6156  
6157 args.Scene = Scene;
6158 args.Sender = this;
6159 args.SenderUUID = this.AgentId;
6160  
6161 ChatMessage handlerChatFromClient = OnChatFromClient;
6162 if (handlerChatFromClient != null)
6163 handlerChatFromClient(this, args);
6164 }
6165 return true;
6166 }
6167  
6168 private bool HandlerAvatarPropertiesUpdate(IClientAPI sender, Packet Pack)
6169 {
6170 AvatarPropertiesUpdatePacket avatarProps = (AvatarPropertiesUpdatePacket)Pack;
6171  
6172 #region Packet Session and User Check
6173 if (m_checkPackets)
6174 {
6175 if (avatarProps.AgentData.SessionID != SessionId ||
6176 avatarProps.AgentData.AgentID != AgentId)
6177 return true;
6178 }
6179 #endregion
6180  
6181 UpdateAvatarProperties handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
6182 if (handlerUpdateAvatarProperties != null)
6183 {
6184 AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = avatarProps.PropertiesData;
6185 UserProfileData UserProfile = new UserProfileData();
6186 UserProfile.ID = AgentId;
6187 UserProfile.AboutText = Utils.BytesToString(Properties.AboutText);
6188 UserProfile.FirstLifeAboutText = Utils.BytesToString(Properties.FLAboutText);
6189 UserProfile.FirstLifeImage = Properties.FLImageID;
6190 UserProfile.Image = Properties.ImageID;
6191 UserProfile.ProfileUrl = Utils.BytesToString(Properties.ProfileURL);
6192 UserProfile.UserFlags &= ~3;
6193 UserProfile.UserFlags |= Properties.AllowPublish ? 1 : 0;
6194 UserProfile.UserFlags |= Properties.MaturePublish ? 2 : 0;
6195  
6196 handlerUpdateAvatarProperties(this, UserProfile);
6197 }
6198 return true;
6199 }
6200  
6201 private bool HandlerScriptDialogReply(IClientAPI sender, Packet Pack)
6202 {
6203 ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
6204  
6205 //m_log.DebugFormat("[CLIENT]: Received ScriptDialogReply from {0}", rdialog.Data.ObjectID);
6206  
6207 #region Packet Session and User Check
6208 if (m_checkPackets)
6209 {
6210 if (rdialog.AgentData.SessionID != SessionId ||
6211 rdialog.AgentData.AgentID != AgentId)
6212 return true;
6213 }
6214 #endregion
6215  
6216 int ch = rdialog.Data.ChatChannel;
6217 byte[] msg = rdialog.Data.ButtonLabel;
6218 if (OnChatFromClient != null)
6219 {
6220 OSChatMessage args = new OSChatMessage();
6221 args.Channel = ch;
6222 args.From = String.Empty;
6223 args.Message = Utils.BytesToString(msg);
6224 args.Type = ChatTypeEnum.Region; //Behaviour in SL is that the response can be heard from any distance
6225 args.Position = new Vector3();
6226 args.Scene = Scene;
6227 args.Sender = this;
6228 ChatMessage handlerChatFromClient2 = OnChatFromClient;
6229 if (handlerChatFromClient2 != null)
6230 handlerChatFromClient2(this, args);
6231 }
6232  
6233 return true;
6234 }
6235  
6236 private bool HandlerImprovedInstantMessage(IClientAPI sender, Packet Pack)
6237 {
6238 ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
6239  
6240 #region Packet Session and User Check
6241 if (m_checkPackets)
6242 {
6243 if (msgpack.AgentData.SessionID != SessionId ||
6244 msgpack.AgentData.AgentID != AgentId)
6245 return true;
6246 }
6247 #endregion
6248  
6249 string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
6250 string IMmessage = Utils.BytesToString(msgpack.MessageBlock.Message);
6251 ImprovedInstantMessage handlerInstantMessage = OnInstantMessage;
6252  
6253 if (handlerInstantMessage != null)
6254 {
6255 GridInstantMessage im = new GridInstantMessage(Scene,
6256 msgpack.AgentData.AgentID,
6257 IMfromName,
6258 msgpack.MessageBlock.ToAgentID,
6259 msgpack.MessageBlock.Dialog,
6260 msgpack.MessageBlock.FromGroup,
6261 IMmessage,
6262 msgpack.MessageBlock.ID,
6263 msgpack.MessageBlock.Offline != 0 ? true : false,
6264 msgpack.MessageBlock.Position,
6265 msgpack.MessageBlock.BinaryBucket,
6266 true);
6267  
6268 handlerInstantMessage(this, im);
6269 }
6270 return true;
6271  
6272 }
6273  
6274 private bool HandlerAcceptFriendship(IClientAPI sender, Packet Pack)
6275 {
6276 AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
6277  
6278 #region Packet Session and User Check
6279 if (m_checkPackets)
6280 {
6281 if (afriendpack.AgentData.SessionID != SessionId ||
6282 afriendpack.AgentData.AgentID != AgentId)
6283 return true;
6284 }
6285 #endregion
6286  
6287 // My guess is this is the folder to stick the calling card into
6288 List<UUID> callingCardFolders = new List<UUID>();
6289  
6290 UUID transactionID = afriendpack.TransactionBlock.TransactionID;
6291  
6292 for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
6293 {
6294 callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
6295 }
6296  
6297 FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest;
6298 if (handlerApproveFriendRequest != null)
6299 {
6300 handlerApproveFriendRequest(this, transactionID, callingCardFolders);
6301 }
6302  
6303 return true;
6304 }
6305  
6306 private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack)
6307 {
6308 DeclineFriendshipPacket dfriendpack = (DeclineFriendshipPacket)Pack;
6309  
6310 #region Packet Session and User Check
6311 if (m_checkPackets)
6312 {
6313 if (dfriendpack.AgentData.SessionID != SessionId ||
6314 dfriendpack.AgentData.AgentID != AgentId)
6315 return true;
6316 }
6317 #endregion
6318  
6319 if (OnDenyFriendRequest != null)
6320 {
6321 OnDenyFriendRequest(this,
6322 dfriendpack.TransactionBlock.TransactionID,
6323 null);
6324 }
6325 return true;
6326 }
6327  
6328 private bool HandlerTerminateFriendship(IClientAPI sender, Packet Pack)
6329 {
6330 TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
6331  
6332 #region Packet Session and User Check
6333 if (m_checkPackets)
6334 {
6335 if (tfriendpack.AgentData.SessionID != SessionId ||
6336 tfriendpack.AgentData.AgentID != AgentId)
6337 return true;
6338 }
6339 #endregion
6340  
6341 UUID exFriendID = tfriendpack.ExBlock.OtherID;
6342 FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship;
6343 if (TerminateFriendshipHandler != null)
6344 {
6345 TerminateFriendshipHandler(this, exFriendID);
6346 return true;
6347 }
6348  
6349 return false;
6350 }
6351  
6352 private bool HandleFindAgent(IClientAPI client, Packet Packet)
6353 {
6354 FindAgentPacket FindAgent =
6355 (FindAgentPacket)Packet;
6356  
6357 FindAgentUpdate FindAgentHandler = OnFindAgent;
6358 if (FindAgentHandler != null)
6359 {
6360 FindAgentHandler(this,FindAgent.AgentBlock.Hunter,FindAgent.AgentBlock.Prey);
6361 return true;
6362 }
6363 return false;
6364 }
6365  
6366 private bool HandleTrackAgent(IClientAPI client, Packet Packet)
6367 {
6368 TrackAgentPacket TrackAgent =
6369 (TrackAgentPacket)Packet;
6370  
6371 TrackAgentUpdate TrackAgentHandler = OnTrackAgent;
6372 if (TrackAgentHandler != null)
6373 {
6374 TrackAgentHandler(this,
6375 TrackAgent.AgentData.AgentID,
6376 TrackAgent.TargetData.PreyID);
6377 return true;
6378 }
6379 return false;
6380 }
6381  
6382 private bool HandlerRezObject(IClientAPI sender, Packet Pack)
6383 {
6384 RezObjectPacket rezPacket = (RezObjectPacket)Pack;
6385  
6386 #region Packet Session and User Check
6387 if (m_checkPackets)
6388 {
6389 if (rezPacket.AgentData.SessionID != SessionId ||
6390 rezPacket.AgentData.AgentID != AgentId)
6391 return true;
6392 }
6393 #endregion
6394  
6395 RezObject handlerRezObject = OnRezObject;
6396 if (handlerRezObject != null)
6397 {
6398 handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
6399 rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
6400 rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
6401 rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
6402 rezPacket.RezData.FromTaskID);
6403 }
6404 return true;
6405 }
6406  
6407 private bool HandlerDeRezObject(IClientAPI sender, Packet Pack)
6408 {
6409 DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)Pack;
6410  
6411 #region Packet Session and User Check
6412 if (m_checkPackets)
6413 {
6414 if (DeRezPacket.AgentData.SessionID != SessionId ||
6415 DeRezPacket.AgentData.AgentID != AgentId)
6416 return true;
6417 }
6418 #endregion
6419  
6420 DeRezObject handlerDeRezObject = OnDeRezObject;
6421 if (handlerDeRezObject != null)
6422 {
6423 List<uint> deRezIDs = new List<uint>();
6424  
6425 foreach (DeRezObjectPacket.ObjectDataBlock data in
6426 DeRezPacket.ObjectData)
6427 {
6428 deRezIDs.Add(data.ObjectLocalID);
6429 }
6430 // It just so happens that the values on the DeRezAction enumerator match the Destination
6431 // values given by a Second Life client
6432 handlerDeRezObject(this, deRezIDs,
6433 DeRezPacket.AgentBlock.GroupID,
6434 (DeRezAction)DeRezPacket.AgentBlock.Destination,
6435 DeRezPacket.AgentBlock.DestinationID);
6436  
6437 }
6438 return true;
6439 }
6440  
6441 private bool HandlerModifyLand(IClientAPI sender, Packet Pack)
6442 {
6443 ModifyLandPacket modify = (ModifyLandPacket)Pack;
6444  
6445 #region Packet Session and User Check
6446 if (m_checkPackets)
6447 {
6448 if (modify.AgentData.SessionID != SessionId ||
6449 modify.AgentData.AgentID != AgentId)
6450 return true;
6451 }
6452  
6453 #endregion
6454 //m_log.Info("[LAND]: LAND:" + modify.ToString());
6455 if (modify.ParcelData.Length > 0)
6456 {
6457 // Note: the ModifyTerrain event handler sends out updated packets before the end of this event. Therefore,
6458 // a simple boolean value should work and perhaps queue up just a few terrain patch packets at the end of the edit.
6459 m_justEditedTerrain = true; // Prevent terrain packet (Land layer) from being queued, make it unreliable
6460 if (OnModifyTerrain != null)
6461 {
6462 for (int i = 0; i < modify.ParcelData.Length; i++)
6463 {
6464 ModifyTerrain handlerModifyTerrain = OnModifyTerrain;
6465 if (handlerModifyTerrain != null)
6466 {
6467 handlerModifyTerrain(AgentId, modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
6468 modify.ModifyBlock.BrushSize,
6469 modify.ModifyBlock.Action, modify.ParcelData[i].North,
6470 modify.ParcelData[i].West, modify.ParcelData[i].South,
6471 modify.ParcelData[i].East, AgentId);
6472 }
6473 }
6474 }
6475 m_justEditedTerrain = false; // Queue terrain packet (Land layer) if necessary, make it reliable again
6476 }
6477  
6478 return true;
6479 }
6480  
6481 private bool HandlerRegionHandshakeReply(IClientAPI sender, Packet Pack)
6482 {
6483 Action<IClientAPI> handlerRegionHandShakeReply = OnRegionHandShakeReply;
6484 if (handlerRegionHandShakeReply != null)
6485 {
6486 handlerRegionHandShakeReply(this);
6487 }
6488  
6489 return true;
6490 }
6491  
6492 private bool HandlerAgentWearablesRequest(IClientAPI sender, Packet Pack)
6493 {
6494 GenericCall1 handlerRequestWearables = OnRequestWearables;
6495  
6496 if (handlerRequestWearables != null)
6497 {
6498 handlerRequestWearables(sender);
6499 }
6500  
6501 Action<IClientAPI> handlerRequestAvatarsData = OnRequestAvatarsData;
6502  
6503 if (handlerRequestAvatarsData != null)
6504 {
6505 handlerRequestAvatarsData(this);
6506 }
6507  
6508 return true;
6509 }
6510  
6511 private bool HandlerAgentSetAppearance(IClientAPI sender, Packet Pack)
6512 {
6513 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
6514  
6515 #region Packet Session and User Check
6516 if (m_checkPackets)
6517 {
6518 if (appear.AgentData.SessionID != SessionId ||
6519 appear.AgentData.AgentID != AgentId)
6520 return true;
6521 }
6522 #endregion
6523  
6524 SetAppearance handlerSetAppearance = OnSetAppearance;
6525 if (handlerSetAppearance != null)
6526 {
6527 // Temporarily protect ourselves from the mantis #951 failure.
6528 // However, we could do this for several other handlers where a failure isn't terminal
6529 // for the client session anyway, in order to protect ourselves against bad code in plugins
6530 Vector3 avSize = appear.AgentData.Size;
6531 try
6532 {
6533 byte[] visualparams = new byte[appear.VisualParam.Length];
6534 for (int i = 0; i < appear.VisualParam.Length; i++)
6535 visualparams[i] = appear.VisualParam[i].ParamValue;
6536 //var b = appear.WearableData[0];
6537  
6538 Primitive.TextureEntry te = null;
6539 if (appear.ObjectData.TextureEntry.Length > 1)
6540 te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length);
6541  
6542 WearableCacheItem[] cacheitems = new WearableCacheItem[appear.WearableData.Length];
6543 for (int i=0; i<appear.WearableData.Length;i++)
6544 cacheitems[i] = new WearableCacheItem(){CacheId = appear.WearableData[i].CacheID,TextureIndex=Convert.ToUInt32(appear.WearableData[i].TextureIndex)};
6545  
6546  
6547  
6548 handlerSetAppearance(sender, te, visualparams,avSize, cacheitems);
6549 }
6550 catch (Exception e)
6551 {
6552 m_log.ErrorFormat(
6553 "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
6554 e);
6555 }
6556 }
6557  
6558 return true;
6559 }
6560  
6561 private bool HandlerAgentIsNowWearing(IClientAPI sender, Packet Pack)
6562 {
6563 if (OnAvatarNowWearing != null)
6564 {
6565 AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
6566  
6567 #region Packet Session and User Check
6568 if (m_checkPackets)
6569 {
6570 if (nowWearing.AgentData.SessionID != SessionId ||
6571 nowWearing.AgentData.AgentID != AgentId)
6572 return true;
6573 }
6574 #endregion
6575  
6576 AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
6577 for (int i = 0; i < nowWearing.WearableData.Length; i++)
6578 {
6579 //m_log.DebugFormat("[XXX]: Wearable type {0} item {1}", nowWearing.WearableData[i].WearableType, nowWearing.WearableData[i].ItemID);
6580 AvatarWearingArgs.Wearable wearable =
6581 new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
6582 nowWearing.WearableData[i].WearableType);
6583 wearingArgs.NowWearing.Add(wearable);
6584 }
6585  
6586 AvatarNowWearing handlerAvatarNowWearing = OnAvatarNowWearing;
6587 if (handlerAvatarNowWearing != null)
6588 {
6589 handlerAvatarNowWearing(this, wearingArgs);
6590 }
6591 }
6592 return true;
6593 }
6594  
6595 private bool HandlerRezSingleAttachmentFromInv(IClientAPI sender, Packet Pack)
6596 {
6597 RezSingleAttachmentFromInv handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
6598 if (handlerRezSingleAttachment != null)
6599 {
6600 RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
6601  
6602 #region Packet Session and User Check
6603 if (m_checkPackets)
6604 {
6605 if (rez.AgentData.SessionID != SessionId ||
6606 rez.AgentData.AgentID != AgentId)
6607 return true;
6608 }
6609 #endregion
6610  
6611 handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
6612 rez.ObjectData.AttachmentPt);
6613 }
6614  
6615 return true;
6616 }
6617  
6618 private bool HandleRezMultipleAttachmentsFromInv(IClientAPI sender, Packet Pack)
6619 {
6620 RezMultipleAttachmentsFromInv handlerRezMultipleAttachments = OnRezMultipleAttachmentsFromInv;
6621 if (handlerRezMultipleAttachments != null)
6622 {
6623 List<KeyValuePair<UUID, uint>> rezlist = new List<KeyValuePair<UUID, uint>>();
6624 foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in ((RezMultipleAttachmentsFromInvPacket)Pack).ObjectData)
6625 rezlist.Add(new KeyValuePair<UUID, uint>(obj.ItemID, obj.AttachmentPt));
6626 handlerRezMultipleAttachments(this, rezlist);
6627 }
6628  
6629 return true;
6630 }
6631  
6632 private bool HandleDetachAttachmentIntoInv(IClientAPI sender, Packet Pack)
6633 {
6634 UUIDNameRequest handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
6635 if (handlerDetachAttachmentIntoInv != null)
6636 {
6637 DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
6638  
6639 #region Packet Session and User Check
6640 // UNSUPPORTED ON THIS PACKET
6641 #endregion
6642  
6643 UUID itemID = detachtoInv.ObjectData.ItemID;
6644 // UUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
6645  
6646 handlerDetachAttachmentIntoInv(itemID, this);
6647 }
6648 return true;
6649 }
6650  
6651 private bool HandleObjectAttach(IClientAPI sender, Packet Pack)
6652 {
6653 if (OnObjectAttach != null)
6654 {
6655 ObjectAttachPacket att = (ObjectAttachPacket)Pack;
6656  
6657 #region Packet Session and User Check
6658 if (m_checkPackets)
6659 {
6660 if (att.AgentData.SessionID != SessionId ||
6661 att.AgentData.AgentID != AgentId)
6662 return true;
6663 }
6664 #endregion
6665  
6666 ObjectAttach handlerObjectAttach = OnObjectAttach;
6667  
6668 if (handlerObjectAttach != null)
6669 {
6670 if (att.ObjectData.Length > 0)
6671 {
6672 handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, false);
6673 }
6674 }
6675 }
6676 return true;
6677 }
6678  
6679 private bool HandleObjectDetach(IClientAPI sender, Packet Pack)
6680 {
6681 ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
6682  
6683 #region Packet Session and User Check
6684 if (m_checkPackets)
6685 {
6686 if (dett.AgentData.SessionID != SessionId ||
6687 dett.AgentData.AgentID != AgentId)
6688 return true;
6689 }
6690 #endregion
6691  
6692 for (int j = 0; j < dett.ObjectData.Length; j++)
6693 {
6694 uint obj = dett.ObjectData[j].ObjectLocalID;
6695 ObjectDeselect handlerObjectDetach = OnObjectDetach;
6696 if (handlerObjectDetach != null)
6697 {
6698 handlerObjectDetach(obj, this);
6699 }
6700  
6701 }
6702 return true;
6703 }
6704  
6705 private bool HandleObjectDrop(IClientAPI sender, Packet Pack)
6706 {
6707 ObjectDropPacket dropp = (ObjectDropPacket)Pack;
6708  
6709 #region Packet Session and User Check
6710 if (m_checkPackets)
6711 {
6712 if (dropp.AgentData.SessionID != SessionId ||
6713 dropp.AgentData.AgentID != AgentId)
6714 return true;
6715 }
6716 #endregion
6717  
6718 for (int j = 0; j < dropp.ObjectData.Length; j++)
6719 {
6720 uint obj = dropp.ObjectData[j].ObjectLocalID;
6721 ObjectDrop handlerObjectDrop = OnObjectDrop;
6722 if (handlerObjectDrop != null)
6723 {
6724 handlerObjectDrop(obj, this);
6725 }
6726 }
6727 return true;
6728 }
6729  
6730 private bool HandleSetAlwaysRun(IClientAPI sender, Packet Pack)
6731 {
6732 SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
6733  
6734 #region Packet Session and User Check
6735 if (m_checkPackets)
6736 {
6737 if (run.AgentData.SessionID != SessionId ||
6738 run.AgentData.AgentID != AgentId)
6739 return true;
6740 }
6741 #endregion
6742  
6743 SetAlwaysRun handlerSetAlwaysRun = OnSetAlwaysRun;
6744 if (handlerSetAlwaysRun != null)
6745 handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
6746  
6747 return true;
6748 }
6749  
6750 private bool HandleCompleteAgentMovement(IClientAPI sender, Packet Pack)
6751 {
6752 Action<IClientAPI, bool> handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
6753 if (handlerCompleteMovementToRegion != null)
6754 {
6755 handlerCompleteMovementToRegion(sender, true);
6756 }
6757 handlerCompleteMovementToRegion = null;
6758  
6759 return true;
6760 }
6761  
6762 private bool HandleAgentAnimation(IClientAPI sender, Packet Pack)
6763 {
6764 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
6765  
6766 #region Packet Session and User Check
6767 if (m_checkPackets)
6768 {
6769 if (AgentAni.AgentData.SessionID != SessionId ||
6770 AgentAni.AgentData.AgentID != AgentId)
6771 return true;
6772 }
6773 #endregion
6774  
6775 StartAnim handlerStartAnim = null;
6776 StopAnim handlerStopAnim = null;
6777  
6778 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
6779 {
6780 if (AgentAni.AnimationList[i].StartAnim)
6781 {
6782 handlerStartAnim = OnStartAnim;
6783 if (handlerStartAnim != null)
6784 {
6785 handlerStartAnim(this, AgentAni.AnimationList[i].AnimID);
6786 }
6787 }
6788 else
6789 {
6790 handlerStopAnim = OnStopAnim;
6791 if (handlerStopAnim != null)
6792 {
6793 handlerStopAnim(this, AgentAni.AnimationList[i].AnimID);
6794 }
6795 }
6796 }
6797 return true;
6798 }
6799  
6800 private bool HandleAgentRequestSit(IClientAPI sender, Packet Pack)
6801 {
6802 if (OnAgentRequestSit != null)
6803 {
6804 AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
6805  
6806 #region Packet Session and User Check
6807 if (m_checkPackets)
6808 {
6809 if (agentRequestSit.AgentData.SessionID != SessionId ||
6810 agentRequestSit.AgentData.AgentID != AgentId)
6811 return true;
6812 }
6813 #endregion
6814  
6815 if (SceneAgent.IsChildAgent)
6816 {
6817 SendCantSitBecauseChildAgentResponse();
6818 return true;
6819 }
6820  
6821 AgentRequestSit handlerAgentRequestSit = OnAgentRequestSit;
6822  
6823 if (handlerAgentRequestSit != null)
6824 handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
6825 agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
6826 }
6827 return true;
6828 }
6829  
6830 private bool HandleAgentSit(IClientAPI sender, Packet Pack)
6831 {
6832 if (OnAgentSit != null)
6833 {
6834 AgentSitPacket agentSit = (AgentSitPacket)Pack;
6835  
6836 #region Packet Session and User Check
6837 if (m_checkPackets)
6838 {
6839 if (agentSit.AgentData.SessionID != SessionId ||
6840 agentSit.AgentData.AgentID != AgentId)
6841 return true;
6842 }
6843 #endregion
6844  
6845 if (SceneAgent.IsChildAgent)
6846 {
6847 SendCantSitBecauseChildAgentResponse();
6848 return true;
6849 }
6850  
6851 AgentSit handlerAgentSit = OnAgentSit;
6852 if (handlerAgentSit != null)
6853 {
6854 OnAgentSit(this, agentSit.AgentData.AgentID);
6855 }
6856 }
6857 return true;
6858 }
6859  
6860 /// <summary>
6861 /// Used when a child agent gets a sit response which should not be fulfilled.
6862 /// </summary>
6863 private void SendCantSitBecauseChildAgentResponse()
6864 {
6865 SendAlertMessage("Try moving closer. Can't sit on object because it is not in the same region as you.");
6866 }
6867  
6868 private bool HandleSoundTrigger(IClientAPI sender, Packet Pack)
6869 {
6870 SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack;
6871  
6872 #region Packet Session and User Check
6873 if (m_checkPackets)
6874 {
6875 // UNSUPPORTED ON THIS PACKET
6876 }
6877 #endregion
6878  
6879 SoundTrigger handlerSoundTrigger = OnSoundTrigger;
6880 if (handlerSoundTrigger != null)
6881 {
6882 // UUIDS are sent as zeroes by the client, substitute agent's id
6883 handlerSoundTrigger(soundTriggerPacket.SoundData.SoundID, AgentId,
6884 AgentId, AgentId,
6885 soundTriggerPacket.SoundData.Gain, soundTriggerPacket.SoundData.Position,
6886 soundTriggerPacket.SoundData.Handle, 0);
6887  
6888 }
6889 return true;
6890 }
6891  
6892 private bool HandleAvatarPickerRequest(IClientAPI sender, Packet Pack)
6893 {
6894 AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
6895  
6896 #region Packet Session and User Check
6897 if (m_checkPackets)
6898 {
6899 if (avRequestQuery.AgentData.SessionID != SessionId ||
6900 avRequestQuery.AgentData.AgentID != AgentId)
6901 return true;
6902 }
6903 #endregion
6904  
6905 AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
6906 AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
6907 //m_log.Debug("Agent Sends:" + Utils.BytesToString(querydata.Name));
6908  
6909 AvatarPickerRequest handlerAvatarPickerRequest = OnAvatarPickerRequest;
6910 if (handlerAvatarPickerRequest != null)
6911 {
6912 handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
6913 Utils.BytesToString(querydata.Name));
6914 }
6915 return true;
6916 }
6917  
6918 private bool HandleAgentDataUpdateRequest(IClientAPI sender, Packet Pack)
6919 {
6920 AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
6921  
6922 #region Packet Session and User Check
6923 if (m_checkPackets)
6924 {
6925 if (avRequestDataUpdatePacket.AgentData.SessionID != SessionId ||
6926 avRequestDataUpdatePacket.AgentData.AgentID != AgentId)
6927 return true;
6928 }
6929 #endregion
6930  
6931 FetchInventory handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
6932  
6933 if (handlerAgentDataUpdateRequest != null)
6934 {
6935 handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
6936 }
6937  
6938 return true;
6939 }
6940  
6941 private bool HandleUserInfoRequest(IClientAPI sender, Packet Pack)
6942 {
6943 UserInfoRequest handlerUserInfoRequest = OnUserInfoRequest;
6944 if (handlerUserInfoRequest != null)
6945 {
6946 handlerUserInfoRequest(this);
6947 }
6948 else
6949 {
6950 SendUserInfoReply(false, true, "");
6951 }
6952 return true;
6953  
6954 }
6955  
6956 private bool HandleUpdateUserInfo(IClientAPI sender, Packet Pack)
6957 {
6958 UpdateUserInfoPacket updateUserInfo = (UpdateUserInfoPacket)Pack;
6959  
6960 #region Packet Session and User Check
6961 if (m_checkPackets)
6962 {
6963 if (updateUserInfo.AgentData.SessionID != SessionId ||
6964 updateUserInfo.AgentData.AgentID != AgentId)
6965 return true;
6966 }
6967 #endregion
6968  
6969 UpdateUserInfo handlerUpdateUserInfo = OnUpdateUserInfo;
6970 if (handlerUpdateUserInfo != null)
6971 {
6972 bool visible = true;
6973 string DirectoryVisibility =
6974 Utils.BytesToString(updateUserInfo.UserData.DirectoryVisibility);
6975 if (DirectoryVisibility == "hidden")
6976 visible = false;
6977  
6978 handlerUpdateUserInfo(
6979 updateUserInfo.UserData.IMViaEMail,
6980 visible, this);
6981 }
6982 return true;
6983 }
6984  
6985 private bool HandleSetStartLocationRequest(IClientAPI sender, Packet Pack)
6986 {
6987 SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
6988  
6989 #region Packet Session and User Check
6990 if (m_checkPackets)
6991 {
6992 if (avSetStartLocationRequestPacket.AgentData.SessionID != SessionId ||
6993 avSetStartLocationRequestPacket.AgentData.AgentID != AgentId)
6994 return true;
6995 }
6996 #endregion
6997  
6998 if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
6999 {
7000 // Linden Client limitation..
7001 if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.X == 255.5f
7002 || avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y == 255.5f)
7003 {
7004 ScenePresence avatar = null;
7005 if (((Scene)m_scene).TryGetScenePresence(AgentId, out avatar))
7006 {
7007 if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.X == 255.5f)
7008 {
7009 avSetStartLocationRequestPacket.StartLocationData.LocationPos.X = avatar.AbsolutePosition.X;
7010 }
7011 if (avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y == 255.5f)
7012 {
7013 avSetStartLocationRequestPacket.StartLocationData.LocationPos.Y = avatar.AbsolutePosition.Y;
7014 }
7015 }
7016  
7017 }
7018 TeleportLocationRequest handlerSetStartLocationRequest = OnSetStartLocationRequest;
7019 if (handlerSetStartLocationRequest != null)
7020 {
7021 handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
7022 avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
7023 avSetStartLocationRequestPacket.StartLocationData.LocationID);
7024 }
7025 }
7026 return true;
7027 }
7028  
7029 private bool HandleAgentThrottle(IClientAPI sender, Packet Pack)
7030 {
7031 AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
7032  
7033 #region Packet Session and User Check
7034 if (m_checkPackets)
7035 {
7036 if (atpack.AgentData.SessionID != SessionId ||
7037 atpack.AgentData.AgentID != AgentId)
7038 return true;
7039 }
7040 #endregion
7041  
7042 m_udpClient.SetThrottles(atpack.Throttle.Throttles);
7043 return true;
7044 }
7045  
7046 private bool HandleAgentPause(IClientAPI sender, Packet Pack)
7047 {
7048 m_udpClient.IsPaused = true;
7049 return true;
7050 }
7051  
7052 private bool HandleAgentResume(IClientAPI sender, Packet Pack)
7053 {
7054 m_udpClient.IsPaused = false;
7055 SendStartPingCheck(m_udpClient.CurrentPingSequence++);
7056 return true;
7057 }
7058  
7059 private bool HandleForceScriptControlRelease(IClientAPI sender, Packet Pack)
7060 {
7061 ForceReleaseControls handlerForceReleaseControls = OnForceReleaseControls;
7062 if (handlerForceReleaseControls != null)
7063 {
7064 handlerForceReleaseControls(this, AgentId);
7065 }
7066 return true;
7067 }
7068  
7069 #endregion Scene/Avatar
7070  
7071 #region Objects/m_sceneObjects
7072  
7073 private bool HandleObjectLink(IClientAPI sender, Packet Pack)
7074 {
7075 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
7076  
7077 #region Packet Session and User Check
7078 if (m_checkPackets)
7079 {
7080 if (link.AgentData.SessionID != SessionId ||
7081 link.AgentData.AgentID != AgentId)
7082 return true;
7083 }
7084 #endregion
7085  
7086 uint parentprimid = 0;
7087 List<uint> childrenprims = new List<uint>();
7088 if (link.ObjectData.Length > 1)
7089 {
7090 parentprimid = link.ObjectData[0].ObjectLocalID;
7091  
7092 for (int i = 1; i < link.ObjectData.Length; i++)
7093 {
7094 childrenprims.Add(link.ObjectData[i].ObjectLocalID);
7095 }
7096 }
7097 LinkObjects handlerLinkObjects = OnLinkObjects;
7098 if (handlerLinkObjects != null)
7099 {
7100 handlerLinkObjects(this, parentprimid, childrenprims);
7101 }
7102 return true;
7103 }
7104  
7105 private bool HandleObjectDelink(IClientAPI sender, Packet Pack)
7106 {
7107 ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
7108  
7109 #region Packet Session and User Check
7110 if (m_checkPackets)
7111 {
7112 if (delink.AgentData.SessionID != SessionId ||
7113 delink.AgentData.AgentID != AgentId)
7114 return true;
7115 }
7116 #endregion
7117  
7118 // It appears the prim at index 0 is not always the root prim (for
7119 // instance, when one prim of a link set has been edited independently
7120 // of the others). Therefore, we'll pass all the ids onto the delink
7121 // method for it to decide which is the root.
7122 List<uint> prims = new List<uint>();
7123 for (int i = 0; i < delink.ObjectData.Length; i++)
7124 {
7125 prims.Add(delink.ObjectData[i].ObjectLocalID);
7126 }
7127 DelinkObjects handlerDelinkObjects = OnDelinkObjects;
7128 if (handlerDelinkObjects != null)
7129 {
7130 handlerDelinkObjects(prims, this);
7131 }
7132  
7133 return true;
7134 }
7135  
7136 private bool HandleObjectAdd(IClientAPI sender, Packet Pack)
7137 {
7138 if (OnAddPrim != null)
7139 {
7140 ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
7141  
7142 #region Packet Session and User Check
7143 if (m_checkPackets)
7144 {
7145 if (addPacket.AgentData.SessionID != SessionId ||
7146 addPacket.AgentData.AgentID != AgentId)
7147 return true;
7148 }
7149 #endregion
7150  
7151 PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
7152 // m_log.Info("[REZData]: " + addPacket.ToString());
7153 //BypassRaycast: 1
7154 //RayStart: <69.79469, 158.2652, 98.40343>
7155 //RayEnd: <61.97724, 141.995, 92.58341>
7156 //RayTargetID: 00000000-0000-0000-0000-000000000000
7157  
7158 //Check to see if adding the prim is allowed; useful for any module wanting to restrict the
7159 //object from rezing initially
7160  
7161 AddNewPrim handlerAddPrim = OnAddPrim;
7162 if (handlerAddPrim != null)
7163 handlerAddPrim(AgentId, ActiveGroupId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
7164 }
7165 return true;
7166 }
7167  
7168 private bool HandleObjectShape(IClientAPI sender, Packet Pack)
7169 {
7170 ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
7171  
7172 #region Packet Session and User Check
7173 if (m_checkPackets)
7174 {
7175 if (shapePacket.AgentData.SessionID != SessionId ||
7176 shapePacket.AgentData.AgentID != AgentId)
7177 return true;
7178 }
7179 #endregion
7180  
7181 UpdateShape handlerUpdatePrimShape = null;
7182 for (int i = 0; i < shapePacket.ObjectData.Length; i++)
7183 {
7184 handlerUpdatePrimShape = OnUpdatePrimShape;
7185 if (handlerUpdatePrimShape != null)
7186 {
7187 UpdateShapeArgs shapeData = new UpdateShapeArgs();
7188 shapeData.ObjectLocalID = shapePacket.ObjectData[i].ObjectLocalID;
7189 shapeData.PathBegin = shapePacket.ObjectData[i].PathBegin;
7190 shapeData.PathCurve = shapePacket.ObjectData[i].PathCurve;
7191 shapeData.PathEnd = shapePacket.ObjectData[i].PathEnd;
7192 shapeData.PathRadiusOffset = shapePacket.ObjectData[i].PathRadiusOffset;
7193 shapeData.PathRevolutions = shapePacket.ObjectData[i].PathRevolutions;
7194 shapeData.PathScaleX = shapePacket.ObjectData[i].PathScaleX;
7195 shapeData.PathScaleY = shapePacket.ObjectData[i].PathScaleY;
7196 shapeData.PathShearX = shapePacket.ObjectData[i].PathShearX;
7197 shapeData.PathShearY = shapePacket.ObjectData[i].PathShearY;
7198 shapeData.PathSkew = shapePacket.ObjectData[i].PathSkew;
7199 shapeData.PathTaperX = shapePacket.ObjectData[i].PathTaperX;
7200 shapeData.PathTaperY = shapePacket.ObjectData[i].PathTaperY;
7201 shapeData.PathTwist = shapePacket.ObjectData[i].PathTwist;
7202 shapeData.PathTwistBegin = shapePacket.ObjectData[i].PathTwistBegin;
7203 shapeData.ProfileBegin = shapePacket.ObjectData[i].ProfileBegin;
7204 shapeData.ProfileCurve = shapePacket.ObjectData[i].ProfileCurve;
7205 shapeData.ProfileEnd = shapePacket.ObjectData[i].ProfileEnd;
7206 shapeData.ProfileHollow = shapePacket.ObjectData[i].ProfileHollow;
7207  
7208 handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
7209 shapeData);
7210 }
7211 }
7212 return true;
7213 }
7214  
7215 private bool HandleObjectExtraParams(IClientAPI sender, Packet Pack)
7216 {
7217 ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
7218  
7219 #region Packet Session and User Check
7220 if (m_checkPackets)
7221 {
7222 if (extraPar.AgentData.SessionID != SessionId ||
7223 extraPar.AgentData.AgentID != AgentId)
7224 return true;
7225 }
7226 #endregion
7227  
7228 ObjectExtraParams handlerUpdateExtraParams = OnUpdateExtraParams;
7229 if (handlerUpdateExtraParams != null)
7230 {
7231 for (int i = 0; i < extraPar.ObjectData.Length; i++)
7232 {
7233 handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[i].ObjectLocalID,
7234 extraPar.ObjectData[i].ParamType,
7235 extraPar.ObjectData[i].ParamInUse, extraPar.ObjectData[i].ParamData);
7236 }
7237 }
7238 return true;
7239 }
7240  
7241 private bool HandleObjectDuplicate(IClientAPI sender, Packet Pack)
7242 {
7243 ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
7244  
7245 #region Packet Session and User Check
7246 if (m_checkPackets)
7247 {
7248 if (dupe.AgentData.SessionID != SessionId ||
7249 dupe.AgentData.AgentID != AgentId)
7250 return true;
7251 }
7252 #endregion
7253  
7254 // ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
7255  
7256 ObjectDuplicate handlerObjectDuplicate = null;
7257  
7258 for (int i = 0; i < dupe.ObjectData.Length; i++)
7259 {
7260 handlerObjectDuplicate = OnObjectDuplicate;
7261 if (handlerObjectDuplicate != null)
7262 {
7263 handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
7264 dupe.SharedData.DuplicateFlags, AgentId,
7265 ActiveGroupId);
7266 }
7267 }
7268  
7269 return true;
7270 }
7271  
7272 private bool HandleRequestMultipleObjects(IClientAPI sender, Packet Pack)
7273 {
7274 RequestMultipleObjectsPacket incomingRequest = (RequestMultipleObjectsPacket)Pack;
7275  
7276 #region Packet Session and User Check
7277 if (m_checkPackets)
7278 {
7279 if (incomingRequest.AgentData.SessionID != SessionId ||
7280 incomingRequest.AgentData.AgentID != AgentId)
7281 return true;
7282 }
7283 #endregion
7284  
7285 ObjectRequest handlerObjectRequest = null;
7286  
7287 for (int i = 0; i < incomingRequest.ObjectData.Length; i++)
7288 {
7289 handlerObjectRequest = OnObjectRequest;
7290 if (handlerObjectRequest != null)
7291 {
7292 handlerObjectRequest(incomingRequest.ObjectData[i].ID, this);
7293 }
7294 }
7295 return true;
7296 }
7297  
7298 private bool HandleObjectSelect(IClientAPI sender, Packet Pack)
7299 {
7300 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
7301  
7302 #region Packet Session and User Check
7303 if (m_checkPackets)
7304 {
7305 if (incomingselect.AgentData.SessionID != SessionId ||
7306 incomingselect.AgentData.AgentID != AgentId)
7307 return true;
7308 }
7309 #endregion
7310  
7311 ObjectSelect handlerObjectSelect = null;
7312  
7313 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
7314 {
7315 handlerObjectSelect = OnObjectSelect;
7316 if (handlerObjectSelect != null)
7317 {
7318 handlerObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
7319 }
7320 }
7321 return true;
7322 }
7323  
7324 private bool HandleObjectDeselect(IClientAPI sender, Packet Pack)
7325 {
7326 ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
7327  
7328 #region Packet Session and User Check
7329 if (m_checkPackets)
7330 {
7331 if (incomingdeselect.AgentData.SessionID != SessionId ||
7332 incomingdeselect.AgentData.AgentID != AgentId)
7333 return true;
7334 }
7335 #endregion
7336  
7337 ObjectDeselect handlerObjectDeselect = null;
7338  
7339 for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
7340 {
7341 handlerObjectDeselect = OnObjectDeselect;
7342 if (handlerObjectDeselect != null)
7343 {
7344 OnObjectDeselect(incomingdeselect.ObjectData[i].ObjectLocalID, this);
7345 }
7346 }
7347 return true;
7348 }
7349  
7350 private bool HandleObjectPosition(IClientAPI sender, Packet Pack)
7351 {
7352 // DEPRECATED: but till libsecondlife removes it, people will use it
7353 ObjectPositionPacket position = (ObjectPositionPacket)Pack;
7354  
7355 #region Packet Session and User Check
7356 if (m_checkPackets)
7357 {
7358 if (position.AgentData.SessionID != SessionId ||
7359 position.AgentData.AgentID != AgentId)
7360 return true;
7361 }
7362 #endregion
7363  
7364  
7365 for (int i = 0; i < position.ObjectData.Length; i++)
7366 {
7367 UpdateVector handlerUpdateVector = OnUpdatePrimGroupPosition;
7368 if (handlerUpdateVector != null)
7369 handlerUpdateVector(position.ObjectData[i].ObjectLocalID, position.ObjectData[i].Position, this);
7370 }
7371  
7372 return true;
7373 }
7374  
7375 private bool HandleObjectScale(IClientAPI sender, Packet Pack)
7376 {
7377 // DEPRECATED: but till libsecondlife removes it, people will use it
7378 ObjectScalePacket scale = (ObjectScalePacket)Pack;
7379  
7380 #region Packet Session and User Check
7381 if (m_checkPackets)
7382 {
7383 if (scale.AgentData.SessionID != SessionId ||
7384 scale.AgentData.AgentID != AgentId)
7385 return true;
7386 }
7387 #endregion
7388  
7389 for (int i = 0; i < scale.ObjectData.Length; i++)
7390 {
7391 UpdateVector handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
7392 if (handlerUpdatePrimGroupScale != null)
7393 handlerUpdatePrimGroupScale(scale.ObjectData[i].ObjectLocalID, scale.ObjectData[i].Scale, this);
7394 }
7395  
7396 return true;
7397 }
7398  
7399 private bool HandleObjectRotation(IClientAPI sender, Packet Pack)
7400 {
7401 // DEPRECATED: but till libsecondlife removes it, people will use it
7402 ObjectRotationPacket rotation = (ObjectRotationPacket)Pack;
7403  
7404 #region Packet Session and User Check
7405 if (m_checkPackets)
7406 {
7407 if (rotation.AgentData.SessionID != SessionId ||
7408 rotation.AgentData.AgentID != AgentId)
7409 return true;
7410 }
7411 #endregion
7412  
7413 for (int i = 0; i < rotation.ObjectData.Length; i++)
7414 {
7415 UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
7416 if (handlerUpdatePrimRotation != null)
7417 handlerUpdatePrimRotation(rotation.ObjectData[i].ObjectLocalID, rotation.ObjectData[i].Rotation, this);
7418 }
7419  
7420 return true;
7421 }
7422  
7423 private bool HandleObjectFlagUpdate(IClientAPI sender, Packet Pack)
7424 {
7425 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
7426  
7427 #region Packet Session and User Check
7428 if (m_checkPackets)
7429 {
7430 if (flags.AgentData.SessionID != SessionId ||
7431 flags.AgentData.AgentID != AgentId)
7432 return true;
7433 }
7434 #endregion
7435  
7436 UpdatePrimFlags handlerUpdatePrimFlags = OnUpdatePrimFlags;
7437  
7438 if (handlerUpdatePrimFlags != null)
7439 {
7440 // byte[] data = Pack.ToBytes();
7441 // 46,47,48 are special positions within the packet
7442 // This may change so perhaps we need a better way
7443 // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
7444 /*
7445 bool UsePhysics = (data[46] != 0) ? true : false;
7446 bool IsTemporary = (data[47] != 0) ? true : false;
7447 bool IsPhantom = (data[48] != 0) ? true : false;
7448 handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
7449 */
7450 bool UsePhysics = flags.AgentData.UsePhysics;
7451 bool IsPhantom = flags.AgentData.IsPhantom;
7452 bool IsTemporary = flags.AgentData.IsTemporary;
7453 ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks = flags.ExtraPhysics;
7454 ExtraPhysicsData physdata = new ExtraPhysicsData();
7455  
7456 if (blocks == null || blocks.Length == 0)
7457 {
7458 physdata.PhysShapeType = PhysShapeType.invalid;
7459 }
7460 else
7461 {
7462 ObjectFlagUpdatePacket.ExtraPhysicsBlock phsblock = blocks[0];
7463 physdata.PhysShapeType = (PhysShapeType)phsblock.PhysicsShapeType;
7464 physdata.Bounce = phsblock.Restitution;
7465 physdata.Density = phsblock.Density;
7466 physdata.Friction = phsblock.Friction;
7467 physdata.GravitationModifier = phsblock.GravityMultiplier;
7468 }
7469  
7470 handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
7471 }
7472 return true;
7473 }
7474  
7475 private bool HandleObjectImage(IClientAPI sender, Packet Pack)
7476 {
7477 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
7478  
7479 UpdatePrimTexture handlerUpdatePrimTexture = null;
7480 for (int i = 0; i < imagePack.ObjectData.Length; i++)
7481 {
7482 handlerUpdatePrimTexture = OnUpdatePrimTexture;
7483 if (handlerUpdatePrimTexture != null)
7484 {
7485 handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
7486 imagePack.ObjectData[i].TextureEntry, this);
7487 }
7488 }
7489 return true;
7490 }
7491  
7492 private bool HandleObjectGrab(IClientAPI sender, Packet Pack)
7493 {
7494 ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
7495  
7496 #region Packet Session and User Check
7497 if (m_checkPackets)
7498 {
7499 if (grab.AgentData.SessionID != SessionId ||
7500 grab.AgentData.AgentID != AgentId)
7501 return true;
7502 }
7503 #endregion
7504  
7505 GrabObject handlerGrabObject = OnGrabObject;
7506  
7507 if (handlerGrabObject != null)
7508 {
7509 List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
7510 if ((grab.SurfaceInfo != null) && (grab.SurfaceInfo.Length > 0))
7511 {
7512 foreach (ObjectGrabPacket.SurfaceInfoBlock surfaceInfo in grab.SurfaceInfo)
7513 {
7514 SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
7515 arg.Binormal = surfaceInfo.Binormal;
7516 arg.FaceIndex = surfaceInfo.FaceIndex;
7517 arg.Normal = surfaceInfo.Normal;
7518 arg.Position = surfaceInfo.Position;
7519 arg.STCoord = surfaceInfo.STCoord;
7520 arg.UVCoord = surfaceInfo.UVCoord;
7521 touchArgs.Add(arg);
7522 }
7523 }
7524 handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this, touchArgs);
7525 }
7526 return true;
7527 }
7528  
7529 private bool HandleObjectGrabUpdate(IClientAPI sender, Packet Pack)
7530 {
7531 ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
7532  
7533 #region Packet Session and User Check
7534 if (m_checkPackets)
7535 {
7536 if (grabUpdate.AgentData.SessionID != SessionId ||
7537 grabUpdate.AgentData.AgentID != AgentId)
7538 return true;
7539 }
7540 #endregion
7541  
7542 MoveObject handlerGrabUpdate = OnGrabUpdate;
7543  
7544 if (handlerGrabUpdate != null)
7545 {
7546 List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
7547 if ((grabUpdate.SurfaceInfo != null) && (grabUpdate.SurfaceInfo.Length > 0))
7548 {
7549 foreach (ObjectGrabUpdatePacket.SurfaceInfoBlock surfaceInfo in grabUpdate.SurfaceInfo)
7550 {
7551 SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
7552 arg.Binormal = surfaceInfo.Binormal;
7553 arg.FaceIndex = surfaceInfo.FaceIndex;
7554 arg.Normal = surfaceInfo.Normal;
7555 arg.Position = surfaceInfo.Position;
7556 arg.STCoord = surfaceInfo.STCoord;
7557 arg.UVCoord = surfaceInfo.UVCoord;
7558 touchArgs.Add(arg);
7559 }
7560 }
7561 handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
7562 grabUpdate.ObjectData.GrabPosition, this, touchArgs);
7563 }
7564 return true;
7565 }
7566  
7567 private bool HandleObjectDeGrab(IClientAPI sender, Packet Pack)
7568 {
7569 ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
7570  
7571 #region Packet Session and User Check
7572 if (m_checkPackets)
7573 {
7574 if (deGrab.AgentData.SessionID != SessionId ||
7575 deGrab.AgentData.AgentID != AgentId)
7576 return true;
7577 }
7578 #endregion
7579  
7580 DeGrabObject handlerDeGrabObject = OnDeGrabObject;
7581 if (handlerDeGrabObject != null)
7582 {
7583 List<SurfaceTouchEventArgs> touchArgs = new List<SurfaceTouchEventArgs>();
7584 if ((deGrab.SurfaceInfo != null) && (deGrab.SurfaceInfo.Length > 0))
7585 {
7586 foreach (ObjectDeGrabPacket.SurfaceInfoBlock surfaceInfo in deGrab.SurfaceInfo)
7587 {
7588 SurfaceTouchEventArgs arg = new SurfaceTouchEventArgs();
7589 arg.Binormal = surfaceInfo.Binormal;
7590 arg.FaceIndex = surfaceInfo.FaceIndex;
7591 arg.Normal = surfaceInfo.Normal;
7592 arg.Position = surfaceInfo.Position;
7593 arg.STCoord = surfaceInfo.STCoord;
7594 arg.UVCoord = surfaceInfo.UVCoord;
7595 touchArgs.Add(arg);
7596 }
7597 }
7598 handlerDeGrabObject(deGrab.ObjectData.LocalID, this, touchArgs);
7599 }
7600 return true;
7601 }
7602  
7603 private bool HandleObjectSpinStart(IClientAPI sender, Packet Pack)
7604 {
7605 //m_log.Warn("[CLIENT]: unhandled ObjectSpinStart packet");
7606 ObjectSpinStartPacket spinStart = (ObjectSpinStartPacket)Pack;
7607  
7608 #region Packet Session and User Check
7609 if (m_checkPackets)
7610 {
7611 if (spinStart.AgentData.SessionID != SessionId ||
7612 spinStart.AgentData.AgentID != AgentId)
7613 return true;
7614 }
7615 #endregion
7616  
7617 SpinStart handlerSpinStart = OnSpinStart;
7618 if (handlerSpinStart != null)
7619 {
7620 handlerSpinStart(spinStart.ObjectData.ObjectID, this);
7621 }
7622 return true;
7623 }
7624  
7625 private bool HandleObjectSpinUpdate(IClientAPI sender, Packet Pack)
7626 {
7627 //m_log.Warn("[CLIENT]: unhandled ObjectSpinUpdate packet");
7628 ObjectSpinUpdatePacket spinUpdate = (ObjectSpinUpdatePacket)Pack;
7629  
7630 #region Packet Session and User Check
7631 if (m_checkPackets)
7632 {
7633 if (spinUpdate.AgentData.SessionID != SessionId ||
7634 spinUpdate.AgentData.AgentID != AgentId)
7635 return true;
7636 }
7637 #endregion
7638  
7639 Vector3 axis;
7640 float angle;
7641 spinUpdate.ObjectData.Rotation.GetAxisAngle(out axis, out angle);
7642 //m_log.Warn("[CLIENT]: ObjectSpinUpdate packet rot axis:" + axis + " angle:" + angle);
7643  
7644 SpinObject handlerSpinUpdate = OnSpinUpdate;
7645 if (handlerSpinUpdate != null)
7646 {
7647 handlerSpinUpdate(spinUpdate.ObjectData.ObjectID, spinUpdate.ObjectData.Rotation, this);
7648 }
7649 return true;
7650 }
7651  
7652 private bool HandleObjectSpinStop(IClientAPI sender, Packet Pack)
7653 {
7654 //m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
7655 ObjectSpinStopPacket spinStop = (ObjectSpinStopPacket)Pack;
7656  
7657 #region Packet Session and User Check
7658 if (m_checkPackets)
7659 {
7660 if (spinStop.AgentData.SessionID != SessionId ||
7661 spinStop.AgentData.AgentID != AgentId)
7662 return true;
7663 }
7664 #endregion
7665  
7666 SpinStop handlerSpinStop = OnSpinStop;
7667 if (handlerSpinStop != null)
7668 {
7669 handlerSpinStop(spinStop.ObjectData.ObjectID, this);
7670 }
7671 return true;
7672 }
7673  
7674 private bool HandleObjectDescription(IClientAPI sender, Packet Pack)
7675 {
7676 ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
7677  
7678 #region Packet Session and User Check
7679 if (m_checkPackets)
7680 {
7681 if (objDes.AgentData.SessionID != SessionId ||
7682 objDes.AgentData.AgentID != AgentId)
7683 return true;
7684 }
7685 #endregion
7686  
7687 GenericCall7 handlerObjectDescription = null;
7688  
7689 for (int i = 0; i < objDes.ObjectData.Length; i++)
7690 {
7691 handlerObjectDescription = OnObjectDescription;
7692 if (handlerObjectDescription != null)
7693 {
7694 handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
7695 Util.FieldToString(objDes.ObjectData[i].Description));
7696 }
7697 }
7698 return true;
7699 }
7700  
7701 private bool HandleObjectName(IClientAPI sender, Packet Pack)
7702 {
7703 ObjectNamePacket objName = (ObjectNamePacket)Pack;
7704  
7705 #region Packet Session and User Check
7706 if (m_checkPackets)
7707 {
7708 if (objName.AgentData.SessionID != SessionId ||
7709 objName.AgentData.AgentID != AgentId)
7710 return true;
7711 }
7712 #endregion
7713  
7714 GenericCall7 handlerObjectName = null;
7715 for (int i = 0; i < objName.ObjectData.Length; i++)
7716 {
7717 handlerObjectName = OnObjectName;
7718 if (handlerObjectName != null)
7719 {
7720 handlerObjectName(this, objName.ObjectData[i].LocalID,
7721 Util.FieldToString(objName.ObjectData[i].Name));
7722 }
7723 }
7724 return true;
7725 }
7726  
7727 private bool HandleObjectPermissions(IClientAPI sender, Packet Pack)
7728 {
7729 if (OnObjectPermissions != null)
7730 {
7731 ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
7732  
7733 #region Packet Session and User Check
7734 if (m_checkPackets)
7735 {
7736 if (newobjPerms.AgentData.SessionID != SessionId ||
7737 newobjPerms.AgentData.AgentID != AgentId)
7738 return true;
7739 }
7740 #endregion
7741  
7742 UUID AgentID = newobjPerms.AgentData.AgentID;
7743 UUID SessionID = newobjPerms.AgentData.SessionID;
7744  
7745 ObjectPermissions handlerObjectPermissions = null;
7746  
7747 for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
7748 {
7749 ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
7750  
7751 byte field = permChanges.Field;
7752 uint localID = permChanges.ObjectLocalID;
7753 uint mask = permChanges.Mask;
7754 byte set = permChanges.Set;
7755  
7756 handlerObjectPermissions = OnObjectPermissions;
7757  
7758 if (handlerObjectPermissions != null)
7759 handlerObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
7760 }
7761 }
7762  
7763 // Here's our data,
7764 // PermField contains the field the info goes into
7765 // PermField determines which mask we're changing
7766 //
7767 // chmask is the mask of the change
7768 // setTF is whether we're adding it or taking it away
7769 //
7770 // objLocalID is the localID of the object.
7771  
7772 // Unfortunately, we have to pass the event the packet because objData is an array
7773 // That means multiple object perms may be updated in a single packet.
7774  
7775 return true;
7776 }
7777  
7778 private bool HandleUndo(IClientAPI sender, Packet Pack)
7779 {
7780 UndoPacket undoitem = (UndoPacket)Pack;
7781  
7782 #region Packet Session and User Check
7783 if (m_checkPackets)
7784 {
7785 if (undoitem.AgentData.SessionID != SessionId ||
7786 undoitem.AgentData.AgentID != AgentId)
7787 return true;
7788 }
7789 #endregion
7790  
7791 if (undoitem.ObjectData.Length > 0)
7792 {
7793 for (int i = 0; i < undoitem.ObjectData.Length; i++)
7794 {
7795 UUID objiD = undoitem.ObjectData[i].ObjectID;
7796 AgentSit handlerOnUndo = OnUndo;
7797 if (handlerOnUndo != null)
7798 {
7799 handlerOnUndo(this, objiD);
7800 }
7801  
7802 }
7803 }
7804 return true;
7805 }
7806  
7807 private bool HandleLandUndo(IClientAPI sender, Packet Pack)
7808 {
7809 UndoLandPacket undolanditem = (UndoLandPacket)Pack;
7810  
7811 #region Packet Session and User Check
7812 if (m_checkPackets)
7813 {
7814 if (undolanditem.AgentData.SessionID != SessionId ||
7815 undolanditem.AgentData.AgentID != AgentId)
7816 return true;
7817 }
7818 #endregion
7819  
7820 LandUndo handlerOnUndo = OnLandUndo;
7821 if (handlerOnUndo != null)
7822 {
7823 handlerOnUndo(this);
7824 }
7825 return true;
7826 }
7827  
7828 private bool HandleRedo(IClientAPI sender, Packet Pack)
7829 {
7830 RedoPacket redoitem = (RedoPacket)Pack;
7831  
7832 #region Packet Session and User Check
7833 if (m_checkPackets)
7834 {
7835 if (redoitem.AgentData.SessionID != SessionId ||
7836 redoitem.AgentData.AgentID != AgentId)
7837 return true;
7838 }
7839 #endregion
7840  
7841 if (redoitem.ObjectData.Length > 0)
7842 {
7843 for (int i = 0; i < redoitem.ObjectData.Length; i++)
7844 {
7845 UUID objiD = redoitem.ObjectData[i].ObjectID;
7846 AgentSit handlerOnRedo = OnRedo;
7847 if (handlerOnRedo != null)
7848 {
7849 handlerOnRedo(this, objiD);
7850 }
7851  
7852 }
7853 }
7854 return true;
7855 }
7856  
7857 private bool HandleObjectDuplicateOnRay(IClientAPI sender, Packet Pack)
7858 {
7859 ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
7860  
7861 #region Packet Session and User Check
7862 if (m_checkPackets)
7863 {
7864 if (dupeOnRay.AgentData.SessionID != SessionId ||
7865 dupeOnRay.AgentData.AgentID != AgentId)
7866 return true;
7867 }
7868 #endregion
7869  
7870 ObjectDuplicateOnRay handlerObjectDuplicateOnRay = null;
7871  
7872 for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
7873 {
7874 handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
7875 if (handlerObjectDuplicateOnRay != null)
7876 {
7877 handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID, dupeOnRay.AgentData.DuplicateFlags,
7878 AgentId, ActiveGroupId, dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
7879 dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast, dupeOnRay.AgentData.RayEndIsIntersection,
7880 dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
7881 }
7882 }
7883  
7884 return true;
7885 }
7886  
7887 private bool HandleRequestObjectPropertiesFamily(IClientAPI sender, Packet Pack)
7888 {
7889 //This powers the little tooltip that appears when you move your mouse over an object
7890 RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
7891  
7892 #region Packet Session and User Check
7893 if (m_checkPackets)
7894 {
7895 if (packToolTip.AgentData.SessionID != SessionId ||
7896 packToolTip.AgentData.AgentID != AgentId)
7897 return true;
7898 }
7899 #endregion
7900  
7901 RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
7902  
7903 RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
7904  
7905 if (handlerRequestObjectPropertiesFamily != null)
7906 {
7907 handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
7908 packObjBlock.ObjectID);
7909 }
7910  
7911 return true;
7912 }
7913  
7914 private bool HandleObjectIncludeInSearch(IClientAPI sender, Packet Pack)
7915 {
7916 //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
7917 ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
7918 ObjectIncludeInSearch handlerObjectIncludeInSearch = null;
7919  
7920 #region Packet Session and User Check
7921 if (m_checkPackets)
7922 {
7923 if (packInSearch.AgentData.SessionID != SessionId ||
7924 packInSearch.AgentData.AgentID != AgentId)
7925 return true;
7926 }
7927 #endregion
7928  
7929 foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData)
7930 {
7931 bool inSearch = objData.IncludeInSearch;
7932 uint localID = objData.ObjectLocalID;
7933  
7934 handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
7935  
7936 if (handlerObjectIncludeInSearch != null)
7937 {
7938 handlerObjectIncludeInSearch(this, inSearch, localID);
7939 }
7940 }
7941 return true;
7942 }
7943  
7944 private bool HandleScriptAnswerYes(IClientAPI sender, Packet Pack)
7945 {
7946 ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
7947  
7948 #region Packet Session and User Check
7949 if (m_checkPackets)
7950 {
7951 if (scriptAnswer.AgentData.SessionID != SessionId ||
7952 scriptAnswer.AgentData.AgentID != AgentId)
7953 return true;
7954 }
7955 #endregion
7956  
7957 ScriptAnswer handlerScriptAnswer = OnScriptAnswer;
7958 if (handlerScriptAnswer != null)
7959 {
7960 handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
7961 }
7962 return true;
7963 }
7964  
7965 private bool HandleObjectClickAction(IClientAPI sender, Packet Pack)
7966 {
7967 ObjectClickActionPacket ocpacket = (ObjectClickActionPacket)Pack;
7968  
7969 #region Packet Session and User Check
7970 if (m_checkPackets)
7971 {
7972 if (ocpacket.AgentData.SessionID != SessionId ||
7973 ocpacket.AgentData.AgentID != AgentId)
7974 return true;
7975 }
7976 #endregion
7977  
7978 GenericCall7 handlerObjectClickAction = OnObjectClickAction;
7979 if (handlerObjectClickAction != null)
7980 {
7981 foreach (ObjectClickActionPacket.ObjectDataBlock odata in ocpacket.ObjectData)
7982 {
7983 byte action = odata.ClickAction;
7984 uint localID = odata.ObjectLocalID;
7985 handlerObjectClickAction(this, localID, action.ToString());
7986 }
7987 }
7988 return true;
7989 }
7990  
7991 private bool HandleObjectMaterial(IClientAPI sender, Packet Pack)
7992 {
7993 ObjectMaterialPacket ompacket = (ObjectMaterialPacket)Pack;
7994  
7995 #region Packet Session and User Check
7996 if (m_checkPackets)
7997 {
7998 if (ompacket.AgentData.SessionID != SessionId ||
7999 ompacket.AgentData.AgentID != AgentId)
8000 return true;
8001 }
8002 #endregion
8003  
8004 GenericCall7 handlerObjectMaterial = OnObjectMaterial;
8005 if (handlerObjectMaterial != null)
8006 {
8007 foreach (ObjectMaterialPacket.ObjectDataBlock odata in ompacket.ObjectData)
8008 {
8009 byte material = odata.Material;
8010 uint localID = odata.ObjectLocalID;
8011 handlerObjectMaterial(this, localID, material.ToString());
8012 }
8013 }
8014 return true;
8015 }
8016  
8017 #endregion Objects/m_sceneObjects
8018  
8019 #region Inventory/Asset/Other related packets
8020  
8021 private bool HandleRequestImage(IClientAPI sender, Packet Pack)
8022 {
8023 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
8024 //m_log.Debug("image request: " + Pack.ToString());
8025  
8026 #region Packet Session and User Check
8027 if (m_checkPackets)
8028 {
8029 if (imageRequest.AgentData.SessionID != SessionId ||
8030 imageRequest.AgentData.AgentID != AgentId)
8031 return true;
8032 }
8033 #endregion
8034  
8035 //handlerTextureRequest = null;
8036 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
8037 {
8038 TextureRequestArgs args = new TextureRequestArgs();
8039  
8040 RequestImagePacket.RequestImageBlock block = imageRequest.RequestImage[i];
8041  
8042 args.RequestedAssetID = block.Image;
8043 args.DiscardLevel = block.DiscardLevel;
8044 args.PacketNumber = block.Packet;
8045 args.Priority = block.DownloadPriority;
8046 args.requestSequence = imageRequest.Header.Sequence;
8047  
8048 // NOTE: This is not a built in part of the LLUDP protocol, but we double the
8049 // priority of avatar textures to get avatars rezzing in faster than the
8050 // surrounding scene
8051 if ((ImageType)block.Type == ImageType.Baked)
8052 args.Priority *= 2.0f;
8053  
8054 ImageManager.EnqueueReq(args);
8055 }
8056  
8057 return true;
8058 }
8059  
8060 /// <summary>
8061 /// This is the entry point for the UDP route by which the client can retrieve asset data. If the request
8062 /// is successful then a TransferInfo packet will be sent back, followed by one or more TransferPackets
8063 /// </summary>
8064 /// <param name="sender"></param>
8065 /// <param name="Pack"></param>
8066 /// <returns>This parameter may be ignored since we appear to return true whatever happens</returns>
8067 private bool HandleTransferRequest(IClientAPI sender, Packet Pack)
8068 {
8069 //m_log.Debug("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
8070  
8071 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
8072 UUID taskID = UUID.Zero;
8073 if (transfer.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
8074 {
8075 if (!(((Scene)m_scene).Permissions.BypassPermissions()))
8076 {
8077 // We're spawning a thread because the permissions check can block this thread
8078 Util.FireAndForget(delegate
8079 {
8080 // This requests the asset if needed
8081 HandleSimInventoryTransferRequestWithPermsCheck(sender, transfer);
8082 });
8083 return true;
8084 }
8085 }
8086 else if (transfer.TransferInfo.SourceType == (int)SourceType.SimEstate)
8087 {
8088 //TransferRequestPacket does not include covenant uuid?
8089 //get scene covenant uuid
8090 taskID = m_scene.RegionInfo.RegionSettings.Covenant;
8091 }
8092  
8093 // This is non-blocking
8094 MakeAssetRequest(transfer, taskID);
8095  
8096 return true;
8097 }
8098  
8099 private void HandleSimInventoryTransferRequestWithPermsCheck(IClientAPI sender, TransferRequestPacket transfer)
8100 {
8101 UUID taskID = new UUID(transfer.TransferInfo.Params, 48);
8102 UUID itemID = new UUID(transfer.TransferInfo.Params, 64);
8103 UUID requestID = new UUID(transfer.TransferInfo.Params, 80);
8104  
8105 //m_log.DebugFormat(
8106 // "[CLIENT]: Got request for asset {0} from item {1} in prim {2} by {3}",
8107 // requestID, itemID, taskID, Name);
8108  
8109 //m_log.Debug("Transfer Request: " + transfer.ToString());
8110 // Validate inventory transfers
8111 // Has to be done here, because AssetCache can't do it
8112 //
8113 if (taskID != UUID.Zero) // Prim
8114 {
8115 SceneObjectPart part = ((Scene)m_scene).GetSceneObjectPart(taskID);
8116  
8117 if (part == null)
8118 {
8119 m_log.WarnFormat(
8120 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but prim does not exist",
8121 Name, requestID, itemID, taskID);
8122 return;
8123 }
8124  
8125 TaskInventoryItem tii = part.Inventory.GetInventoryItem(itemID);
8126 if (tii == null)
8127 {
8128 m_log.WarnFormat(
8129 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item does not exist",
8130 Name, requestID, itemID, taskID);
8131 return;
8132 }
8133  
8134 if (tii.Type == (int)AssetType.LSLText)
8135 {
8136 if (!((Scene)m_scene).Permissions.CanEditScript(itemID, taskID, AgentId))
8137 return;
8138 }
8139 else if (tii.Type == (int)AssetType.Notecard)
8140 {
8141 if (!((Scene)m_scene).Permissions.CanEditNotecard(itemID, taskID, AgentId))
8142 return;
8143 }
8144 else
8145 {
8146 // TODO: Change this code to allow items other than notecards and scripts to be successfully
8147 // shared with group. In fact, this whole block of permissions checking should move to an IPermissionsModule
8148 if (part.OwnerID != AgentId)
8149 {
8150 m_log.WarnFormat(
8151 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the prim is owned by {4}",
8152 Name, requestID, itemID, taskID, part.OwnerID);
8153 return;
8154 }
8155  
8156 if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
8157 {
8158 m_log.WarnFormat(
8159 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but modify permissions are not set",
8160 Name, requestID, itemID, taskID);
8161 return;
8162 }
8163  
8164 if (tii.OwnerID != AgentId)
8165 {
8166 m_log.WarnFormat(
8167 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but the item is owned by {4}",
8168 Name, requestID, itemID, taskID, tii.OwnerID);
8169 return;
8170 }
8171  
8172 if ((
8173 tii.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
8174 != ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy | (uint)PermissionMask.Transfer))
8175 {
8176 m_log.WarnFormat(
8177 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but item permissions are not modify/copy/transfer",
8178 Name, requestID, itemID, taskID);
8179 return;
8180 }
8181  
8182 if (tii.AssetID != requestID)
8183 {
8184 m_log.WarnFormat(
8185 "[CLIENT]: {0} requested asset {1} from item {2} in prim {3} but this does not match item's asset {4}",
8186 Name, requestID, itemID, taskID, tii.AssetID);
8187 return;
8188 }
8189 }
8190 }
8191 else // Agent
8192 {
8193 IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
8194 if (invAccess != null)
8195 {
8196 if (!invAccess.CanGetAgentInventoryItem(this, itemID, requestID))
8197 return;
8198 }
8199 else
8200 {
8201 return;
8202 }
8203 }
8204  
8205 // Permissions out of the way, let's request the asset
8206 MakeAssetRequest(transfer, taskID);
8207  
8208 }
8209  
8210  
8211 private bool HandleAssetUploadRequest(IClientAPI sender, Packet Pack)
8212 {
8213 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
8214  
8215 // m_log.Debug("upload request " + request.ToString());
8216 // m_log.Debug("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
8217 UUID temp = UUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
8218  
8219 UDPAssetUploadRequest handlerAssetUploadRequest = OnAssetUploadRequest;
8220  
8221 if (handlerAssetUploadRequest != null)
8222 {
8223 handlerAssetUploadRequest(this, temp,
8224 request.AssetBlock.TransactionID, request.AssetBlock.Type,
8225 request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
8226 request.AssetBlock.Tempfile);
8227 }
8228 return true;
8229 }
8230  
8231 private bool HandleRequestXfer(IClientAPI sender, Packet Pack)
8232 {
8233 RequestXferPacket xferReq = (RequestXferPacket)Pack;
8234  
8235 RequestXfer handlerRequestXfer = OnRequestXfer;
8236  
8237 if (handlerRequestXfer != null)
8238 {
8239 handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
8240 }
8241 return true;
8242 }
8243  
8244 private bool HandleSendXferPacket(IClientAPI sender, Packet Pack)
8245 {
8246 SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
8247  
8248 XferReceive handlerXferReceive = OnXferReceive;
8249 if (handlerXferReceive != null)
8250 {
8251 handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
8252 }
8253 return true;
8254 }
8255  
8256 private bool HandleConfirmXferPacket(IClientAPI sender, Packet Pack)
8257 {
8258 ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
8259  
8260 ConfirmXfer handlerConfirmXfer = OnConfirmXfer;
8261 if (handlerConfirmXfer != null)
8262 {
8263 handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
8264 }
8265 return true;
8266 }
8267  
8268 private bool HandleAbortXfer(IClientAPI sender, Packet Pack)
8269 {
8270 AbortXferPacket abortXfer = (AbortXferPacket)Pack;
8271 AbortXfer handlerAbortXfer = OnAbortXfer;
8272 if (handlerAbortXfer != null)
8273 {
8274 handlerAbortXfer(this, abortXfer.XferID.ID);
8275 }
8276  
8277 return true;
8278 }
8279  
8280 private bool HandleCreateInventoryFolder(IClientAPI sender, Packet Pack)
8281 {
8282 CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
8283  
8284 #region Packet Session and User Check
8285 if (m_checkPackets)
8286 {
8287 if (invFolder.AgentData.SessionID != SessionId ||
8288 invFolder.AgentData.AgentID != AgentId)
8289 return true;
8290 }
8291 #endregion
8292  
8293 CreateInventoryFolder handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
8294 if (handlerCreateInventoryFolder != null)
8295 {
8296 handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
8297 (ushort)invFolder.FolderData.Type,
8298 Util.FieldToString(invFolder.FolderData.Name),
8299 invFolder.FolderData.ParentID);
8300 }
8301 return true;
8302 }
8303  
8304 private bool HandleUpdateInventoryFolder(IClientAPI sender, Packet Pack)
8305 {
8306 if (OnUpdateInventoryFolder != null)
8307 {
8308 UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
8309  
8310 #region Packet Session and User Check
8311 if (m_checkPackets)
8312 {
8313 if (invFolderx.AgentData.SessionID != SessionId ||
8314 invFolderx.AgentData.AgentID != AgentId)
8315 return true;
8316 }
8317 #endregion
8318  
8319 UpdateInventoryFolder handlerUpdateInventoryFolder = null;
8320  
8321 for (int i = 0; i < invFolderx.FolderData.Length; i++)
8322 {
8323 handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
8324 if (handlerUpdateInventoryFolder != null)
8325 {
8326 OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
8327 (ushort)invFolderx.FolderData[i].Type,
8328 Util.FieldToString(invFolderx.FolderData[i].Name),
8329 invFolderx.FolderData[i].ParentID);
8330 }
8331 }
8332 }
8333 return true;
8334 }
8335  
8336 private bool HandleMoveInventoryFolder(IClientAPI sender, Packet Pack)
8337 {
8338 if (OnMoveInventoryFolder != null)
8339 {
8340 MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
8341  
8342 #region Packet Session and User Check
8343 if (m_checkPackets)
8344 {
8345 if (invFoldery.AgentData.SessionID != SessionId ||
8346 invFoldery.AgentData.AgentID != AgentId)
8347 return true;
8348 }
8349 #endregion
8350  
8351 MoveInventoryFolder handlerMoveInventoryFolder = null;
8352  
8353 for (int i = 0; i < invFoldery.InventoryData.Length; i++)
8354 {
8355 handlerMoveInventoryFolder = OnMoveInventoryFolder;
8356 if (handlerMoveInventoryFolder != null)
8357 {
8358 OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
8359 invFoldery.InventoryData[i].ParentID);
8360 }
8361 }
8362 }
8363 return true;
8364 }
8365  
8366 private bool HandleCreateInventoryItem(IClientAPI sender, Packet Pack)
8367 {
8368 CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
8369  
8370 #region Packet Session and User Check
8371 if (m_checkPackets)
8372 {
8373 if (createItem.AgentData.SessionID != SessionId ||
8374 createItem.AgentData.AgentID != AgentId)
8375 return true;
8376 }
8377 #endregion
8378  
8379 CreateNewInventoryItem handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
8380 if (handlerCreateNewInventoryItem != null)
8381 {
8382 handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
8383 createItem.InventoryBlock.FolderID,
8384 createItem.InventoryBlock.CallbackID,
8385 Util.FieldToString(createItem.InventoryBlock.Description),
8386 Util.FieldToString(createItem.InventoryBlock.Name),
8387 createItem.InventoryBlock.InvType,
8388 createItem.InventoryBlock.Type,
8389 createItem.InventoryBlock.WearableType,
8390 createItem.InventoryBlock.NextOwnerMask,
8391 Util.UnixTimeSinceEpoch());
8392 }
8393 return true;
8394 }
8395  
8396 private bool HandleLinkInventoryItem(IClientAPI sender, Packet Pack)
8397 {
8398 LinkInventoryItemPacket createLink = (LinkInventoryItemPacket)Pack;
8399  
8400 #region Packet Session and User Check
8401 if (m_checkPackets)
8402 {
8403 if (createLink.AgentData.SessionID != SessionId ||
8404 createLink.AgentData.AgentID != AgentId)
8405 return true;
8406 }
8407 #endregion
8408  
8409 LinkInventoryItem linkInventoryItem = OnLinkInventoryItem;
8410  
8411 if (linkInventoryItem != null)
8412 {
8413 linkInventoryItem(
8414 this,
8415 createLink.InventoryBlock.TransactionID,
8416 createLink.InventoryBlock.FolderID,
8417 createLink.InventoryBlock.CallbackID,
8418 Util.FieldToString(createLink.InventoryBlock.Description),
8419 Util.FieldToString(createLink.InventoryBlock.Name),
8420 createLink.InventoryBlock.InvType,
8421 createLink.InventoryBlock.Type,
8422 createLink.InventoryBlock.OldItemID);
8423 }
8424  
8425 return true;
8426 }
8427  
8428 private bool HandleFetchInventory(IClientAPI sender, Packet Pack)
8429 {
8430 if (OnFetchInventory != null)
8431 {
8432 FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
8433  
8434 #region Packet Session and User Check
8435 if (m_checkPackets)
8436 {
8437 if (FetchInventoryx.AgentData.SessionID != SessionId ||
8438 FetchInventoryx.AgentData.AgentID != AgentId)
8439 return true;
8440 }
8441 #endregion
8442  
8443 FetchInventory handlerFetchInventory = null;
8444  
8445 for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
8446 {
8447 handlerFetchInventory = OnFetchInventory;
8448  
8449 if (handlerFetchInventory != null)
8450 {
8451 OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
8452 FetchInventoryx.InventoryData[i].OwnerID);
8453 }
8454 }
8455 }
8456 return true;
8457 }
8458  
8459 private bool HandleFetchInventoryDescendents(IClientAPI sender, Packet Pack)
8460 {
8461 FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
8462  
8463 #region Packet Session and User Check
8464 if (m_checkPackets)
8465 {
8466 if (Fetch.AgentData.SessionID != SessionId ||
8467 Fetch.AgentData.AgentID != AgentId)
8468 return true;
8469 }
8470 #endregion
8471  
8472 FetchInventoryDescendents handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
8473 if (handlerFetchInventoryDescendents != null)
8474 {
8475 handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
8476 Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
8477 Fetch.InventoryData.SortOrder);
8478 }
8479 return true;
8480 }
8481  
8482 private bool HandlePurgeInventoryDescendents(IClientAPI sender, Packet Pack)
8483 {
8484 PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
8485  
8486 #region Packet Session and User Check
8487 if (m_checkPackets)
8488 {
8489 if (Purge.AgentData.SessionID != SessionId ||
8490 Purge.AgentData.AgentID != AgentId)
8491 return true;
8492 }
8493 #endregion
8494  
8495 PurgeInventoryDescendents handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
8496 if (handlerPurgeInventoryDescendents != null)
8497 {
8498 handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
8499 }
8500 return true;
8501 }
8502  
8503 private bool HandleUpdateInventoryItem(IClientAPI sender, Packet Pack)
8504 {
8505 UpdateInventoryItemPacket inventoryItemUpdate = (UpdateInventoryItemPacket)Pack;
8506  
8507 #region Packet Session and User Check
8508 if (m_checkPackets)
8509 {
8510 if (inventoryItemUpdate.AgentData.SessionID != SessionId ||
8511 inventoryItemUpdate.AgentData.AgentID != AgentId)
8512 return true;
8513 }
8514 #endregion
8515  
8516 if (OnUpdateInventoryItem != null)
8517 {
8518 UpdateInventoryItem handlerUpdateInventoryItem = null;
8519 for (int i = 0; i < inventoryItemUpdate.InventoryData.Length; i++)
8520 {
8521 handlerUpdateInventoryItem = OnUpdateInventoryItem;
8522  
8523 if (handlerUpdateInventoryItem != null)
8524 {
8525 InventoryItemBase itemUpd = new InventoryItemBase();
8526 itemUpd.ID = inventoryItemUpdate.InventoryData[i].ItemID;
8527 itemUpd.Name = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Name);
8528 itemUpd.Description = Util.FieldToString(inventoryItemUpdate.InventoryData[i].Description);
8529 itemUpd.GroupID = inventoryItemUpdate.InventoryData[i].GroupID;
8530 itemUpd.GroupOwned = inventoryItemUpdate.InventoryData[i].GroupOwned;
8531 itemUpd.GroupPermissions = inventoryItemUpdate.InventoryData[i].GroupMask;
8532 itemUpd.NextPermissions = inventoryItemUpdate.InventoryData[i].NextOwnerMask;
8533 itemUpd.EveryOnePermissions = inventoryItemUpdate.InventoryData[i].EveryoneMask;
8534 itemUpd.CreationDate = inventoryItemUpdate.InventoryData[i].CreationDate;
8535 itemUpd.Folder = inventoryItemUpdate.InventoryData[i].FolderID;
8536 itemUpd.InvType = inventoryItemUpdate.InventoryData[i].InvType;
8537 itemUpd.SalePrice = inventoryItemUpdate.InventoryData[i].SalePrice;
8538 itemUpd.SaleType = inventoryItemUpdate.InventoryData[i].SaleType;
8539 itemUpd.Flags = inventoryItemUpdate.InventoryData[i].Flags;
8540  
8541 OnUpdateInventoryItem(this, inventoryItemUpdate.InventoryData[i].TransactionID,
8542 inventoryItemUpdate.InventoryData[i].ItemID,
8543 itemUpd);
8544 }
8545 }
8546 }
8547 return true;
8548 }
8549  
8550 private bool HandleCopyInventoryItem(IClientAPI sender, Packet Pack)
8551 {
8552 CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
8553  
8554 #region Packet Session and User Check
8555 if (m_checkPackets)
8556 {
8557 if (copyitem.AgentData.SessionID != SessionId ||
8558 copyitem.AgentData.AgentID != AgentId)
8559 return true;
8560 }
8561 #endregion
8562  
8563 CopyInventoryItem handlerCopyInventoryItem = null;
8564 if (OnCopyInventoryItem != null)
8565 {
8566 foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
8567 {
8568 handlerCopyInventoryItem = OnCopyInventoryItem;
8569 if (handlerCopyInventoryItem != null)
8570 {
8571 handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
8572 datablock.OldItemID, datablock.NewFolderID,
8573 Util.FieldToString(datablock.NewName));
8574 }
8575 }
8576 }
8577 return true;
8578 }
8579  
8580 private bool HandleMoveInventoryItem(IClientAPI sender, Packet Pack)
8581 {
8582 MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
8583  
8584 #region Packet Session and User Check
8585 if (m_checkPackets)
8586 {
8587 if (moveitem.AgentData.SessionID != SessionId ||
8588 moveitem.AgentData.AgentID != AgentId)
8589 return true;
8590 }
8591 #endregion
8592  
8593 if (OnMoveInventoryItem != null)
8594 {
8595 MoveInventoryItem handlerMoveInventoryItem = null;
8596 InventoryItemBase itm = null;
8597 List<InventoryItemBase> items = new List<InventoryItemBase>();
8598 foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
8599 {
8600 itm = new InventoryItemBase(datablock.ItemID, AgentId);
8601 itm.Folder = datablock.FolderID;
8602 itm.Name = Util.FieldToString(datablock.NewName);
8603 // weird, comes out as empty string
8604 //m_log.DebugFormat("[XXX] new name: {0}", itm.Name);
8605 items.Add(itm);
8606 }
8607 handlerMoveInventoryItem = OnMoveInventoryItem;
8608 if (handlerMoveInventoryItem != null)
8609 {
8610 handlerMoveInventoryItem(this, items);
8611 }
8612 }
8613 return true;
8614 }
8615  
8616 private bool HandleRemoveInventoryItem(IClientAPI sender, Packet Pack)
8617 {
8618 RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
8619  
8620 #region Packet Session and User Check
8621 if (m_checkPackets)
8622 {
8623 if (removeItem.AgentData.SessionID != SessionId ||
8624 removeItem.AgentData.AgentID != AgentId)
8625 return true;
8626 }
8627 #endregion
8628  
8629 if (OnRemoveInventoryItem != null)
8630 {
8631 RemoveInventoryItem handlerRemoveInventoryItem = null;
8632 List<UUID> uuids = new List<UUID>();
8633 foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
8634 {
8635 uuids.Add(datablock.ItemID);
8636 }
8637 handlerRemoveInventoryItem = OnRemoveInventoryItem;
8638 if (handlerRemoveInventoryItem != null)
8639 {
8640 handlerRemoveInventoryItem(this, uuids);
8641 }
8642  
8643 }
8644 return true;
8645 }
8646  
8647 private bool HandleRemoveInventoryFolder(IClientAPI sender, Packet Pack)
8648 {
8649 RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
8650  
8651 #region Packet Session and User Check
8652 if (m_checkPackets)
8653 {
8654 if (removeFolder.AgentData.SessionID != SessionId ||
8655 removeFolder.AgentData.AgentID != AgentId)
8656 return true;
8657 }
8658 #endregion
8659  
8660 if (OnRemoveInventoryFolder != null)
8661 {
8662 RemoveInventoryFolder handlerRemoveInventoryFolder = null;
8663 List<UUID> uuids = new List<UUID>();
8664 foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
8665 {
8666 uuids.Add(datablock.FolderID);
8667 }
8668 handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
8669 if (handlerRemoveInventoryFolder != null)
8670 {
8671 handlerRemoveInventoryFolder(this, uuids);
8672 }
8673 }
8674 return true;
8675 }
8676  
8677 private bool HandleRemoveInventoryObjects(IClientAPI sender, Packet Pack)
8678 {
8679 RemoveInventoryObjectsPacket removeObject = (RemoveInventoryObjectsPacket)Pack;
8680 #region Packet Session and User Check
8681 if (m_checkPackets)
8682 {
8683 if (removeObject.AgentData.SessionID != SessionId ||
8684 removeObject.AgentData.AgentID != AgentId)
8685 return true;
8686 }
8687 #endregion
8688 if (OnRemoveInventoryFolder != null)
8689 {
8690 RemoveInventoryFolder handlerRemoveInventoryFolder = null;
8691 List<UUID> uuids = new List<UUID>();
8692 foreach (RemoveInventoryObjectsPacket.FolderDataBlock datablock in removeObject.FolderData)
8693 {
8694 uuids.Add(datablock.FolderID);
8695 }
8696 handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
8697 if (handlerRemoveInventoryFolder != null)
8698 {
8699 handlerRemoveInventoryFolder(this, uuids);
8700 }
8701 }
8702  
8703 if (OnRemoveInventoryItem != null)
8704 {
8705 RemoveInventoryItem handlerRemoveInventoryItem = null;
8706 List<UUID> uuids = new List<UUID>();
8707 foreach (RemoveInventoryObjectsPacket.ItemDataBlock datablock in removeObject.ItemData)
8708 {
8709 uuids.Add(datablock.ItemID);
8710 }
8711 handlerRemoveInventoryItem = OnRemoveInventoryItem;
8712 if (handlerRemoveInventoryItem != null)
8713 {
8714 handlerRemoveInventoryItem(this, uuids);
8715 }
8716 }
8717 return true;
8718 }
8719  
8720 private bool HandleRequestTaskInventory(IClientAPI sender, Packet Pack)
8721 {
8722 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
8723  
8724 #region Packet Session and User Check
8725 if (m_checkPackets)
8726 {
8727 if (requesttask.AgentData.SessionID != SessionId ||
8728 requesttask.AgentData.AgentID != AgentId)
8729 return true;
8730 }
8731 #endregion
8732  
8733 RequestTaskInventory handlerRequestTaskInventory = OnRequestTaskInventory;
8734 if (handlerRequestTaskInventory != null)
8735 {
8736 handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
8737 }
8738 return true;
8739 }
8740  
8741 private bool HandleUpdateTaskInventory(IClientAPI sender, Packet Pack)
8742 {
8743 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
8744  
8745 #region Packet Session and User Check
8746 if (m_checkPackets)
8747 {
8748 if (updatetask.AgentData.SessionID != SessionId ||
8749 updatetask.AgentData.AgentID != AgentId)
8750 return true;
8751 }
8752 #endregion
8753  
8754 if (OnUpdateTaskInventory != null)
8755 {
8756 if (updatetask.UpdateData.Key == 0)
8757 {
8758 UpdateTaskInventory handlerUpdateTaskInventory = OnUpdateTaskInventory;
8759 if (handlerUpdateTaskInventory != null)
8760 {
8761 TaskInventoryItem newTaskItem = new TaskInventoryItem();
8762 newTaskItem.ItemID = updatetask.InventoryData.ItemID;
8763 newTaskItem.ParentID = updatetask.InventoryData.FolderID;
8764 newTaskItem.CreatorID = updatetask.InventoryData.CreatorID;
8765 newTaskItem.OwnerID = updatetask.InventoryData.OwnerID;
8766 newTaskItem.GroupID = updatetask.InventoryData.GroupID;
8767 newTaskItem.BasePermissions = updatetask.InventoryData.BaseMask;
8768 newTaskItem.CurrentPermissions = updatetask.InventoryData.OwnerMask;
8769 newTaskItem.GroupPermissions = updatetask.InventoryData.GroupMask;
8770 newTaskItem.EveryonePermissions = updatetask.InventoryData.EveryoneMask;
8771 newTaskItem.NextPermissions = updatetask.InventoryData.NextOwnerMask;
8772  
8773 // Unused? Clicking share with group sets GroupPermissions instead, so perhaps this is something
8774 // different
8775 //newTaskItem.GroupOwned=updatetask.InventoryData.GroupOwned;
8776 newTaskItem.Type = updatetask.InventoryData.Type;
8777 newTaskItem.InvType = updatetask.InventoryData.InvType;
8778 newTaskItem.Flags = updatetask.InventoryData.Flags;
8779 //newTaskItem.SaleType=updatetask.InventoryData.SaleType;
8780 //newTaskItem.SalePrice=updatetask.InventoryData.SalePrice;
8781 newTaskItem.Name = Util.FieldToString(updatetask.InventoryData.Name);
8782 newTaskItem.Description = Util.FieldToString(updatetask.InventoryData.Description);
8783 newTaskItem.CreationDate = (uint)updatetask.InventoryData.CreationDate;
8784 handlerUpdateTaskInventory(this, updatetask.InventoryData.TransactionID,
8785 newTaskItem, updatetask.UpdateData.LocalID);
8786 }
8787 }
8788 }
8789  
8790 return true;
8791 }
8792  
8793 private bool HandleRemoveTaskInventory(IClientAPI sender, Packet Pack)
8794 {
8795 RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
8796  
8797 #region Packet Session and User Check
8798 if (m_checkPackets)
8799 {
8800 if (removeTask.AgentData.SessionID != SessionId ||
8801 removeTask.AgentData.AgentID != AgentId)
8802 return true;
8803 }
8804 #endregion
8805  
8806 RemoveTaskInventory handlerRemoveTaskItem = OnRemoveTaskItem;
8807  
8808 if (handlerRemoveTaskItem != null)
8809 {
8810 handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
8811 }
8812  
8813 return true;
8814 }
8815  
8816 private bool HandleMoveTaskInventory(IClientAPI sender, Packet Pack)
8817 {
8818 MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
8819  
8820 #region Packet Session and User Check
8821 if (m_checkPackets)
8822 {
8823 if (moveTaskInventoryPacket.AgentData.SessionID != SessionId ||
8824 moveTaskInventoryPacket.AgentData.AgentID != AgentId)
8825 return true;
8826 }
8827 #endregion
8828  
8829 MoveTaskInventory handlerMoveTaskItem = OnMoveTaskItem;
8830  
8831 if (handlerMoveTaskItem != null)
8832 {
8833 handlerMoveTaskItem(
8834 this, moveTaskInventoryPacket.AgentData.FolderID,
8835 moveTaskInventoryPacket.InventoryData.LocalID,
8836 moveTaskInventoryPacket.InventoryData.ItemID);
8837 }
8838  
8839 return true;
8840 }
8841  
8842 private bool HandleRezScript(IClientAPI sender, Packet Pack)
8843 {
8844 //m_log.Debug(Pack.ToString());
8845 RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
8846  
8847 #region Packet Session and User Check
8848 if (m_checkPackets)
8849 {
8850 if (rezScriptx.AgentData.SessionID != SessionId ||
8851 rezScriptx.AgentData.AgentID != AgentId)
8852 return true;
8853 }
8854 #endregion
8855  
8856 RezScript handlerRezScript = OnRezScript;
8857 InventoryItemBase item = new InventoryItemBase();
8858 item.ID = rezScriptx.InventoryBlock.ItemID;
8859 item.Folder = rezScriptx.InventoryBlock.FolderID;
8860 item.CreatorId = rezScriptx.InventoryBlock.CreatorID.ToString();
8861 item.Owner = rezScriptx.InventoryBlock.OwnerID;
8862 item.BasePermissions = rezScriptx.InventoryBlock.BaseMask;
8863 item.CurrentPermissions = rezScriptx.InventoryBlock.OwnerMask;
8864 item.EveryOnePermissions = rezScriptx.InventoryBlock.EveryoneMask;
8865 item.NextPermissions = rezScriptx.InventoryBlock.NextOwnerMask;
8866 item.GroupPermissions = rezScriptx.InventoryBlock.GroupMask;
8867 item.GroupOwned = rezScriptx.InventoryBlock.GroupOwned;
8868 item.GroupID = rezScriptx.InventoryBlock.GroupID;
8869 item.AssetType = rezScriptx.InventoryBlock.Type;
8870 item.InvType = rezScriptx.InventoryBlock.InvType;
8871 item.Flags = rezScriptx.InventoryBlock.Flags;
8872 item.SaleType = rezScriptx.InventoryBlock.SaleType;
8873 item.SalePrice = rezScriptx.InventoryBlock.SalePrice;
8874 item.Name = Util.FieldToString(rezScriptx.InventoryBlock.Name);
8875 item.Description = Util.FieldToString(rezScriptx.InventoryBlock.Description);
8876 item.CreationDate = rezScriptx.InventoryBlock.CreationDate;
8877  
8878 if (handlerRezScript != null)
8879 {
8880 handlerRezScript(this, item, rezScriptx.InventoryBlock.TransactionID, rezScriptx.UpdateBlock.ObjectLocalID);
8881 }
8882 return true;
8883 }
8884  
8885 private bool HandleMapLayerRequest(IClientAPI sender, Packet Pack)
8886 {
8887 RequestMapLayer();
8888 return true;
8889 }
8890  
8891 private bool HandleMapBlockRequest(IClientAPI sender, Packet Pack)
8892 {
8893 MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
8894  
8895 #region Packet Session and User Check
8896 if (m_checkPackets)
8897 {
8898 if (MapRequest.AgentData.SessionID != SessionId ||
8899 MapRequest.AgentData.AgentID != AgentId)
8900 return true;
8901 }
8902 #endregion
8903  
8904 RequestMapBlocks handlerRequestMapBlocks = OnRequestMapBlocks;
8905 if (handlerRequestMapBlocks != null)
8906 {
8907 handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
8908 MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY, MapRequest.AgentData.Flags);
8909 }
8910 return true;
8911 }
8912  
8913 private bool HandleMapNameRequest(IClientAPI sender, Packet Pack)
8914 {
8915 MapNameRequestPacket map = (MapNameRequestPacket)Pack;
8916  
8917 #region Packet Session and User Check
8918 if (m_checkPackets)
8919 {
8920 if (map.AgentData.SessionID != SessionId ||
8921 map.AgentData.AgentID != AgentId)
8922 return true;
8923 }
8924 #endregion
8925 string mapName = Util.UTF8.GetString(map.NameData.Name, 0,
8926 map.NameData.Name.Length - 1);
8927 RequestMapName handlerMapNameRequest = OnMapNameRequest;
8928 if (handlerMapNameRequest != null)
8929 {
8930 handlerMapNameRequest(this, mapName, map.AgentData.Flags);
8931 }
8932 return true;
8933 }
8934  
8935 private bool HandleTeleportLandmarkRequest(IClientAPI sender, Packet Pack)
8936 {
8937 TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
8938  
8939 #region Packet Session and User Check
8940 if (m_checkPackets)
8941 {
8942 if (tpReq.Info.SessionID != SessionId ||
8943 tpReq.Info.AgentID != AgentId)
8944 return true;
8945 }
8946 #endregion
8947  
8948 UUID lmid = tpReq.Info.LandmarkID;
8949 AssetLandmark lm;
8950 if (lmid != UUID.Zero)
8951 {
8952  
8953 //AssetBase lma = m_assetCache.GetAsset(lmid, false);
8954 AssetBase lma = m_assetService.Get(lmid.ToString());
8955  
8956 if (lma == null)
8957 {
8958 // Failed to find landmark
8959  
8960 // Let's try to search in the user's home asset server
8961 lma = FindAssetInUserAssetServer(lmid.ToString());
8962  
8963 if (lma == null)
8964 {
8965 // Really doesn't exist
8966 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
8967 tpCancel.Info.SessionID = tpReq.Info.SessionID;
8968 tpCancel.Info.AgentID = tpReq.Info.AgentID;
8969 OutPacket(tpCancel, ThrottleOutPacketType.Task);
8970 }
8971 }
8972  
8973 try
8974 {
8975 lm = new AssetLandmark(lma);
8976 }
8977 catch (NullReferenceException)
8978 {
8979 // asset not found generates null ref inside the assetlandmark constructor.
8980 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
8981 tpCancel.Info.SessionID = tpReq.Info.SessionID;
8982 tpCancel.Info.AgentID = tpReq.Info.AgentID;
8983 OutPacket(tpCancel, ThrottleOutPacketType.Task);
8984 return true;
8985 }
8986 }
8987 else
8988 {
8989 // Teleport home request
8990 UUIDNameRequest handlerTeleportHomeRequest = OnTeleportHomeRequest;
8991 if (handlerTeleportHomeRequest != null)
8992 {
8993 handlerTeleportHomeRequest(AgentId, this);
8994 }
8995 return true;
8996 }
8997  
8998 TeleportLandmarkRequest handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
8999 if (handlerTeleportLandmarkRequest != null)
9000 {
9001 handlerTeleportLandmarkRequest(this, lm);
9002 }
9003 else
9004 {
9005 //no event handler so cancel request
9006 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
9007 tpCancel.Info.AgentID = tpReq.Info.AgentID;
9008 tpCancel.Info.SessionID = tpReq.Info.SessionID;
9009 OutPacket(tpCancel, ThrottleOutPacketType.Task);
9010  
9011 }
9012 return true;
9013 }
9014  
9015 private bool HandleTeleportCancel(IClientAPI sender, Packet Pack)
9016 {
9017 TeleportCancel handlerTeleportCancel = OnTeleportCancel;
9018 if (handlerTeleportCancel != null)
9019 {
9020 handlerTeleportCancel(this);
9021 }
9022 return true;
9023 }
9024  
9025 private AssetBase FindAssetInUserAssetServer(string id)
9026 {
9027 AgentCircuitData aCircuit = ((Scene)Scene).AuthenticateHandler.GetAgentCircuitData(CircuitCode);
9028 if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
9029 {
9030 string assetServer = aCircuit.ServiceURLs["AssetServerURI"].ToString();
9031 if (!string.IsNullOrEmpty(assetServer))
9032 return ((Scene)Scene).AssetService.Get(assetServer + "/" + id);
9033 }
9034  
9035 return null;
9036 }
9037  
9038 private bool HandleTeleportLocationRequest(IClientAPI sender, Packet Pack)
9039 {
9040 TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
9041 // m_log.Debug(tpLocReq.ToString());
9042  
9043 #region Packet Session and User Check
9044 if (m_checkPackets)
9045 {
9046 if (tpLocReq.AgentData.SessionID != SessionId ||
9047 tpLocReq.AgentData.AgentID != AgentId)
9048 return true;
9049 }
9050 #endregion
9051  
9052 TeleportLocationRequest handlerTeleportLocationRequest = OnTeleportLocationRequest;
9053 if (handlerTeleportLocationRequest != null)
9054 {
9055 // Adjust teleport location to base of a larger region if requested to teleport to a sub-region
9056 uint locX, locY;
9057 Util.RegionHandleToWorldLoc(tpLocReq.Info.RegionHandle, out locX, out locY);
9058 if ((locX >= m_scene.RegionInfo.WorldLocX)
9059 && (locX < (m_scene.RegionInfo.WorldLocX + m_scene.RegionInfo.RegionSizeX))
9060 && (locY >= m_scene.RegionInfo.WorldLocY)
9061 && (locY < (m_scene.RegionInfo.WorldLocY + m_scene.RegionInfo.RegionSizeY)) )
9062 {
9063 tpLocReq.Info.RegionHandle = m_scene.RegionInfo.RegionHandle;
9064 tpLocReq.Info.Position.X += locX - m_scene.RegionInfo.WorldLocX;
9065 tpLocReq.Info.Position.Y += locY - m_scene.RegionInfo.WorldLocY;
9066 }
9067  
9068 handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
9069 tpLocReq.Info.LookAt, 16);
9070 }
9071 else
9072 {
9073 //no event handler so cancel request
9074 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
9075 tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
9076 tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
9077 OutPacket(tpCancel, ThrottleOutPacketType.Task);
9078 }
9079 return true;
9080 }
9081  
9082 #endregion Inventory/Asset/Other related packets
9083  
9084 private bool HandleUUIDNameRequest(IClientAPI sender, Packet Pack)
9085 {
9086 UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
9087  
9088 foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
9089 {
9090 UUIDNameRequest handlerNameRequest = OnNameFromUUIDRequest;
9091 if (handlerNameRequest != null)
9092 {
9093 handlerNameRequest(UUIDBlock.ID, this);
9094 }
9095 }
9096 return true;
9097 }
9098  
9099 #region Parcel related packets
9100  
9101 private bool HandleRegionHandleRequest(IClientAPI sender, Packet Pack)
9102 {
9103 RegionHandleRequestPacket rhrPack = (RegionHandleRequestPacket)Pack;
9104  
9105 RegionHandleRequest handlerRegionHandleRequest = OnRegionHandleRequest;
9106 if (handlerRegionHandleRequest != null)
9107 {
9108 handlerRegionHandleRequest(this, rhrPack.RequestBlock.RegionID);
9109 }
9110 return true;
9111 }
9112  
9113 private bool HandleParcelInfoRequest(IClientAPI sender, Packet Pack)
9114 {
9115 ParcelInfoRequestPacket pirPack = (ParcelInfoRequestPacket)Pack;
9116  
9117 #region Packet Session and User Check
9118 if (m_checkPackets)
9119 {
9120 if (pirPack.AgentData.SessionID != SessionId ||
9121 pirPack.AgentData.AgentID != AgentId)
9122 return true;
9123 }
9124 #endregion
9125  
9126 ParcelInfoRequest handlerParcelInfoRequest = OnParcelInfoRequest;
9127 if (handlerParcelInfoRequest != null)
9128 {
9129 handlerParcelInfoRequest(this, pirPack.Data.ParcelID);
9130 }
9131 return true;
9132 }
9133  
9134 private bool HandleParcelAccessListRequest(IClientAPI sender, Packet Pack)
9135 {
9136 ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
9137  
9138 #region Packet Session and User Check
9139 if (m_checkPackets)
9140 {
9141 if (requestPacket.AgentData.SessionID != SessionId ||
9142 requestPacket.AgentData.AgentID != AgentId)
9143 return true;
9144 }
9145 #endregion
9146  
9147 ParcelAccessListRequest handlerParcelAccessListRequest = OnParcelAccessListRequest;
9148  
9149 if (handlerParcelAccessListRequest != null)
9150 {
9151 handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
9152 requestPacket.Data.Flags, requestPacket.Data.SequenceID,
9153 requestPacket.Data.LocalID, this);
9154 }
9155 return true;
9156 }
9157  
9158 private bool HandleParcelAccessListUpdate(IClientAPI sender, Packet Pack)
9159 {
9160 ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
9161  
9162 #region Packet Session and User Check
9163 if (m_checkPackets)
9164 {
9165 if (updatePacket.AgentData.SessionID != SessionId ||
9166 updatePacket.AgentData.AgentID != AgentId)
9167 return true;
9168 }
9169 #endregion
9170  
9171 List<LandAccessEntry> entries = new List<LandAccessEntry>();
9172 foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
9173 {
9174 LandAccessEntry entry = new LandAccessEntry();
9175 entry.AgentID = block.ID;
9176 entry.Flags = (AccessList)block.Flags;
9177 entry.Expires = block.Time;
9178 entries.Add(entry);
9179 }
9180  
9181 ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
9182 if (handlerParcelAccessListUpdateRequest != null)
9183 {
9184 handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
9185 updatePacket.Data.Flags,
9186 updatePacket.Data.LocalID,
9187 updatePacket.Data.TransactionID,
9188 updatePacket.Data.SequenceID,
9189 updatePacket.Data.Sections,
9190 entries, this);
9191 }
9192 return true;
9193 }
9194  
9195 private bool HandleParcelPropertiesRequest(IClientAPI sender, Packet Pack)
9196 {
9197 ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
9198  
9199 #region Packet Session and User Check
9200 if (m_checkPackets)
9201 {
9202 if (propertiesRequest.AgentData.SessionID != SessionId ||
9203 propertiesRequest.AgentData.AgentID != AgentId)
9204 return true;
9205 }
9206 #endregion
9207  
9208 ParcelPropertiesRequest handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
9209 if (handlerParcelPropertiesRequest != null)
9210 {
9211 handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
9212 (int)Math.Round(propertiesRequest.ParcelData.South),
9213 (int)Math.Round(propertiesRequest.ParcelData.East),
9214 (int)Math.Round(propertiesRequest.ParcelData.North),
9215 propertiesRequest.ParcelData.SequenceID,
9216 propertiesRequest.ParcelData.SnapSelection, this);
9217 }
9218 return true;
9219 }
9220  
9221 private bool HandleParcelDivide(IClientAPI sender, Packet Pack)
9222 {
9223 ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
9224  
9225 #region Packet Session and User Check
9226 if (m_checkPackets)
9227 {
9228 if (landDivide.AgentData.SessionID != SessionId ||
9229 landDivide.AgentData.AgentID != AgentId)
9230 return true;
9231 }
9232 #endregion
9233  
9234 ParcelDivideRequest handlerParcelDivideRequest = OnParcelDivideRequest;
9235 if (handlerParcelDivideRequest != null)
9236 {
9237 handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
9238 (int)Math.Round(landDivide.ParcelData.South),
9239 (int)Math.Round(landDivide.ParcelData.East),
9240 (int)Math.Round(landDivide.ParcelData.North), this);
9241 }
9242 return true;
9243 }
9244  
9245 private bool HandleParcelJoin(IClientAPI sender, Packet Pack)
9246 {
9247 ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
9248  
9249 #region Packet Session and User Check
9250 if (m_checkPackets)
9251 {
9252 if (landJoin.AgentData.SessionID != SessionId ||
9253 landJoin.AgentData.AgentID != AgentId)
9254 return true;
9255 }
9256 #endregion
9257  
9258 ParcelJoinRequest handlerParcelJoinRequest = OnParcelJoinRequest;
9259  
9260 if (handlerParcelJoinRequest != null)
9261 {
9262 handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
9263 (int)Math.Round(landJoin.ParcelData.South),
9264 (int)Math.Round(landJoin.ParcelData.East),
9265 (int)Math.Round(landJoin.ParcelData.North), this);
9266 }
9267 return true;
9268 }
9269  
9270 private bool HandleParcelPropertiesUpdate(IClientAPI sender, Packet Pack)
9271 {
9272 ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
9273  
9274 #region Packet Session and User Check
9275 if (m_checkPackets)
9276 {
9277 if (parcelPropertiesPacket.AgentData.SessionID != SessionId ||
9278 parcelPropertiesPacket.AgentData.AgentID != AgentId)
9279 return true;
9280 }
9281 #endregion
9282  
9283 ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
9284  
9285 if (handlerParcelPropertiesUpdateRequest != null)
9286 {
9287 LandUpdateArgs args = new LandUpdateArgs();
9288  
9289 args.AuthBuyerID = parcelPropertiesPacket.ParcelData.AuthBuyerID;
9290 args.Category = (ParcelCategory)parcelPropertiesPacket.ParcelData.Category;
9291 args.Desc = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Desc);
9292 args.GroupID = parcelPropertiesPacket.ParcelData.GroupID;
9293 args.LandingType = parcelPropertiesPacket.ParcelData.LandingType;
9294 args.MediaAutoScale = parcelPropertiesPacket.ParcelData.MediaAutoScale;
9295 args.MediaID = parcelPropertiesPacket.ParcelData.MediaID;
9296 args.MediaURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MediaURL);
9297 args.MusicURL = Utils.BytesToString(parcelPropertiesPacket.ParcelData.MusicURL);
9298 args.Name = Utils.BytesToString(parcelPropertiesPacket.ParcelData.Name);
9299 args.ParcelFlags = parcelPropertiesPacket.ParcelData.ParcelFlags;
9300 args.PassHours = parcelPropertiesPacket.ParcelData.PassHours;
9301 args.PassPrice = parcelPropertiesPacket.ParcelData.PassPrice;
9302 args.SalePrice = parcelPropertiesPacket.ParcelData.SalePrice;
9303 args.SnapshotID = parcelPropertiesPacket.ParcelData.SnapshotID;
9304 args.UserLocation = parcelPropertiesPacket.ParcelData.UserLocation;
9305 args.UserLookAt = parcelPropertiesPacket.ParcelData.UserLookAt;
9306 handlerParcelPropertiesUpdateRequest(args, parcelPropertiesPacket.ParcelData.LocalID, this);
9307 }
9308 return true;
9309 }
9310  
9311 private bool HandleParcelSelectObjects(IClientAPI sender, Packet Pack)
9312 {
9313 ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
9314  
9315 #region Packet Session and User Check
9316 if (m_checkPackets)
9317 {
9318 if (selectPacket.AgentData.SessionID != SessionId ||
9319 selectPacket.AgentData.AgentID != AgentId)
9320 return true;
9321 }
9322 #endregion
9323  
9324 List<UUID> returnIDs = new List<UUID>();
9325  
9326 foreach (ParcelSelectObjectsPacket.ReturnIDsBlock rb in
9327 selectPacket.ReturnIDs)
9328 {
9329 returnIDs.Add(rb.ReturnID);
9330 }
9331  
9332 ParcelSelectObjects handlerParcelSelectObjects = OnParcelSelectObjects;
9333  
9334 if (handlerParcelSelectObjects != null)
9335 {
9336 handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
9337 Convert.ToInt32(selectPacket.ParcelData.ReturnType), returnIDs, this);
9338 }
9339 return true;
9340 }
9341  
9342 private bool HandleParcelObjectOwnersRequest(IClientAPI sender, Packet Pack)
9343 {
9344 ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
9345  
9346 #region Packet Session and User Check
9347 if (m_checkPackets)
9348 {
9349 if (reqPacket.AgentData.SessionID != SessionId ||
9350 reqPacket.AgentData.AgentID != AgentId)
9351 return true;
9352 }
9353 #endregion
9354  
9355 ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
9356  
9357 if (handlerParcelObjectOwnerRequest != null)
9358 {
9359 handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
9360 }
9361 return true;
9362  
9363 }
9364  
9365 private bool HandleParcelGodForceOwner(IClientAPI sender, Packet Pack)
9366 {
9367 ParcelGodForceOwnerPacket godForceOwnerPacket = (ParcelGodForceOwnerPacket)Pack;
9368  
9369 #region Packet Session and User Check
9370 if (m_checkPackets)
9371 {
9372 if (godForceOwnerPacket.AgentData.SessionID != SessionId ||
9373 godForceOwnerPacket.AgentData.AgentID != AgentId)
9374 return true;
9375 }
9376 #endregion
9377  
9378 ParcelGodForceOwner handlerParcelGodForceOwner = OnParcelGodForceOwner;
9379 if (handlerParcelGodForceOwner != null)
9380 {
9381 handlerParcelGodForceOwner(godForceOwnerPacket.Data.LocalID, godForceOwnerPacket.Data.OwnerID, this);
9382 }
9383 return true;
9384 }
9385  
9386 private bool HandleParcelRelease(IClientAPI sender, Packet Pack)
9387 {
9388 ParcelReleasePacket releasePacket = (ParcelReleasePacket)Pack;
9389  
9390 #region Packet Session and User Check
9391 if (m_checkPackets)
9392 {
9393 if (releasePacket.AgentData.SessionID != SessionId ||
9394 releasePacket.AgentData.AgentID != AgentId)
9395 return true;
9396 }
9397 #endregion
9398  
9399 ParcelAbandonRequest handlerParcelAbandonRequest = OnParcelAbandonRequest;
9400 if (handlerParcelAbandonRequest != null)
9401 {
9402 handlerParcelAbandonRequest(releasePacket.Data.LocalID, this);
9403 }
9404 return true;
9405 }
9406  
9407 private bool HandleParcelReclaim(IClientAPI sender, Packet Pack)
9408 {
9409 ParcelReclaimPacket reclaimPacket = (ParcelReclaimPacket)Pack;
9410  
9411 #region Packet Session and User Check
9412 if (m_checkPackets)
9413 {
9414 if (reclaimPacket.AgentData.SessionID != SessionId ||
9415 reclaimPacket.AgentData.AgentID != AgentId)
9416 return true;
9417 }
9418 #endregion
9419  
9420 ParcelReclaim handlerParcelReclaim = OnParcelReclaim;
9421 if (handlerParcelReclaim != null)
9422 {
9423 handlerParcelReclaim(reclaimPacket.Data.LocalID, this);
9424 }
9425 return true;
9426 }
9427  
9428 private bool HandleParcelReturnObjects(IClientAPI sender, Packet Pack)
9429 {
9430 ParcelReturnObjectsPacket parcelReturnObjects = (ParcelReturnObjectsPacket)Pack;
9431  
9432 #region Packet Session and User Check
9433 if (m_checkPackets)
9434 {
9435 if (parcelReturnObjects.AgentData.SessionID != SessionId ||
9436 parcelReturnObjects.AgentData.AgentID != AgentId)
9437 return true;
9438 }
9439 #endregion
9440  
9441 UUID[] puserselectedOwnerIDs = new UUID[parcelReturnObjects.OwnerIDs.Length];
9442 for (int parceliterator = 0; parceliterator < parcelReturnObjects.OwnerIDs.Length; parceliterator++)
9443 puserselectedOwnerIDs[parceliterator] = parcelReturnObjects.OwnerIDs[parceliterator].OwnerID;
9444  
9445 UUID[] puserselectedTaskIDs = new UUID[parcelReturnObjects.TaskIDs.Length];
9446  
9447 for (int parceliterator = 0; parceliterator < parcelReturnObjects.TaskIDs.Length; parceliterator++)
9448 puserselectedTaskIDs[parceliterator] = parcelReturnObjects.TaskIDs[parceliterator].TaskID;
9449  
9450 ParcelReturnObjectsRequest handlerParcelReturnObjectsRequest = OnParcelReturnObjectsRequest;
9451 if (handlerParcelReturnObjectsRequest != null)
9452 {
9453 handlerParcelReturnObjectsRequest(parcelReturnObjects.ParcelData.LocalID, parcelReturnObjects.ParcelData.ReturnType, puserselectedOwnerIDs, puserselectedTaskIDs, this);
9454  
9455 }
9456 return true;
9457 }
9458  
9459 private bool HandleParcelSetOtherCleanTime(IClientAPI sender, Packet Pack)
9460 {
9461 ParcelSetOtherCleanTimePacket parcelSetOtherCleanTimePacket = (ParcelSetOtherCleanTimePacket)Pack;
9462  
9463 #region Packet Session and User Check
9464 if (m_checkPackets)
9465 {
9466 if (parcelSetOtherCleanTimePacket.AgentData.SessionID != SessionId ||
9467 parcelSetOtherCleanTimePacket.AgentData.AgentID != AgentId)
9468 return true;
9469 }
9470 #endregion
9471  
9472 ParcelSetOtherCleanTime handlerParcelSetOtherCleanTime = OnParcelSetOtherCleanTime;
9473 if (handlerParcelSetOtherCleanTime != null)
9474 {
9475 handlerParcelSetOtherCleanTime(this,
9476 parcelSetOtherCleanTimePacket.ParcelData.LocalID,
9477 parcelSetOtherCleanTimePacket.ParcelData.OtherCleanTime);
9478 }
9479 return true;
9480 }
9481  
9482 private bool HandleLandStatRequest(IClientAPI sender, Packet Pack)
9483 {
9484 LandStatRequestPacket lsrp = (LandStatRequestPacket)Pack;
9485  
9486 #region Packet Session and User Check
9487 if (m_checkPackets)
9488 {
9489 if (lsrp.AgentData.SessionID != SessionId ||
9490 lsrp.AgentData.AgentID != AgentId)
9491 return true;
9492 }
9493 #endregion
9494  
9495 GodLandStatRequest handlerLandStatRequest = OnLandStatRequest;
9496 if (handlerLandStatRequest != null)
9497 {
9498 handlerLandStatRequest(lsrp.RequestData.ParcelLocalID, lsrp.RequestData.ReportType, lsrp.RequestData.RequestFlags, Utils.BytesToString(lsrp.RequestData.Filter), this);
9499 }
9500 return true;
9501 }
9502  
9503 private bool HandleParcelDwellRequest(IClientAPI sender, Packet Pack)
9504 {
9505 ParcelDwellRequestPacket dwellrq =
9506 (ParcelDwellRequestPacket)Pack;
9507  
9508 #region Packet Session and User Check
9509 if (m_checkPackets)
9510 {
9511 if (dwellrq.AgentData.SessionID != SessionId ||
9512 dwellrq.AgentData.AgentID != AgentId)
9513 return true;
9514 }
9515 #endregion
9516  
9517 ParcelDwellRequest handlerParcelDwellRequest = OnParcelDwellRequest;
9518 if (handlerParcelDwellRequest != null)
9519 {
9520 handlerParcelDwellRequest(dwellrq.Data.LocalID, this);
9521 }
9522 return true;
9523 }
9524  
9525 #endregion Parcel related packets
9526  
9527 #region Estate Packets
9528  
9529 private bool HandleEstateOwnerMessage(IClientAPI sender, Packet Pack)
9530 {
9531 EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
9532 // m_log.InfoFormat("[LLCLIENTVIEW]: Packet: {0}", Utils.BytesToString(messagePacket.MethodData.Method));
9533 GodLandStatRequest handlerLandStatRequest;
9534  
9535 #region Packet Session and User Check
9536 if (m_checkPackets)
9537 {
9538 if (messagePacket.AgentData.SessionID != SessionId ||
9539 messagePacket.AgentData.AgentID != AgentId)
9540 return true;
9541 }
9542 #endregion
9543  
9544 string method = Utils.BytesToString(messagePacket.MethodData.Method);
9545  
9546 switch (method)
9547 {
9548 case "getinfo":
9549 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9550 {
9551 OnDetailedEstateDataRequest(this, messagePacket.MethodData.Invoice);
9552 }
9553 return true;
9554 case "setregioninfo":
9555 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9556 {
9557 OnSetEstateFlagsRequest(convertParamStringToBool(messagePacket.ParamList[0].Parameter), convertParamStringToBool(messagePacket.ParamList[1].Parameter),
9558 convertParamStringToBool(messagePacket.ParamList[2].Parameter), !convertParamStringToBool(messagePacket.ParamList[3].Parameter),
9559 Convert.ToInt16(Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[4].Parameter), Culture.NumberFormatInfo)),
9560 (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo),
9561 Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[6].Parameter)),
9562 convertParamStringToBool(messagePacket.ParamList[7].Parameter), convertParamStringToBool(messagePacket.ParamList[8].Parameter));
9563 }
9564 return true;
9565 // case "texturebase":
9566 // if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9567 // {
9568 // foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
9569 // {
9570 // string s = Utils.BytesToString(block.Parameter);
9571 // string[] splitField = s.Split(' ');
9572 // if (splitField.Length == 2)
9573 // {
9574 // UUID tempUUID = new UUID(splitField[1]);
9575 // OnSetEstateTerrainBaseTexture(this, Convert.ToInt16(splitField[0]), tempUUID);
9576 // }
9577 // }
9578 // }
9579 // break;
9580 case "texturedetail":
9581 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9582 {
9583 foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
9584 {
9585 string s = Utils.BytesToString(block.Parameter);
9586 string[] splitField = s.Split(' ');
9587 if (splitField.Length == 2)
9588 {
9589 Int16 corner = Convert.ToInt16(splitField[0]);
9590 UUID textureUUID = new UUID(splitField[1]);
9591  
9592 OnSetEstateTerrainDetailTexture(this, corner, textureUUID);
9593 }
9594 }
9595 }
9596  
9597 return true;
9598 case "textureheights":
9599 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9600 {
9601 foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
9602 {
9603 string s = Utils.BytesToString(block.Parameter);
9604 string[] splitField = s.Split(' ');
9605 if (splitField.Length == 3)
9606 {
9607 Int16 corner = Convert.ToInt16(splitField[0]);
9608 float lowValue = (float)Convert.ToDecimal(splitField[1], Culture.NumberFormatInfo);
9609 float highValue = (float)Convert.ToDecimal(splitField[2], Culture.NumberFormatInfo);
9610  
9611 OnSetEstateTerrainTextureHeights(this, corner, lowValue, highValue);
9612 }
9613 }
9614 }
9615 return true;
9616 case "texturecommit":
9617 OnCommitEstateTerrainTextureRequest(this);
9618 return true;
9619 case "setregionterrain":
9620 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9621 {
9622 if (messagePacket.ParamList.Length != 9)
9623 {
9624 m_log.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
9625 }
9626 else
9627 {
9628 try
9629 {
9630 string tmp = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
9631 if (!tmp.Contains(".")) tmp += ".00";
9632 float WaterHeight = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
9633 tmp = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
9634 if (!tmp.Contains(".")) tmp += ".00";
9635 float TerrainRaiseLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
9636 tmp = Utils.BytesToString(messagePacket.ParamList[2].Parameter);
9637 if (!tmp.Contains(".")) tmp += ".00";
9638 float TerrainLowerLimit = (float)Convert.ToDecimal(tmp, Culture.NumberFormatInfo);
9639 bool UseEstateSun = convertParamStringToBool(messagePacket.ParamList[3].Parameter);
9640 bool UseFixedSun = convertParamStringToBool(messagePacket.ParamList[4].Parameter);
9641 float SunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[5].Parameter), Culture.NumberFormatInfo);
9642 bool UseGlobal = convertParamStringToBool(messagePacket.ParamList[6].Parameter);
9643 bool EstateFixedSun = convertParamStringToBool(messagePacket.ParamList[7].Parameter);
9644 float EstateSunHour = (float)Convert.ToDecimal(Utils.BytesToString(messagePacket.ParamList[8].Parameter), Culture.NumberFormatInfo);
9645  
9646 OnSetRegionTerrainSettings(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseEstateSun, UseFixedSun, SunHour, UseGlobal, EstateFixedSun, EstateSunHour);
9647  
9648 }
9649 catch (Exception ex)
9650 {
9651 m_log.Error("EstateOwnerMessage: Exception while setting terrain settings: \n" + messagePacket + "\n" + ex);
9652 }
9653 }
9654 }
9655  
9656 return true;
9657 case "restart":
9658 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9659 {
9660 // There's only 1 block in the estateResetSim.. and that's the number of seconds till restart.
9661 foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
9662 {
9663 float timeSeconds;
9664 Utils.TryParseSingle(Utils.BytesToString(block.Parameter), out timeSeconds);
9665 timeSeconds = (int)timeSeconds;
9666 OnEstateRestartSimRequest(this, (int)timeSeconds);
9667  
9668 }
9669 }
9670 return true;
9671 case "estatechangecovenantid":
9672 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9673 {
9674 foreach (EstateOwnerMessagePacket.ParamListBlock block in messagePacket.ParamList)
9675 {
9676 UUID newCovenantID = new UUID(Utils.BytesToString(block.Parameter));
9677 OnEstateChangeCovenantRequest(this, newCovenantID);
9678 }
9679 }
9680 return true;
9681 case "estateaccessdelta": // Estate access delta manages the banlist and allow list too.
9682 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9683 {
9684 int estateAccessType = Convert.ToInt16(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
9685 OnUpdateEstateAccessDeltaRequest(this, messagePacket.MethodData.Invoice, estateAccessType, new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter)));
9686  
9687 }
9688 return true;
9689 case "simulatormessage":
9690 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9691 {
9692 UUID invoice = messagePacket.MethodData.Invoice;
9693 UUID SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
9694 string SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
9695 string Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
9696 UUID sessionID = messagePacket.AgentData.SessionID;
9697 OnSimulatorBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
9698 }
9699 return true;
9700 case "instantmessage":
9701 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9702 {
9703 if (messagePacket.ParamList.Length < 2)
9704 return true;
9705  
9706 UUID invoice = messagePacket.MethodData.Invoice;
9707 UUID sessionID = messagePacket.AgentData.SessionID;
9708  
9709 UUID SenderID;
9710 string SenderName;
9711 string Message;
9712  
9713 if (messagePacket.ParamList.Length < 5)
9714 {
9715 SenderID = AgentId;
9716 SenderName = Utils.BytesToString(messagePacket.ParamList[0].Parameter);
9717 Message = Utils.BytesToString(messagePacket.ParamList[1].Parameter);
9718 }
9719 else
9720 {
9721 SenderID = new UUID(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
9722 SenderName = Utils.BytesToString(messagePacket.ParamList[3].Parameter);
9723 Message = Utils.BytesToString(messagePacket.ParamList[4].Parameter);
9724 }
9725  
9726 OnEstateBlueBoxMessageRequest(this, invoice, SenderID, sessionID, SenderName, Message);
9727 }
9728 return true;
9729 case "setregiondebug":
9730 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9731 {
9732 UUID invoice = messagePacket.MethodData.Invoice;
9733 UUID SenderID = messagePacket.AgentData.AgentID;
9734 bool scripted = convertParamStringToBool(messagePacket.ParamList[0].Parameter);
9735 bool collisionEvents = convertParamStringToBool(messagePacket.ParamList[1].Parameter);
9736 bool physics = convertParamStringToBool(messagePacket.ParamList[2].Parameter);
9737  
9738 OnEstateDebugRegionRequest(this, invoice, SenderID, scripted, collisionEvents, physics);
9739 }
9740 return true;
9741 case "teleporthomeuser":
9742 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9743 {
9744 UUID invoice = messagePacket.MethodData.Invoice;
9745 UUID SenderID = messagePacket.AgentData.AgentID;
9746 UUID Prey;
9747  
9748 UUID.TryParse(Utils.BytesToString(messagePacket.ParamList[1].Parameter), out Prey);
9749  
9750 OnEstateTeleportOneUserHomeRequest(this, invoice, SenderID, Prey);
9751 }
9752 return true;
9753 case "teleporthomeallusers":
9754 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9755 {
9756 UUID invoice = messagePacket.MethodData.Invoice;
9757 UUID SenderID = messagePacket.AgentData.AgentID;
9758 OnEstateTeleportAllUsersHomeRequest(this, invoice, SenderID);
9759 }
9760 return true;
9761 case "colliders":
9762 handlerLandStatRequest = OnLandStatRequest;
9763 if (handlerLandStatRequest != null)
9764 {
9765 handlerLandStatRequest(0, 1, 0, "", this);
9766 }
9767 return true;
9768 case "scripts":
9769 handlerLandStatRequest = OnLandStatRequest;
9770 if (handlerLandStatRequest != null)
9771 {
9772 handlerLandStatRequest(0, 0, 0, "", this);
9773 }
9774 return true;
9775 case "terrain":
9776 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9777 {
9778 if (messagePacket.ParamList.Length > 0)
9779 {
9780 if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "bake")
9781 {
9782 BakeTerrain handlerBakeTerrain = OnBakeTerrain;
9783 if (handlerBakeTerrain != null)
9784 {
9785 handlerBakeTerrain(this);
9786 }
9787 }
9788 if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "download filename")
9789 {
9790 if (messagePacket.ParamList.Length > 1)
9791 {
9792 RequestTerrain handlerRequestTerrain = OnRequestTerrain;
9793 if (handlerRequestTerrain != null)
9794 {
9795 handlerRequestTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
9796 }
9797 }
9798 }
9799 if (Utils.BytesToString(messagePacket.ParamList[0].Parameter) == "upload filename")
9800 {
9801 if (messagePacket.ParamList.Length > 1)
9802 {
9803 RequestTerrain handlerUploadTerrain = OnUploadTerrain;
9804 if (handlerUploadTerrain != null)
9805 {
9806 handlerUploadTerrain(this, Utils.BytesToString(messagePacket.ParamList[1].Parameter));
9807 }
9808 }
9809 }
9810  
9811 }
9812  
9813  
9814 }
9815 return true;
9816  
9817 case "estatechangeinfo":
9818 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9819 {
9820 UUID invoice = messagePacket.MethodData.Invoice;
9821 UUID SenderID = messagePacket.AgentData.AgentID;
9822 UInt32 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
9823 UInt32 param2 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[2].Parameter));
9824  
9825 EstateChangeInfo handlerEstateChangeInfo = OnEstateChangeInfo;
9826 if (handlerEstateChangeInfo != null)
9827 {
9828 handlerEstateChangeInfo(this, invoice, SenderID, param1, param2);
9829 }
9830 }
9831 return true;
9832  
9833 case "telehub":
9834 if (((Scene)m_scene).Permissions.CanIssueEstateCommand(AgentId, false))
9835 {
9836 UUID invoice = messagePacket.MethodData.Invoice;
9837 UUID SenderID = messagePacket.AgentData.AgentID;
9838 UInt32 param1 = 0u;
9839  
9840 string command = (string)Utils.BytesToString(messagePacket.ParamList[0].Parameter);
9841  
9842 if (command != "info ui")
9843 {
9844 try
9845 {
9846 param1 = Convert.ToUInt32(Utils.BytesToString(messagePacket.ParamList[1].Parameter));
9847 }
9848 catch
9849 {
9850 }
9851 }
9852  
9853 EstateManageTelehub handlerEstateManageTelehub = OnEstateManageTelehub;
9854 if (handlerEstateManageTelehub != null)
9855 {
9856 handlerEstateManageTelehub(this, invoice, SenderID, command, param1);
9857 }
9858 }
9859 return true;
9860  
9861 default:
9862 m_log.WarnFormat(
9863 "[LLCLIENTVIEW]: EstateOwnerMessage: Unknown method {0} requested for {1} in {2}",
9864 method, Name, Scene.Name);
9865  
9866 for (int i = 0; i < messagePacket.ParamList.Length; i++)
9867 {
9868 EstateOwnerMessagePacket.ParamListBlock block = messagePacket.ParamList[i];
9869 string data = (string)Utils.BytesToString(block.Parameter);
9870 m_log.DebugFormat("[LLCLIENTVIEW]: Param {0}={1}", i, data);
9871 }
9872  
9873 return true;
9874 }
9875  
9876 //int parcelID, uint reportType, uint requestflags, string filter
9877  
9878 //lsrp.RequestData.ParcelLocalID;
9879 //lsrp.RequestData.ReportType; // 1 = colliders, 0 = scripts
9880 //lsrp.RequestData.RequestFlags;
9881 //lsrp.RequestData.Filter;
9882 }
9883  
9884 private bool HandleRequestRegionInfo(IClientAPI sender, Packet Pack)
9885 {
9886 RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
9887  
9888 #region Packet Session and User Check
9889 if (m_checkPackets)
9890 {
9891 if (mPacket.SessionID != SessionId ||
9892 mPacket.AgentID != AgentId)
9893 return true;
9894 }
9895 #endregion
9896  
9897 RegionInfoRequest handlerRegionInfoRequest = OnRegionInfoRequest;
9898 if (handlerRegionInfoRequest != null)
9899 {
9900 handlerRegionInfoRequest(this);
9901 }
9902 return true;
9903 }
9904  
9905 private bool HandleEstateCovenantRequest(IClientAPI sender, Packet Pack)
9906 {
9907  
9908 //EstateCovenantRequestPacket.AgentDataBlock epack =
9909 // ((EstateCovenantRequestPacket)Pack).AgentData;
9910  
9911 EstateCovenantRequest handlerEstateCovenantRequest = OnEstateCovenantRequest;
9912 if (handlerEstateCovenantRequest != null)
9913 {
9914 handlerEstateCovenantRequest(this);
9915 }
9916 return true;
9917  
9918 }
9919  
9920 #endregion Estate Packets
9921  
9922 #region GodPackets
9923  
9924 private bool HandleRequestGodlikePowers(IClientAPI sender, Packet Pack)
9925 {
9926 RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
9927 RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
9928 UUID token = rblock.Token;
9929  
9930 RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
9931  
9932 RequestGodlikePowers handlerReqGodlikePowers = OnRequestGodlikePowers;
9933  
9934 if (handlerReqGodlikePowers != null)
9935 {
9936 handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike, this);
9937 }
9938  
9939 return true;
9940 }
9941  
9942 private bool HandleGodUpdateRegionInfoUpdate(IClientAPI client, Packet Packet)
9943 {
9944 GodUpdateRegionInfoPacket GodUpdateRegionInfo =
9945 (GodUpdateRegionInfoPacket)Packet;
9946  
9947 GodUpdateRegionInfoUpdate handlerGodUpdateRegionInfo = OnGodUpdateRegionInfoUpdate;
9948 if (handlerGodUpdateRegionInfo != null)
9949 {
9950 handlerGodUpdateRegionInfo(this,
9951 GodUpdateRegionInfo.RegionInfo.BillableFactor,
9952 GodUpdateRegionInfo.RegionInfo.EstateID,
9953 GodUpdateRegionInfo.RegionInfo.RegionFlags,
9954 GodUpdateRegionInfo.RegionInfo.SimName,
9955 GodUpdateRegionInfo.RegionInfo.RedirectGridX,
9956 GodUpdateRegionInfo.RegionInfo.RedirectGridY);
9957 return true;
9958 }
9959 return false;
9960 }
9961  
9962 private bool HandleSimWideDeletes(IClientAPI client, Packet Packet)
9963 {
9964 SimWideDeletesPacket SimWideDeletesRequest =
9965 (SimWideDeletesPacket)Packet;
9966 SimWideDeletesDelegate handlerSimWideDeletesRequest = OnSimWideDeletes;
9967 if (handlerSimWideDeletesRequest != null)
9968 {
9969 handlerSimWideDeletesRequest(this, SimWideDeletesRequest.AgentData.AgentID,(int)SimWideDeletesRequest.DataBlock.Flags,SimWideDeletesRequest.DataBlock.TargetID);
9970 return true;
9971 }
9972 return false;
9973 }
9974  
9975 private bool HandleGodlikeMessage(IClientAPI client, Packet Packet)
9976 {
9977 GodlikeMessagePacket GodlikeMessage =
9978 (GodlikeMessagePacket)Packet;
9979  
9980 GodlikeMessage handlerGodlikeMessage = onGodlikeMessage;
9981 if (handlerGodlikeMessage != null)
9982 {
9983 handlerGodlikeMessage(this,
9984 GodlikeMessage.MethodData.Invoice,
9985 GodlikeMessage.MethodData.Method,
9986 GodlikeMessage.ParamList[0].Parameter);
9987 return true;
9988 }
9989 return false;
9990 }
9991  
9992 private bool HandleSaveStatePacket(IClientAPI client, Packet Packet)
9993 {
9994 StateSavePacket SaveStateMessage =
9995 (StateSavePacket)Packet;
9996 SaveStateHandler handlerSaveStatePacket = OnSaveState;
9997 if (handlerSaveStatePacket != null)
9998 {
9999 handlerSaveStatePacket(this,SaveStateMessage.AgentData.AgentID);
10000 return true;
10001 }
10002 return false;
10003 }
10004  
10005 private bool HandleGodKickUser(IClientAPI sender, Packet Pack)
10006 {
10007 GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
10008  
10009 if (gkupack.UserInfo.GodSessionID == SessionId && AgentId == gkupack.UserInfo.GodID)
10010 {
10011 GodKickUser handlerGodKickUser = OnGodKickUser;
10012 if (handlerGodKickUser != null)
10013 {
10014 handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.GodSessionID,
10015 gkupack.UserInfo.AgentID, gkupack.UserInfo.KickFlags, gkupack.UserInfo.Reason);
10016 }
10017 }
10018 else
10019 {
10020 SendAgentAlertMessage("Kick request denied", false);
10021 }
10022 //KickUserPacket kupack = new KickUserPacket();
10023 //KickUserPacket.UserInfoBlock kupackib = kupack.UserInfo;
10024  
10025 //kupack.UserInfo.AgentID = gkupack.UserInfo.AgentID;
10026 //kupack.UserInfo.SessionID = gkupack.UserInfo.GodSessionID;
10027  
10028 //kupack.TargetBlock.TargetIP = (uint)0;
10029 //kupack.TargetBlock.TargetPort = (ushort)0;
10030 //kupack.UserInfo.Reason = gkupack.UserInfo.Reason;
10031  
10032 //OutPacket(kupack, ThrottleOutPacketType.Task);
10033 return true;
10034 }
10035 #endregion GodPackets
10036  
10037 #region Economy/Transaction Packets
10038  
10039 private bool HandleMoneyBalanceRequest(IClientAPI sender, Packet Pack)
10040 {
10041 MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
10042  
10043 #region Packet Session and User Check
10044 if (m_checkPackets)
10045 {
10046 if (moneybalancerequestpacket.AgentData.SessionID != SessionId ||
10047 moneybalancerequestpacket.AgentData.AgentID != AgentId)
10048 return true;
10049 }
10050 #endregion
10051  
10052 MoneyBalanceRequest handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
10053  
10054 if (handlerMoneyBalanceRequest != null)
10055 {
10056 handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
10057 }
10058  
10059 return true;
10060 }
10061 private bool HandleEconomyDataRequest(IClientAPI sender, Packet Pack)
10062 {
10063 EconomyDataRequest handlerEconomoyDataRequest = OnEconomyDataRequest;
10064 if (handlerEconomoyDataRequest != null)
10065 {
10066 handlerEconomoyDataRequest(this);
10067 }
10068 return true;
10069 }
10070 private bool HandleRequestPayPrice(IClientAPI sender, Packet Pack)
10071 {
10072 RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
10073  
10074 RequestPayPrice handlerRequestPayPrice = OnRequestPayPrice;
10075 if (handlerRequestPayPrice != null)
10076 {
10077 handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
10078 }
10079 return true;
10080 }
10081 private bool HandleObjectSaleInfo(IClientAPI sender, Packet Pack)
10082 {
10083 ObjectSaleInfoPacket objectSaleInfoPacket = (ObjectSaleInfoPacket)Pack;
10084  
10085 #region Packet Session and User Check
10086 if (m_checkPackets)
10087 {
10088 if (objectSaleInfoPacket.AgentData.SessionID != SessionId ||
10089 objectSaleInfoPacket.AgentData.AgentID != AgentId)
10090 return true;
10091 }
10092 #endregion
10093  
10094 ObjectSaleInfo handlerObjectSaleInfo = OnObjectSaleInfo;
10095 if (handlerObjectSaleInfo != null)
10096 {
10097 foreach (ObjectSaleInfoPacket.ObjectDataBlock d
10098 in objectSaleInfoPacket.ObjectData)
10099 {
10100 handlerObjectSaleInfo(this,
10101 objectSaleInfoPacket.AgentData.AgentID,
10102 objectSaleInfoPacket.AgentData.SessionID,
10103 d.LocalID,
10104 d.SaleType,
10105 d.SalePrice);
10106 }
10107 }
10108 return true;
10109 }
10110 private bool HandleObjectBuy(IClientAPI sender, Packet Pack)
10111 {
10112 ObjectBuyPacket objectBuyPacket = (ObjectBuyPacket)Pack;
10113  
10114 #region Packet Session and User Check
10115 if (m_checkPackets)
10116 {
10117 if (objectBuyPacket.AgentData.SessionID != SessionId ||
10118 objectBuyPacket.AgentData.AgentID != AgentId)
10119 return true;
10120 }
10121 #endregion
10122  
10123 ObjectBuy handlerObjectBuy = OnObjectBuy;
10124  
10125 if (handlerObjectBuy != null)
10126 {
10127 foreach (ObjectBuyPacket.ObjectDataBlock d
10128 in objectBuyPacket.ObjectData)
10129 {
10130 handlerObjectBuy(this,
10131 objectBuyPacket.AgentData.AgentID,
10132 objectBuyPacket.AgentData.SessionID,
10133 objectBuyPacket.AgentData.GroupID,
10134 objectBuyPacket.AgentData.CategoryID,
10135 d.ObjectLocalID,
10136 d.SaleType,
10137 d.SalePrice);
10138 }
10139 }
10140 return true;
10141 }
10142  
10143 #endregion Economy/Transaction Packets
10144  
10145 #region Script Packets
10146 private bool HandleGetScriptRunning(IClientAPI sender, Packet Pack)
10147 {
10148 GetScriptRunningPacket scriptRunning = (GetScriptRunningPacket)Pack;
10149  
10150 GetScriptRunning handlerGetScriptRunning = OnGetScriptRunning;
10151 if (handlerGetScriptRunning != null)
10152 {
10153 handlerGetScriptRunning(this, scriptRunning.Script.ObjectID, scriptRunning.Script.ItemID);
10154 }
10155 return true;
10156 }
10157 private bool HandleSetScriptRunning(IClientAPI sender, Packet Pack)
10158 {
10159 SetScriptRunningPacket setScriptRunning = (SetScriptRunningPacket)Pack;
10160  
10161 #region Packet Session and User Check
10162 if (m_checkPackets)
10163 {
10164 if (setScriptRunning.AgentData.SessionID != SessionId ||
10165 setScriptRunning.AgentData.AgentID != AgentId)
10166 return true;
10167 }
10168 #endregion
10169  
10170 SetScriptRunning handlerSetScriptRunning = OnSetScriptRunning;
10171 if (handlerSetScriptRunning != null)
10172 {
10173 handlerSetScriptRunning(this, setScriptRunning.Script.ObjectID, setScriptRunning.Script.ItemID, setScriptRunning.Script.Running);
10174 }
10175 return true;
10176 }
10177  
10178 private bool HandleScriptReset(IClientAPI sender, Packet Pack)
10179 {
10180 ScriptResetPacket scriptResetPacket = (ScriptResetPacket)Pack;
10181  
10182 #region Packet Session and User Check
10183 if (m_checkPackets)
10184 {
10185 if (scriptResetPacket.AgentData.SessionID != SessionId ||
10186 scriptResetPacket.AgentData.AgentID != AgentId)
10187 return true;
10188 }
10189 #endregion
10190  
10191 ScriptReset handlerScriptReset = OnScriptReset;
10192 if (handlerScriptReset != null)
10193 {
10194 handlerScriptReset(this, scriptResetPacket.Script.ObjectID, scriptResetPacket.Script.ItemID);
10195 }
10196 return true;
10197 }
10198  
10199 #endregion Script Packets
10200  
10201 #region Gesture Managment
10202  
10203 private bool HandleActivateGestures(IClientAPI sender, Packet Pack)
10204 {
10205 ActivateGesturesPacket activateGesturePacket = (ActivateGesturesPacket)Pack;
10206  
10207 #region Packet Session and User Check
10208 if (m_checkPackets)
10209 {
10210 if (activateGesturePacket.AgentData.SessionID != SessionId ||
10211 activateGesturePacket.AgentData.AgentID != AgentId)
10212 return true;
10213 }
10214 #endregion
10215  
10216 ActivateGesture handlerActivateGesture = OnActivateGesture;
10217 if (handlerActivateGesture != null)
10218 {
10219 handlerActivateGesture(this,
10220 activateGesturePacket.Data[0].AssetID,
10221 activateGesturePacket.Data[0].ItemID);
10222 }
10223 else m_log.Error("Null pointer for activateGesture");
10224  
10225 return true;
10226 }
10227 private bool HandleDeactivateGestures(IClientAPI sender, Packet Pack)
10228 {
10229 DeactivateGesturesPacket deactivateGesturePacket = (DeactivateGesturesPacket)Pack;
10230  
10231 #region Packet Session and User Check
10232 if (m_checkPackets)
10233 {
10234 if (deactivateGesturePacket.AgentData.SessionID != SessionId ||
10235 deactivateGesturePacket.AgentData.AgentID != AgentId)
10236 return true;
10237 }
10238 #endregion
10239  
10240 DeactivateGesture handlerDeactivateGesture = OnDeactivateGesture;
10241 if (handlerDeactivateGesture != null)
10242 {
10243 handlerDeactivateGesture(this, deactivateGesturePacket.Data[0].ItemID);
10244 }
10245 return true;
10246 }
10247 private bool HandleObjectOwner(IClientAPI sender, Packet Pack)
10248 {
10249 ObjectOwnerPacket objectOwnerPacket = (ObjectOwnerPacket)Pack;
10250  
10251 #region Packet Session and User Check
10252 if (m_checkPackets)
10253 {
10254 if (objectOwnerPacket.AgentData.SessionID != SessionId ||
10255 objectOwnerPacket.AgentData.AgentID != AgentId)
10256 return true;
10257 }
10258 #endregion
10259  
10260 List<uint> localIDs = new List<uint>();
10261  
10262 foreach (ObjectOwnerPacket.ObjectDataBlock d in objectOwnerPacket.ObjectData)
10263 localIDs.Add(d.ObjectLocalID);
10264  
10265 ObjectOwner handlerObjectOwner = OnObjectOwner;
10266 if (handlerObjectOwner != null)
10267 {
10268 handlerObjectOwner(this, objectOwnerPacket.HeaderData.OwnerID, objectOwnerPacket.HeaderData.GroupID, localIDs);
10269 }
10270 return true;
10271 }
10272  
10273 #endregion Gesture Managment
10274  
10275 private bool HandleAgentFOV(IClientAPI sender, Packet Pack)
10276 {
10277 AgentFOVPacket fovPacket = (AgentFOVPacket)Pack;
10278  
10279 if (fovPacket.FOVBlock.GenCounter > m_agentFOVCounter)
10280 {
10281 m_agentFOVCounter = fovPacket.FOVBlock.GenCounter;
10282 AgentFOV handlerAgentFOV = OnAgentFOV;
10283 if (handlerAgentFOV != null)
10284 {
10285 handlerAgentFOV(this, fovPacket.FOVBlock.VerticalAngle);
10286 }
10287 }
10288 return true;
10289 }
10290  
10291 #region unimplemented handlers
10292  
10293 private bool HandleViewerStats(IClientAPI sender, Packet Pack)
10294 {
10295 // TODO: handle this packet
10296 //m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
10297 return true;
10298 }
10299  
10300 private bool HandleMapItemRequest(IClientAPI sender, Packet Pack)
10301 {
10302 MapItemRequestPacket mirpk = (MapItemRequestPacket)Pack;
10303  
10304 #region Packet Session and User Check
10305 if (m_checkPackets)
10306 {
10307 if (mirpk.AgentData.SessionID != SessionId ||
10308 mirpk.AgentData.AgentID != AgentId)
10309 return true;
10310 }
10311 #endregion
10312  
10313 //m_log.Debug(mirpk.ToString());
10314 MapItemRequest handlerMapItemRequest = OnMapItemRequest;
10315 if (handlerMapItemRequest != null)
10316 {
10317 handlerMapItemRequest(this, mirpk.AgentData.Flags, mirpk.AgentData.EstateID,
10318 mirpk.AgentData.Godlike, mirpk.RequestData.ItemType,
10319 mirpk.RequestData.RegionHandle);
10320  
10321 }
10322 return true;
10323 }
10324  
10325 private bool HandleTransferAbort(IClientAPI sender, Packet Pack)
10326 {
10327 return true;
10328 }
10329  
10330 private bool HandleMuteListRequest(IClientAPI sender, Packet Pack)
10331 {
10332 MuteListRequestPacket muteListRequest =
10333 (MuteListRequestPacket)Pack;
10334  
10335 #region Packet Session and User Check
10336 if (m_checkPackets)
10337 {
10338 if (muteListRequest.AgentData.SessionID != SessionId ||
10339 muteListRequest.AgentData.AgentID != AgentId)
10340 return true;
10341 }
10342 #endregion
10343  
10344 MuteListRequest handlerMuteListRequest = OnMuteListRequest;
10345 if (handlerMuteListRequest != null)
10346 {
10347 handlerMuteListRequest(this, muteListRequest.MuteData.MuteCRC);
10348 }
10349 else
10350 {
10351 SendUseCachedMuteList();
10352 }
10353 return true;
10354 }
10355  
10356 private bool HandleUpdateMuteListEntry(IClientAPI client, Packet Packet)
10357 {
10358 UpdateMuteListEntryPacket UpdateMuteListEntry =
10359 (UpdateMuteListEntryPacket)Packet;
10360 MuteListEntryUpdate handlerUpdateMuteListEntry = OnUpdateMuteListEntry;
10361 if (handlerUpdateMuteListEntry != null)
10362 {
10363 handlerUpdateMuteListEntry(this, UpdateMuteListEntry.MuteData.MuteID,
10364 Utils.BytesToString(UpdateMuteListEntry.MuteData.MuteName),
10365 UpdateMuteListEntry.MuteData.MuteType,
10366 UpdateMuteListEntry.AgentData.AgentID);
10367 return true;
10368 }
10369 return false;
10370 }
10371  
10372 private bool HandleRemoveMuteListEntry(IClientAPI client, Packet Packet)
10373 {
10374 RemoveMuteListEntryPacket RemoveMuteListEntry =
10375 (RemoveMuteListEntryPacket)Packet;
10376 MuteListEntryRemove handlerRemoveMuteListEntry = OnRemoveMuteListEntry;
10377 if (handlerRemoveMuteListEntry != null)
10378 {
10379 handlerRemoveMuteListEntry(this,
10380 RemoveMuteListEntry.MuteData.MuteID,
10381 Utils.BytesToString(RemoveMuteListEntry.MuteData.MuteName),
10382 RemoveMuteListEntry.AgentData.AgentID);
10383 return true;
10384 }
10385 return false;
10386 }
10387  
10388 private bool HandleUserReport(IClientAPI client, Packet Packet)
10389 {
10390 UserReportPacket UserReport =
10391 (UserReportPacket)Packet;
10392  
10393 NewUserReport handlerUserReport = OnUserReport;
10394 if (handlerUserReport != null)
10395 {
10396 handlerUserReport(this,
10397 Utils.BytesToString(UserReport.ReportData.AbuseRegionName),
10398 UserReport.ReportData.AbuserID,
10399 UserReport.ReportData.Category,
10400 UserReport.ReportData.CheckFlags,
10401 Utils.BytesToString(UserReport.ReportData.Details),
10402 UserReport.ReportData.ObjectID,
10403 UserReport.ReportData.Position,
10404 UserReport.ReportData.ReportType,
10405 UserReport.ReportData.ScreenshotID,
10406 Utils.BytesToString(UserReport.ReportData.Summary),
10407 UserReport.AgentData.AgentID);
10408 return true;
10409 }
10410 return false;
10411 }
10412  
10413 private bool HandleSendPostcard(IClientAPI client, Packet packet)
10414 {
10415 // SendPostcardPacket SendPostcard =
10416 // (SendPostcardPacket)packet;
10417 SendPostcard handlerSendPostcard = OnSendPostcard;
10418 if (handlerSendPostcard != null)
10419 {
10420 handlerSendPostcard(this);
10421 return true;
10422 }
10423 return false;
10424 }
10425  
10426 private bool HandleUseCircuitCode(IClientAPI sender, Packet Pack)
10427 {
10428 return true;
10429 }
10430  
10431 private bool HandleAgentHeightWidth(IClientAPI sender, Packet Pack)
10432 {
10433 return true;
10434 }
10435  
10436 private bool HandleInventoryDescendents(IClientAPI sender, Packet Pack)
10437 {
10438 return true;
10439 }
10440  
10441 #endregion unimplemented handlers
10442  
10443 #region Dir handlers
10444  
10445 private bool HandleDirPlacesQuery(IClientAPI sender, Packet Pack)
10446 {
10447 DirPlacesQueryPacket dirPlacesQueryPacket = (DirPlacesQueryPacket)Pack;
10448 //m_log.Debug(dirPlacesQueryPacket.ToString());
10449  
10450 #region Packet Session and User Check
10451 if (m_checkPackets)
10452 {
10453 if (dirPlacesQueryPacket.AgentData.SessionID != SessionId ||
10454 dirPlacesQueryPacket.AgentData.AgentID != AgentId)
10455 return true;
10456 }
10457 #endregion
10458  
10459 DirPlacesQuery handlerDirPlacesQuery = OnDirPlacesQuery;
10460 if (handlerDirPlacesQuery != null)
10461 {
10462 handlerDirPlacesQuery(this,
10463 dirPlacesQueryPacket.QueryData.QueryID,
10464 Utils.BytesToString(
10465 dirPlacesQueryPacket.QueryData.QueryText),
10466 (int)dirPlacesQueryPacket.QueryData.QueryFlags,
10467 (int)dirPlacesQueryPacket.QueryData.Category,
10468 Utils.BytesToString(
10469 dirPlacesQueryPacket.QueryData.SimName),
10470 dirPlacesQueryPacket.QueryData.QueryStart);
10471 }
10472 return true;
10473 }
10474  
10475 private bool HandleDirFindQuery(IClientAPI sender, Packet Pack)
10476 {
10477 DirFindQueryPacket dirFindQueryPacket = (DirFindQueryPacket)Pack;
10478  
10479 #region Packet Session and User Check
10480 if (m_checkPackets)
10481 {
10482 if (dirFindQueryPacket.AgentData.SessionID != SessionId ||
10483 dirFindQueryPacket.AgentData.AgentID != AgentId)
10484 return true;
10485 }
10486 #endregion
10487  
10488 DirFindQuery handlerDirFindQuery = OnDirFindQuery;
10489 if (handlerDirFindQuery != null)
10490 {
10491 handlerDirFindQuery(this,
10492 dirFindQueryPacket.QueryData.QueryID,
10493 Utils.BytesToString(
10494 dirFindQueryPacket.QueryData.QueryText).Trim(),
10495 dirFindQueryPacket.QueryData.QueryFlags,
10496 dirFindQueryPacket.QueryData.QueryStart);
10497 }
10498 return true;
10499 }
10500  
10501 private bool HandleDirLandQuery(IClientAPI sender, Packet Pack)
10502 {
10503 DirLandQueryPacket dirLandQueryPacket = (DirLandQueryPacket)Pack;
10504  
10505 #region Packet Session and User Check
10506 if (m_checkPackets)
10507 {
10508 if (dirLandQueryPacket.AgentData.SessionID != SessionId ||
10509 dirLandQueryPacket.AgentData.AgentID != AgentId)
10510 return true;
10511 }
10512 #endregion
10513  
10514 DirLandQuery handlerDirLandQuery = OnDirLandQuery;
10515 if (handlerDirLandQuery != null)
10516 {
10517 handlerDirLandQuery(this,
10518 dirLandQueryPacket.QueryData.QueryID,
10519 dirLandQueryPacket.QueryData.QueryFlags,
10520 dirLandQueryPacket.QueryData.SearchType,
10521 dirLandQueryPacket.QueryData.Price,
10522 dirLandQueryPacket.QueryData.Area,
10523 dirLandQueryPacket.QueryData.QueryStart);
10524 }
10525 return true;
10526 }
10527  
10528 private bool HandleDirPopularQuery(IClientAPI sender, Packet Pack)
10529 {
10530 DirPopularQueryPacket dirPopularQueryPacket = (DirPopularQueryPacket)Pack;
10531  
10532 #region Packet Session and User Check
10533 if (m_checkPackets)
10534 {
10535 if (dirPopularQueryPacket.AgentData.SessionID != SessionId ||
10536 dirPopularQueryPacket.AgentData.AgentID != AgentId)
10537 return true;
10538 }
10539 #endregion
10540  
10541 DirPopularQuery handlerDirPopularQuery = OnDirPopularQuery;
10542 if (handlerDirPopularQuery != null)
10543 {
10544 handlerDirPopularQuery(this,
10545 dirPopularQueryPacket.QueryData.QueryID,
10546 dirPopularQueryPacket.QueryData.QueryFlags);
10547 }
10548 return true;
10549 }
10550  
10551 private bool HandleDirClassifiedQuery(IClientAPI sender, Packet Pack)
10552 {
10553 DirClassifiedQueryPacket dirClassifiedQueryPacket = (DirClassifiedQueryPacket)Pack;
10554  
10555 #region Packet Session and User Check
10556 if (m_checkPackets)
10557 {
10558 if (dirClassifiedQueryPacket.AgentData.SessionID != SessionId ||
10559 dirClassifiedQueryPacket.AgentData.AgentID != AgentId)
10560 return true;
10561 }
10562 #endregion
10563  
10564 DirClassifiedQuery handlerDirClassifiedQuery = OnDirClassifiedQuery;
10565 if (handlerDirClassifiedQuery != null)
10566 {
10567 handlerDirClassifiedQuery(this,
10568 dirClassifiedQueryPacket.QueryData.QueryID,
10569 Utils.BytesToString(
10570 dirClassifiedQueryPacket.QueryData.QueryText),
10571 dirClassifiedQueryPacket.QueryData.QueryFlags,
10572 dirClassifiedQueryPacket.QueryData.Category,
10573 dirClassifiedQueryPacket.QueryData.QueryStart);
10574 }
10575 return true;
10576 }
10577  
10578 private bool HandleEventInfoRequest(IClientAPI sender, Packet Pack)
10579 {
10580 EventInfoRequestPacket eventInfoRequestPacket = (EventInfoRequestPacket)Pack;
10581  
10582 #region Packet Session and User Check
10583 if (m_checkPackets)
10584 {
10585 if (eventInfoRequestPacket.AgentData.SessionID != SessionId ||
10586 eventInfoRequestPacket.AgentData.AgentID != AgentId)
10587 return true;
10588 }
10589 #endregion
10590  
10591 if (OnEventInfoRequest != null)
10592 {
10593 OnEventInfoRequest(this, eventInfoRequestPacket.EventData.EventID);
10594 }
10595 return true;
10596 }
10597  
10598 #endregion
10599  
10600 #region Calling Card
10601  
10602 private bool HandleOfferCallingCard(IClientAPI sender, Packet Pack)
10603 {
10604 OfferCallingCardPacket offerCallingCardPacket = (OfferCallingCardPacket)Pack;
10605  
10606 #region Packet Session and User Check
10607 if (m_checkPackets)
10608 {
10609 if (offerCallingCardPacket.AgentData.SessionID != SessionId ||
10610 offerCallingCardPacket.AgentData.AgentID != AgentId)
10611 return true;
10612 }
10613 #endregion
10614  
10615 if (OnOfferCallingCard != null)
10616 {
10617 OnOfferCallingCard(this,
10618 offerCallingCardPacket.AgentBlock.DestID,
10619 offerCallingCardPacket.AgentBlock.TransactionID);
10620 }
10621 return true;
10622 }
10623  
10624 private bool HandleAcceptCallingCard(IClientAPI sender, Packet Pack)
10625 {
10626 AcceptCallingCardPacket acceptCallingCardPacket = (AcceptCallingCardPacket)Pack;
10627  
10628 #region Packet Session and User Check
10629 if (m_checkPackets)
10630 {
10631 if (acceptCallingCardPacket.AgentData.SessionID != SessionId ||
10632 acceptCallingCardPacket.AgentData.AgentID != AgentId)
10633 return true;
10634 }
10635 #endregion
10636  
10637 // according to http://wiki.secondlife.com/wiki/AcceptCallingCard FolderData should
10638 // contain exactly one entry
10639 if (OnAcceptCallingCard != null && acceptCallingCardPacket.FolderData.Length > 0)
10640 {
10641 OnAcceptCallingCard(this,
10642 acceptCallingCardPacket.TransactionBlock.TransactionID,
10643 acceptCallingCardPacket.FolderData[0].FolderID);
10644 }
10645 return true;
10646 }
10647  
10648 private bool HandleDeclineCallingCard(IClientAPI sender, Packet Pack)
10649 {
10650 DeclineCallingCardPacket declineCallingCardPacket = (DeclineCallingCardPacket)Pack;
10651  
10652 #region Packet Session and User Check
10653 if (m_checkPackets)
10654 {
10655 if (declineCallingCardPacket.AgentData.SessionID != SessionId ||
10656 declineCallingCardPacket.AgentData.AgentID != AgentId)
10657 return true;
10658 }
10659 #endregion
10660  
10661 if (OnDeclineCallingCard != null)
10662 {
10663 OnDeclineCallingCard(this,
10664 declineCallingCardPacket.TransactionBlock.TransactionID);
10665 }
10666 return true;
10667 }
10668  
10669 #endregion Calling Card
10670  
10671 #region Groups
10672  
10673 private bool HandleActivateGroup(IClientAPI sender, Packet Pack)
10674 {
10675 ActivateGroupPacket activateGroupPacket = (ActivateGroupPacket)Pack;
10676  
10677 #region Packet Session and User Check
10678 if (m_checkPackets)
10679 {
10680 if (activateGroupPacket.AgentData.SessionID != SessionId ||
10681 activateGroupPacket.AgentData.AgentID != AgentId)
10682 return true;
10683 }
10684 #endregion
10685  
10686 if (m_GroupsModule != null)
10687 {
10688 m_GroupsModule.ActivateGroup(this, activateGroupPacket.AgentData.GroupID);
10689 m_GroupsModule.SendAgentGroupDataUpdate(this);
10690 }
10691 return true;
10692  
10693 }
10694  
10695 private bool HandleGroupVoteHistoryRequest(IClientAPI client, Packet Packet)
10696 {
10697 GroupVoteHistoryRequestPacket GroupVoteHistoryRequest =
10698 (GroupVoteHistoryRequestPacket)Packet;
10699 GroupVoteHistoryRequest handlerGroupVoteHistoryRequest = OnGroupVoteHistoryRequest;
10700 if (handlerGroupVoteHistoryRequest != null)
10701 {
10702 handlerGroupVoteHistoryRequest(this, GroupVoteHistoryRequest.AgentData.AgentID,GroupVoteHistoryRequest.AgentData.SessionID,GroupVoteHistoryRequest.GroupData.GroupID,GroupVoteHistoryRequest.TransactionData.TransactionID);
10703 return true;
10704 }
10705 return false;
10706 }
10707  
10708 private bool HandleGroupActiveProposalsRequest(IClientAPI client, Packet Packet)
10709 {
10710 GroupActiveProposalsRequestPacket GroupActiveProposalsRequest =
10711 (GroupActiveProposalsRequestPacket)Packet;
10712 GroupActiveProposalsRequest handlerGroupActiveProposalsRequest = OnGroupActiveProposalsRequest;
10713 if (handlerGroupActiveProposalsRequest != null)
10714 {
10715 handlerGroupActiveProposalsRequest(this, GroupActiveProposalsRequest.AgentData.AgentID,GroupActiveProposalsRequest.AgentData.SessionID,GroupActiveProposalsRequest.GroupData.GroupID,GroupActiveProposalsRequest.TransactionData.TransactionID);
10716 return true;
10717 }
10718 return false;
10719 }
10720  
10721 private bool HandleGroupAccountDetailsRequest(IClientAPI client, Packet Packet)
10722 {
10723 GroupAccountDetailsRequestPacket GroupAccountDetailsRequest =
10724 (GroupAccountDetailsRequestPacket)Packet;
10725 GroupAccountDetailsRequest handlerGroupAccountDetailsRequest = OnGroupAccountDetailsRequest;
10726 if (handlerGroupAccountDetailsRequest != null)
10727 {
10728 handlerGroupAccountDetailsRequest(this, GroupAccountDetailsRequest.AgentData.AgentID,GroupAccountDetailsRequest.AgentData.GroupID,GroupAccountDetailsRequest.MoneyData.RequestID,GroupAccountDetailsRequest.AgentData.SessionID);
10729 return true;
10730 }
10731 return false;
10732 }
10733  
10734 private bool HandleGroupAccountSummaryRequest(IClientAPI client, Packet Packet)
10735 {
10736 GroupAccountSummaryRequestPacket GroupAccountSummaryRequest =
10737 (GroupAccountSummaryRequestPacket)Packet;
10738 GroupAccountSummaryRequest handlerGroupAccountSummaryRequest = OnGroupAccountSummaryRequest;
10739 if (handlerGroupAccountSummaryRequest != null)
10740 {
10741 handlerGroupAccountSummaryRequest(this, GroupAccountSummaryRequest.AgentData.AgentID,GroupAccountSummaryRequest.AgentData.GroupID);
10742 return true;
10743 }
10744 return false;
10745 }
10746  
10747 private bool HandleGroupTransactionsDetailsRequest(IClientAPI client, Packet Packet)
10748 {
10749 GroupAccountTransactionsRequestPacket GroupAccountTransactionsRequest =
10750 (GroupAccountTransactionsRequestPacket)Packet;
10751 GroupAccountTransactionsRequest handlerGroupAccountTransactionsRequest = OnGroupAccountTransactionsRequest;
10752 if (handlerGroupAccountTransactionsRequest != null)
10753 {
10754 handlerGroupAccountTransactionsRequest(this, GroupAccountTransactionsRequest.AgentData.AgentID,GroupAccountTransactionsRequest.AgentData.GroupID,GroupAccountTransactionsRequest.MoneyData.RequestID,GroupAccountTransactionsRequest.AgentData.SessionID);
10755 return true;
10756 }
10757 return false;
10758 }
10759  
10760 private bool HandleGroupTitlesRequest(IClientAPI sender, Packet Pack)
10761 {
10762 GroupTitlesRequestPacket groupTitlesRequest =
10763 (GroupTitlesRequestPacket)Pack;
10764  
10765 #region Packet Session and User Check
10766 if (m_checkPackets)
10767 {
10768 if (groupTitlesRequest.AgentData.SessionID != SessionId ||
10769 groupTitlesRequest.AgentData.AgentID != AgentId)
10770 return true;
10771 }
10772 #endregion
10773  
10774 if (m_GroupsModule != null)
10775 {
10776 GroupTitlesReplyPacket groupTitlesReply = (GroupTitlesReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupTitlesReply);
10777  
10778 groupTitlesReply.AgentData =
10779 new GroupTitlesReplyPacket.AgentDataBlock();
10780  
10781 groupTitlesReply.AgentData.AgentID = AgentId;
10782 groupTitlesReply.AgentData.GroupID =
10783 groupTitlesRequest.AgentData.GroupID;
10784  
10785 groupTitlesReply.AgentData.RequestID =
10786 groupTitlesRequest.AgentData.RequestID;
10787  
10788 List<GroupTitlesData> titles =
10789 m_GroupsModule.GroupTitlesRequest(this,
10790 groupTitlesRequest.AgentData.GroupID);
10791  
10792 groupTitlesReply.GroupData =
10793 new GroupTitlesReplyPacket.GroupDataBlock[titles.Count];
10794  
10795 int i = 0;
10796 foreach (GroupTitlesData d in titles)
10797 {
10798 groupTitlesReply.GroupData[i] =
10799 new GroupTitlesReplyPacket.GroupDataBlock();
10800  
10801 groupTitlesReply.GroupData[i].Title =
10802 Util.StringToBytes256(d.Name);
10803 groupTitlesReply.GroupData[i].RoleID =
10804 d.UUID;
10805 groupTitlesReply.GroupData[i].Selected =
10806 d.Selected;
10807 i++;
10808 }
10809  
10810 OutPacket(groupTitlesReply, ThrottleOutPacketType.Task);
10811 }
10812 return true;
10813 }
10814 private bool HandleGroupProfileRequest(IClientAPI sender, Packet Pack)
10815 {
10816 GroupProfileRequestPacket groupProfileRequest =
10817 (GroupProfileRequestPacket)Pack;
10818  
10819 #region Packet Session and User Check
10820 if (m_checkPackets)
10821 {
10822 if (groupProfileRequest.AgentData.SessionID != SessionId ||
10823 groupProfileRequest.AgentData.AgentID != AgentId)
10824 return true;
10825 }
10826 #endregion
10827  
10828 if (m_GroupsModule != null)
10829 {
10830 GroupProfileReplyPacket groupProfileReply = (GroupProfileReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupProfileReply);
10831  
10832 groupProfileReply.AgentData = new GroupProfileReplyPacket.AgentDataBlock();
10833 groupProfileReply.GroupData = new GroupProfileReplyPacket.GroupDataBlock();
10834 groupProfileReply.AgentData.AgentID = AgentId;
10835  
10836 GroupProfileData d = m_GroupsModule.GroupProfileRequest(this,
10837 groupProfileRequest.GroupData.GroupID);
10838  
10839 groupProfileReply.GroupData.GroupID = d.GroupID;
10840 groupProfileReply.GroupData.Name = Util.StringToBytes256(d.Name);
10841 groupProfileReply.GroupData.Charter = Util.StringToBytes1024(d.Charter);
10842 groupProfileReply.GroupData.ShowInList = d.ShowInList;
10843 groupProfileReply.GroupData.MemberTitle = Util.StringToBytes256(d.MemberTitle);
10844 groupProfileReply.GroupData.PowersMask = d.PowersMask;
10845 groupProfileReply.GroupData.InsigniaID = d.InsigniaID;
10846 groupProfileReply.GroupData.FounderID = d.FounderID;
10847 groupProfileReply.GroupData.MembershipFee = d.MembershipFee;
10848 groupProfileReply.GroupData.OpenEnrollment = d.OpenEnrollment;
10849 groupProfileReply.GroupData.Money = d.Money;
10850 groupProfileReply.GroupData.GroupMembershipCount = d.GroupMembershipCount;
10851 groupProfileReply.GroupData.GroupRolesCount = d.GroupRolesCount;
10852 groupProfileReply.GroupData.AllowPublish = d.AllowPublish;
10853 groupProfileReply.GroupData.MaturePublish = d.MaturePublish;
10854 groupProfileReply.GroupData.OwnerRole = d.OwnerRole;
10855  
10856 OutPacket(groupProfileReply, ThrottleOutPacketType.Task);
10857 }
10858 return true;
10859 }
10860 private bool HandleGroupMembersRequest(IClientAPI sender, Packet Pack)
10861 {
10862 GroupMembersRequestPacket groupMembersRequestPacket =
10863 (GroupMembersRequestPacket)Pack;
10864  
10865 #region Packet Session and User Check
10866 if (m_checkPackets)
10867 {
10868 if (groupMembersRequestPacket.AgentData.SessionID != SessionId ||
10869 groupMembersRequestPacket.AgentData.AgentID != AgentId)
10870 return true;
10871 }
10872 #endregion
10873  
10874 if (m_GroupsModule != null)
10875 {
10876 List<GroupMembersData> members =
10877 m_GroupsModule.GroupMembersRequest(this, groupMembersRequestPacket.GroupData.GroupID);
10878  
10879 int memberCount = members.Count;
10880  
10881 while (true)
10882 {
10883 int blockCount = members.Count;
10884 if (blockCount > 40)
10885 blockCount = 40;
10886  
10887 GroupMembersReplyPacket groupMembersReply = (GroupMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupMembersReply);
10888  
10889 groupMembersReply.AgentData =
10890 new GroupMembersReplyPacket.AgentDataBlock();
10891 groupMembersReply.GroupData =
10892 new GroupMembersReplyPacket.GroupDataBlock();
10893 groupMembersReply.MemberData =
10894 new GroupMembersReplyPacket.MemberDataBlock[
10895 blockCount];
10896  
10897 groupMembersReply.AgentData.AgentID = AgentId;
10898 groupMembersReply.GroupData.GroupID =
10899 groupMembersRequestPacket.GroupData.GroupID;
10900 groupMembersReply.GroupData.RequestID =
10901 groupMembersRequestPacket.GroupData.RequestID;
10902 groupMembersReply.GroupData.MemberCount = memberCount;
10903  
10904 for (int i = 0; i < blockCount; i++)
10905 {
10906 GroupMembersData m = members[0];
10907 members.RemoveAt(0);
10908  
10909 groupMembersReply.MemberData[i] =
10910 new GroupMembersReplyPacket.MemberDataBlock();
10911 groupMembersReply.MemberData[i].AgentID =
10912 m.AgentID;
10913 groupMembersReply.MemberData[i].Contribution =
10914 m.Contribution;
10915 groupMembersReply.MemberData[i].OnlineStatus =
10916 Util.StringToBytes256(m.OnlineStatus);
10917 groupMembersReply.MemberData[i].AgentPowers =
10918 m.AgentPowers;
10919 groupMembersReply.MemberData[i].Title =
10920 Util.StringToBytes256(m.Title);
10921 groupMembersReply.MemberData[i].IsOwner =
10922 m.IsOwner;
10923 }
10924 OutPacket(groupMembersReply, ThrottleOutPacketType.Task);
10925 if (members.Count == 0)
10926 return true;
10927 }
10928 }
10929 return true;
10930 }
10931 private bool HandleGroupRoleDataRequest(IClientAPI sender, Packet Pack)
10932 {
10933 GroupRoleDataRequestPacket groupRolesRequest =
10934 (GroupRoleDataRequestPacket)Pack;
10935  
10936 #region Packet Session and User Check
10937 if (m_checkPackets)
10938 {
10939 if (groupRolesRequest.AgentData.SessionID != SessionId ||
10940 groupRolesRequest.AgentData.AgentID != AgentId)
10941 return true;
10942 }
10943 #endregion
10944  
10945 if (m_GroupsModule != null)
10946 {
10947 GroupRoleDataReplyPacket groupRolesReply = (GroupRoleDataReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleDataReply);
10948  
10949 groupRolesReply.AgentData =
10950 new GroupRoleDataReplyPacket.AgentDataBlock();
10951  
10952 groupRolesReply.AgentData.AgentID = AgentId;
10953  
10954 groupRolesReply.GroupData =
10955 new GroupRoleDataReplyPacket.GroupDataBlock();
10956  
10957 groupRolesReply.GroupData.GroupID =
10958 groupRolesRequest.GroupData.GroupID;
10959  
10960 groupRolesReply.GroupData.RequestID =
10961 groupRolesRequest.GroupData.RequestID;
10962  
10963 List<GroupRolesData> titles =
10964 m_GroupsModule.GroupRoleDataRequest(this,
10965 groupRolesRequest.GroupData.GroupID);
10966  
10967 groupRolesReply.GroupData.RoleCount =
10968 titles.Count;
10969  
10970 groupRolesReply.RoleData =
10971 new GroupRoleDataReplyPacket.RoleDataBlock[titles.Count];
10972  
10973 int i = 0;
10974 foreach (GroupRolesData d in titles)
10975 {
10976 groupRolesReply.RoleData[i] =
10977 new GroupRoleDataReplyPacket.RoleDataBlock();
10978  
10979 groupRolesReply.RoleData[i].RoleID =
10980 d.RoleID;
10981 groupRolesReply.RoleData[i].Name =
10982 Util.StringToBytes256(d.Name);
10983 groupRolesReply.RoleData[i].Title =
10984 Util.StringToBytes256(d.Title);
10985 groupRolesReply.RoleData[i].Description =
10986 Util.StringToBytes1024(d.Description);
10987 groupRolesReply.RoleData[i].Powers =
10988 d.Powers;
10989 groupRolesReply.RoleData[i].Members =
10990 (uint)d.Members;
10991  
10992 i++;
10993 }
10994  
10995 OutPacket(groupRolesReply, ThrottleOutPacketType.Task);
10996 }
10997 return true;
10998 }
10999  
11000 private bool HandleGroupRoleMembersRequest(IClientAPI sender, Packet Pack)
11001 {
11002 GroupRoleMembersRequestPacket groupRoleMembersRequest =
11003 (GroupRoleMembersRequestPacket)Pack;
11004  
11005 #region Packet Session and User Check
11006 if (m_checkPackets)
11007 {
11008 if (groupRoleMembersRequest.AgentData.SessionID != SessionId ||
11009 groupRoleMembersRequest.AgentData.AgentID != AgentId)
11010 return true;
11011 }
11012 #endregion
11013  
11014 if (m_GroupsModule != null)
11015 {
11016 List<GroupRoleMembersData> mappings =
11017 m_GroupsModule.GroupRoleMembersRequest(this,
11018 groupRoleMembersRequest.GroupData.GroupID);
11019  
11020 int mappingsCount = mappings.Count;
11021  
11022 while (mappings.Count > 0)
11023 {
11024 int pairs = mappings.Count;
11025 if (pairs > 32)
11026 pairs = 32;
11027  
11028 GroupRoleMembersReplyPacket groupRoleMembersReply = (GroupRoleMembersReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupRoleMembersReply);
11029 groupRoleMembersReply.AgentData =
11030 new GroupRoleMembersReplyPacket.AgentDataBlock();
11031 groupRoleMembersReply.AgentData.AgentID =
11032 AgentId;
11033 groupRoleMembersReply.AgentData.GroupID =
11034 groupRoleMembersRequest.GroupData.GroupID;
11035 groupRoleMembersReply.AgentData.RequestID =
11036 groupRoleMembersRequest.GroupData.RequestID;
11037  
11038 groupRoleMembersReply.AgentData.TotalPairs =
11039 (uint)mappingsCount;
11040  
11041 groupRoleMembersReply.MemberData =
11042 new GroupRoleMembersReplyPacket.MemberDataBlock[pairs];
11043  
11044 for (int i = 0; i < pairs; i++)
11045 {
11046 GroupRoleMembersData d = mappings[0];
11047 mappings.RemoveAt(0);
11048  
11049 groupRoleMembersReply.MemberData[i] =
11050 new GroupRoleMembersReplyPacket.MemberDataBlock();
11051  
11052 groupRoleMembersReply.MemberData[i].RoleID =
11053 d.RoleID;
11054 groupRoleMembersReply.MemberData[i].MemberID =
11055 d.MemberID;
11056 }
11057  
11058 OutPacket(groupRoleMembersReply, ThrottleOutPacketType.Task);
11059 }
11060 }
11061 return true;
11062 }
11063 private bool HandleCreateGroupRequest(IClientAPI sender, Packet Pack)
11064 {
11065 CreateGroupRequestPacket createGroupRequest =
11066 (CreateGroupRequestPacket)Pack;
11067  
11068 #region Packet Session and User Check
11069 if (m_checkPackets)
11070 {
11071 if (createGroupRequest.AgentData.SessionID != SessionId ||
11072 createGroupRequest.AgentData.AgentID != AgentId)
11073 return true;
11074 }
11075 #endregion
11076  
11077 if (m_GroupsModule != null)
11078 {
11079 m_GroupsModule.CreateGroup(this,
11080 Utils.BytesToString(createGroupRequest.GroupData.Name),
11081 Utils.BytesToString(createGroupRequest.GroupData.Charter),
11082 createGroupRequest.GroupData.ShowInList,
11083 createGroupRequest.GroupData.InsigniaID,
11084 createGroupRequest.GroupData.MembershipFee,
11085 createGroupRequest.GroupData.OpenEnrollment,
11086 createGroupRequest.GroupData.AllowPublish,
11087 createGroupRequest.GroupData.MaturePublish);
11088 }
11089 return true;
11090 }
11091 private bool HandleUpdateGroupInfo(IClientAPI sender, Packet Pack)
11092 {
11093 UpdateGroupInfoPacket updateGroupInfo =
11094 (UpdateGroupInfoPacket)Pack;
11095  
11096 #region Packet Session and User Check
11097 if (m_checkPackets)
11098 {
11099 if (updateGroupInfo.AgentData.SessionID != SessionId ||
11100 updateGroupInfo.AgentData.AgentID != AgentId)
11101 return true;
11102 }
11103 #endregion
11104  
11105 if (m_GroupsModule != null)
11106 {
11107 m_GroupsModule.UpdateGroupInfo(this,
11108 updateGroupInfo.GroupData.GroupID,
11109 Utils.BytesToString(updateGroupInfo.GroupData.Charter),
11110 updateGroupInfo.GroupData.ShowInList,
11111 updateGroupInfo.GroupData.InsigniaID,
11112 updateGroupInfo.GroupData.MembershipFee,
11113 updateGroupInfo.GroupData.OpenEnrollment,
11114 updateGroupInfo.GroupData.AllowPublish,
11115 updateGroupInfo.GroupData.MaturePublish);
11116 }
11117  
11118 return true;
11119 }
11120 private bool HandleSetGroupAcceptNotices(IClientAPI sender, Packet Pack)
11121 {
11122 SetGroupAcceptNoticesPacket setGroupAcceptNotices =
11123 (SetGroupAcceptNoticesPacket)Pack;
11124  
11125 #region Packet Session and User Check
11126 if (m_checkPackets)
11127 {
11128 if (setGroupAcceptNotices.AgentData.SessionID != SessionId ||
11129 setGroupAcceptNotices.AgentData.AgentID != AgentId)
11130 return true;
11131 }
11132 #endregion
11133  
11134 if (m_GroupsModule != null)
11135 {
11136 m_GroupsModule.SetGroupAcceptNotices(this,
11137 setGroupAcceptNotices.Data.GroupID,
11138 setGroupAcceptNotices.Data.AcceptNotices,
11139 setGroupAcceptNotices.NewData.ListInProfile);
11140 }
11141  
11142 return true;
11143 }
11144 private bool HandleGroupTitleUpdate(IClientAPI sender, Packet Pack)
11145 {
11146 GroupTitleUpdatePacket groupTitleUpdate =
11147 (GroupTitleUpdatePacket)Pack;
11148  
11149 #region Packet Session and User Check
11150 if (m_checkPackets)
11151 {
11152 if (groupTitleUpdate.AgentData.SessionID != SessionId ||
11153 groupTitleUpdate.AgentData.AgentID != AgentId)
11154 return true;
11155 }
11156 #endregion
11157  
11158 if (m_GroupsModule != null)
11159 {
11160 m_GroupsModule.GroupTitleUpdate(this,
11161 groupTitleUpdate.AgentData.GroupID,
11162 groupTitleUpdate.AgentData.TitleRoleID);
11163 }
11164  
11165 return true;
11166 }
11167 private bool HandleParcelDeedToGroup(IClientAPI sender, Packet Pack)
11168 {
11169 ParcelDeedToGroupPacket parcelDeedToGroup = (ParcelDeedToGroupPacket)Pack;
11170 if (m_GroupsModule != null)
11171 {
11172 ParcelDeedToGroup handlerParcelDeedToGroup = OnParcelDeedToGroup;
11173 if (handlerParcelDeedToGroup != null)
11174 {
11175 handlerParcelDeedToGroup(parcelDeedToGroup.Data.LocalID, parcelDeedToGroup.Data.GroupID, this);
11176  
11177 }
11178 }
11179  
11180 return true;
11181 }
11182 private bool HandleGroupNoticesListRequest(IClientAPI sender, Packet Pack)
11183 {
11184 GroupNoticesListRequestPacket groupNoticesListRequest =
11185 (GroupNoticesListRequestPacket)Pack;
11186  
11187 #region Packet Session and User Check
11188 if (m_checkPackets)
11189 {
11190 if (groupNoticesListRequest.AgentData.SessionID != SessionId ||
11191 groupNoticesListRequest.AgentData.AgentID != AgentId)
11192 return true;
11193 }
11194 #endregion
11195  
11196 if (m_GroupsModule != null)
11197 {
11198 GroupNoticeData[] gn =
11199 m_GroupsModule.GroupNoticesListRequest(this,
11200 groupNoticesListRequest.Data.GroupID);
11201  
11202 GroupNoticesListReplyPacket groupNoticesListReply = (GroupNoticesListReplyPacket)PacketPool.Instance.GetPacket(PacketType.GroupNoticesListReply);
11203 groupNoticesListReply.AgentData =
11204 new GroupNoticesListReplyPacket.AgentDataBlock();
11205 groupNoticesListReply.AgentData.AgentID = AgentId;
11206 groupNoticesListReply.AgentData.GroupID = groupNoticesListRequest.Data.GroupID;
11207  
11208 groupNoticesListReply.Data = new GroupNoticesListReplyPacket.DataBlock[gn.Length];
11209  
11210 int i = 0;
11211 foreach (GroupNoticeData g in gn)
11212 {
11213 groupNoticesListReply.Data[i] = new GroupNoticesListReplyPacket.DataBlock();
11214 groupNoticesListReply.Data[i].NoticeID =
11215 g.NoticeID;
11216 groupNoticesListReply.Data[i].Timestamp =
11217 g.Timestamp;
11218 groupNoticesListReply.Data[i].FromName =
11219 Util.StringToBytes256(g.FromName);
11220 groupNoticesListReply.Data[i].Subject =
11221 Util.StringToBytes256(g.Subject);
11222 groupNoticesListReply.Data[i].HasAttachment =
11223 g.HasAttachment;
11224 groupNoticesListReply.Data[i].AssetType =
11225 g.AssetType;
11226 i++;
11227 }
11228  
11229 OutPacket(groupNoticesListReply, ThrottleOutPacketType.Task);
11230 }
11231  
11232 return true;
11233 }
11234 private bool HandleGroupNoticeRequest(IClientAPI sender, Packet Pack)
11235 {
11236 GroupNoticeRequestPacket groupNoticeRequest =
11237 (GroupNoticeRequestPacket)Pack;
11238  
11239 #region Packet Session and User Check
11240 if (m_checkPackets)
11241 {
11242 if (groupNoticeRequest.AgentData.SessionID != SessionId ||
11243 groupNoticeRequest.AgentData.AgentID != AgentId)
11244 return true;
11245 }
11246 #endregion
11247  
11248 if (m_GroupsModule != null)
11249 {
11250 m_GroupsModule.GroupNoticeRequest(this,
11251 groupNoticeRequest.Data.GroupNoticeID);
11252 }
11253 return true;
11254 }
11255 private bool HandleGroupRoleUpdate(IClientAPI sender, Packet Pack)
11256 {
11257 GroupRoleUpdatePacket groupRoleUpdate =
11258 (GroupRoleUpdatePacket)Pack;
11259  
11260 #region Packet Session and User Check
11261 if (m_checkPackets)
11262 {
11263 if (groupRoleUpdate.AgentData.SessionID != SessionId ||
11264 groupRoleUpdate.AgentData.AgentID != AgentId)
11265 return true;
11266 }
11267 #endregion
11268  
11269 if (m_GroupsModule != null)
11270 {
11271 foreach (GroupRoleUpdatePacket.RoleDataBlock d in
11272 groupRoleUpdate.RoleData)
11273 {
11274 m_GroupsModule.GroupRoleUpdate(this,
11275 groupRoleUpdate.AgentData.GroupID,
11276 d.RoleID,
11277 Utils.BytesToString(d.Name),
11278 Utils.BytesToString(d.Description),
11279 Utils.BytesToString(d.Title),
11280 d.Powers,
11281 d.UpdateType);
11282 }
11283 m_GroupsModule.NotifyChange(groupRoleUpdate.AgentData.GroupID);
11284 }
11285 return true;
11286 }
11287 private bool HandleGroupRoleChanges(IClientAPI sender, Packet Pack)
11288 {
11289 GroupRoleChangesPacket groupRoleChanges =
11290 (GroupRoleChangesPacket)Pack;
11291  
11292 #region Packet Session and User Check
11293 if (m_checkPackets)
11294 {
11295 if (groupRoleChanges.AgentData.SessionID != SessionId ||
11296 groupRoleChanges.AgentData.AgentID != AgentId)
11297 return true;
11298 }
11299 #endregion
11300  
11301 if (m_GroupsModule != null)
11302 {
11303 foreach (GroupRoleChangesPacket.RoleChangeBlock d in
11304 groupRoleChanges.RoleChange)
11305 {
11306 m_GroupsModule.GroupRoleChanges(this,
11307 groupRoleChanges.AgentData.GroupID,
11308 d.RoleID,
11309 d.MemberID,
11310 d.Change);
11311 }
11312 m_GroupsModule.NotifyChange(groupRoleChanges.AgentData.GroupID);
11313 }
11314 return true;
11315 }
11316 private bool HandleJoinGroupRequest(IClientAPI sender, Packet Pack)
11317 {
11318 JoinGroupRequestPacket joinGroupRequest =
11319 (JoinGroupRequestPacket)Pack;
11320  
11321 #region Packet Session and User Check
11322 if (m_checkPackets)
11323 {
11324 if (joinGroupRequest.AgentData.SessionID != SessionId ||
11325 joinGroupRequest.AgentData.AgentID != AgentId)
11326 return true;
11327 }
11328 #endregion
11329  
11330 if (m_GroupsModule != null)
11331 {
11332 m_GroupsModule.JoinGroupRequest(this,
11333 joinGroupRequest.GroupData.GroupID);
11334 }
11335 return true;
11336 }
11337 private bool HandleLeaveGroupRequest(IClientAPI sender, Packet Pack)
11338 {
11339 LeaveGroupRequestPacket leaveGroupRequest =
11340 (LeaveGroupRequestPacket)Pack;
11341  
11342 #region Packet Session and User Check
11343 if (m_checkPackets)
11344 {
11345 if (leaveGroupRequest.AgentData.SessionID != SessionId ||
11346 leaveGroupRequest.AgentData.AgentID != AgentId)
11347 return true;
11348 }
11349 #endregion
11350  
11351 if (m_GroupsModule != null)
11352 {
11353 m_GroupsModule.LeaveGroupRequest(this,
11354 leaveGroupRequest.GroupData.GroupID);
11355 }
11356 return true;
11357 }
11358 private bool HandleEjectGroupMemberRequest(IClientAPI sender, Packet Pack)
11359 {
11360 EjectGroupMemberRequestPacket ejectGroupMemberRequest =
11361 (EjectGroupMemberRequestPacket)Pack;
11362  
11363 #region Packet Session and User Check
11364 if (m_checkPackets)
11365 {
11366 if (ejectGroupMemberRequest.AgentData.SessionID != SessionId ||
11367 ejectGroupMemberRequest.AgentData.AgentID != AgentId)
11368 return true;
11369 }
11370 #endregion
11371  
11372 if (m_GroupsModule != null)
11373 {
11374 foreach (EjectGroupMemberRequestPacket.EjectDataBlock e
11375 in ejectGroupMemberRequest.EjectData)
11376 {
11377 m_GroupsModule.EjectGroupMemberRequest(this,
11378 ejectGroupMemberRequest.GroupData.GroupID,
11379 e.EjecteeID);
11380 }
11381 }
11382 return true;
11383 }
11384 private bool HandleInviteGroupRequest(IClientAPI sender, Packet Pack)
11385 {
11386 InviteGroupRequestPacket inviteGroupRequest =
11387 (InviteGroupRequestPacket)Pack;
11388  
11389 #region Packet Session and User Check
11390 if (m_checkPackets)
11391 {
11392 if (inviteGroupRequest.AgentData.SessionID != SessionId ||
11393 inviteGroupRequest.AgentData.AgentID != AgentId)
11394 return true;
11395 }
11396 #endregion
11397  
11398 if (m_GroupsModule != null)
11399 {
11400 foreach (InviteGroupRequestPacket.InviteDataBlock b in
11401 inviteGroupRequest.InviteData)
11402 {
11403 m_GroupsModule.InviteGroupRequest(this,
11404 inviteGroupRequest.GroupData.GroupID,
11405 b.InviteeID,
11406 b.RoleID);
11407 }
11408 }
11409 return true;
11410 }
11411  
11412 #endregion Groups
11413  
11414 private bool HandleStartLure(IClientAPI sender, Packet Pack)
11415 {
11416 StartLurePacket startLureRequest = (StartLurePacket)Pack;
11417  
11418 #region Packet Session and User Check
11419 if (m_checkPackets)
11420 {
11421 if (startLureRequest.AgentData.SessionID != SessionId ||
11422 startLureRequest.AgentData.AgentID != AgentId)
11423 return true;
11424 }
11425 #endregion
11426  
11427 StartLure handlerStartLure = OnStartLure;
11428 if (handlerStartLure != null)
11429 handlerStartLure(startLureRequest.Info.LureType,
11430 Utils.BytesToString(
11431 startLureRequest.Info.Message),
11432 startLureRequest.TargetData[0].TargetID,
11433 this);
11434 return true;
11435 }
11436 private bool HandleTeleportLureRequest(IClientAPI sender, Packet Pack)
11437 {
11438 TeleportLureRequestPacket teleportLureRequest =
11439 (TeleportLureRequestPacket)Pack;
11440  
11441 #region Packet Session and User Check
11442 if (m_checkPackets)
11443 {
11444 if (teleportLureRequest.Info.SessionID != SessionId ||
11445 teleportLureRequest.Info.AgentID != AgentId)
11446 return true;
11447 }
11448 #endregion
11449  
11450 TeleportLureRequest handlerTeleportLureRequest = OnTeleportLureRequest;
11451 if (handlerTeleportLureRequest != null)
11452 handlerTeleportLureRequest(
11453 teleportLureRequest.Info.LureID,
11454 teleportLureRequest.Info.TeleportFlags,
11455 this);
11456 return true;
11457 }
11458 private bool HandleClassifiedInfoRequest(IClientAPI sender, Packet Pack)
11459 {
11460 ClassifiedInfoRequestPacket classifiedInfoRequest =
11461 (ClassifiedInfoRequestPacket)Pack;
11462  
11463 #region Packet Session and User Check
11464 if (m_checkPackets)
11465 {
11466 if (classifiedInfoRequest.AgentData.SessionID != SessionId ||
11467 classifiedInfoRequest.AgentData.AgentID != AgentId)
11468 return true;
11469 }
11470 #endregion
11471  
11472 ClassifiedInfoRequest handlerClassifiedInfoRequest = OnClassifiedInfoRequest;
11473 if (handlerClassifiedInfoRequest != null)
11474 handlerClassifiedInfoRequest(
11475 classifiedInfoRequest.Data.ClassifiedID,
11476 this);
11477 return true;
11478 }
11479 private bool HandleClassifiedInfoUpdate(IClientAPI sender, Packet Pack)
11480 {
11481 ClassifiedInfoUpdatePacket classifiedInfoUpdate =
11482 (ClassifiedInfoUpdatePacket)Pack;
11483  
11484 #region Packet Session and User Check
11485 if (m_checkPackets)
11486 {
11487 if (classifiedInfoUpdate.AgentData.SessionID != SessionId ||
11488 classifiedInfoUpdate.AgentData.AgentID != AgentId)
11489 return true;
11490 }
11491 #endregion
11492  
11493 ClassifiedInfoUpdate handlerClassifiedInfoUpdate = OnClassifiedInfoUpdate;
11494 if (handlerClassifiedInfoUpdate != null)
11495 handlerClassifiedInfoUpdate(
11496 classifiedInfoUpdate.Data.ClassifiedID,
11497 classifiedInfoUpdate.Data.Category,
11498 Utils.BytesToString(
11499 classifiedInfoUpdate.Data.Name),
11500 Utils.BytesToString(
11501 classifiedInfoUpdate.Data.Desc),
11502 classifiedInfoUpdate.Data.ParcelID,
11503 classifiedInfoUpdate.Data.ParentEstate,
11504 classifiedInfoUpdate.Data.SnapshotID,
11505 new Vector3(
11506 classifiedInfoUpdate.Data.PosGlobal),
11507 classifiedInfoUpdate.Data.ClassifiedFlags,
11508 classifiedInfoUpdate.Data.PriceForListing,
11509 this);
11510 return true;
11511 }
11512 private bool HandleClassifiedDelete(IClientAPI sender, Packet Pack)
11513 {
11514 ClassifiedDeletePacket classifiedDelete =
11515 (ClassifiedDeletePacket)Pack;
11516  
11517 #region Packet Session and User Check
11518 if (m_checkPackets)
11519 {
11520 if (classifiedDelete.AgentData.SessionID != SessionId ||
11521 classifiedDelete.AgentData.AgentID != AgentId)
11522 return true;
11523 }
11524 #endregion
11525  
11526 ClassifiedDelete handlerClassifiedDelete = OnClassifiedDelete;
11527 if (handlerClassifiedDelete != null)
11528 handlerClassifiedDelete(
11529 classifiedDelete.Data.ClassifiedID,
11530 this);
11531 return true;
11532 }
11533 private bool HandleClassifiedGodDelete(IClientAPI sender, Packet Pack)
11534 {
11535 ClassifiedGodDeletePacket classifiedGodDelete =
11536 (ClassifiedGodDeletePacket)Pack;
11537  
11538 #region Packet Session and User Check
11539 if (m_checkPackets)
11540 {
11541 if (classifiedGodDelete.AgentData.SessionID != SessionId ||
11542 classifiedGodDelete.AgentData.AgentID != AgentId)
11543 return true;
11544 }
11545 #endregion
11546  
11547 ClassifiedDelete handlerClassifiedGodDelete = OnClassifiedGodDelete;
11548 if (handlerClassifiedGodDelete != null)
11549 handlerClassifiedGodDelete(
11550 classifiedGodDelete.Data.ClassifiedID,
11551 this);
11552 return true;
11553 }
11554 private bool HandleEventGodDelete(IClientAPI sender, Packet Pack)
11555 {
11556 EventGodDeletePacket eventGodDelete =
11557 (EventGodDeletePacket)Pack;
11558  
11559 #region Packet Session and User Check
11560 if (m_checkPackets)
11561 {
11562 if (eventGodDelete.AgentData.SessionID != SessionId ||
11563 eventGodDelete.AgentData.AgentID != AgentId)
11564 return true;
11565 }
11566 #endregion
11567  
11568 EventGodDelete handlerEventGodDelete = OnEventGodDelete;
11569 if (handlerEventGodDelete != null)
11570 handlerEventGodDelete(
11571 eventGodDelete.EventData.EventID,
11572 eventGodDelete.QueryData.QueryID,
11573 Utils.BytesToString(
11574 eventGodDelete.QueryData.QueryText),
11575 eventGodDelete.QueryData.QueryFlags,
11576 eventGodDelete.QueryData.QueryStart,
11577 this);
11578 return true;
11579 }
11580 private bool HandleEventNotificationAddRequest(IClientAPI sender, Packet Pack)
11581 {
11582 EventNotificationAddRequestPacket eventNotificationAdd =
11583 (EventNotificationAddRequestPacket)Pack;
11584  
11585 #region Packet Session and User Check
11586 if (m_checkPackets)
11587 {
11588 if (eventNotificationAdd.AgentData.SessionID != SessionId ||
11589 eventNotificationAdd.AgentData.AgentID != AgentId)
11590 return true;
11591 }
11592 #endregion
11593  
11594 EventNotificationAddRequest handlerEventNotificationAddRequest = OnEventNotificationAddRequest;
11595 if (handlerEventNotificationAddRequest != null)
11596 handlerEventNotificationAddRequest(
11597 eventNotificationAdd.EventData.EventID, this);
11598 return true;
11599 }
11600 private bool HandleEventNotificationRemoveRequest(IClientAPI sender, Packet Pack)
11601 {
11602 EventNotificationRemoveRequestPacket eventNotificationRemove =
11603 (EventNotificationRemoveRequestPacket)Pack;
11604  
11605 #region Packet Session and User Check
11606 if (m_checkPackets)
11607 {
11608 if (eventNotificationRemove.AgentData.SessionID != SessionId ||
11609 eventNotificationRemove.AgentData.AgentID != AgentId)
11610 return true;
11611 }
11612 #endregion
11613  
11614 EventNotificationRemoveRequest handlerEventNotificationRemoveRequest = OnEventNotificationRemoveRequest;
11615 if (handlerEventNotificationRemoveRequest != null)
11616 handlerEventNotificationRemoveRequest(
11617 eventNotificationRemove.EventData.EventID, this);
11618 return true;
11619 }
11620 private bool HandleRetrieveInstantMessages(IClientAPI sender, Packet Pack)
11621 {
11622 RetrieveInstantMessagesPacket rimpInstantMessagePack = (RetrieveInstantMessagesPacket)Pack;
11623  
11624 #region Packet Session and User Check
11625 if (m_checkPackets)
11626 {
11627 if (rimpInstantMessagePack.AgentData.SessionID != SessionId ||
11628 rimpInstantMessagePack.AgentData.AgentID != AgentId)
11629 return true;
11630 }
11631 #endregion
11632  
11633 RetrieveInstantMessages handlerRetrieveInstantMessages = OnRetrieveInstantMessages;
11634 if (handlerRetrieveInstantMessages != null)
11635 handlerRetrieveInstantMessages(this);
11636 return true;
11637 }
11638 private bool HandlePickDelete(IClientAPI sender, Packet Pack)
11639 {
11640 PickDeletePacket pickDelete =
11641 (PickDeletePacket)Pack;
11642  
11643 #region Packet Session and User Check
11644 if (m_checkPackets)
11645 {
11646 if (pickDelete.AgentData.SessionID != SessionId ||
11647 pickDelete.AgentData.AgentID != AgentId)
11648 return true;
11649 }
11650 #endregion
11651  
11652 PickDelete handlerPickDelete = OnPickDelete;
11653 if (handlerPickDelete != null)
11654 handlerPickDelete(this, pickDelete.Data.PickID);
11655 return true;
11656 }
11657 private bool HandlePickGodDelete(IClientAPI sender, Packet Pack)
11658 {
11659 PickGodDeletePacket pickGodDelete =
11660 (PickGodDeletePacket)Pack;
11661  
11662 #region Packet Session and User Check
11663 if (m_checkPackets)
11664 {
11665 if (pickGodDelete.AgentData.SessionID != SessionId ||
11666 pickGodDelete.AgentData.AgentID != AgentId)
11667 return true;
11668 }
11669 #endregion
11670  
11671 PickGodDelete handlerPickGodDelete = OnPickGodDelete;
11672 if (handlerPickGodDelete != null)
11673 handlerPickGodDelete(this,
11674 pickGodDelete.AgentData.AgentID,
11675 pickGodDelete.Data.PickID,
11676 pickGodDelete.Data.QueryID);
11677 return true;
11678 }
11679 private bool HandlePickInfoUpdate(IClientAPI sender, Packet Pack)
11680 {
11681 PickInfoUpdatePacket pickInfoUpdate =
11682 (PickInfoUpdatePacket)Pack;
11683  
11684 #region Packet Session and User Check
11685 if (m_checkPackets)
11686 {
11687 if (pickInfoUpdate.AgentData.SessionID != SessionId ||
11688 pickInfoUpdate.AgentData.AgentID != AgentId)
11689 return true;
11690 }
11691 #endregion
11692  
11693 PickInfoUpdate handlerPickInfoUpdate = OnPickInfoUpdate;
11694 if (handlerPickInfoUpdate != null)
11695 handlerPickInfoUpdate(this,
11696 pickInfoUpdate.Data.PickID,
11697 pickInfoUpdate.Data.CreatorID,
11698 pickInfoUpdate.Data.TopPick,
11699 Utils.BytesToString(pickInfoUpdate.Data.Name),
11700 Utils.BytesToString(pickInfoUpdate.Data.Desc),
11701 pickInfoUpdate.Data.SnapshotID,
11702 pickInfoUpdate.Data.SortOrder,
11703 pickInfoUpdate.Data.Enabled);
11704 return true;
11705 }
11706 private bool HandleAvatarNotesUpdate(IClientAPI sender, Packet Pack)
11707 {
11708 AvatarNotesUpdatePacket avatarNotesUpdate =
11709 (AvatarNotesUpdatePacket)Pack;
11710  
11711 #region Packet Session and User Check
11712 if (m_checkPackets)
11713 {
11714 if (avatarNotesUpdate.AgentData.SessionID != SessionId ||
11715 avatarNotesUpdate.AgentData.AgentID != AgentId)
11716 return true;
11717 }
11718 #endregion
11719  
11720 AvatarNotesUpdate handlerAvatarNotesUpdate = OnAvatarNotesUpdate;
11721 if (handlerAvatarNotesUpdate != null)
11722 handlerAvatarNotesUpdate(this,
11723 avatarNotesUpdate.Data.TargetID,
11724 Utils.BytesToString(avatarNotesUpdate.Data.Notes));
11725 return true;
11726 }
11727 private bool HandleAvatarInterestsUpdate(IClientAPI sender, Packet Pack)
11728 {
11729 AvatarInterestsUpdatePacket avatarInterestUpdate =
11730 (AvatarInterestsUpdatePacket)Pack;
11731  
11732 #region Packet Session and User Check
11733 if (m_checkPackets)
11734 {
11735 if (avatarInterestUpdate.AgentData.SessionID != SessionId ||
11736 avatarInterestUpdate.AgentData.AgentID != AgentId)
11737 return true;
11738 }
11739 #endregion
11740  
11741 AvatarInterestUpdate handlerAvatarInterestUpdate = OnAvatarInterestUpdate;
11742 if (handlerAvatarInterestUpdate != null)
11743 handlerAvatarInterestUpdate(this,
11744 avatarInterestUpdate.PropertiesData.WantToMask,
11745 Utils.BytesToString(avatarInterestUpdate.PropertiesData.WantToText),
11746 avatarInterestUpdate.PropertiesData.SkillsMask,
11747 Utils.BytesToString(avatarInterestUpdate.PropertiesData.SkillsText),
11748 Utils.BytesToString(avatarInterestUpdate.PropertiesData.LanguagesText));
11749 return true;
11750 }
11751  
11752 private bool HandleGrantUserRights(IClientAPI sender, Packet Pack)
11753 {
11754 GrantUserRightsPacket GrantUserRights =
11755 (GrantUserRightsPacket)Pack;
11756 #region Packet Session and User Check
11757 if (m_checkPackets)
11758 {
11759 if (GrantUserRights.AgentData.SessionID != SessionId ||
11760 GrantUserRights.AgentData.AgentID != AgentId)
11761 return true;
11762 }
11763 #endregion
11764  
11765 GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights;
11766 if (GrantUserRightsHandler != null)
11767 GrantUserRightsHandler(this,
11768 GrantUserRights.Rights[0].AgentRelated,
11769 GrantUserRights.Rights[0].RelatedRights);
11770  
11771 return true;
11772 }
11773  
11774 private bool HandlePlacesQuery(IClientAPI sender, Packet Pack)
11775 {
11776 PlacesQueryPacket placesQueryPacket =
11777 (PlacesQueryPacket)Pack;
11778  
11779 PlacesQuery handlerPlacesQuery = OnPlacesQuery;
11780  
11781 if (handlerPlacesQuery != null)
11782 handlerPlacesQuery(placesQueryPacket.AgentData.QueryID,
11783 placesQueryPacket.TransactionData.TransactionID,
11784 Utils.BytesToString(
11785 placesQueryPacket.QueryData.QueryText),
11786 placesQueryPacket.QueryData.QueryFlags,
11787 (byte)placesQueryPacket.QueryData.Category,
11788 Utils.BytesToString(
11789 placesQueryPacket.QueryData.SimName),
11790 this);
11791 return true;
11792 }
11793  
11794 #endregion Packet Handlers
11795  
11796 public void SendScriptQuestion(UUID taskID, string taskName, string ownerName, UUID itemID, int question)
11797 {
11798 ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
11799 scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
11800 // TODO: don't create new blocks if recycling an old packet
11801 scriptQuestion.Data.TaskID = taskID;
11802 scriptQuestion.Data.ItemID = itemID;
11803 scriptQuestion.Data.Questions = question;
11804 scriptQuestion.Data.ObjectName = Util.StringToBytes256(taskName);
11805 scriptQuestion.Data.ObjectOwner = Util.StringToBytes256(ownerName);
11806  
11807 OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
11808 }
11809  
11810 /// <summary>
11811 /// Handler called when we receive a logout packet.
11812 /// </summary>
11813 /// <param name="client"></param>
11814 /// <param name="packet"></param>
11815 /// <returns></returns>
11816 protected virtual bool HandleLogout(IClientAPI client, Packet packet)
11817 {
11818 if (packet.Type == PacketType.LogoutRequest)
11819 {
11820 if (((LogoutRequestPacket)packet).AgentData.SessionID != SessionId) return false;
11821 }
11822  
11823 return Logout(client);
11824 }
11825  
11826 /// <summary>
11827 ///
11828 /// </summary>
11829 /// <param name="client"></param>
11830 /// <returns></returns>
11831 protected virtual bool Logout(IClientAPI client)
11832 {
11833 m_log.InfoFormat("[CLIENT]: Got a logout request for {0} in {1}", Name, Scene.RegionInfo.RegionName);
11834  
11835 Action<IClientAPI> handlerLogout = OnLogout;
11836  
11837 if (handlerLogout != null)
11838 {
11839 handlerLogout(client);
11840 }
11841  
11842 return true;
11843 }
11844  
11845 /// <summary>
11846 /// </summary>
11847 /// <remarks>
11848 /// At the moment, we always reply that there is no cached texture.
11849 /// </remarks>
11850 /// <param name="simclient"></param>
11851 /// <param name="packet"></param>
11852 /// <returns></returns>
11853 protected bool HandleAgentTextureCached(IClientAPI simclient, Packet packet)
11854 {
11855 AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
11856 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
11857  
11858 if (cachedtex.AgentData.SessionID != SessionId)
11859 return false;
11860  
11861  
11862 // TODO: don't create new blocks if recycling an old packet
11863 cachedresp.AgentData.AgentID = AgentId;
11864 cachedresp.AgentData.SessionID = m_sessionId;
11865 cachedresp.AgentData.SerialNum = m_cachedTextureSerial;
11866 m_cachedTextureSerial++;
11867 cachedresp.WearableData =
11868 new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
11869  
11870 int maxWearablesLoop = cachedtex.WearableData.Length;
11871 if (maxWearablesLoop > AvatarWearable.MAX_WEARABLES)
11872 maxWearablesLoop = AvatarWearable.MAX_WEARABLES;
11873  
11874 // Find the cached baked textures for this user, if they're available
11875  
11876 IAssetService cache = m_scene.AssetService;
11877 IBakedTextureModule bakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
11878  
11879 WearableCacheItem[] cacheItems = null;
11880  
11881 if (bakedTextureModule != null && cache != null)
11882 {
11883 ScenePresence p = m_scene.GetScenePresence(AgentId);
11884 if (p.Appearance != null)
11885 {
11886 if (p.Appearance.WearableCacheItems == null || p.Appearance.WearableCacheItemsDirty)
11887 {
11888 try
11889 {
11890 cacheItems = bakedTextureModule.Get(AgentId);
11891 p.Appearance.WearableCacheItems = cacheItems;
11892 p.Appearance.WearableCacheItemsDirty = false;
11893 }
11894 catch (Exception)
11895 {
11896 cacheItems = null;
11897 }
11898  
11899 }
11900 else if (p.Appearance.WearableCacheItems != null)
11901 {
11902 cacheItems = p.Appearance.WearableCacheItems;
11903 }
11904 }
11905 }
11906  
11907 if (cacheItems != null)
11908 {
11909 // We need to make sure the asset stored in the bake is available on this server also by its assetid before we map it to a Cacheid.
11910 // Copy the baked textures to the sim's assets cache (local only).
11911 foreach (WearableCacheItem item in cacheItems)
11912 {
11913 if (cache.GetCached(item.TextureID.ToString()) == null)
11914 {
11915 item.TextureAsset.Temporary = true;
11916 item.TextureAsset.Local = true;
11917 cache.Store(item.TextureAsset);
11918 }
11919 }
11920  
11921 // Return the cached textures
11922 for (int i = 0; i < maxWearablesLoop; i++)
11923 {
11924 WearableCacheItem item =
11925 WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex, cacheItems);
11926  
11927 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
11928 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
11929 cachedresp.WearableData[i].HostName = new byte[0];
11930 if (item != null && cachedtex.WearableData[i].ID == item.CacheId)
11931 {
11932 cachedresp.WearableData[i].TextureID = item.TextureID;
11933 }
11934 else
11935 {
11936 cachedresp.WearableData[i].TextureID = UUID.Zero;
11937 }
11938 }
11939 }
11940 else
11941 {
11942 // Cached textures not available
11943 for (int i = 0; i < maxWearablesLoop; i++)
11944 {
11945 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
11946 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
11947 cachedresp.WearableData[i].TextureID = UUID.Zero;
11948 cachedresp.WearableData[i].HostName = new byte[0];
11949 }
11950 }
11951  
11952 cachedresp.Header.Zerocoded = true;
11953 OutPacket(cachedresp, ThrottleOutPacketType.Task);
11954  
11955 return true;
11956 }
11957  
11958 /// <summary>
11959 /// Send a response back to a client when it asks the asset server (via the region server) if it has
11960 /// its appearance texture cached.
11961 /// </summary>
11962 /// <param name="avatar"></param>
11963 /// <param name="serial"></param>
11964 /// <param name="cachedTextures"></param>
11965 /// <returns></returns>
11966 public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures)
11967 {
11968 ScenePresence presence = avatar as ScenePresence;
11969 if (presence == null)
11970 return;
11971  
11972 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
11973  
11974 // TODO: don't create new blocks if recycling an old packet
11975 cachedresp.AgentData.AgentID = m_agentId;
11976 cachedresp.AgentData.SessionID = m_sessionId;
11977 cachedresp.AgentData.SerialNum = serial;
11978 cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[cachedTextures.Count];
11979  
11980 for (int i = 0; i < cachedTextures.Count; i++)
11981 {
11982 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
11983 cachedresp.WearableData[i].TextureIndex = (byte)cachedTextures[i].BakedTextureIndex;
11984 cachedresp.WearableData[i].TextureID = cachedTextures[i].BakedTextureID;
11985 cachedresp.WearableData[i].HostName = new byte[0];
11986 }
11987  
11988 cachedresp.Header.Zerocoded = true;
11989 OutPacket(cachedresp, ThrottleOutPacketType.Task);
11990 }
11991  
11992 protected bool HandleMultipleObjUpdate(IClientAPI simClient, Packet packet)
11993 {
11994 MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
11995  
11996 if (multipleupdate.AgentData.SessionID != SessionId)
11997 return false;
11998  
11999 // m_log.DebugFormat(
12000 // "[CLIENT]: Incoming MultipleObjectUpdatePacket contained {0} blocks", multipleupdate.ObjectData.Length);
12001  
12002 Scene tScene = (Scene)m_scene;
12003  
12004 for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
12005 {
12006 MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
12007  
12008 // Can't act on Null Data
12009 if (block.Data != null)
12010 {
12011 uint localId = block.ObjectLocalID;
12012 SceneObjectPart part = tScene.GetSceneObjectPart(localId);
12013  
12014 if (part == null)
12015 {
12016 // It's a ghost! tell the client to delete it from view.
12017 simClient.SendKillObject(new List<uint> { localId });
12018 }
12019 else
12020 {
12021 // m_log.DebugFormat(
12022 // "[CLIENT]: Processing block {0} type {1} for {2} {3}",
12023 // i, block.Type, part.Name, part.LocalId);
12024  
12025 // // Do this once since fetch parts creates a new array.
12026 // SceneObjectPart[] parts = part.ParentGroup.Parts;
12027 // for (int j = 0; j < parts.Length; j++)
12028 // {
12029 // part.StoreUndoState();
12030 // parts[j].IgnoreUndoUpdate = true;
12031 // }
12032  
12033 UpdatePrimGroupRotation handlerUpdatePrimGroupRotation;
12034  
12035 switch (block.Type)
12036 {
12037 case 1:
12038 Vector3 pos1 = new Vector3(block.Data, 0);
12039  
12040 UpdateVector handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
12041 if (handlerUpdatePrimSinglePosition != null)
12042 {
12043 // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
12044 handlerUpdatePrimSinglePosition(localId, pos1, this);
12045 }
12046 break;
12047  
12048 case 2:
12049 Quaternion rot1 = new Quaternion(block.Data, 0, true);
12050  
12051 UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
12052 if (handlerUpdatePrimSingleRotation != null)
12053 {
12054 // m_log.Info("new tab rotation is " + rot1.X + " , " + rot1.Y + " , " + rot1.Z + " , " + rot1.W);
12055 handlerUpdatePrimSingleRotation(localId, rot1, this);
12056 }
12057 break;
12058  
12059 case 3:
12060 Vector3 rotPos = new Vector3(block.Data, 0);
12061 Quaternion rot2 = new Quaternion(block.Data, 12, true);
12062  
12063 UpdatePrimSingleRotationPosition handlerUpdatePrimSingleRotationPosition = OnUpdatePrimSingleRotationPosition;
12064 if (handlerUpdatePrimSingleRotationPosition != null)
12065 {
12066 // m_log.Debug("new mouse rotation position is " + rotPos.X + " , " + rotPos.Y + " , " + rotPos.Z);
12067 // m_log.Info("new mouse rotation is " + rot2.X + " , " + rot2.Y + " , " + rot2.Z + " , " + rot2.W);
12068 handlerUpdatePrimSingleRotationPosition(localId, rot2, rotPos, this);
12069 }
12070 break;
12071  
12072 case 4:
12073 case 20:
12074 Vector3 scale4 = new Vector3(block.Data, 0);
12075  
12076 UpdateVector handlerUpdatePrimScale = OnUpdatePrimScale;
12077 if (handlerUpdatePrimScale != null)
12078 {
12079 // m_log.Debug("new scale is " + scale4.X + " , " + scale4.Y + " , " + scale4.Z);
12080 handlerUpdatePrimScale(localId, scale4, this);
12081 }
12082 break;
12083  
12084 case 5:
12085 Vector3 scale1 = new Vector3(block.Data, 12);
12086 Vector3 pos11 = new Vector3(block.Data, 0);
12087  
12088 handlerUpdatePrimScale = OnUpdatePrimScale;
12089 if (handlerUpdatePrimScale != null)
12090 {
12091 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12092 handlerUpdatePrimScale(localId, scale1, this);
12093  
12094 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
12095 if (handlerUpdatePrimSinglePosition != null)
12096 {
12097 handlerUpdatePrimSinglePosition(localId, pos11, this);
12098 }
12099 }
12100 break;
12101  
12102 case 9:
12103 Vector3 pos2 = new Vector3(block.Data, 0);
12104  
12105 UpdateVector handlerUpdateVector = OnUpdatePrimGroupPosition;
12106  
12107 if (handlerUpdateVector != null)
12108 {
12109 handlerUpdateVector(localId, pos2, this);
12110 }
12111 break;
12112  
12113 case 10:
12114 Quaternion rot3 = new Quaternion(block.Data, 0, true);
12115  
12116 UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
12117 if (handlerUpdatePrimRotation != null)
12118 {
12119 // Console.WriteLine("new rotation is " + rot3.X + " , " + rot3.Y + " , " + rot3.Z + " , " + rot3.W);
12120 handlerUpdatePrimRotation(localId, rot3, this);
12121 }
12122 break;
12123  
12124 case 11:
12125 Vector3 pos3 = new Vector3(block.Data, 0);
12126 Quaternion rot4 = new Quaternion(block.Data, 12, true);
12127  
12128 handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
12129 if (handlerUpdatePrimGroupRotation != null)
12130 {
12131 // m_log.Debug("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
12132 // m_log.Debug("new group mouse rotation is " + rot4.X + " , " + rot4.Y + " , " + rot4.Z + " , " + rot4.W);
12133 handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
12134 }
12135 break;
12136 case 12:
12137 case 28:
12138 Vector3 scale7 = new Vector3(block.Data, 0);
12139  
12140 UpdateVector handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
12141 if (handlerUpdatePrimGroupScale != null)
12142 {
12143 // m_log.Debug("new scale is " + scale7.X + " , " + scale7.Y + " , " + scale7.Z);
12144 handlerUpdatePrimGroupScale(localId, scale7, this);
12145 }
12146 break;
12147  
12148 case 13:
12149 Vector3 scale2 = new Vector3(block.Data, 12);
12150 Vector3 pos4 = new Vector3(block.Data, 0);
12151  
12152 handlerUpdatePrimScale = OnUpdatePrimScale;
12153 if (handlerUpdatePrimScale != null)
12154 {
12155 //m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12156 handlerUpdatePrimScale(localId, scale2, this);
12157  
12158 // Change the position based on scale (for bug number 246)
12159 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
12160 // m_log.Debug("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
12161 if (handlerUpdatePrimSinglePosition != null)
12162 {
12163 handlerUpdatePrimSinglePosition(localId, pos4, this);
12164 }
12165 }
12166 break;
12167  
12168 case 29:
12169 Vector3 scale5 = new Vector3(block.Data, 12);
12170 Vector3 pos5 = new Vector3(block.Data, 0);
12171  
12172 handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
12173 if (handlerUpdatePrimGroupScale != null)
12174 {
12175 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12176 part.StoreUndoState(true);
12177 part.IgnoreUndoUpdate = true;
12178 handlerUpdatePrimGroupScale(localId, scale5, this);
12179 handlerUpdateVector = OnUpdatePrimGroupPosition;
12180  
12181 if (handlerUpdateVector != null)
12182 {
12183 handlerUpdateVector(localId, pos5, this);
12184 }
12185  
12186 part.IgnoreUndoUpdate = false;
12187 }
12188  
12189 break;
12190  
12191 case 21:
12192 Vector3 scale6 = new Vector3(block.Data, 12);
12193 Vector3 pos6 = new Vector3(block.Data, 0);
12194  
12195 handlerUpdatePrimScale = OnUpdatePrimScale;
12196 if (handlerUpdatePrimScale != null)
12197 {
12198 part.StoreUndoState(false);
12199 part.IgnoreUndoUpdate = true;
12200  
12201 // m_log.Debug("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
12202 handlerUpdatePrimScale(localId, scale6, this);
12203 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
12204 if (handlerUpdatePrimSinglePosition != null)
12205 {
12206 handlerUpdatePrimSinglePosition(localId, pos6, this);
12207 }
12208  
12209 part.IgnoreUndoUpdate = false;
12210 }
12211 break;
12212  
12213 default:
12214 m_log.Debug("[CLIENT]: MultipleObjUpdate recieved an unknown packet type: " + (block.Type));
12215 break;
12216 }
12217  
12218 // for (int j = 0; j < parts.Length; j++)
12219 // parts[j].IgnoreUndoUpdate = false;
12220 }
12221 }
12222 }
12223  
12224 return true;
12225 }
12226  
12227 public void RequestMapLayer()
12228 {
12229 //should be getting the map layer from the grid server
12230 //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
12231 MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
12232 // TODO: don't create new blocks if recycling an old packet
12233 mapReply.AgentData.AgentID = AgentId;
12234 mapReply.AgentData.Flags = 0;
12235 mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
12236 mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
12237 mapReply.LayerData[0].Bottom = 0;
12238 mapReply.LayerData[0].Left = 0;
12239 mapReply.LayerData[0].Top = 30000;
12240 mapReply.LayerData[0].Right = 30000;
12241 mapReply.LayerData[0].ImageID = new UUID("00000000-0000-1111-9999-000000000006");
12242 mapReply.Header.Zerocoded = true;
12243 OutPacket(mapReply, ThrottleOutPacketType.Land);
12244 }
12245  
12246 public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
12247 {
12248 /*
12249 IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
12250 MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
12251 mbReply.AgentData.AgentId = AgentId;
12252 int len;
12253 if (simMapProfiles == null)
12254 len = 0;
12255 else
12256 len = simMapProfiles.Count;
12257  
12258 mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
12259 int iii;
12260 for (iii = 0; iii < len; iii++)
12261 {
12262 Hashtable mp = (Hashtable)simMapProfiles[iii];
12263 mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
12264 mbReply.Data[iii].Name = Util.UTF8.GetBytes((string)mp["name"]);
12265 mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
12266 mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
12267 mbReply.Data[iii].MapImageID = new UUID((string)mp["map-image-id"]);
12268 mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
12269 mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
12270 mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
12271 mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
12272 }
12273 this.OutPacket(mbReply, ThrottleOutPacketType.Land);
12274 */
12275 }
12276  
12277 /// <summary>
12278 /// Sets the throttles from values supplied by the client
12279 /// </summary>
12280 /// <param name="throttles"></param>
12281 public void SetChildAgentThrottle(byte[] throttles)
12282 {
12283 m_udpClient.SetThrottles(throttles);
12284 }
12285  
12286 /// <summary>
12287 /// Get the current throttles for this client as a packed byte array
12288 /// </summary>
12289 /// <param name="multiplier">Unused</param>
12290 /// <returns></returns>
12291 public byte[] GetThrottlesPacked(float multiplier)
12292 {
12293 return m_udpClient.GetThrottlesPacked(multiplier);
12294 }
12295  
12296 /// <summary>
12297 /// Cruft?
12298 /// </summary>
12299 public virtual void InPacket(object NewPack)
12300 {
12301 throw new NotImplementedException();
12302 }
12303  
12304 /// <summary>
12305 /// This is the starting point for sending a simulator packet out to the client
12306 /// </summary>
12307 /// <param name="packet">Packet to send</param>
12308 /// <param name="throttlePacketType">Throttling category for the packet</param>
12309 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType)
12310 {
12311 #region BinaryStats
12312 LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length);
12313 #endregion BinaryStats
12314  
12315 OutPacket(packet, throttlePacketType, true);
12316 }
12317  
12318 /// <summary>
12319 /// This is the starting point for sending a simulator packet out to the client
12320 /// </summary>
12321 /// <param name="packet">Packet to send</param>
12322 /// <param name="throttlePacketType">Throttling category for the packet</param>
12323 /// <param name="doAutomaticSplitting">True to automatically split oversized
12324 /// packets (the default), or false to disable splitting if the calling code
12325 /// handles splitting manually</param>
12326 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting)
12327 {
12328 OutPacket(packet, throttlePacketType, doAutomaticSplitting, null);
12329 }
12330  
12331 /// <summary>
12332 /// This is the starting point for sending a simulator packet out to the client
12333 /// </summary>
12334 /// <param name="packet">Packet to send</param>
12335 /// <param name="throttlePacketType">Throttling category for the packet</param>
12336 /// <param name="doAutomaticSplitting">True to automatically split oversized
12337 /// packets (the default), or false to disable splitting if the calling code
12338 /// handles splitting manually</param>
12339 /// <param name="method">The method to be called in the event this packet is reliable
12340 /// and unacknowledged. The server will provide normal resend capability if you do not
12341 /// provide your own method.</param>
12342 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting, UnackedPacketMethod method)
12343 {
12344 if (m_outPacketsToDrop != null)
12345 if (m_outPacketsToDrop.Contains(packet.Type.ToString()))
12346 return;
12347  
12348 if (DebugPacketLevel > 0)
12349 {
12350 bool logPacket = true;
12351  
12352 if (DebugPacketLevel <= 255
12353 && (packet.Type == PacketType.SimStats || packet.Type == PacketType.SimulatorViewerTimeMessage))
12354 logPacket = false;
12355  
12356 if (DebugPacketLevel <= 200
12357 && (packet.Type == PacketType.ImagePacket
12358 || packet.Type == PacketType.ImageData
12359 || packet.Type == PacketType.LayerData
12360 || packet.Type == PacketType.CoarseLocationUpdate))
12361 logPacket = false;
12362  
12363 if (DebugPacketLevel <= 100 && (packet.Type == PacketType.AvatarAnimation || packet.Type == PacketType.ViewerEffect))
12364 logPacket = false;
12365  
12366 if (DebugPacketLevel <= 50
12367 && (packet.Type == PacketType.ImprovedTerseObjectUpdate || packet.Type == PacketType.ObjectUpdate))
12368 logPacket = false;
12369  
12370 if (DebugPacketLevel <= 25 && packet.Type == PacketType.ObjectPropertiesFamily)
12371 logPacket = false;
12372  
12373 if (logPacket)
12374 m_log.DebugFormat(
12375 "[CLIENT]: PACKET OUT to {0} ({1}) in {2} - {3}",
12376 Name, SceneAgent.IsChildAgent ? "child" : "root ", m_scene.RegionInfo.RegionName, packet.Type);
12377 }
12378  
12379 m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, doAutomaticSplitting, method);
12380 }
12381  
12382 protected void HandleAutopilot(Object sender, string method, List<String> args)
12383 {
12384 float locx = 0;
12385 float locy = 0;
12386 float locz = 0;
12387 uint regionX = 0;
12388 uint regionY = 0;
12389  
12390 Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out regionX, out regionY);
12391 locx = Convert.ToSingle(args[0]) - (float)regionX;
12392 locy = Convert.ToSingle(args[1]) - (float)regionY;
12393 locz = Convert.ToSingle(args[2]);
12394  
12395 Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo;
12396 if (handlerAutoPilotGo != null)
12397 handlerAutoPilotGo(new Vector3(locx, locy, locz), false, false);
12398 }
12399  
12400 /// <summary>
12401 /// Entryway from the client to the simulator. All UDP packets from the client will end up here
12402 /// </summary>
12403 /// <param name="Pack">OpenMetaverse.packet</param>
12404 public void ProcessInPacket(Packet packet)
12405 {
12406 if (m_inPacketsToDrop != null)
12407 if (m_inPacketsToDrop.Contains(packet.Type.ToString()))
12408 return;
12409  
12410 if (DebugPacketLevel > 0)
12411 {
12412 bool logPacket = true;
12413  
12414 if (DebugPacketLevel <= 255 && packet.Type == PacketType.AgentUpdate)
12415 logPacket = false;
12416  
12417 if (DebugPacketLevel <= 200 && packet.Type == PacketType.RequestImage)
12418 logPacket = false;
12419  
12420 if (DebugPacketLevel <= 100 && (packet.Type == PacketType.ViewerEffect || packet.Type == PacketType.AgentAnimation))
12421 logPacket = false;
12422  
12423 if (DebugPacketLevel <= 25 && packet.Type == PacketType.RequestObjectPropertiesFamily)
12424 logPacket = false;
12425  
12426 if (logPacket)
12427 m_log.DebugFormat(
12428 "[CLIENT]: PACKET IN from {0} ({1}) in {2} - {3}",
12429 Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name, packet.Type);
12430 }
12431  
12432 if (!ProcessPacketMethod(packet))
12433 m_log.WarnFormat(
12434 "[CLIENT]: Unhandled packet {0} from {1} ({2}) in {3}. Ignoring.",
12435 packet.Type, Name, SceneAgent.IsChildAgent ? "child" : "root ", Scene.Name);
12436 }
12437  
12438 private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
12439 {
12440 PrimitiveBaseShape shape = new PrimitiveBaseShape();
12441  
12442 shape.PCode = addPacket.ObjectData.PCode;
12443 shape.State = addPacket.ObjectData.State;
12444 shape.LastAttachPoint = addPacket.ObjectData.State;
12445 shape.PathBegin = addPacket.ObjectData.PathBegin;
12446 shape.PathEnd = addPacket.ObjectData.PathEnd;
12447 shape.PathScaleX = addPacket.ObjectData.PathScaleX;
12448 shape.PathScaleY = addPacket.ObjectData.PathScaleY;
12449 shape.PathShearX = addPacket.ObjectData.PathShearX;
12450 shape.PathShearY = addPacket.ObjectData.PathShearY;
12451 shape.PathSkew = addPacket.ObjectData.PathSkew;
12452 shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
12453 shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
12454 shape.Scale = addPacket.ObjectData.Scale;
12455 shape.PathCurve = addPacket.ObjectData.PathCurve;
12456 shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
12457 shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
12458 shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
12459 shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
12460 shape.PathTaperX = addPacket.ObjectData.PathTaperX;
12461 shape.PathTaperY = addPacket.ObjectData.PathTaperY;
12462 shape.PathTwist = addPacket.ObjectData.PathTwist;
12463 shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
12464 Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f"));
12465 shape.TextureEntry = ntex.GetBytes();
12466 //shape.Textures = ntex;
12467 return shape;
12468 }
12469  
12470 public ClientInfo GetClientInfo()
12471 {
12472 ClientInfo info = m_udpClient.GetClientInfo();
12473  
12474 info.proxyEP = null;
12475 if (info.agentcircuit == null)
12476 info.agentcircuit = RequestClientInfo();
12477  
12478 return info;
12479 }
12480  
12481 public void SetClientInfo(ClientInfo info)
12482 {
12483 m_udpClient.SetClientInfo(info);
12484 }
12485  
12486 #region Media Parcel Members
12487  
12488 public void SendParcelMediaCommand(uint flags, ParcelMediaCommandEnum command, float time)
12489 {
12490 ParcelMediaCommandMessagePacket commandMessagePacket = new ParcelMediaCommandMessagePacket();
12491 commandMessagePacket.CommandBlock.Flags = flags;
12492 commandMessagePacket.CommandBlock.Command = (uint)command;
12493 commandMessagePacket.CommandBlock.Time = time;
12494  
12495 OutPacket(commandMessagePacket, ThrottleOutPacketType.Task);
12496 }
12497  
12498 public void SendParcelMediaUpdate(string mediaUrl, UUID mediaTextureID,
12499 byte autoScale, string mediaType, string mediaDesc, int mediaWidth, int mediaHeight,
12500 byte mediaLoop)
12501 {
12502 ParcelMediaUpdatePacket updatePacket = new ParcelMediaUpdatePacket();
12503 updatePacket.DataBlock.MediaURL = Util.StringToBytes256(mediaUrl);
12504 updatePacket.DataBlock.MediaID = mediaTextureID;
12505 updatePacket.DataBlock.MediaAutoScale = autoScale;
12506  
12507 updatePacket.DataBlockExtended.MediaType = Util.StringToBytes256(mediaType);
12508 updatePacket.DataBlockExtended.MediaDesc = Util.StringToBytes256(mediaDesc);
12509 updatePacket.DataBlockExtended.MediaWidth = mediaWidth;
12510 updatePacket.DataBlockExtended.MediaHeight = mediaHeight;
12511 updatePacket.DataBlockExtended.MediaLoop = mediaLoop;
12512  
12513 OutPacket(updatePacket, ThrottleOutPacketType.Task);
12514 }
12515  
12516 #endregion
12517  
12518 #region Camera
12519  
12520 public void SendSetFollowCamProperties(UUID objectID, SortedDictionary<int, float> parameters)
12521 {
12522 SetFollowCamPropertiesPacket packet = (SetFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.SetFollowCamProperties);
12523 packet.ObjectData.ObjectID = objectID;
12524 SetFollowCamPropertiesPacket.CameraPropertyBlock[] camPropBlock = new SetFollowCamPropertiesPacket.CameraPropertyBlock[parameters.Count];
12525 uint idx = 0;
12526 foreach (KeyValuePair<int, float> pair in parameters)
12527 {
12528 SetFollowCamPropertiesPacket.CameraPropertyBlock block = new SetFollowCamPropertiesPacket.CameraPropertyBlock();
12529 block.Type = pair.Key;
12530 block.Value = pair.Value;
12531  
12532 camPropBlock[idx++] = block;
12533 }
12534 packet.CameraProperty = camPropBlock;
12535 OutPacket(packet, ThrottleOutPacketType.Task);
12536 }
12537  
12538 public void SendClearFollowCamProperties(UUID objectID)
12539 {
12540 ClearFollowCamPropertiesPacket packet = (ClearFollowCamPropertiesPacket)PacketPool.Instance.GetPacket(PacketType.ClearFollowCamProperties);
12541 packet.ObjectData.ObjectID = objectID;
12542 OutPacket(packet, ThrottleOutPacketType.Task);
12543 }
12544  
12545 #endregion
12546  
12547 public void SetClientOption(string option, string value)
12548 {
12549 switch (option)
12550 {
12551 default:
12552 break;
12553 }
12554 }
12555  
12556 public string GetClientOption(string option)
12557 {
12558 switch (option)
12559 {
12560 default:
12561 break;
12562 }
12563 return string.Empty;
12564 }
12565  
12566 #region IClientCore
12567  
12568 private readonly Dictionary<Type, object> m_clientInterfaces = new Dictionary<Type, object>();
12569  
12570 /// <summary>
12571 /// Register an interface on this client, should only be called in the constructor.
12572 /// </summary>
12573 /// <typeparam name="T"></typeparam>
12574 /// <param name="iface"></param>
12575 protected void RegisterInterface<T>(T iface)
12576 {
12577 lock (m_clientInterfaces)
12578 {
12579 if (!m_clientInterfaces.ContainsKey(typeof(T)))
12580 {
12581 m_clientInterfaces.Add(typeof(T), iface);
12582 }
12583 }
12584 }
12585  
12586 public bool TryGet<T>(out T iface)
12587 {
12588 if (m_clientInterfaces.ContainsKey(typeof(T)))
12589 {
12590 iface = (T)m_clientInterfaces[typeof(T)];
12591 return true;
12592 }
12593 iface = default(T);
12594 return false;
12595 }
12596  
12597 public T Get<T>()
12598 {
12599 return (T)m_clientInterfaces[typeof(T)];
12600 }
12601  
12602 public void Disconnect(string reason)
12603 {
12604 Kick(reason);
12605 Thread.Sleep(1000);
12606 Disconnect();
12607 }
12608  
12609 public void Disconnect()
12610 {
12611 Close();
12612 }
12613  
12614 #endregion
12615  
12616 public void RefreshGroupMembership()
12617 {
12618 if (m_GroupsModule != null)
12619 {
12620 GroupMembershipData[] GroupMembership =
12621 m_GroupsModule.GetMembershipData(AgentId);
12622  
12623 m_groupPowers.Clear();
12624  
12625 if (GroupMembership != null)
12626 {
12627 for (int i = 0; i < GroupMembership.Length; i++)
12628 {
12629 m_groupPowers[GroupMembership[i].GroupID] = GroupMembership[i].GroupPowers;
12630 }
12631 }
12632 }
12633 }
12634  
12635 public string Report()
12636 {
12637 return m_udpClient.GetStats();
12638 }
12639  
12640 public string XReport(string uptime, string version)
12641 {
12642 return String.Empty;
12643 }
12644  
12645 public OSDMap OReport(string uptime, string version)
12646 {
12647 return new OSDMap();
12648 }
12649  
12650 /// <summary>
12651 /// Make an asset request to the asset service in response to a client request.
12652 /// </summary>
12653 /// <param name="transferRequest"></param>
12654 /// <param name="taskID"></param>
12655 protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID)
12656 {
12657 UUID requestID = UUID.Zero;
12658 int sourceType = transferRequest.TransferInfo.SourceType;
12659  
12660 if (sourceType == (int)SourceType.Asset)
12661 {
12662 requestID = new UUID(transferRequest.TransferInfo.Params, 0);
12663 }
12664 else if (sourceType == (int)SourceType.SimInventoryItem)
12665 {
12666 requestID = new UUID(transferRequest.TransferInfo.Params, 80);
12667 }
12668 else if (sourceType == (int)SourceType.SimEstate)
12669 {
12670 requestID = taskID;
12671 }
12672  
12673 // m_log.DebugFormat(
12674 // "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}",
12675 // requestID, taskID, (SourceType)sourceType, Name);
12676  
12677 m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived);
12678 }
12679  
12680 /// <summary>
12681 /// When we get a reply back from the asset service in response to a client request, send back the data.
12682 /// </summary>
12683 /// <param name="id"></param>
12684 /// <param name="sender"></param>
12685 /// <param name="asset"></param>
12686 protected void AssetReceived(string id, Object sender, AssetBase asset)
12687 {
12688 TransferRequestPacket transferRequest = (TransferRequestPacket)sender;
12689  
12690 UUID requestID = UUID.Zero;
12691 byte source = (byte)SourceType.Asset;
12692  
12693 AssetRequestToClient req = new AssetRequestToClient();
12694  
12695 if (asset == null)
12696 {
12697 // Try the user's asset server
12698 IInventoryAccessModule inventoryAccessModule = Scene.RequestModuleInterface<IInventoryAccessModule>();
12699  
12700 string assetServerURL = string.Empty;
12701 if (inventoryAccessModule.IsForeignUser(AgentId, out assetServerURL) && !string.IsNullOrEmpty(assetServerURL))
12702 {
12703 if (!assetServerURL.EndsWith("/") && !assetServerURL.EndsWith("="))
12704 assetServerURL = assetServerURL + "/";
12705  
12706 //m_log.DebugFormat("[LLCLIENTVIEW]: asset {0} not found in local storage. Trying user's storage.", assetServerURL + id);
12707 asset = m_scene.AssetService.Get(assetServerURL + id);
12708 }
12709  
12710 if (asset == null)
12711 {
12712 req.AssetInf = null;
12713 req.AssetRequestSource = source;
12714 req.IsTextureRequest = false;
12715 req.NumPackets = 0;
12716 req.Params = transferRequest.TransferInfo.Params;
12717 req.RequestAssetID = requestID;
12718 req.TransferRequestID = transferRequest.TransferInfo.TransferID;
12719  
12720 SendAssetNotFound(req);
12721 return;
12722 }
12723  
12724 }
12725  
12726 if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset)
12727 {
12728 requestID = new UUID(transferRequest.TransferInfo.Params, 0);
12729 }
12730 else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem)
12731 {
12732 requestID = new UUID(transferRequest.TransferInfo.Params, 80);
12733 source = (byte)SourceType.SimInventoryItem;
12734 //m_log.Debug("asset request " + requestID);
12735 }
12736  
12737 // Scripts cannot be retrieved by direct request
12738 if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset && asset.Type == 10)
12739 return;
12740  
12741 // The asset is known to exist and is in our cache, so add it to the AssetRequests list
12742 req.AssetInf = asset;
12743 req.AssetRequestSource = source;
12744 req.IsTextureRequest = false;
12745 req.NumPackets = CalculateNumPackets(asset.Data);
12746 req.Params = transferRequest.TransferInfo.Params;
12747 req.RequestAssetID = requestID;
12748 req.TransferRequestID = transferRequest.TransferInfo.TransferID;
12749  
12750 SendAsset(req);
12751 }
12752  
12753 /// <summary>
12754 /// Calculate the number of packets required to send the asset to the client.
12755 /// </summary>
12756 /// <param name="data"></param>
12757 /// <returns></returns>
12758 private static int CalculateNumPackets(byte[] data)
12759 {
12760 const uint m_maxPacketSize = 600;
12761 int numPackets = 1;
12762  
12763 if (data == null)
12764 return 0;
12765  
12766 if (data.LongLength > m_maxPacketSize)
12767 {
12768 // over max number of bytes so split up file
12769 long restData = data.LongLength - m_maxPacketSize;
12770 int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
12771 numPackets += restPackets;
12772 }
12773  
12774 return numPackets;
12775 }
12776  
12777 public void SendRebakeAvatarTextures(UUID textureID)
12778 {
12779 RebakeAvatarTexturesPacket pack =
12780 (RebakeAvatarTexturesPacket)PacketPool.Instance.GetPacket(PacketType.RebakeAvatarTextures);
12781  
12782 pack.TextureData = new RebakeAvatarTexturesPacket.TextureDataBlock();
12783 pack.TextureData.TextureID = textureID;
12784 OutPacket(pack, ThrottleOutPacketType.Task);
12785 }
12786  
12787 public struct PacketProcessor
12788 {
12789 public PacketMethod method;
12790 public bool Async;
12791 }
12792  
12793 public class AsyncPacketProcess
12794 {
12795 public bool result = false;
12796 public readonly LLClientView ClientView = null;
12797 public readonly Packet Pack = null;
12798 public readonly PacketMethod Method = null;
12799 public AsyncPacketProcess(LLClientView pClientview, PacketMethod pMethod, Packet pPack)
12800 {
12801 ClientView = pClientview;
12802 Method = pMethod;
12803 Pack = pPack;
12804 }
12805 }
12806  
12807 public static OSD BuildEvent(string eventName, OSD eventBody)
12808 {
12809 OSDMap osdEvent = new OSDMap(2);
12810 osdEvent.Add("message", new OSDString(eventName));
12811 osdEvent.Add("body", eventBody);
12812  
12813 return osdEvent;
12814 }
12815  
12816 public void SendAvatarInterestsReply(UUID avatarID, uint wantMask, string wantText, uint skillsMask, string skillsText, string languages)
12817 {
12818 AvatarInterestsReplyPacket packet = (AvatarInterestsReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarInterestsReply);
12819  
12820 packet.AgentData = new AvatarInterestsReplyPacket.AgentDataBlock();
12821 packet.AgentData.AgentID = AgentId;
12822 packet.AgentData.AvatarID = avatarID;
12823  
12824 packet.PropertiesData = new AvatarInterestsReplyPacket.PropertiesDataBlock();
12825 packet.PropertiesData.WantToMask = wantMask;
12826 packet.PropertiesData.WantToText = Utils.StringToBytes(wantText);
12827 packet.PropertiesData.SkillsMask = skillsMask;
12828 packet.PropertiesData.SkillsText = Utils.StringToBytes(skillsText);
12829 packet.PropertiesData.LanguagesText = Utils.StringToBytes(languages);
12830 OutPacket(packet, ThrottleOutPacketType.Task);
12831 }
12832  
12833 public void SendChangeUserRights(UUID agentID, UUID friendID, int rights)
12834 {
12835 ChangeUserRightsPacket packet = (ChangeUserRightsPacket)PacketPool.Instance.GetPacket(PacketType.ChangeUserRights);
12836  
12837 packet.AgentData = new ChangeUserRightsPacket.AgentDataBlock();
12838 packet.AgentData.AgentID = agentID;
12839  
12840 packet.Rights = new ChangeUserRightsPacket.RightsBlock[1];
12841 packet.Rights[0] = new ChangeUserRightsPacket.RightsBlock();
12842 packet.Rights[0].AgentRelated = friendID;
12843 packet.Rights[0].RelatedRights = rights;
12844  
12845 OutPacket(packet, ThrottleOutPacketType.Task);
12846 }
12847  
12848 public void SendTextBoxRequest(string message, int chatChannel, string objectname, UUID ownerID, string ownerFirstName, string ownerLastName, UUID objectId)
12849 {
12850 ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
12851 dialog.Data.ObjectID = objectId;
12852 dialog.Data.ChatChannel = chatChannel;
12853 dialog.Data.ImageID = UUID.Zero;
12854 dialog.Data.ObjectName = Util.StringToBytes256(objectname);
12855 // this is the username of the *owner*
12856 dialog.Data.FirstName = Util.StringToBytes256(ownerFirstName);
12857 dialog.Data.LastName = Util.StringToBytes256(ownerLastName);
12858 dialog.Data.Message = Util.StringToBytes256(message);
12859  
12860 ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[1];
12861 buttons[0] = new ScriptDialogPacket.ButtonsBlock();
12862 buttons[0].ButtonLabel = Util.StringToBytes256("!!llTextBox!!");
12863 dialog.Buttons = buttons;
12864  
12865 dialog.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1];
12866 dialog.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock();
12867 dialog.OwnerData[0].OwnerID = ownerID;
12868  
12869 OutPacket(dialog, ThrottleOutPacketType.Task);
12870 }
12871  
12872 public void SendAgentTerseUpdate(ISceneEntity p)
12873 {
12874 if (p is ScenePresence)
12875 {
12876 // m_log.DebugFormat(
12877 // "[LLCLIENTVIEW]: Immediately sending terse agent update for {0} to {1} in {2}",
12878 // p.Name, Name, Scene.Name);
12879  
12880 // It turns out to get the agent to stop flying, you have to feed it stop flying velocities
12881 // There's no explicit message to send the client to tell it to stop flying.. it relies on the
12882 // velocity, collision plane and avatar height
12883  
12884 // Add 1/6 the avatar's height to it's position so it doesn't shoot into the air
12885 // when the avatar stands up
12886  
12887 ImprovedTerseObjectUpdatePacket.ObjectDataBlock block =
12888 CreateImprovedTerseBlock(p, false);
12889  
12890 const float TIME_DILATION = 1.0f;
12891 ushort timeDilation = Utils.FloatToUInt16(TIME_DILATION, 0.0f, 1.0f);
12892  
12893 ImprovedTerseObjectUpdatePacket packet
12894 = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(
12895 PacketType.ImprovedTerseObjectUpdate);
12896  
12897 packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle;
12898 packet.RegionData.TimeDilation = timeDilation;
12899 packet.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
12900  
12901 packet.ObjectData[0] = block;
12902  
12903 OutPacket(packet, ThrottleOutPacketType.Task, true);
12904 }
12905  
12906 //ControllingClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
12907 // AbsolutePosition, Velocity, Vector3.Zero, m_bodyRot, new Vector4(0,0,1,AbsolutePosition.Z - 0.5f), m_uuid, null, GetUpdatePriority(ControllingClient)));
12908 }
12909  
12910 public void SendPlacesReply(UUID queryID, UUID transactionID,
12911 PlacesReplyData[] data)
12912 {
12913 PlacesReplyPacket reply = null;
12914 PlacesReplyPacket.QueryDataBlock[] dataBlocks =
12915 new PlacesReplyPacket.QueryDataBlock[0];
12916  
12917 for (int i = 0 ; i < data.Length ; i++)
12918 {
12919 PlacesReplyPacket.QueryDataBlock block =
12920 new PlacesReplyPacket.QueryDataBlock();
12921  
12922 block.OwnerID = data[i].OwnerID;
12923 block.Name = Util.StringToBytes256(data[i].Name);
12924 block.Desc = Util.StringToBytes1024(data[i].Desc);
12925 block.ActualArea = data[i].ActualArea;
12926 block.BillableArea = data[i].BillableArea;
12927 block.Flags = data[i].Flags;
12928 block.GlobalX = data[i].GlobalX;
12929 block.GlobalY = data[i].GlobalY;
12930 block.GlobalZ = data[i].GlobalZ;
12931 block.SimName = Util.StringToBytes256(data[i].SimName);
12932 block.SnapshotID = data[i].SnapshotID;
12933 block.Dwell = data[i].Dwell;
12934 block.Price = data[i].Price;
12935  
12936 if (reply != null && reply.Length + block.Length > 1400)
12937 {
12938 OutPacket(reply, ThrottleOutPacketType.Task);
12939  
12940 reply = null;
12941 dataBlocks = new PlacesReplyPacket.QueryDataBlock[0];
12942 }
12943  
12944 if (reply == null)
12945 {
12946 reply = (PlacesReplyPacket)PacketPool.Instance.GetPacket(PacketType.PlacesReply);
12947 reply.AgentData = new PlacesReplyPacket.AgentDataBlock();
12948 reply.AgentData.AgentID = AgentId;
12949 reply.AgentData.QueryID = queryID;
12950  
12951 reply.TransactionData = new PlacesReplyPacket.TransactionDataBlock();
12952 reply.TransactionData.TransactionID = transactionID;
12953  
12954 reply.QueryData = dataBlocks;
12955 }
12956  
12957 Array.Resize(ref dataBlocks, dataBlocks.Length + 1);
12958 dataBlocks[dataBlocks.Length - 1] = block;
12959 reply.QueryData = dataBlocks;
12960 }
12961 if (reply != null)
12962 OutPacket(reply, ThrottleOutPacketType.Task);
12963 }
12964  
12965 public void SendRemoveInventoryItems(UUID[] items)
12966 {
12967 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
12968  
12969 if (eq == null)
12970 {
12971 m_log.DebugFormat("[LLCLIENT]: Null event queue");
12972 return;
12973 }
12974  
12975 OSDMap llsd = new OSDMap(3);
12976  
12977 OSDMap AgentDataMap = new OSDMap(1);
12978 AgentDataMap.Add("AgentID", OSD.FromUUID(AgentId));
12979 AgentDataMap.Add("SessionID", OSD.FromUUID(SessionId));
12980  
12981 OSDArray AgentData = new OSDArray(1);
12982 AgentData.Add(AgentDataMap);
12983  
12984 llsd.Add("AgentData", AgentData);
12985  
12986 OSDArray ItemData = new OSDArray();
12987  
12988 foreach (UUID item in items)
12989 {
12990 OSDMap ItemDataMap = new OSDMap(2);
12991 ItemDataMap.Add("ItemID", OSD.FromUUID(item));
12992 ItemDataMap.Add("AgentID", OSD.FromUUID(AgentId));
12993  
12994 ItemData.Add(ItemDataMap);
12995 }
12996  
12997 llsd.Add("InventoryData", ItemData);
12998  
12999 eq.Enqueue(BuildEvent("RemoveInventoryItem",
13000 llsd), AgentId);
13001 }
13002  
13003 public void SendRemoveInventoryFolders(UUID[] folders)
13004 {
13005 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
13006  
13007 if (eq == null)
13008 {
13009 m_log.DebugFormat("[LLCLIENT]: Null event queue");
13010 return;
13011 }
13012  
13013 OSDMap llsd = new OSDMap(3);
13014  
13015 OSDMap AgentDataMap = new OSDMap(1);
13016 AgentDataMap.Add("AgentID", OSD.FromUUID(AgentId));
13017 AgentDataMap.Add("SessionID", OSD.FromUUID(SessionId));
13018  
13019 OSDArray AgentData = new OSDArray(1);
13020 AgentData.Add(AgentDataMap);
13021  
13022 llsd.Add("AgentData", AgentData);
13023  
13024 OSDArray FolderData = new OSDArray();
13025  
13026 foreach (UUID folder in folders)
13027 {
13028 OSDMap FolderDataMap = new OSDMap(2);
13029 FolderDataMap.Add("FolderID", OSD.FromUUID(folder));
13030 FolderDataMap.Add("AgentID", OSD.FromUUID(AgentId));
13031  
13032 FolderData.Add(FolderDataMap);
13033 }
13034  
13035 llsd.Add("FolderData", FolderData);
13036  
13037 eq.Enqueue(BuildEvent("RemoveInventoryFolder",
13038 llsd), AgentId);
13039 }
13040  
13041 private byte[] EncodeU32(uint val)
13042 {
13043 byte[] ret = BitConverter.GetBytes(val);
13044 if (BitConverter.IsLittleEndian)
13045 Array.Reverse(ret);
13046 return ret;
13047 }
13048  
13049 public void SendBulkUpdateInventory(InventoryFolderBase[] folders, InventoryItemBase[] items)
13050 {
13051 IEventQueue eq = Scene.RequestModuleInterface<IEventQueue>();
13052  
13053 if (eq == null)
13054 {
13055 m_log.DebugFormat("[LLCLIENT]: Null event queue");
13056 return;
13057 }
13058  
13059 OSDMap llsd = new OSDMap(3);
13060  
13061 OSDMap AgentDataMap = new OSDMap(1);
13062 AgentDataMap.Add("AgentID", OSD.FromUUID(AgentId));
13063 AgentDataMap.Add("SessionID", OSD.FromUUID(SessionId));
13064 AgentDataMap.Add("TransactionID", OSD.FromUUID(UUID.Random()));
13065  
13066 OSDArray AgentData = new OSDArray(1);
13067 AgentData.Add(AgentDataMap);
13068  
13069 llsd.Add("AgentData", AgentData);
13070  
13071 OSDArray FolderData = new OSDArray();
13072  
13073 foreach (InventoryFolderBase folder in folders)
13074 {
13075 OSDMap FolderDataMap = new OSDMap(5);
13076 FolderDataMap.Add("FolderID", OSD.FromUUID(folder.ID));
13077 FolderDataMap.Add("AgentID", OSD.FromUUID(AgentId));
13078 FolderDataMap.Add("ParentID", OSD.FromUUID(folder.ParentID));
13079 FolderDataMap.Add("Type", OSD.FromInteger(folder.Type));
13080 FolderDataMap.Add("Name", OSD.FromString(folder.Name));
13081  
13082 FolderData.Add(FolderDataMap);
13083 }
13084  
13085 llsd.Add("FolderData", FolderData);
13086  
13087 OSDArray ItemData = new OSDArray();
13088  
13089 foreach (InventoryItemBase item in items)
13090 {
13091 OSDMap ItemDataMap = new OSDMap();
13092  
13093 ItemDataMap.Add("ItemID", OSD.FromUUID(item.ID));
13094 ItemDataMap.Add("FolderID", OSD.FromUUID(item.Folder));
13095  
13096 ItemDataMap.Add("CreatorID", OSD.FromUUID(item.CreatorIdAsUuid));
13097 ItemDataMap.Add("OwnerID", OSD.FromUUID(item.Owner));
13098 ItemDataMap.Add("GroupID", OSD.FromUUID(item.GroupID));
13099 ItemDataMap.Add("BaseMask", OSD.FromBinary(EncodeU32((uint)item.BasePermissions)));
13100 ItemDataMap.Add("OwnerMask", OSD.FromBinary(EncodeU32((uint)item.CurrentPermissions)));
13101 ItemDataMap.Add("GroupMask", OSD.FromBinary(EncodeU32((uint)item.GroupPermissions)));
13102 ItemDataMap.Add("EveryoneMask", OSD.FromBinary(EncodeU32((uint)item.EveryOnePermissions)));
13103 ItemDataMap.Add("NextOwnerMask", OSD.FromBinary(EncodeU32((uint)item.NextPermissions)));
13104 ItemDataMap.Add("GroupOwned", OSD.FromBoolean(item.GroupOwned));
13105 ItemDataMap.Add("AssetID", OSD.FromUUID(item.AssetID));
13106 ItemDataMap.Add("Type", OSD.FromInteger(item.AssetType));
13107 ItemDataMap.Add("InvType", OSD.FromInteger(item.InvType));
13108 ItemDataMap.Add("Flags", OSD.FromBinary(EncodeU32((uint)item.Flags)));
13109 ItemDataMap.Add("SaleType", OSD.FromInteger((byte)item.SaleType));
13110 ItemDataMap.Add("SalePrice", OSD.FromInteger(item.SalePrice));
13111 ItemDataMap.Add("Name", OSD.FromString(item.Name));
13112 ItemDataMap.Add("Description", OSD.FromString(item.Description));
13113 ItemDataMap.Add("CreationDate", OSD.FromInteger(item.CreationDate));
13114  
13115 ItemDataMap.Add("CRC", OSD.FromBinary(EncodeU32(
13116 Helpers.InventoryCRC(1000, 0, (sbyte)item.InvType,
13117 (sbyte)item.AssetType, item.AssetID,
13118 item.GroupID, 100,
13119 item.Owner, item.CreatorIdAsUuid,
13120 item.ID, item.Folder,
13121 (uint)PermissionMask.All, 1, (uint)PermissionMask.All, (uint)PermissionMask.All,
13122 (uint)PermissionMask.All)
13123 )));
13124 ItemDataMap.Add("CallbackID", 0);
13125  
13126 ItemData.Add(ItemDataMap);
13127 }
13128  
13129 llsd.Add("ItemData", ItemData);
13130  
13131 eq.Enqueue(BuildEvent("BulkUpdateInventory",
13132 llsd), AgentId);
13133 }
13134  
13135 private HashSet<string> m_outPacketsToDrop;
13136  
13137 public bool AddOutPacketToDropSet(string packetName)
13138 {
13139 if (m_outPacketsToDrop == null)
13140 m_outPacketsToDrop = new HashSet<string>();
13141  
13142 return m_outPacketsToDrop.Add(packetName);
13143 }
13144  
13145 public bool RemoveOutPacketFromDropSet(string packetName)
13146 {
13147 if (m_outPacketsToDrop == null)
13148 return false;
13149  
13150 return m_outPacketsToDrop.Remove(packetName);
13151 }
13152  
13153 public HashSet<string> GetOutPacketDropSet()
13154 {
13155 return new HashSet<string>(m_outPacketsToDrop);
13156 }
13157  
13158 private HashSet<string> m_inPacketsToDrop;
13159  
13160 public bool AddInPacketToDropSet(string packetName)
13161 {
13162 if (m_inPacketsToDrop == null)
13163 m_inPacketsToDrop = new HashSet<string>();
13164  
13165 return m_inPacketsToDrop.Add(packetName);
13166 }
13167  
13168 public bool RemoveInPacketFromDropSet(string packetName)
13169 {
13170 if (m_inPacketsToDrop == null)
13171 return false;
13172  
13173 return m_inPacketsToDrop.Remove(packetName);
13174 }
13175  
13176 public HashSet<string> GetInPacketDropSet()
13177 {
13178 return new HashSet<string>(m_inPacketsToDrop);
13179 }
13180 }
13181 }