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