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