aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/ClientView.ProcessPackets.cs
diff options
context:
space:
mode:
authorMW2007-05-21 16:06:58 +0000
committerMW2007-05-21 16:06:58 +0000
commitfe46b045f75dec5ecdd0a29273c70df3e6ea540e (patch)
tree554c0fb47e513fc6a89f496d99b7b67de24edde7 /OpenSim.RegionServer/ClientView.ProcessPackets.cs
parentIncreased version number to 0.2! ZOMG! (diff)
downloadopensim-SC_OLD-fe46b045f75dec5ecdd0a29273c70df3e6ea540e.zip
opensim-SC_OLD-fe46b045f75dec5ecdd0a29273c70df3e6ea540e.tar.gz
opensim-SC_OLD-fe46b045f75dec5ecdd0a29273c70df3e6ea540e.tar.bz2
opensim-SC_OLD-fe46b045f75dec5ecdd0a29273c70df3e6ea540e.tar.xz
Start of a redesign of SimClient (now renamed ClientView)/World/Avatar/Prim , switching to a event based system (World/Avatar register as event handlers). It is possible that I've broke something with this commit but it doesn't matter as I'll just hide and no one will find me.
Diffstat (limited to 'OpenSim.RegionServer/ClientView.ProcessPackets.cs')
-rw-r--r--OpenSim.RegionServer/ClientView.ProcessPackets.cs443
1 files changed, 443 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/ClientView.ProcessPackets.cs b/OpenSim.RegionServer/ClientView.ProcessPackets.cs
new file mode 100644
index 0000000..0079d96
--- /dev/null
+++ b/OpenSim.RegionServer/ClientView.ProcessPackets.cs
@@ -0,0 +1,443 @@
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 ChatFromViewer(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID);
24
25
26 public event ChatFromViewer OnChatFromViewer;
27
28 protected override void ProcessInPacket(Packet Pack)
29 {
30 ack_pack(Pack);
31 if (debug)
32 {
33 if (Pack.Type != PacketType.AgentUpdate)
34 {
35 Console.WriteLine(Pack.Type.ToString());
36 }
37 }
38
39 if (this.ProcessPacketMethod(Pack))
40 {
41 //there is a handler registered that handled this packet type
42 return;
43 }
44 else
45 {
46 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
47
48 switch (Pack.Type)
49 {
50 #region New Event system
51 case PacketType.ChatFromViewer:
52 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
53 if (Util.FieldToString(inchatpack.ChatData.Message) == "")
54 {
55 //empty message so don't bother with it
56 break;
57 }
58 string fromName = ClientAvatar.firstname + " " + ClientAvatar.lastname;
59 byte[] message = inchatpack.ChatData.Message;
60 byte type = inchatpack.ChatData.Type;
61 LLVector3 fromPos = ClientAvatar.Pos;
62 LLUUID fromAgentID = AgentID;
63 this.OnChatFromViewer(message, type, fromPos, fromName, fromAgentID);
64 break;
65 #endregion
66
67 #region World/Avatar/Primitive related packets
68 case PacketType.CompleteAgentMovement:
69 if (this.m_child) this.UpgradeClient();
70 ClientAvatar.CompleteMovement(m_world);
71 ClientAvatar.SendInitialPosition();
72 this.EnableNeighbours();
73 break;
74 case PacketType.RegionHandshakeReply:
75 m_world.SendLayerData(this);
76 break;
77 case PacketType.AgentWearablesRequest:
78 ClientAvatar.SendInitialAppearance();
79 foreach (ClientView client in m_clientThreads.Values)
80 {
81 if (client.AgentID != this.AgentID)
82 {
83 ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket();
84 this.OutPacket(objupdate);
85 client.ClientAvatar.SendAppearanceToOtherAgent(this.ClientAvatar);
86 }
87 }
88 m_world.GetInitialPrims(this);
89 break;
90 case PacketType.AgentIsNowWearing:
91 AgentIsNowWearingPacket wear = (AgentIsNowWearingPacket)Pack;
92 //Console.WriteLine(Pack.ToString());
93 break;
94 case PacketType.AgentSetAppearance:
95 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
96 // Console.WriteLine(appear.ToString());
97 this.ClientAvatar.SetAppearance(appear);
98 break;
99 case PacketType.ObjectAdd:
100 m_world.AddNewPrim((ObjectAddPacket)Pack, this);
101 break;
102 case PacketType.ObjectLink:
103 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, Pack.ToString());
104 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
105 uint parentprimid = 0;
106 OpenSim.world.Primitive parentprim = null;
107 if (link.ObjectData.Length > 1)
108 {
109 parentprimid = link.ObjectData[0].ObjectLocalID;
110 foreach (Entity ent in m_world.Entities.Values)
111 {
112 if (ent.localid == parentprimid)
113 {
114 parentprim = (OpenSim.world.Primitive)ent;
115
116 }
117 }
118 for (int i = 1; i < link.ObjectData.Length; i++)
119 {
120 foreach (Entity ent in m_world.Entities.Values)
121 {
122 if (ent.localid == link.ObjectData[i].ObjectLocalID)
123 {
124 ((OpenSim.world.Primitive)ent).MakeParent(parentprim);
125 }
126 }
127 }
128 }
129 break;
130 case PacketType.ObjectScale:
131 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, Pack.ToString());
132 break;
133 case PacketType.ObjectShape:
134 ObjectShapePacket shape = (ObjectShapePacket)Pack;
135 for (int i = 0; i < shape.ObjectData.Length; i++)
136 {
137 foreach (Entity ent in m_world.Entities.Values)
138 {
139 if (ent.localid == shape.ObjectData[i].ObjectLocalID)
140 {
141 ((OpenSim.world.Primitive)ent).UpdateShape(shape.ObjectData[i]);
142 }
143 }
144 }
145 break;
146 case PacketType.AgentUpdate:
147 ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack);
148 break;
149 case PacketType.ObjectImage:
150 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
151 for (int i = 0; i < imagePack.ObjectData.Length; i++)
152 {
153 foreach (Entity ent in m_world.Entities.Values)
154 {
155 if (ent.localid == imagePack.ObjectData[i].ObjectLocalID)
156 {
157 ((OpenSim.world.Primitive)ent).UpdateTexture(imagePack.ObjectData[i].TextureEntry);
158 }
159 }
160 }
161 break;
162 case PacketType.ObjectFlagUpdate:
163 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
164 foreach (Entity ent in m_world.Entities.Values)
165 {
166 if (ent.localid == flags.AgentData.ObjectLocalID)
167 {
168 ((OpenSim.world.Primitive)ent).UpdateObjectFlags(flags);
169 }
170 }
171 break;
172 case PacketType.AgentAnimation:
173 if (!m_child)
174 {
175 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
176 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
177 {
178 if (AgentAni.AnimationList[i].StartAnim)
179 {
180 ClientAvatar.current_anim = AgentAni.AnimationList[i].AnimID;
181 ClientAvatar.anim_seq = 1;
182 ClientAvatar.SendAnimPack();
183 }
184 }
185 }
186 break;
187 case PacketType.ObjectSelect:
188 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
189 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
190 {
191 foreach (Entity ent in m_world.Entities.Values)
192 {
193 if (ent.localid == incomingselect.ObjectData[i].ObjectLocalID)
194 {
195 ((OpenSim.world.Primitive)ent).GetProperites(this);
196 break;
197 }
198 }
199 }
200 break;
201 case PacketType.ViewerEffect:
202 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
203 foreach (ClientView client in m_clientThreads.Values)
204 {
205 if (client.AgentID != this.AgentID)
206 {
207 viewer.AgentData.AgentID = client.AgentID;
208 viewer.AgentData.SessionID = client.SessionID;
209 client.OutPacket(viewer);
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 }
441 }
442 }
443}