opensim – Blame information for rev 1

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