/Aurora/ClientStack/LLClientView.cs
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
- /*
- * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Aurora-Sim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- using Aurora.Framework;
- using Aurora.Framework.ClientInterfaces;
- using Aurora.Framework.ConsoleFramework;
- using Aurora.Framework.Modules;
- using Aurora.Framework.PresenceInfo;
- using Aurora.Framework.SceneInfo;
- using Aurora.Framework.SceneInfo.Entities;
- using Aurora.Framework.Services;
- using Aurora.Framework.Services.ClassHelpers.Assets;
- using Aurora.Framework.Services.ClassHelpers.Inventory;
- using Aurora.Framework.Utilities;
- using Nini.Config;
- using OpenMetaverse;
- using OpenMetaverse.Messages.Linden;
- using OpenMetaverse.Packets;
- using OpenMetaverse.StructuredData;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Threading;
- using System.Xml;
- using RegionFlags = OpenMetaverse.RegionFlags;
-
- namespace Aurora.ClientStack
- {
- public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
-
- /// <summary>
- /// Handles new client connections
- /// Constructor takes a single Packet and authenticates everything
- /// </summary>
- public sealed class LLClientView : IClientAPI, IStatsCollector
- {
- /// <value>
- /// Debug packet level. See OpenSim.RegisterConsoleCommands() for more details.
- /// </value>
- private int m_debugPacketLevel;
-
- private readonly bool m_allowUDPInv;
-
- #region Events
-
- public event BinaryGenericMessage OnBinaryGenericMessage;
- public event Action<IClientAPI> OnLogout;
- public event ObjectPermissions OnObjectPermissions;
- public event Action<IClientAPI> OnConnectionClosed;
- public event ViewerEffectEventHandler OnViewerEffect;
- public event ImprovedInstantMessage OnInstantMessage;
- public event PreSendImprovedInstantMessage OnPreSendInstantMessage;
- public event ChatMessage OnChatFromClient;
- public event RezObject OnRezObject;
- public event DeRezObject OnDeRezObject;
- public event ModifyTerrain OnModifyTerrain;
- public event Action<IClientAPI> OnRegionHandShakeReply;
- public event GenericCall1 OnRequestWearables;
- public event SetAppearance OnSetAppearance;
- public event AvatarNowWearing OnAvatarNowWearing;
- public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
- public event UUIDNameRequest OnDetachAttachmentIntoInv;
- public event ObjectAttach OnObjectAttach;
- public event ObjectDeselect OnObjectDetach;
- public event ObjectDrop OnObjectDrop;
- public event GenericCall1 OnCompleteMovementToRegion;
- public event UpdateAgent OnAgentUpdate;
- public event AgentRequestSit OnAgentRequestSit;
- public event AgentSit OnAgentSit;
- public event AvatarPickerRequest OnAvatarPickerRequest;
- public event StartAnim OnStartAnim;
- public event StopAnim OnStopAnim;
- public event Action<IClientAPI> OnRequestAvatarsData;
- public event LinkObjects OnLinkObjects;
- public event DelinkObjects OnDelinkObjects;
- public event GrabObject OnGrabObject;
- public event DeGrabObject OnDeGrabObject;
- public event SpinStart OnSpinStart;
- public event SpinStop OnSpinStop;
- public event ObjectDuplicate OnObjectDuplicate;
- public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
- public event MoveObject OnGrabUpdate;
- public event SpinObject OnSpinUpdate;
- public event AddNewPrim OnAddPrim;
- public event RequestGodlikePowers OnRequestGodlikePowers;
- public event GodKickUser OnGodKickUser;
- public event ObjectExtraParams OnUpdateExtraParams;
- public event UpdateShape OnUpdatePrimShape;
- public event ObjectRequest OnObjectRequest;
- public event ObjectSelect OnObjectSelect;
- public event ObjectDeselect OnObjectDeselect;
- public event GenericCall7 OnObjectDescription;
- public event GenericCall7 OnObjectName;
- public event GenericCall7 OnObjectClickAction;
- public event GenericCall7 OnObjectMaterial;
- public event ObjectIncludeInSearch OnObjectIncludeInSearch;
- public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
- public event UpdatePrimFlags OnUpdatePrimFlags;
- public event UpdatePrimTexture OnUpdatePrimTexture;
- public event UpdateVectorWithUpdate OnUpdatePrimGroupPosition;
- public event UpdateVectorWithUpdate OnUpdatePrimSinglePosition;
- public event UpdatePrimRotation OnUpdatePrimGroupRotation;
- public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
- public event UpdatePrimSingleRotationPosition OnUpdatePrimSingleRotationPosition;
- public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
- public event UpdateVector OnUpdatePrimScale;
- public event UpdateVector OnUpdatePrimGroupScale;
-
- #pragma warning disable 67
-
- public event StatusChange OnChildAgentStatus;
- public event GenericMessage OnGenericMessage;
- public event BuyObjectInventory OnBuyObjectInventory;
- public event SetEstateTerrainBaseTexture OnSetEstateTerrainBaseTexture;
-
- #pragma warning restore 67
-
- public event RequestMapBlocks OnRequestMapBlocks;
- public event RequestMapName OnMapNameRequest;
- public event TeleportLocationRequest OnTeleportLocationRequest;
- public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
- public event RequestAvatarProperties OnRequestAvatarProperties;
- public event SetAlwaysRun OnSetAlwaysRun;
- public event FetchInventory OnAgentDataUpdateRequest;
- public event TeleportLocationRequest OnSetStartLocationRequest;
- public event UpdateAvatarProperties OnUpdateAvatarProperties;
- public event CreateNewInventoryItem OnCreateNewInventoryItem;
- public event LinkInventoryItem OnLinkInventoryItem;
- public event CreateInventoryFolder OnCreateNewInventoryFolder;
- public event UpdateInventoryFolder OnUpdateInventoryFolder;
- public event MoveInventoryFolder OnMoveInventoryFolder;
- public event FetchInventoryDescendents OnFetchInventoryDescendents;
- public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
- public event FetchInventory OnFetchInventory;
- public event RequestTaskInventory OnRequestTaskInventory;
- public event UpdateInventoryItem OnUpdateInventoryItem;
- public event ChangeInventoryItemFlags OnChangeInventoryItemFlags;
- public event CopyInventoryItem OnCopyInventoryItem;
- public event MoveInventoryItem OnMoveInventoryItem;
- public event RemoveInventoryItem OnRemoveInventoryItem;
- public event RemoveInventoryFolder OnRemoveInventoryFolder;
- public event UDPAssetUploadRequest OnAssetUploadRequest;
- public event XferReceive OnXferReceive;
- public event RequestXfer OnRequestXfer;
- public event ConfirmXfer OnConfirmXfer;
- public event AbortXfer OnAbortXfer;
- public event RequestTerrain OnRequestTerrain;
- public event RezScript OnRezScript;
- public event UpdateTaskInventory OnUpdateTaskInventory;
- public event MoveTaskInventory OnMoveTaskItem;
- public event RemoveTaskInventory OnRemoveTaskItem;
- public event UUIDNameRequest OnNameFromUUIDRequest;
- public event ParcelAccessListRequest OnParcelAccessListRequest;
- public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
- public event ParcelPropertiesRequest OnParcelPropertiesRequest;
- public event ParcelDivideRequest OnParcelDivideRequest;
- public event ParcelJoinRequest OnParcelJoinRequest;
- public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
- public event ParcelSelectObjects OnParcelSelectObjects;
- public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
- public event ParcelAbandonRequest OnParcelAbandonRequest;
- public event ParcelGodForceOwner OnParcelGodForceOwner;
- public event ParcelReclaim OnParcelReclaim;
- public event ParcelReturnObjectsRequest OnParcelReturnObjectsRequest;
- public event ParcelReturnObjectsRequest OnParcelDisableObjectsRequest;
- public event ParcelDeedToGroup OnParcelDeedToGroup;
- public event RegionInfoRequest OnRegionInfoRequest;
- public event EstateCovenantRequest OnEstateCovenantRequest;
- public event FriendActionDelegate OnApproveFriendRequest;
- public event FriendActionDelegate OnDenyFriendRequest;
- public event FriendshipTermination OnTerminateFriendship;
- public event GrantUserFriendRights OnGrantUserRights;
- public event MoneyTransferRequest OnMoneyTransferRequest;
- public event EconomyDataRequest OnEconomyDataRequest;
- public event MoneyBalanceRequest OnMoneyBalanceRequest;
- public event ParcelBuy OnParcelBuy;
- public event UUIDNameRequest OnTeleportHomeRequest;
- public event UUIDNameRequest OnUUIDGroupNameRequest;
- public event ScriptAnswer OnScriptAnswer;
- public event RequestPayPrice OnRequestPayPrice;
- public event ObjectSaleInfo OnObjectSaleInfo;
- public event ObjectBuy OnObjectBuy;
- public event AgentSit OnUndo;
- public event AgentSit OnRedo;
- public event LandUndo OnLandUndo;
- public event ForceReleaseControls OnForceReleaseControls;
- public event GodLandStatRequest OnLandStatRequest;
- public event RequestObjectPropertiesFamily OnObjectGroupRequest;
- public event DetailedEstateDataRequest OnDetailedEstateDataRequest;
- public event SetEstateFlagsRequest OnSetEstateFlagsRequest;
- public event SetEstateTerrainDetailTexture OnSetEstateTerrainDetailTexture;
- public event SetEstateTerrainTextureHeights OnSetEstateTerrainTextureHeights;
- public event CommitEstateTerrainTextureRequest OnCommitEstateTerrainTextureRequest;
- public event SetRegionTerrainSettings OnSetRegionTerrainSettings;
- public event BakeTerrain OnBakeTerrain;
- public event RequestTerrain OnUploadTerrain;
- public event EstateChangeInfo OnEstateChangeInfo;
- public event EstateRestartSimRequest OnEstateRestartSimRequest;
- public event EstateChangeCovenantRequest OnEstateChangeCovenantRequest;
- public event UpdateEstateAccessDeltaRequest OnUpdateEstateAccessDeltaRequest;
- public event SimulatorBlueBoxMessageRequest OnSimulatorBlueBoxMessageRequest;
- public event EstateBlueBoxMessageRequest OnEstateBlueBoxMessageRequest;
- public event EstateDebugRegionRequest OnEstateDebugRegionRequest;
- public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
- public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
- public event RegionHandleRequest OnRegionHandleRequest;
- public event ParcelInfoRequest OnParcelInfoRequest;
- public event ScriptReset OnScriptReset;
- public event GetScriptRunning OnGetScriptRunning;
- public event SetScriptRunning OnSetScriptRunning;
- public event UpdateVector OnAutoPilotGo;
- public event ActivateGesture OnActivateGesture;
- public event DeactivateGesture OnDeactivateGesture;
- public event ObjectOwner OnObjectOwner;
- public event DirPlacesQuery OnDirPlacesQuery;
- public event DirFindQuery OnDirFindQuery;
- public event DirLandQuery OnDirLandQuery;
- public event DirPopularQuery OnDirPopularQuery;
- public event DirClassifiedQuery OnDirClassifiedQuery;
- public event EventInfoRequest OnEventInfoRequest;
- public event ParcelSetOtherCleanTime OnParcelSetOtherCleanTime;
- public event MapItemRequest OnMapItemRequest;
- public event OfferCallingCard OnOfferCallingCard;
- public event AcceptCallingCard OnAcceptCallingCard;
- public event DeclineCallingCard OnDeclineCallingCard;
- public event SoundTrigger OnSoundTrigger;
- public event StartLure OnStartLure;
- public event TeleportLureRequest OnTeleportLureRequest;
- public event NetworkStats OnNetworkStatsUpdate;
- public event ClassifiedInfoRequest OnClassifiedInfoRequest;
- public event ClassifiedInfoUpdate OnClassifiedInfoUpdate;
- public event ClassifiedDelete OnClassifiedDelete;
- public event ClassifiedDelete OnClassifiedGodDelete;
- public event EventNotificationAddRequest OnEventNotificationAddRequest;
- public event EventNotificationRemoveRequest OnEventNotificationRemoveRequest;
- public event EventGodDelete OnEventGodDelete;
- public event ParcelDwellRequest OnParcelDwellRequest;
- public event UserInfoRequest OnUserInfoRequest;
- public event UpdateUserInfo OnUpdateUserInfo;
- public event RetrieveInstantMessages OnRetrieveInstantMessages;
- public event PickDelete OnPickDelete;
- public event PickGodDelete OnPickGodDelete;
- public event PickInfoUpdate OnPickInfoUpdate;
- public event AvatarNotesUpdate OnAvatarNotesUpdate;
- public event MuteListRequest OnMuteListRequest;
- public event AvatarInterestUpdate OnAvatarInterestUpdate;
- public event PlacesQuery OnPlacesQuery;
- public event AgentFOV OnAgentFOV;
- public event FindAgentUpdate OnFindAgent;
- public event TrackAgentUpdate OnTrackAgent;
- public event NewUserReport OnUserReport;
- public event SaveStateHandler OnSaveState;
- public event GroupAccountSummaryRequest OnGroupAccountSummaryRequest;
- public event GroupAccountDetailsRequest OnGroupAccountDetailsRequest;
- public event GroupAccountTransactionsRequest OnGroupAccountTransactionsRequest;
- public event FreezeUserUpdate OnParcelFreezeUser;
- public event EjectUserUpdate OnParcelEjectUser;
- public event ParcelBuyPass OnParcelBuyPass;
- public event ParcelGodMark OnParcelGodMark;
- public event GroupActiveProposalsRequest OnGroupActiveProposalsRequest;
- public event GroupVoteHistoryRequest OnGroupVoteHistoryRequest;
- public event SimWideDeletesDelegate OnSimWideDeletes;
- public event SendPostcard OnSendPostcard;
- public event TeleportCancel OnTeleportCancel;
- public event MuteListEntryUpdate OnUpdateMuteListEntry;
- public event MuteListEntryRemove OnRemoveMuteListEntry;
- public event GodlikeMessage OnGodlikeMessage;
- public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
- public event GodlikeMessage OnEstateTelehubRequest;
- public event ViewerStartAuction OnViewerStartAuction;
- public event GroupProposalBallotRequest OnGroupProposalBallotRequest;
- public event AgentCachedTextureRequest OnAgentCachedTextureRequest;
-
- #endregion Events
-
- #region Enums
-
- public enum TransferPacketStatus
- {
- MorePacketsToCome = 0,
- Done = 1,
- AssetSkip = 2,
- AssetAbort = 3,
- AssetRequestFailed = -1,
- AssetUnknownSource = -2, // Equivalent of a 404
- InsufficientPermissions = -3
- }
-
- #endregion
-
- #region Class Members
-
- // LLClientView Only
- public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
-
- /// <summary>
- /// Used to adjust Sun Orbit values so Linden based viewers properly position sun
- /// </summary>
- private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
-
- private static readonly Dictionary<PacketType, PacketMethod> PacketHandlers =
- new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
-
- private readonly LLUDPServer m_udpServer;
- private readonly LLUDPClient m_udpClient;
- private readonly UUID m_sessionId;
- private readonly UUID m_secureSessionId;
- private readonly UUID m_agentId;
- private readonly uint m_circuitCode;
- private readonly byte[] m_channelVersion = Utils.EmptyBytes;
- private readonly Dictionary<string, UUID> m_defaultAnimations = new Dictionary<string, UUID>();
- private readonly IGroupsModule m_GroupsModule;
-
- private int m_cachedTextureSerial;
-
- /// <value>
- /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the
- /// thread servicing the m_primFullUpdates queue after a kill. If this happens the object persists as an
- /// ownerless phantom.
- /// All manipulation of this set has to occur under an m_entityUpdates.SyncRoot lock
- /// </value>
- //protected HashSet<uint> m_killRecord = new HashSet<uint>();
- // protected HashSet<uint> m_attachmentsSent;
- private int m_animationSequenceNumber = 1;
-
- private bool m_SendLogoutPacketWhenClosing = true;
- private AgentUpdateArgs lastarg;
- private bool m_IsActive = true;
-
- private readonly Dictionary<PacketType, PacketProcessor> m_packetHandlers =
- new Dictionary<PacketType, PacketProcessor>();
-
- private readonly Dictionary<string, GenericMessage> m_genericPacketHandlers =
- new Dictionary<string, GenericMessage>();
-
- //PauPaw:Local Generic Message handlers
-
- private readonly IScene m_scene;
- private readonly LLImageManager m_imageManager;
- private readonly string m_firstName;
- private readonly string m_lastName;
- private readonly string m_Name;
- private readonly EndPoint m_userEndPoint;
- private UUID m_activeGroupID;
- private string m_activeGroupName = String.Empty;
- private ulong m_activeGroupPowers;
- private uint m_agentFOVCounter;
-
- private readonly IAssetService m_assetService;
- // ReSharper disable ConvertToConstant.Local
- private bool m_checkPackets = true;
- // ReSharper restore ConvertToConstant.Local
-
- #endregion Class Members
-
- #region Properties
-
- public LLUDPClient UDPClient
- {
- get { return m_udpClient; }
- }
-
- public IPEndPoint RemoteEndPoint
- {
- get { return m_udpClient.RemoteEndPoint; }
- }
-
- public UUID SecureSessionId
- {
- get { return m_secureSessionId; }
- }
-
- public IScene Scene
- {
- get { return m_scene; }
- }
-
- public UUID SessionId
- {
- get { return m_sessionId; }
- }
-
- public Vector3 StartPos { get; set; }
-
- public UUID AgentId
- {
- get { return m_agentId; }
- }
-
- public UUID ScopeID { get; set; }
-
- public List<UUID> AllScopeIDs { get; set; }
-
- public UUID ActiveGroupId
- {
- get { return m_activeGroupID; }
- }
-
- public string ActiveGroupName
- {
- get { return m_activeGroupName; }
- }
-
- public ulong ActiveGroupPowers
- {
- get { return m_activeGroupPowers; }
- }
-
- /// <summary>
- /// First name of the agent/avatar represented by the client
- /// </summary>
- public string FirstName
- {
- get { return m_firstName; }
- }
-
- /// <summary>
- /// Last name of the agent/avatar represented by the client
- /// </summary>
- public string LastName
- {
- get { return m_lastName; }
- }
-
- /// <summary>
- /// Full name of the client (first name and last name)
- /// </summary>
- public string Name
- {
- get { return m_Name; }
- }
-
- public uint CircuitCode
- {
- get { return m_circuitCode; }
- }
-
- public int NextAnimationSequenceNumber
- {
- get { return m_animationSequenceNumber; }
- }
-
- public bool IsActive
- {
- get { return m_IsActive; }
- set { m_IsActive = value; }
- }
-
- public bool IsLoggingOut { get; set; }
-
- public bool SendLogoutPacketWhenClosing
- {
- set { m_SendLogoutPacketWhenClosing = value; }
- }
-
- #endregion Properties
-
- /// <summary>
- /// Constructor
- /// </summary>
- public LLClientView(EndPoint remoteEP, IScene scene, LLUDPServer udpServer, LLUDPClient udpClient,
- AgentCircuitData sessionInfo,
- UUID agentId, UUID sessionId, uint circuitCode)
- {
- InitDefaultAnimations();
-
- m_scene = scene;
-
- IConfig advancedConfig = m_scene.Config.Configs["ClientStack.LindenUDP"];
- if (advancedConfig != null)
- m_allowUDPInv = advancedConfig.GetBoolean("AllowUDPInventory", m_allowUDPInv);
-
- //m_killRecord = new HashSet<uint>();
- // m_attachmentsSent = new HashSet<uint>();
-
- m_assetService = m_scene.RequestModuleInterface<IAssetService>();
- m_GroupsModule = scene.RequestModuleInterface<IGroupsModule>();
- m_imageManager = new LLImageManager(this, m_assetService, Scene.RequestModuleInterface<IJ2KDecoder>());
- ISimulationBase simulationBase = m_scene.RequestModuleInterface<ISimulationBase>();
- if (simulationBase != null)
- m_channelVersion = Util.StringToBytes256(simulationBase.Version);
- m_agentId = agentId;
- m_sessionId = sessionId;
- m_secureSessionId = sessionInfo.SecureSessionID;
- m_circuitCode = circuitCode;
- m_userEndPoint = remoteEP;
- UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.AllScopeIDs, m_agentId);
- if (account != null)
- {
- m_firstName = account.FirstName;
- m_lastName = account.LastName;
- m_Name = account.Name;
- }
- else
- {
- m_firstName = sessionInfo.firstname;
- m_lastName = sessionInfo.lastname;
- m_Name = sessionInfo.firstname + " " + sessionInfo.lastname;
- }
- StartPos = sessionInfo.startpos;
-
- m_udpServer = udpServer;
- m_udpClient = udpClient;
- m_udpClient.OnQueueEmpty += HandleQueueEmpty;
- m_udpClient.OnPacketStats += PopulateStats;
-
- RegisterLocalPacketHandlers();
- }
-
- public void Reset()
- {
- lastarg = null;
- //Reset the killObjectUpdate packet stats
- //m_killRecord = new HashSet<uint>();
- }
-
- public void SetDebugPacketLevel(int newDebug)
- {
- m_debugPacketLevel = newDebug;
- }
-
- #region Client Methods
-
- public void Stop()
- {
- // Send the STOP packet NOW, otherwise it doesn't get out in time
- DisableSimulatorPacket disable =
- (DisableSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
- OutPacket(disable, ThrottleOutPacketType.Immediate);
- }
-
- /// <summary>
- /// Shut down the client view
- /// </summary>
- public void Close(bool forceClose)
- {
- //MainConsole.Instance.DebugFormat(
- // "[CLIENT]: Close has been called for {0} attached to scene {1}",
- // Name, m_scene.RegionInfo.RegionName);
-
- if (forceClose && !IsLoggingOut) //Don't send it to clients that are logging out
- {
- // Send the STOP packet NOW, otherwise it doesn't get out in time
- DisableSimulatorPacket disable =
- (DisableSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
- OutPacket(disable, ThrottleOutPacketType.Immediate);
- }
-
- IsActive = false;
-
- // Shutdown the image manager
- if (m_imageManager != null)
- m_imageManager.Close();
-
- // Fire the callback for this connection closing
- if (OnConnectionClosed != null)
- OnConnectionClosed(this);
-
- // Flush all of the packets out of the UDP server for this client
- if (m_udpServer != null)
- {
- m_udpServer.Flush(m_udpClient);
- m_udpServer.RemoveClient(this);
- }
-
- // Disable UDP handling for this client
- m_udpClient.Shutdown();
-
- //MainConsole.Instance.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
- //GC.Collect();
- //MainConsole.Instance.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
- }
-
- public void Kick(string message)
- {
- if (!ChildAgentStatus())
- {
- KickUserPacket kupack = (KickUserPacket) PacketPool.Instance.GetPacket(PacketType.KickUser);
- kupack.UserInfo.AgentID = AgentId;
- kupack.UserInfo.SessionID = SessionId;
- kupack.TargetBlock.TargetIP = 0;
- kupack.TargetBlock.TargetPort = 0;
- kupack.UserInfo.Reason = Util.StringToBytes256(message);
- OutPacket(kupack, ThrottleOutPacketType.OutBand);
- // You must sleep here or users get no message!
- Thread.Sleep(500);
- }
- }
-
- #endregion Client Methods
-
- #region Packet Handling
-
- public void PopulateStats(int inPackets, int outPackets, int unAckedBytes)
- {
- NetworkStats handlerNetworkStatsUpdate = OnNetworkStatsUpdate;
- if (handlerNetworkStatsUpdate != null)
- {
- handlerNetworkStatsUpdate(inPackets, outPackets, unAckedBytes);
- }
- }
-
- public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
- {
- bool result = false;
- lock (PacketHandlers)
- {
- if (!PacketHandlers.ContainsKey(packetType))
- {
- PacketHandlers.Add(packetType, handler);
- result = true;
- }
- }
- return result;
- }
-
- public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
- {
- return AddLocalPacketHandler(packetType, handler, true);
- }
-
- public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler, bool runasync)
- {
- bool result = false;
- lock (m_packetHandlers)
- {
- if (!m_packetHandlers.ContainsKey(packetType))
- {
- m_packetHandlers.Add(packetType, new PacketProcessor {method = handler, Async = runasync});
- result = true;
- }
- }
- return result;
- }
-
- public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)
- {
- MethodName = MethodName.ToLower().Trim();
-
- bool result = false;
- lock (m_genericPacketHandlers)
- {
- if (!m_genericPacketHandlers.ContainsKey(MethodName))
- {
- m_genericPacketHandlers.Add(MethodName, handler);
- result = true;
- }
- }
- return result;
- }
-
- public bool RemoveGenericPacketHandler(string MethodName)
- {
- MethodName = MethodName.ToLower().Trim();
-
- bool result = false;
- lock (m_genericPacketHandlers)
- {
- if (m_genericPacketHandlers.ContainsKey(MethodName))
- {
- m_genericPacketHandlers.Remove(MethodName);
- result = true;
- }
- }
- return result;
- }
-
- /// <summary>
- /// Try to process a packet using registered packet handlers
- /// </summary>
- /// <param name="packet"></param>
- /// <returns>True if a handler was found which successfully processed the packet.</returns>
- private bool ProcessPacketMethod(Packet packet)
- {
- bool result = false;
- PacketProcessor pprocessor;
- if (m_packetHandlers.TryGetValue(packet.Type, out pprocessor))
- {
- //there is a local handler for this packet type
- if (pprocessor.Async)
- {
- object obj = new AsyncPacketProcess(this, pprocessor.method, packet);
- m_udpServer.FireAndForget(ProcessSpecificPacketAsync, obj);
- result = true;
- }
- else
- {
- result = pprocessor.method(this, packet);
- }
- }
- else
- {
- //there is not a local handler so see if there is a Global handler
- PacketMethod method = null;
- bool found;
- lock (PacketHandlers)
- {
- found = PacketHandlers.TryGetValue(packet.Type, out method);
- }
- if (found)
- {
- result = method(this, packet);
- }
- }
- return result;
- }
-
- public void ProcessSpecificPacketAsync(object state)
- {
- AsyncPacketProcess packetObject = (AsyncPacketProcess) state;
-
- try
- {
- packetObject.result = packetObject.Method(packetObject.ClientView, packetObject.Pack);
- }
- catch (Exception e)
- {
- // Make sure that we see any exception caused by the asynchronous operation.
- MainConsole.Instance.ErrorFormat(
- "[LLCLIENTVIEW]: Caught exception while processing {0} for {1}, {2} {3}",
- packetObject.Pack, Name, e.Message, e.StackTrace);
- }
- }
-
- #endregion Packet Handling
-
- #region Scene/Avatar to Client
-
- public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args)
- {
- RegionHandshakePacket handshake =
- (RegionHandshakePacket) PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
- handshake.RegionInfo = new RegionHandshakePacket.RegionInfoBlock
- {
- BillableFactor = args.billableFactor,
- IsEstateManager = args.isEstateManager,
- TerrainHeightRange00 = args.terrainHeightRange0,
- TerrainHeightRange01 = args.terrainHeightRange1,
- TerrainHeightRange10 = args.terrainHeightRange2,
- TerrainHeightRange11 = args.terrainHeightRange3,
- TerrainStartHeight00 = args.terrainStartHeight0,
- TerrainStartHeight01 = args.terrainStartHeight1,
- TerrainStartHeight10 = args.terrainStartHeight2,
- TerrainStartHeight11 = args.terrainStartHeight3,
- SimAccess = args.simAccess,
- WaterHeight = args.waterHeight,
- RegionFlags = (uint) args.regionFlags,
- SimName = Util.StringToBytes256(args.regionName),
- SimOwner = args.SimOwner,
- TerrainBase0 = args.terrainBase0,
- TerrainBase1 = args.terrainBase1,
- TerrainBase2 = args.terrainBase2,
- TerrainBase3 = args.terrainBase3,
- TerrainDetail0 = args.terrainDetail0,
- TerrainDetail1 = args.terrainDetail1,
- TerrainDetail2 = args.terrainDetail2,
- TerrainDetail3 = args.terrainDetail3,
- CacheID = UUID.Random()
- };
-
- //I guess this is for the client to remember an old setting?
- handshake.RegionInfo2 = new RegionHandshakePacket.RegionInfo2Block {RegionID = regionInfo.RegionID};
- handshake.RegionInfo4 = new RegionHandshakePacket.RegionInfo4Block[1]
- {
- new RegionHandshakePacket.RegionInfo4Block
- {
- RegionFlagsExtended = args.regionFlags,
- RegionProtocols = (ulong) RegionProtocols.AgentAppearanceService
- }
- };
- handshake.RegionInfo3 = new RegionHandshakePacket.RegionInfo3Block
- {
- CPUClassID = 9,
- CPURatio = 1,
- ColoName = Utils.EmptyBytes,
- ProductName = Util.StringToBytes256(regionInfo.RegionType),
- ProductSKU = Utils.EmptyBytes
- };
-
-
- OutPacket(handshake, ThrottleOutPacketType.Task);
- }
-
- /// <summary>
- /// </summary>
- public void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look)
- {
- AgentMovementCompletePacket mov =
- (AgentMovementCompletePacket) PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
- mov.SimData.ChannelVersion = m_channelVersion;
- mov.AgentData.SessionID = m_sessionId;
- mov.AgentData.AgentID = AgentId;
- mov.Data.RegionHandle = regInfo.RegionHandle;
- mov.Data.Timestamp = (uint) Util.UnixTimeSinceEpoch();
- mov.Data.Position = pos;
- mov.Data.LookAt = look;
-
- // Hack to get this out immediately and skip the throttles
- OutPacket(mov, ThrottleOutPacketType.OutBand);
- }
-
- public void SendChatMessage(string message, byte type, Vector3 fromPos, string fromName,
- UUID fromAgentID, byte source, byte audible)
- {
- ChatFromSimulatorPacket reply =
- (ChatFromSimulatorPacket) PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
- reply.ChatData.Audible = audible;
- reply.ChatData.Message = Util.StringToBytes1024(message);
- reply.ChatData.ChatType = type;
- reply.ChatData.SourceType = source;
- reply.ChatData.Position = fromPos;
- reply.ChatData.FromName = Util.StringToBytes256(fromName);
- reply.ChatData.OwnerID = fromAgentID;
- reply.ChatData.SourceID = fromAgentID;
-
- //Don't split me up!
- reply.HasVariableBlocks = false;
- // Hack to get this out immediately and skip throttles
- OutPacket(reply, ThrottleOutPacketType.AvatarInfo);
- }
-
- public void SendTelehubInfo(Vector3 TelehubPos, Quaternion TelehubRot, List<Vector3> SpawnPoint, UUID ObjectID,
- string nameT)
- {
- TelehubInfoPacket packet = (TelehubInfoPacket) PacketPool.Instance.GetPacket(PacketType.TelehubInfo);
- packet.SpawnPointBlock = new TelehubInfoPacket.SpawnPointBlockBlock[SpawnPoint.Count];
- int i = 0;
- foreach (Vector3 pos in SpawnPoint)
- {
- packet.SpawnPointBlock[i] = new TelehubInfoPacket.SpawnPointBlockBlock {SpawnPointPos = pos};
- i++;
- }
- packet.TelehubBlock.ObjectID = ObjectID;
- packet.TelehubBlock.ObjectName = Utils.StringToBytes(nameT);
- packet.TelehubBlock.TelehubPos = TelehubPos;
- packet.TelehubBlock.TelehubRot = TelehubRot;
- OutPacket(packet, ThrottleOutPacketType.AvatarInfo);
- }
-
- /// <summary>
- /// Send an instant message to this client
- /// </summary>
- //
- // Don't remove transaction ID! Groups and item gives need to set it!
- public void SendInstantMessage(GridInstantMessage im)
- {
- if (m_scene.Permissions.CanInstantMessage(im.fromAgentID, im.toAgentID))
- {
- ImprovedInstantMessagePacket msg
- = (ImprovedInstantMessagePacket) PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
-
- msg.AgentData.AgentID = im.fromAgentID;
- msg.AgentData.SessionID = UUID.Zero;
- msg.MessageBlock.FromAgentName = Util.StringToBytes256(im.fromAgentName);
- msg.MessageBlock.Dialog = im.dialog;
- msg.MessageBlock.FromGroup = im.fromGroup;
- if (im.imSessionID == UUID.Zero)
- msg.MessageBlock.ID = im.fromAgentID ^ im.toAgentID;
- else
- msg.MessageBlock.ID = im.imSessionID;
- msg.MessageBlock.Offline = im.offline;
- msg.MessageBlock.ParentEstateID = im.ParentEstateID;
- msg.MessageBlock.Position = im.Position;
- msg.MessageBlock.RegionID = im.RegionID;
- msg.MessageBlock.Timestamp = im.timestamp;
- msg.MessageBlock.ToAgentID = im.toAgentID;
- msg.MessageBlock.Message = Util.StringToBytes1024(im.message);
- msg.MessageBlock.BinaryBucket = im.binaryBucket;
-
- OutPacket(msg, ThrottleOutPacketType.AvatarInfo);
- }
- }
-
- public void SendGenericMessage(string method, List<string> message)
- {
- List<byte[]> convertedmessage =
- message.ConvertAll<byte[]>(delegate(string item) { return Util.StringToBytes256(item); });
- SendGenericMessage(method, convertedmessage);
- }
-
- public void SendGenericMessage(string method, List<byte[]> message)
- {
- GenericMessagePacket gmp = new GenericMessagePacket
- {
- MethodData = {Method = Util.StringToBytes256(method)},
- ParamList = new GenericMessagePacket.ParamListBlock[message.Count]
- };
- int i = 0;
- foreach (byte[] val in message)
- {
- gmp.ParamList[i] = new GenericMessagePacket.ParamListBlock();
- gmp.ParamList[i++].Parameter = val;
- }
-
- OutPacket(gmp, ThrottleOutPacketType.AvatarInfo);
- }
-
- public void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals)
- {
- GroupActiveProposalItemReplyPacket GAPIRP = new GroupActiveProposalItemReplyPacket
- {
- AgentData = {AgentID = AgentId, GroupID = groupID},
- TransactionData =
- {
- TransactionID = transactionID,
- TotalNumItems = (uint) Proposals.Length
- },
- ProposalData =
- new GroupActiveProposalItemReplyPacket.
- ProposalDataBlock[Proposals.Length]
- };
-
-
- int i = 0;
- foreach (
- GroupActiveProposalItemReplyPacket.ProposalDataBlock ProposalData in
- Proposals.Select(Proposal => new GroupActiveProposalItemReplyPacket.ProposalDataBlock
- {
- VoteCast = Utils.StringToBytes("false"),
- VoteID = new UUID(Proposal.VoteID),
- VoteInitiator = new UUID(Proposal.VoteInitiator),
- Majority = Convert.ToInt32(Proposal.Majority),
- Quorum = Convert.ToInt32(Proposal.Quorum),
- TerseDateID = Utils.StringToBytes(Proposal.TerseDateID),
- StartDateTime = Utils.StringToBytes(Proposal.StartDateTime),
- EndDateTime = Utils.StringToBytes(Proposal.EndDateTime),
- ProposalText = Utils.StringToBytes(Proposal.ProposalText),
- AlreadyVoted = false
- }))
- {
- GAPIRP.ProposalData[i] = ProposalData;
- i++;
- }
- OutPacket(GAPIRP, ThrottleOutPacketType.AvatarInfo);
- }
-
- public void SendGroupVoteHistory(UUID groupID, UUID transactionID, GroupVoteHistory Vote,
- GroupVoteHistoryItem[] VoteItems)
- {
- GroupVoteHistoryItemReplyPacket GVHIRP = new GroupVoteHistoryItemReplyPacket
- {
- AgentData = {AgentID = AgentId, GroupID = groupID},
- TransactionData =
- {
- TransactionID = transactionID,
- TotalNumItems = (uint) VoteItems.Length
- },
- HistoryItemData =
- {
- VoteID = new UUID(Vote.VoteID),
- VoteInitiator = new UUID(Vote.VoteInitiator),
- Majority = Convert.ToInt32(Vote.Majority),
- Quorum = Convert.ToInt32(Vote.Quorum),
- TerseDateID = Utils.StringToBytes(Vote.TerseDateID),
- StartDateTime =
- Utils.StringToBytes(Vote.StartDateTime),
- EndDateTime = Utils.StringToBytes(Vote.EndDateTime),
- VoteType = Utils.StringToBytes(Vote.VoteType),
- VoteResult = Utils.StringToBytes(Vote.VoteResult),
- ProposalText =
- Utils.StringToBytes(Vote.ProposalText)
- }
- };
-
-
- int i = 0;
- GVHIRP.VoteItem = new GroupVoteHistoryItemReplyPacket.VoteItemBlock[VoteItems.Length];
-
- foreach (
- GroupVoteHistoryItemReplyPacket.VoteItemBlock VoteItem in
- VoteItems.Select(item => new GroupVoteHistoryItemReplyPacket.VoteItemBlock
- {
- CandidateID = item.CandidateID,
- NumVotes = item.NumVotes,
- VoteCast = Utils.StringToBytes(item.VoteCast)
- }))
- {
- GVHIRP.VoteItem[i] = VoteItem;
- i++;
- }
- OutPacket(GVHIRP, ThrottleOutPacketType.AvatarInfo);
- }
-
- public void SendGroupAccountingDetails(IClientAPI sender, UUID groupID, UUID transactionID, UUID sessionID,
- int amt, int currentInterval, int interval, string startDate,
- GroupAccountHistory[] history)
- {
- GroupAccountDetailsReplyPacket GADRP = new GroupAccountDetailsReplyPacket
- {
- AgentData = new GroupAccountDetailsReplyPacket.AgentDataBlock
- {AgentID = sender.AgentId, GroupID = groupID},
- HistoryData =
- new GroupAccountDetailsReplyPacket.HistoryDataBlock[
- history.Length]
- };
- int i = 0;
- foreach (GroupAccountHistory h in history)
- {
- GroupAccountDetailsReplyPacket.HistoryDataBlock History =
- new GroupAccountDetailsReplyPacket.HistoryDataBlock();
-
- History.Amount = h.Amount;
- History.Description = Utils.StringToBytes(h.Description);
-
- GADRP.HistoryData[i++] = History;
- }
- GADRP.MoneyData = new GroupAccountDetailsReplyPacket.MoneyDataBlock
- {
- CurrentInterval = currentInterval,
- IntervalDays = interval,
- RequestID = transactionID,
- Sta…
Large files files are truncated, but you can click here to view the full file