aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientView.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-05-02 16:41:08 +0000
committerAdam Frisby2008-05-02 16:41:08 +0000
commit29b8c84ceaaeca80bfa9c0bfc8c31e421e39ef71 (patch)
tree848ce119d9b87bc186c20b08cc604de50a872b31 /OpenSim/Region/ClientStack/ClientView.cs
parent* Refactored ClientView into LLClientView. Removed all direct references to U... (diff)
downloadopensim-SC_OLD-29b8c84ceaaeca80bfa9c0bfc8c31e421e39ef71.zip
opensim-SC_OLD-29b8c84ceaaeca80bfa9c0bfc8c31e421e39ef71.tar.gz
opensim-SC_OLD-29b8c84ceaaeca80bfa9c0bfc8c31e421e39ef71.tar.bz2
opensim-SC_OLD-29b8c84ceaaeca80bfa9c0bfc8c31e421e39ef71.tar.xz
* Commit 2/3 - Please dont attempt to update to this revision until all 3 are in.
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientView.cs')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs4926
1 files changed, 0 insertions, 4926 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
deleted file mode 100644
index 010a37f..0000000
--- a/OpenSim/Region/ClientStack/ClientView.cs
+++ /dev/null
@@ -1,4926 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Net.Sockets;
32using System.Reflection;
33using System.Text;
34using System.Threading;
35using System.Timers;
36using Axiom.Math;
37using libsecondlife;
38using libsecondlife.Packets;
39using log4net;
40using OpenSim.Framework;
41using OpenSim.Framework.Communications.Cache;
42using OpenSim.Region.Environment.Scenes;
43using Timer=System.Timers.Timer;
44
45namespace OpenSim.Region.ClientStack
46{
47 public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
48
49 /// <summary>
50 /// Handles new client connections
51 /// Constructor takes a single Packet and authenticates everything
52 /// </summary>
53 public class ClientView : IClientAPI
54 {
55 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56
57 // ~ClientView()
58 // {
59 // m_log.Info("[CLIENTVIEW]: Destructor called");
60 // }
61
62 /* static variables */
63 public static TerrainManager TerrainManager;
64
65 public delegate bool SynchronizeClientHandler(IScene scene, Packet packet, LLUUID agentID, ThrottleOutPacketType throttlePacketType);
66 public static SynchronizeClientHandler SynchronizeClient = null;
67 /* private variables */
68 private readonly LLUUID m_sessionId;
69 private LLUUID m_secureSessionId = LLUUID.Zero;
70 //private AgentAssetUpload UploadAssets;
71 private int m_debug = 0;
72 private readonly AssetCache m_assetCache;
73 // private InventoryCache m_inventoryCache;
74 private int m_cachedTextureSerial = 0;
75 private Timer m_clientPingTimer;
76
77 private bool m_clientBlocked = false;
78
79 private int m_packetsReceived = 0;
80 private int m_lastPacketsReceivedSentToScene = 0;
81 private int m_unAckedBytes = 0;
82
83 private int m_packetsSent = 0;
84 private int m_lastPacketsSentSentToScene = 0;
85
86 private int m_probesWithNoIngressPackets = 0;
87 private int m_lastPacketsReceived = 0;
88 private byte[] ZeroOutBuffer = new byte[4096];
89
90 private readonly LLUUID m_agentId;
91 private readonly uint m_circuitCode;
92 private int m_moneyBalance;
93
94 private int m_animationSequenceNumber = 1;
95
96 private byte[] m_channelVersion = Helpers.StringToField("OpenSimulator 0.5"); // Dummy value needed by libSL
97
98 /* protected variables */
99
100 protected static Dictionary<PacketType, PacketMethod> PacketHandlers =
101 new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
102
103 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>();
104
105 protected IScene m_scene;
106 protected AgentCircuitManager m_authenticateSessionsHandler;
107
108 protected PacketQueue m_packetQueue;
109
110 protected Dictionary<uint, uint> m_pendingAcks = new Dictionary<uint, uint>();
111 protected Dictionary<uint, Packet> m_needAck = new Dictionary<uint, Packet>();
112
113 protected Timer m_ackTimer;
114 protected uint m_sequence = 0;
115 protected object m_sequenceLock = new object();
116 protected const int MAX_APPENDED_ACKS = 10;
117 protected const int RESEND_TIMEOUT = 4000;
118 protected const int MAX_SEQUENCE = 0xFFFFFF;
119 protected PacketServer m_networkServer;
120
121 /* public variables */
122 protected string m_firstName;
123 protected string m_lastName;
124 protected Thread m_clientThread;
125 protected LLVector3 m_startpos;
126 protected EndPoint m_userEndPoint;
127 protected EndPoint m_proxyEndPoint;
128
129 /* Instantiated Designated Event Delegates */
130 //- used so we don't create new objects for each incoming packet and then toss it out later */
131
132 private RequestAvatarProperties handlerRequestAvatarProperties = null; //OnRequestAvatarProperties;
133 private UpdateAvatarProperties handlerUpdateAvatarProperties = null; // OnUpdateAvatarProperties;
134 private ChatFromViewer handlerChatFromViewer = null; //OnChatFromViewer;
135 private ChatFromViewer handlerChatFromViewer2 = null; //OnChatFromViewer;
136 private ImprovedInstantMessage handlerInstantMessage = null; //OnInstantMessage;
137 private FriendActionDelegate handlerApproveFriendRequest = null; //OnApproveFriendRequest;
138 private FriendshipTermination handlerTerminateFriendship = null; //OnTerminateFriendship;
139 private RezObject handlerRezObject = null; //OnRezObject;
140 private GenericCall4 handlerDeRezObject = null; //OnDeRezObject;
141 private ModifyTerrain handlerModifyTerrain = null;
142 private Action<IClientAPI> handlerRegionHandShakeReply = null; //OnRegionHandShakeReply;
143 private GenericCall2 handlerRequestWearables = null; //OnRequestWearables;
144 private Action<IClientAPI> handlerRequestAvatarsData = null; //OnRequestAvatarsData;
145 private SetAppearance handlerSetAppearance = null; //OnSetAppearance;
146 private AvatarNowWearing handlerAvatarNowWearing = null; //OnAvatarNowWearing;
147 private RezSingleAttachmentFromInv handlerRezSingleAttachment = null; //OnRezSingleAttachmentFromInv;
148 private UUIDNameRequest handlerDetachAttachmentIntoInv = null; // Detach attachment!
149 private ObjectAttach handlerObjectAttach = null; //OnObjectAttach;
150 private SetAlwaysRun handlerSetAlwaysRun = null; //OnSetAlwaysRun;
151 private GenericCall2 handlerCompleteMovementToRegion = null; //OnCompleteMovementToRegion;
152 private UpdateAgent handlerAgentUpdate = null; //OnAgentUpdate;
153 private StartAnim handlerStartAnim = null;
154 private StopAnim handlerStopAnim = null;
155 private AgentRequestSit handlerAgentRequestSit = null; //OnAgentRequestSit;
156 private AgentSit handlerAgentSit = null; //OnAgentSit;
157 private AvatarPickerRequest handlerAvatarPickerRequest = null; //OnAvatarPickerRequest;
158 private FetchInventory handlerAgentDataUpdateRequest = null; //OnAgentDataUpdateRequest;
159 private FetchInventory handlerUserInfoRequest = null; //OnUserInfoRequest;
160 private TeleportLocationRequest handlerSetStartLocationRequest = null; //OnSetStartLocationRequest;
161 private TeleportLandmarkRequest handlerTeleportLandmarkRequest = null; //OnTeleportLandmarkRequest;
162 private LinkObjects handlerLinkObjects = null; //OnLinkObjects;
163 private DelinkObjects handlerDelinkObjects = null; //OnDelinkObjects;
164 private AddNewPrim handlerAddPrim = null; //OnAddPrim;
165 private UpdateShape handlerUpdatePrimShape = null; //null;
166 private ObjectExtraParams handlerUpdateExtraParams = null; //OnUpdateExtraParams;
167 private ObjectDuplicate handlerObjectDuplicate = null;
168 private ObjectDuplicateOnRay handlerObjectDuplicateOnRay = null;
169 private ObjectSelect handlerObjectSelect = null;
170 private ObjectDeselect handlerObjectDeselect = null;
171 private ObjectIncludeInSearch handlerObjectIncludeInSearch = null;
172 private UpdatePrimFlags handlerUpdatePrimFlags = null; //OnUpdatePrimFlags;
173 private UpdatePrimTexture handlerUpdatePrimTexture = null;
174 private UpdateVector handlerGrabObject = null; //OnGrabObject;
175 private MoveObject handlerGrabUpdate = null; //OnGrabUpdate;
176 private ObjectSelect handlerDeGrabObject = null; //OnDeGrabObject;
177 private GenericCall7 handlerObjectDescription = null;
178 private GenericCall7 handlerObjectName = null;
179 private ObjectPermissions handlerObjectPermissions = null;
180 private RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily = null; //OnRequestObjectPropertiesFamily;
181 private TextureRequest handlerTextureRequest = null;
182 private UDPAssetUploadRequest handlerAssetUploadRequest = null; //OnAssetUploadRequest;
183 private RequestXfer handlerRequestXfer = null; //OnRequestXfer;
184 private XferReceive handlerXferReceive = null; //OnXferReceive;
185 private ConfirmXfer handlerConfirmXfer = null; //OnConfirmXfer;
186 private CreateInventoryFolder handlerCreateInventoryFolder = null; //OnCreateNewInventoryFolder;
187 private UpdateInventoryFolder handlerUpdateInventoryFolder = null;
188 private MoveInventoryFolder handlerMoveInventoryFolder = null;
189 private CreateNewInventoryItem handlerCreateNewInventoryItem = null; //OnCreateNewInventoryItem;
190 private FetchInventory handlerFetchInventory = null;
191 private FetchInventoryDescendents handlerFetchInventoryDescendents = null; //OnFetchInventoryDescendents;
192 private PurgeInventoryDescendents handlerPurgeInventoryDescendents = null; //OnPurgeInventoryDescendents;
193 private UpdateInventoryItem handlerUpdateInventoryItem = null;
194 private CopyInventoryItem handlerCopyInventoryItem = null;
195 private MoveInventoryItem handlerMoveInventoryItem = null;
196 private RemoveInventoryItem handlerRemoveInventoryItem = null;
197 private RemoveInventoryFolder handlerRemoveInventoryFolder = null;
198 private RequestTaskInventory handlerRequestTaskInventory = null; //OnRequestTaskInventory;
199 private UpdateTaskInventory handlerUpdateTaskInventory = null; //OnUpdateTaskInventory;
200 private MoveTaskInventory handlerMoveTaskItem = null;
201 private RemoveTaskInventory handlerRemoveTaskItem = null; //OnRemoveTaskItem;
202 private RezScript handlerRezScript = null; //OnRezScript;
203 private RequestMapBlocks handlerRequestMapBlocks = null; //OnRequestMapBlocks;
204 private RequestMapName handlerMapNameRequest = null; //OnMapNameRequest;
205 private TeleportLocationRequest handlerTeleportLocationRequest = null; //OnTeleportLocationRequest;
206 private MoneyBalanceRequest handlerMoneyBalanceRequest = null; //OnMoneyBalanceRequest;
207 private UUIDNameRequest handlerNameRequest = null;
208 private ParcelAccessListRequest handlerParcelAccessListRequest = null; //OnParcelAccessListRequest;
209 private ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest = null; //OnParcelAccessListUpdateRequest;
210 private ParcelPropertiesRequest handlerParcelPropertiesRequest = null; //OnParcelPropertiesRequest;
211 private ParcelDivideRequest handlerParcelDivideRequest = null; //OnParcelDivideRequest;
212 private ParcelJoinRequest handlerParcelJoinRequest = null; //OnParcelJoinRequest;
213 private ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest = null; //OnParcelPropertiesUpdateRequest;
214 private ParcelSelectObjects handlerParcelSelectObjects = null; //OnParcelSelectObjects;
215 private ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest = null; //OnParcelObjectOwnerRequest;
216 private EstateOwnerMessageRequest handlerEstateOwnerMessage = null; //OnEstateOwnerMessage;
217 private RegionInfoRequest handlerRegionInfoRequest = null; //OnRegionInfoRequest;
218 private EstateCovenantRequest handlerEstateCovenantRequest = null; //OnEstateCovenantRequest;
219 private RequestGodlikePowers handlerReqGodlikePowers = null; //OnRequestGodlikePowers;
220 private GodKickUser handlerGodKickUser = null; //OnGodKickUser;
221 private ViewerEffectEventHandler handlerViewerEffect = null; //OnViewerEffect;
222 private Action<IClientAPI> handlerLogout = null; //OnLogout;
223 private MoneyTransferRequest handlerMoneyTransferRequest = null; //OnMoneyTransferRequest;
224 private ParcelBuy handlerParcelBuy = null;
225 private EconomyDataRequest handlerEconomoyDataRequest = null;
226
227 private UpdateVector handlerUpdatePrimSinglePosition = null; //OnUpdatePrimSinglePosition;
228 private UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = null; //OnUpdatePrimSingleRotation;
229 private UpdateVector handlerUpdatePrimScale = null; //OnUpdatePrimScale;
230 private UpdateVector handlerUpdatePrimGroupScale = null; //OnUpdateGroupScale;
231 private UpdateVector handlerUpdateVector = null; //OnUpdatePrimGroupPosition;
232 private UpdatePrimRotation handlerUpdatePrimRotation = null; //OnUpdatePrimGroupRotation;
233 private UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = null; //OnUpdatePrimGroupMouseRotation;
234 private PacketStats handlerPacketStats = null; // OnPacketStats;#
235 private RequestAsset handlerRequestAsset = null; // OnRequestAsset;
236 private UUIDNameRequest handlerTeleportHomeRequest = null;
237
238 private ScriptAnswer handlerScriptAnswer = null;
239 private RequestPayPrice handlerRequestPayPrice = null;
240 private ObjectDeselect handlerObjectDetach = null;
241 private AgentSit handlerOnUndo = null;
242
243 /* Properties */
244
245 public LLUUID SecureSessionId
246 {
247 get { return m_secureSessionId; }
248 }
249
250 public IScene Scene
251 {
252 get { return m_scene; }
253 }
254
255 public LLUUID SessionId
256 {
257 get { return m_sessionId; }
258 }
259
260 public LLVector3 StartPos
261 {
262 get { return m_startpos; }
263 set { m_startpos = value; }
264 }
265
266 public LLUUID AgentId
267 {
268 get { return m_agentId; }
269 }
270
271 /// <summary>
272 /// This is a utility method used by single states to not duplicate kicks and blue card of death messages.
273 /// </summary>
274 public bool ChildAgentStatus()
275 {
276 return m_scene.PresenceChildStatus(AgentId);
277 }
278
279 /// <summary>
280 /// First name of the agent/avatar represented by the client
281 /// </summary>
282 public string FirstName
283 {
284 get { return m_firstName; }
285 }
286
287 /// <summary>
288 /// Last name of the agent/avatar represented by the client
289 /// </summary>
290 public string LastName
291 {
292 get { return m_lastName; }
293 }
294
295 /// <summary>
296 /// Full name of the client (first name and last name)
297 /// </summary>
298 public string Name
299 {
300 get { return FirstName + " " + LastName; }
301 }
302
303 public uint CircuitCode
304 {
305 get { return m_circuitCode; }
306 }
307
308 public int MoneyBalance
309 {
310 get { return m_moneyBalance; }
311 }
312
313 public int NextAnimationSequenceNumber
314 {
315 get { return m_animationSequenceNumber++; }
316 }
317
318 /* METHODS */
319
320 public ClientView(EndPoint remoteEP, IScene scene, AssetCache assetCache, PacketServer packServer,
321 AgentCircuitManager authenSessions, LLUUID agentId, LLUUID sessionId, uint circuitCode, EndPoint proxyEP)
322 {
323 m_moneyBalance = 1000;
324
325 m_channelVersion = Helpers.StringToField(scene.GetSimulatorVersion());
326
327 m_scene = scene;
328 m_assetCache = assetCache;
329
330 m_networkServer = packServer;
331 // m_inventoryCache = inventoryCache;
332 m_authenticateSessionsHandler = authenSessions;
333
334 m_log.Info("[CLIENT]: Started up new client thread to handle incoming request");
335
336 m_agentId = agentId;
337 m_sessionId = sessionId;
338 m_circuitCode = circuitCode;
339
340 m_userEndPoint = remoteEP;
341 m_proxyEndPoint = proxyEP;
342
343 m_startpos = m_authenticateSessionsHandler.GetPosition(circuitCode);
344
345 // While working on this, the BlockingQueue had me fooled for a bit.
346 // The Blocking queue causes the thread to stop until there's something
347 // in it to process. It's an on-purpose threadlock though because
348 // without it, the clientloop will suck up all sim resources.
349
350 m_packetQueue = new PacketQueue(agentId);
351
352 RegisterLocalPacketHandlers();
353
354 m_clientThread = new Thread(new ThreadStart(AuthUser));
355 m_clientThread.Name = "ClientThread";
356 m_clientThread.IsBackground = true;
357 m_clientThread.Start();
358 ThreadTracker.Add(m_clientThread);
359 }
360
361 public void SetDebug(int newDebug)
362 {
363 m_debug = newDebug;
364 }
365
366 # region Client Methods
367
368 private void CloseCleanup(bool shutdownCircuit)
369 {
370 m_scene.RemoveClient(AgentId);
371
372 //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
373 //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
374
375 // Send the STOP packet
376 DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
377 OutPacket(disable, ThrottleOutPacketType.Unknown);
378
379 m_packetQueue.Close();
380
381 Thread.Sleep(2000);
382
383
384 // Shut down timers
385 m_ackTimer.Stop();
386 m_clientPingTimer.Stop();
387
388 // This is just to give the client a reasonable chance of
389 // flushing out all it's packets. There should probably
390 // be a better mechanism here
391
392 // We can't reach into other scenes and close the connection
393 // We need to do this over grid communications
394 //m_scene.CloseAllAgents(CircuitCode);
395
396 // If we're not shutting down the circuit, then this is the last time we'll go here.
397 // If we are shutting down the circuit, the UDP Server will come back here with
398 // ShutDownCircuit = false
399 if (!(shutdownCircuit))
400 {
401 GC.Collect();
402 m_clientThread.Abort();
403 }
404 }
405
406 /// <summary>
407 /// Close down the client view. This *must* be the last method called, since the last #
408 /// statement of CloseCleanup() aborts the thread.
409 /// </summary>
410 /// <param name="shutdownCircuit"></param>
411 public void Close(bool shutdownCircuit)
412 {
413 // Pull Client out of Region
414 m_log.Info("[CLIENT]: Close has been called");
415 m_packetQueue.Flush();
416
417 //raiseevent on the packet server to Shutdown the circuit
418 if (shutdownCircuit)
419 {
420 OnConnectionClosed(this);
421 }
422
423 CloseCleanup(shutdownCircuit);
424 }
425
426 public void Kick(string message)
427 {
428 if (!ChildAgentStatus())
429 {
430 KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
431 kupack.UserInfo.AgentID = AgentId;
432 kupack.UserInfo.SessionID = SessionId;
433 kupack.TargetBlock.TargetIP = (uint)0;
434 kupack.TargetBlock.TargetPort = (ushort)0;
435 kupack.UserInfo.Reason = Helpers.StringToField(message);
436 OutPacket(kupack, ThrottleOutPacketType.Task);
437 }
438 }
439
440 public void Stop()
441 {
442 // Shut down timers
443 m_ackTimer.Stop();
444 m_clientPingTimer.Stop();
445 }
446
447 public void Restart()
448 {
449 // re-construct
450 m_pendingAcks = new Dictionary<uint, uint>();
451 m_needAck = new Dictionary<uint, Packet>();
452 m_sequence += 1000000;
453
454 m_ackTimer = new Timer(750);
455 m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
456 m_ackTimer.Start();
457
458 m_clientPingTimer = new Timer(5000);
459 m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
460 m_clientPingTimer.Enabled = true;
461 }
462
463 public void Terminate()
464 {
465 // disable blocking queue
466 m_packetQueue.Enqueue(null);
467
468 // wait for thread stoped
469 m_clientThread.Join();
470
471 // delete circuit code
472 m_networkServer.CloseClient(this);
473 }
474
475 #endregion
476
477 # region Packet Handling
478
479 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
480 {
481 bool result = false;
482 lock (PacketHandlers)
483 {
484 if (!PacketHandlers.ContainsKey(packetType))
485 {
486 PacketHandlers.Add(packetType, handler);
487 result = true;
488 }
489 }
490 return result;
491 }
492
493 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
494 {
495 bool result = false;
496 lock (m_packetHandlers)
497 {
498 if (!m_packetHandlers.ContainsKey(packetType))
499 {
500 m_packetHandlers.Add(packetType, handler);
501 result = true;
502 }
503 }
504 return result;
505 }
506
507 /// <summary>
508 /// Try to process a packet using registered packet handlers
509 /// </summary>
510 /// <param name="packet"></param>
511 /// <returns>True if a handler was found which successfully processed the packet.</returns>
512 protected virtual bool ProcessPacketMethod(Packet packet)
513 {
514 bool result = false;
515 bool found = false;
516 PacketMethod method;
517 if (m_packetHandlers.TryGetValue(packet.Type, out method))
518 {
519 //there is a local handler for this packet type
520 result = method(this, packet);
521 }
522 else
523 {
524 //there is not a local handler so see if there is a Global handler
525 lock (PacketHandlers)
526 {
527 found = PacketHandlers.TryGetValue(packet.Type, out method);
528 }
529 if (found)
530 {
531 result = method(this, packet);
532 }
533 }
534 return result;
535 }
536
537 protected void DebugPacket(string direction, Packet packet)
538 {
539 if (m_debug > 0)
540 {
541 string info = String.Empty;
542
543 if (m_debug < 255 && packet.Type == PacketType.AgentUpdate)
544 return;
545 if (m_debug < 254 && packet.Type == PacketType.ViewerEffect)
546 return;
547 if (m_debug < 253 && (
548 packet.Type == PacketType.CompletePingCheck ||
549 packet.Type == PacketType.StartPingCheck
550 ))
551 return;
552 if (m_debug < 252 && packet.Type == PacketType.PacketAck)
553 return;
554
555 if (m_debug > 1)
556 {
557 info = packet.ToString();
558 }
559 else
560 {
561 info = packet.Type.ToString();
562 }
563 Console.WriteLine(m_circuitCode + ":" + direction + ": " + info);
564 }
565 }
566
567 protected virtual void ClientLoop()
568 {
569 m_log.Info("[CLIENT]: Entered loop");
570 while (true)
571 {
572 QueItem nextPacket = m_packetQueue.Dequeue();
573 if (nextPacket == null)
574 {
575 break;
576 }
577 if (nextPacket.Incoming)
578 {
579 if (nextPacket.Packet.Type != PacketType.AgentUpdate)
580 {
581 m_packetsReceived++;
582 }
583 DebugPacket("IN", nextPacket.Packet);
584 ProcessInPacket(nextPacket.Packet);
585 }
586 else
587 {
588 DebugPacket("OUT", nextPacket.Packet);
589 ProcessOutPacket(nextPacket.Packet);
590 }
591 }
592 }
593
594 # endregion
595
596 protected void CheckClientConnectivity(object sender, ElapsedEventArgs e)
597 {
598 if (m_packetsReceived == m_lastPacketsReceived)
599 {
600 m_probesWithNoIngressPackets++;
601 if ((m_probesWithNoIngressPackets > 30 && !m_clientBlocked) || (m_probesWithNoIngressPackets > 90 && m_clientBlocked))
602 {
603
604 if (OnConnectionClosed != null)
605 {
606 OnConnectionClosed(this);
607 }
608 }
609 else
610 {
611 // this will normally trigger at least one packet (ping response)
612 SendStartPingCheck(0);
613
614 }
615 }
616 else
617 {
618 // Something received in the meantime - we can reset the counters
619 m_probesWithNoIngressPackets = 0;
620 m_lastPacketsReceived = m_packetsReceived;
621
622 }
623 //SendPacketStats();
624 }
625
626 # region Setup
627
628 protected virtual void InitNewClient()
629 {
630 //this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
631
632 // Establish our two timers. We could probably get this down to one
633 m_ackTimer = new Timer(750);
634 m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
635 m_ackTimer.Start();
636
637 m_clientPingTimer = new Timer(5000);
638 m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
639 m_clientPingTimer.Enabled = true;
640
641 m_log.Info("[CLIENT]: Adding viewer agent to scene");
642 m_scene.AddNewClient(this, true);
643 }
644
645 protected virtual void AuthUser()
646 {
647 // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(m_cirpack.m_circuitCode.m_sessionId, m_cirpack.m_circuitCode.ID, m_cirpack.m_circuitCode.Code);
648 AuthenticateResponse sessionInfo =
649 m_authenticateSessionsHandler.AuthenticateSession(m_sessionId, m_agentId,
650 m_circuitCode);
651 if (!sessionInfo.Authorised)
652 {
653 //session/circuit not authorised
654 m_log.Info("[CLIENT]: New user request denied to " + m_userEndPoint.ToString());
655 m_packetQueue.Close();
656 m_clientThread.Abort();
657 }
658 else
659 {
660 m_log.Info("[CLIENT]: Got authenticated connection from " + m_userEndPoint.ToString());
661 //session is authorised
662 m_firstName = sessionInfo.LoginInfo.First;
663 m_lastName = sessionInfo.LoginInfo.Last;
664
665 if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
666 {
667 m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
668 }
669 // This sets up all the timers
670 InitNewClient();
671
672 ClientLoop();
673 }
674 }
675
676 # endregion
677
678 // Previously ClientView.API partial class
679 public event Action<IClientAPI> OnLogout;
680 public event ObjectPermissions OnObjectPermissions;
681
682 public event Action<IClientAPI> OnConnectionClosed;
683 public event ViewerEffectEventHandler OnViewerEffect;
684 public event ImprovedInstantMessage OnInstantMessage;
685 public event ChatFromViewer OnChatFromViewer;
686 public event TextureRequest OnRequestTexture;
687 public event RezObject OnRezObject;
688 public event GenericCall4 OnDeRezObject;
689 public event ModifyTerrain OnModifyTerrain;
690 public event Action<IClientAPI> OnRegionHandShakeReply;
691 public event GenericCall2 OnRequestWearables;
692 public event SetAppearance OnSetAppearance;
693 public event AvatarNowWearing OnAvatarNowWearing;
694 public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
695 public event UUIDNameRequest OnDetachAttachmentIntoInv;
696 public event ObjectAttach OnObjectAttach;
697 public event ObjectDeselect OnObjectDetach;
698 public event GenericCall2 OnCompleteMovementToRegion;
699 public event UpdateAgent OnAgentUpdate;
700 public event AgentRequestSit OnAgentRequestSit;
701 public event AgentSit OnAgentSit;
702 public event AvatarPickerRequest OnAvatarPickerRequest;
703 public event StartAnim OnStartAnim;
704 public event StopAnim OnStopAnim;
705 public event Action<IClientAPI> OnRequestAvatarsData;
706 public event LinkObjects OnLinkObjects;
707 public event DelinkObjects OnDelinkObjects;
708 public event UpdateVector OnGrabObject;
709 public event ObjectSelect OnDeGrabObject;
710 public event ObjectDuplicate OnObjectDuplicate;
711 public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
712 public event MoveObject OnGrabUpdate;
713 public event AddNewPrim OnAddPrim;
714 public event RequestGodlikePowers OnRequestGodlikePowers;
715 public event GodKickUser OnGodKickUser;
716 public event ObjectExtraParams OnUpdateExtraParams;
717 public event UpdateShape OnUpdatePrimShape;
718 public event ObjectSelect OnObjectSelect;
719 public event ObjectDeselect OnObjectDeselect;
720 public event GenericCall7 OnObjectDescription;
721 public event GenericCall7 OnObjectName;
722 public event ObjectIncludeInSearch OnObjectIncludeInSearch;
723 public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
724 public event UpdatePrimFlags OnUpdatePrimFlags;
725 public event UpdatePrimTexture OnUpdatePrimTexture;
726 public event UpdateVector OnUpdatePrimGroupPosition;
727 public event UpdateVector OnUpdatePrimSinglePosition;
728 public event UpdatePrimRotation OnUpdatePrimGroupRotation;
729 public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
730 public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
731 public event UpdateVector OnUpdatePrimScale;
732 public event UpdateVector OnUpdatePrimGroupScale;
733 public event StatusChange OnChildAgentStatus;
734 public event GenericCall2 OnStopMovement;
735 public event Action<LLUUID> OnRemoveAvatar;
736 public event RequestMapBlocks OnRequestMapBlocks;
737 public event RequestMapName OnMapNameRequest;
738 public event TeleportLocationRequest OnTeleportLocationRequest;
739 public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
740 public event DisconnectUser OnDisconnectUser;
741 public event RequestAvatarProperties OnRequestAvatarProperties;
742 public event SetAlwaysRun OnSetAlwaysRun;
743
744 public event FetchInventory OnAgentDataUpdateRequest;
745 public event FetchInventory OnUserInfoRequest;
746 public event TeleportLocationRequest OnSetStartLocationRequest;
747 public event UpdateAvatarProperties OnUpdateAvatarProperties;
748
749
750 public event CreateNewInventoryItem OnCreateNewInventoryItem;
751 public event CreateInventoryFolder OnCreateNewInventoryFolder;
752 public event UpdateInventoryFolder OnUpdateInventoryFolder;
753 public event MoveInventoryFolder OnMoveInventoryFolder;
754 public event FetchInventoryDescendents OnFetchInventoryDescendents;
755 public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
756 public event FetchInventory OnFetchInventory;
757 public event RequestTaskInventory OnRequestTaskInventory;
758 public event UpdateInventoryItem OnUpdateInventoryItem;
759 public event CopyInventoryItem OnCopyInventoryItem;
760 public event MoveInventoryItem OnMoveInventoryItem;
761 public event RemoveInventoryItem OnRemoveInventoryItem;
762 public event RemoveInventoryFolder OnRemoveInventoryFolder;
763 public event UDPAssetUploadRequest OnAssetUploadRequest;
764 public event XferReceive OnXferReceive;
765 public event RequestXfer OnRequestXfer;
766 public event ConfirmXfer OnConfirmXfer;
767 public event RezScript OnRezScript;
768 public event UpdateTaskInventory OnUpdateTaskInventory;
769 public event MoveTaskInventory OnMoveTaskItem;
770 public event RemoveTaskInventory OnRemoveTaskItem;
771 public event RequestAsset OnRequestAsset;
772
773 public event UUIDNameRequest OnNameFromUUIDRequest;
774
775 public event ParcelAccessListRequest OnParcelAccessListRequest;
776 public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
777 public event ParcelPropertiesRequest OnParcelPropertiesRequest;
778 public event ParcelDivideRequest OnParcelDivideRequest;
779 public event ParcelJoinRequest OnParcelJoinRequest;
780 public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
781 public event ParcelSelectObjects OnParcelSelectObjects;
782 public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
783 public event EstateOwnerMessageRequest OnEstateOwnerMessage;
784 public event RegionInfoRequest OnRegionInfoRequest;
785 public event EstateCovenantRequest OnEstateCovenantRequest;
786
787 public event FriendActionDelegate OnApproveFriendRequest;
788 public event FriendActionDelegate OnDenyFriendRequest;
789 public event FriendshipTermination OnTerminateFriendship;
790
791 public event PacketStats OnPacketStats;
792
793 public event MoneyTransferRequest OnMoneyTransferRequest;
794 public event EconomyDataRequest OnEconomyDataRequest;
795
796 public event MoneyBalanceRequest OnMoneyBalanceRequest;
797 public event ParcelBuy OnParcelBuy;
798
799 public event UUIDNameRequest OnTeleportHomeRequest;
800
801 public event ScriptAnswer OnScriptAnswer;
802 public event RequestPayPrice OnRequestPayPrice;
803 public event AgentSit OnUndo;
804
805 #region Scene/Avatar to Client
806
807 /// <summary>
808 ///
809 /// </summary>
810 /// <param name="regionInfo"></param>
811 public void SendRegionHandshake(RegionInfo regionInfo)
812 {
813 RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
814
815 bool estatemanager = false;
816 LLUUID[] EstateManagers = regionInfo.EstateSettings.estateManagers;
817 for (int i = 0; i < EstateManagers.Length; i++)
818 {
819 if (EstateManagers[i] == AgentId)
820 estatemanager = true;
821 }
822
823 handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor;
824 handshake.RegionInfo.IsEstateManager = estatemanager;
825 handshake.RegionInfo.TerrainHeightRange00 = regionInfo.EstateSettings.terrainHeightRange0;
826 handshake.RegionInfo.TerrainHeightRange01 = regionInfo.EstateSettings.terrainHeightRange1;
827 handshake.RegionInfo.TerrainHeightRange10 = regionInfo.EstateSettings.terrainHeightRange2;
828 handshake.RegionInfo.TerrainHeightRange11 = regionInfo.EstateSettings.terrainHeightRange3;
829 handshake.RegionInfo.TerrainStartHeight00 = regionInfo.EstateSettings.terrainStartHeight0;
830 handshake.RegionInfo.TerrainStartHeight01 = regionInfo.EstateSettings.terrainStartHeight1;
831 handshake.RegionInfo.TerrainStartHeight10 = regionInfo.EstateSettings.terrainStartHeight2;
832 handshake.RegionInfo.TerrainStartHeight11 = regionInfo.EstateSettings.terrainStartHeight3;
833 handshake.RegionInfo.SimAccess = (byte)regionInfo.EstateSettings.simAccess;
834 handshake.RegionInfo.WaterHeight = regionInfo.EstateSettings.waterHeight;
835
836 handshake.RegionInfo.RegionFlags = (uint)regionInfo.EstateSettings.regionFlags;
837 handshake.RegionInfo.SimName = Helpers.StringToField(regionInfo.RegionName);
838 handshake.RegionInfo.SimOwner = regionInfo.MasterAvatarAssignedUUID;
839 handshake.RegionInfo.TerrainBase0 = regionInfo.EstateSettings.terrainBase0;
840 handshake.RegionInfo.TerrainBase1 = regionInfo.EstateSettings.terrainBase1;
841 handshake.RegionInfo.TerrainBase2 = regionInfo.EstateSettings.terrainBase2;
842 handshake.RegionInfo.TerrainBase3 = regionInfo.EstateSettings.terrainBase3;
843 handshake.RegionInfo.TerrainDetail0 = regionInfo.EstateSettings.terrainDetail0;
844 handshake.RegionInfo.TerrainDetail1 = regionInfo.EstateSettings.terrainDetail1;
845 handshake.RegionInfo.TerrainDetail2 = regionInfo.EstateSettings.terrainDetail2;
846 handshake.RegionInfo.TerrainDetail3 = regionInfo.EstateSettings.terrainDetail3;
847 handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting?
848
849 OutPacket(handshake, ThrottleOutPacketType.Task);
850 }
851
852 /// <summary>
853 ///
854 /// </summary>
855 /// <param name="regInfo"></param>
856 public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
857 {
858 AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
859 mov.SimData.ChannelVersion = m_channelVersion;
860 mov.AgentData.SessionID = m_sessionId;
861 mov.AgentData.AgentID = AgentId;
862 mov.Data.RegionHandle = regInfo.RegionHandle;
863 mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this
864
865 if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
866 {
867 mov.Data.Position = m_startpos;
868 }
869 else
870 {
871 mov.Data.Position = pos;
872 }
873 mov.Data.LookAt = look;
874
875 // Hack to get this out immediately and skip the throttles
876 OutPacket(mov, ThrottleOutPacketType.Unknown);
877 }
878
879 /// <summary>
880 ///
881 /// </summary>
882 /// <param name="message"></param>
883 /// <param name="type"></param>
884 /// <param name="fromPos"></param>
885 /// <param name="fromName"></param>
886 /// <param name="fromAgentID"></param>
887 public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
888 {
889 SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID);
890 }
891
892 public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
893 {
894 ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
895 reply.ChatData.Audible = 1;
896 reply.ChatData.Message = message;
897 reply.ChatData.ChatType = type;
898 reply.ChatData.SourceType = 1;
899 reply.ChatData.Position = fromPos;
900 reply.ChatData.FromName = Helpers.StringToField(fromName);
901 reply.ChatData.OwnerID = fromAgentID;
902 reply.ChatData.SourceID = fromAgentID;
903
904 OutPacket(reply, ThrottleOutPacketType.Task);
905 }
906
907 /// <summary>
908 /// Send an instant message to this client
909 /// </summary>
910 /// <param name="message"></param>
911 /// <param name="target"></param>
912 public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
913 LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
914 {
915 SendInstantMessage(
916 fromAgent, fromAgentSession, message, toAgent,
917 imSessionID, fromName, dialog, timeStamp, new byte[0]);
918 }
919
920 /// <summary>
921 /// Send an instant message to this client
922 /// </summary>
923 /// <param name="message"></param>
924 /// <param name="target"></param>
925 public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
926 LLUUID imSessionID, string fromName, byte dialog, uint timeStamp,
927 byte[] binaryBucket)
928 {
929 ImprovedInstantMessagePacket msg
930 = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
931
932 msg.AgentData.AgentID = fromAgent;
933 msg.AgentData.SessionID = fromAgentSession;
934 msg.MessageBlock.FromAgentName = Helpers.StringToField(fromName);
935 msg.MessageBlock.Dialog = dialog;
936 msg.MessageBlock.FromGroup = false;
937 msg.MessageBlock.ID = imSessionID;
938 msg.MessageBlock.Offline = 0;
939 msg.MessageBlock.ParentEstateID = 0;
940 msg.MessageBlock.Position = new LLVector3();
941 msg.MessageBlock.RegionID = LLUUID.Random();
942 msg.MessageBlock.Timestamp = timeStamp;
943 msg.MessageBlock.ToAgentID = toAgent;
944 msg.MessageBlock.Message = Helpers.StringToField(message);
945 msg.MessageBlock.BinaryBucket = binaryBucket;
946
947 OutPacket(msg, ThrottleOutPacketType.Task);
948 }
949
950 /// <summary>
951 /// Send the region heightmap to the client
952 /// </summary>
953 /// <param name="map">heightmap</param>
954 public virtual void SendLayerData(float[] map)
955 {
956 try
957 {
958 int[] patches = new int[4];
959
960 for (int y = 0; y < 16; y++)
961 {
962 for (int x = 0; x < 16; x += 4)
963 {
964 patches[0] = x + 0 + y * 16;
965 patches[1] = x + 1 + y * 16;
966 patches[2] = x + 2 + y * 16;
967 patches[3] = x + 3 + y * 16;
968
969 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
970 OutPacket(layerpack, ThrottleOutPacketType.Land);
971 }
972 }
973 }
974 catch (Exception e)
975 {
976 m_log.Warn("[client]: " +
977 "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
978 }
979 }
980
981 /// <summary>
982 /// Sends a specified patch to a client
983 /// </summary>
984 /// <param name="px">Patch coordinate (x) 0..16</param>
985 /// <param name="py">Patch coordinate (y) 0..16</param>
986 /// <param name="map">heightmap</param>
987 public void SendLayerData(int px, int py, float[] map)
988 {
989 try
990 {
991 int[] patches = new int[1];
992 int patchx, patchy;
993 patchx = px;
994 patchy = py;
995
996 patches[0] = patchx + 0 + patchy * 16;
997
998 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
999 OutPacket(layerpack, ThrottleOutPacketType.Land);
1000 }
1001 catch (Exception e)
1002 {
1003 m_log.Warn("[client]: " +
1004 "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
1005 }
1006 }
1007
1008 /// <summary>
1009 ///
1010 /// </summary>
1011 /// <param name="neighbourHandle"></param>
1012 /// <param name="neighbourIP"></param>
1013 /// <param name="neighbourPort"></param>
1014 public void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
1015 {
1016 IPAddress neighbourIP = neighbourEndPoint.Address;
1017 ushort neighbourPort = (ushort)neighbourEndPoint.Port;
1018
1019 EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
1020 // TODO: don't create new blocks if recycling an old packet
1021 enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
1022 enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
1023
1024 byte[] byteIP = neighbourIP.GetAddressBytes();
1025 enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
1026 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
1027 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
1028 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
1029 enablesimpacket.SimulatorInfo.Port = neighbourPort;
1030 OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
1031 }
1032
1033 /// <summary>
1034 ///
1035 /// </summary>
1036 /// <returns></returns>
1037 public AgentCircuitData RequestClientInfo()
1038 {
1039 AgentCircuitData agentData = new AgentCircuitData();
1040 agentData.AgentID = AgentId;
1041 agentData.SessionID = m_sessionId;
1042 agentData.SecureSessionID = SecureSessionId;
1043 agentData.circuitcode = m_circuitCode;
1044 agentData.child = false;
1045 agentData.firstname = m_firstName;
1046 agentData.lastname = m_lastName;
1047 agentData.CapsPath = m_scene.GetCapsPath(m_agentId);
1048 return agentData;
1049 }
1050
1051 public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint externalIPEndPoint,
1052 string capsURL)
1053 {
1054 LLVector3 look = new LLVector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
1055
1056 //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
1057 CrossedRegionPacket newSimPack = new CrossedRegionPacket();
1058 // TODO: don't create new blocks if recycling an old packet
1059 newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
1060 newSimPack.AgentData.AgentID = AgentId;
1061 newSimPack.AgentData.SessionID = m_sessionId;
1062 newSimPack.Info = new CrossedRegionPacket.InfoBlock();
1063 newSimPack.Info.Position = pos;
1064 newSimPack.Info.LookAt = look;
1065 newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
1066 newSimPack.RegionData.RegionHandle = newRegionHandle;
1067 byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
1068 newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
1069 newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
1070 newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
1071 newSimPack.RegionData.SimIP += (uint)byteIP[0];
1072 newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
1073 newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL);
1074
1075 // Hack to get this out immediately and skip throttles
1076 OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
1077 }
1078
1079 public void SendMapBlock(List<MapBlockData> mapBlocks)
1080 {
1081 MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
1082 // TODO: don't create new blocks if recycling an old packet
1083 mapReply.AgentData.AgentID = AgentId;
1084 mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count];
1085 mapReply.AgentData.Flags = 0;
1086
1087 for (int i = 0; i < mapBlocks.Count; i++)
1088 {
1089 mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
1090 mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId;
1091 mapReply.Data[i].X = mapBlocks[i].X;
1092 mapReply.Data[i].Y = mapBlocks[i].Y;
1093 mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight;
1094 mapReply.Data[i].Name = Helpers.StringToField(mapBlocks[i].Name);
1095 mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags;
1096 mapReply.Data[i].Access = mapBlocks[i].Access;
1097 mapReply.Data[i].Agents = mapBlocks[i].Agents;
1098 }
1099 OutPacket(mapReply, ThrottleOutPacketType.Land);
1100 }
1101
1102 public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
1103 {
1104 TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
1105 tpLocal.Info.AgentID = AgentId;
1106 tpLocal.Info.TeleportFlags = flags;
1107 tpLocal.Info.LocationID = 2;
1108 tpLocal.Info.LookAt = lookAt;
1109 tpLocal.Info.Position = position;
1110
1111 // Hack to get this out immediately and skip throttles
1112 OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
1113 }
1114
1115 public void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
1116 uint flags, string capsURL)
1117 {
1118 //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
1119
1120 TeleportFinishPacket teleport = new TeleportFinishPacket();
1121 teleport.Info.AgentID = AgentId;
1122 teleport.Info.RegionHandle = regionHandle;
1123 teleport.Info.SimAccess = simAccess;
1124
1125 teleport.Info.SeedCapability = Helpers.StringToField(capsURL);
1126
1127 IPAddress oIP = newRegionEndPoint.Address;
1128 byte[] byteIP = oIP.GetAddressBytes();
1129 uint ip = (uint)byteIP[3] << 24;
1130 ip += (uint)byteIP[2] << 16;
1131 ip += (uint)byteIP[1] << 8;
1132 ip += (uint)byteIP[0];
1133
1134 teleport.Info.SimIP = ip;
1135 teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
1136 teleport.Info.LocationID = 4;
1137 teleport.Info.TeleportFlags = 1 << 4;
1138
1139 // Hack to get this out immediately and skip throttles.
1140 OutPacket(teleport, ThrottleOutPacketType.Unknown);
1141 }
1142
1143 /// <summary>
1144 ///
1145 /// </summary>
1146 public void SendTeleportFailed(string reason)
1147 {
1148 TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
1149 tpFailed.Info.AgentID = AgentId;
1150 tpFailed.Info.Reason = Helpers.StringToField(reason);
1151
1152 // Hack to get this out immediately and skip throttles
1153 OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
1154 }
1155
1156 /// <summary>
1157 ///
1158 /// </summary>
1159 public void SendTeleportLocationStart()
1160 {
1161 //TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
1162 TeleportStartPacket tpStart = new TeleportStartPacket();
1163 tpStart.Info.TeleportFlags = 16; // Teleport via location
1164
1165 // Hack to get this out immediately and skip throttles
1166 OutPacket(tpStart, ThrottleOutPacketType.Unknown);
1167 }
1168
1169 public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
1170 {
1171 MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
1172 money.MoneyData.AgentID = AgentId;
1173 money.MoneyData.TransactionID = transaction;
1174 money.MoneyData.TransactionSuccess = success;
1175 money.MoneyData.Description = description;
1176 money.MoneyData.MoneyBalance = balance;
1177 OutPacket(money, ThrottleOutPacketType.Task);
1178 }
1179
1180 public void SendPayPrice(LLUUID objectID, int[] payPrice)
1181 {
1182 if(payPrice[0] == 0 &&
1183 payPrice[1] == 0 &&
1184 payPrice[2] == 0 &&
1185 payPrice[3] == 0 &&
1186 payPrice[4] == 0)
1187 return;
1188
1189 PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
1190 payPriceReply.ObjectData.ObjectID = objectID;
1191 payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
1192
1193 payPriceReply.ButtonData=new PayPriceReplyPacket.ButtonDataBlock[4];
1194 payPriceReply.ButtonData[0]=new PayPriceReplyPacket.ButtonDataBlock();
1195 payPriceReply.ButtonData[0].PayButton = payPrice[1];
1196 payPriceReply.ButtonData[1]=new PayPriceReplyPacket.ButtonDataBlock();
1197 payPriceReply.ButtonData[1].PayButton = payPrice[2];
1198 payPriceReply.ButtonData[2]=new PayPriceReplyPacket.ButtonDataBlock();
1199 payPriceReply.ButtonData[2].PayButton = payPrice[3];
1200 payPriceReply.ButtonData[3]=new PayPriceReplyPacket.ButtonDataBlock();
1201 payPriceReply.ButtonData[3].PayButton = payPrice[4];
1202
1203 OutPacket(payPriceReply, ThrottleOutPacketType.Task);
1204 }
1205
1206 public void SendStartPingCheck(byte seq)
1207 {
1208 StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
1209 pc.PingID.PingID = seq;
1210 pc.Header.Reliable = false;
1211 OutPacket(pc, ThrottleOutPacketType.Unknown);
1212 }
1213
1214 public void SendKillObject(ulong regionHandle, uint localID)
1215 {
1216 KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
1217 // TODO: don't create new blocks if recycling an old packet
1218 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
1219 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
1220 kill.ObjectData[0].ID = localID;
1221 kill.Header.Reliable = false;
1222 OutPacket(kill, ThrottleOutPacketType.Task);
1223 }
1224
1225 /// <summary>
1226 /// Send information about the items contained in a folder to the client.
1227 ///
1228 /// XXX This method needs some refactoring loving
1229 /// </summary>
1230 /// <param name="ownerID">The owner of the folder</param>
1231 /// <param name="folderID">The id of the folder</param>
1232 /// <param name="items">The items contained in the folder identified by folderID</param>
1233 /// <param name="fetchFolders">Do we need to send folder information?</param>
1234 /// <param name="fetchItems">Do we need to send item information?</param>
1235 public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items,
1236 List<InventoryFolderBase> folders,
1237 bool fetchFolders, bool fetchItems)
1238 {
1239 // An inventory descendents packet consists of a single agent section and an inventory details
1240 // section for each inventory item. The size of each inventory item is approximately 550 bytes.
1241 // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
1242 // packets containing metadata for in excess of 100 items. But in practice, there may be other
1243 // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
1244 //
1245 // http://opensimulator.org/mantis/view.php?id=226
1246 //
1247 // for one example of this kind of thing. In fact, the Linden servers appear to only send about
1248 // 6 to 7 items at a time, so let's stick with 6
1249 int MAX_ITEMS_PER_PACKET = 6;
1250
1251//Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08)
1252//Ckrinke uint FULL_MASK_PERMISSIONS = 2147483647;
1253
1254 if (fetchItems)
1255 {
1256 InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
1257
1258 if (items.Count < MAX_ITEMS_PER_PACKET)
1259 {
1260 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
1261 descend.AgentData.Descendents = items.Count;
1262 }
1263 else
1264 {
1265 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
1266 descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
1267 }
1268
1269 // Even if we aren't fetching the folders, we still need to include the folder count
1270 // in the total number of descendents. Failure to do so will cause subtle bugs such
1271 // as the failure of textures which haven't been expanded in inventory to show up
1272 // in the texture prim edit selection panel.
1273 if (!fetchFolders)
1274 {
1275 descend.AgentData.Descendents += folders.Count;
1276 }
1277
1278 int count = 0;
1279 int i = 0;
1280 foreach (InventoryItemBase item in items)
1281 {
1282 descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
1283 descend.ItemData[i].ItemID = item.ID;
1284 descend.ItemData[i].AssetID = item.AssetID;
1285 descend.ItemData[i].CreatorID = item.Creator;
1286 descend.ItemData[i].BaseMask = item.BasePermissions;
1287 descend.ItemData[i].Description = Helpers.StringToField(item.Description);
1288 descend.ItemData[i].EveryoneMask = item.EveryOnePermissions;
1289 descend.ItemData[i].OwnerMask = item.CurrentPermissions;
1290 descend.ItemData[i].FolderID = item.Folder;
1291 descend.ItemData[i].InvType = (sbyte)item.InvType;
1292 descend.ItemData[i].Name = Helpers.StringToField(item.Name);
1293 descend.ItemData[i].NextOwnerMask = item.NextPermissions;
1294 descend.ItemData[i].OwnerID = item.Owner;
1295 descend.ItemData[i].Type = (sbyte)item.AssetType;
1296
1297 //descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
1298 descend.ItemData[i].GroupID = item.GroupID;
1299 descend.ItemData[i].GroupOwned = item.GroupOwned;
1300 descend.ItemData[i].GroupMask = 0;
1301 descend.ItemData[i].CreationDate = item.CreationDate;
1302 descend.ItemData[i].SalePrice = item.SalePrice;
1303 descend.ItemData[i].SaleType = item.SaleType;
1304 descend.ItemData[i].Flags = item.Flags;
1305
1306 descend.ItemData[i].CRC =
1307 Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
1308 descend.ItemData[i].InvType, descend.ItemData[i].Type,
1309 descend.ItemData[i].AssetID, descend.ItemData[i].GroupID,
1310 descend.ItemData[i].SalePrice,
1311 descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
1312 descend.ItemData[i].ItemID, descend.ItemData[i].FolderID,
1313 descend.ItemData[i].EveryoneMask,
1314 descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask,
1315 descend.ItemData[i].GroupMask, item.CurrentPermissions);
1316
1317 i++;
1318 count++;
1319 if (i == MAX_ITEMS_PER_PACKET)
1320 {
1321 OutPacket(descend, ThrottleOutPacketType.Asset);
1322
1323 if ((items.Count - count) > 0)
1324 {
1325 descend = CreateInventoryDescendentsPacket(ownerID, folderID);
1326 if ((items.Count - count) < MAX_ITEMS_PER_PACKET)
1327 {
1328 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
1329 descend.AgentData.Descendents = items.Count - count;
1330 }
1331 else
1332 {
1333 descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
1334 descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
1335 }
1336 i = 0;
1337 }
1338 }
1339 }
1340
1341 if (i < MAX_ITEMS_PER_PACKET)
1342 {
1343 OutPacket(descend, ThrottleOutPacketType.Asset);
1344 }
1345 }
1346
1347 //send subfolders
1348 if (fetchFolders)
1349 {
1350 InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
1351
1352 if (folders.Count < MAX_ITEMS_PER_PACKET)
1353 {
1354 descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
1355 descend.AgentData.Descendents = folders.Count;
1356 }
1357 else
1358 {
1359 descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
1360 descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
1361 }
1362
1363 // Not sure if this scenario ever actually occurs, but nonetheless we include the items
1364 // count even if we're not sending item data for the same reasons as above.
1365 if (!fetchItems)
1366 {
1367 descend.AgentData.Descendents += items.Count;
1368 }
1369
1370 int i = 0;
1371 int count = 0;
1372 foreach (InventoryFolderBase folder in folders)
1373 {
1374 descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
1375 descend.FolderData[i].FolderID = folder.ID;
1376 descend.FolderData[i].Name = Helpers.StringToField(folder.Name);
1377 descend.FolderData[i].ParentID = folder.ParentID;
1378 descend.FolderData[i].Type = (sbyte) folder.Type;
1379
1380 i++;
1381 count++;
1382 if (i == MAX_ITEMS_PER_PACKET)
1383 {
1384 OutPacket(descend, ThrottleOutPacketType.Asset);
1385
1386 if ((folders.Count - count) > 0)
1387 {
1388 descend = CreateInventoryDescendentsPacket(ownerID, folderID);
1389 if ((folders.Count - count) < MAX_ITEMS_PER_PACKET)
1390 {
1391 descend.FolderData =
1392 new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count];
1393 descend.AgentData.Descendents = folders.Count - count;
1394 }
1395 else
1396 {
1397 descend.FolderData =
1398 new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
1399 descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
1400 }
1401 i = 0;
1402 }
1403 }
1404 }
1405
1406 if (i < MAX_ITEMS_PER_PACKET)
1407 {
1408 OutPacket(descend, ThrottleOutPacketType.Asset);
1409 }
1410 }
1411 }
1412
1413 private InventoryDescendentsPacket CreateInventoryDescendentsPacket(LLUUID ownerID, LLUUID folderID)
1414 {
1415 InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
1416 descend.AgentData.AgentID = AgentId;
1417 descend.AgentData.OwnerID = ownerID;
1418 descend.AgentData.FolderID = folderID;
1419 descend.AgentData.Version = 1;
1420
1421 return descend;
1422 }
1423
1424 public void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
1425 {
1426 uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
1427 FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
1428 // TODO: don't create new blocks if recycling an old packet
1429 inventoryReply.AgentData.AgentID = AgentId;
1430 inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
1431 inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
1432 inventoryReply.InventoryData[0].ItemID = item.ID;
1433 inventoryReply.InventoryData[0].AssetID = item.AssetID;
1434 inventoryReply.InventoryData[0].CreatorID = item.Creator;
1435 inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
1436 inventoryReply.InventoryData[0].CreationDate =
1437 (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
1438 inventoryReply.InventoryData[0].Description = Helpers.StringToField(item.Description);
1439 inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
1440 inventoryReply.InventoryData[0].FolderID = item.Folder;
1441 inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
1442 inventoryReply.InventoryData[0].Name = Helpers.StringToField(item.Name);
1443 inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
1444 inventoryReply.InventoryData[0].OwnerID = item.Owner;
1445 inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
1446 inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
1447
1448 //inventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
1449 inventoryReply.InventoryData[0].GroupID = item.GroupID;
1450 inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
1451 inventoryReply.InventoryData[0].GroupMask = 0;
1452 inventoryReply.InventoryData[0].Flags = item.Flags;
1453 inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
1454 inventoryReply.InventoryData[0].SaleType = item.SaleType;
1455
1456 inventoryReply.InventoryData[0].CRC =
1457 Helpers.InventoryCRC(1000, 0, inventoryReply.InventoryData[0].InvType,
1458 inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
1459 inventoryReply.InventoryData[0].GroupID, 100,
1460 inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
1461 inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
1462 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
1463 FULL_MASK_PERMISSIONS);
1464
1465 OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
1466 }
1467
1468 /// <see>IClientAPI.SendBulkUpdateInventory(InventoryItemBase)</see>
1469 public void SendBulkUpdateInventory(InventoryItemBase item)
1470 {
1471 uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
1472
1473 BulkUpdateInventoryPacket bulkUpdate
1474 = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
1475
1476 bulkUpdate.AgentData.AgentID = AgentId;
1477 bulkUpdate.AgentData.TransactionID = LLUUID.Random();
1478
1479 bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
1480 bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
1481 bulkUpdate.FolderData[0].FolderID = LLUUID.Zero;
1482 bulkUpdate.FolderData[0].ParentID = LLUUID.Zero;
1483 bulkUpdate.FolderData[0].Type = -1;
1484 bulkUpdate.FolderData[0].Name = new byte[0];
1485
1486 bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
1487 bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
1488 bulkUpdate.ItemData[0].ItemID = item.ID;
1489 bulkUpdate.ItemData[0].AssetID = item.AssetID;
1490 bulkUpdate.ItemData[0].CreatorID = item.Creator;
1491 bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
1492 bulkUpdate.ItemData[0].CreationDate = 1000;
1493 bulkUpdate.ItemData[0].Description = Helpers.StringToField(item.Description);
1494 bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
1495 bulkUpdate.ItemData[0].FolderID = item.Folder;
1496 bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
1497 bulkUpdate.ItemData[0].Name = Helpers.StringToField(item.Name);
1498 bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
1499 bulkUpdate.ItemData[0].OwnerID = item.Owner;
1500 bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
1501 bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
1502
1503 //bulkUpdate.ItemData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
1504 bulkUpdate.ItemData[0].GroupID = item.GroupID;
1505 bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
1506 bulkUpdate.ItemData[0].GroupMask = 0;
1507 bulkUpdate.ItemData[0].Flags = item.Flags;
1508 bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
1509 bulkUpdate.ItemData[0].SaleType = item.SaleType;
1510
1511 bulkUpdate.ItemData[0].CRC =
1512 Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
1513 bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
1514 bulkUpdate.ItemData[0].GroupID, 100,
1515 bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
1516 bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
1517 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
1518 FULL_MASK_PERMISSIONS);
1519
1520 OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
1521 }
1522
1523 /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
1524 public void SendInventoryItemCreateUpdate(InventoryItemBase Item)
1525 {
1526 uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
1527
1528 UpdateCreateInventoryItemPacket InventoryReply
1529 = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
1530 PacketType.UpdateCreateInventoryItem);
1531
1532 // TODO: don't create new blocks if recycling an old packet
1533 InventoryReply.AgentData.AgentID = AgentId;
1534 InventoryReply.AgentData.SimApproved = true;
1535 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
1536 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
1537 InventoryReply.InventoryData[0].ItemID = Item.ID;
1538 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
1539 InventoryReply.InventoryData[0].CreatorID = Item.Creator;
1540 InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
1541 InventoryReply.InventoryData[0].Description = Helpers.StringToField(Item.Description);
1542 InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
1543 InventoryReply.InventoryData[0].FolderID = Item.Folder;
1544 InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
1545 InventoryReply.InventoryData[0].Name = Helpers.StringToField(Item.Name);
1546 InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
1547 InventoryReply.InventoryData[0].OwnerID = Item.Owner;
1548 InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
1549 InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
1550
1551 //InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
1552 InventoryReply.InventoryData[0].GroupID = Item.GroupID;
1553 InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
1554 InventoryReply.InventoryData[0].GroupMask = 0;
1555 InventoryReply.InventoryData[0].Flags = Item.Flags;
1556 InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
1557 InventoryReply.InventoryData[0].SaleType = Item.SaleType;
1558
1559 InventoryReply.InventoryData[0].CRC =
1560 Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
1561 InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
1562 InventoryReply.InventoryData[0].GroupID, 100,
1563 InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
1564 InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
1565 FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
1566 FULL_MASK_PERMISSIONS);
1567
1568 OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
1569 }
1570
1571 public void SendRemoveInventoryItem(LLUUID itemID)
1572 {
1573 RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
1574 // TODO: don't create new blocks if recycling an old packet
1575 remove.AgentData.AgentID = AgentId;
1576 remove.AgentData.SessionID = m_sessionId;
1577 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
1578 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
1579 remove.InventoryData[0].ItemID = itemID;
1580
1581 OutPacket(remove, ThrottleOutPacketType.Asset);
1582 }
1583
1584 public void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
1585 {
1586 ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
1587 replytask.InventoryData.TaskID = taskID;
1588 replytask.InventoryData.Serial = serial;
1589 replytask.InventoryData.Filename = fileName;
1590 OutPacket(replytask, ThrottleOutPacketType.Asset);
1591 }
1592
1593 public void SendXferPacket(ulong xferID, uint packet, byte[] data)
1594 {
1595 SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
1596 sendXfer.XferID.ID = xferID;
1597 sendXfer.XferID.Packet = packet;
1598 sendXfer.DataPacket.Data = data;
1599 OutPacket(sendXfer, ThrottleOutPacketType.Task);
1600 }
1601
1602 public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
1603 int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
1604 int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
1605 int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
1606 {
1607 EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
1608 economyData.Info.EnergyEfficiency = EnergyEfficiency;
1609 economyData.Info.ObjectCapacity = ObjectCapacity;
1610 economyData.Info.ObjectCount = ObjectCount;
1611 economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
1612 economyData.Info.PriceGroupCreate = PriceGroupCreate;
1613 economyData.Info.PriceObjectClaim = PriceObjectClaim;
1614 economyData.Info.PriceObjectRent = PriceObjectRent;
1615 economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
1616 economyData.Info.PriceParcelClaim = PriceParcelClaim;
1617 economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
1618 economyData.Info.PriceParcelRent = PriceParcelRent;
1619 economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
1620 economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
1621 economyData.Info.PriceRentLight = PriceRentLight;
1622 economyData.Info.PriceUpload = PriceUpload;
1623 economyData.Info.TeleportMinPrice = TeleportMinPrice;
1624 economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
1625 economyData.Header.Reliable = true;
1626 OutPacket(economyData, ThrottleOutPacketType.Unknown);
1627
1628 }
1629
1630 public void SendAvatarPickerReply(AvatarPickerReplyPacket replyPacket)
1631 {
1632 OutPacket(replyPacket, ThrottleOutPacketType.Task);
1633 }
1634
1635 public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
1636 {
1637 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
1638 sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
1639 sendAgentDataUpdate.AgentData.AgentID = agentid;
1640 sendAgentDataUpdate.AgentData.FirstName = Helpers.StringToField(firstname);
1641 sendAgentDataUpdate.AgentData.GroupName = Helpers.StringToField(groupname);
1642 sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
1643 sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle);
1644 sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname);
1645 OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
1646 }
1647
1648 /// <summary>
1649 /// Send an alert message to the client. On the Linden client (tested 1.19.1.4), this pops up a brief duration
1650 /// blue information box in the bottom right hand corner.
1651 /// </summary>
1652 /// <param name="message"></param>
1653 public void SendAlertMessage(string message)
1654 {
1655 AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
1656 alertPack.AlertData.Message = Helpers.StringToField(message);
1657 OutPacket(alertPack, ThrottleOutPacketType.Task);
1658 }
1659
1660 /// <summary>
1661 /// Send an agent alert message to the client.
1662 /// </summary>
1663 /// <param name="message"></param>
1664 /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
1665 /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
1666 /// the AlertMessage packet).</param>
1667 public void SendAgentAlertMessage(string message, bool modal)
1668 {
1669 AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
1670 alertPack.AgentData.AgentID = AgentId;
1671 alertPack.AlertData.Message = Helpers.StringToField(message);
1672 alertPack.AlertData.Modal = modal;
1673 OutPacket(alertPack, ThrottleOutPacketType.Task);
1674 }
1675
1676 public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
1677 string url)
1678 {
1679 LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
1680 loadURL.Data.ObjectName = Helpers.StringToField(objectname);
1681 loadURL.Data.ObjectID = objectID;
1682 loadURL.Data.OwnerID = ownerID;
1683 loadURL.Data.OwnerIsGroup = groupOwned;
1684 loadURL.Data.Message = Helpers.StringToField(message);
1685 loadURL.Data.URL = Helpers.StringToField(url);
1686 OutPacket(loadURL, ThrottleOutPacketType.Task);
1687 }
1688
1689 public void SendDialog(string objectname, LLUUID objectID, LLUUID ownerID, string msg, LLUUID textureID, int ch, string[] buttonlabels)
1690 {
1691 ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
1692 dialog.Data.ObjectID = objectID;
1693 dialog.Data.ObjectName = Helpers.StringToField(objectname);
1694 dialog.Data.FirstName = Helpers.StringToField(this.FirstName);
1695 dialog.Data.LastName = Helpers.StringToField(this.LastName);
1696 dialog.Data.Message = Helpers.StringToField(msg);
1697 dialog.Data.ImageID = textureID;
1698 dialog.Data.ChatChannel = ch;
1699 ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
1700 for (int i = 0; i < buttonlabels.Length; i++)
1701 {
1702 buttons[i] = new ScriptDialogPacket.ButtonsBlock();
1703 buttons[i].ButtonLabel = Helpers.StringToField(buttonlabels[i]);
1704 }
1705 dialog.Buttons = buttons;
1706 OutPacket(dialog, ThrottleOutPacketType.Task);
1707 }
1708
1709 public void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
1710 {
1711 PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
1712 // TODO: don't create new blocks if recycling an old packet
1713 preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
1714 preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
1715 preSound.DataBlock[0].ObjectID = objectID;
1716 preSound.DataBlock[0].OwnerID = ownerID;
1717 preSound.DataBlock[0].SoundID = soundID;
1718 OutPacket(preSound, ThrottleOutPacketType.Task);
1719 }
1720
1721 public void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags)
1722 {
1723 AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
1724 sound.DataBlock.SoundID = soundID;
1725 sound.DataBlock.ObjectID = objectID;
1726 sound.DataBlock.OwnerID = ownerID;
1727 sound.DataBlock.Gain = gain;
1728 sound.DataBlock.Flags = flags;
1729
1730 OutPacket(sound, ThrottleOutPacketType.Task);
1731 }
1732
1733 public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain)
1734 {
1735 SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
1736 sound.SoundData.SoundID = soundID;
1737 sound.SoundData.OwnerID = ownerID;
1738 sound.SoundData.ObjectID = objectID;
1739 sound.SoundData.ParentID = parentID;
1740 sound.SoundData.Handle = handle;
1741 sound.SoundData.Position = position;
1742 sound.SoundData.Gain = gain;
1743
1744 OutPacket(sound, ThrottleOutPacketType.Task);
1745 }
1746
1747 public void SendAttachedSoundGainChange(LLUUID objectID, float gain)
1748 {
1749 AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
1750 sound.DataBlock.ObjectID = objectID;
1751 sound.DataBlock.Gain = gain;
1752
1753 OutPacket(sound, ThrottleOutPacketType.Task);
1754 }
1755
1756 public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel)
1757 {
1758 SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
1759 viewertime.TimeInfo.SunDirection = sunPos;
1760 viewertime.TimeInfo.SunAngVelocity = sunVel;
1761 viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
1762 viewertime.Header.Reliable = false;
1763 OutPacket(viewertime, ThrottleOutPacketType.Task);
1764 }
1765
1766 public void SendViewerTime(int phase)
1767 {
1768 Console.WriteLine("SunPhase: {0}", phase);
1769 SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
1770 //viewertime.TimeInfo.SecPerDay = 86400;
1771 //viewertime.TimeInfo.SecPerYear = 31536000;
1772 viewertime.TimeInfo.SecPerDay = 1000;
1773 viewertime.TimeInfo.SecPerYear = 365000;
1774 viewertime.TimeInfo.SunPhase = 1;
1775 int sunPhase = (phase + 2) / 2;
1776 if ((sunPhase < 6) || (sunPhase > 36))
1777 {
1778 viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
1779 Console.WriteLine("sending night");
1780 }
1781 else
1782 {
1783 if (sunPhase < 12)
1784 {
1785 sunPhase = 12;
1786 }
1787 sunPhase = sunPhase - 12;
1788
1789 float yValue = 0.1f * (sunPhase);
1790 Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
1791 if (yValue > 1.2f)
1792 {
1793 yValue = yValue - 1.2f;
1794 }
1795
1796 yValue = Util.Clip(yValue, 0, 1);
1797
1798 if (sunPhase < 14)
1799 {
1800 yValue = 1 - yValue;
1801 }
1802 if (sunPhase < 12)
1803 {
1804 yValue *= -1;
1805 }
1806 viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
1807 Console.WriteLine("sending sun update " + yValue);
1808 }
1809 viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
1810 viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
1811 viewertime.Header.Reliable = false;
1812 OutPacket(viewertime, ThrottleOutPacketType.Task);
1813 }
1814
1815 public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
1816 string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
1817 LLUUID partnerID)
1818 {
1819 AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
1820 avatarReply.AgentData.AgentID = AgentId;
1821 avatarReply.AgentData.AvatarID = avatarID;
1822 if (aboutText != null)
1823 avatarReply.PropertiesData.AboutText = Helpers.StringToField(aboutText);
1824 else
1825 avatarReply.PropertiesData.AboutText = Helpers.StringToField("");
1826 avatarReply.PropertiesData.BornOn = Helpers.StringToField(bornOn);
1827 avatarReply.PropertiesData.CharterMember = Helpers.StringToField(charterMember);
1828 if (flAbout != null)
1829 avatarReply.PropertiesData.FLAboutText = Helpers.StringToField(flAbout);
1830 else
1831 avatarReply.PropertiesData.FLAboutText = Helpers.StringToField("");
1832 avatarReply.PropertiesData.Flags = 0;
1833 avatarReply.PropertiesData.FLImageID = flImageID;
1834 avatarReply.PropertiesData.ImageID = imageID;
1835 avatarReply.PropertiesData.ProfileURL = Helpers.StringToField(profileURL);
1836 avatarReply.PropertiesData.PartnerID = partnerID;
1837 OutPacket(avatarReply, ThrottleOutPacketType.Task);
1838 }
1839
1840 #endregion
1841
1842 #region Appearance/ Wearables Methods
1843
1844 /// <summary>
1845 ///
1846 /// </summary>
1847 /// <param name="wearables"></param>
1848 public void SendWearables(AvatarWearable[] wearables, int serial)
1849 {
1850 AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
1851 aw.AgentData.AgentID = AgentId;
1852 aw.AgentData.SerialNum = (uint)serial;
1853 aw.AgentData.SessionID = m_sessionId;
1854
1855 // TODO: don't create new blocks if recycling an old packet
1856 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
1857 AgentWearablesUpdatePacket.WearableDataBlock awb;
1858 for (int i = 0; i < wearables.Length; i++)
1859 {
1860 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
1861 awb.WearableType = (byte)i;
1862 awb.AssetID = wearables[i].AssetID;
1863 awb.ItemID = wearables[i].ItemID;
1864 aw.WearableData[i] = awb;
1865 }
1866
1867 OutPacket(aw, ThrottleOutPacketType.Task);
1868 }
1869
1870 /// <summary>
1871 ///
1872 /// </summary>
1873 /// <param name="agentID"></param>
1874 /// <param name="visualParams"></param>
1875 /// <param name="textureEntry"></param>
1876 public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
1877 {
1878 AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
1879 // TODO: don't create new blocks if recycling an old packet
1880 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
1881 avp.ObjectData.TextureEntry = textureEntry;
1882
1883 AvatarAppearancePacket.VisualParamBlock avblock = null;
1884 for (int i = 0; i < visualParams.Length; i++)
1885 {
1886 avblock = new AvatarAppearancePacket.VisualParamBlock();
1887 avblock.ParamValue = visualParams[i];
1888 avp.VisualParam[i] = avblock;
1889 }
1890
1891 avp.Sender.IsTrial = false;
1892 avp.Sender.ID = agentID;
1893 OutPacket(avp, ThrottleOutPacketType.Task);
1894 }
1895
1896 public void SendAnimations(LLUUID[] animations, int[] seqs, LLUUID sourceAgentId)
1897 {
1898 AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
1899 // TODO: don't create new blocks if recycling an old packet
1900 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
1901 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
1902 ani.AnimationSourceList[0].ObjectID = sourceAgentId;
1903 ani.Sender = new AvatarAnimationPacket.SenderBlock();
1904 ani.Sender.ID = sourceAgentId;
1905 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
1906
1907 for (int i = 0; i < animations.Length; ++i)
1908 {
1909 ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
1910 ani.AnimationList[i].AnimID = animations[i];
1911 ani.AnimationList[i].AnimSequenceID = seqs[i];
1912 }
1913 ani.Header.Reliable = false;
1914 OutPacket(ani, ThrottleOutPacketType.Task);
1915 }
1916
1917 #endregion
1918
1919 #region Avatar Packet/data sending Methods
1920
1921 /// <summary>
1922 /// send a objectupdate packet with information about the clients avatar
1923 /// </summary>
1924 /// <param name="regionInfo"></param>
1925 /// <param name="firstName"></param>
1926 /// <param name="lastName"></param>
1927 /// <param name="avatarID"></param>
1928 /// <param name="avatarLocalID"></param>
1929 /// <param name="Pos"></param>
1930 public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
1931 uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
1932 {
1933 ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
1934 // TODO: don't create new blocks if recycling an old packet
1935 objupdate.RegionData.RegionHandle = regionHandle;
1936 objupdate.RegionData.TimeDilation = ushort.MaxValue;
1937 objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
1938 objupdate.ObjectData[0] = CreateDefaultAvatarPacket(textureEntry);
1939
1940 //give this avatar object a local id and assign the user a name
1941 objupdate.ObjectData[0].ID = avatarLocalID;
1942 objupdate.ObjectData[0].FullID = avatarID;
1943 objupdate.ObjectData[0].ParentID = parentID;
1944 objupdate.ObjectData[0].NameValue =
1945 Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName);
1946 LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
1947 byte[] pb = pos2.GetBytes();
1948 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
1949
1950 OutPacket(objupdate, ThrottleOutPacketType.Task);
1951 }
1952
1953 /// <summary>
1954 ///
1955 /// </summary>
1956 /// <param name="regionHandle"></param>
1957 /// <param name="timeDilation"></param>
1958 /// <param name="localID"></param>
1959 /// <param name="position"></param>
1960 /// <param name="velocity"></param>
1961 public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
1962 LLVector3 velocity, LLQuaternion rotation)
1963 {
1964 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock =
1965 CreateAvatarImprovedBlock(localID, position, velocity, rotation);
1966 ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
1967 // TODO: don't create new blocks if recycling an old packet
1968 terse.RegionData.RegionHandle = regionHandle;
1969 terse.RegionData.TimeDilation = timeDilation;
1970 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
1971 terse.ObjectData[0] = terseBlock;
1972
1973 terse.Header.Reliable = false;
1974
1975
1976 OutPacket(terse, ThrottleOutPacketType.Task);
1977 }
1978
1979 public void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
1980 {
1981 CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
1982 // TODO: don't create new blocks if recycling an old packet
1983 int total = CoarseLocations.Count;
1984 CoarseLocationUpdatePacket.IndexBlock ib =
1985 new CoarseLocationUpdatePacket.IndexBlock();
1986 loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
1987 for (int i = 0; i < total; i++)
1988 {
1989 CoarseLocationUpdatePacket.LocationBlock lb =
1990 new CoarseLocationUpdatePacket.LocationBlock();
1991 lb.X = (byte)CoarseLocations[i].X;
1992 lb.Y = (byte)CoarseLocations[i].Y;
1993 lb.Z = (byte)(CoarseLocations[i].Z / 4);
1994 loc.Location[i] = lb;
1995 }
1996 ib.You = -1;
1997 ib.Prey = -1;
1998 loc.Index = ib;
1999 loc.Header.Reliable = false;
2000 OutPacket(loc, ThrottleOutPacketType.Task);
2001 }
2002
2003 #endregion
2004
2005 #region Primitive Packet/data Sending Methods
2006
2007 /// <summary>
2008 ///
2009 /// </summary>
2010 /// <param name="localID"></param>
2011 /// <param name="rotation"></param>
2012 /// <param name="attachPoint"></param>
2013 public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
2014 {
2015
2016 ObjectAttachPacket attach = (ObjectAttachPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAttach);
2017 Console.WriteLine("Attach object!");
2018 // TODO: don't create new blocks if recycling an old packet
2019 attach.AgentData.AgentID = AgentId;
2020 attach.AgentData.SessionID = m_sessionId;
2021 attach.AgentData.AttachmentPoint = attachPoint;
2022 attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
2023 attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
2024 attach.ObjectData[0].ObjectLocalID = localID;
2025 attach.ObjectData[0].Rotation = rotation;
2026
2027 OutPacket(attach, ThrottleOutPacketType.Task);
2028 }
2029
2030 public void SendPrimitiveToClient(
2031 ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos,
2032 uint flags,
2033 LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
2034 LLQuaternion rotation, byte clickAction)
2035 {
2036 byte[] textureanim = new byte[0];
2037
2038 SendPrimitiveToClient(regionHandle, timeDilation, localID, primShape, pos, flags,
2039 objectID, ownerID, text, color, parentID, particleSystem,
2040 rotation, clickAction, textureanim, false,(uint)0, LLUUID.Zero);
2041 }
2042 public void SendPrimitiveToClient(
2043 ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos,
2044 uint flags,
2045 LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
2046 LLQuaternion rotation, byte clickAction, byte[] textureanim, bool attachment, uint AttachPoint, LLUUID AssetId)
2047 {
2048 ObjectUpdatePacket outPacket = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
2049 // TODO: don't create new blocks if recycling an old packet
2050 outPacket.RegionData.RegionHandle = regionHandle;
2051 outPacket.RegionData.TimeDilation = timeDilation;
2052 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
2053
2054 outPacket.ObjectData[0] = CreatePrimUpdateBlock(primShape, flags);
2055
2056 outPacket.ObjectData[0].ID = localID;
2057 outPacket.ObjectData[0].FullID = objectID;
2058 outPacket.ObjectData[0].OwnerID = ownerID;
2059
2060 // Anything more than 255 will cause libsecondlife to barf
2061 if (text.Length > 255)
2062 {
2063 text = text.Remove(255);
2064 }
2065
2066 outPacket.ObjectData[0].Text = Helpers.StringToField(text);
2067
2068 outPacket.ObjectData[0].TextColor[0] = color[0];
2069 outPacket.ObjectData[0].TextColor[1] = color[1];
2070 outPacket.ObjectData[0].TextColor[2] = color[2];
2071 outPacket.ObjectData[0].TextColor[3] = color[3];
2072 outPacket.ObjectData[0].ParentID = parentID;
2073 outPacket.ObjectData[0].PSBlock = particleSystem;
2074 outPacket.ObjectData[0].ClickAction = clickAction;
2075 //outPacket.ObjectData[0].Flags = 0;
2076
2077 if (attachment)
2078 {
2079 // Necessary???
2080 outPacket.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 2);
2081 outPacket.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
2082
2083 // Item from inventory???
2084 outPacket.ObjectData[0].NameValue =
2085 Helpers.StringToField("AttachItemID STRING RW SV " + AssetId.UUID);
2086 outPacket.ObjectData[0].State = (byte)((AttachPoint % 16) * 16 + (AttachPoint / 16));
2087 }
2088
2089 // Sound Radius
2090 outPacket.ObjectData[0].Radius = 20;
2091
2092 byte[] pb = pos.GetBytes();
2093 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
2094
2095 byte[] rot = rotation.GetBytes();
2096 Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length);
2097
2098 if (textureanim.Length > 0)
2099 {
2100 outPacket.ObjectData[0].TextureAnim = textureanim;
2101 }
2102
2103 OutPacket(outPacket, ThrottleOutPacketType.Task);
2104 }
2105
2106 /// <summary>
2107 ///
2108 /// </summary>
2109 /// <param name="regionHandle"></param>
2110 /// <param name="timeDilation"></param>
2111 /// <param name="localID"></param>
2112 /// <param name="position"></param>
2113 /// <param name="rotation"></param>
2114 public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
2115 LLQuaternion rotation, byte state, LLUUID AssetId)
2116 {
2117 LLVector3 velocity = new LLVector3(0f, 0f, 0f);
2118 LLVector3 rotationalvelocity = new LLVector3(0f, 0f, 0f);
2119 ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
2120 // TODO: don't create new blocks if recycling an old packet
2121 terse.RegionData.RegionHandle = regionHandle;
2122 terse.RegionData.TimeDilation = timeDilation;
2123 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
2124 terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, state); // AssetID should fall into here probably somehow...
2125 terse.Header.Reliable = false;
2126 OutPacket(terse, ThrottleOutPacketType.Task);
2127 }
2128
2129 public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
2130 LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity)
2131 {
2132 ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
2133 // TODO: don't create new blocks if recycling an old packet
2134 terse.RegionData.RegionHandle = regionHandle;
2135 terse.RegionData.TimeDilation = timeDilation;
2136 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
2137 terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, 0);
2138 terse.Header.Reliable = false;
2139 OutPacket(terse, ThrottleOutPacketType.Task);
2140 }
2141
2142 #endregion
2143
2144 #region Helper Methods
2145
2146 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos,
2147 LLVector3 velocity,
2148 LLQuaternion rotation)
2149 {
2150 byte[] bytes = new byte[60];
2151 int i = 0;
2152 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
2153
2154 dat.TextureEntry = new byte[0]; // AvatarTemplate.TextureEntry;
2155
2156 uint ID = localID;
2157
2158 bytes[i++] = (byte)(ID % 256);
2159 bytes[i++] = (byte)((ID >> 8) % 256);
2160 bytes[i++] = (byte)((ID >> 16) % 256);
2161 bytes[i++] = (byte)((ID >> 24) % 256);
2162 bytes[i++] = 0;
2163 bytes[i++] = 1;
2164 i += 14;
2165 bytes[i++] = 128;
2166 bytes[i++] = 63;
2167
2168 byte[] pb = pos.GetBytes();
2169 Array.Copy(pb, 0, bytes, i, pb.Length);
2170 i += 12;
2171 ushort InternVelocityX;
2172 ushort InternVelocityY;
2173 ushort InternVelocityZ;
2174 Vector3 internDirec = new Vector3(0, 0, 0);
2175
2176 internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z);
2177
2178 internDirec = internDirec / 128.0f;
2179 internDirec.x += 1;
2180 internDirec.y += 1;
2181 internDirec.z += 1;
2182
2183 InternVelocityX = (ushort)(32768 * internDirec.x);
2184 InternVelocityY = (ushort)(32768 * internDirec.y);
2185 InternVelocityZ = (ushort)(32768 * internDirec.z);
2186
2187 ushort ac = 32767;
2188 bytes[i++] = (byte)(InternVelocityX % 256);
2189 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
2190 bytes[i++] = (byte)(InternVelocityY % 256);
2191 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
2192 bytes[i++] = (byte)(InternVelocityZ % 256);
2193 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
2194
2195 //accel
2196 bytes[i++] = (byte)(ac % 256);
2197 bytes[i++] = (byte)((ac >> 8) % 256);
2198 bytes[i++] = (byte)(ac % 256);
2199 bytes[i++] = (byte)((ac >> 8) % 256);
2200 bytes[i++] = (byte)(ac % 256);
2201 bytes[i++] = (byte)((ac >> 8) % 256);
2202
2203 //rotation
2204 ushort rw, rx, ry, rz;
2205 rw = (ushort)(32768 * (rotation.W + 1));
2206 rx = (ushort)(32768 * (rotation.X + 1));
2207 ry = (ushort)(32768 * (rotation.Y + 1));
2208 rz = (ushort)(32768 * (rotation.Z + 1));
2209
2210 //rot
2211 bytes[i++] = (byte)(rx % 256);
2212 bytes[i++] = (byte)((rx >> 8) % 256);
2213 bytes[i++] = (byte)(ry % 256);
2214 bytes[i++] = (byte)((ry >> 8) % 256);
2215 bytes[i++] = (byte)(rz % 256);
2216 bytes[i++] = (byte)((rz >> 8) % 256);
2217 bytes[i++] = (byte)(rw % 256);
2218 bytes[i++] = (byte)((rw >> 8) % 256);
2219
2220 //rotation vel
2221 bytes[i++] = (byte)(ac % 256);
2222 bytes[i++] = (byte)((ac >> 8) % 256);
2223 bytes[i++] = (byte)(ac % 256);
2224 bytes[i++] = (byte)((ac >> 8) % 256);
2225 bytes[i++] = (byte)(ac % 256);
2226 bytes[i++] = (byte)((ac >> 8) % 256);
2227
2228 dat.Data = bytes;
2229
2230 return (dat);
2231 }
2232
2233 /// <summary>
2234 ///
2235 /// </summary>
2236 /// <param name="localID"></param>
2237 /// <param name="position"></param>
2238 /// <param name="rotation"></param>
2239 /// <returns></returns>
2240 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID,
2241 LLVector3 position,
2242 LLQuaternion rotation,
2243 LLVector3 velocity,
2244 LLVector3 rotationalvelocity,
2245 byte state)
2246 {
2247 uint ID = localID;
2248 byte[] bytes = new byte[60];
2249
2250 int i = 0;
2251 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
2252 dat.TextureEntry = new byte[0];
2253 bytes[i++] = (byte)(ID % 256);
2254 bytes[i++] = (byte)((ID >> 8) % 256);
2255 bytes[i++] = (byte)((ID >> 16) % 256);
2256 bytes[i++] = (byte)((ID >> 24) % 256);
2257 bytes[i++] = state;
2258 bytes[i++] = 0;
2259
2260 byte[] pb = position.GetBytes();
2261 Array.Copy(pb, 0, bytes, i, pb.Length);
2262 i += 12;
2263 ushort ac = 32767;
2264
2265 ushort velx, vely, velz;
2266 Vector3 vel = new Vector3(velocity.X, velocity.Y, velocity.Z);
2267
2268 vel = vel / 128.0f;
2269 vel.x += 1;
2270 vel.y += 1;
2271 vel.z += 1;
2272 //vel
2273 velx = (ushort)(32768 * (vel.x));
2274 vely = (ushort)(32768 * (vel.y));
2275 velz = (ushort)(32768 * (vel.z));
2276
2277 bytes[i++] = (byte)(velx % 256);
2278 bytes[i++] = (byte)((velx >> 8) % 256);
2279 bytes[i++] = (byte)(vely % 256);
2280 bytes[i++] = (byte)((vely >> 8) % 256);
2281 bytes[i++] = (byte)(velz % 256);
2282 bytes[i++] = (byte)((velz >> 8) % 256);
2283
2284 //accel
2285 bytes[i++] = (byte)(ac % 256);
2286 bytes[i++] = (byte)((ac >> 8) % 256);
2287 bytes[i++] = (byte)(ac % 256);
2288 bytes[i++] = (byte)((ac >> 8) % 256);
2289 bytes[i++] = (byte)(ac % 256);
2290 bytes[i++] = (byte)((ac >> 8) % 256);
2291
2292 ushort rw, rx, ry, rz;
2293 rw = (ushort)(32768 * (rotation.W + 1));
2294 rx = (ushort)(32768 * (rotation.X + 1));
2295 ry = (ushort)(32768 * (rotation.Y + 1));
2296 rz = (ushort)(32768 * (rotation.Z + 1));
2297
2298 //rot
2299 bytes[i++] = (byte)(rx % 256);
2300 bytes[i++] = (byte)((rx >> 8) % 256);
2301 bytes[i++] = (byte)(ry % 256);
2302 bytes[i++] = (byte)((ry >> 8) % 256);
2303 bytes[i++] = (byte)(rz % 256);
2304 bytes[i++] = (byte)((rz >> 8) % 256);
2305 bytes[i++] = (byte)(rw % 256);
2306 bytes[i++] = (byte)((rw >> 8) % 256);
2307
2308 //rotation vel
2309 ushort rvelx, rvely, rvelz;
2310 Vector3 rvel = new Vector3(rotationalvelocity.X, rotationalvelocity.Y, rotationalvelocity.Z);
2311
2312 rvel = rvel / 128.0f;
2313 rvel.x += 1;
2314 rvel.y += 1;
2315 rvel.z += 1;
2316 //vel
2317 rvelx = (ushort)(32768 * (rvel.x));
2318 rvely = (ushort)(32768 * (rvel.y));
2319 rvelz = (ushort)(32768 * (rvel.z));
2320
2321 bytes[i++] = (byte)(rvelx % 256);
2322 bytes[i++] = (byte)((rvelx >> 8) % 256);
2323 bytes[i++] = (byte)(rvely % 256);
2324 bytes[i++] = (byte)((rvely >> 8) % 256);
2325 bytes[i++] = (byte)(rvelz % 256);
2326 bytes[i++] = (byte)((rvelz >> 8) % 256);
2327 dat.Data = bytes;
2328
2329
2330 return dat;
2331 }
2332
2333 /// <summary>
2334 /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
2335 /// </summary>
2336 /// <param name="primData"></param>
2337 /// <returns></returns>
2338 protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, uint flags)
2339 {
2340 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
2341 SetDefaultPrimPacketValues(objupdate);
2342 objupdate.UpdateFlags = flags;
2343 SetPrimPacketShapeData(objupdate, primShape);
2344
2345 if ((primShape.PCode == (byte)PCode.NewTree) || (primShape.PCode == (byte)PCode.Tree) || (primShape.PCode == (byte)PCode.Grass))
2346 {
2347 objupdate.Data = new byte[1];
2348 objupdate.Data[0] = primShape.State;
2349 }
2350 return objupdate;
2351 }
2352
2353 protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData)
2354 {
2355 objectData.TextureEntry = primData.TextureEntry;
2356 objectData.PCode = primData.PCode;
2357 objectData.State = primData.State;
2358 objectData.PathBegin = primData.PathBegin;
2359 objectData.PathEnd = primData.PathEnd;
2360 objectData.PathScaleX = primData.PathScaleX;
2361 objectData.PathScaleY = primData.PathScaleY;
2362 objectData.PathShearX = primData.PathShearX;
2363 objectData.PathShearY = primData.PathShearY;
2364 objectData.PathSkew = primData.PathSkew;
2365 objectData.ProfileBegin = primData.ProfileBegin;
2366 objectData.ProfileEnd = primData.ProfileEnd;
2367 objectData.Scale = primData.Scale;
2368 objectData.PathCurve = primData.PathCurve;
2369 objectData.ProfileCurve = primData.ProfileCurve;
2370 objectData.ProfileHollow = primData.ProfileHollow;
2371 objectData.PathRadiusOffset = primData.PathRadiusOffset;
2372 objectData.PathRevolutions = primData.PathRevolutions;
2373 objectData.PathTaperX = primData.PathTaperX;
2374 objectData.PathTaperY = primData.PathTaperY;
2375 objectData.PathTwist = primData.PathTwist;
2376 objectData.PathTwistBegin = primData.PathTwistBegin;
2377 objectData.ExtraParams = primData.ExtraParams;
2378 }
2379
2380 /// <summary>
2381 /// Set some default values in a ObjectUpdatePacket
2382 /// </summary>
2383 /// <param name="objdata"></param>
2384 protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
2385 {
2386 objdata.PSBlock = new byte[0];
2387 objdata.ExtraParams = new byte[1];
2388 objdata.MediaURL = new byte[0];
2389 objdata.NameValue = new byte[0];
2390 objdata.Text = new byte[0];
2391 objdata.TextColor = new byte[4];
2392 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
2393 objdata.JointPivot = new LLVector3(0, 0, 0);
2394 objdata.Material = 3;
2395 objdata.TextureAnim = new byte[0];
2396 objdata.Sound = LLUUID.Zero;
2397 objdata.State = 0;
2398 objdata.Data = new byte[0];
2399
2400 objdata.ObjectData = new byte[60];
2401 objdata.ObjectData[46] = 128;
2402 objdata.ObjectData[47] = 63;
2403 }
2404
2405
2406 /// <summary>
2407 ///
2408 /// </summary>
2409 /// <returns></returns>
2410 public ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
2411 {
2412 ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock();
2413 // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
2414
2415 SetDefaultAvatarPacketValues(ref objdata);
2416 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
2417 objdata.PathCurve = 16;
2418 objdata.ProfileCurve = 1;
2419 objdata.PathScaleX = 100;
2420 objdata.PathScaleY = 100;
2421 objdata.ParentID = 0;
2422 objdata.OwnerID = LLUUID.Zero;
2423 objdata.Scale = new LLVector3(1, 1, 1);
2424 objdata.PCode = (byte)PCode.Avatar;
2425 if (textureEntry != null)
2426 {
2427 objdata.TextureEntry = textureEntry;
2428 }
2429 LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
2430 pos.X = 100f;
2431 objdata.ID = 8880000;
2432 objdata.NameValue = Helpers.StringToField("FirstName STRING RW SV Test \nLastName STRING RW SV User ");
2433 //LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
2434 //objdata.FullID=user.AgentId;
2435 byte[] pb = pos.GetBytes();
2436 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
2437
2438 return objdata;
2439 }
2440
2441 /// <summary>
2442 ///
2443 /// </summary>
2444 /// <param name="objdata"></param>
2445 protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
2446 {
2447 objdata.PSBlock = new byte[0];
2448 objdata.ExtraParams = new byte[1];
2449 objdata.MediaURL = new byte[0];
2450 objdata.NameValue = new byte[0];
2451 objdata.Text = new byte[0];
2452 objdata.TextColor = new byte[4];
2453 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
2454 objdata.JointPivot = new LLVector3(0, 0, 0);
2455 objdata.Material = 4;
2456 objdata.TextureAnim = new byte[0];
2457 objdata.Sound = LLUUID.Zero;
2458 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
2459 objdata.TextureEntry = ntex.ToBytes();
2460
2461 objdata.State = 0;
2462 objdata.Data = new byte[0];
2463
2464 objdata.ObjectData = new byte[76];
2465 objdata.ObjectData[15] = 128;
2466 objdata.ObjectData[16] = 63;
2467 objdata.ObjectData[56] = 128;
2468 objdata.ObjectData[61] = 102;
2469 objdata.ObjectData[62] = 40;
2470 objdata.ObjectData[63] = 61;
2471 objdata.ObjectData[64] = 189;
2472 }
2473
2474 public void SendNameReply(LLUUID profileId, string firstname, string lastname)
2475 {
2476 UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
2477 // TODO: don't create new blocks if recycling an old packet
2478 packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
2479 packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
2480 packet.UUIDNameBlock[0].ID = profileId;
2481 packet.UUIDNameBlock[0].FirstName = Helpers.StringToField(firstname);
2482 packet.UUIDNameBlock[0].LastName = Helpers.StringToField(lastname);
2483
2484 OutPacket(packet, ThrottleOutPacketType.Task);
2485 }
2486
2487 #endregion
2488
2489 protected virtual void RegisterLocalPacketHandlers()
2490 {
2491 AddLocalPacketHandler(PacketType.LogoutRequest, Logout);
2492 AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect);
2493 AddLocalPacketHandler(PacketType.AgentCachedTexture, AgentTextureCached);
2494 AddLocalPacketHandler(PacketType.MultipleObjectUpdate, MultipleObjUpdate);
2495 AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest);
2496 AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest);
2497 }
2498
2499 private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
2500 {
2501 MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
2502 // validate the agent owns the agentID and sessionID
2503 if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId && money.AgentData.SessionID == sender.SessionId)
2504 {
2505 handlerMoneyTransferRequest = OnMoneyTransferRequest;
2506 if (handlerMoneyTransferRequest != null)
2507 {
2508 handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
2509 money.MoneyData.Amount, money.MoneyData.TransactionType,
2510 Util.FieldToString(money.MoneyData.Description));
2511 }
2512
2513 return true;
2514 }
2515 else
2516 {
2517 return false;
2518 }
2519 }
2520
2521 private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
2522 {
2523 ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
2524 if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == this.SessionId)
2525 {
2526 handlerParcelBuy = OnParcelBuy;
2527 if (handlerParcelBuy != null)
2528 {
2529 handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final, parcel.Data.IsGroupOwned,
2530 parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area, parcel.ParcelData.Price,
2531 false);
2532 }
2533 return true;
2534
2535 }
2536 else
2537 {
2538 return false;
2539 }
2540
2541 }
2542
2543 private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
2544 {
2545 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
2546 handlerViewerEffect = OnViewerEffect;
2547 if (handlerViewerEffect != null)
2548 {
2549 handlerViewerEffect(sender, viewer.Effect);
2550 }
2551
2552 return true;
2553 }
2554
2555 public void SendScriptQuestion(LLUUID taskID, string taskName, string ownerName, LLUUID itemID, int question)
2556 {
2557 ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
2558 scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
2559 // TODO: don't create new blocks if recycling an old packet
2560 scriptQuestion.Data.TaskID = taskID;
2561 scriptQuestion.Data.ItemID = itemID;
2562 scriptQuestion.Data.Questions = question;
2563 scriptQuestion.Data.ObjectName = Helpers.StringToField(taskName);
2564 scriptQuestion.Data.ObjectOwner = Helpers.StringToField(ownerName);
2565
2566 OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
2567 }
2568
2569 protected virtual bool Logout(IClientAPI client, Packet packet)
2570 {
2571 m_log.Info("[CLIENT]: Got a logout request");
2572
2573 handlerLogout = OnLogout;
2574
2575 if (handlerLogout != null)
2576 {
2577 handlerLogout(client);
2578 }
2579
2580 return true;
2581 }
2582
2583 /// <summary>
2584 /// Send a response back to a client when it asks the asset server (via the region server) if it has
2585 /// its appearance texture cached.
2586 ///
2587 /// At the moment, we always reply that there is no cached texture.
2588 /// </summary>
2589 /// <param name="simclient"></param>
2590 /// <param name="packet"></param>
2591 /// <returns></returns>
2592 protected bool AgentTextureCached(IClientAPI simclient, Packet packet)
2593 {
2594 //Console.WriteLine("texture cached: " + packet.ToString());
2595 AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
2596 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
2597 // TODO: don't create new blocks if recycling an old packet
2598 cachedresp.AgentData.AgentID = AgentId;
2599 cachedresp.AgentData.SessionID = m_sessionId;
2600 cachedresp.AgentData.SerialNum = m_cachedTextureSerial;
2601 m_cachedTextureSerial++;
2602 cachedresp.WearableData =
2603 new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
2604
2605 for (int i = 0; i < cachedtex.WearableData.Length; i++)
2606 {
2607 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
2608 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
2609 cachedresp.WearableData[i].TextureID = LLUUID.Zero;
2610 cachedresp.WearableData[i].HostName = new byte[0];
2611 }
2612
2613 // Temporarily throw these packets on to the wind queue, so we can identify whether these
2614 // are somehow the source of the packet bloat.
2615 OutPacket(cachedresp, ThrottleOutPacketType.Wind);
2616 return true;
2617 }
2618
2619 protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet)
2620 {
2621 MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
2622 // Console.WriteLine("new multi update packet " + multipleupdate.ToString());
2623 Scene tScene = (Scene)m_scene;
2624
2625 for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
2626 {
2627 MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
2628
2629 // Can't act on Null Data
2630 if (block.Data != null)
2631 {
2632 uint localId = block.ObjectLocalID;
2633 SceneObjectPart part = tScene.GetSceneObjectPart(localId);
2634
2635 if (part == null)
2636 {
2637 // It's a ghost! tell the client to delete it from view.
2638 simClient.SendKillObject(Scene.RegionInfo.RegionHandle,
2639 localId);
2640 }
2641 else
2642 {
2643 LLUUID partId = part.UUID;
2644 UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
2645 UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
2646
2647 switch (block.Type)
2648 {
2649 case 1:
2650 LLVector3 pos1 = new LLVector3(block.Data, 0);
2651
2652 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
2653 if (handlerUpdatePrimSinglePosition != null)
2654 {
2655
2656 // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
2657 handlerUpdatePrimSinglePosition(localId, pos1, this);
2658 }
2659 break;
2660 case 2:
2661 LLQuaternion rot1 = new LLQuaternion(block.Data, 0, true);
2662
2663 handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
2664 if (handlerUpdatePrimSingleRotation != null)
2665 {
2666
2667 //Console.WriteLine("new tab rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2668 handlerUpdatePrimSingleRotation(localId, rot1, this);
2669 }
2670 break;
2671 case 3:
2672
2673 LLQuaternion rot2 = new LLQuaternion(block.Data, 12, true);
2674 handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
2675 if (handlerUpdatePrimSingleRotation != null)
2676 {
2677
2678 //Console.WriteLine("new mouse rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2679 handlerUpdatePrimSingleRotation(localId, rot2, this);
2680 }
2681 break;
2682 case 5:
2683
2684 LLVector3 scale1 = new LLVector3(block.Data, 12);
2685 LLVector3 pos11 = new LLVector3(block.Data, 0);
2686
2687 handlerUpdatePrimScale = OnUpdatePrimScale;
2688 if (handlerUpdatePrimScale != null)
2689 {
2690
2691 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
2692 handlerUpdatePrimScale(localId, scale1, this);
2693
2694
2695 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
2696 if (handlerUpdatePrimSinglePosition != null)
2697 {
2698 handlerUpdatePrimSinglePosition(localId, pos11, this);
2699 }
2700 }
2701 break;
2702 case 9:
2703 LLVector3 pos2 = new LLVector3(block.Data, 0);
2704
2705 handlerUpdateVector = OnUpdatePrimGroupPosition;
2706
2707 if (handlerUpdateVector != null)
2708 {
2709
2710 handlerUpdateVector(localId, pos2, this);
2711 }
2712 break;
2713 case 10:
2714
2715 LLQuaternion rot3 = new LLQuaternion(block.Data, 0, true);
2716
2717 handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
2718 if (handlerUpdatePrimRotation != null)
2719 {
2720
2721 // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2722 handlerUpdatePrimRotation(localId, rot3, this);
2723 }
2724 break;
2725 case 11:
2726
2727 LLVector3 pos3 = new LLVector3(block.Data, 0);
2728 LLQuaternion rot4 = new LLQuaternion(block.Data, 12, true);
2729
2730 handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
2731 if (handlerUpdatePrimGroupRotation != null)
2732 {
2733
2734 //Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
2735 // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2736 handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
2737 }
2738 break;
2739 case 13:
2740
2741 LLVector3 scale2 = new LLVector3(block.Data, 12);
2742 LLVector3 pos4 = new LLVector3(block.Data, 0);
2743
2744 handlerUpdatePrimScale = OnUpdatePrimScale;
2745 if (handlerUpdatePrimScale != null)
2746 {
2747
2748 //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
2749 handlerUpdatePrimScale(localId, scale2, this);
2750
2751 // Change the position based on scale (for bug number 246)
2752 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
2753 // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
2754 if (handlerUpdatePrimSinglePosition != null)
2755 {
2756 handlerUpdatePrimSinglePosition(localId, pos4, this);
2757 }
2758 }
2759 break;
2760 case 29:
2761 LLVector3 scale5 = new LLVector3(block.Data, 12);
2762 LLVector3 pos5 = new LLVector3(block.Data, 0);
2763
2764 handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
2765 if (handlerUpdatePrimGroupScale != null)
2766 {
2767
2768 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z );
2769 handlerUpdatePrimGroupScale(localId, scale5, this);
2770 handlerUpdateVector = OnUpdatePrimGroupPosition;
2771
2772 if (handlerUpdateVector != null)
2773 {
2774
2775 handlerUpdateVector(localId, pos5, this);
2776 }
2777 }
2778 break;
2779 case 21:
2780 LLVector3 scale6 = new LLVector3(block.Data, 12);
2781 LLVector3 pos6 = new LLVector3(block.Data, 0);
2782
2783 handlerUpdatePrimScale = OnUpdatePrimScale;
2784 if (handlerUpdatePrimScale != null)
2785 {
2786 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
2787 handlerUpdatePrimScale(localId, scale6, this);
2788 handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
2789 if (handlerUpdatePrimSinglePosition != null)
2790 {
2791 handlerUpdatePrimSinglePosition(localId, pos6, this);
2792 }
2793 }
2794 break;
2795 }
2796 }
2797 }
2798 }
2799 return true;
2800 }
2801
2802 public void RequestMapLayer()
2803 {
2804 //should be getting the map layer from the grid server
2805 //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
2806 MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
2807 // TODO: don't create new blocks if recycling an old packet
2808 mapReply.AgentData.AgentID = AgentId;
2809 mapReply.AgentData.Flags = 0;
2810 mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
2811 mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
2812 mapReply.LayerData[0].Bottom = 0;
2813 mapReply.LayerData[0].Left = 0;
2814 mapReply.LayerData[0].Top = 30000;
2815 mapReply.LayerData[0].Right = 30000;
2816 mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-1111-9999-000000000006");
2817 OutPacket(mapReply, ThrottleOutPacketType.Land);
2818 }
2819
2820 public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
2821 {
2822 /*
2823 IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
2824 MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
2825 mbReply.AgentData.AgentId = this.AgentId;
2826 int len;
2827 if (simMapProfiles == null)
2828 len = 0;
2829 else
2830 len = simMapProfiles.Count;
2831
2832 mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
2833 int iii;
2834 for (iii = 0; iii < len; iii++)
2835 {
2836 Hashtable mp = (Hashtable)simMapProfiles[iii];
2837 mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
2838 mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
2839 mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
2840 mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
2841 mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
2842 mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
2843 mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
2844 mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
2845 mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
2846 }
2847 this.OutPacket(mbReply, ThrottleOutPacketType.Land);
2848 */
2849 }
2850
2851 public byte[] GetThrottlesPacked(float multiplier)
2852 {
2853 return m_packetQueue.GetThrottlesPacked(multiplier);
2854 }
2855
2856 public void SetChildAgentThrottle(byte[] throttles)
2857 {
2858 m_packetQueue.SetThrottleFromClient(throttles);
2859 }
2860
2861 // Previously ClientView.m_packetQueue
2862
2863 // A thread safe sequence number allocator.
2864 protected uint NextSeqNum()
2865 {
2866 // Set the sequence number
2867 uint seq = 1;
2868 lock (m_sequenceLock)
2869 {
2870 if (m_sequence >= MAX_SEQUENCE)
2871 {
2872 m_sequence = 1;
2873 }
2874 else
2875 {
2876 m_sequence++;
2877 }
2878 seq = m_sequence;
2879 }
2880 return seq;
2881 }
2882
2883 protected void AddAck(Packet Pack)
2884 {
2885 lock (m_needAck)
2886 {
2887 if (!m_needAck.ContainsKey(Pack.Header.Sequence))
2888 {
2889 try
2890 {
2891 m_needAck.Add(Pack.Header.Sequence, Pack);
2892 m_unAckedBytes += Pack.ToBytes().Length;
2893 }
2894 catch (Exception) // HACKY
2895 {
2896 // Ignore
2897 // Seems to throw a exception here occasionally
2898 // of 'duplicate key' despite being locked.
2899 // !?!?!?
2900 }
2901 }
2902 else
2903 {
2904 // Client.Log("Attempted to add a duplicate sequence number (" +
2905 // packet.Header.m_sequence + ") to the m_needAck dictionary for packet type " +
2906 // packet.Type.ToString(), Helpers.LogLevel.Warning);
2907 }
2908 }
2909 }
2910
2911 protected virtual void SetPendingAcks(ref Packet Pack)
2912 {
2913 // Append any ACKs that need to be sent out to this packet
2914 lock (m_pendingAcks)
2915 {
2916 // TODO: If we are over MAX_APPENDED_ACKS we should drain off some of these
2917 if (m_pendingAcks.Count > 0 && m_pendingAcks.Count < MAX_APPENDED_ACKS)
2918 {
2919 Pack.Header.AckList = new uint[m_pendingAcks.Count];
2920 int i = 0;
2921
2922 foreach (uint ack in m_pendingAcks.Values)
2923 {
2924 Pack.Header.AckList[i] = ack;
2925 i++;
2926 }
2927
2928 m_pendingAcks.Clear();
2929 Pack.Header.AppendedAcks = true;
2930 }
2931 }
2932 }
2933
2934 protected virtual void ProcessOutPacket(Packet Pack)
2935 {
2936 // Keep track of when this packet was sent out
2937 Pack.TickCount = System.Environment.TickCount;
2938
2939 if (!Pack.Header.Resent)
2940 {
2941 Pack.Header.Sequence = NextSeqNum();
2942
2943 if (Pack.Header.Reliable) //DIRTY HACK
2944 {
2945 AddAck(Pack); // this adds the need to ack this packet later
2946
2947 if (Pack.Type != PacketType.PacketAck && Pack.Type != PacketType.LogoutRequest)
2948 {
2949 SetPendingAcks(ref Pack);
2950 }
2951 }
2952 }
2953
2954 // Actually make the byte array and send it
2955 try
2956 {
2957 byte[] sendbuffer = Pack.ToBytes();
2958 PacketPool.Instance.ReturnPacket(Pack);
2959
2960 if (Pack.Header.Zerocoded)
2961 {
2962 int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
2963 m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
2964 }
2965 else
2966 {
2967 //Need some extra space in case we need to add proxy information to the message later
2968 Buffer.BlockCopy(sendbuffer, 0, ZeroOutBuffer, 0, sendbuffer.Length);
2969 m_networkServer.SendPacketTo(ZeroOutBuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
2970 }
2971 }
2972 catch (Exception e)
2973 {
2974 m_log.Warn("[client]: " +
2975 "ClientView.m_packetQueue.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " +
2976 m_userEndPoint.ToString() + " - killing thread");
2977 m_log.Error(e.ToString());
2978 Close(true);
2979 }
2980 }
2981
2982 public virtual void InPacket(Packet NewPack)
2983 {
2984 if (!m_packetProcessingEnabled && NewPack.Type != PacketType.LogoutRequest)
2985 {
2986 PacketPool.Instance.ReturnPacket(NewPack);
2987 return;
2988 }
2989
2990 // Handle appended ACKs
2991 if (NewPack != null)
2992 {
2993 if (NewPack.Header.AppendedAcks)
2994 {
2995 lock (m_needAck)
2996 {
2997 foreach (uint ackedPacketId in NewPack.Header.AckList)
2998 {
2999 Packet ackedPacket;
3000
3001 if (m_needAck.TryGetValue(ackedPacketId, out ackedPacket))
3002 {
3003 m_unAckedBytes -= ackedPacket.ToBytes().Length;
3004 m_needAck.Remove(ackedPacketId);
3005 }
3006 }
3007 }
3008 }
3009
3010 // Handle PacketAck packets
3011 if (NewPack.Type == PacketType.PacketAck)
3012 {
3013 PacketAckPacket ackPacket = (PacketAckPacket)NewPack;
3014
3015 lock (m_needAck)
3016 {
3017 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
3018 {
3019 uint ackedPackId = block.ID;
3020 Packet ackedPacket;
3021 if (m_needAck.TryGetValue(ackedPackId, out ackedPacket))
3022 {
3023 m_unAckedBytes -= ackedPacket.ToBytes().Length;
3024 m_needAck.Remove(ackedPackId);
3025 }
3026 }
3027 }
3028 }
3029 else if ((NewPack.Type == PacketType.StartPingCheck))
3030 {
3031 //reply to pingcheck
3032 StartPingCheckPacket startPing = (StartPingCheckPacket)NewPack;
3033 CompletePingCheckPacket endPing = (CompletePingCheckPacket)PacketPool.Instance.GetPacket(PacketType.CompletePingCheck);
3034 endPing.PingID.PingID = startPing.PingID.PingID;
3035 OutPacket(endPing, ThrottleOutPacketType.Task);
3036 }
3037 else
3038 {
3039 QueItem item = new QueItem();
3040 item.Packet = NewPack;
3041 item.Incoming = true;
3042 m_packetQueue.Enqueue(item);
3043 }
3044 }
3045 }
3046
3047 public virtual void OutPacket(Packet NewPack, ThrottleOutPacketType throttlePacketType)
3048 {
3049 if ((SynchronizeClient != null) && (!PacketProcessingEnabled))
3050 {
3051 // Sending packet to active client's server.
3052 if (SynchronizeClient(m_scene, NewPack, m_agentId, throttlePacketType))
3053 {
3054 return;
3055 }
3056 }
3057
3058 QueItem item = new QueItem();
3059 item.Packet = NewPack;
3060 item.Incoming = false;
3061 item.throttleType = throttlePacketType; // Packet throttle type
3062 m_packetQueue.Enqueue(item);
3063 m_packetsSent++;
3064 }
3065
3066 # region Low Level Packet Methods
3067
3068 protected void ack_pack(Packet Pack)
3069 {
3070 if (Pack.Header.Reliable)
3071 {
3072 PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
3073 // TODO: don't create new blocks if recycling an old packet
3074 ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
3075 ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
3076 ack_it.Packets[0].ID = Pack.Header.Sequence;
3077 ack_it.Header.Reliable = false;
3078
3079 OutPacket(ack_it, ThrottleOutPacketType.Unknown);
3080 }
3081 /*
3082 if (Pack.Header.Reliable)
3083 {
3084 lock (m_pendingAcks)
3085 {
3086 uint sequence = (uint)Pack.Header.m_sequence;
3087 if (!m_pendingAcks.ContainsKey(sequence)) { m_pendingAcks[sequence] = sequence; }
3088 }
3089 }*/
3090 }
3091
3092 protected void ResendUnacked()
3093 {
3094 int now = System.Environment.TickCount;
3095
3096 lock (m_needAck)
3097 {
3098 foreach (Packet packet in m_needAck.Values)
3099 {
3100 if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
3101 {
3102 //m_log.Debug("[NETWORK]: Resending " + packet.Type.ToString() + " packet, " +
3103 //(now - packet.TickCount) + "ms have passed");
3104
3105 packet.Header.Resent = true;
3106 OutPacket(packet, ThrottleOutPacketType.Resend);
3107 }
3108 }
3109 }
3110 }
3111
3112 protected void SendAcks()
3113 {
3114 lock (m_pendingAcks)
3115 {
3116 if (m_pendingAcks.Count > 0)
3117 {
3118 if (m_pendingAcks.Count > 250)
3119 {
3120 // FIXME: Handle the odd case where we have too many pending ACKs queued up
3121 m_log.Info("[NETWORK]: Too many ACKs queued up!");
3122 return;
3123 }
3124
3125 //m_log.Info("[NETWORK]: Sending PacketAck");
3126
3127 int i = 0;
3128 PacketAckPacket acks = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
3129 // TODO: don't create new blocks if recycling an old packet
3130 acks.Packets = new PacketAckPacket.PacketsBlock[m_pendingAcks.Count];
3131
3132 foreach (uint ack in m_pendingAcks.Values)
3133 {
3134 acks.Packets[i] = new PacketAckPacket.PacketsBlock();
3135 acks.Packets[i].ID = ack;
3136 i++;
3137 }
3138
3139 acks.Header.Reliable = false;
3140 OutPacket(acks, ThrottleOutPacketType.Unknown);
3141
3142 m_pendingAcks.Clear();
3143 }
3144 }
3145 }
3146
3147 protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
3148 {
3149
3150 SendAcks();
3151 ResendUnacked();
3152 SendPacketStats();
3153
3154 }
3155
3156 protected void SendPacketStats()
3157 {
3158 handlerPacketStats = OnPacketStats;
3159 if (handlerPacketStats != null)
3160 {
3161 handlerPacketStats(m_packetsReceived - m_lastPacketsReceivedSentToScene, m_packetsSent - m_lastPacketsSentSentToScene, m_unAckedBytes);
3162 m_lastPacketsReceivedSentToScene = m_packetsReceived;
3163 m_lastPacketsSentSentToScene = m_packetsSent;
3164 }
3165 }
3166
3167 #endregion
3168
3169 // Previously ClientView.ProcessPackets
3170
3171 public bool AddMoney(int debit)
3172 {
3173 if (m_moneyBalance + debit >= 0)
3174 {
3175 m_moneyBalance += debit;
3176 SendMoneyBalance(LLUUID.Zero, true, Helpers.StringToField("Poof Poof!"), m_moneyBalance);
3177 return true;
3178 }
3179 else
3180 {
3181 return false;
3182 }
3183 }
3184
3185 private bool m_packetProcessingEnabled = true;
3186
3187 public bool PacketProcessingEnabled {
3188 get { return m_packetProcessingEnabled; }
3189 set { m_packetProcessingEnabled = value; }
3190 }
3191
3192 protected void ProcessInPacket(Packet Pack)
3193 {
3194 ack_pack(Pack);
3195
3196 if (ProcessPacketMethod(Pack))
3197 {
3198 //there is a handler registered that handled this packet type
3199 return;
3200 }
3201 else
3202 {
3203 switch (Pack.Type)
3204 {
3205 #region Scene/Avatar
3206
3207 case PacketType.AvatarPropertiesRequest:
3208 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
3209
3210 handlerRequestAvatarProperties = OnRequestAvatarProperties;
3211 if (handlerRequestAvatarProperties != null)
3212 {
3213 handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
3214 }
3215
3216 break;
3217 case PacketType.ChatFromViewer:
3218 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
3219
3220 string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
3221 byte[] message = inchatpack.ChatData.Message;
3222 byte type = inchatpack.ChatData.Type;
3223 LLVector3 fromPos = new LLVector3(); // ClientAvatar.Pos;
3224 LLUUID fromAgentID = AgentId;
3225
3226 int channel = inchatpack.ChatData.Channel;
3227
3228 if (OnChatFromViewer != null)
3229 {
3230 ChatFromViewerArgs args = new ChatFromViewerArgs();
3231 args.Channel = channel;
3232 args.From = fromName;
3233 args.Message = Helpers.FieldToUTF8String(message);
3234 args.Type = (ChatTypeEnum)type;
3235 args.Position = fromPos;
3236
3237 args.Scene = Scene;
3238 args.Sender = this;
3239
3240 handlerChatFromViewer = OnChatFromViewer;
3241 if (handlerChatFromViewer != null)
3242 handlerChatFromViewer(this, args);
3243 }
3244 break;
3245 case PacketType.AvatarPropertiesUpdate:
3246 AvatarPropertiesUpdatePacket Packet = (AvatarPropertiesUpdatePacket)Pack;
3247
3248 handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
3249 if (handlerUpdateAvatarProperties != null)
3250 {
3251 AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = Packet.PropertiesData;
3252 UserProfileData UserProfile = new UserProfileData();
3253 UserProfile.ID = AgentId;
3254 UserProfile.AboutText = Helpers.FieldToUTF8String(Properties.AboutText);
3255 UserProfile.FirstLifeAboutText = Helpers.FieldToUTF8String(Properties.FLAboutText);
3256 UserProfile.FirstLifeImage = Properties.FLImageID;
3257 UserProfile.Image = Properties.ImageID;
3258
3259 handlerUpdateAvatarProperties(this, UserProfile);
3260 }
3261 break;
3262
3263 case PacketType.ScriptDialogReply:
3264 ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
3265 int ch = rdialog.Data.ChatChannel;
3266 byte[] msg = rdialog.Data.ButtonLabel;
3267 if (OnChatFromViewer != null)
3268 {
3269 ChatFromViewerArgs args = new ChatFromViewerArgs();
3270 args.Channel = ch;
3271 args.From = String.Empty;
3272 args.Message = Helpers.FieldToUTF8String(msg);
3273 args.Type = ChatTypeEnum.Shout;
3274 args.Position = new LLVector3();
3275 args.Scene = Scene;
3276 args.Sender = this;
3277 handlerChatFromViewer2 = OnChatFromViewer;
3278 if (handlerChatFromViewer2 != null)
3279 handlerChatFromViewer2(this, args);
3280 }
3281
3282 break;
3283 case PacketType.ImprovedInstantMessage:
3284 ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
3285 string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
3286 string IMmessage = Helpers.FieldToUTF8String(msgpack.MessageBlock.Message);
3287 handlerInstantMessage = OnInstantMessage;
3288
3289 if (handlerInstantMessage != null)
3290 {
3291 handlerInstantMessage(this, msgpack.AgentData.AgentID, msgpack.AgentData.SessionID,
3292 msgpack.MessageBlock.ToAgentID, msgpack.MessageBlock.ID,
3293 msgpack.MessageBlock.Timestamp, IMfromName, IMmessage,
3294 msgpack.MessageBlock.Dialog, msgpack.MessageBlock.FromGroup,
3295 msgpack.MessageBlock.Offline, msgpack.MessageBlock.ParentEstateID,
3296 msgpack.MessageBlock.Position, msgpack.MessageBlock.RegionID,
3297 msgpack.MessageBlock.BinaryBucket);
3298 }
3299 break;
3300
3301 case PacketType.AcceptFriendship:
3302 AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
3303
3304 // My guess is this is the folder to stick the calling card into
3305 List<LLUUID> callingCardFolders = new List<LLUUID>();
3306
3307 LLUUID agentID = afriendpack.AgentData.AgentID;
3308 LLUUID transactionID = afriendpack.TransactionBlock.TransactionID;
3309
3310 for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
3311 {
3312 callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
3313 }
3314
3315 handlerApproveFriendRequest = OnApproveFriendRequest;
3316 if (handlerApproveFriendRequest != null)
3317 {
3318 handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders);
3319 }
3320 break;
3321 case PacketType.TerminateFriendship:
3322 TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
3323 LLUUID listOwnerAgentID = tfriendpack.AgentData.AgentID;
3324 LLUUID exFriendID = tfriendpack.ExBlock.OtherID;
3325
3326 handlerTerminateFriendship = OnTerminateFriendship;
3327 if (handlerTerminateFriendship != null)
3328 {
3329 handlerTerminateFriendship(this, listOwnerAgentID, exFriendID);
3330 }
3331 break;
3332 case PacketType.RezObject:
3333 RezObjectPacket rezPacket = (RezObjectPacket)Pack;
3334
3335 handlerRezObject = OnRezObject;
3336 if (handlerRezObject != null)
3337 {
3338 //rezPacket.RezData.BypassRaycast;
3339 //rezPacket.RezData.RayEnd;
3340 //rezPacket.RezData.RayEndIsIntersection;
3341 //rezPacket.RezData.RayStart;
3342 //rezPacket.RezData.RayTargetID;
3343 //rezPacket.RezData.RemoveItem;
3344 //rezPacket.RezData.RezSelected;
3345 //rezPacket.RezData.FromTaskID;
3346 //m_log.Info("[REZData]: " + rezPacket.ToString());
3347
3348 handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
3349 rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
3350 rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
3351 rezPacket.RezData.EveryoneMask, rezPacket.RezData.GroupMask,
3352 rezPacket.RezData.NextOwnerMask, rezPacket.RezData.ItemFlags,
3353 rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
3354 rezPacket.RezData.FromTaskID);
3355 }
3356 break;
3357 case PacketType.DeRezObject:
3358 handlerDeRezObject = OnDeRezObject;
3359 if (handlerDeRezObject != null)
3360 {
3361 handlerDeRezObject(Pack, this);
3362 }
3363 break;
3364 case PacketType.ModifyLand:
3365 ModifyLandPacket modify = (ModifyLandPacket)Pack;
3366 //m_log.Info("[LAND]: LAND:" + modify.ToString());
3367 if (modify.ParcelData.Length > 0)
3368 {
3369 if (OnModifyTerrain != null)
3370 {
3371 for (int i = 0; i < modify.ParcelData.Length; i++)
3372 {
3373 handlerModifyTerrain = OnModifyTerrain;
3374 if (handlerModifyTerrain != null)
3375 {
3376 handlerModifyTerrain(modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
3377 modify.ModifyBlock.BrushSize,
3378 modify.ModifyBlock.Action, modify.ParcelData[i].North,
3379 modify.ParcelData[i].West, modify.ParcelData[i].South,
3380 modify.ParcelData[i].East, this);
3381 }
3382 }
3383 }
3384 }
3385
3386 break;
3387 case PacketType.RegionHandshakeReply:
3388
3389 handlerRegionHandShakeReply = OnRegionHandShakeReply;
3390 if (handlerRegionHandShakeReply != null)
3391 {
3392 handlerRegionHandShakeReply(this);
3393 }
3394
3395 break;
3396 case PacketType.AgentWearablesRequest:
3397 handlerRequestWearables = OnRequestWearables;
3398
3399 if (handlerRequestWearables != null)
3400 {
3401 handlerRequestWearables();
3402 }
3403
3404 handlerRequestAvatarsData = OnRequestAvatarsData;
3405
3406 if (handlerRequestAvatarsData != null)
3407 {
3408 handlerRequestAvatarsData(this);
3409 }
3410
3411 break;
3412 case PacketType.AgentSetAppearance:
3413 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
3414
3415 handlerSetAppearance = OnSetAppearance;
3416 if (handlerSetAppearance != null)
3417 {
3418 // Temporarily protect ourselves from the mantis #951 failure.
3419 // However, we could do this for several other handlers where a failure isn't terminal
3420 // for the client session anyway, in order to protect ourselves against bad code in plugins
3421 try
3422 {
3423 handlerSetAppearance(appear.ObjectData.TextureEntry, appear.VisualParam);
3424 }
3425 catch (Exception e)
3426 {
3427 m_log.ErrorFormat(
3428 "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
3429 e);
3430 }
3431 }
3432
3433 break;
3434 case PacketType.AgentIsNowWearing:
3435 if (OnAvatarNowWearing != null)
3436 {
3437 AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
3438 AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
3439 for (int i = 0; i < nowWearing.WearableData.Length; i++)
3440 {
3441 AvatarWearingArgs.Wearable wearable =
3442 new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
3443 nowWearing.WearableData[i].WearableType);
3444 wearingArgs.NowWearing.Add(wearable);
3445 }
3446
3447 handlerAvatarNowWearing = OnAvatarNowWearing;
3448 if (handlerAvatarNowWearing != null)
3449 {
3450 handlerAvatarNowWearing(this, wearingArgs);
3451 }
3452 }
3453 break;
3454 case PacketType.RezSingleAttachmentFromInv:
3455 handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
3456 if (handlerRezSingleAttachment != null)
3457 {
3458 RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
3459 handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
3460 rez.ObjectData.AttachmentPt, rez.ObjectData.ItemFlags, rez.ObjectData.NextOwnerMask);
3461 }
3462
3463 break;
3464 case PacketType.DetachAttachmentIntoInv:
3465 handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
3466 if (handlerDetachAttachmentIntoInv != null)
3467 {
3468 DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
3469
3470 LLUUID itemID = detachtoInv.ObjectData.ItemID;
3471 LLUUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
3472
3473 handlerDetachAttachmentIntoInv(itemID, this);
3474 }
3475 break;
3476 case PacketType.ObjectAttach:
3477 if (OnObjectAttach != null)
3478 {
3479 ObjectAttachPacket att = (ObjectAttachPacket)Pack;
3480
3481 handlerObjectAttach = OnObjectAttach;
3482
3483 if (handlerObjectAttach != null)
3484 {
3485 if (att.ObjectData.Length > 0)
3486 {
3487 handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation);
3488 }
3489 }
3490 }
3491
3492 break;
3493 case PacketType.ObjectDetach:
3494
3495 ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
3496 for (int j = 0; j < dett.ObjectData.Length; j++)
3497 {
3498 uint obj = dett.ObjectData[j].ObjectLocalID;
3499 handlerObjectDetach = OnObjectDetach;
3500 if (handlerObjectDetach != null)
3501 {
3502 handlerObjectDetach(obj,this);
3503 }
3504
3505 }
3506
3507 break;
3508 case PacketType.SetAlwaysRun:
3509 SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
3510
3511 handlerSetAlwaysRun = OnSetAlwaysRun;
3512 if (handlerSetAlwaysRun != null)
3513 handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
3514
3515 break;
3516 case PacketType.CompleteAgentMovement:
3517 handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
3518 if (handlerCompleteMovementToRegion != null)
3519 {
3520 handlerCompleteMovementToRegion();
3521 }
3522 handlerCompleteMovementToRegion = null;
3523
3524 break;
3525 case PacketType.AgentUpdate:
3526 if (OnAgentUpdate != null)
3527 {
3528 AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack;
3529
3530 handlerAgentUpdate = OnAgentUpdate;
3531 if (handlerAgentUpdate != null)
3532 OnAgentUpdate(this, agenUpdate);
3533
3534 handlerAgentUpdate = null;
3535 //agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotationa);
3536 }
3537 break;
3538 case PacketType.AgentAnimation:
3539 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
3540
3541 handlerStartAnim = null;
3542 handlerStopAnim = null;
3543
3544 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
3545 {
3546 if (AgentAni.AnimationList[i].StartAnim)
3547 {
3548 handlerStartAnim = OnStartAnim;
3549 if (handlerStartAnim != null)
3550 {
3551 handlerStartAnim(this, AgentAni.AnimationList[i].AnimID);
3552 }
3553 }
3554 else
3555 {
3556 handlerStopAnim = OnStopAnim;
3557 if (handlerStopAnim != null)
3558 {
3559 handlerStopAnim(this, AgentAni.AnimationList[i].AnimID);
3560 }
3561 }
3562 }
3563 break;
3564 case PacketType.AgentRequestSit:
3565 if (OnAgentRequestSit != null)
3566 {
3567 AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
3568
3569 handlerAgentRequestSit = OnAgentRequestSit;
3570 if (handlerAgentRequestSit != null)
3571 handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
3572 agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
3573 }
3574 break;
3575 case PacketType.AgentSit:
3576 if (OnAgentSit != null)
3577 {
3578 AgentSitPacket agentSit = (AgentSitPacket)Pack;
3579
3580 handlerAgentSit = OnAgentSit;
3581 if (handlerAgentSit != null)
3582 {
3583 OnAgentSit(this, agentSit.AgentData.AgentID);
3584 }
3585 }
3586 break;
3587 case PacketType.AvatarPickerRequest:
3588 AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
3589 AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
3590 AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
3591 //Console.WriteLine("Agent Sends:" + Helpers.FieldToUTF8String(querydata.Name));
3592
3593 handlerAvatarPickerRequest = OnAvatarPickerRequest;
3594 if (handlerAvatarPickerRequest != null)
3595 {
3596 handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
3597 Helpers.FieldToUTF8String(querydata.Name));
3598 }
3599 break;
3600 case PacketType.AgentDataUpdateRequest:
3601 AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
3602
3603 handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
3604
3605 if (handlerAgentDataUpdateRequest != null)
3606 {
3607 handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
3608 }
3609
3610 break;
3611 case PacketType.UserInfoRequest:
3612 UserInfoRequestPacket avUserInfoRequestPacket = (UserInfoRequestPacket)Pack;
3613
3614 handlerUserInfoRequest = OnUserInfoRequest;
3615 if (handlerUserInfoRequest != null)
3616 {
3617 handlerUserInfoRequest(this, avUserInfoRequestPacket.AgentData.AgentID, avUserInfoRequestPacket.AgentData.SessionID);
3618 }
3619 break;
3620
3621 case PacketType.SetStartLocationRequest:
3622 SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
3623
3624 if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
3625 {
3626 handlerSetStartLocationRequest = OnSetStartLocationRequest;
3627 if (handlerSetStartLocationRequest != null)
3628 {
3629 handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
3630 avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
3631 avSetStartLocationRequestPacket.StartLocationData.LocationID);
3632 }
3633 }
3634 break;
3635
3636 case PacketType.AgentThrottle:
3637 AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
3638 m_packetQueue.SetThrottleFromClient(atpack.Throttle.Throttles);
3639 break;
3640
3641 case PacketType.AgentPause:
3642 m_probesWithNoIngressPackets = 0;
3643 m_clientBlocked = true;
3644 break;
3645
3646 case PacketType.AgentResume:
3647 m_probesWithNoIngressPackets = 0;
3648 m_clientBlocked = false;
3649 SendStartPingCheck(0);
3650
3651 break;
3652
3653 #endregion
3654
3655 #region Objects/m_sceneObjects
3656
3657 case PacketType.ObjectLink:
3658 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
3659 uint parentprimid = 0;
3660 List<uint> childrenprims = new List<uint>();
3661 if (link.ObjectData.Length > 1)
3662 {
3663 parentprimid = link.ObjectData[0].ObjectLocalID;
3664
3665 for (int i = 1; i < link.ObjectData.Length; i++)
3666 {
3667 childrenprims.Add(link.ObjectData[i].ObjectLocalID);
3668 }
3669 }
3670 handlerLinkObjects = OnLinkObjects;
3671 if (handlerLinkObjects != null)
3672 {
3673 handlerLinkObjects(this, parentprimid, childrenprims);
3674 }
3675 break;
3676 case PacketType.ObjectDelink:
3677 ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
3678
3679 // It appears the prim at index 0 is not always the root prim (for
3680 // instance, when one prim of a link set has been edited independently
3681 // of the others). Therefore, we'll pass all the ids onto the delink
3682 // method for it to decide which is the root.
3683 List<uint> prims = new List<uint>();
3684 for (int i = 0; i < delink.ObjectData.Length; i++)
3685 {
3686 prims.Add(delink.ObjectData[i].ObjectLocalID);
3687 }
3688 handlerDelinkObjects = OnDelinkObjects;
3689 if (handlerDelinkObjects != null)
3690 {
3691 handlerDelinkObjects(prims);
3692 }
3693
3694 break;
3695 case PacketType.ObjectAdd:
3696 if (OnAddPrim != null)
3697 {
3698 ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
3699 PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
3700 // m_log.Info("[REZData]: " + addPacket.ToString());
3701 //BypassRaycast: 1
3702 //RayStart: <69.79469, 158.2652, 98.40343>
3703 //RayEnd: <61.97724, 141.995, 92.58341>
3704 //RayTargetID: 00000000-0000-0000-0000-000000000000
3705
3706 handlerAddPrim = OnAddPrim;
3707 if (handlerAddPrim != null)
3708 handlerAddPrim(AgentId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
3709 }
3710 break;
3711 case PacketType.ObjectShape:
3712 ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
3713 handlerUpdatePrimShape = null;
3714 for (int i = 0; i < shapePacket.ObjectData.Length; i++)
3715 {
3716 handlerUpdatePrimShape = OnUpdatePrimShape;
3717 if (handlerUpdatePrimShape != null)
3718 {
3719 handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
3720 shapePacket.ObjectData[i]);
3721 }
3722 }
3723 break;
3724 case PacketType.ObjectExtraParams:
3725 ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
3726
3727 handlerUpdateExtraParams = OnUpdateExtraParams;
3728 if (handlerUpdateExtraParams != null)
3729 {
3730 handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[0].ObjectLocalID,
3731 extraPar.ObjectData[0].ParamType,
3732 extraPar.ObjectData[0].ParamInUse, extraPar.ObjectData[0].ParamData);
3733 }
3734 break;
3735 case PacketType.ObjectDuplicate:
3736 ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
3737 ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
3738
3739 handlerObjectDuplicate = null;
3740
3741 for (int i = 0; i < dupe.ObjectData.Length; i++)
3742 {
3743 handlerObjectDuplicate = OnObjectDuplicate;
3744 if (handlerObjectDuplicate != null)
3745 {
3746 handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
3747 dupe.SharedData.DuplicateFlags, AgentandGroupData.AgentID,
3748 AgentandGroupData.GroupID);
3749 }
3750 }
3751
3752 break;
3753
3754 case PacketType.ObjectSelect:
3755 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
3756
3757 handlerObjectSelect = null;
3758
3759 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
3760 {
3761 handlerObjectSelect = OnObjectSelect;
3762 if (handlerObjectSelect != null)
3763 {
3764 handlerObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
3765 }
3766 }
3767 break;
3768 case PacketType.ObjectDeselect:
3769 ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
3770
3771 handlerObjectDeselect = null;
3772
3773 for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
3774 {
3775 handlerObjectDeselect = OnObjectDeselect;
3776 if (handlerObjectDeselect != null)
3777 {
3778 OnObjectDeselect(incomingdeselect.ObjectData[i].ObjectLocalID, this);
3779 }
3780 }
3781 break;
3782 case PacketType.ObjectFlagUpdate:
3783 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
3784
3785 handlerUpdatePrimFlags = OnUpdatePrimFlags;
3786
3787 if (handlerUpdatePrimFlags != null)
3788 {
3789 handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
3790 }
3791 break;
3792 case PacketType.ObjectImage:
3793 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
3794
3795 handlerUpdatePrimTexture = null;
3796 for (int i = 0; i < imagePack.ObjectData.Length; i++)
3797 {
3798 handlerUpdatePrimTexture = OnUpdatePrimTexture;
3799 if (handlerUpdatePrimTexture != null)
3800 {
3801 handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
3802 imagePack.ObjectData[i].TextureEntry, this);
3803 }
3804 }
3805 break;
3806 case PacketType.ObjectGrab:
3807 ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
3808
3809 handlerGrabObject = OnGrabObject;
3810
3811 if (handlerGrabObject != null)
3812 {
3813 handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this);
3814 }
3815 break;
3816 case PacketType.ObjectGrabUpdate:
3817 ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
3818
3819 handlerGrabUpdate = OnGrabUpdate;
3820
3821 if (handlerGrabUpdate != null)
3822 {
3823 handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
3824 grabUpdate.ObjectData.GrabPosition, this);
3825 }
3826 break;
3827 case PacketType.ObjectDeGrab:
3828 ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
3829
3830 handlerDeGrabObject = OnDeGrabObject;
3831 if (handlerDeGrabObject != null)
3832 {
3833 handlerDeGrabObject(deGrab.ObjectData.LocalID, this);
3834 }
3835 break;
3836 case PacketType.ObjectDescription:
3837 ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
3838
3839 handlerObjectDescription = null;
3840
3841 for (int i = 0; i < objDes.ObjectData.Length; i++)
3842 {
3843 handlerObjectDescription = OnObjectDescription;
3844 if (handlerObjectDescription != null)
3845 {
3846 handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
3847 Util.FieldToString(objDes.ObjectData[i].Description));
3848 }
3849 }
3850 break;
3851 case PacketType.ObjectName:
3852 ObjectNamePacket objName = (ObjectNamePacket)Pack;
3853
3854 handlerObjectName = null;
3855 for (int i = 0; i < objName.ObjectData.Length; i++)
3856 {
3857 handlerObjectName = OnObjectName;
3858 if (handlerObjectName != null)
3859 {
3860 handlerObjectName(this, objName.ObjectData[i].LocalID,
3861 Util.FieldToString(objName.ObjectData[i].Name));
3862 }
3863 }
3864 break;
3865 case PacketType.ObjectPermissions:
3866 if (OnObjectPermissions != null)
3867 {
3868 ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
3869
3870 LLUUID AgentID = newobjPerms.AgentData.AgentID;
3871 LLUUID SessionID = newobjPerms.AgentData.SessionID;
3872
3873 handlerObjectPermissions = null;
3874
3875 for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
3876 {
3877 ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
3878
3879 byte field = permChanges.Field;
3880 uint localID = permChanges.ObjectLocalID;
3881 uint mask = permChanges.Mask;
3882 byte set = permChanges.Set;
3883
3884 handlerObjectPermissions = OnObjectPermissions;
3885
3886 if (handlerObjectPermissions != null)
3887 OnObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
3888 }
3889 }
3890
3891 // Here's our data,
3892 // PermField contains the field the info goes into
3893 // PermField determines which mask we're changing
3894 //
3895 // chmask is the mask of the change
3896 // setTF is whether we're adding it or taking it away
3897 //
3898 // objLocalID is the localID of the object.
3899
3900 // Unfortunately, we have to pass the event the packet because objData is an array
3901 // That means multiple object perms may be updated in a single packet.
3902
3903 break;
3904
3905 case PacketType.Undo:
3906 UndoPacket undoitem = (UndoPacket)Pack;
3907 if (undoitem.ObjectData.Length > 0)
3908 {
3909 for (int i = 0; i < undoitem.ObjectData.Length; i++)
3910 {
3911 LLUUID objiD = undoitem.ObjectData[i].ObjectID;
3912 handlerOnUndo = OnUndo;
3913 if (handlerOnUndo != null)
3914 {
3915 handlerOnUndo(this, objiD);
3916 }
3917
3918 }
3919 }
3920 break;
3921 case PacketType.ObjectDuplicateOnRay:
3922 ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
3923
3924 handlerObjectDuplicateOnRay = null;
3925
3926
3927 for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
3928 {
3929 handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
3930 if (handlerObjectDuplicateOnRay != null)
3931 {
3932 handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID, dupeOnRay.AgentData.DuplicateFlags,
3933 dupeOnRay.AgentData.AgentID, dupeOnRay.AgentData.GroupID, dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
3934 dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast, dupeOnRay.AgentData.RayEndIsIntersection,
3935 dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
3936 }
3937 }
3938
3939 break;
3940 case PacketType.RequestObjectPropertiesFamily:
3941 //This powers the little tooltip that appears when you move your mouse over an object
3942 RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
3943
3944 RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
3945
3946 handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
3947
3948 if (handlerRequestObjectPropertiesFamily != null)
3949 {
3950 handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
3951 packObjBlock.ObjectID);
3952 }
3953
3954 break;
3955 case PacketType.ObjectIncludeInSearch:
3956 //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
3957 ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
3958 handlerObjectIncludeInSearch = null;
3959
3960 foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData) {
3961 bool inSearch = objData.IncludeInSearch;
3962 uint localID = objData.ObjectLocalID;
3963
3964 handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
3965
3966 if (handlerObjectIncludeInSearch != null) {
3967 handlerObjectIncludeInSearch(this, inSearch, localID);
3968 }
3969 }
3970 break;
3971
3972 case PacketType.ScriptAnswerYes:
3973 ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
3974
3975 handlerScriptAnswer = OnScriptAnswer;
3976 if (handlerScriptAnswer != null)
3977 {
3978 handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
3979 }
3980 break;
3981
3982 #endregion
3983
3984 #region Inventory/Asset/Other related packets
3985
3986 case PacketType.RequestImage:
3987 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
3988 //Console.WriteLine("image request: " + Pack.ToString());
3989
3990 handlerTextureRequest = null;
3991
3992 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
3993 {
3994 if (OnRequestTexture != null)
3995 {
3996 TextureRequestArgs args = new TextureRequestArgs();
3997 args.RequestedAssetID = imageRequest.RequestImage[i].Image;
3998 args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel;
3999 args.PacketNumber = imageRequest.RequestImage[i].Packet;
4000 args.Priority = imageRequest.RequestImage[i].DownloadPriority;
4001
4002 handlerTextureRequest = OnRequestTexture;
4003
4004 if (handlerTextureRequest != null)
4005 OnRequestTexture(this, args);
4006 }
4007 }
4008 break;
4009 case PacketType.TransferRequest:
4010 //Console.WriteLine("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
4011 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
4012 m_assetCache.AddAssetRequest(this, transfer);
4013 /* RequestAsset = OnRequestAsset;
4014 if (RequestAsset != null)
4015 {
4016 RequestAsset(this, transfer);
4017 }*/
4018 break;
4019 case PacketType.AssetUploadRequest:
4020 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
4021 // Console.WriteLine("upload request " + Pack.ToString());
4022 // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
4023 LLUUID temp = LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
4024
4025 handlerAssetUploadRequest = OnAssetUploadRequest;
4026
4027 if (handlerAssetUploadRequest != null)
4028 {
4029 handlerAssetUploadRequest(this, temp,
4030 request.AssetBlock.TransactionID, request.AssetBlock.Type,
4031 request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
4032 request.AssetBlock.Tempfile);
4033 }
4034 break;
4035 case PacketType.RequestXfer:
4036 RequestXferPacket xferReq = (RequestXferPacket)Pack;
4037
4038 handlerRequestXfer = OnRequestXfer;
4039
4040 if (handlerRequestXfer != null)
4041 {
4042 handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
4043 }
4044 break;
4045 case PacketType.SendXferPacket:
4046 SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
4047
4048 handlerXferReceive = OnXferReceive;
4049 if (handlerXferReceive != null)
4050 {
4051 handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
4052 }
4053 break;
4054 case PacketType.ConfirmXferPacket:
4055 ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
4056
4057 handlerConfirmXfer = OnConfirmXfer;
4058 if (handlerConfirmXfer != null)
4059 {
4060 handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
4061 }
4062 break;
4063 case PacketType.CreateInventoryFolder:
4064 CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
4065
4066 handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
4067 if (handlerCreateInventoryFolder != null)
4068 {
4069 handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
4070 (ushort)invFolder.FolderData.Type,
4071 Util.FieldToString(invFolder.FolderData.Name),
4072 invFolder.FolderData.ParentID);
4073 }
4074 break;
4075 case PacketType.UpdateInventoryFolder:
4076 if (OnUpdateInventoryFolder != null)
4077 {
4078 UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
4079
4080 handlerUpdateInventoryFolder = null;
4081
4082 for (int i = 0; i < invFolderx.FolderData.Length; i++)
4083 {
4084 handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
4085 if (handlerUpdateInventoryFolder != null)
4086 {
4087 OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
4088 (ushort)invFolderx.FolderData[i].Type,
4089 Util.FieldToString(invFolderx.FolderData[i].Name),
4090 invFolderx.FolderData[i].ParentID);
4091 }
4092 }
4093 }
4094 break;
4095 case PacketType.MoveInventoryFolder:
4096 if (OnMoveInventoryFolder != null)
4097 {
4098 MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
4099
4100 handlerMoveInventoryFolder = null;
4101
4102 for (int i = 0; i < invFoldery.InventoryData.Length; i++)
4103 {
4104 handlerMoveInventoryFolder = OnMoveInventoryFolder;
4105 if (handlerMoveInventoryFolder != null)
4106 {
4107 OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
4108 invFoldery.InventoryData[i].ParentID);
4109 }
4110 }
4111 }
4112 break;
4113 case PacketType.CreateInventoryItem:
4114 CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
4115
4116 handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
4117 if (handlerCreateNewInventoryItem != null)
4118 {
4119 handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
4120 createItem.InventoryBlock.FolderID,
4121 createItem.InventoryBlock.CallbackID,
4122 Util.FieldToString(createItem.InventoryBlock.Description),
4123 Util.FieldToString(createItem.InventoryBlock.Name),
4124 createItem.InventoryBlock.InvType,
4125 createItem.InventoryBlock.Type,
4126 createItem.InventoryBlock.WearableType,
4127 createItem.InventoryBlock.NextOwnerMask);
4128 }
4129 break;
4130 case PacketType.FetchInventory:
4131 if (OnFetchInventory != null)
4132 {
4133 FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
4134
4135 handlerFetchInventory = null;
4136
4137 for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
4138 {
4139 handlerFetchInventory = OnFetchInventory;
4140
4141 if (handlerFetchInventory != null)
4142 {
4143 OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
4144 FetchInventoryx.InventoryData[i].OwnerID);
4145 }
4146 }
4147 }
4148 break;
4149 case PacketType.FetchInventoryDescendents:
4150 FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
4151
4152 handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
4153 if (handlerFetchInventoryDescendents != null)
4154 {
4155 handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
4156 Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
4157 Fetch.InventoryData.SortOrder);
4158 }
4159 break;
4160 case PacketType.PurgeInventoryDescendents:
4161 PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
4162
4163 handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
4164 if (handlerPurgeInventoryDescendents != null)
4165 {
4166 handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
4167 }
4168 break;
4169 case PacketType.UpdateInventoryItem:
4170 UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
4171 if (OnUpdateInventoryItem != null)
4172 {
4173 handlerUpdateInventoryItem = null;
4174 for (int i = 0; i < update.InventoryData.Length; i++)
4175 {
4176 handlerUpdateInventoryItem = OnUpdateInventoryItem;
4177
4178 if (handlerUpdateInventoryItem != null)
4179 {
4180 InventoryItemBase itemUpd = new InventoryItemBase();
4181 itemUpd.ID = update.InventoryData[i].ItemID;
4182 itemUpd.Name = Util.FieldToString(update.InventoryData[i].Name);
4183 itemUpd.Description = Util.FieldToString(update.InventoryData[i].Description);
4184 itemUpd.GroupID = update.InventoryData[i].GroupID;
4185 itemUpd.GroupOwned = update.InventoryData[i].GroupOwned;
4186 itemUpd.NextPermissions = update.InventoryData[i].NextOwnerMask;
4187 itemUpd.EveryOnePermissions = update.InventoryData[i].EveryoneMask;
4188 itemUpd.CreationDate = update.InventoryData[i].CreationDate;
4189 itemUpd.Folder = update.InventoryData[i].FolderID;
4190 itemUpd.InvType = update.InventoryData[i].InvType;
4191 itemUpd.SalePrice = update.InventoryData[i].SalePrice;
4192 itemUpd.SaleType = update.InventoryData[i].SaleType;
4193 itemUpd.Flags = update.InventoryData[i].Flags;
4194 /*
4195 OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
4196 update.InventoryData[i].ItemID,
4197 Util.FieldToString(update.InventoryData[i].Name),
4198 Util.FieldToString(update.InventoryData[i].Description),
4199 update.InventoryData[i].NextOwnerMask);
4200 */
4201 OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
4202 update.InventoryData[i].ItemID,
4203 itemUpd);
4204 }
4205 }
4206 }
4207 //Console.WriteLine(Pack.ToString());
4208 /*for (int i = 0; i < update.InventoryData.Length; i++)
4209 {
4210 if (update.InventoryData[i].TransactionID != LLUUID.Zero)
4211 {
4212 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
4213 if (asset != null)
4214 {
4215 // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
4216 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
4217 }
4218 else
4219 {
4220 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
4221 if (asset != null)
4222 {
4223 //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
4224 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
4225 }
4226 else
4227 {
4228 //Console.WriteLine("trying to update inventory item, but asset is null");
4229 }
4230 }
4231 }
4232 else
4233 {
4234 m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
4235 }
4236 }*/
4237 break;
4238 case PacketType.CopyInventoryItem:
4239 CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
4240
4241 handlerCopyInventoryItem = null;
4242 if (OnCopyInventoryItem != null)
4243 {
4244 foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
4245 {
4246 handlerCopyInventoryItem = OnCopyInventoryItem;
4247 if (handlerCopyInventoryItem != null)
4248 {
4249 handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
4250 datablock.OldItemID, datablock.NewFolderID,
4251 Util.FieldToString(datablock.NewName));
4252 }
4253 }
4254 }
4255 break;
4256 case PacketType.MoveInventoryItem:
4257 MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
4258 if (OnMoveInventoryItem != null)
4259 {
4260 handlerMoveInventoryItem = null;
4261 foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
4262 {
4263 handlerMoveInventoryItem = OnMoveInventoryItem;
4264 if (handlerMoveInventoryItem != null)
4265 {
4266 handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length,
4267 Util.FieldToString(datablock.NewName));
4268 }
4269 }
4270 }
4271 break;
4272 case PacketType.RemoveInventoryItem:
4273 RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
4274 if (OnRemoveInventoryItem != null)
4275 {
4276 handlerRemoveInventoryItem = null;
4277 foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
4278 {
4279 handlerRemoveInventoryItem = OnRemoveInventoryItem;
4280 if (handlerRemoveInventoryItem != null)
4281 {
4282 handlerRemoveInventoryItem(this, datablock.ItemID);
4283 }
4284 }
4285 }
4286 break;
4287 case PacketType.RemoveInventoryFolder:
4288 RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
4289 if (OnRemoveInventoryFolder != null)
4290 {
4291 handlerRemoveInventoryFolder = null;
4292 foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
4293 {
4294 handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
4295
4296 if (handlerRemoveInventoryFolder != null)
4297 {
4298 handlerRemoveInventoryFolder(this, datablock.FolderID);
4299 }
4300 }
4301 }
4302 break;
4303 case PacketType.RequestTaskInventory:
4304 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
4305
4306 handlerRequestTaskInventory = OnRequestTaskInventory;
4307 if (handlerRequestTaskInventory != null)
4308 {
4309 handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
4310 }
4311 break;
4312 case PacketType.UpdateTaskInventory:
4313 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
4314 if (OnUpdateTaskInventory != null)
4315 {
4316 if (updatetask.UpdateData.Key == 0)
4317 {
4318 handlerUpdateTaskInventory = OnUpdateTaskInventory;
4319 if (handlerUpdateTaskInventory != null)
4320 {
4321 handlerUpdateTaskInventory(this, updatetask.InventoryData.ItemID,
4322 updatetask.InventoryData.FolderID, updatetask.UpdateData.LocalID);
4323 }
4324 }
4325 }
4326
4327 break;
4328
4329 case PacketType.RemoveTaskInventory:
4330
4331 RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
4332
4333 handlerRemoveTaskItem = OnRemoveTaskItem;
4334
4335 if (handlerRemoveTaskItem != null)
4336 {
4337 handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
4338 }
4339
4340 break;
4341
4342 case PacketType.MoveTaskInventory:
4343
4344 MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
4345
4346 handlerMoveTaskItem = OnMoveTaskItem;
4347
4348 if (handlerMoveTaskItem != null)
4349 {
4350 handlerMoveTaskItem(
4351 this, moveTaskInventoryPacket.AgentData.FolderID,
4352 moveTaskInventoryPacket.InventoryData.LocalID,
4353 moveTaskInventoryPacket.InventoryData.ItemID);
4354 }
4355
4356 break;
4357
4358 case PacketType.RezScript:
4359
4360 //Console.WriteLine(Pack.ToString());
4361 RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
4362
4363 handlerRezScript = OnRezScript;
4364
4365 if (handlerRezScript != null)
4366 {
4367 handlerRezScript(this, rezScriptx.InventoryBlock.ItemID, rezScriptx.UpdateBlock.ObjectLocalID);
4368 }
4369 break;
4370
4371 case PacketType.MapLayerRequest:
4372 RequestMapLayer();
4373 break;
4374 case PacketType.MapBlockRequest:
4375 MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
4376
4377 handlerRequestMapBlocks = OnRequestMapBlocks;
4378 if (handlerRequestMapBlocks != null)
4379 {
4380 handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
4381 MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY);
4382 }
4383 break;
4384 case PacketType.MapNameRequest:
4385 MapNameRequestPacket map = (MapNameRequestPacket)Pack;
4386 string mapName = UTF8Encoding.UTF8.GetString(map.NameData.Name, 0,
4387 map.NameData.Name.Length - 1);
4388 handlerMapNameRequest = OnMapNameRequest;
4389 if (handlerMapNameRequest != null)
4390 {
4391 handlerMapNameRequest(this, mapName);
4392 }
4393 break;
4394 case PacketType.TeleportLandmarkRequest:
4395 TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
4396 LLUUID lmid = tpReq.Info.LandmarkID;
4397 AssetLandmark lm;
4398 if (lmid != LLUUID.Zero)
4399 {
4400 AssetBase lma = m_assetCache.GetAsset(lmid, false);
4401
4402 if (lma == null)
4403 {
4404 // Failed to find landmark
4405
4406 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
4407 tpCancel.Info.SessionID = tpReq.Info.SessionID;
4408 tpCancel.Info.AgentID = tpReq.Info.AgentID;
4409 OutPacket(tpCancel, ThrottleOutPacketType.Task);
4410 }
4411
4412
4413 try
4414 {
4415 lm = new AssetLandmark(lma);
4416 }
4417 catch (NullReferenceException)
4418 {
4419 // asset not found generates null ref inside the assetlandmark constructor.
4420 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
4421 tpCancel.Info.SessionID = tpReq.Info.SessionID;
4422 tpCancel.Info.AgentID = tpReq.Info.AgentID;
4423 OutPacket(tpCancel, ThrottleOutPacketType.Task);
4424 break;
4425 }
4426 }
4427 else
4428 {
4429
4430 // Teleport home request
4431 handlerTeleportHomeRequest = OnTeleportHomeRequest;
4432 if (handlerTeleportHomeRequest != null)
4433 {
4434 handlerTeleportHomeRequest(this.AgentId,this);
4435 }
4436 break;
4437 }
4438
4439 handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
4440 if (handlerTeleportLandmarkRequest != null)
4441 {
4442 handlerTeleportLandmarkRequest(this, lm.RegionHandle, lm.Position);
4443 }
4444 else
4445 {
4446 //no event handler so cancel request
4447
4448
4449 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
4450 tpCancel.Info.AgentID = tpReq.Info.AgentID;
4451 tpCancel.Info.SessionID = tpReq.Info.SessionID;
4452 OutPacket(tpCancel, ThrottleOutPacketType.Task);
4453
4454 }
4455 break;
4456 case PacketType.TeleportLocationRequest:
4457 TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
4458 // Console.WriteLine(tpLocReq.ToString());
4459
4460 handlerTeleportLocationRequest = OnTeleportLocationRequest;
4461 if (handlerTeleportLocationRequest != null)
4462 {
4463 handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
4464 tpLocReq.Info.LookAt, 16);
4465 }
4466 else
4467 {
4468 //no event handler so cancel request
4469 TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
4470 tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
4471 tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
4472 OutPacket(tpCancel, ThrottleOutPacketType.Task);
4473 }
4474 break;
4475
4476 #endregion
4477
4478
4479 case PacketType.UUIDNameRequest:
4480 UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
4481 foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
4482 {
4483 handlerNameRequest = OnNameFromUUIDRequest;
4484 if (handlerNameRequest != null)
4485 {
4486 handlerNameRequest(UUIDBlock.ID, this);
4487 }
4488 }
4489 break;
4490
4491 #region Parcel related packets
4492
4493 case PacketType.ParcelAccessListRequest:
4494 ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
4495
4496 handlerParcelAccessListRequest = OnParcelAccessListRequest;
4497
4498 if (handlerParcelAccessListRequest != null)
4499 {
4500 handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
4501 requestPacket.Data.Flags, requestPacket.Data.SequenceID,
4502 requestPacket.Data.LocalID, this);
4503 }
4504 break;
4505
4506 case PacketType.ParcelAccessListUpdate:
4507 ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
4508 List<ParcelManager.ParcelAccessEntry> entries = new List<ParcelManager.ParcelAccessEntry>();
4509 foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
4510 {
4511 ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
4512 entry.AgentID = block.ID;
4513 entry.Flags = (ParcelManager.AccessList)block.Flags;
4514 entry.Time = new DateTime();
4515 entries.Add(entry);
4516 }
4517
4518 handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
4519 if (handlerParcelAccessListUpdateRequest != null)
4520 {
4521 handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
4522 updatePacket.AgentData.SessionID, updatePacket.Data.Flags,
4523 updatePacket.Data.LocalID, entries, this);
4524 }
4525 break;
4526 case PacketType.ParcelPropertiesRequest:
4527
4528 ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
4529
4530 handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
4531 if (handlerParcelPropertiesRequest != null)
4532 {
4533 handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
4534 (int)Math.Round(propertiesRequest.ParcelData.South),
4535 (int)Math.Round(propertiesRequest.ParcelData.East),
4536 (int)Math.Round(propertiesRequest.ParcelData.North),
4537 propertiesRequest.ParcelData.SequenceID,
4538 propertiesRequest.ParcelData.SnapSelection, this);
4539 }
4540 break;
4541 case PacketType.ParcelDivide:
4542 ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
4543
4544 handlerParcelDivideRequest = OnParcelDivideRequest;
4545 if (handlerParcelDivideRequest != null)
4546 {
4547 handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
4548 (int)Math.Round(landDivide.ParcelData.South),
4549 (int)Math.Round(landDivide.ParcelData.East),
4550 (int)Math.Round(landDivide.ParcelData.North), this);
4551 }
4552 break;
4553 case PacketType.ParcelJoin:
4554 ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
4555
4556 handlerParcelJoinRequest = OnParcelJoinRequest;
4557
4558 if (handlerParcelJoinRequest != null)
4559 {
4560 handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
4561 (int)Math.Round(landJoin.ParcelData.South),
4562 (int)Math.Round(landJoin.ParcelData.East),
4563 (int)Math.Round(landJoin.ParcelData.North), this);
4564 }
4565 break;
4566 case PacketType.ParcelPropertiesUpdate:
4567 ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
4568
4569 handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
4570
4571 if (handlerParcelPropertiesUpdateRequest != null)
4572 {
4573 handlerParcelPropertiesUpdateRequest(parcelPropertiesPacket, this);
4574 }
4575 break;
4576 case PacketType.ParcelSelectObjects:
4577 ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
4578
4579 handlerParcelSelectObjects = OnParcelSelectObjects;
4580
4581 if (handlerParcelSelectObjects != null)
4582 {
4583 handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
4584 Convert.ToInt32(selectPacket.ParcelData.ReturnType), this);
4585 }
4586 break;
4587 case PacketType.ParcelObjectOwnersRequest:
4588 //Console.WriteLine(Pack.ToString());
4589 ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
4590
4591 handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
4592
4593 if (handlerParcelObjectOwnerRequest != null)
4594 {
4595 handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
4596 }
4597 break;
4598
4599 #endregion
4600
4601 #region Estate Packets
4602
4603 case PacketType.EstateOwnerMessage:
4604 EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
4605
4606 handlerEstateOwnerMessage = OnEstateOwnerMessage;
4607
4608 if (handlerEstateOwnerMessage != null)
4609 {
4610 handlerEstateOwnerMessage(messagePacket, this);
4611 }
4612 break;
4613 case PacketType.RequestRegionInfo:
4614 RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
4615
4616 handlerRegionInfoRequest = OnRegionInfoRequest;
4617 if (handlerRegionInfoRequest != null)
4618 {
4619 handlerRegionInfoRequest(this, mPacket.SessionID);
4620 }
4621 break;
4622 case PacketType.EstateCovenantRequest:
4623
4624 EstateCovenantRequestPacket.AgentDataBlock epack =
4625 ((EstateCovenantRequestPacket)Pack).AgentData;
4626
4627 handlerEstateCovenantRequest = OnEstateCovenantRequest;
4628 if (handlerEstateCovenantRequest != null)
4629 {
4630 handlerEstateCovenantRequest(this, epack.SessionID);
4631 }
4632 break;
4633
4634 #endregion
4635
4636 #region GodPackets
4637
4638 case PacketType.RequestGodlikePowers:
4639 RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
4640 RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
4641 LLUUID token = rblock.Token;
4642
4643 RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
4644
4645 handlerReqGodlikePowers = OnRequestGodlikePowers;
4646
4647 if (handlerReqGodlikePowers != null)
4648 {
4649 handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike, this);
4650 }
4651
4652 break;
4653 case PacketType.GodKickUser:
4654 m_log.Warn("[CLIENT]: unhandled GodKickUser packet");
4655
4656 GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
4657
4658 if (gkupack.UserInfo.GodSessionID == SessionId && AgentId == gkupack.UserInfo.GodID)
4659 {
4660 handlerGodKickUser = OnGodKickUser;
4661 if (handlerGodKickUser != null)
4662 {
4663 handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.GodSessionID,
4664 gkupack.UserInfo.AgentID, (uint)0, gkupack.UserInfo.Reason);
4665 }
4666 }
4667 else
4668 {
4669 SendAgentAlertMessage("Kick request denied", false);
4670 }
4671 //KickUserPacket kupack = new KickUserPacket();
4672 //KickUserPacket.UserInfoBlock kupackib = kupack.UserInfo;
4673
4674 //kupack.UserInfo.AgentID = gkupack.UserInfo.AgentID;
4675 //kupack.UserInfo.SessionID = gkupack.UserInfo.GodSessionID;
4676
4677 //kupack.TargetBlock.TargetIP = (uint)0;
4678 //kupack.TargetBlock.TargetPort = (ushort)0;
4679 //kupack.UserInfo.Reason = gkupack.UserInfo.Reason;
4680
4681 //OutPacket(kupack, ThrottleOutPacketType.Task);
4682 break;
4683
4684 #endregion
4685
4686 #region Economy/Transaction Packets
4687
4688 case PacketType.MoneyBalanceRequest:
4689 MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
4690
4691 handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
4692
4693 if (handlerMoneyBalanceRequest != null)
4694 {
4695 handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
4696 }
4697
4698 break;
4699 case PacketType.EconomyDataRequest:
4700
4701 handlerEconomoyDataRequest = OnEconomyDataRequest;
4702 if (handlerEconomoyDataRequest != null)
4703 {
4704 handlerEconomoyDataRequest(AgentId);
4705 }
4706 // TODO: handle this packet
4707 //m_log.Warn("[CLIENT]: unhandled EconomyDataRequest packet");
4708 break;
4709 case PacketType.RequestPayPrice:
4710 RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
4711 handlerRequestPayPrice = OnRequestPayPrice;
4712 if (handlerRequestPayPrice != null)
4713 {
4714 handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
4715 }
4716 break;
4717
4718 #endregion
4719
4720 #region unimplemented handlers
4721
4722 case PacketType.StartPingCheck:
4723 // Send the client the ping response back
4724 // Pass the same PingID in the matching packet
4725 // Handled In the packet processing
4726 //m_log.Debug("[CLIENT]: possibly unhandled StartPingCheck packet");
4727 break;
4728 case PacketType.CompletePingCheck:
4729 // TODO: Perhaps this should be processed on the Sim to determine whether or not to drop a dead client
4730 //m_log.Warn("[CLIENT]: unhandled CompletePingCheck packet");
4731 break;
4732 case PacketType.ObjectScale:
4733 // TODO: handle this packet
4734 m_log.Warn("[CLIENT]: unhandled ObjectScale packet");
4735 break;
4736 case PacketType.ViewerStats:
4737 // TODO: handle this packet
4738 m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
4739 break;
4740
4741 case PacketType.CreateGroupRequest:
4742 // TODO: handle this packet
4743 m_log.Warn("[CLIENT]: unhandled CreateGroupRequest packet");
4744 break;
4745 case PacketType.GenericMessage:
4746 // TODO: handle this packet
4747 m_log.Warn("[CLIENT]: unhandled GenericMessage packet");
4748 break;
4749 case PacketType.MapItemRequest:
4750 // TODO: handle this packet
4751 m_log.Warn("[CLIENT]: unhandled MapItemRequest packet");
4752 break;
4753 case PacketType.TransferAbort:
4754 // TODO: handle this packet
4755 m_log.Warn("[CLIENT]: unhandled TransferAbort packet");
4756 break;
4757 case PacketType.MuteListRequest:
4758 // TODO: handle this packet
4759 m_log.Warn("[CLIENT]: unhandled MuteListRequest packet");
4760 break;
4761 case PacketType.ParcelDwellRequest:
4762 // TODO: handle this packet
4763 m_log.Warn("[CLIENT]: unhandled ParcelDwellRequest packet");
4764 break;
4765 case PacketType.UseCircuitCode:
4766 // TODO: Don't display this one, we handle it at a lower level
4767 //m_log.Warn("[CLIENT]: unhandled UseCircuitCode packet");
4768 break;
4769
4770 case PacketType.AgentHeightWidth:
4771 // TODO: handle this packet
4772 m_log.Warn("[CLIENT]: unhandled AgentHeightWidth packet");
4773 break;
4774 case PacketType.ObjectSpinStop:
4775 // TODO: handle this packet
4776 m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
4777 break;
4778 case PacketType.SoundTrigger:
4779 // TODO: handle this packet
4780 m_log.Warn("[CLIENT]: unhandled SoundTrigger packet");
4781 break;
4782 case PacketType.InventoryDescendents:
4783 // TODO: handle this packet
4784 m_log.Warn("[CLIENT]: unhandled InventoryDescent packet");
4785 break;
4786 case PacketType.GetScriptRunning:
4787 m_log.Warn("[CLIENT]: unhandled GetScriptRunning packet");
4788 break;
4789 default:
4790 m_log.Warn("[CLIENT]: unhandled packet " + Pack.ToString());
4791 break;
4792
4793 #endregion
4794 }
4795 }
4796
4797 PacketPool.Instance.ReturnPacket(Pack);
4798 }
4799
4800 private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
4801 {
4802 PrimitiveBaseShape shape = new PrimitiveBaseShape();
4803
4804 shape.PCode = addPacket.ObjectData.PCode;
4805 shape.State = addPacket.ObjectData.State;
4806 shape.PathBegin = addPacket.ObjectData.PathBegin;
4807 shape.PathEnd = addPacket.ObjectData.PathEnd;
4808 shape.PathScaleX = addPacket.ObjectData.PathScaleX;
4809 shape.PathScaleY = addPacket.ObjectData.PathScaleY;
4810 shape.PathShearX = addPacket.ObjectData.PathShearX;
4811 shape.PathShearY = addPacket.ObjectData.PathShearY;
4812 shape.PathSkew = addPacket.ObjectData.PathSkew;
4813 shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
4814 shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
4815 shape.Scale = addPacket.ObjectData.Scale;
4816 shape.PathCurve = addPacket.ObjectData.PathCurve;
4817 shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
4818 shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
4819 shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
4820 shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
4821 shape.PathTaperX = addPacket.ObjectData.PathTaperX;
4822 shape.PathTaperY = addPacket.ObjectData.PathTaperY;
4823 shape.PathTwist = addPacket.ObjectData.PathTwist;
4824 shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
4825 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
4826 shape.TextureEntry = ntex.ToBytes();
4827 //shape.Textures = ntex;
4828 return shape;
4829 }
4830
4831 public void SendBlueBoxMessage(LLUUID FromAvatarID, LLUUID fromSessionID, String FromAvatarName, String Message)
4832 {
4833 if (!ChildAgentStatus())
4834 SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)1, (uint)Util.UnixTimeSinceEpoch());
4835
4836 //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
4837 }
4838
4839 public void SendLogoutPacket()
4840 {
4841 LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
4842 // TODO: don't create new blocks if recycling an old packet
4843 logReply.AgentData.AgentID = AgentId;
4844 logReply.AgentData.SessionID = SessionId;
4845 logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
4846 logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
4847 logReply.InventoryData[0].ItemID = LLUUID.Zero;
4848
4849 OutPacket(logReply, ThrottleOutPacketType.Task);
4850 }
4851
4852 public ClientInfo GetClientInfo()
4853 {
4854 //MainLog.Instance.Verbose("CLIENT", "GetClientInfo BGN");
4855
4856 ClientInfo info = new ClientInfo();
4857 info.userEP = this.m_userEndPoint;
4858 info.proxyEP = this.m_proxyEndPoint;
4859 info.agentcircuit = new sAgentCircuitData(RequestClientInfo());
4860
4861 info.pendingAcks = m_pendingAcks;
4862
4863 info.needAck = new Dictionary<uint,byte[]>();
4864
4865 lock (m_needAck)
4866 {
4867 foreach (uint key in m_needAck.Keys)
4868 {
4869 info.needAck.Add(key, m_needAck[key].ToBytes());
4870 }
4871 }
4872
4873/* pending
4874 QueItem[] queitems = m_packetQueue.GetQueueArray();
4875
4876 MainLog.Instance.Verbose("CLIENT", "Queue Count : [{0}]", queitems.Length);
4877
4878 for (int i = 0; i < queitems.Length; i++)
4879 {
4880 if (queitems[i].Incoming == false)
4881 {
4882 info.out_packets.Add(queitems[i].Packet.ToBytes());
4883 MainLog.Instance.Verbose("CLIENT", "Add OutPacket [{0}]", queitems[i].Packet.Type.ToString());
4884 }
4885 }
4886*/
4887
4888 info.sequence = m_sequence;
4889
4890 //MainLog.Instance.Verbose("CLIENT", "GetClientInfo END");
4891
4892 return info;
4893 }
4894
4895 public void SetClientInfo(ClientInfo info)
4896 {
4897 m_pendingAcks = info.pendingAcks;
4898
4899 m_needAck = new Dictionary<uint,Packet>();
4900
4901 Packet packet = null;
4902 int packetEnd = 0;
4903 byte[] zero = new byte[3000];
4904
4905 foreach (uint key in info.needAck.Keys)
4906 {
4907 byte[] buff = info.needAck[key];
4908
4909 packetEnd = buff.Length - 1;
4910
4911 try
4912 {
4913 packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
4914 }
4915 catch (Exception)
4916 {
4917 //MainLog.Instance.Debug("UDPSERVER", e.ToString());
4918 }
4919
4920 m_needAck.Add(key, packet);
4921 }
4922
4923 m_sequence = info.sequence;
4924 }
4925 }
4926}