ClientView.ProcessPackets.cs 24 KB

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