aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs550
1 files changed, 550 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
new file mode 100644
index 0000000..191ef21
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
@@ -0,0 +1,550 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using libsecondlife.Packets;
33using Nwc.XmlRpc;
34using System.Net;
35using System.Net.Sockets;
36using System.IO;
37using System.Threading;
38using System.Timers;
39using OpenSim.Framework.Interfaces;
40using OpenSim.Framework.Types;
41using OpenSim.Framework.Inventory;
42using OpenSim.Framework.Utilities;
43using OpenSim.Assets;
44
45namespace OpenSim
46{
47 public partial class ClientView
48 {
49 protected override void ProcessInPacket(Packet Pack)
50 {
51 ack_pack(Pack);
52 if (debug)
53 {
54 if (Pack.Type != PacketType.AgentUpdate)
55 {
56 Console.WriteLine(Pack.Type.ToString());
57 }
58 }
59
60 if (this.ProcessPacketMethod(Pack))
61 {
62 //there is a handler registered that handled this packet type
63 return;
64 }
65 else
66 {
67 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
68
69 switch (Pack.Type)
70 {
71 case PacketType.ViewerEffect:
72 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
73 foreach (ClientView client in m_clientThreads.Values)
74 {
75 if (client.AgentID != this.AgentID)
76 {
77 viewer.AgentData.AgentID = client.AgentID;
78 viewer.AgentData.SessionID = client.SessionID;
79 client.OutPacket(viewer);
80 }
81 }
82 break;
83
84 #region World/Avatar
85 case PacketType.ChatFromViewer:
86 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
87 if (Util.FieldToString(inchatpack.ChatData.Message) == "")
88 {
89 //empty message so don't bother with it
90 break;
91 }
92 string fromName = ""; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
93 byte[] message = inchatpack.ChatData.Message;
94 byte type = inchatpack.ChatData.Type;
95 LLVector3 fromPos = new LLVector3(); // ClientAvatar.Pos;
96 LLUUID fromAgentID = AgentID;
97 if (OnChatFromViewer != null)
98 {
99 this.OnChatFromViewer(message, type, fromPos, fromName, fromAgentID);
100 }
101 break;
102 case PacketType.RezObject:
103 RezObjectPacket rezPacket = (RezObjectPacket)Pack;
104 AgentInventory inven = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
105 if (inven != null)
106 {
107 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
108 {
109 AssetBase asset = this.m_assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
110 if (asset != null)
111 {
112 if (OnRezObject != null)
113 {
114 this.OnRezObject(asset, rezPacket.RezData.RayEnd);
115 this.m_inventoryCache.DeleteInventoryItem(this, rezPacket.InventoryData.ItemID);
116 }
117 }
118 }
119 }
120 break;
121 case PacketType.DeRezObject:
122 if (OnDeRezObject != null)
123 {
124 OnDeRezObject(Pack, this);
125 }
126 break;
127 case PacketType.ModifyLand:
128 ModifyLandPacket modify = (ModifyLandPacket)Pack;
129 if (modify.ParcelData.Length > 0)
130 {
131 if (OnModifyTerrain != null)
132 {
133 OnModifyTerrain(modify.ModifyBlock.Height, modify.ModifyBlock.Seconds, modify.ModifyBlock.BrushSize,
134 modify.ModifyBlock.Action, modify.ParcelData[0].North, modify.ParcelData[0].West);
135 }
136 }
137 break;
138 case PacketType.RegionHandshakeReply:
139 if (OnRegionHandShakeReply != null)
140 {
141 OnRegionHandShakeReply(this);
142 }
143 break;
144 case PacketType.AgentWearablesRequest:
145 if (OnRequestWearables != null)
146 {
147 OnRequestWearables(this);
148 }
149 if (OnRequestAvatarsData != null)
150 {
151 OnRequestAvatarsData(this);
152 }
153 break;
154 case PacketType.AgentSetAppearance:
155 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
156 if (OnSetAppearance != null)
157 {
158 OnSetAppearance(appear.ObjectData.TextureEntry, appear.VisualParam);
159 }
160 break;
161 case PacketType.CompleteAgentMovement:
162 if (OnCompleteMovementToRegion != null)
163 {
164 OnCompleteMovementToRegion();
165 }
166 break;
167 case PacketType.AgentUpdate:
168 if (OnAgentUpdate != null)
169 {
170 AgentUpdatePacket agenUpdate = (AgentUpdatePacket) Pack;
171 OnAgentUpdate(this, agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotation );
172 }
173 break;
174 case PacketType.AgentAnimation:
175 if (!m_child)
176 {
177 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
178 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
179 {
180 if (AgentAni.AnimationList[i].StartAnim)
181 {
182 if (OnStartAnim != null)
183 {
184 OnStartAnim(AgentAni.AnimationList[i].AnimID, 1);
185 }
186 }
187 }
188 }
189 break;
190
191 #endregion
192
193 #region Objects/Prims
194 case PacketType.ObjectLink:
195 // OpenSim.Framework.Console.MainLog.Instance.Verbose( Pack.ToString());
196 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
197 uint parentprimid = 0;
198 List<uint> childrenprims = new List<uint>();
199 if (link.ObjectData.Length > 1)
200 {
201 parentprimid = link.ObjectData[0].ObjectLocalID;
202
203 for (int i = 1; i < link.ObjectData.Length; i++)
204 {
205 childrenprims.Add(link.ObjectData[i].ObjectLocalID);
206 }
207 }
208 if (OnLinkObjects != null)
209 {
210 OnLinkObjects(parentprimid, childrenprims);
211 }
212 break;
213 case PacketType.ObjectAdd:
214 // m_world.AddNewPrim((ObjectAddPacket)Pack, this);
215 if (OnAddPrim != null)
216 {
217 OnAddPrim(Pack, this);
218 }
219 break;
220 case PacketType.ObjectShape:
221 ObjectShapePacket shape = (ObjectShapePacket)Pack;
222 for (int i = 0; i < shape.ObjectData.Length; i++)
223 {
224 if (OnUpdatePrimShape != null)
225 {
226 OnUpdatePrimShape(shape.ObjectData[i].ObjectLocalID, shape.ObjectData[i]);
227 }
228 }
229 break;
230 case PacketType.ObjectSelect:
231 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
232 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
233 {
234 if (OnObjectSelect != null)
235 {
236 OnObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
237 }
238 }
239 break;
240 case PacketType.ObjectFlagUpdate:
241 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
242 if (OnUpdatePrimFlags != null)
243 {
244 OnUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
245 }
246 break;
247 case PacketType.ObjectImage:
248 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
249 for (int i = 0; i < imagePack.ObjectData.Length; i++)
250 {
251 if (OnUpdatePrimTexture != null)
252 {
253 OnUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID, imagePack.ObjectData[i].TextureEntry, this);
254 }
255 }
256 break;
257 case PacketType.ObjectGrab:
258 ObjectGrabPacket grap = (ObjectGrabPacket)Pack;
259 if (OnGrapObject != null)
260 {
261 OnGrapObject(grap.ObjectData.LocalID, grap.ObjectData.GrabOffset, this);
262 }
263 break;
264 case PacketType.ObjectGrabUpdate:
265 ObjectGrabUpdatePacket grapUpdate = (ObjectGrabUpdatePacket)Pack;
266 if (OnGrapUpdate != null)
267 {
268 OnGrapUpdate(grapUpdate.ObjectData.ObjectID, grapUpdate.ObjectData.GrabOffsetInitial, grapUpdate.ObjectData.GrabPosition, this);
269 }
270 break;
271 case PacketType.ObjectDeGrab:
272 ObjectDeGrabPacket deGrap = (ObjectDeGrabPacket)Pack;
273 if (OnDeGrapObject != null)
274 {
275 OnDeGrapObject(deGrap.ObjectData.LocalID, this);
276 }
277 break;
278 #endregion
279
280 #region Inventory/Asset/Other related packets
281 case PacketType.RequestImage:
282 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
283 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
284 {
285 m_assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image);
286 }
287 break;
288 case PacketType.TransferRequest:
289 //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request");
290 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
291 m_assetCache.AddAssetRequest(this, transfer);
292 break;
293 case PacketType.AssetUploadRequest:
294 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
295 this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID));
296 break;
297 case PacketType.RequestXfer:
298 //Console.WriteLine(Pack.ToString());
299 break;
300 case PacketType.SendXferPacket:
301 this.UploadAssets.HandleXferPacket((SendXferPacketPacket)Pack);
302 break;
303 case PacketType.CreateInventoryFolder:
304 CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
305 m_inventoryCache.CreateNewInventoryFolder(this, invFolder.FolderData.FolderID, (ushort)invFolder.FolderData.Type, Util.FieldToString(invFolder.FolderData.Name), invFolder.FolderData.ParentID);
306 //Console.WriteLine(Pack.ToString());
307 break;
308 case PacketType.CreateInventoryItem:
309 //Console.WriteLine(Pack.ToString());
310 CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
311 if (createItem.InventoryBlock.TransactionID != LLUUID.Zero)
312 {
313 this.UploadAssets.CreateInventoryItem(createItem);
314 }
315 else
316 {
317 // Console.Write(Pack.ToString());
318 this.CreateInventoryItem(createItem);
319 }
320 break;
321 case PacketType.FetchInventory:
322 //Console.WriteLine("fetch item packet");
323 FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack;
324 m_inventoryCache.FetchInventory(this, FetchInventory);
325 break;
326 case PacketType.FetchInventoryDescendents:
327 FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
328 m_inventoryCache.FetchInventoryDescendents(this, Fetch);
329 break;
330 case PacketType.UpdateInventoryItem:
331 UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
332 //Console.WriteLine(Pack.ToString());
333 for (int i = 0; i < update.InventoryData.Length; i++)
334 {
335 if (update.InventoryData[i].TransactionID != LLUUID.Zero)
336 {
337 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID));
338 if (asset != null)
339 {
340 // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache");
341 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
342 }
343 else
344 {
345 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
346 if (asset != null)
347 {
348 //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache");
349 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
350 }
351 else
352 {
353 //Console.WriteLine("trying to update inventory item, but asset is null");
354 }
355 }
356 }
357 else
358 {
359 m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
360 }
361 }
362 break;
363 case PacketType.RequestTaskInventory:
364 // Console.WriteLine(Pack.ToString());
365 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
366 ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket();
367 bool foundent = false;
368 /* foreach (Entity ent in m_world.Entities.Values)
369 {
370 if (ent.localid == requesttask.InventoryData.LocalID)
371 {
372 replytask.InventoryData.TaskID = ent.uuid;
373 replytask.InventoryData.Serial = 0;
374 replytask.InventoryData.Filename = new byte[0];
375 foundent = true;
376 }
377 }
378 if (foundent)
379 {
380 this.OutPacket(replytask);
381 }*/
382 break;
383 case PacketType.UpdateTaskInventory:
384 // Console.WriteLine(Pack.ToString());
385 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
386 AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
387 /*if (myinventory != null)
388 {
389 if (updatetask.UpdateData.Key == 0)
390 {
391 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID] != null)
392 {
393 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID].Type == 7)
394 {
395 LLUUID noteaid = myinventory.InventoryItems[updatetask.InventoryData.ItemID].AssetID;
396 AssetBase assBase = this.m_assetCache.GetAsset(noteaid);
397 if (assBase != null)
398 {
399 foreach (Entity ent in m_world.Entities.Values)
400 {
401 if (ent.localid == updatetask.UpdateData.LocalID)
402 {
403 if (ent is OpenSim.world.Primitive)
404 {
405 this.m_world.AddScript(ent, Util.FieldToString(assBase.Data));
406 }
407 }
408 }
409 }
410 }
411 }
412 }
413 }*/
414 break;
415 case PacketType.MapLayerRequest:
416 this.RequestMapLayer();
417 break;
418 case PacketType.MapBlockRequest:
419 MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
420 if (OnRequestMapBlocks != null)
421 {
422 OnRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY, MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY);
423 }
424 break;
425 case PacketType.TeleportLandmarkRequest:
426 TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
427
428 TeleportStartPacket tpStart = new TeleportStartPacket();
429 tpStart.Info.TeleportFlags = 8; // tp via lm
430 this.OutPacket(tpStart);
431
432 TeleportProgressPacket tpProgress = new TeleportProgressPacket();
433 tpProgress.Info.Message = (new System.Text.ASCIIEncoding()).GetBytes("sending_landmark");
434 tpProgress.Info.TeleportFlags = 8;
435 tpProgress.AgentData.AgentID = tpReq.Info.AgentID;
436 this.OutPacket(tpProgress);
437
438 // Fetch landmark
439 LLUUID lmid = tpReq.Info.LandmarkID;
440 AssetBase lma = this.m_assetCache.GetAsset(lmid);
441 if (lma != null)
442 {
443 AssetLandmark lm = new AssetLandmark(lma);
444
445 if (lm.RegionID == m_regionData.SimUUID)
446 {
447 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
448
449 tpLocal.Info.AgentID = tpReq.Info.AgentID;
450 tpLocal.Info.TeleportFlags = 8; // Teleport via landmark
451 tpLocal.Info.LocationID = 2;
452 tpLocal.Info.Position = lm.Position;
453 OutPacket(tpLocal);
454 }
455 else
456 {
457 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
458 tpCancel.Info.AgentID = tpReq.Info.AgentID;
459 tpCancel.Info.SessionID = tpReq.Info.SessionID;
460 OutPacket(tpCancel);
461 }
462 }
463 else
464 {
465 Console.WriteLine("Cancelling Teleport - fetch asset not yet implemented");
466
467 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
468 tpCancel.Info.AgentID = tpReq.Info.AgentID;
469 tpCancel.Info.SessionID = tpReq.Info.SessionID;
470 OutPacket(tpCancel);
471 }
472 break;
473 case PacketType.TeleportLocationRequest:
474 TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
475 // Console.WriteLine(tpLocReq.ToString());
476
477 if (OnTeleportLocationRequest != null)
478 {
479 OnTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position, tpLocReq.Info.LookAt, 16);
480 }
481 else
482 {
483 //no event handler so cancel request
484 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
485 tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
486 tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
487 OutPacket(tpCancel);
488 }
489 break;
490 #endregion
491
492 case PacketType.MoneyBalanceRequest:
493 this.SendMoneyBalance(LLUUID.Zero, true, new byte[0], 1000);
494 break;
495
496 #region Parcel related packets
497 case PacketType.ParcelPropertiesRequest:
498 ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
499 if (OnParcelPropertiesRequest != null)
500 {
501 OnParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West), (int)Math.Round(propertiesRequest.ParcelData.South), (int)Math.Round(propertiesRequest.ParcelData.East), (int)Math.Round(propertiesRequest.ParcelData.North), propertiesRequest.ParcelData.SequenceID, propertiesRequest.ParcelData.SnapSelection, this);
502 }
503 break;
504 case PacketType.ParcelDivide:
505 ParcelDividePacket parcelDivide = (ParcelDividePacket)Pack;
506 if (OnParcelDivideRequest != null)
507 {
508 OnParcelDivideRequest((int)Math.Round(parcelDivide.ParcelData.West), (int)Math.Round(parcelDivide.ParcelData.South), (int)Math.Round(parcelDivide.ParcelData.East), (int)Math.Round(parcelDivide.ParcelData.North), this);
509 }
510 break;
511 case PacketType.ParcelJoin:
512 ParcelJoinPacket parcelJoin = (ParcelJoinPacket)Pack;
513 if (OnParcelJoinRequest != null)
514 {
515 OnParcelJoinRequest((int)Math.Round(parcelJoin.ParcelData.West), (int)Math.Round(parcelJoin.ParcelData.South), (int)Math.Round(parcelJoin.ParcelData.East), (int)Math.Round(parcelJoin.ParcelData.North), this);
516 }
517 break;
518 case PacketType.ParcelPropertiesUpdate:
519 ParcelPropertiesUpdatePacket updatePacket = (ParcelPropertiesUpdatePacket)Pack;
520 if (OnParcelPropertiesUpdateRequest != null)
521 {
522 OnParcelPropertiesUpdateRequest(updatePacket, this);
523 }
524 break;
525 #endregion
526
527 #region Estate Packets
528 case PacketType.EstateOwnerMessage:
529 EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
530 if (OnEstateOwnerMessage != null)
531 {
532 OnEstateOwnerMessage(messagePacket, this);
533 }
534 break;
535 #endregion
536
537 #region unimplemented handlers
538 case PacketType.AgentIsNowWearing:
539 // AgentIsNowWearingPacket wear = (AgentIsNowWearingPacket)Pack;
540 //Console.WriteLine(Pack.ToString());
541 break;
542 case PacketType.ObjectScale:
543 //OpenSim.Framework.Console.MainLog.Instance.Verbose( Pack.ToString());
544 break;
545 #endregion
546 }
547 }
548 }
549 }
550}