PageRenderTime 81ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 3ms

/Aurora/ClientStack/LLClientView.cs

https://bitbucket.org/VirtualReality/async-sim-testing
C# | 10397 lines | 8339 code | 1512 blank | 546 comment | 1349 complexity | 50eea75bbf5beee320f42e3fd095fa23 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the Aurora-Sim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using Aurora.Framework;
  28. using Aurora.Framework.ClientInterfaces;
  29. using Aurora.Framework.ConsoleFramework;
  30. using Aurora.Framework.Modules;
  31. using Aurora.Framework.PresenceInfo;
  32. using Aurora.Framework.SceneInfo;
  33. using Aurora.Framework.SceneInfo.Entities;
  34. using Aurora.Framework.Services;
  35. using Aurora.Framework.Services.ClassHelpers.Assets;
  36. using Aurora.Framework.Services.ClassHelpers.Inventory;
  37. using Aurora.Framework.Utilities;
  38. using Nini.Config;
  39. using OpenMetaverse;
  40. using OpenMetaverse.Messages.Linden;
  41. using OpenMetaverse.Packets;
  42. using OpenMetaverse.StructuredData;
  43. using System;
  44. using System.Collections.Generic;
  45. using System.Linq;
  46. using System.Net;
  47. using System.Threading;
  48. using System.Xml;
  49. using RegionFlags = OpenMetaverse.RegionFlags;
  50. namespace Aurora.ClientStack
  51. {
  52. public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
  53. /// <summary>
  54. /// Handles new client connections
  55. /// Constructor takes a single Packet and authenticates everything
  56. /// </summary>
  57. public sealed class LLClientView : IClientAPI, IStatsCollector
  58. {
  59. /// <value>
  60. /// Debug packet level. See OpenSim.RegisterConsoleCommands() for more details.
  61. /// </value>
  62. private int m_debugPacketLevel;
  63. private readonly bool m_allowUDPInv;
  64. #region Events
  65. public event BinaryGenericMessage OnBinaryGenericMessage;
  66. public event Action<IClientAPI> OnLogout;
  67. public event ObjectPermissions OnObjectPermissions;
  68. public event Action<IClientAPI> OnConnectionClosed;
  69. public event ViewerEffectEventHandler OnViewerEffect;
  70. public event ImprovedInstantMessage OnInstantMessage;
  71. public event PreSendImprovedInstantMessage OnPreSendInstantMessage;
  72. public event ChatMessage OnChatFromClient;
  73. public event RezObject OnRezObject;
  74. public event DeRezObject OnDeRezObject;
  75. public event ModifyTerrain OnModifyTerrain;
  76. public event Action<IClientAPI> OnRegionHandShakeReply;
  77. public event GenericCall1 OnRequestWearables;
  78. public event SetAppearance OnSetAppearance;
  79. public event AvatarNowWearing OnAvatarNowWearing;
  80. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  81. public event UUIDNameRequest OnDetachAttachmentIntoInv;
  82. public event ObjectAttach OnObjectAttach;
  83. public event ObjectDeselect OnObjectDetach;
  84. public event ObjectDrop OnObjectDrop;
  85. public event GenericCall1 OnCompleteMovementToRegion;
  86. public event UpdateAgent OnAgentUpdate;
  87. public event AgentRequestSit OnAgentRequestSit;
  88. public event AgentSit OnAgentSit;
  89. public event AvatarPickerRequest OnAvatarPickerRequest;
  90. public event StartAnim OnStartAnim;
  91. public event StopAnim OnStopAnim;
  92. public event Action<IClientAPI> OnRequestAvatarsData;
  93. public event LinkObjects OnLinkObjects;
  94. public event DelinkObjects OnDelinkObjects;
  95. public event GrabObject OnGrabObject;
  96. public event DeGrabObject OnDeGrabObject;
  97. public event SpinStart OnSpinStart;
  98. public event SpinStop OnSpinStop;
  99. public event ObjectDuplicate OnObjectDuplicate;
  100. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  101. public event MoveObject OnGrabUpdate;
  102. public event SpinObject OnSpinUpdate;
  103. public event AddNewPrim OnAddPrim;
  104. public event RequestGodlikePowers OnRequestGodlikePowers;
  105. public event GodKickUser OnGodKickUser;
  106. public event ObjectExtraParams OnUpdateExtraParams;
  107. public event UpdateShape OnUpdatePrimShape;
  108. public event ObjectRequest OnObjectRequest;
  109. public event ObjectSelect OnObjectSelect;
  110. public event ObjectDeselect OnObjectDeselect;
  111. public event GenericCall7 OnObjectDescription;
  112. public event GenericCall7 OnObjectName;
  113. public event GenericCall7 OnObjectClickAction;
  114. public event GenericCall7 OnObjectMaterial;
  115. public event ObjectIncludeInSearch OnObjectIncludeInSearch;
  116. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  117. public event UpdatePrimFlags OnUpdatePrimFlags;
  118. public event UpdatePrimTexture OnUpdatePrimTexture;
  119. public event UpdateVectorWithUpdate OnUpdatePrimGroupPosition;
  120. public event UpdateVectorWithUpdate OnUpdatePrimSinglePosition;
  121. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  122. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  123. public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
  124. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  125. public event UpdateVector OnUpdatePrimScale;
  126. public event UpdateVector OnUpdatePrimGroupScale;
  127. #pragma warning disable 67
  128. public event StatusChange OnChildAgentStatus;
  129. public event GenericMessage OnGenericMessage;
  130. public event BuyObjectInventory OnBuyObjectInventory;
  131. public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
  132. #pragma warning restore 67
  133. public event RequestMapBlocks OnRequestMapBlocks;
  134. public event RequestMapName OnMapNameRequest;
  135. public event TeleportLocationRequest OnTeleportLocationRequest;
  136. public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
  137. public event RequestAvatarProperties OnRequestAvatarProperties;
  138. public event SetAlwaysRun OnSetAlwaysRun;
  139. public event FetchInventory OnAgentDataUpdateRequest;
  140. public event TeleportLocationRequest OnSetStartLocationRequest;
  141. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  142. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  143. public event LinkInventoryItem OnLinkInventoryItem;
  144. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  145. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  146. public event MoveInventoryFolder OnMoveInventoryFolder;
  147. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  148. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  149. public event FetchInventory OnFetchInventory;
  150. public event RequestTaskInventory OnRequestTaskInventory;
  151. public event UpdateInventoryItem OnUpdateInventoryItem;
  152. public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
  153. public event CopyInventoryItem OnCopyInventoryItem;
  154. public event MoveInventoryItem OnMoveInventoryItem;
  155. public event RemoveInventoryItem OnRemoveInventoryItem;
  156. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  157. public event UDPAssetUploadRequest OnAssetUploadRequest;
  158. public event XferReceive OnXferReceive;
  159. public event RequestXfer OnRequestXfer;
  160. public event ConfirmXfer OnConfirmXfer;
  161. public event AbortXfer OnAbortXfer;
  162. public event RequestTerrain OnRequestTerrain;
  163. public event RezScript OnRezScript;
  164. public event UpdateTaskInventory OnUpdateTaskInventory;
  165. public event MoveTaskInventory OnMoveTaskItem;
  166. public event RemoveTaskInventory OnRemoveTaskItem;
  167. public event UUIDNameRequest OnNameFromUUIDRequest;
  168. public event ParcelAccessListRequest OnParcelAccessListRequest;
  169. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  170. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  171. public event ParcelDivideRequest OnParcelDivideRequest;
  172. public event ParcelJoinRequest OnParcelJoinRequest;
  173. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  174. public event ParcelSelectObjects OnParcelSelectObjects;
  175. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  176. public event ParcelAbandonRequest OnParcelAbandonRequest;
  177. public event ParcelGodForceOwner OnParcelGodForceOwner;
  178. public event ParcelReclaim OnParcelReclaim;
  179. public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
  180. public event ParcelReturnObjectsRequest OnParcelDisableObjectsRequest;
  181. public event ParcelDeedToGroup OnParcelDeedToGroup;
  182. public event RegionInfoRequest OnRegionInfoRequest;
  183. public event EstateCovenantRequest OnEstateCovenantRequest;
  184. public event FriendActionDelegate OnApproveFriendRequest;
  185. public event FriendActionDelegate OnDenyFriendRequest;
  186. public event FriendshipTermination OnTerminateFriendship;
  187. public event GrantUserFriendRights OnGrantUserRights;
  188. public event MoneyTransferRequest OnMoneyTransferRequest;
  189. public event EconomyDataRequest OnEconomyDataRequest;
  190. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  191. public event ParcelBuy OnParcelBuy;
  192. public event UUIDNameRequest OnTeleportHomeRequest;
  193. public event UUIDNameRequest OnUUIDGroupNameRequest;
  194. public event ScriptAnswer OnScriptAnswer;
  195. public event RequestPayPrice OnRequestPayPrice;
  196. public event ObjectSaleInfo OnObjectSaleInfo;
  197. public event ObjectBuy OnObjectBuy;
  198. public event AgentSit OnUndo;
  199. public event AgentSit OnRedo;
  200. public event LandUndo OnLandUndo;
  201. public event ForceReleaseControls OnForceReleaseControls;
  202. public event GodLandStatRequest OnLandStatRequest;
  203. public event RequestObjectPropertiesFamily OnObjectGroupRequest;
  204. public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
  205. public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
  206. public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
  207. public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
  208. public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
  209. public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
  210. public event BakeTerrain OnBakeTerrain;
  211. public event RequestTerrain OnUploadTerrain;
  212. public event EstateChangeInfo OnEstateChangeInfo;
  213. public event EstateRestartSimRequest OnEstateRestartSimRequest;
  214. public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
  215. public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
  216. public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
  217. public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
  218. public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
  219. public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
  220. public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
  221. public event RegionHandleRequest OnRegionHandleRequest;
  222. public event ParcelInfoRequest OnParcelInfoRequest;
  223. public event ScriptReset OnScriptReset;
  224. public event GetScriptRunning OnGetScriptRunning;
  225. public event SetScriptRunning OnSetScriptRunning;
  226. public event UpdateVector OnAutoPilotGo;
  227. public event ActivateGesture OnActivateGesture;
  228. public event DeactivateGesture OnDeactivateGesture;
  229. public event ObjectOwner OnObjectOwner;
  230. public event DirPlacesQuery OnDirPlacesQuery;
  231. public event DirFindQuery OnDirFindQuery;
  232. public event DirLandQuery OnDirLandQuery;
  233. public event DirPopularQuery OnDirPopularQuery;
  234. public event DirClassifiedQuery OnDirClassifiedQuery;
  235. public event EventInfoRequest OnEventInfoRequest;
  236. public event ParcelSetOtherCleanTime OnParcelSetOtherCleanTime;
  237. public event MapItemRequest OnMapItemRequest;
  238. public event OfferCallingCard OnOfferCallingCard;
  239. public event AcceptCallingCard OnAcceptCallingCard;
  240. public event DeclineCallingCard OnDeclineCallingCard;
  241. public event SoundTrigger OnSoundTrigger;
  242. public event StartLure OnStartLure;
  243. public event TeleportLureRequest OnTeleportLureRequest;
  244. public event NetworkStats OnNetworkStatsUpdate;
  245. public event ClassifiedInfoRequest OnClassifiedInfoRequest;
  246. public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
  247. public event ClassifiedDelete OnClassifiedDelete;
  248. public event ClassifiedDelete OnClassifiedGodDelete;
  249. public event EventNotificationAddRequest OnEventNotificationAddRequest;
  250. public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
  251. public event EventGodDelete OnEventGodDelete;
  252. public event ParcelDwellRequest OnParcelDwellRequest;
  253. public event UserInfoRequest OnUserInfoRequest;
  254. public event UpdateUserInfo OnUpdateUserInfo;
  255. public event RetrieveInstantMessages OnRetrieveInstantMessages;
  256. public event PickDelete OnPickDelete;
  257. public event PickGodDelete OnPickGodDelete;
  258. public event PickInfoUpdate OnPickInfoUpdate;
  259. public event AvatarNotesUpdate OnAvatarNotesUpdate;
  260. public event MuteListRequest OnMuteListRequest;
  261. public event AvatarInterestUpdate OnAvatarInterestUpdate;
  262. public event PlacesQuery OnPlacesQuery;
  263. public event AgentFOV OnAgentFOV;
  264. public event FindAgentUpdate OnFindAgent;
  265. public event TrackAgentUpdate OnTrackAgent;
  266. public event NewUserReport OnUserReport;
  267. public event SaveStateHandler OnSaveState;
  268. public event GroupAccountSummaryRequest OnGroupAccountSummaryRequest;
  269. public event GroupAccountDetailsRequest OnGroupAccountDetailsRequest;
  270. public event GroupAccountTransactionsRequest OnGroupAccountTransactionsRequest;
  271. public event FreezeUserUpdate OnParcelFreezeUser;
  272. public event EjectUserUpdate OnParcelEjectUser;
  273. public event ParcelBuyPass OnParcelBuyPass;
  274. public event ParcelGodMark OnParcelGodMark;
  275. public event GroupActiveProposalsRequest OnGroupActiveProposalsRequest;
  276. public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
  277. public event SimWideDeletesDelegate OnSimWideDeletes;
  278. public event SendPostcard OnSendPostcard;
  279. public event TeleportCancel OnTeleportCancel;
  280. public event MuteListEntryUpdate OnUpdateMuteListEntry;
  281. public event MuteListEntryRemove OnRemoveMuteListEntry;
  282. public event GodlikeMessage OnGodlikeMessage;
  283. public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
  284. public event GodlikeMessage OnEstateTelehubRequest;
  285. public event ViewerStartAuction OnViewerStartAuction;
  286. public event GroupProposalBallotRequest OnGroupProposalBallotRequest;
  287. public event AgentCachedTextureRequest OnAgentCachedTextureRequest;
  288. #endregion Events
  289. #region Enums
  290. public enum TransferPacketStatus
  291. {
  292. MorePacketsToCome = 0,
  293. Done = 1,
  294. AssetSkip = 2,
  295. AssetAbort = 3,
  296. AssetRequestFailed = -1,
  297. AssetUnknownSource = -2, // Equivalent of a 404
  298. InsufficientPermissions = -3
  299. }
  300. #endregion
  301. #region Class Members
  302. // LLClientView Only
  303. public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
  304. /// <summary>
  305. /// Used to adjust Sun Orbit values so Linden based viewers properly position sun
  306. /// </summary>
  307. private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
  308. private static readonly Dictionary<PacketType, PacketMethod> PacketHandlers =
  309. new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
  310. private readonly LLUDPServer m_udpServer;
  311. private readonly LLUDPClient m_udpClient;
  312. private readonly UUID m_sessionId;
  313. private readonly UUID m_secureSessionId;
  314. private readonly UUID m_agentId;
  315. private readonly uint m_circuitCode;
  316. private readonly byte[] m_channelVersion = Utils.EmptyBytes;
  317. private readonly Dictionary<string, UUID> m_defaultAnimations = new Dictionary<string, UUID>();
  318. private readonly IGroupsModule m_GroupsModule;
  319. private int m_cachedTextureSerial;
  320. /// <value>
  321. /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the
  322. /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
  323. /// ownerless phantom.
  324. /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock
  325. /// </value>
  326. //protected HashSet<uint> m_killRecord = new HashSet<uint>();
  327. // protected HashSet<uint> m_attachmentsSent;
  328. private int m_animationSequenceNumber = 1;
  329. private bool m_SendLogoutPacketWhenClosing = true;
  330. private AgentUpdateArgs lastarg;
  331. private bool m_IsActive = true;
  332. private readonly Dictionary<PacketType, PacketProcessor> m_packetHandlers =
  333. new Dictionary<PacketType, PacketProcessor>();
  334. private readonly Dictionary<string, GenericMessage> m_genericPacketHandlers =
  335. new Dictionary<string, GenericMessage>();
  336. //PauPaw:Local Generic Message handlers
  337. private readonly IScene m_scene;
  338. private readonly LLImageManager m_imageManager;
  339. private readonly string m_firstName;
  340. private readonly string m_lastName;
  341. private readonly string m_Name;
  342. private readonly EndPoint m_userEndPoint;
  343. private UUID m_activeGroupID;
  344. private string m_activeGroupName = String.Empty;
  345. private ulong m_activeGroupPowers;
  346. private uint m_agentFOVCounter;
  347. private readonly IAssetService m_assetService;
  348. // ReSharper disable ConvertToConstant.Local
  349. private bool m_checkPackets = true;
  350. // ReSharper restore ConvertToConstant.Local
  351. #endregion Class Members
  352. #region Properties
  353. public LLUDPClient UDPClient
  354. {
  355. get { return m_udpClient; }
  356. }
  357. public IPEndPoint RemoteEndPoint
  358. {
  359. get { return m_udpClient.RemoteEndPoint; }
  360. }
  361. public UUID SecureSessionId
  362. {
  363. get { return m_secureSessionId; }
  364. }
  365. public IScene Scene
  366. {
  367. get { return m_scene; }
  368. }
  369. public UUID SessionId
  370. {
  371. get { return m_sessionId; }
  372. }
  373. public Vector3 StartPos { get; set; }
  374. public UUID AgentId
  375. {
  376. get { return m_agentId; }
  377. }
  378. public UUID ScopeID { get; set; }
  379. public List<UUID> AllScopeIDs { get; set; }
  380. public UUID ActiveGroupId
  381. {
  382. get { return m_activeGroupID; }
  383. }
  384. public string ActiveGroupName
  385. {
  386. get { return m_activeGroupName; }
  387. }
  388. public ulong ActiveGroupPowers
  389. {
  390. get { return m_activeGroupPowers; }
  391. }
  392. /// <summary>
  393. /// First name of the agent/avatar represented by the client
  394. /// </summary>
  395. public string FirstName
  396. {
  397. get { return m_firstName; }
  398. }
  399. /// <summary>
  400. /// Last name of the agent/avatar represented by the client
  401. /// </summary>
  402. public string LastName
  403. {
  404. get { return m_lastName; }
  405. }
  406. /// <summary>
  407. /// Full name of the client (first name and last name)
  408. /// </summary>
  409. public string Name
  410. {
  411. get { return m_Name; }
  412. }
  413. public uint CircuitCode
  414. {
  415. get { return m_circuitCode; }
  416. }
  417. public int NextAnimationSequenceNumber
  418. {
  419. get { return m_animationSequenceNumber; }
  420. }
  421. public bool IsActive
  422. {
  423. get { return m_IsActive; }
  424. set { m_IsActive = value; }
  425. }
  426. public bool IsLoggingOut { get; set; }
  427. public bool SendLogoutPacketWhenClosing
  428. {
  429. set { m_SendLogoutPacketWhenClosing = value; }
  430. }
  431. #endregion Properties
  432. /// <summary>
  433. /// Constructor
  434. /// </summary>
  435. public LLClientView(EndPoint remoteEP, IScene scene, LLUDPServer udpServer, LLUDPClient udpClient,
  436. AgentCircuitData sessionInfo,
  437. UUID agentId, UUID sessionId, uint circuitCode)
  438. {
  439. InitDefaultAnimations();
  440. m_scene = scene;
  441. IConfig advancedConfig = m_scene.Config.Configs["ClientStack.LindenUDP"];
  442. if (advancedConfig != null)
  443. m_allowUDPInv = advancedConfig.GetBoolean("AllowUDPInventory", m_allowUDPInv);
  444. //m_killRecord = new HashSet<uint>();
  445. // m_attachmentsSent = new HashSet<uint>();
  446. m_assetService = m_scene.RequestModuleInterface<IAssetService>();
  447. m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
  448. m_imageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
  449. ISimulationBase simulationBase = m_scene.RequestModuleInterface<ISimulationBase>();
  450. if (simulationBase != null)
  451. m_channelVersion = Util.StringToBytes256(simulationBase.Version);
  452. m_agentId = agentId;
  453. m_sessionId = sessionId;
  454. m_secureSessionId = sessionInfo.SecureSessionID;
  455. m_circuitCode = circuitCode;
  456. m_userEndPoint = remoteEP;
  457. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.AllScopeIDs, m_agentId);
  458. if (account != null)
  459. {
  460. m_firstName = account.FirstName;
  461. m_lastName = account.LastName;
  462. m_Name = account.Name;
  463. }
  464. else
  465. {
  466. m_firstName = sessionInfo.firstname;
  467. m_lastName = sessionInfo.lastname;
  468. m_Name = sessionInfo.firstname + " " + sessionInfo.lastname;
  469. }
  470. StartPos = sessionInfo.startpos;
  471. m_udpServer = udpServer;
  472. m_udpClient = udpClient;
  473. m_udpClient.OnQueueEmpty += HandleQueueEmpty;
  474. m_udpClient.OnPacketStats += PopulateStats;
  475. RegisterLocalPacketHandlers();
  476. }
  477. public void Reset()
  478. {
  479. lastarg = null;
  480. //Reset the killObjectUpdate packet stats
  481. //m_killRecord = new HashSet<uint>();
  482. }
  483. public void SetDebugPacketLevel(int newDebug)
  484. {
  485. m_debugPacketLevel = newDebug;
  486. }
  487. #region Client Methods
  488. public void Stop()
  489. {
  490. // Send the STOP packet NOW, otherwise it doesn't get out in time
  491. DisableSimulatorPacket disable =
  492. (DisableSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  493. OutPacket(disable, ThrottleOutPacketType.Immediate);
  494. }
  495. /// <summary>
  496. /// Shut down the client view
  497. /// </summary>
  498. public void Close(bool forceClose)
  499. {
  500. //MainConsole.Instance.DebugFormat(
  501. // "[CLIENT]: Close has been called for {0} attached to scene {1}",
  502. // Name, m_scene.RegionInfo.RegionName);
  503. if (forceClose && !IsLoggingOut) //Don't send it to clients that are logging out
  504. {
  505. // Send the STOP packet NOW, otherwise it doesn't get out in time
  506. DisableSimulatorPacket disable =
  507. (DisableSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  508. OutPacket(disable, ThrottleOutPacketType.Immediate);
  509. }
  510. IsActive = false;
  511. // Shutdown the image manager
  512. if (m_imageManager != null)
  513. m_imageManager.Close();
  514. // Fire the callback for this connection closing
  515. if (OnConnectionClosed != null)
  516. OnConnectionClosed(this);
  517. // Flush all of the packets out of the UDP server for this client
  518. if (m_udpServer != null)
  519. {
  520. m_udpServer.Flush(m_udpClient);
  521. m_udpServer.RemoveClient(this);
  522. }
  523. // Disable UDP handling for this client
  524. m_udpClient.Shutdown();
  525. //MainConsole.Instance.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
  526. //GC.Collect();
  527. //MainConsole.Instance.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
  528. }
  529. public void Kick(string message)
  530. {
  531. if (!ChildAgentStatus())
  532. {
  533. KickUserPacket kupack = (KickUserPacket) PacketPool.Instance.GetPacket(PacketType.KickUser);
  534. kupack.UserInfo.AgentID = AgentId;
  535. kupack.UserInfo.SessionID = SessionId;
  536. kupack.TargetBlock.TargetIP = 0;
  537. kupack.TargetBlock.TargetPort = 0;
  538. kupack.UserInfo.Reason = Util.StringToBytes256(message);
  539. OutPacket(kupack, ThrottleOutPacketType.OutBand);
  540. // You must sleep here or users get no message!
  541. Thread.Sleep(500);
  542. }
  543. }
  544. #endregion Client Methods
  545. #region Packet Handling
  546. public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
  547. {
  548. NetworkStats handlerNetworkStatsUpdate = OnNetworkStatsUpdate;
  549. if (handlerNetworkStatsUpdate != null)
  550. {
  551. handlerNetworkStatsUpdate(inPackets, outPackets, unAckedBytes);
  552. }
  553. }
  554. public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
  555. {
  556. bool result = false;
  557. lock (PacketHandlers)
  558. {
  559. if (!PacketHandlers.ContainsKey(packetType))
  560. {
  561. PacketHandlers.Add(packetType, handler);
  562. result = true;
  563. }
  564. }
  565. return result;
  566. }
  567. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  568. {
  569. return AddLocalPacketHandler(packetType, handler, true);
  570. }
  571. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler, bool runasync)
  572. {
  573. bool result = false;
  574. lock (m_packetHandlers)
  575. {
  576. if (!m_packetHandlers.ContainsKey(packetType))
  577. {
  578. m_packetHandlers.Add(packetType, new PacketProcessor {method = handler, Async = runasync});
  579. result = true;
  580. }
  581. }
  582. return result;
  583. }
  584. public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
  585. {
  586. MethodName = MethodName.ToLower().Trim();
  587. bool result = false;
  588. lock (m_genericPacketHandlers)
  589. {
  590. if (!m_genericPacketHandlers.ContainsKey(MethodName))
  591. {
  592. m_genericPacketHandlers.Add(MethodName, handler);
  593. result = true;
  594. }
  595. }
  596. return result;
  597. }
  598. public bool RemoveGenericPacketHandler(string MethodName)
  599. {
  600. MethodName = MethodName.ToLower().Trim();
  601. bool result = false;
  602. lock (m_genericPacketHandlers)
  603. {
  604. if (m_genericPacketHandlers.ContainsKey(MethodName))
  605. {
  606. m_genericPacketHandlers.Remove(MethodName);
  607. result = true;
  608. }
  609. }
  610. return result;
  611. }
  612. /// <summary>
  613. /// Try to process a packet using registered packet handlers
  614. /// </summary>
  615. /// <param name="packet"></param>
  616. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  617. private bool ProcessPacketMethod(Packet packet)
  618. {
  619. bool result = false;
  620. PacketProcessor pprocessor;
  621. if (m_packetHandlers.TryGetValue(packet.Type, out pprocessor))
  622. {
  623. //there is a local handler for this packet type
  624. if (pprocessor.Async)
  625. {
  626. object obj = new AsyncPacketProcess(this, pprocessor.method, packet);
  627. m_udpServer.FireAndForget(ProcessSpecificPacketAsync, obj);
  628. result = true;
  629. }
  630. else
  631. {
  632. result = pprocessor.method(this, packet);
  633. }
  634. }
  635. else
  636. {
  637. //there is not a local handler so see if there is a Global handler
  638. PacketMethod method = null;
  639. bool found;
  640. lock (PacketHandlers)
  641. {
  642. found = PacketHandlers.TryGetValue(packet.Type, out method);
  643. }
  644. if (found)
  645. {
  646. result = method(this, packet);
  647. }
  648. }
  649. return result;
  650. }
  651. public void ProcessSpecificPacketAsync(object state)
  652. {
  653. AsyncPacketProcess packetObject = (AsyncPacketProcess) state;
  654. try
  655. {
  656. packetObject.result = packetObject.Method(packetObject.ClientView, packetObject.Pack);
  657. }
  658. catch (Exception e)
  659. {
  660. // Make sure that we see any exception caused by the asynchronous operation.
  661. MainConsole.Instance.ErrorFormat(
  662. "[LLCLIENTVIEW]: Caught exception while processing {0} for {1}, {2} {3}",
  663. packetObject.Pack, Name, e.Message, e.StackTrace);
  664. }
  665. }
  666. #endregion Packet Handling
  667. #region Scene/Avatar to Client
  668. public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
  669. {
  670. RegionHandshakePacket handshake =
  671. (RegionHandshakePacket) PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
  672. handshake.RegionInfo = new RegionHandshakePacket.RegionInfoBlock
  673. {
  674. BillableFactor = args.billableFactor,
  675. IsEstateManager = args.isEstateManager,
  676. TerrainHeightRange00 = args.terrainHeightRange0,
  677. TerrainHeightRange01 = args.terrainHeightRange1,
  678. TerrainHeightRange10 = args.terrainHeightRange2,
  679. TerrainHeightRange11 = args.terrainHeightRange3,
  680. TerrainStartHeight00 = args.terrainStartHeight0,
  681. TerrainStartHeight01 = args.terrainStartHeight1,
  682. TerrainStartHeight10 = args.terrainStartHeight2,
  683. TerrainStartHeight11 = args.terrainStartHeight3,
  684. SimAccess = args.simAccess,
  685. WaterHeight = args.waterHeight,
  686. RegionFlags = (uint) args.regionFlags,
  687. SimName = Util.StringToBytes256(args.regionName),
  688. SimOwner = args.SimOwner,
  689. TerrainBase0 = args.terrainBase0,
  690. TerrainBase1 = args.terrainBase1,
  691. TerrainBase2 = args.terrainBase2,
  692. TerrainBase3 = args.terrainBase3,
  693. TerrainDetail0 = args.terrainDetail0,
  694. TerrainDetail1 = args.terrainDetail1,
  695. TerrainDetail2 = args.terrainDetail2,
  696. TerrainDetail3 = args.terrainDetail3,
  697. CacheID = UUID.Random()
  698. };
  699. //I guess this is for the client to remember an old setting?
  700. handshake.RegionInfo2 = new RegionHandshakePacket.RegionInfo2Block {RegionID = regionInfo.RegionID};
  701. handshake.RegionInfo4 = new RegionHandshakePacket.RegionInfo4Block[1]
  702. {
  703. new RegionHandshakePacket.RegionInfo4Block
  704. {
  705. RegionFlagsExtended = args.regionFlags,
  706. RegionProtocols = (ulong) RegionProtocols.AgentAppearanceService
  707. }
  708. };
  709. handshake.RegionInfo3 = new RegionHandshakePacket.RegionInfo3Block
  710. {
  711. CPUClassID = 9,
  712. CPURatio = 1,
  713. ColoName = Utils.EmptyBytes,
  714. ProductName = Util.StringToBytes256(regionInfo.RegionType),
  715. ProductSKU = Utils.EmptyBytes
  716. };
  717. OutPacket(handshake, ThrottleOutPacketType.Task);
  718. }
  719. /// <summary>
  720. /// </summary>
  721. public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
  722. {
  723. AgentMovementCompletePacket mov =
  724. (AgentMovementCompletePacket) PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
  725. mov.SimData.ChannelVersion = m_channelVersion;
  726. mov.AgentData.SessionID = m_sessionId;
  727. mov.AgentData.AgentID = AgentId;
  728. mov.Data.RegionHandle = regInfo.RegionHandle;
  729. mov.Data.Timestamp = (uint) Util.UnixTimeSinceEpoch();
  730. mov.Data.Position = pos;
  731. mov.Data.LookAt = look;
  732. // Hack to get this out immediately and skip the throttles
  733. OutPacket(mov, ThrottleOutPacketType.OutBand);
  734. }
  735. public void SendChatMessage(string message, byte type, Vector3 fromPos, string fromName,
  736. UUID fromAgentID, byte source, byte audible)
  737. {
  738. ChatFromSimulatorPacket reply =
  739. (ChatFromSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
  740. reply.ChatData.Audible = audible;
  741. reply.ChatData.Message = Util.StringToBytes1024(message);
  742. reply.ChatData.ChatType = type;
  743. reply.ChatData.SourceType = source;
  744. reply.ChatData.Position = fromPos;
  745. reply.ChatData.FromName = Util.StringToBytes256(fromName);
  746. reply.ChatData.OwnerID = fromAgentID;
  747. reply.ChatData.SourceID = fromAgentID;
  748. //Don't split me up!
  749. reply.HasVariableBlocks = false;
  750. // Hack to get this out immediately and skip throttles
  751. OutPacket(reply, ThrottleOutPacketType.AvatarInfo);
  752. }
  753. public void SendTelehubInfo(Vector3 TelehubPos, Quaternion TelehubRot, List<Vector3> SpawnPoint, UUID ObjectID,
  754. string nameT)
  755. {
  756. TelehubInfoPacket packet = (TelehubInfoPacket) PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
  757. packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
  758. int i = 0;
  759. foreach (Vector3 pos in SpawnPoint)
  760. {
  761. packet.SpawnPointBlock[i] = new TelehubInfoPacket.SpawnPointBlockBlock {SpawnPointPos = pos};
  762. i++;
  763. }
  764. packet.TelehubBlock.ObjectID = ObjectID;
  765. packet.TelehubBlock.ObjectName = Utils.StringToBytes(nameT);
  766. packet.TelehubBlock.TelehubPos = TelehubPos;
  767. packet.TelehubBlock.TelehubRot = TelehubRot;
  768. OutPacket(packet, ThrottleOutPacketType.AvatarInfo);
  769. }
  770. /// <summary>
  771. /// Send an instant message to this client
  772. /// </summary>
  773. //
  774. // Don't remove transaction ID! Groups and item gives need to set it!
  775. public void SendInstantMessage(GridInstantMessage im)
  776. {
  777. if (m_scene.Permissions.CanInstantMessage(im.fromAgentID, im.toAgentID))
  778. {
  779. ImprovedInstantMessagePacket msg
  780. = (ImprovedInstantMessagePacket) PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
  781. msg.AgentData.AgentID = im.fromAgentID;
  782. msg.AgentData.SessionID = UUID.Zero;
  783. msg.MessageBlock.FromAgentName = Util.StringToBytes256(im.fromAgentName);
  784. msg.MessageBlock.Dialog = im.dialog;
  785. msg.MessageBlock.FromGroup = im.fromGroup;
  786. if (im.imSessionID == UUID.Zero)
  787. msg.MessageBlock.ID = im.fromAgentID ^ im.toAgentID;
  788. else
  789. msg.MessageBlock.ID = im.imSessionID;
  790. msg.MessageBlock.Offline = im.offline;
  791. msg.MessageBlock.ParentEstateID = im.ParentEstateID;
  792. msg.MessageBlock.Position = im.Position;
  793. msg.MessageBlock.RegionID = im.RegionID;
  794. msg.MessageBlock.Timestamp = im.timestamp;
  795. msg.MessageBlock.ToAgentID = im.toAgentID;
  796. msg.MessageBlock.Message = Util.StringToBytes1024(im.message);
  797. msg.MessageBlock.BinaryBucket = im.binaryBucket;
  798. OutPacket(msg, ThrottleOutPacketType.AvatarInfo);
  799. }
  800. }
  801. public void SendGenericMessage(string method, List<string> message)
  802. {
  803. List<byte[]> convertedmessage =
  804. message.ConvertAll<byte[]>(delegate(string item) { return Util.StringToBytes256(item); });
  805. SendGenericMessage(method, convertedmessage);
  806. }
  807. public void SendGenericMessage(string method, List<byte[]> message)
  808. {
  809. GenericMessagePacket gmp = new GenericMessagePacket
  810. {
  811. MethodData = {Method = Util.StringToBytes256(method)},
  812. ParamList = new GenericMessagePacket.ParamListBlock[message.Count]
  813. };
  814. int i = 0;
  815. foreach (byte[] val in message)
  816. {
  817. gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
  818. gmp.ParamList[i++].Parameter = val;
  819. }
  820. OutPacket(gmp, ThrottleOutPacketType.AvatarInfo);
  821. }
  822. public void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals)
  823. {
  824. GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket
  825. {
  826. AgentData = {AgentID = AgentId, GroupID = groupID},
  827. TransactionData =
  828. {
  829. TransactionID = transactionID,
  830. TotalNumItems = (uint) Proposals.Length
  831. },
  832. ProposalData =
  833. new GroupActiveProposalItemReplyPacket.
  834. ProposalDataBlock[Proposals.Length]
  835. };
  836. int i = 0;
  837. foreach (
  838. GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData in
  839. Proposals.Select(Proposal => new GroupActiveProposalItemReplyPacket.ProposalDataBlock
  840. {
  841. VoteCast = Utils.StringToBytes("false"),
  842. VoteID = new UUID(Proposal.VoteID),
  843. VoteInitiator = new UUID(Proposal.VoteInitiator),
  844. Majority = Convert.ToInt32(Proposal.Majority),
  845. Quorum = Convert.ToInt32(Proposal.Quorum),
  846. TerseDateID = Utils.StringToBytes(Proposal.TerseDateID),
  847. StartDateTime = Utils.StringToBytes(Proposal.StartDateTime),
  848. EndDateTime = Utils.StringToBytes(Proposal.EndDateTime),
  849. ProposalText = Utils.StringToBytes(Proposal.ProposalText),
  850. AlreadyVoted = false
  851. }))
  852. {
  853. GAPIRP.ProposalData[i] = ProposalData;
  854. i++;
  855. }
  856. OutPacket(GAPIRP, ThrottleOutPacketType.AvatarInfo);
  857. }
  858. public void SendGroupVoteHistory(UUID groupID, UUID transactionID, GroupVoteHistory Vote,
  859. GroupVoteHistoryItem[] VoteItems)
  860. {
  861. GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket
  862. {
  863. AgentData = {AgentID = AgentId, GroupID = groupID},
  864. TransactionData =
  865. {
  866. TransactionID = transactionID,
  867. TotalNumItems = (uint) VoteItems.Length
  868. },
  869. HistoryItemData =
  870. {
  871. VoteID = new UUID(Vote.VoteID),
  872. VoteInitiator = new UUID(Vote.VoteInitiator),
  873. Majority = Convert.ToInt32(Vote.Majority),
  874. Quorum = Convert.ToInt32(Vote.Quorum),
  875. TerseDateID = Utils.StringToBytes(Vote.TerseDateID),
  876. StartDateTime =
  877. Utils.StringToBytes(Vote.StartDateTime),
  878. EndDateTime = Utils.StringToBytes(Vote.EndDateTime),
  879. VoteType = Utils.StringToBytes(Vote.VoteType),
  880. VoteResult = Utils.StringToBytes(Vote.VoteResult),
  881. ProposalText =
  882. Utils.StringToBytes(Vote.ProposalText)
  883. }
  884. };
  885. int i = 0;
  886. GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[VoteItems.Length];
  887. foreach (
  888. GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem in
  889. VoteItems.Select(item => new GroupVoteHistoryItemReplyPacket.VoteItemBlock
  890. {
  891. CandidateID = item.CandidateID,
  892. NumVotes = item.NumVotes,
  893. VoteCast = Utils.StringToBytes(item.VoteCast)
  894. }))
  895. {
  896. GVHIRP.VoteItem[i] = VoteItem;
  897. i++;
  898. }
  899. OutPacket(GVHIRP, ThrottleOutPacketType.AvatarInfo);
  900. }
  901. public void SendGroupAccountingDetails(IClientAPI sender, UUID groupID, UUID transactionID, UUID sessionID,
  902. int amt, int currentInterval, int interval, string startDate,
  903. GroupAccountHistory[] history)
  904. {
  905. GroupAccountDetailsReplyPacket GADRP = new GroupAccountDetailsReplyPacket
  906. {
  907. AgentData = new GroupAccountDetailsReplyPacket.AgentDataBlock
  908. {AgentID = sender.AgentId, GroupID = groupID},
  909. HistoryData =
  910. new GroupAccountDetailsReplyPacket.HistoryDataBlock[
  911. history.Length]
  912. };
  913. int i = 0;
  914. foreach (GroupAccountHistory h in history)
  915. {
  916. GroupAccountDetailsReplyPacket.HistoryDataBlock History =
  917. new GroupAccountDetailsReplyPacket.HistoryDataBlock();
  918. History.Amount = h.Amount;
  919. History.Description = Utils.StringToBytes(h.Description);
  920. GADRP.HistoryData[i++] = History;
  921. }
  922. GADRP.MoneyData = new GroupAccountDetailsReplyPacket.MoneyDataBlock
  923. {
  924. CurrentInterval = currentInterval,
  925. IntervalDays = interval,
  926. RequestID = transactionID,
  927. Sta

Large files files are truncated, but you can click here to view the full file