aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs519
1 files changed, 519 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs b/OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs
new file mode 100644
index 0000000..b07749e
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Client/ClientView.ProcessPackets.cs
@@ -0,0 +1,519 @@
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.RegionServer.Simulator;
44using OpenSim.RegionServer.Assets;
45using OpenSim.Framework.Console;
46
47namespace OpenSim.RegionServer.Client
48{
49 public partial class ClientView
50 {
51 public delegate void GenericCall(ClientView remoteClient);
52 public delegate void GenericCall2();
53 public delegate void GenericCall3(Packet packet); // really don't want to be passing packets in these events, so this is very temporary.
54 public delegate void GenericCall4(Packet packet, ClientView remoteClient);
55 public delegate void UpdateShape(uint localID, ObjectShapePacket.ObjectDataBlock shapeBlock);
56 public delegate void ObjectSelect(uint localID, ClientView remoteClient);
57 public delegate void UpdatePrimFlags(uint localID, Packet packet, ClientView remoteClient);
58 public delegate void UpdatePrimTexture(uint localID, byte[] texture, ClientView remoteClient);
59 public delegate void UpdatePrimVector(uint localID, LLVector3 pos, ClientView remoteClient);
60 public delegate void UpdatePrimRotation(uint localID, LLQuaternion rot, ClientView remoteClient);
61 public delegate void StatusChange(bool status);
62
63
64 public event ChatFromViewer OnChatFromViewer;
65 public event RezObject OnRezObject;
66 public event GenericCall4 OnDeRezObject;
67 public event ModifyTerrain OnModifyTerrain;
68 public event GenericCall OnRegionHandShakeReply;
69 public event GenericCall OnRequestWearables;
70 public event SetAppearance OnSetAppearance;
71 public event GenericCall2 OnCompleteMovementToRegion;
72 public event GenericCall3 OnAgentUpdate;
73 public event StartAnim OnStartAnim;
74 public event GenericCall OnRequestAvatarsData;
75 public event LinkObjects OnLinkObjects;
76 public event GenericCall4 OnAddPrim;
77 public event UpdateShape OnUpdatePrimShape;
78 public event ObjectSelect OnObjectSelect;
79 public event UpdatePrimFlags OnUpdatePrimFlags;
80 public event UpdatePrimTexture OnUpdatePrimTexture;
81 public event UpdatePrimVector OnUpdatePrimPosition;
82 public event UpdatePrimRotation OnUpdatePrimRotation;
83 public event UpdatePrimVector OnUpdatePrimScale;
84 public event StatusChange OnChildAgentStatus;
85
86 public event ParcelPropertiesRequest OnParcelPropertiesRequest;
87 public event ParcelDivideRequest OnParcelDivideRequest;
88 public event ParcelJoinRequest OnParcelJoinRequest;
89 public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
90
91 protected override void ProcessInPacket(Packet Pack)
92 {
93 ack_pack(Pack);
94 debug = true;
95 if (debug)
96 {
97 if (Pack.Type != PacketType.AgentUpdate)
98 {
99 Console.WriteLine("IN: " + Pack.Type.ToString());
100 }
101 }
102
103
104 if (this.ProcessPacketMethod(Pack))
105 {
106 //there is a handler registered that handled this packet type
107 return;
108 }
109 else
110 {
111 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
112
113 switch (Pack.Type)
114 {
115 case PacketType.ViewerEffect:
116 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
117 foreach (ClientView client in m_clientThreads.Values)
118 {
119 if (client.AgentID != this.AgentID)
120 {
121 viewer.AgentData.AgentID = client.AgentID;
122 viewer.AgentData.SessionID = client.SessionID;
123 client.OutPacket(viewer);
124 }
125 }
126 break;
127
128 #region New Event System - World/Avatar
129 case PacketType.ChatFromViewer:
130 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
131 if (Util.FieldToString(inchatpack.ChatData.Message) == "")
132 {
133 //empty message so don't bother with it
134 break;
135 }
136 string fromName = ClientAvatar.firstname + " " + ClientAvatar.lastname;
137 byte[] message = inchatpack.ChatData.Message;
138 byte type = inchatpack.ChatData.Type;
139 LLVector3 fromPos = ClientAvatar.Pos;
140 LLUUID fromAgentID = AgentID;
141 this.OnChatFromViewer(message, type, fromPos, fromName, fromAgentID);
142 break;
143 case PacketType.RezObject:
144 RezObjectPacket rezPacket = (RezObjectPacket)Pack;
145 AgentInventory inven = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
146 if (inven != null)
147 {
148 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
149 {
150 AssetBase asset = this.m_assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
151 if (asset != null)
152 {
153 this.OnRezObject(asset, rezPacket.RezData.RayEnd);
154 this.m_inventoryCache.DeleteInventoryItem(this, rezPacket.InventoryData.ItemID);
155 }
156 }
157 }
158 break;
159 case PacketType.DeRezObject:
160 OnDeRezObject(Pack, this);
161 break;
162 case PacketType.ModifyLand:
163 ModifyLandPacket modify = (ModifyLandPacket)Pack;
164 if (modify.ParcelData.Length > 0)
165 {
166 OnModifyTerrain(modify.ModifyBlock.Action, modify.ParcelData[0].North, modify.ParcelData[0].West);
167 }
168 break;
169 case PacketType.RegionHandshakeReply:
170 OnRegionHandShakeReply(this);
171 break;
172 case PacketType.AgentWearablesRequest:
173 OnRequestWearables(this);
174 OnRequestAvatarsData(this);
175 break;
176 case PacketType.AgentSetAppearance:
177 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
178 OnSetAppearance(appear.ObjectData.TextureEntry, appear.VisualParam);
179 break;
180 case PacketType.CompleteAgentMovement:
181 if (this.m_child) this.UpgradeClient();
182 OnCompleteMovementToRegion();
183 this.EnableNeighbours();
184 break;
185 case PacketType.AgentUpdate:
186 OnAgentUpdate(Pack);
187 break;
188 case PacketType.AgentAnimation:
189 if (!m_child)
190 {
191 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
192 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
193 {
194 if (AgentAni.AnimationList[i].StartAnim)
195 {
196 OnStartAnim(AgentAni.AnimationList[i].AnimID, 1);
197 }
198 }
199 }
200 break;
201
202 #endregion
203
204 #region New Event System - Objects/Prims
205 case PacketType.ObjectLink:
206 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
207 uint parentprimid = 0;
208 List<uint> childrenprims = new List<uint>();
209 if (link.ObjectData.Length > 1)
210 {
211 parentprimid = link.ObjectData[0].ObjectLocalID;
212
213 for (int i = 1; i < link.ObjectData.Length; i++)
214 {
215 childrenprims.Add(link.ObjectData[i].ObjectLocalID);
216 }
217 }
218 OnLinkObjects(parentprimid, childrenprims);
219 break;
220 case PacketType.ObjectAdd:
221 m_world.AddNewPrim((ObjectAddPacket)Pack, this);
222 OnAddPrim(Pack, this);
223 break;
224 case PacketType.ObjectShape:
225 ObjectShapePacket shape = (ObjectShapePacket)Pack;
226 for (int i = 0; i < shape.ObjectData.Length; i++)
227 {
228 OnUpdatePrimShape(shape.ObjectData[i].ObjectLocalID, shape.ObjectData[i]);
229 }
230 break;
231 case PacketType.ObjectSelect:
232 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
233 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
234 {
235 OnObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
236 }
237 break;
238 case PacketType.ObjectFlagUpdate:
239 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
240 OnUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
241 break;
242 case PacketType.ObjectImage:
243 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
244 for (int i = 0; i < imagePack.ObjectData.Length; i++)
245 {
246 OnUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID, imagePack.ObjectData[i].TextureEntry, this);
247
248 }
249 break;
250 #endregion
251
252 #region Inventory/Asset/Other related packets
253 case PacketType.RequestImage:
254 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
255 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
256 {
257 m_assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image);
258 }
259 break;
260 case PacketType.TransferRequest:
261 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
262 m_assetCache.AddAssetRequest(this, transfer);
263 break;
264 case PacketType.AssetUploadRequest:
265 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
266 this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID));
267 break;
268 case PacketType.RequestXfer:
269 break;
270 case PacketType.SendXferPacket:
271 this.UploadAssets.HandleXferPacket((SendXferPacketPacket)Pack);
272 break;
273 case PacketType.CreateInventoryFolder:
274 CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
275 m_inventoryCache.CreateNewInventoryFolder(this, invFolder.FolderData.FolderID, (ushort)invFolder.FolderData.Type, Util.FieldToString(invFolder.FolderData.Name), invFolder.FolderData.ParentID);
276 break;
277 case PacketType.CreateInventoryItem:
278 CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
279 if (createItem.InventoryBlock.TransactionID != LLUUID.Zero)
280 {
281 this.UploadAssets.CreateInventoryItem(createItem);
282 }
283 else
284 {
285 this.CreateInventoryItem(createItem);
286 }
287 break;
288 case PacketType.FetchInventory:
289 FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack;
290 m_inventoryCache.FetchInventory(this, FetchInventory);
291 break;
292 case PacketType.FetchInventoryDescendents:
293 FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
294 m_inventoryCache.FetchInventoryDescendents(this, Fetch);
295 break;
296 case PacketType.UpdateInventoryItem:
297 UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
298 for (int i = 0; i < update.InventoryData.Length; i++)
299 {
300 if (update.InventoryData[i].TransactionID != LLUUID.Zero)
301 {
302 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID));
303 if (asset != null)
304 {
305 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
306 }
307 else
308 {
309 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
310 if (asset != null)
311 {
312 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
313 }
314 else
315 {
316
317 }
318 }
319 }
320 else
321 {
322 m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
323 }
324 }
325 break;
326 case PacketType.RequestTaskInventory:
327 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
328 ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket();
329 bool foundent = false;
330 foreach (Entity ent in m_world.Entities.Values)
331 {
332 if (ent.localid == requesttask.InventoryData.LocalID)
333 {
334 replytask.InventoryData.TaskID = ent.uuid;
335 replytask.InventoryData.Serial = 0;
336 replytask.InventoryData.Filename = new byte[0];
337 foundent = true;
338 }
339 }
340 if (foundent)
341 {
342 this.OutPacket(replytask);
343 }
344 break;
345 case PacketType.UpdateTaskInventory:
346 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
347 AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
348 if (myinventory != null)
349 {
350 if (updatetask.UpdateData.Key == 0)
351 {
352 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID] != null)
353 {
354 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID].Type == 7)
355 {
356 LLUUID noteaid = myinventory.InventoryItems[updatetask.InventoryData.ItemID].AssetID;
357 AssetBase assBase = this.m_assetCache.GetAsset(noteaid);
358 if (assBase != null)
359 {
360 foreach (Entity ent in m_world.Entities.Values)
361 {
362 if (ent.localid == updatetask.UpdateData.LocalID)
363 {
364 if (ent is OpenSim.RegionServer.Simulator.Primitive)
365 {
366 this.m_world.AddScript(ent, Util.FieldToString(assBase.Data));
367 }
368 }
369 }
370 }
371 }
372 }
373 }
374 }
375 break;
376 case PacketType.MapLayerRequest:
377 // This be busted.
378 MapLayerRequestPacket MapRequest = (MapLayerRequestPacket)Pack;
379 this.RequestMapLayer();
380 this.RequestMapBlocks((int)this.m_regionData.RegionLocX - 5, (int)this.m_regionData.RegionLocY - 5, (int)this.m_regionData.RegionLocX + 5, (int)this.m_regionData.RegionLocY + 5);
381 break;
382
383 case PacketType.MapBlockRequest:
384 MapBlockRequestPacket MapBRequest = (MapBlockRequestPacket)Pack;
385 this.RequestMapBlocks(MapBRequest.PositionData.MinX, MapBRequest.PositionData.MinY, MapBRequest.PositionData.MaxX, MapBRequest.PositionData.MaxY);
386 break;
387
388 case PacketType.MapNameRequest:
389 // TODO.
390 break;
391
392 case PacketType.TeleportLandmarkRequest:
393 TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
394
395 TeleportStartPacket tpStart = new TeleportStartPacket();
396 tpStart.Info.TeleportFlags = 8; // tp via lm
397 this.OutPacket(tpStart);
398
399 TeleportProgressPacket tpProgress = new TeleportProgressPacket();
400 tpProgress.Info.Message = (new System.Text.ASCIIEncoding()).GetBytes("sending_landmark");
401 tpProgress.Info.TeleportFlags = 8;
402 tpProgress.AgentData.AgentID = tpReq.Info.AgentID;
403 this.OutPacket(tpProgress);
404
405 // Fetch landmark
406 LLUUID lmid = tpReq.Info.LandmarkID;
407 AssetBase lma = this.m_assetCache.GetAsset(lmid);
408 if (lma != null)
409 {
410 AssetLandmark lm = new AssetLandmark(lma);
411
412 if (lm.RegionID == m_regionData.SimUUID)
413 {
414 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
415
416 tpLocal.Info.AgentID = tpReq.Info.AgentID;
417 tpLocal.Info.TeleportFlags = 8; // Teleport via landmark
418 tpLocal.Info.LocationID = 2;
419 tpLocal.Info.Position = lm.Position;
420 OutPacket(tpLocal);
421 }
422 else
423 {
424 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
425 tpCancel.Info.AgentID = tpReq.Info.AgentID;
426 tpCancel.Info.SessionID = tpReq.Info.SessionID;
427 OutPacket(tpCancel);
428 }
429 }
430 else
431 {
432 Console.WriteLine("Cancelling Teleport - fetch asset not yet implemented");
433
434 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
435 tpCancel.Info.AgentID = tpReq.Info.AgentID;
436 tpCancel.Info.SessionID = tpReq.Info.SessionID;
437 OutPacket(tpCancel);
438 }
439 break;
440 case PacketType.TeleportLocationRequest:
441 TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
442 Console.WriteLine(tpLocReq.ToString());
443
444 tpStart = new TeleportStartPacket();
445 tpStart.Info.TeleportFlags = 16; // Teleport via location
446 Console.WriteLine(tpStart.ToString());
447 OutPacket(tpStart);
448
449 if (m_regionData.RegionHandle != tpLocReq.Info.RegionHandle)
450 {
451 /* m_gridServer.getRegion(tpLocReq.Info.RegionHandle); */
452 Console.WriteLine("Inter-sim teleport not yet implemented");
453 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
454 tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
455 tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
456
457 OutPacket(tpCancel);
458 }
459 else
460 {
461 Console.WriteLine("Local teleport");
462 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
463 tpLocal.Info.AgentID = tpLocReq.AgentData.AgentID;
464 tpLocal.Info.TeleportFlags = tpStart.Info.TeleportFlags;
465 tpLocal.Info.LocationID = 2;
466 tpLocal.Info.LookAt = tpLocReq.Info.LookAt;
467 tpLocal.Info.Position = tpLocReq.Info.Position;
468 OutPacket(tpLocal);
469
470 }
471 break;
472 #endregion
473
474 #region Parcel Packets
475 case PacketType.ParcelPropertiesRequest:
476 ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
477 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);
478 break;
479 case PacketType.ParcelDivide:
480 ParcelDividePacket parcelDivide = (ParcelDividePacket)Pack;
481 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);
482 break;
483 case PacketType.ParcelJoin:
484 ParcelJoinPacket parcelJoin = (ParcelJoinPacket)Pack;
485 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);
486 break;
487 case PacketType.ParcelPropertiesUpdate:
488 ParcelPropertiesUpdatePacket updatePacket = (ParcelPropertiesUpdatePacket)Pack;
489 OnParcelPropertiesUpdateRequest(updatePacket, this);
490 break;
491 #endregion
492
493 #region unimplemented handlers
494 case PacketType.AgentIsNowWearing:
495 // AgentIsNowWearingPacket wear = (AgentIsNowWearingPacket)Pack;
496 break;
497 case PacketType.ObjectScale:
498 break;
499 case PacketType.MoneyBalanceRequest:
500 //This need to be actually done and not thrown back with fake infos
501 break;
502
503 case PacketType.EstateCovenantRequest:
504 //This should be actually done and not thrown back with fake info
505 EstateCovenantRequestPacket estateCovenantRequest = (EstateCovenantRequestPacket)Pack;
506 EstateCovenantReplyPacket estateCovenantReply = new EstateCovenantReplyPacket();
507 estateCovenantReply.Data.EstateName = libsecondlife.Helpers.StringToField("Leet Estate");
508 estateCovenantReply.Data.EstateOwnerID = LLUUID.Zero;
509 estateCovenantReply.Data.CovenantID = LLUUID.Zero;
510 estateCovenantReply.Data.CovenantTimestamp = (uint)0;
511 this.OutPacket((Packet)estateCovenantReply);
512 MainConsole.Instance.Notice("Sent Temporary Estate packet (they are in leet estate)");
513 break;
514 #endregion
515 }
516 }
517 }
518 }
519}