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