diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs index e43f7cf57a..c120a120fe 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs @@ -1,169 +1,184 @@ -/* - * Copyright (c) Contributors, 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 OpenSimulator 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 System; -using System.Collections.Generic; -using System.Net; -using OpenMetaverse; - -namespace OpenSim.Region.ClientStack.LindenUDP -{ - /// - /// Special collection that is optimized for tracking unacknowledged packets - /// - public sealed class UnackedPacketCollection - { - /// - /// Holds information about a pending acknowledgement - /// - private struct PendingAck - { - /// Sequence number of the packet to remove - public uint SequenceNumber; - /// Environment.TickCount value when the remove was queued. - /// This is used to update round-trip times for packets - public int RemoveTime; - /// Whether or not this acknowledgement was attached to a - /// resent packet. If so, round-trip time will not be calculated - public bool FromResend; - - public PendingAck(uint sequenceNumber, int currentTime, bool fromResend) - { - SequenceNumber = sequenceNumber; - RemoveTime = currentTime; - FromResend = fromResend; - } - } - - /// Holds the actual unacked packet data, sorted by sequence number - private Dictionary m_packets = new Dictionary(); - /// Holds packets that need to be added to the unacknowledged list - private LocklessQueue m_pendingAdds = new LocklessQueue(); - /// Holds information about pending acknowledgements - private LocklessQueue m_pendingRemoves = new LocklessQueue(); - - /// - /// Add an unacked packet to the collection - /// - /// Packet that is awaiting acknowledgement - /// True if the packet was successfully added, false if the - /// packet already existed in the collection - /// This does not immediately add the ACK to the collection, - /// it only queues it so it can be added in a thread-safe way later - public void Add(OutgoingPacket packet) - { - m_pendingAdds.Enqueue(packet); - } - - /// - /// Marks a packet as acknowledged - /// - /// Sequence number of the packet to - /// acknowledge - /// Current value of Environment.TickCount - /// This does not immediately acknowledge the packet, it only - /// queues the ack so it can be handled in a thread-safe way later - public void Remove(uint sequenceNumber, int currentTime, bool fromResend) - { - m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend)); - } - - /// - /// Returns a list of all of the packets with a TickCount older than - /// the specified timeout - /// - /// Number of ticks (milliseconds) before a - /// packet is considered expired - /// A list of all expired packets according to the given - /// expiration timeout - /// This function is not thread safe, and cannot be called - /// multiple times concurrently - public List GetExpiredPackets(int timeoutMS) - { - ProcessQueues(); - - List expiredPackets = null; - - if (m_packets.Count > 0) - { - int now = Environment.TickCount & Int32.MaxValue; - - foreach (OutgoingPacket packet in m_packets.Values) - { - // TickCount of zero means a packet is in the resend queue - // but hasn't actually been sent over the wire yet - if (packet.TickCount == 0) - continue; - - if (now - packet.TickCount >= timeoutMS) - { - if (expiredPackets == null) - expiredPackets = new List(); - - // The TickCount will be set to the current time when the packet - // is actually sent out again - packet.TickCount = 0; - - expiredPackets.Add(packet); - } - } - } - - return expiredPackets; - } - - private void ProcessQueues() - { - // Process all the pending adds - OutgoingPacket pendingAdd; - while (m_pendingAdds.Dequeue(out pendingAdd)) - m_packets[pendingAdd.SequenceNumber] = pendingAdd; - - // Process all the pending removes, including updating statistics and round-trip times - PendingAck pendingRemove; - OutgoingPacket ackedPacket; - while (m_pendingRemoves.Dequeue(out pendingRemove)) - { - if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket)) - { - m_packets.Remove(pendingRemove.SequenceNumber); - - // Update stats - System.Threading.Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); - - if (!pendingRemove.FromResend) - { - // Calculate the round-trip time for this packet and its ACK - int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount; - if (rtt > 0) - ackedPacket.Client.UpdateRoundTrip(rtt); - } - } - } - } - } -} +/* + * Copyright (c) Contributors, 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 OpenSimulator 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 System; +using System.Collections.Generic; +using System.Net; +using OpenMetaverse; + +namespace OpenSim.Region.ClientStack.LindenUDP +{ + /// + /// Special collection that is optimized for tracking unacknowledged packets + /// + public sealed class UnackedPacketCollection + { + /// + /// Holds information about a pending acknowledgement + /// + private struct PendingAck + { + /// Sequence number of the packet to remove + public uint SequenceNumber; + /// Environment.TickCount value when the remove was queued. + /// This is used to update round-trip times for packets + public int RemoveTime; + /// Whether or not this acknowledgement was attached to a + /// resent packet. If so, round-trip time will not be calculated + public bool FromResend; + + public PendingAck(uint sequenceNumber, int currentTime, bool fromResend) + { + SequenceNumber = sequenceNumber; + RemoveTime = currentTime; + FromResend = fromResend; + } + } + + /// Holds the actual unacked packet data, sorted by sequence number + private Dictionary m_packets = new Dictionary(); + /// Holds packets that need to be added to the unacknowledged list + private LocklessQueue m_pendingAdds = new LocklessQueue(); + /// Holds information about pending acknowledgements + private LocklessQueue m_pendingRemoves = new LocklessQueue(); + + /// + /// Add an unacked packet to the collection + /// + /// Packet that is awaiting acknowledgement + /// True if the packet was successfully added, false if the + /// packet already existed in the collection + /// This does not immediately add the ACK to the collection, + /// it only queues it so it can be added in a thread-safe way later + public void Add(OutgoingPacket packet) + { + m_pendingAdds.Enqueue(packet); + } + + /// + /// Marks a packet as acknowledged + /// + /// Sequence number of the packet to + /// acknowledge + /// Current value of Environment.TickCount + /// This does not immediately acknowledge the packet, it only + /// queues the ack so it can be handled in a thread-safe way later + public void Remove(uint sequenceNumber, int currentTime, bool fromResend) + { + m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend)); + } + + /// + /// Returns a list of all of the packets with a TickCount older than + /// the specified timeout + /// + /// Number of ticks (milliseconds) before a + /// packet is considered expired + /// A list of all expired packets according to the given + /// expiration timeout + /// This function is not thread safe, and cannot be called + /// multiple times concurrently + public List GetExpiredPackets(int timeoutMS) + { + ProcessQueues(); + + List expiredPackets = null; + + if (m_packets.Count > 0) + { + int now = Environment.TickCount & Int32.MaxValue; + + foreach (OutgoingPacket packet in m_packets.Values) + { + // TickCount of zero means a packet is in the resend queue + // but hasn't actually been sent over the wire yet + if (packet.TickCount == 0) + continue; + + if (now - packet.TickCount >= timeoutMS) + { + if (expiredPackets == null) + expiredPackets = new List(); + + // The TickCount will be set to the current time when the packet + // is actually sent out again + packet.TickCount = 0; + + expiredPackets.Add(packet); + } + } + } + + return expiredPackets; + } + + private void ProcessQueues() + { + // Process all the pending adds + + OutgoingPacket pendingAdd; + if (m_pendingAdds != null) + { + while (m_pendingAdds.Dequeue(out pendingAdd)) + { + if (pendingAdd != null && m_packets != null) + { + m_packets[pendingAdd.SequenceNumber] = pendingAdd; + } + } + } + + // Process all the pending removes, including updating statistics and round-trip times + PendingAck pendingRemove; + OutgoingPacket ackedPacket; + if (m_pendingRemoves != null) + { + while (m_pendingRemoves.Dequeue(out pendingRemove)) + { + if (m_pendingRemoves != null && m_packets != null) + { + if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket)) + { + m_packets.Remove(pendingRemove.SequenceNumber); + + // Update stats + System.Threading.Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); + + if (!pendingRemove.FromResend) + { + // Calculate the round-trip time for this packet and its ACK + int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount; + if (rtt > 0) + ackedPacket.Client.UpdateRoundTrip(rtt); + } + } + } + } + } + } + } +} diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs index fb0bd1a049..1498dbaf09 100644 --- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs @@ -1,220 +1,223 @@ -/* - * Copyright (c) Contributors, 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 OpenSimulator 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 System; -using System.Collections.Generic; -using System.Reflection; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenSim.Framework; - -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Services.Interfaces; - -namespace OpenSim.Region.CoreModules.Avatar.Dialog -{ - public class DialogModule : IRegionModule, IDialogModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - protected Scene m_scene; - - public void Initialise(Scene scene, IConfigSource source) - { - m_scene = scene; - m_scene.RegisterModuleInterface(this); - - m_scene.AddCommand( - this, "alert", "alert ", "Send an alert to a user", HandleAlertConsoleCommand); - - m_scene.AddCommand( - this, "alert general", "alert general ", "Send an alert to everyone", HandleAlertConsoleCommand); - - m_scene.AddCommand( - this, "alert dialog", "alert dialog ", "Send a dialog alert to everyone", HandleAlertConsoleCommand); - - - } - - public void PostInitialise() {} - public void Close() {} - public string Name { get { return "Dialog Module"; } } - public bool IsSharedModule { get { return false; } } - - public void SendAlertToUser(IClientAPI client, string message) - { - SendAlertToUser(client, message, false); - } - - public void SendAlertToUser(IClientAPI client, string message, bool modal) - { - client.SendAgentAlertMessage(message, modal); - } - - public void SendAlertToUser(UUID agentID, string message) - { - SendAlertToUser(agentID, message, false); - } - - public void SendAlertToUser(UUID agentID, string message, bool modal) - { - ScenePresence sp = m_scene.GetScenePresence(agentID); - - if (sp != null) - sp.ControllingClient.SendAgentAlertMessage(message, modal); - } - - public void SendAlertToUser(string firstName, string lastName, string message, bool modal) - { - ScenePresence presence = m_scene.GetScenePresence(firstName, lastName); - if (presence != null) - presence.ControllingClient.SendAgentAlertMessage(message, modal); - } - - public void SendGeneralAlert(string message) - { - m_scene.ForEachScenePresence(delegate(ScenePresence presence) - { - presence.ControllingClient.SendAlertMessage(message); - }); - } - - public void SendDialogToUser( - UUID avatarID, string objectName, UUID objectID, UUID ownerID, - string message, UUID textureID, int ch, string[] buttonlabels) - { - UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID); - string ownerFirstName, ownerLastName; - if (account != null) - { - ownerFirstName = account.FirstName; - ownerLastName = account.LastName; - } - else - { - ownerFirstName = "(unknown"; - ownerLastName = "user)"; - } - - ScenePresence sp = m_scene.GetScenePresence(avatarID); - if (sp != null) - sp.ControllingClient.SendDialog(objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels); - } - - public void SendUrlToUser( - UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url) - { - ScenePresence sp = m_scene.GetScenePresence(avatarID); - - if (sp != null) - sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url); - } - - public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid) - { - UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid); - string ownerFirstName, ownerLastName; - if (account != null) - { - ownerFirstName = account.FirstName; - ownerLastName = account.LastName; - } - else - { - ownerFirstName = "(unknown"; - ownerLastName = "user)"; - } - - ScenePresence sp = m_scene.GetScenePresence(avatarid); - - if (sp != null) - sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerFirstName, ownerLastName, objectid); - } - - public void SendNotificationToUsersInRegion( - UUID fromAvatarID, string fromAvatarName, string message) - { - m_scene.ForEachScenePresence(delegate(ScenePresence presence) - { - if (!presence.IsChildAgent) - presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message); - }); - } - - /// - /// Handle an alert command from the console. - /// - /// - /// - public void HandleAlertConsoleCommand(string module, string[] cmdparams) - { - if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene) - return; - - if (cmdparams[1] == "general") - { - string message = CombineParams(cmdparams, 2); - - m_log.InfoFormat( - "[DIALOG]: Sending general alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); - SendGeneralAlert(message); - } - else if (cmdparams[1] == "dialog") - { - string message = CombineParams(cmdparams, 2); - - m_log.InfoFormat( - "[DIALOG]: Sending dialog alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); - SendNotificationToUsersInRegion(UUID.Zero, "System", message); - } - else - { - string firstName = cmdparams[1]; - string lastName = cmdparams[2]; - string message = CombineParams(cmdparams, 3); - - m_log.InfoFormat( - "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}", - m_scene.RegionInfo.RegionName, firstName, lastName, message); - SendAlertToUser(firstName, lastName, message, false); - } - } - - private string CombineParams(string[] commandParams, int pos) - { - string result = string.Empty; - for (int i = pos; i < commandParams.Length; i++) - { - result += commandParams[i] + " "; - } - - return result; - } - } -} +/* + * Copyright (c) Contributors, 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 OpenSimulator 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 System; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; + +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.Avatar.Dialog +{ + public class DialogModule : IRegionModule, IDialogModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected Scene m_scene; + + public void Initialise(Scene scene, IConfigSource source) + { + m_scene = scene; + m_scene.RegisterModuleInterface(this); + + m_scene.AddCommand( + this, "alert", "alert ", "Send an alert to a user", HandleAlertConsoleCommand); + + m_scene.AddCommand( + this, "alert general", "alert general ", "Send an alert to everyone", HandleAlertConsoleCommand); + + m_scene.AddCommand( + this, "alert dialog", "alert dialog ", "Send a dialog alert to everyone", HandleAlertConsoleCommand); + + + } + + public void PostInitialise() {} + public void Close() {} + public string Name { get { return "Dialog Module"; } } + public bool IsSharedModule { get { return false; } } + + public void SendAlertToUser(IClientAPI client, string message) + { + SendAlertToUser(client, message, false); + } + + public void SendAlertToUser(IClientAPI client, string message, bool modal) + { + client.SendAgentAlertMessage(message, modal); + } + + public void SendAlertToUser(UUID agentID, string message) + { + SendAlertToUser(agentID, message, false); + } + + public void SendAlertToUser(UUID agentID, string message, bool modal) + { + ScenePresence sp = m_scene.GetScenePresence(agentID); + + if (sp != null) + sp.ControllingClient.SendAgentAlertMessage(message, modal); + } + + public void SendAlertToUser(string firstName, string lastName, string message, bool modal) + { + ScenePresence presence = m_scene.GetScenePresence(firstName, lastName); + if (presence != null) + presence.ControllingClient.SendAgentAlertMessage(message, modal); + } + + public void SendGeneralAlert(string message) + { + m_scene.ForEachScenePresence(delegate(ScenePresence presence) + { + if (!presence.IsChildAgent) + { + presence.ControllingClient.SendAlertMessage(message); + } + }); + } + + public void SendDialogToUser( + UUID avatarID, string objectName, UUID objectID, UUID ownerID, + string message, UUID textureID, int ch, string[] buttonlabels) + { + UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID); + string ownerFirstName, ownerLastName; + if (account != null) + { + ownerFirstName = account.FirstName; + ownerLastName = account.LastName; + } + else + { + ownerFirstName = "(unknown"; + ownerLastName = "user)"; + } + + ScenePresence sp = m_scene.GetScenePresence(avatarID); + if (sp != null) + sp.ControllingClient.SendDialog(objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels); + } + + public void SendUrlToUser( + UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url) + { + ScenePresence sp = m_scene.GetScenePresence(avatarID); + + if (sp != null) + sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url); + } + + public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid) + { + UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid); + string ownerFirstName, ownerLastName; + if (account != null) + { + ownerFirstName = account.FirstName; + ownerLastName = account.LastName; + } + else + { + ownerFirstName = "(unknown"; + ownerLastName = "user)"; + } + + ScenePresence sp = m_scene.GetScenePresence(avatarid); + + if (sp != null) + sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerFirstName, ownerLastName, objectid); + } + + public void SendNotificationToUsersInRegion( + UUID fromAvatarID, string fromAvatarName, string message) + { + m_scene.ForEachScenePresence(delegate(ScenePresence presence) + { + if (!presence.IsChildAgent) + presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message); + }); + } + + /// + /// Handle an alert command from the console. + /// + /// + /// + public void HandleAlertConsoleCommand(string module, string[] cmdparams) + { + if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene) + return; + + if (cmdparams[1] == "general") + { + string message = CombineParams(cmdparams, 2); + + m_log.InfoFormat( + "[DIALOG]: Sending general alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); + SendGeneralAlert(message); + } + else if (cmdparams[1] == "dialog") + { + string message = CombineParams(cmdparams, 2); + + m_log.InfoFormat( + "[DIALOG]: Sending dialog alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); + SendNotificationToUsersInRegion(UUID.Zero, "System", message); + } + else + { + string firstName = cmdparams[1]; + string lastName = cmdparams[2]; + string message = CombineParams(cmdparams, 3); + + m_log.InfoFormat( + "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}", + m_scene.RegionInfo.RegionName, firstName, lastName, message); + SendAlertToUser(firstName, lastName, message, false); + } + } + + private string CombineParams(string[] commandParams, int pos) + { + string result = string.Empty; + for (int i = pos; i < commandParams.Length; i++) + { + result += commandParams[i] + " "; + } + + return result; + } + } +} diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 8ce79a2488..a8281271fa 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -476,6 +476,7 @@ namespace OpenSim.Region.Framework.Scenes part.IgnoreUndoUpdate = false; part.StoreUndoState(UndoType.STATE_GROUP_POSITION); part.GroupPosition = val; + part.TriggerScriptChangedEvent(Changed.POSITION); } foreach (ScenePresence av in m_linkedAvatars) @@ -1734,9 +1735,9 @@ namespace OpenSim.Region.Framework.Scenes // don't backup while it's selected or you're asking for changes mid stream. if ((isTimeToPersist()) || (forcedBackup)) { - m_log.DebugFormat( - "[SCENE]: Storing {0}, {1} in {2}", - Name, UUID, m_scene.RegionInfo.RegionName); + // m_log.DebugFormat( + // "[SCENE]: Storing {0}, {1} in {2}", + // Name, UUID, m_scene.RegionInfo.RegionName); SceneObjectGroup backup_group = Copy(false); backup_group.RootPart.Velocity = RootPart.Velocity; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 773b012b4a..b0ce450b9b 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -60,7 +60,8 @@ namespace OpenSim.Region.Framework.Scenes TELEPORT = 512, REGION_RESTART = 1024, MEDIA = 2048, - ANIMATION = 16384 + ANIMATION = 16384, + POSITION = 32768 } // I don't really know where to put this except here. @@ -730,6 +731,7 @@ namespace OpenSim.Region.Framework.Scenes } } } + TriggerScriptChangedEvent(Changed.POSITION); } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index b3fa2f4403..56e7e93531 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1,4328 +1,4330 @@ -/* - * Copyright (c) Contributors, 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 OpenSimulator 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 System; -using System.Xml; -using System.Collections.Generic; -using System.Reflection; -using System.Timers; -using OpenMetaverse; -using log4net; -using OpenSim.Framework; -using OpenSim.Framework.Client; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes.Animation; -using OpenSim.Region.Framework.Scenes.Types; -using OpenSim.Region.Physics.Manager; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using OpenSim.Services.Interfaces; - -namespace OpenSim.Region.Framework.Scenes -{ - enum ScriptControlled : uint - { - CONTROL_ZERO = 0, - CONTROL_FWD = 1, - CONTROL_BACK = 2, - CONTROL_LEFT = 4, - CONTROL_RIGHT = 8, - CONTROL_UP = 16, - CONTROL_DOWN = 32, - CONTROL_ROT_LEFT = 256, - CONTROL_ROT_RIGHT = 512, - CONTROL_LBUTTON = 268435456, - CONTROL_ML_LBUTTON = 1073741824 - } - - struct ScriptControllers - { - public UUID itemID; - public ScriptControlled ignoreControls; - public ScriptControlled eventControls; - } - - public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List coarseLocations, List avatarUUIDs); - - public class ScenePresence : EntityBase, ISceneEntity - { -// ~ScenePresence() -// { -// m_log.Debug("[ScenePresence] Destructor called"); -// } - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; -// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); - private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); - private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); - - /// - /// Experimentally determined "fudge factor" to make sit-target positions - /// the same as in SecondLife. Fudge factor was tested for 36 different - /// test cases including prims of type box, sphere, cylinder, and torus, - /// with varying parameters for sit target location, prim size, prim - /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis - /// issue #1716 - /// -// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); - // Value revised by KF 091121 by comparison with SL. - private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); - - public UUID currentParcelUUID = UUID.Zero; - - private ISceneViewer m_sceneViewer; - - /// - /// The animator for this avatar - /// - public ScenePresenceAnimator Animator - { - get { return m_animator; } - } - protected ScenePresenceAnimator m_animator; - - /// - /// The scene objects attached to this avatar. Do not change this list directly - use methods such as - /// AddAttachment() and RemoveAttachment(). Lock this list when performing any read operations upon it. - /// - public List Attachments - { - get { return m_attachments; } - } - protected List m_attachments = new List(); - - private Dictionary scriptedcontrols = new Dictionary(); - private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; - private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; - private bool MouseDown = false; - private SceneObjectGroup proxyObjectGroup; - //private SceneObjectPart proxyObjectPart = null; - public Vector3 lastKnownAllowedPosition; - public bool sentMessageAboutRestrictedParcelFlyingDown; - public Vector4 CollisionPlane = Vector4.UnitW; - - private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation - private Vector3 m_avUnscriptedSitPos; // for non-scripted prims - private Vector3 m_lastPosition; - private Vector3 m_lastWorldPosition; - private Quaternion m_lastRotation; - private Vector3 m_lastVelocity; - //private int m_lastTerseSent; - - private bool m_updateflag; - private byte m_movementflag; - private Vector3? m_forceToApply; - private uint m_requestedSitTargetID; - private UUID m_requestedSitTargetUUID; - public bool SitGround = false; - - private SendCourseLocationsMethod m_sendCourseLocationsMethod; - - private bool m_startAnimationSet; - - //private Vector3 m_requestedSitOffset = new Vector3(); - - private Vector3 m_LastFinitePos; - - private float m_sitAvatarHeight = 2.0f; - - private int m_godLevel; - private int m_userLevel; - - private bool m_invulnerable = true; - - private Vector3 m_lastChildAgentUpdatePosition; - private Vector3 m_lastChildAgentUpdateCamPosition; - - private int m_perfMonMS; - - private bool m_setAlwaysRun; - private bool m_forceFly; - private bool m_flyDisabled; - - private float m_speedModifier = 1.0f; - - private Quaternion m_bodyRot= Quaternion.Identity; - - private Quaternion m_bodyRotPrevious = Quaternion.Identity; - - private const int LAND_VELOCITYMAG_MAX = 12; - - public bool IsRestrictedToRegion; - - public string JID = String.Empty; - - private float m_health = 100f; - - // Default AV Height - private float m_avHeight = 127.0f; - - protected RegionInfo m_regionInfo; - protected ulong crossingFromRegion; - - private readonly Vector3[] Dir_Vectors = new Vector3[11]; - private bool m_isNudging = false; - - // Position of agent's camera in world (region cordinates) - protected Vector3 m_CameraCenter; - protected Vector3 m_lastCameraCenter; - - protected Timer m_reprioritization_timer; - protected bool m_reprioritizing; - protected bool m_reprioritization_called; - - // Use these three vectors to figure out what the agent is looking at - // Convert it to a Matrix and/or Quaternion - protected Vector3 m_CameraAtAxis; - protected Vector3 m_CameraLeftAxis; - protected Vector3 m_CameraUpAxis; - private AgentManager.ControlFlags m_AgentControlFlags; - private Quaternion m_headrotation = Quaternion.Identity; - private byte m_state; - - //Reuse the Vector3 instead of creating a new one on the UpdateMovement method -// private Vector3 movementvector; - - private bool m_autopilotMoving; - private Vector3 m_autoPilotTarget; - private bool m_sitAtAutoTarget; - private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit - - private string m_nextSitAnimation = String.Empty; - - //PauPaw:Proper PID Controler for autopilot************ - private bool m_moveToPositionInProgress; - private Vector3 m_moveToPositionTarget; - private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); - - private bool m_followCamAuto; - - private int m_movementUpdateCount; - private int m_lastColCount = -1; //KF: Look for Collision chnages - private int m_updateCount = 0; //KF: Update Anims for a while - private static readonly int UPDATE_COUNT = 10; // how many frames to update for - private const int NumMovementsBetweenRayCast = 5; - private List m_lastColliders = new List(); - - private bool CameraConstraintActive; - //private int m_moveToPositionStateStatus; - //***************************************************** - - // Agent's Draw distance. - protected float m_DrawDistance; - - protected AvatarAppearance m_appearance; - - // neighbouring regions we have enabled a child agent in - // holds the seed cap for the child agent in that region - private Dictionary m_knownChildRegions = new Dictionary(); - - /// - /// Implemented Control Flags - /// - private enum Dir_ControlFlags - { - DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, - DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, - DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, - DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, - DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, - DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, - DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, - DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, - DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS, - DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG, - DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG - } - - /// - /// Position at which a significant movement was made - /// - private Vector3 posLastSignificantMove; - - // For teleports and crossings callbacks - string m_callbackURI; - UUID m_originRegionID; - - ulong m_rootRegionHandle; - - /// - /// Script engines present in the scene - /// - private IScriptModule[] m_scriptEngines; - - #region Properties - - /// - /// Physical scene representation of this Avatar. - /// - public PhysicsActor PhysicsActor - { - set { m_physicsActor = value; } - get { return m_physicsActor; } - } - - public byte MovementFlag - { - set { m_movementflag = value; } - get { return m_movementflag; } - } - - public bool Updated - { - set { m_updateflag = value; } - get { return m_updateflag; } - } - - public bool Invulnerable - { - set { m_invulnerable = value; } - get { return m_invulnerable; } - } - - public int UserLevel - { - get { return m_userLevel; } - } - - public int GodLevel - { - get { return m_godLevel; } - } - - public ulong RegionHandle - { - get { return m_rootRegionHandle; } - } - - public Vector3 CameraPosition - { - get { return m_CameraCenter; } - } - - public Quaternion CameraRotation - { - get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } - } - - public Vector3 CameraAtAxis - { - get { return m_CameraAtAxis; } - } - - public Vector3 CameraLeftAxis - { - get { return m_CameraLeftAxis; } - } - - public Vector3 CameraUpAxis - { - get { return m_CameraUpAxis; } - } - - public Vector3 Lookat - { - get - { - Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0); - - if (a == Vector3.Zero) - return a; - - return Util.GetNormalizedVector(a); - } - } - - private readonly string m_firstname; - - public string Firstname - { - get { return m_firstname; } - } - - private readonly string m_lastname; - - public string Lastname - { - get { return m_lastname; } - } - - private string m_grouptitle; - - public string Grouptitle - { - get { return m_grouptitle; } - set { m_grouptitle = value; } - } - - public float DrawDistance - { - get { return m_DrawDistance; } - } - - protected bool m_allowMovement = true; - - public bool AllowMovement - { - get { return m_allowMovement; } - set { m_allowMovement = value; } - } - - public bool SetAlwaysRun - { - get - { - if (PhysicsActor != null) - { - return PhysicsActor.SetAlwaysRun; - } - else - { - return m_setAlwaysRun; - } - } - set - { - m_setAlwaysRun = value; - if (PhysicsActor != null) - { - PhysicsActor.SetAlwaysRun = value; - } - } - } - - public byte State - { - get { return m_state; } - set { m_state = value; } - } - - public uint AgentControlFlags - { - get { return (uint)m_AgentControlFlags; } - set { m_AgentControlFlags = (AgentManager.ControlFlags)value; } - } - - /// - /// This works out to be the ClientView object associated with this avatar, or it's client connection manager - /// - private IClientAPI m_controllingClient; - - protected PhysicsActor m_physicsActor; - - /// - /// The client controlling this presence - /// - public IClientAPI ControllingClient - { - get { return m_controllingClient; } - } - - public IClientCore ClientView - { - get { return (IClientCore) m_controllingClient; } - } - - protected Vector3 m_parentPosition; - public Vector3 ParentPosition - { - get { return m_parentPosition; } - set { m_parentPosition = value; } - } - - /// - /// Position of this avatar relative to the region the avatar is in - /// - public override Vector3 AbsolutePosition - { - get - { - PhysicsActor actor = m_physicsActor; -// if (actor != null) - if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting! - m_pos = actor.Position; - - // If we're sitting, we need to update our position - if (m_parentID != 0) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); - if (part != null) - m_parentPosition = part.AbsolutePosition; - } - - return m_parentPosition + m_pos; - } - set - { - PhysicsActor actor = m_physicsActor; - if (actor != null) - { - try - { - lock (m_scene.SyncRoot) - m_physicsActor.Position = value; - } - catch (Exception e) - { - m_log.Error("[SCENEPRESENCE]: ABSOLUTE POSITION " + e.Message); - } - } - - if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting! - m_pos = value; - m_parentPosition = Vector3.Zero; - } - } - - public Vector3 OffsetPosition - { - get { return m_pos; } - set { m_pos = value; } - } - - /// - /// Current velocity of the avatar. - /// - public override Vector3 Velocity - { - get - { - PhysicsActor actor = m_physicsActor; - if (actor != null) - m_velocity = actor.Velocity; - - return m_velocity; - } - set - { - PhysicsActor actor = m_physicsActor; - if (actor != null) - { - try - { - lock (m_scene.SyncRoot) - actor.Velocity = value; - } - catch (Exception e) - { - m_log.Error("[SCENEPRESENCE]: VELOCITY " + e.Message); - } - } - - m_velocity = value; - } - } - - public Quaternion OffsetRotation - { - get { return m_offsetRotation; } - set { m_offsetRotation = value; } - } - - public Quaternion Rotation - { - get { - if (m_parentID != 0) - { - if (m_offsetRotation != null) - { - return m_offsetRotation; - } - else - { - return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); - } - - } - else - { - return m_bodyRot; - } - } - set { - m_bodyRot = value; - if (m_parentID != 0) - { - m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); - } - } - } - - public Quaternion PreviousRotation - { - get { return m_bodyRotPrevious; } - set { m_bodyRotPrevious = value; } - } - - /// - /// If this is true, agent doesn't have a representation in this scene. - /// this is an agent 'looking into' this scene from a nearby scene(region) - /// - /// if False, this agent has a representation in this scene - /// - private bool m_isChildAgent = true; - - public bool IsChildAgent - { - get { return m_isChildAgent; } - set { m_isChildAgent = value; } - } - - private uint m_parentID; - - - private UUID m_linkedPrim; - - public uint ParentID - { - get { return m_parentID; } - set { m_parentID = value; } - } - - public UUID LinkedPrim - { - get { return m_linkedPrim; } - set { m_linkedPrim = value; } - } - - public float Health - { - get { return m_health; } - set { m_health = value; } - } - - /// - /// These are the region handles known by the avatar. - /// - public List KnownChildRegionHandles - { - get - { - if (m_knownChildRegions.Count == 0) - return new List(); - else - return new List(m_knownChildRegions.Keys); - } - } - - public Dictionary KnownRegions - { - get { return m_knownChildRegions; } - set - { - m_knownChildRegions = value; - } - } - - public ISceneViewer SceneViewer - { - get { return m_sceneViewer; } - } - - public void AdjustKnownSeeds() - { - Dictionary seeds; - - if (Scene.CapsModule != null) - seeds = Scene.CapsModule.GetChildrenSeeds(UUID); - else - seeds = new Dictionary(); - - List old = new List(); - foreach (ulong handle in seeds.Keys) - { - uint x, y; - Utils.LongToUInts(handle, out x, out y); - x = x / Constants.RegionSize; - y = y / Constants.RegionSize; - if (Util.IsOutsideView(x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) - { - old.Add(handle); - } - } - DropOldNeighbours(old); - - if (Scene.CapsModule != null) - Scene.CapsModule.SetChildrenSeed(UUID, seeds); - - KnownRegions = seeds; - //m_log.Debug(" ++++++++++AFTER+++++++++++++ "); - //DumpKnownRegions(); - } - - public void DumpKnownRegions() - { - m_log.Info("================ KnownRegions "+Scene.RegionInfo.RegionName+" ================"); - foreach (KeyValuePair kvp in KnownRegions) - { - uint x, y; - Utils.LongToUInts(kvp.Key, out x, out y); - x = x / Constants.RegionSize; - y = y / Constants.RegionSize; - m_log.Info(" >> "+x+", "+y+": "+kvp.Value); - } - } - - private bool m_inTransit; - private bool m_mouseLook; - private bool m_leftButtonDown; - - public bool IsInTransit - { - get { return m_inTransit; } - set { m_inTransit = value; } - } - - public float SpeedModifier - { - get { return m_speedModifier; } - set { m_speedModifier = value; } - } - - public bool ForceFly - { - get { return m_forceFly; } - set { m_forceFly = value; } - } - - public bool FlyDisabled - { - get { return m_flyDisabled; } - set { m_flyDisabled = value; } - } - - public string Viewer - { - get { return m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode).Viewer; } - } - - #endregion - - #region Constructor(s) - - public ScenePresence() - { - m_sendCourseLocationsMethod = SendCoarseLocationsDefault; - CreateSceneViewer(); - m_animator = new ScenePresenceAnimator(this); - } - - private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() - { - m_rootRegionHandle = reginfo.RegionHandle; - m_controllingClient = client; - m_firstname = m_controllingClient.FirstName; - m_lastname = m_controllingClient.LastName; - m_name = String.Format("{0} {1}", m_firstname, m_lastname); - m_scene = world; - m_uuid = client.AgentId; - m_regionInfo = reginfo; - m_localId = m_scene.AllocateLocalId(); - - UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); - - if (account != null) - m_userLevel = account.UserLevel; - - IGroupsModule gm = m_scene.RequestModuleInterface(); - if (gm != null) - m_grouptitle = gm.GetGroupTitle(m_uuid); - - m_scriptEngines = m_scene.RequestModuleInterfaces(); - - AbsolutePosition = posLastSignificantMove = m_CameraCenter = - m_lastCameraCenter = m_controllingClient.StartPos; - - m_reprioritization_timer = new Timer(world.ReprioritizationInterval); - m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); - m_reprioritization_timer.AutoReset = false; - - AdjustKnownSeeds(); - Animator.TrySetMovementAnimation("STAND"); - // we created a new ScenePresence (a new child agent) in a fresh region. - // Request info about all the (root) agents in this region - // Note: This won't send data *to* other clients in that region (children don't send) - SendInitialFullUpdateToAllClients(); - RegisterToEvents(); - if (m_controllingClient != null) - { - m_controllingClient.ProcessPendingPackets(); - } - SetDirectionVectors(); - } - - public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, - AvatarWearable[] wearables) - : this(client, world, reginfo) - { - m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); - } - - public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) - : this(client, world, reginfo) - { - m_appearance = appearance; - } - - private void CreateSceneViewer() - { - m_sceneViewer = new SceneViewer(this); - } - - public void RegisterToEvents() - { - m_controllingClient.OnRequestWearables += SendWearables; - m_controllingClient.OnSetAppearance += SetAppearance; - m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; - //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; - m_controllingClient.OnAgentUpdate += HandleAgentUpdate; - m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit; - m_controllingClient.OnAgentSit += HandleAgentSit; - m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; - m_controllingClient.OnStartAnim += HandleStartAnim; - m_controllingClient.OnStopAnim += HandleStopAnim; - m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; - m_controllingClient.OnAutoPilotGo += DoAutoPilot; - m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition); - - // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); - // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); - } - - private void SetDirectionVectors() - { - Dir_Vectors[0] = Vector3.UnitX; //FORWARD - Dir_Vectors[1] = -Vector3.UnitX; //BACK - Dir_Vectors[2] = Vector3.UnitY; //LEFT - Dir_Vectors[3] = -Vector3.UnitY; //RIGHT - Dir_Vectors[4] = Vector3.UnitZ; //UP - Dir_Vectors[5] = -Vector3.UnitZ; //DOWN - Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE - Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE - Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE - Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE - Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge - } - - private Vector3[] GetWalkDirectionVectors() - { - Vector3[] vector = new Vector3[11]; - vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD - vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK - vector[2] = Vector3.UnitY; //LEFT - vector[3] = -Vector3.UnitY; //RIGHT - vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP - vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN - vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE - vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE - vector[8] = Vector3.UnitY; //LEFT_NUDGE - vector[9] = -Vector3.UnitY; //RIGHT_NUDGE - vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE - return vector; - } - - private bool[] GetDirectionIsNudge() - { - bool[] isNudge = new bool[11]; - isNudge[0] = false; //FORWARD - isNudge[1] = false; //BACK - isNudge[2] = false; //LEFT - isNudge[3] = false; //RIGHT - isNudge[4] = false; //UP - isNudge[5] = false; //DOWN - isNudge[6] = true; //FORWARD_NUDGE - isNudge[7] = true; //BACK_NUDGE - isNudge[8] = true; //LEFT_NUDGE - isNudge[9] = true; //RIGHT_NUDGE - isNudge[10] = true; //DOWN_Nudge - return isNudge; - } - - - #endregion - - public uint GenerateClientFlags(UUID ObjectID) - { - return m_scene.Permissions.GenerateClientFlags(m_uuid, ObjectID); - } - - /// - /// Send updates to the client about prims which have been placed on the update queue. We don't - /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent - /// timestamp has already been sent. - /// - public void SendPrimUpdates() - { - m_perfMonMS = Util.EnvironmentTickCount(); - - m_sceneViewer.SendPrimUpdates(); - - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - #region Status Methods - - /// - /// This turns a child agent, into a root agent - /// This is called when an agent teleports into a region, or if an - /// agent crosses into this region from a neighbor over the border - /// - public void MakeRootAgent(Vector3 pos, bool isFlying) - { - m_log.DebugFormat( - "[SCENE]: Upgrading child to root agent for {0} in {1}", - Name, m_scene.RegionInfo.RegionName); - - //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); - - IGroupsModule gm = m_scene.RequestModuleInterface(); - if (gm != null) - m_grouptitle = gm.GetGroupTitle(m_uuid); - - m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; - m_scene.SetRootAgentScene(m_uuid); - - // Moved this from SendInitialData to ensure that m_appearance is initialized - // before the inventory is processed in MakeRootAgent. This fixes a race condition - // related to the handling of attachments - //m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); - if (m_scene.TestBorderCross(pos, Cardinals.E)) - { - Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); - pos.X = crossedBorder.BorderLine.Z - 1; - } - - if (m_scene.TestBorderCross(pos, Cardinals.N)) - { - Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); - pos.Y = crossedBorder.BorderLine.Z - 1; - } - - //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet. - //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent, - //they'll bypass the landing point. But I can't think of any decent way of fixing this. - if (KnownChildRegionHandles.Count == 0) - { - ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); - if (land != null) - { - //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni. - if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && UserLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid) - { - pos = land.LandData.UserLocation; - } - } - } - - if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) - { - Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128); - - if (pos.X < 0) - { - emergencyPos.X = (int)Constants.RegionSize + pos.X; - if (!(pos.Y < 0)) - emergencyPos.Y = pos.Y; - if (!(pos.Z < 0)) - emergencyPos.Z = pos.Z; - } - if (pos.Y < 0) - { - emergencyPos.Y = (int)Constants.RegionSize + pos.Y; - if (!(pos.X < 0)) - emergencyPos.X = pos.X; - if (!(pos.Z < 0)) - emergencyPos.Z = pos.Z; - } - if (pos.Z < 0) - { - emergencyPos.Z = 128; - if (!(pos.Y < 0)) - emergencyPos.Y = pos.Y; - if (!(pos.X < 0)) - emergencyPos.X = pos.X; - } - } - - if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) - { - m_log.WarnFormat( - "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", - pos, Name, UUID); - - if (pos.X < 0f) pos.X = 0f; - if (pos.Y < 0f) pos.Y = 0f; - if (pos.Z < 0f) pos.Z = 0f; - } - - float localAVHeight = 1.56f; - if (m_avHeight != 127.0f) - { - localAVHeight = m_avHeight; - } - - float posZLimit = 0; - - if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) - posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; - - float newPosZ = posZLimit + localAVHeight / 2; - if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) - { - pos.Z = newPosZ; - } - AbsolutePosition = pos; - - AddToPhysicalScene(isFlying); - - if (m_forceFly) - { - m_physicsActor.Flying = true; - } - else if (m_flyDisabled) - { - m_physicsActor.Flying = false; - } - - if (m_appearance != null) - { - if (m_appearance.AvatarHeight > 0) - SetHeight(m_appearance.AvatarHeight); - } - else - { - m_log.ErrorFormat("[SCENE PRESENCE]: null appearance in MakeRoot in {0}", Scene.RegionInfo.RegionName); - // emergency; this really shouldn't happen - m_appearance = new AvatarAppearance(UUID); - } - - // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying - // avatar to return to the standing position in mid-air. On login it looks like this is being sent - // elsewhere anyway - // Animator.SendAnimPack(); - - m_scene.SwapRootAgentCount(false); - - //CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); - //if (userInfo != null) - // userInfo.FetchInventory(); - //else - // m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid); - - // On the next prim update, all objects will be sent - // - m_sceneViewer.Reset(); - - m_isChildAgent = false; - - // send the animations of the other presences to me - m_scene.ForEachScenePresence(delegate(ScenePresence presence) - { - if (presence != this) - presence.Animator.SendAnimPackToClient(ControllingClient); - }); - - m_scene.EventManager.TriggerOnMakeRootAgent(this); - } - - /// - /// This turns a root agent into a child agent - /// when an agent departs this region for a neighbor, this gets called. - /// - /// It doesn't get called for a teleport. Reason being, an agent that - /// teleports out may not end up anywhere near this region - /// - public void MakeChildAgent() - { - // It looks like m_animator is set to null somewhere, and MakeChild - // is called after that. Probably in aborted teleports. - if (m_animator == null) - m_animator = new ScenePresenceAnimator(this); - else - Animator.ResetAnimations(); - -// m_log.DebugFormat( -// "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", -// Name, UUID, m_scene.RegionInfo.RegionName); - - // Don't zero out the velocity since this can cause problems when an avatar is making a region crossing, - // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated. - //Velocity = new Vector3(0, 0, 0); - - m_isChildAgent = true; - m_scene.SwapRootAgentCount(true); - RemoveFromPhysicalScene(); - - // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into - - m_scene.EventManager.TriggerOnMakeChildAgent(this); - } - - /// - /// Removes physics plugin scene representation of this agent if it exists. - /// - private void RemoveFromPhysicalScene() - { - if (PhysicsActor != null) - { - m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; - m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; - m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); - m_physicsActor.UnSubscribeEvents(); - m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; - PhysicsActor = null; - } - } - - /// - /// - /// - /// - public void Teleport(Vector3 pos) - { - bool isFlying = false; - - if (m_physicsActor != null) - isFlying = m_physicsActor.Flying; - - RemoveFromPhysicalScene(); - Velocity = Vector3.Zero; - AbsolutePosition = pos; - AddToPhysicalScene(isFlying); - if (m_appearance != null) - { - if (m_appearance.AvatarHeight > 0) - SetHeight(m_appearance.AvatarHeight); - } - - SendTerseUpdateToAllClients(); - - } - - public void TeleportWithMomentum(Vector3 pos) - { - bool isFlying = false; - if (m_physicsActor != null) - isFlying = m_physicsActor.Flying; - - RemoveFromPhysicalScene(); - AbsolutePosition = pos; - AddToPhysicalScene(isFlying); - if (m_appearance != null) - { - if (m_appearance.AvatarHeight > 0) - SetHeight(m_appearance.AvatarHeight); - } - - SendTerseUpdateToAllClients(); - } - - /// - /// - /// - public void StopMovement() - { - } - - public void StopFlying() - { - ControllingClient.StopFlying(this); - } - - public void AddNeighbourRegion(ulong regionHandle, string cap) - { - lock (m_knownChildRegions) - { - if (!m_knownChildRegions.ContainsKey(regionHandle)) - { - uint x, y; - Utils.LongToUInts(regionHandle, out x, out y); - m_knownChildRegions.Add(regionHandle, cap); - } - } - } - - public void RemoveNeighbourRegion(ulong regionHandle) - { - lock (m_knownChildRegions) - { - if (m_knownChildRegions.ContainsKey(regionHandle)) - { - m_knownChildRegions.Remove(regionHandle); - //m_log.Debug(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); - } - } - } - - public void DropOldNeighbours(List oldRegions) - { - foreach (ulong handle in oldRegions) - { - RemoveNeighbourRegion(handle); - Scene.CapsModule.DropChildSeed(UUID, handle); - } - } - - public List GetKnownRegionList() - { - return new List(m_knownChildRegions.Keys); - } - - #endregion - - #region Event Handlers - - /// - /// Sets avatar height in the phyiscs plugin - /// - internal void SetHeight(float height) - { - m_avHeight = height; - if (PhysicsActor != null && !IsChildAgent) - { - Vector3 SetSize = new Vector3(0.45f, 0.6f, m_avHeight); - PhysicsActor.Size = SetSize; - } - } - - /// - /// Complete Avatar's movement into the region. - /// This is called upon a very important packet sent from the client, - /// so it's client-controlled. Never call this method directly. - /// - public void CompleteMovement(IClientAPI client) - { - //m_log.Debug("[SCENE PRESENCE]: CompleteMovement"); - - Vector3 look = Velocity; - if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) - { - look = new Vector3(0.99f, 0.042f, 0); - } - - // Prevent teleporting to an underground location - // (may crash client otherwise) - // - Vector3 pos = AbsolutePosition; - float ground = m_scene.GetGroundHeight(pos.X, pos.Y); - if (pos.Z < ground + 1.5f) - { - pos.Z = ground + 1.5f; - AbsolutePosition = pos; - } - m_isChildAgent = false; - bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); - MakeRootAgent(AbsolutePosition, m_flying); - - if ((m_callbackURI != null) && !m_callbackURI.Equals("")) - { - m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); - Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI); - m_callbackURI = null; - } - - //m_log.DebugFormat("Completed movement"); - - m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); - SendInitialData(); - - // Create child agents in neighbouring regions - if (!m_isChildAgent) - { - IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); - if (m_agentTransfer != null) - m_agentTransfer.EnableChildAgents(this); - else - m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active"); - - IFriendsModule friendsModule = m_scene.RequestModuleInterface(); - if (friendsModule != null) - friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); - } - - } - - /// - /// Callback for the Camera view block check. Gets called with the results of the camera view block test - /// hitYN is true when there's something in the way. - /// - /// - /// - /// - /// - public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) - { - const float POSITION_TOLERANCE = 0.02f; - const float VELOCITY_TOLERANCE = 0.02f; - const float ROTATION_TOLERANCE = 0.02f; - - if (m_followCamAuto) - { - if (hitYN) - { - CameraConstraintActive = true; - //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); - - Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); - ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); - } - else - { - if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || - !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || - !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) - { - if (CameraConstraintActive) - { - ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); - CameraConstraintActive = false; - } - } - } - } - } - - /// - /// This is the event handler for client movement. If a client is moving, this event is triggering. - /// - public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) - { - //if (m_isChildAgent) - //{ - // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); - // return; - //} - - m_perfMonMS = Util.EnvironmentTickCount(); - - ++m_movementUpdateCount; - if (m_movementUpdateCount < 1) - m_movementUpdateCount = 1; - - #region Sanity Checking - - // This is irritating. Really. - if (!AbsolutePosition.IsFinite()) - { - RemoveFromPhysicalScene(); - m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); - - m_pos = m_LastFinitePos; - - if (!m_pos.IsFinite()) - { - m_pos.X = 127f; - m_pos.Y = 127f; - m_pos.Z = 127f; - m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903"); - } - - AddToPhysicalScene(false); - } - else - { - m_LastFinitePos = m_pos; - } - - #endregion Sanity Checking - - #region Inputs - - AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; - Quaternion bodyRotation = agentData.BodyRotation; - - // Camera location in world. We'll need to raytrace - // from this location from time to time. - m_CameraCenter = agentData.CameraCenter; - if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) - { - ReprioritizeUpdates(); - m_lastCameraCenter = m_CameraCenter; - } - - // Use these three vectors to figure out what the agent is looking at - // Convert it to a Matrix and/or Quaternion - m_CameraAtAxis = agentData.CameraAtAxis; - m_CameraLeftAxis = agentData.CameraLeftAxis; - m_CameraUpAxis = agentData.CameraUpAxis; - - // The Agent's Draw distance setting - m_DrawDistance = agentData.Far; - - // Check if Client has camera in 'follow cam' or 'build' mode. - Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); - - m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) - && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; - - m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; - m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; - - #endregion Inputs - - if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) - { - StandUp(); - } - - //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); - // Raycast from the avatar's head to the camera to see if there's anything blocking the view - if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) - { - if (m_followCamAuto) - { - Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; - m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); - } - } - lock (scriptedcontrols) - { - if (scriptedcontrols.Count > 0) - { - SendControlToScripts((uint)flags); - flags = RemoveIgnoredControls(flags, IgnoredControls); - } - } - - if (m_autopilotMoving) - CheckAtSitTarget(); - - if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) - { - m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. - Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); - - // TODO: This doesn't prevent the user from walking yet. - // Setting parent ID would fix this, if we knew what value - // to use. Or we could add a m_isSitting variable. - //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); - SitGround = true; - } - - // In the future, these values might need to go global. - // Here's where you get them. - m_AgentControlFlags = flags; - m_headrotation = agentData.HeadRotation; - m_state = agentData.State; - - PhysicsActor actor = PhysicsActor; - if (actor == null) - { - return; - } - - bool update_movementflag = false; - - if (m_allowMovement && !SitGround) - { - if (agentData.UseClientAgentPosition) - { - m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f; - m_moveToPositionTarget = agentData.ClientAgentPosition; - } - - int i = 0; - - bool update_rotation = false; - bool DCFlagKeyPressed = false; - Vector3 agent_control_v3 = Vector3.Zero; - Quaternion q = bodyRotation; - - bool oldflying = PhysicsActor.Flying; - - if (m_forceFly) - actor.Flying = true; - else if (m_flyDisabled) - actor.Flying = false; - else - actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); - - if (actor.Flying != oldflying) - update_movementflag = true; - - if (q != m_bodyRot) - { - m_bodyRot = q; - update_rotation = true; - } - - //guilty until proven innocent.. - bool Nudging = true; - //Basically, if there is at least one non-nudge control then we don't need - //to worry about stopping the avatar - - if (m_parentID == 0) - { - bool bAllowUpdateMoveToPosition = false; - bool bResetMoveToPosition = false; - - Vector3[] dirVectors; - - // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying - // this prevents 'jumping' in inappropriate situations. - if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) - dirVectors = GetWalkDirectionVectors(); - else - dirVectors = Dir_Vectors; - - bool[] isNudge = GetDirectionIsNudge(); - - - - - - foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) - { - if (((uint)flags & (uint)DCF) != 0) - { - bResetMoveToPosition = true; - DCFlagKeyPressed = true; - try - { - agent_control_v3 += dirVectors[i]; - if (isNudge[i] == false) - { - Nudging = false; - } - } - catch (IndexOutOfRangeException) - { - // Why did I get this? - } - - if ((m_movementflag & (uint)DCF) == 0) - { - m_movementflag += (byte)(uint)DCF; - update_movementflag = true; - } - } - else - { - if ((m_movementflag & (uint)DCF) != 0) - { - m_movementflag -= (byte)(uint)DCF; - update_movementflag = true; - } - else - { - bAllowUpdateMoveToPosition = true; - } - } - i++; - } - //Paupaw:Do Proper PID for Autopilot here - if (bResetMoveToPosition) - { - m_moveToPositionTarget = Vector3.Zero; - m_moveToPositionInProgress = false; - update_movementflag = true; - bAllowUpdateMoveToPosition = false; - } - - if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving)) - { - //Check the error term of the current position in relation to the target position - if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 0.5f) - { - // we are close enough to the target - m_moveToPositionTarget = Vector3.Zero; - m_moveToPositionInProgress = false; - update_movementflag = true; - } - else - { - try - { - // move avatar in 2D at one meter/second towards target, in avatar coordinate frame. - // This movement vector gets added to the velocity through AddNewMovement(). - // Theoretically we might need a more complex PID approach here if other - // unknown forces are acting on the avatar and we need to adaptively respond - // to such forces, but the following simple approach seems to works fine. - Vector3 LocalVectorToTarget3D = - (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords - * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords - // Ignore z component of vector - Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); - LocalVectorToTarget2D.Normalize(); - - //We're not nudging - Nudging = false; - agent_control_v3 += LocalVectorToTarget2D; - - // update avatar movement flags. the avatar coordinate system is as follows: - // - // +X (forward) - // - // ^ - // | - // | - // | - // | - // (left) +Y <--------o--------> -Y - // avatar - // | - // | - // | - // | - // v - // -X - // - - // based on the above avatar coordinate system, classify the movement into - // one of left/right/back/forward. - if (LocalVectorToTarget2D.Y > 0)//MoveLeft - { - m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; - //AgentControlFlags - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; - update_movementflag = true; - } - else if (LocalVectorToTarget2D.Y < 0) //MoveRight - { - m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; - update_movementflag = true; - } - if (LocalVectorToTarget2D.X < 0) //MoveBack - { - m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; - update_movementflag = true; - } - else if (LocalVectorToTarget2D.X > 0) //Move Forward - { - m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; - update_movementflag = true; - } - } - catch (Exception e) - { - //Avoid system crash, can be slower but... - m_log.DebugFormat("Crash! {0}", e.ToString()); - } - } - } - } - - // Cause the avatar to stop flying if it's colliding - // with something with the down arrow pressed. - - // Only do this if we're flying - if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) - { - // Landing detection code - - // Are the landing controls requirements filled? - bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || - ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); - - // Are the collision requirements fulfilled? - bool colliding = (m_physicsActor.IsColliding == true); - - if (m_physicsActor.Flying && colliding && controlland) - { - // nesting this check because LengthSquared() is expensive and we don't - // want to do it every step when flying. - if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX)) - StopFlying(); - } - } - - if (update_movementflag || (update_rotation && DCFlagKeyPressed)) - { - // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed)); - // m_log.DebugFormat( - // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); - - AddNewMovement(agent_control_v3, q, Nudging); - - - } - } - - if (update_movementflag && !SitGround) - Animator.UpdateMovementAnimations(); - - m_scene.EventManager.TriggerOnClientMovement(this); - - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client) - { - m_autopilotMoving = true; - m_autoPilotTarget = Pos; - m_sitAtAutoTarget = false; - PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; - //proxy.PCode = (byte)PCode.ParticleSystem; - proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); - proxyObjectGroup.AttachToScene(m_scene); - - // Commented out this code since it could never have executed, but might still be informative. -// if (proxyObjectGroup != null) -// { - proxyObjectGroup.SendGroupFullUpdate(); - remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); - m_scene.DeleteSceneObject(proxyObjectGroup, false); -// } -// else -// { -// m_autopilotMoving = false; -// m_autoPilotTarget = Vector3.Zero; -// ControllingClient.SendAlertMessage("Autopilot cancelled"); -// } - } - - public void DoMoveToPosition(Object sender, string method, List args) - { - try - { - float locx = 0f; - float locy = 0f; - float locz = 0f; - uint regionX = 0; - uint regionY = 0; - try - { - Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY); - locx = Convert.ToSingle(args[0]) - (float)regionX; - locy = Convert.ToSingle(args[1]) - (float)regionY; - locz = Convert.ToSingle(args[2]); - } - catch (InvalidCastException) - { - m_log.Error("[CLIENT]: Invalid autopilot request"); - return; - } - m_moveToPositionInProgress = true; - m_moveToPositionTarget = new Vector3(locx, locy, locz); - } - catch (Exception ex) - { - //Why did I get this error? - m_log.Error("[SCENEPRESENCE]: DoMoveToPosition" + ex); - } - } - - private void CheckAtSitTarget() - { - //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); - if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5) - { - if (m_sitAtAutoTarget) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID); - if (part != null) - { - AbsolutePosition = part.AbsolutePosition; - Velocity = Vector3.Zero; - SendFullUpdateToAllClients(); - - HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ?? - } - //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); - m_requestedSitTargetUUID = UUID.Zero; - } - /* - else - { - //ControllingClient.SendAlertMessage("Autopilot cancelled"); - //SendTerseUpdateToAllClients(); - //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; - //proxy.PCode = (byte)PCode.ParticleSystem; - ////uint nextUUID = m_scene.NextLocalId; - - //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy); - //if (proxyObjectGroup != null) - //{ - //proxyObjectGroup.SendGroupFullUpdate(); - //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); - //m_scene.DeleteSceneObject(proxyObjectGroup); - //} - } - */ - m_autoPilotTarget = Vector3.Zero; - m_autopilotMoving = false; - } - } - /// - /// Perform the logic necessary to stand the avatar up. This method also executes - /// the stand animation. - /// - public void StandUp() - { - SitGround = false; - - if (m_parentID != 0) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); - if (part != null) - { - part.TaskInventory.LockItemsForRead(true); - TaskInventoryDictionary taskIDict = part.TaskInventory; - if (taskIDict != null) - { - foreach (UUID taskID in taskIDict.Keys) - { - UnRegisterControlEventsToScript(LocalId, taskID); - taskIDict[taskID].PermsMask &= ~( - 2048 | //PERMISSION_CONTROL_CAMERA - 4); // PERMISSION_TAKE_CONTROLS - } - } - part.TaskInventory.LockItemsForRead(false); - // Reset sit target. - if (part.GetAvatarOnSitTarget() == UUID) - part.SetAvatarOnSitTarget(UUID.Zero); - m_parentPosition = part.GetWorldPosition(); - ControllingClient.SendClearFollowCamProperties(part.ParentUUID); - } - // part.GetWorldRotation() is the rotation of the object being sat on - // Rotation is the sittiing Av's rotation - - Quaternion partRot; -// if (part.LinkNum == 1) -// { // Root prim of linkset -// partRot = part.ParentGroup.RootPart.RotationOffset; -// } -// else -// { // single or child prim - -// } - if (part == null) //CW: Part may be gone. llDie() for example. - { - partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); - } - else - { - partRot = part.GetWorldRotation(); - } - - Quaternion partIRot = Quaternion.Inverse(partRot); - - Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av - Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av - - - if (m_physicsActor == null) - { - AddToPhysicalScene(false); - } - //CW: If the part isn't null then we can set the current position - if (part != null) - { - Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset! - AbsolutePosition = avWorldStandUp; //KF: Fix stand up. - part.IsOccupied = false; - part.ParentGroup.DeleteAvatar(ControllingClient.AgentId); - } - else - { - //CW: Since the part doesn't exist, a coarse standup position isn't an issue - AbsolutePosition = m_lastWorldPosition; - } - - m_parentPosition = Vector3.Zero; - m_parentID = 0; - m_linkedPrim = UUID.Zero; - m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); - SendFullUpdateToAllClients(); - m_requestedSitTargetID = 0; - - if ((m_physicsActor != null) && (m_avHeight > 0)) - { - SetHeight(m_avHeight); - } - } - Animator.TrySetMovementAnimation("STAND"); - } - - private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) - { - SceneObjectPart targetPart = m_scene.GetSceneObjectPart(targetID); - if (targetPart == null) - return null; - - // If the primitive the player clicked on has a sit target and that sit target is not full, that sit target is used. - // If the primitive the player clicked on has no sit target, and one or more other linked objects have sit targets that are not full, the sit target of the object with the lowest link number will be used. - - // Get our own copy of the part array, and sort into the order we want to test - SceneObjectPart[] partArray = targetPart.ParentGroup.GetParts(); - Array.Sort(partArray, delegate(SceneObjectPart p1, SceneObjectPart p2) - { - // we want the originally selected part first, then the rest in link order -- so make the selected part link num (-1) - int linkNum1 = p1==targetPart ? -1 : p1.LinkNum; - int linkNum2 = p2==targetPart ? -1 : p2.LinkNum; - return linkNum1 - linkNum2; - } - ); - - //look for prims with explicit sit targets that are available - foreach (SceneObjectPart part in partArray) - { - // Is a sit target available? - Vector3 avSitOffSet = part.SitTargetPosition; - Quaternion avSitOrientation = part.SitTargetOrientation; - UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); - bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero); - bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. - if (SitTargetisSet && !SitTargetOccupied) - { - //switch the target to this prim - return part; - } - } - - // no explicit sit target found - use original target - return targetPart; - } - - private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) - { - bool autopilot = true; - Vector3 autopilotTarget = new Vector3(); - Quaternion sitOrientation = Quaternion.Identity; - Vector3 pos = new Vector3(); - Vector3 cameraEyeOffset = Vector3.Zero; - Vector3 cameraAtOffset = Vector3.Zero; - bool forceMouselook = false; - - //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); - SceneObjectPart part = FindNextAvailableSitTarget(targetID); - if (part == null) return; - - // TODO: determine position to sit at based on scene geometry; don't trust offset from client - // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it - - // part is the prim to sit on - // offset is the world-ref vector distance from that prim center to the click-spot - // UUID is the UUID of the Avatar doing the clicking - - m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation - - // Is a sit target available? - Vector3 avSitOffSet = part.SitTargetPosition; - Quaternion avSitOrientation = part.SitTargetOrientation; - - bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. - // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation()); - Quaternion partRot; -// if (part.LinkNum == 1) -// { // Root prim of linkset -// partRot = part.ParentGroup.RootPart.RotationOffset; -// } -// else -// { // single or child prim - partRot = part.GetWorldRotation(); -// } - Quaternion partIRot = Quaternion.Inverse(partRot); -//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet); - // Sit analysis rewritten by KF 091125 - if (SitTargetisSet) // scipted sit - { - if (!part.IsOccupied) - { -//Console.WriteLine("Scripted, unoccupied"); - part.SetAvatarOnSitTarget(UUID); // set that Av will be on it - offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one - - Quaternion nrot = avSitOrientation; - if (!part.IsRoot) - { - nrot = part.RotationOffset * avSitOrientation; - } - sitOrientation = nrot; // Change rotatione to the scripted one - OffsetRotation = nrot; - autopilot = false; // Jump direct to scripted llSitPos() - } - else - { -//Console.WriteLine("Scripted, occupied"); - return; - } - } - else // Not Scripted - { - if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) ) - { - // large prim & offset, ignore if other Avs sitting -// offset.Z -= 0.05f; - m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked - autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point - -//Console.WriteLine(" offset ={0}", offset); -//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos); -//Console.WriteLine(" autopilotTarget={0}", autopilotTarget); - - } - else // small offset - { -//Console.WriteLine("Small offset"); - if (!part.IsOccupied) - { - m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center - autopilotTarget = part.AbsolutePosition; -//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget); - } - else return; // occupied small - } // end large/small - } // end Scripted/not - cameraAtOffset = part.GetCameraAtOffset(); - cameraEyeOffset = part.GetCameraEyeOffset(); - forceMouselook = part.GetForceMouselook(); - if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); // - if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); // - - if (m_physicsActor != null) - { - // If we're not using the client autopilot, we're immediately warping the avatar to the location - // We can remove the physicsActor until they stand up. - m_sitAvatarHeight = m_physicsActor.Size.Z; - if (autopilot) - { // its not a scripted sit -// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5) - if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 2.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 2.0f) ) - { - autopilot = false; // close enough - m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup. - Not using the part's position because returning the AV to the last known standing - position is likely to be more friendly, isn't it? */ - RemoveFromPhysicalScene(); - AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target - } // else the autopilot will get us close - } - else - { // its a scripted sit - m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup. - I *am* using the part's position this time because we have no real idea how far away - the avatar is from the sit target. */ - RemoveFromPhysicalScene(); - } - } - else return; // physactor is null! - - Vector3 offsetr; // = offset * partIRot; - // KF: In a linkset, offsetr needs to be relative to the group root! 091208 - // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot); - // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error. - // { // Single, or Root prim of linkset, target is ClickOffset * RootRot - //offsetr = offset * partIRot; -// - // else - // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot) - // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + - // (offset * partRot); - // } - -//Console.WriteLine(" "); -//Console.WriteLine("link number ={0}", part.LinkNum); -//Console.WriteLine("Prim offset ={0}", part.OffsetPosition ); -//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset); -//Console.WriteLine("Click offst ={0}", offset); -//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation()); -//Console.WriteLine("offsetr ={0}", offsetr); -//Console.WriteLine("Camera At ={0}", cameraAtOffset); -//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset); - - //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child - ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); - - m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target - // This calls HandleAgentSit twice, once from here, and the client calls - // HandleAgentSit itself after it gets to the location - // It doesn't get to the location until we've moved them there though - // which happens in HandleAgentSit :P - m_autopilotMoving = autopilot; - m_autoPilotTarget = autopilotTarget; - m_sitAtAutoTarget = autopilot; - m_initialSitTarget = autopilotTarget; - if (!autopilot) - HandleAgentSit(remoteClient, UUID); - } - - public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) - { - if (m_parentID != 0) - { - StandUp(); - } - m_nextSitAnimation = "SIT"; - - //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); - SceneObjectPart part = FindNextAvailableSitTarget(targetID); - - if (part != null) - { - if (!String.IsNullOrEmpty(part.SitAnimation)) - { - m_nextSitAnimation = part.SitAnimation; - } - m_requestedSitTargetID = part.LocalId; - //m_requestedSitOffset = offset; - m_requestedSitTargetUUID = targetID; - - m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); - - if (m_scene.PhysicsScene.SupportsRayCast()) - { - //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); - //SitRayCastAvatarPosition(part); - //return; - } - } - else - { - - m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); - } - - - - SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); - } - /* - public void SitRayCastAvatarPosition(SceneObjectPart part) - { - Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; - Vector3 StartRayCastPosition = AbsolutePosition; - Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); - float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); - m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse); - } - - public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) - { - SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); - if (part != null) - { - if (hitYN) - { - if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) - { - SitRaycastFindEdge(collisionPoint, normal); - m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); - } - else - { - SitRayCastAvatarPositionCameraZ(part); - } - } - else - { - SitRayCastAvatarPositionCameraZ(part); - } - } - else - { - ControllingClient.SendAlertMessage("Sit position no longer exists"); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - - } - - public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) - { - // Next, try to raycast from the camera Z position - Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; - Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z; - Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); - float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); - m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse); - } - - public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) - { - SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); - if (part != null) - { - if (hitYN) - { - if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) - { - SitRaycastFindEdge(collisionPoint, normal); - m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal); - } - else - { - SitRayCastCameraPosition(part); - } - } - else - { - SitRayCastCameraPosition(part); - } - } - else - { - ControllingClient.SendAlertMessage("Sit position no longer exists"); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - - } - - public void SitRayCastCameraPosition(SceneObjectPart part) - { - // Next, try to raycast from the camera position - Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; - Vector3 StartRayCastPosition = CameraPosition; - Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); - float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); - m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse); - } - - public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) - { - SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); - if (part != null) - { - if (hitYN) - { - if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) - { - SitRaycastFindEdge(collisionPoint, normal); - m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); - } - else - { - SitRayHorizontal(part); - } - } - else - { - SitRayHorizontal(part); - } - } - else - { - ControllingClient.SendAlertMessage("Sit position no longer exists"); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - - } - - public void SitRayHorizontal(SceneObjectPart part) - { - // Next, try to raycast from the avatar position to fwd - Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; - Vector3 StartRayCastPosition = CameraPosition; - Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); - float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); - m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); - } - - public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) - { - SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); - if (part != null) - { - if (hitYN) - { - if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) - { - SitRaycastFindEdge(collisionPoint, normal); - m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); - // Next, try to raycast from the camera position - Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; - Vector3 StartRayCastPosition = CameraPosition; - Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); - float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); - //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition); - } - else - { - ControllingClient.SendAlertMessage("Sit position not accessable."); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - } - else - { - ControllingClient.SendAlertMessage("Sit position not accessable."); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - } - else - { - ControllingClient.SendAlertMessage("Sit position no longer exists"); - m_requestedSitTargetUUID = UUID.Zero; - m_requestedSitTargetID = 0; - m_requestedSitOffset = Vector3.Zero; - } - - } - - private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) - { - int i = 0; - //throw new NotImplementedException(); - //m_requestedSitTargetUUID = UUID.Zero; - //m_requestedSitTargetID = 0; - //m_requestedSitOffset = Vector3.Zero; - - SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); - } - */ - public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) - { - if (m_parentID != 0) - { - StandUp(); - } - if (!String.IsNullOrEmpty(sitAnimation)) - { - m_nextSitAnimation = sitAnimation; - } - else - { - m_nextSitAnimation = "SIT"; - } - - //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); - SceneObjectPart part = FindNextAvailableSitTarget(targetID); - if (part != null) - { - m_requestedSitTargetID = part.LocalId; - //m_requestedSitOffset = offset; - m_requestedSitTargetUUID = targetID; - - m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); - - if (m_scene.PhysicsScene.SupportsRayCast()) - { - //SitRayCastAvatarPosition(part); - //return; - } - } - else - { - m_log.Warn("Sit requested on unknown object: " + targetID); - } - - SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); - } - - public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) - { - if (!String.IsNullOrEmpty(m_nextSitAnimation)) - { - HandleAgentSit(remoteClient, agentID, m_nextSitAnimation); - } - else - { - HandleAgentSit(remoteClient, agentID, "SIT"); - } - } - - public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); - - if (m_sitAtAutoTarget || !m_autopilotMoving) - { - if (part != null) - { -//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation()); - if (part.GetAvatarOnSitTarget() == UUID) - { -//Console.WriteLine("Scripted Sit"); - // Scripted sit - Vector3 sitTargetPos = part.SitTargetPosition; - Quaternion sitTargetOrient = part.SitTargetOrientation; - m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); - m_pos += SIT_TARGET_ADJUSTMENT; - if (!part.IsRoot) - { - m_pos *= part.RotationOffset; - } - m_bodyRot = sitTargetOrient; - m_parentPosition = part.AbsolutePosition; - part.IsOccupied = true; - part.ParentGroup.AddAvatar(agentID); -Console.WriteLine("Scripted Sit ofset {0}", m_pos); - } - else - { - // if m_avUnscriptedSitPos is zero then Av sits above center - // Else Av sits at m_avUnscriptedSitPos - - // Non-scripted sit by Kitto Flora 21Nov09 - // Calculate angle of line from prim to Av - Quaternion partIRot; -// if (part.LinkNum == 1) -// { // Root prim of linkset -// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); -// } -// else -// { // single or child prim - partIRot = Quaternion.Inverse(part.GetWorldRotation()); -// } - Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos; - float y_diff = (m_avInitialPos.Y - sitTargetPos.Y); - float x_diff = ( m_avInitialPos.X - sitTargetPos.X); - if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0 - if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0 - float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff); - // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'. - // Av sits at world euler <0,0, z>, translated by part rotation - m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click - - m_parentPosition = part.AbsolutePosition; - part.IsOccupied = true; - part.ParentGroup.AddAvatar(agentID); - m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation - (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center - (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) + - m_avUnscriptedSitPos; // adds click offset, if any - //Set up raytrace to find top surface of prim - Vector3 size = part.Scale; - float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z)); - Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag); - Vector3 down = new Vector3(0f, 0f, -1f); -//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag); - m_scene.PhysicsScene.RaycastWorld( - start, // Vector3 position, - down, // Vector3 direction, - mag, // float length, - SitAltitudeCallback); // retMethod - } // end scripted/not - } - else // no Av - { - return; - } - } - - //We want our offsets to reference the root prim, not the child we may have sat on - if (!part.IsRoot) - { - m_parentID = part.ParentGroup.RootPart.LocalId; - m_pos += part.OffsetPosition; - } - else - { - m_parentID = m_requestedSitTargetID; - } - - m_linkedPrim = part.UUID; - - Velocity = Vector3.Zero; - RemoveFromPhysicalScene(); - - Animator.TrySetMovementAnimation(sitAnimation); - SendFullUpdateToAllClients(); - } - - public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal) - { - // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer - // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height. - if(hitYN) - { - // m_pos = Av offset from prim center to make look like on center - // m_parentPosition = Actual center pos of prim - // collisionPoint = spot on prim where we want to sit - // collisionPoint.Z = global sit surface height - SceneObjectPart part = m_scene.GetSceneObjectPart(localid); - Quaternion partIRot; -// if (part.LinkNum == 1) -/// { // Root prim of linkset -// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); -// } -// else -// { // single or child prim - partIRot = Quaternion.Inverse(part.GetWorldRotation()); -// } - if (m_initialSitTarget != null) - { - float offZ = collisionPoint.Z - m_initialSitTarget.Z; - Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction - //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset); - m_pos += offset; - // ControllingClient.SendClearFollowCamProperties(part.UUID); - } - - } - } // End SitAltitudeCallback KF. - - /// - /// Event handler for the 'Always run' setting on the client - /// Tells the physics plugin to increase speed of movement. - /// - public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun) - { - m_setAlwaysRun = pSetAlwaysRun; - if (PhysicsActor != null) - { - PhysicsActor.SetAlwaysRun = pSetAlwaysRun; - } - } - - public void HandleStartAnim(IClientAPI remoteClient, UUID animID) - { - Animator.AddAnimation(animID, UUID.Zero); - } - - public void HandleStopAnim(IClientAPI remoteClient, UUID animID) - { - Animator.RemoveAnimation(animID); - } - - /// - /// Rotate the avatar to the given rotation and apply a movement in the given relative vector - /// - /// The vector in which to move. This is relative to the rotation argument - /// The direction in which this avatar should now face. - public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging) - { - if (m_isChildAgent) - { - // WHAT??? - m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); - - // we have to reset the user's child agent connections. - // Likely, here they've lost the eventqueue for other regions so border - // crossings will fail at this point unless we reset them. - - List regions = new List(KnownChildRegionHandles); - regions.Remove(m_scene.RegionInfo.RegionHandle); - - MakeRootAgent(new Vector3(127f, 127f, 127f), true); - - // Async command - if (m_scene.SceneGridService != null) - { - m_scene.SceneGridService.SendCloseChildAgentConnections(UUID, regions); - - // Give the above command some time to try and close the connections. - // this is really an emergency.. so sleep, or we'll get all discombobulated. - System.Threading.Thread.Sleep(500); - } - - if (m_scene.SceneGridService != null) - { - IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); - if (m_agentTransfer != null) - m_agentTransfer.EnableChildAgents(this); - } - - return; - } - - m_perfMonMS = Util.EnvironmentTickCount(); - - Rotation = rotation; - Vector3 direc = vec * rotation; - direc.Normalize(); - PhysicsActor actor = m_physicsActor; - if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up. - - direc *= 0.03f * 128f * m_speedModifier; - - if (actor != null) - { - if (actor.Flying) - { - direc *= 4.0f; - //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); - //bool colliding = (m_physicsActor.IsColliding==true); - //if (controlland) - // m_log.Info("[AGENT]: landCommand"); - //if (colliding) - // m_log.Info("[AGENT]: colliding"); - //if (m_physicsActor.Flying && colliding && controlland) - //{ - // StopFlying(); - // m_log.Info("[AGENT]: Stop FLying"); - //} - } - else if (!actor.Flying && actor.IsColliding) - { - if (direc.Z > 2.0f) - { - if(m_animator.m_animTickJump == -1) - { - direc.Z *= 3.0f; // jump - } - else - { - direc.Z *= 0.1f; // prejump - } - /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs - Animator.TrySetMovementAnimation("PREJUMP"); - Animator.TrySetMovementAnimation("JUMP"); - */ - } - } - } - - // TODO: Add the force instead of only setting it to support multiple forces per frame? - m_forceToApply = direc; - m_isNudging = Nudging; - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - #endregion - - #region Overridden Methods - - public override void Update() - { - const float ROTATION_TOLERANCE = 0.01f; - const float VELOCITY_TOLERANCE = 0.001f; - const float POSITION_TOLERANCE = 0.05f; - //const int TIME_MS_TOLERANCE = 3000; - - - - if (m_isChildAgent == false) - { -// PhysicsActor actor = m_physicsActor; - - // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to - // grab the latest PhysicsActor velocity, whereas m_velocity is often - // storing a requested force instead of an actual traveling velocity - - // Throw away duplicate or insignificant updates - if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || - !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || - !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) - //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) - { - SendTerseUpdateToAllClients(); - - // Update the "last" values - m_lastPosition = m_pos; - m_lastRotation = m_bodyRot; - m_lastVelocity = Velocity; - //m_lastTerseSent = Environment.TickCount; - } - - // followed suggestion from mic bowman. reversed the two lines below. - if (m_parentID == 0 && m_physicsActor != null || m_parentID != 0) // Check that we have a physics actor or we're sitting on something - CheckForBorderCrossing(); - CheckForSignificantMovement(); // sends update to the modules. - } - - //Sending prim updates AFTER the avatar terse updates are sent - SendPrimUpdates(); - } - - #endregion - - #region Update Client(s) - - /// - /// Sends a location update to the client connected to this scenePresence - /// - /// - public void SendTerseUpdateToClient(IClientAPI remoteClient) - { - // If the client is inactive, it's getting its updates from another - // server. - if (remoteClient.IsActive) - { - m_perfMonMS = Util.EnvironmentTickCount(); - - PhysicsActor actor = m_physicsActor; - Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero; - - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - - //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); - - remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity); - - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - m_scene.StatsReporter.AddAgentUpdates(1); - } - } - - /// - /// Send a location/velocity/accelleration update to all agents in scene - /// - public void SendTerseUpdateToAllClients() - { - m_perfMonMS = Util.EnvironmentTickCount(); - - m_scene.ForEachClient(SendTerseUpdateToClient); - - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - public void SendCoarseLocations(List coarseLocations, List avatarUUIDs) - { - SendCourseLocationsMethod d = m_sendCourseLocationsMethod; - if (d != null) - { - d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs); - } - } - - public void SetSendCourseLocationMethod(SendCourseLocationsMethod d) - { - if (d != null) - m_sendCourseLocationsMethod = d; - } - - public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List coarseLocations, List avatarUUIDs) - { - m_perfMonMS = Util.EnvironmentTickCount(); - m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - /// - /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) - /// - /// - public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) - { - // 2 stage check is needed. - if (remoteAvatar == null) - return; - IClientAPI cl=remoteAvatar.ControllingClient; - if (cl == null) - return; - if (m_appearance.Texture == null) - return; - - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - - remoteAvatar.m_controllingClient.SendAvatarDataImmediate(this); - m_scene.StatsReporter.AddAgentUpdates(1); - } - - /// - /// Tell *ALL* agents about this agent - /// - public void SendInitialFullUpdateToAllClients() - { - m_perfMonMS = Util.EnvironmentTickCount(); - int avUpdates = 0; - m_scene.ForEachScenePresence(delegate(ScenePresence avatar) - { - ++avUpdates; - // only send if this is the root (children are only "listening posts" in a foreign region) - if (!IsChildAgent) - { - SendFullUpdateToOtherClient(avatar); - } - - if (avatar.LocalId != LocalId) - { - if (!avatar.IsChildAgent) - { - avatar.SendFullUpdateToOtherClient(this); - avatar.SendAppearanceToOtherAgent(this); - avatar.Animator.SendAnimPackToClient(ControllingClient); - } - } - }); - - m_scene.StatsReporter.AddAgentUpdates(avUpdates); - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - - //Animator.SendAnimPack(); - } - - public void SendFullUpdateToAllClients() - { - m_perfMonMS = Util.EnvironmentTickCount(); - - // only send update from root agents to other clients; children are only "listening posts" - int count = 0; - m_scene.ForEachScenePresence(delegate(ScenePresence sp) - { - if (sp.IsChildAgent) - return; - SendFullUpdateToOtherClient(sp); - ++count; - }); - m_scene.StatsReporter.AddAgentUpdates(count); - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - - Animator.SendAnimPack(); - } - - /// - /// Do everything required once a client completes its movement into a region - /// - public void SendInitialData() - { - // Moved this into CompleteMovement to ensure that m_appearance is initialized before - // the inventory arrives - // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); - - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - - m_controllingClient.SendAvatarDataImmediate(this); - - SendInitialFullUpdateToAllClients(); - SendAppearanceToAllOtherAgents(); - } - - /// - /// Tell the client for this scene presence what items it should be wearing now - /// - public void SendWearables() - { - m_log.DebugFormat("[SCENE]: Received request for wearables of {0}", Name); - - ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); - } - - /// - /// - /// - public void SendAppearanceToAllOtherAgents() - { - m_perfMonMS = Util.EnvironmentTickCount(); - - m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) - { - if (scenePresence.UUID != UUID) - { - SendAppearanceToOtherAgent(scenePresence); - } - }); - - m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); - } - - /// - /// Send appearance data to an agent that isn't this one. - /// - /// - public void SendAppearanceToOtherAgent(ScenePresence avatar) - { - avatar.ControllingClient.SendAppearance( - m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); - } - - /// - /// Set appearance data (textureentry and slider settings) received from the client - /// - /// - /// - public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) - { - if (m_physicsActor != null) - { - if (!IsChildAgent) - { - // This may seem like it's redundant, remove the avatar from the physics scene - // just to add it back again, but it saves us from having to update - // 3 variables 10 times a second. - bool flyingTemp = m_physicsActor.Flying; - RemoveFromPhysicalScene(); - //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); - - //PhysicsActor = null; - - AddToPhysicalScene(flyingTemp); - } - } - - #region Bake Cache Check - - if (textureEntry != null) - { - for (int i = 0; i < BAKE_INDICES.Length; i++) - { - int j = BAKE_INDICES[i]; - Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; - - if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) - { - if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) - { - m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); - this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); - } - } - } - - } - - - #endregion Bake Cache Check - - m_appearance.SetAppearance(textureEntry, visualParams); - if (m_appearance.AvatarHeight > 0) - SetHeight(m_appearance.AvatarHeight); - - // This is not needed, because only the transient data changed - //AvatarData adata = new AvatarData(m_appearance); - //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); - - SendAppearanceToAllOtherAgents(); - if (!m_startAnimationSet) - { - Animator.UpdateMovementAnimations(); - m_startAnimationSet = true; - } - - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - - m_controllingClient.SendAvatarDataImmediate(this); - } - - public void SetWearable(int wearableId, AvatarWearable wearable) - { - m_appearance.SetWearable(wearableId, wearable); - AvatarData adata = new AvatarData(m_appearance); - m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); - m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); - } - - // Because appearance setting is in a module, we actually need - // to give it access to our appearance directly, otherwise we - // get a synchronization issue. - public AvatarAppearance Appearance - { - get { return m_appearance; } - set { m_appearance = value; } - } - - #endregion - - #region Significant Movement Method - - /// - /// This checks for a significant movement and sends a courselocationchange update - /// - protected void CheckForSignificantMovement() - { - // Movement updates for agents in neighboring regions are sent directly to clients. - // This value only affects how often agent positions are sent to neighbor regions - // for things such as distance-based update prioritization - const float SIGNIFICANT_MOVEMENT = 2.0f; - - if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT) - { - posLastSignificantMove = AbsolutePosition; - m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); - } - - // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m - if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || - Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) - { - m_lastChildAgentUpdatePosition = AbsolutePosition; - m_lastChildAgentUpdateCamPosition = CameraPosition; - - ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); - cadu.ActiveGroupID = UUID.Zero.Guid; - cadu.AgentID = UUID.Guid; - cadu.alwaysrun = m_setAlwaysRun; - cadu.AVHeight = m_avHeight; - Vector3 tempCameraCenter = m_CameraCenter; - cadu.cameraPosition = tempCameraCenter; - cadu.drawdistance = m_DrawDistance; - cadu.GroupAccess = 0; - cadu.Position = AbsolutePosition; - cadu.regionHandle = m_rootRegionHandle; - float multiplier = 1; - int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); - if (innacurateNeighbors != 0) - { - multiplier = 1f / (float)innacurateNeighbors; - } - if (multiplier <= 0f) - { - multiplier = 0.25f; - } - - //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); - cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); - cadu.Velocity = Velocity; - - AgentPosition agentpos = new AgentPosition(); - agentpos.CopyFrom(cadu); - - m_scene.SendOutChildAgentUpdates(agentpos, this); - } - } - - #endregion - - #region Border Crossing Methods - - /// - /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion - /// - protected void CheckForBorderCrossing() - { - if (IsChildAgent) - return; - - Vector3 pos2 = AbsolutePosition; - Vector3 vel = Velocity; - int neighbor = 0; - int[] fix = new int[2]; - - float timeStep = 0.1f; - pos2.X = pos2.X + (vel.X*timeStep); - pos2.Y = pos2.Y + (vel.Y*timeStep); - pos2.Z = pos2.Z + (vel.Z*timeStep); - - if (!IsInTransit) - { - // Checks if where it's headed exists a region - - bool needsTransit = false; - if (m_scene.TestBorderCross(pos2, Cardinals.W)) - { - if (m_scene.TestBorderCross(pos2, Cardinals.S)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.SW, ref fix); - } - else if (m_scene.TestBorderCross(pos2, Cardinals.N)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.NW, ref fix); - } - else - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.W, ref fix); - } - } - else if (m_scene.TestBorderCross(pos2, Cardinals.E)) - { - if (m_scene.TestBorderCross(pos2, Cardinals.S)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.SE, ref fix); - } - else if (m_scene.TestBorderCross(pos2, Cardinals.N)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.NE, ref fix); - } - else - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.E, ref fix); - } - } - else if (m_scene.TestBorderCross(pos2, Cardinals.S)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.S, ref fix); - } - else if (m_scene.TestBorderCross(pos2, Cardinals.N)) - { - needsTransit = true; - neighbor = HaveNeighbor(Cardinals.N, ref fix); - } - - - // Makes sure avatar does not end up outside region - if (neighbor <= 0) - { - if (!needsTransit) - { - if (m_requestedSitTargetUUID == UUID.Zero) - { - Vector3 pos = AbsolutePosition; - if (AbsolutePosition.X < 0) - pos.X += Velocity.X; - else if (AbsolutePosition.X > Constants.RegionSize) - pos.X -= Velocity.X; - if (AbsolutePosition.Y < 0) - pos.Y += Velocity.Y; - else if (AbsolutePosition.Y > Constants.RegionSize) - pos.Y -= Velocity.Y; - AbsolutePosition = pos; - } - } - } - else if (neighbor > 0) - CrossToNewRegion(); - } - else - { - RemoveFromPhysicalScene(); - // This constant has been inferred from experimentation - // I'm not sure what this value should be, so I tried a few values. - timeStep = 0.04f; - pos2 = AbsolutePosition; - pos2.X = pos2.X + (vel.X * timeStep); - pos2.Y = pos2.Y + (vel.Y * timeStep); - pos2.Z = pos2.Z + (vel.Z * timeStep); - m_pos = pos2; - } - } - - protected int HaveNeighbor(Cardinals car, ref int[] fix) - { - uint neighbourx = m_regionInfo.RegionLocX; - uint neighboury = m_regionInfo.RegionLocY; - - int dir = (int)car; - - if (dir > 1 && dir < 5) //Heading East - neighbourx++; - else if (dir > 5) // Heading West - neighbourx--; - - if (dir < 3 || dir == 8) // Heading North - neighboury++; - else if (dir > 3 && dir < 7) // Heading Sout - neighboury--; - - int x = (int)(neighbourx * Constants.RegionSize); - int y = (int)(neighboury * Constants.RegionSize); - GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y); - - if (neighbourRegion == null) - { - fix[0] = (int)(m_regionInfo.RegionLocX - neighbourx); - fix[1] = (int)(m_regionInfo.RegionLocY - neighboury); - return dir * (-1); - } - else - return dir; - } - - /// - /// Moves the agent outside the region bounds - /// Tells neighbor region that we're crossing to it - /// If the neighbor accepts, remove the agent's viewable avatar from this scene - /// set them to a child agent. - /// - protected void CrossToNewRegion() - { - InTransit(); - try - { - m_scene.CrossAgentToNewRegion(this, m_physicsActor.Flying); - } - catch - { - m_scene.CrossAgentToNewRegion(this, false); - } - } - - public void InTransit() - { - m_inTransit = true; - - if ((m_physicsActor != null) && m_physicsActor.Flying) - m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY; - else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) - m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY; - } - - public void NotInTransit() - { - m_inTransit = false; - } - - public void RestoreInCurrentScene() - { - AddToPhysicalScene(false); // not exactly false - } - - public void Reset() - { - // Put the child agent back at the center - AbsolutePosition - = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); - Animator.ResetAnimations(); - } - - /// - /// Computes which child agents to close when the scene presence moves to another region. - /// Removes those regions from m_knownRegions. - /// - /// The new region's x on the map - /// The new region's y on the map - /// - public void CloseChildAgents(uint newRegionX, uint newRegionY) - { - List byebyeRegions = new List(); - m_log.DebugFormat( - "[SCENE PRESENCE]: Closing child agents. Checking {0} regions in {1}", - m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName); - //DumpKnownRegions(); - - lock (m_knownChildRegions) - { - foreach (ulong handle in m_knownChildRegions.Keys) - { - // Don't close the agent on this region yet - if (handle != Scene.RegionInfo.RegionHandle) - { - uint x, y; - Utils.LongToUInts(handle, out x, out y); - x = x / Constants.RegionSize; - y = y / Constants.RegionSize; - - //m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); - //m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); - if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) - { - byebyeRegions.Add(handle); - } - } - } - } - - if (byebyeRegions.Count > 0) - { - m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents"); - m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); - } - - foreach (ulong handle in byebyeRegions) - { - RemoveNeighbourRegion(handle); - } - } - - #endregion - - /// - /// This allows the Sim owner the abiility to kick users from their sim currently. - /// It tells the client that the agent has permission to do so. - /// - public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus) - { - if (godStatus) - { - // For now, assign god level 200 to anyone - // who is granted god powers, but has no god level set. - // - UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID); - if (account != null) - { - if (account.UserLevel > 0) - m_godLevel = account.UserLevel; - else - m_godLevel = 200; - } - } - else - { - m_godLevel = 0; - } - - ControllingClient.SendAdminResponse(token, (uint)m_godLevel); - } - - #region Child Agent Updates - - public void ChildAgentDataUpdate(AgentData cAgentData) - { - //m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName); - if (!IsChildAgent) - return; - - CopyFrom(cAgentData); - } - - /// - /// This updates important decision making data about a child agent - /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region - /// - public void ChildAgentDataUpdate(AgentPosition cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY) - { - if (!IsChildAgent) - return; - - //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); - int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; - int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; - - Vector3 offset = new Vector3(shiftx, shifty, 0f); - - m_DrawDistance = cAgentData.Far; - if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!! - m_pos = cAgentData.Position + offset; - - if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) - { - posLastSignificantMove = AbsolutePosition; - ReprioritizeUpdates(); - } - - m_CameraCenter = cAgentData.Center + offset; - - m_avHeight = cAgentData.Size.Z; - //SetHeight(cAgentData.AVHeight); - - if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0) - ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); - - // Sends out the objects in the user's draw distance if m_sendTasksToChild is true. - if (m_scene.m_seeIntoRegionFromNeighbor) - m_sceneViewer.Reset(); - - //cAgentData.AVHeight; - m_rootRegionHandle = cAgentData.RegionHandle; - //m_velocity = cAgentData.Velocity; - } - - public void CopyTo(AgentData cAgent) - { - cAgent.AgentID = UUID; - cAgent.RegionID = Scene.RegionInfo.RegionID; - - cAgent.Position = AbsolutePosition; - cAgent.Velocity = m_velocity; - cAgent.Center = m_CameraCenter; - // Don't copy the size; it is inferred from apearance parameters - //cAgent.Size = new Vector3(0, 0, m_avHeight); - cAgent.AtAxis = m_CameraAtAxis; - cAgent.LeftAxis = m_CameraLeftAxis; - cAgent.UpAxis = m_CameraUpAxis; - - cAgent.Far = m_DrawDistance; - - // Throttles - float multiplier = 1; - int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); - if (innacurateNeighbors != 0) - { - multiplier = 1f / innacurateNeighbors; - } - if (multiplier <= 0f) - { - multiplier = 0.25f; - } - //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); - cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); - - cAgent.HeadRotation = m_headrotation; - cAgent.BodyRotation = m_bodyRot; - cAgent.ControlFlags = (uint)m_AgentControlFlags; - - if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) - cAgent.GodLevel = (byte)m_godLevel; - else - cAgent.GodLevel = (byte) 0; - - cAgent.AlwaysRun = m_setAlwaysRun; - - try - { - // We might not pass the Wearables in all cases... - // They're only needed so that persistent changes to the appearance - // are preserved in the new region where the user is moving to. - // But in Hypergrid we might not let this happen. - int i = 0; - UUID[] wears = new UUID[m_appearance.Wearables.Length * 2]; - foreach (AvatarWearable aw in m_appearance.Wearables) - { - if (aw != null) - { - wears[i++] = aw.ItemID; - wears[i++] = aw.AssetID; - } - else - { - wears[i++] = UUID.Zero; - wears[i++] = UUID.Zero; - } - } - cAgent.Wearables = wears; - - cAgent.VisualParams = m_appearance.VisualParams; - - if (m_appearance.Texture != null) - cAgent.AgentTextures = m_appearance.Texture.GetBytes(); - } - catch (Exception e) - { - m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message); - } - - //Attachments - List attPoints = m_appearance.GetAttachedPoints(); - if (attPoints != null) - { - //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); - int i = 0; - AttachmentData[] attachs = new AttachmentData[attPoints.Count]; - foreach (int point in attPoints) - { - attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); - } - cAgent.Attachments = attachs; - } - - lock (scriptedcontrols) - { - ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; - int i = 0; - - foreach (ScriptControllers c in scriptedcontrols.Values) - { - controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); - } - cAgent.Controllers = controls; - } - - // Animations - try - { - cAgent.Anims = Animator.Animations.ToArray(); - } - catch { } - - // cAgent.GroupID = ?? - // Groups??? - - } - - public void CopyFrom(AgentData cAgent) - { - m_originRegionID = cAgent.RegionID; - - m_callbackURI = cAgent.CallbackURI; - - m_pos = cAgent.Position; - - m_velocity = cAgent.Velocity; - m_CameraCenter = cAgent.Center; - //m_avHeight = cAgent.Size.Z; - m_CameraAtAxis = cAgent.AtAxis; - m_CameraLeftAxis = cAgent.LeftAxis; - m_CameraUpAxis = cAgent.UpAxis; - - m_DrawDistance = cAgent.Far; - - if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) - ControllingClient.SetChildAgentThrottle(cAgent.Throttles); - - m_headrotation = cAgent.HeadRotation; - m_bodyRot = cAgent.BodyRotation; - m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; - - if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) - m_godLevel = cAgent.GodLevel; - m_setAlwaysRun = cAgent.AlwaysRun; - - uint i = 0; - try - { - if (cAgent.Wearables == null) - cAgent.Wearables = new UUID[0]; - AvatarWearable[] wears = new AvatarWearable[cAgent.Wearables.Length / 2]; - for (uint n = 0; n < cAgent.Wearables.Length; n += 2) - { - UUID itemId = cAgent.Wearables[n]; - UUID assetId = cAgent.Wearables[n + 1]; - wears[i++] = new AvatarWearable(itemId, assetId); - } - m_appearance.Wearables = wears; - Primitive.TextureEntry te; - if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1) - te = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); - else - te = AvatarAppearance.GetDefaultTexture(); - if ((cAgent.VisualParams == null) || (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) - cAgent.VisualParams = AvatarAppearance.GetDefaultVisualParams(); - m_appearance.SetAppearance(te, (byte[])cAgent.VisualParams.Clone()); - } - catch (Exception e) - { - m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message); - } - - // Attachments - try - { - if (cAgent.Attachments != null) - { - m_appearance.ClearAttachments(); - foreach (AttachmentData att in cAgent.Attachments) - { - m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); - } - } - } - catch { } - - try - { - lock (scriptedcontrols) - { - if (cAgent.Controllers != null) - { - scriptedcontrols.Clear(); - - foreach (ControllerData c in cAgent.Controllers) - { - ScriptControllers sc = new ScriptControllers(); - sc.itemID = c.ItemID; - sc.ignoreControls = (ScriptControlled)c.IgnoreControls; - sc.eventControls = (ScriptControlled)c.EventControls; - - scriptedcontrols[sc.itemID] = sc; - } - } - } - } - catch { } - // Animations - try - { - Animator.ResetAnimations(); - Animator.Animations.FromArray(cAgent.Anims); - } - catch { } - - //cAgent.GroupID = ?? - //Groups??? - } - - public bool CopyAgent(out IAgentData agent) - { - agent = new CompleteAgentData(); - CopyTo((AgentData)agent); - return true; - } - - #endregion Child Agent Updates - - /// - /// Handles part of the PID controller function for moving an avatar. - /// - public override void UpdateMovement() - { - if (m_forceToApply.HasValue) - { - - Vector3 force = m_forceToApply.Value; - m_updateflag = true; - Velocity = force; - - m_forceToApply = null; - } - else - { - if (m_isNudging) - { - Vector3 force = Vector3.Zero; - - m_updateflag = true; - Velocity = force; - m_isNudging = false; - m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND" - } - } - } - - public override void SetText(string text, Vector3 color, double alpha) - { - throw new Exception("Can't set Text on avatar."); - } - - /// - /// Adds a physical representation of the avatar to the Physics plugin - /// - public void AddToPhysicalScene(bool isFlying) - { - PhysicsScene scene = m_scene.PhysicsScene; - - Vector3 pVec = AbsolutePosition; - - // Old bug where the height was in centimeters instead of meters - if (m_avHeight == 127.0f) - { - m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new Vector3(0f, 0f, 1.56f), - isFlying); - } - else - { - m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, - new Vector3(0f, 0f, m_avHeight), isFlying); - } - scene.AddPhysicsActorTaint(m_physicsActor); - //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; - m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; - m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong - m_physicsActor.SubscribeEvents(500); - m_physicsActor.LocalID = LocalId; - } - - private void OutOfBoundsCall(Vector3 pos) - { - //bool flying = m_physicsActor.Flying; - //RemoveFromPhysicalScene(); - - //AddToPhysicalScene(flying); - if (ControllingClient != null) - ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); - } - - // Event called by the physics plugin to tell the avatar about a collision. - private void PhysicsCollisionUpdate(EventArgs e) - { - if (e == null) - return; - - // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents( - // as of this comment the interval is set in AddToPhysicalScene - if (Animator!=null) - { - if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper, - { // else its will lock out other animation changes, like ground sit. - Animator.UpdateMovementAnimations(); - m_updateCount--; - } - } - - CollisionEventUpdate collisionData = (CollisionEventUpdate)e; - Dictionary coldata = collisionData.m_objCollisionList; - - CollisionPlane = Vector4.UnitW; - - if (m_lastColCount != coldata.Count) - { - m_updateCount = UPDATE_COUNT; - m_lastColCount = coldata.Count; - } - - if (coldata.Count != 0 && Animator != null) - { - switch (Animator.CurrentMovementAnimation) - { - case "STAND": - case "WALK": - case "RUN": - case "CROUCH": - case "CROUCHWALK": - { - ContactPoint lowest; - lowest.SurfaceNormal = Vector3.Zero; - lowest.Position = Vector3.Zero; - lowest.Position.Z = Single.NaN; - - foreach (ContactPoint contact in coldata.Values) - { - if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) - { - lowest = contact; - } - } - - CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); - } - break; - } - } - - List thisHitColliders = new List(); - List endedColliders = new List(); - List startedColliders = new List(); - - foreach (uint localid in coldata.Keys) - { - thisHitColliders.Add(localid); - if (!m_lastColliders.Contains(localid)) - { - startedColliders.Add(localid); - } - //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); - } - - // calculate things that ended colliding - foreach (uint localID in m_lastColliders) - { - if (!thisHitColliders.Contains(localID)) - { - endedColliders.Add(localID); - } - } - //add the items that started colliding this time to the last colliders list. - foreach (uint localID in startedColliders) - { - m_lastColliders.Add(localID); - } - // remove things that ended colliding from the last colliders list - foreach (uint localID in endedColliders) - { - m_lastColliders.Remove(localID); - } - - // do event notification - if (startedColliders.Count > 0) - { - ColliderArgs StartCollidingMessage = new ColliderArgs(); - List colliding = new List(); - foreach (uint localId in startedColliders) - { - if (localId == 0) - continue; - - SceneObjectPart obj = Scene.GetSceneObjectPart(localId); - string data = ""; - if (obj != null) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = obj.UUID; - detobj.nameStr = obj.Name; - detobj.ownerUUID = obj.OwnerID; - detobj.posVector = obj.AbsolutePosition; - detobj.rotQuat = obj.GetWorldRotation(); - detobj.velVector = obj.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = obj.GroupID; - colliding.Add(detobj); - } - } - - if (colliding.Count > 0) - { - StartCollidingMessage.Colliders = colliding; - - foreach (SceneObjectGroup att in Attachments) - Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); - } - } - - if (endedColliders.Count > 0) - { - ColliderArgs EndCollidingMessage = new ColliderArgs(); - List colliding = new List(); - foreach (uint localId in endedColliders) - { - if (localId == 0) - continue; - - SceneObjectPart obj = Scene.GetSceneObjectPart(localId); - string data = ""; - if (obj != null) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = obj.UUID; - detobj.nameStr = obj.Name; - detobj.ownerUUID = obj.OwnerID; - detobj.posVector = obj.AbsolutePosition; - detobj.rotQuat = obj.GetWorldRotation(); - detobj.velVector = obj.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = obj.GroupID; - colliding.Add(detobj); - } - } - - if (colliding.Count > 0) - { - EndCollidingMessage.Colliders = colliding; - - foreach (SceneObjectGroup att in Attachments) - Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); - } - } - - if (thisHitColliders.Count > 0) - { - ColliderArgs CollidingMessage = new ColliderArgs(); - List colliding = new List(); - foreach (uint localId in thisHitColliders) - { - if (localId == 0) - continue; - - SceneObjectPart obj = Scene.GetSceneObjectPart(localId); - string data = ""; - if (obj != null) - { - DetectedObject detobj = new DetectedObject(); - detobj.keyUUID = obj.UUID; - detobj.nameStr = obj.Name; - detobj.ownerUUID = obj.OwnerID; - detobj.posVector = obj.AbsolutePosition; - detobj.rotQuat = obj.GetWorldRotation(); - detobj.velVector = obj.Velocity; - detobj.colliderType = 0; - detobj.groupUUID = obj.GroupID; - colliding.Add(detobj); - } - } - - if (colliding.Count > 0) - { - CollidingMessage.Colliders = colliding; - - lock (m_attachments) - { - foreach (SceneObjectGroup att in m_attachments) - Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage); - } - } - } - - if (m_invulnerable) - return; - - float starthealth = Health; - uint killerObj = 0; - foreach (uint localid in coldata.Keys) - { - SceneObjectPart part = Scene.GetSceneObjectPart(localid); - - if (part != null && part.ParentGroup.Damage != -1.0f) - Health -= part.ParentGroup.Damage; - else - { - if (coldata[localid].PenetrationDepth >= 0.10f) - Health -= coldata[localid].PenetrationDepth * 5.0f; - } - - if (Health <= 0.0f) - { - if (localid != 0) - killerObj = localid; - } - //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); - } - //Health = 100; - if (!m_invulnerable) - { - if (starthealth != Health) - { - ControllingClient.SendHealth(Health); - } - if (m_health <= 0) - m_scene.EventManager.TriggerAvatarKill(killerObj, this); - } - } - - public void setHealthWithUpdate(float health) - { - Health = health; - ControllingClient.SendHealth(Health); - } - - public void Close() - { - lock (m_attachments) - { - // Delete attachments from scene - // Don't try to save, as this thread won't live long - // enough to complete the save. This would cause no copy - // attachments to poof! - // - foreach (SceneObjectGroup grp in m_attachments) - { - m_scene.DeleteSceneObject(grp, false); - } - m_attachments.Clear(); - } - - lock (m_knownChildRegions) - { - m_knownChildRegions.Clear(); - } - - lock (m_reprioritization_timer) - { - m_reprioritization_timer.Enabled = false; - m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); - } - - // I don't get it but mono crashes when you try to dispose of this timer, - // unsetting the elapsed callback should be enough to allow for cleanup however. - // m_reprioritizationTimer.Dispose(); - - m_sceneViewer.Close(); - - RemoveFromPhysicalScene(); - m_animator.Close(); - m_animator = null; - } - - public void AddAttachment(SceneObjectGroup gobj) - { - lock (m_attachments) - { - m_attachments.Add(gobj); - } - } - - public bool HasAttachments() - { - return m_attachments.Count > 0; - } - - public bool HasScriptedAttachments() - { - lock (m_attachments) - { - foreach (SceneObjectGroup gobj in m_attachments) - { - if (gobj != null) - { - if (gobj.RootPart.Inventory.ContainsScripts()) - return true; - } - } - } - return false; - } - - public void RemoveAttachment(SceneObjectGroup gobj) - { - lock (m_attachments) - { - if (m_attachments.Contains(gobj)) - { - m_attachments.Remove(gobj); - } - } - } - - public bool ValidateAttachments() - { - lock (m_attachments) - { - // Validate - foreach (SceneObjectGroup gobj in m_attachments) - { - if (gobj == null) - return false; - - if (gobj.IsDeleted) - return false; - } - } - return true; - } - - /// - /// Send a script event to this scene presence's attachments - /// - /// The name of the event - /// The arguments for the event - public void SendScriptEventToAttachments(string eventName, Object[] args) - { - if (m_scriptEngines != null) - { - lock (m_attachments) - { - foreach (SceneObjectGroup grp in m_attachments) - { - // 16384 is CHANGED_ANIMATION - // - // Send this to all attachment root prims - // - foreach (IScriptModule m in m_scriptEngines) - { - if (m == null) // No script engine loaded - continue; - - m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); - } - } - } - } - } - - - public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) - { - m_controllingClient = client; - m_regionInfo = region; - m_scene = scene; - - RegisterToEvents(); - if (m_controllingClient != null) - { - m_controllingClient.ProcessPendingPackets(); - } - /* - AbsolutePosition = client.StartPos; - - Animations = new AvatarAnimations(); - Animations.LoadAnims(); - - m_animations = new List(); - m_animations.Add(Animations.AnimsUUID["STAND"]); - m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); - - SetDirectionVectors(); - */ - } - - internal void PushForce(Vector3 impulse) - { - if (PhysicsActor != null) - { - PhysicsActor.AddForce(impulse,true); - } - } - - public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) - { - ScriptControllers obj = new ScriptControllers(); - obj.ignoreControls = ScriptControlled.CONTROL_ZERO; - obj.eventControls = ScriptControlled.CONTROL_ZERO; - - obj.itemID = Script_item_UUID; - if (pass_on == 0 && accept == 0) - { - IgnoredControls |= (ScriptControlled)controls; - obj.ignoreControls = (ScriptControlled)controls; - } - - if (pass_on == 0 && accept == 1) - { - IgnoredControls |= (ScriptControlled)controls; - obj.ignoreControls = (ScriptControlled)controls; - obj.eventControls = (ScriptControlled)controls; - } - if (pass_on == 1 && accept == 1) - { - IgnoredControls = ScriptControlled.CONTROL_ZERO; - obj.eventControls = (ScriptControlled)controls; - obj.ignoreControls = ScriptControlled.CONTROL_ZERO; - } - - lock (scriptedcontrols) - { - if (pass_on == 1 && accept == 0) - { - IgnoredControls &= ~(ScriptControlled)controls; - if (scriptedcontrols.ContainsKey(Script_item_UUID)) - scriptedcontrols.Remove(Script_item_UUID); - } - else - { - scriptedcontrols[Script_item_UUID] = obj; - } - } - ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); - } - - public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID) - { - IgnoredControls = ScriptControlled.CONTROL_ZERO; - lock (scriptedcontrols) - { - scriptedcontrols.Clear(); - } - ControllingClient.SendTakeControls(int.MaxValue, false, false); - } - - public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) - { - ScriptControllers takecontrols; - - lock (scriptedcontrols) - { - if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols)) - { - ScriptControlled sctc = takecontrols.eventControls; - - ControllingClient.SendTakeControls((int)sctc, false, false); - ControllingClient.SendTakeControls((int)sctc, true, false); - - scriptedcontrols.Remove(Script_item_UUID); - IgnoredControls = ScriptControlled.CONTROL_ZERO; - foreach (ScriptControllers scData in scriptedcontrols.Values) - { - IgnoredControls |= scData.ignoreControls; - } - } - } - } - - internal void SendControlToScripts(uint flags) - { - ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; - - if (MouseDown) - { - allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) - { - allflags = ScriptControlled.CONTROL_ZERO; - MouseDown = true; - } - } - - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) - { - allflags |= ScriptControlled.CONTROL_ML_LBUTTON; - MouseDown = true; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0) - { - allflags |= ScriptControlled.CONTROL_LBUTTON; - MouseDown = true; - } - - // find all activated controls, whether the scripts are interested in them or not - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) - { - allflags |= ScriptControlled.CONTROL_FWD; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0) - { - allflags |= ScriptControlled.CONTROL_BACK; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0) - { - allflags |= ScriptControlled.CONTROL_UP; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0) - { - allflags |= ScriptControlled.CONTROL_DOWN; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0) - { - allflags |= ScriptControlled.CONTROL_LEFT; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0) - { - allflags |= ScriptControlled.CONTROL_RIGHT; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) - { - allflags |= ScriptControlled.CONTROL_ROT_RIGHT; - } - if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) - { - allflags |= ScriptControlled.CONTROL_ROT_LEFT; - } - // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that - if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands) - { - lock (scriptedcontrols) - { - foreach (KeyValuePair kvp in scriptedcontrols) - { - UUID scriptUUID = kvp.Key; - ScriptControllers scriptControlData = kvp.Value; - - ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us - ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle - ScriptControlled localChange = localHeld ^ localLast; // the changed bits - if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) - { - // only send if still pressed or just changed - m_scene.EventManager.TriggerControlEvent(scriptUUID, UUID, (uint)localHeld, (uint)localChange); - } - } - } - } - - LastCommands = allflags; - } - - internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) - { - if (ignored == ScriptControlled.CONTROL_ZERO) - return flags; - - if ((ignored & ScriptControlled.CONTROL_BACK) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); - if ((ignored & ScriptControlled.CONTROL_FWD) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_AT_POS); - if ((ignored & ScriptControlled.CONTROL_DOWN) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG); - if ((ignored & ScriptControlled.CONTROL_UP) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_UP_POS); - if ((ignored & ScriptControlled.CONTROL_LEFT) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); - if ((ignored & ScriptControlled.CONTROL_RIGHT) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG); - if ((ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG); - if ((ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS); - if ((ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN); - if ((ignored & ScriptControlled.CONTROL_LBUTTON) != 0) - flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN); - - //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, - //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, - //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, - //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, - //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, - //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, - //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG - - return flags; - } - - /// - /// RezAttachments. This should only be called upon login on the first region. - /// Attachment rezzings on crossings and TPs are done in a different way. - /// - public void RezAttachments() - { - if (null == m_appearance) - { - m_log.WarnFormat("[ATTACHMENT]: Appearance has not been initialized for agent {0}", UUID); - return; - } - - XmlDocument doc = new XmlDocument(); - string stateData = String.Empty; - - IAttachmentsService attServ = m_scene.RequestModuleInterface(); - if (attServ != null) - { - m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service"); - stateData = attServ.Get(ControllingClient.AgentId.ToString()); - if (stateData != String.Empty) - { - try - { - doc.LoadXml(stateData); - } - catch { } - } - } - - Dictionary itemData = new Dictionary(); - - XmlNodeList nodes = doc.GetElementsByTagName("Attachment"); - if (nodes.Count > 0) - { - foreach (XmlNode n in nodes) - { - XmlElement elem = (XmlElement)n; - string itemID = elem.GetAttribute("ItemID"); - string xml = elem.InnerXml; - - itemData[new UUID(itemID)] = xml; - } - } - - List attPoints = m_appearance.GetAttachedPoints(); - foreach (int p in attPoints) - { - if (m_isDeleted) - return; - - UUID itemID = m_appearance.GetAttachedItem(p); - UUID assetID = m_appearance.GetAttachedAsset(p); - - // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down - // But they're not used anyway, the item is being looked up for now, so let's proceed. - //if (UUID.Zero == assetID) - //{ - // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); - // continue; - //} - - try - { - string xmlData; - XmlDocument d = new XmlDocument(); - UUID asset; - if (itemData.TryGetValue(itemID, out xmlData)) - { - d.LoadXml(xmlData); - m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID); - - // Rez from inventory - asset - = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d); - - } - else - { - // Rez from inventory (with a null doc to let - // CHANGED_OWNER happen) - asset - = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null); - } - - m_log.InfoFormat( - "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", - p, itemID, assetID, asset); - } - catch (Exception e) - { - m_log.ErrorFormat("[ATTACHMENT]: Unable to rez attachment: {0}", e.ToString()); - } - } - } - - private void ReprioritizeUpdates() - { - if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time) - { - lock (m_reprioritization_timer) - { - if (!m_reprioritizing) - m_reprioritization_timer.Enabled = m_reprioritizing = true; - else - m_reprioritization_called = true; - } - } - } - - private void Reprioritize(object sender, ElapsedEventArgs e) - { - m_controllingClient.ReprioritizeUpdates(); - - lock (m_reprioritization_timer) - { - m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called; - m_reprioritization_called = false; - } - } - - private Vector3 Quat2Euler(Quaternion rot){ - float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) , - (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z))); - float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W))); - float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) , - (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z))); - return(new Vector3(x,y,z)); - } - - - } -} +/* + * Copyright (c) Contributors, 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 OpenSimulator 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 System; +using System.Xml; +using System.Collections.Generic; +using System.Reflection; +using System.Timers; +using OpenMetaverse; +using log4net; +using OpenSim.Framework; +using OpenSim.Framework.Client; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes.Animation; +using OpenSim.Region.Framework.Scenes.Types; +using OpenSim.Region.Physics.Manager; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.Framework.Scenes +{ + enum ScriptControlled : uint + { + CONTROL_ZERO = 0, + CONTROL_FWD = 1, + CONTROL_BACK = 2, + CONTROL_LEFT = 4, + CONTROL_RIGHT = 8, + CONTROL_UP = 16, + CONTROL_DOWN = 32, + CONTROL_ROT_LEFT = 256, + CONTROL_ROT_RIGHT = 512, + CONTROL_LBUTTON = 268435456, + CONTROL_ML_LBUTTON = 1073741824 + } + + struct ScriptControllers + { + public UUID itemID; + public ScriptControlled ignoreControls; + public ScriptControlled eventControls; + } + + public delegate void SendCourseLocationsMethod(UUID scene, ScenePresence presence, List coarseLocations, List avatarUUIDs); + + public class ScenePresence : EntityBase, ISceneEntity + { +// ~ScenePresence() +// { +// m_log.Debug("[ScenePresence] Destructor called"); +// } + + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; +// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); + private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); + private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); + + /// + /// Experimentally determined "fudge factor" to make sit-target positions + /// the same as in SecondLife. Fudge factor was tested for 36 different + /// test cases including prims of type box, sphere, cylinder, and torus, + /// with varying parameters for sit target location, prim size, prim + /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis + /// issue #1716 + /// +// private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.1f, 0.0f, 0.3f); + // Value revised by KF 091121 by comparison with SL. + private static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); + + public UUID currentParcelUUID = UUID.Zero; + + private ISceneViewer m_sceneViewer; + + /// + /// The animator for this avatar + /// + public ScenePresenceAnimator Animator + { + get { return m_animator; } + } + protected ScenePresenceAnimator m_animator; + + /// + /// The scene objects attached to this avatar. Do not change this list directly - use methods such as + /// AddAttachment() and RemoveAttachment(). Lock this list when performing any read operations upon it. + /// + public List Attachments + { + get { return m_attachments; } + } + protected List m_attachments = new List(); + + private Dictionary scriptedcontrols = new Dictionary(); + private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; + private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; + private bool MouseDown = false; + private SceneObjectGroup proxyObjectGroup; + //private SceneObjectPart proxyObjectPart = null; + public Vector3 lastKnownAllowedPosition; + public bool sentMessageAboutRestrictedParcelFlyingDown; + public Vector4 CollisionPlane = Vector4.UnitW; + + private Vector3 m_avInitialPos; // used to calculate unscripted sit rotation + private Vector3 m_avUnscriptedSitPos; // for non-scripted prims + private Vector3 m_lastPosition; + private Vector3 m_lastWorldPosition; + private Quaternion m_lastRotation; + private Vector3 m_lastVelocity; + //private int m_lastTerseSent; + + private bool m_updateflag; + private byte m_movementflag; + private Vector3? m_forceToApply; + private uint m_requestedSitTargetID; + private UUID m_requestedSitTargetUUID; + public bool SitGround = false; + + private SendCourseLocationsMethod m_sendCourseLocationsMethod; + + private bool m_startAnimationSet; + + //private Vector3 m_requestedSitOffset = new Vector3(); + + private Vector3 m_LastFinitePos; + + private float m_sitAvatarHeight = 2.0f; + + private int m_godLevel; + private int m_userLevel; + + private bool m_invulnerable = true; + + private Vector3 m_lastChildAgentUpdatePosition; + private Vector3 m_lastChildAgentUpdateCamPosition; + + private int m_perfMonMS; + + private bool m_setAlwaysRun; + private bool m_forceFly; + private bool m_flyDisabled; + + private float m_speedModifier = 1.0f; + + private Quaternion m_bodyRot= Quaternion.Identity; + + private Quaternion m_bodyRotPrevious = Quaternion.Identity; + + private const int LAND_VELOCITYMAG_MAX = 12; + + public bool IsRestrictedToRegion; + + public string JID = String.Empty; + + private float m_health = 100f; + + // Default AV Height + private float m_avHeight = 127.0f; + + protected RegionInfo m_regionInfo; + protected ulong crossingFromRegion; + + private readonly Vector3[] Dir_Vectors = new Vector3[11]; + private bool m_isNudging = false; + + // Position of agent's camera in world (region cordinates) + protected Vector3 m_CameraCenter; + protected Vector3 m_lastCameraCenter; + + protected Timer m_reprioritization_timer; + protected bool m_reprioritizing; + protected bool m_reprioritization_called; + + // Use these three vectors to figure out what the agent is looking at + // Convert it to a Matrix and/or Quaternion + protected Vector3 m_CameraAtAxis; + protected Vector3 m_CameraLeftAxis; + protected Vector3 m_CameraUpAxis; + private AgentManager.ControlFlags m_AgentControlFlags; + private Quaternion m_headrotation = Quaternion.Identity; + private byte m_state; + + //Reuse the Vector3 instead of creating a new one on the UpdateMovement method +// private Vector3 movementvector; + + private bool m_autopilotMoving; + private Vector3 m_autoPilotTarget; + private bool m_sitAtAutoTarget; + private Vector3 m_initialSitTarget = Vector3.Zero; //KF: First estimate of where to sit + + private string m_nextSitAnimation = String.Empty; + + //PauPaw:Proper PID Controler for autopilot************ + private bool m_moveToPositionInProgress; + private Vector3 m_moveToPositionTarget; + private Quaternion m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + + private bool m_followCamAuto; + + private int m_movementUpdateCount; + private int m_lastColCount = -1; //KF: Look for Collision chnages + private int m_updateCount = 0; //KF: Update Anims for a while + private static readonly int UPDATE_COUNT = 10; // how many frames to update for + private const int NumMovementsBetweenRayCast = 5; + private List m_lastColliders = new List(); + + private bool CameraConstraintActive; + //private int m_moveToPositionStateStatus; + //***************************************************** + + // Agent's Draw distance. + protected float m_DrawDistance; + + protected AvatarAppearance m_appearance; + + // neighbouring regions we have enabled a child agent in + // holds the seed cap for the child agent in that region + private Dictionary m_knownChildRegions = new Dictionary(); + + /// + /// Implemented Control Flags + /// + private enum Dir_ControlFlags + { + DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, + DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, + DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, + DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, + DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, + DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, + DIR_CONTROL_FLAG_FORWARD_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS, + DIR_CONTROL_FLAG_BACK_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG, + DIR_CONTROL_FLAG_LEFT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS, + DIR_CONTROL_FLAG_RIGHT_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG, + DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG + } + + /// + /// Position at which a significant movement was made + /// + private Vector3 posLastSignificantMove; + + // For teleports and crossings callbacks + string m_callbackURI; + UUID m_originRegionID; + + ulong m_rootRegionHandle; + + /// + /// Script engines present in the scene + /// + private IScriptModule[] m_scriptEngines; + + #region Properties + + /// + /// Physical scene representation of this Avatar. + /// + public PhysicsActor PhysicsActor + { + set { m_physicsActor = value; } + get { return m_physicsActor; } + } + + public byte MovementFlag + { + set { m_movementflag = value; } + get { return m_movementflag; } + } + + public bool Updated + { + set { m_updateflag = value; } + get { return m_updateflag; } + } + + public bool Invulnerable + { + set { m_invulnerable = value; } + get { return m_invulnerable; } + } + + public int UserLevel + { + get { return m_userLevel; } + } + + public int GodLevel + { + get { return m_godLevel; } + } + + public ulong RegionHandle + { + get { return m_rootRegionHandle; } + } + + public Vector3 CameraPosition + { + get { return m_CameraCenter; } + } + + public Quaternion CameraRotation + { + get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); } + } + + public Vector3 CameraAtAxis + { + get { return m_CameraAtAxis; } + } + + public Vector3 CameraLeftAxis + { + get { return m_CameraLeftAxis; } + } + + public Vector3 CameraUpAxis + { + get { return m_CameraUpAxis; } + } + + public Vector3 Lookat + { + get + { + Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0); + + if (a == Vector3.Zero) + return a; + + return Util.GetNormalizedVector(a); + } + } + + private readonly string m_firstname; + + public string Firstname + { + get { return m_firstname; } + } + + private readonly string m_lastname; + + public string Lastname + { + get { return m_lastname; } + } + + private string m_grouptitle; + + public string Grouptitle + { + get { return m_grouptitle; } + set { m_grouptitle = value; } + } + + public float DrawDistance + { + get { return m_DrawDistance; } + } + + protected bool m_allowMovement = true; + + public bool AllowMovement + { + get { return m_allowMovement; } + set { m_allowMovement = value; } + } + + public bool SetAlwaysRun + { + get + { + if (PhysicsActor != null) + { + return PhysicsActor.SetAlwaysRun; + } + else + { + return m_setAlwaysRun; + } + } + set + { + m_setAlwaysRun = value; + if (PhysicsActor != null) + { + PhysicsActor.SetAlwaysRun = value; + } + } + } + + public byte State + { + get { return m_state; } + set { m_state = value; } + } + + public uint AgentControlFlags + { + get { return (uint)m_AgentControlFlags; } + set { m_AgentControlFlags = (AgentManager.ControlFlags)value; } + } + + /// + /// This works out to be the ClientView object associated with this avatar, or it's client connection manager + /// + private IClientAPI m_controllingClient; + + protected PhysicsActor m_physicsActor; + + /// + /// The client controlling this presence + /// + public IClientAPI ControllingClient + { + get { return m_controllingClient; } + } + + public IClientCore ClientView + { + get { return (IClientCore) m_controllingClient; } + } + + protected Vector3 m_parentPosition; + public Vector3 ParentPosition + { + get { return m_parentPosition; } + set { m_parentPosition = value; } + } + + /// + /// Position of this avatar relative to the region the avatar is in + /// + public override Vector3 AbsolutePosition + { + get + { + PhysicsActor actor = m_physicsActor; +// if (actor != null) + if ((actor != null) && (m_parentID == 0)) // KF Do NOT update m_pos here if Av is sitting! + m_pos = actor.Position; + + // If we're sitting, we need to update our position + if (m_parentID != 0) + { + SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID); + if (part != null) + m_parentPosition = part.AbsolutePosition; + } + + return m_parentPosition + m_pos; + } + set + { + PhysicsActor actor = m_physicsActor; + if (actor != null) + { + try + { + lock (m_scene.SyncRoot) + m_physicsActor.Position = value; + } + catch (Exception e) + { + m_log.Error("[SCENEPRESENCE]: ABSOLUTE POSITION " + e.Message); + } + } + + if (m_parentID == 0) // KF Do NOT update m_pos here if Av is sitting! + m_pos = value; + m_parentPosition = Vector3.Zero; + } + } + + public Vector3 OffsetPosition + { + get { return m_pos; } + set { m_pos = value; } + } + + /// + /// Current velocity of the avatar. + /// + public override Vector3 Velocity + { + get + { + PhysicsActor actor = m_physicsActor; + if (actor != null) + m_velocity = actor.Velocity; + + return m_velocity; + } + set + { + PhysicsActor actor = m_physicsActor; + if (actor != null) + { + try + { + lock (m_scene.SyncRoot) + actor.Velocity = value; + } + catch (Exception e) + { + m_log.Error("[SCENEPRESENCE]: VELOCITY " + e.Message); + } + } + + m_velocity = value; + } + } + + public Quaternion OffsetRotation + { + get { return m_offsetRotation; } + set { m_offsetRotation = value; } + } + + public Quaternion Rotation + { + get { + if (m_parentID != 0) + { + if (m_offsetRotation != null) + { + return m_offsetRotation; + } + else + { + return new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + } + + } + else + { + return m_bodyRot; + } + } + set { + m_bodyRot = value; + if (m_parentID != 0) + { + m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + } + } + } + + public Quaternion PreviousRotation + { + get { return m_bodyRotPrevious; } + set { m_bodyRotPrevious = value; } + } + + /// + /// If this is true, agent doesn't have a representation in this scene. + /// this is an agent 'looking into' this scene from a nearby scene(region) + /// + /// if False, this agent has a representation in this scene + /// + private bool m_isChildAgent = true; + + public bool IsChildAgent + { + get { return m_isChildAgent; } + set { m_isChildAgent = value; } + } + + private uint m_parentID; + + + private UUID m_linkedPrim; + + public uint ParentID + { + get { return m_parentID; } + set { m_parentID = value; } + } + + public UUID LinkedPrim + { + get { return m_linkedPrim; } + set { m_linkedPrim = value; } + } + + public float Health + { + get { return m_health; } + set { m_health = value; } + } + + /// + /// These are the region handles known by the avatar. + /// + public List KnownChildRegionHandles + { + get + { + if (m_knownChildRegions.Count == 0) + return new List(); + else + return new List(m_knownChildRegions.Keys); + } + } + + public Dictionary KnownRegions + { + get { return m_knownChildRegions; } + set + { + m_knownChildRegions = value; + } + } + + public ISceneViewer SceneViewer + { + get { return m_sceneViewer; } + } + + public void AdjustKnownSeeds() + { + Dictionary seeds; + + if (Scene.CapsModule != null) + seeds = Scene.CapsModule.GetChildrenSeeds(UUID); + else + seeds = new Dictionary(); + + List old = new List(); + foreach (ulong handle in seeds.Keys) + { + uint x, y; + Utils.LongToUInts(handle, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + if (Util.IsOutsideView(x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY)) + { + old.Add(handle); + } + } + DropOldNeighbours(old); + + if (Scene.CapsModule != null) + Scene.CapsModule.SetChildrenSeed(UUID, seeds); + + KnownRegions = seeds; + //m_log.Debug(" ++++++++++AFTER+++++++++++++ "); + //DumpKnownRegions(); + } + + public void DumpKnownRegions() + { + m_log.Info("================ KnownRegions "+Scene.RegionInfo.RegionName+" ================"); + foreach (KeyValuePair kvp in KnownRegions) + { + uint x, y; + Utils.LongToUInts(kvp.Key, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + m_log.Info(" >> "+x+", "+y+": "+kvp.Value); + } + } + + private bool m_inTransit; + private bool m_mouseLook; + private bool m_leftButtonDown; + + public bool IsInTransit + { + get { return m_inTransit; } + set { m_inTransit = value; } + } + + public float SpeedModifier + { + get { return m_speedModifier; } + set { m_speedModifier = value; } + } + + public bool ForceFly + { + get { return m_forceFly; } + set { m_forceFly = value; } + } + + public bool FlyDisabled + { + get { return m_flyDisabled; } + set { m_flyDisabled = value; } + } + + public string Viewer + { + get { return m_scene.AuthenticateHandler.GetAgentCircuitData(ControllingClient.CircuitCode).Viewer; } + } + + #endregion + + #region Constructor(s) + + public ScenePresence() + { + m_sendCourseLocationsMethod = SendCoarseLocationsDefault; + CreateSceneViewer(); + m_animator = new ScenePresenceAnimator(this); + } + + private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() + { + m_rootRegionHandle = reginfo.RegionHandle; + m_controllingClient = client; + m_firstname = m_controllingClient.FirstName; + m_lastname = m_controllingClient.LastName; + m_name = String.Format("{0} {1}", m_firstname, m_lastname); + m_scene = world; + m_uuid = client.AgentId; + m_regionInfo = reginfo; + m_localId = m_scene.AllocateLocalId(); + + UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid); + + if (account != null) + m_userLevel = account.UserLevel; + + IGroupsModule gm = m_scene.RequestModuleInterface(); + if (gm != null) + m_grouptitle = gm.GetGroupTitle(m_uuid); + + m_scriptEngines = m_scene.RequestModuleInterfaces(); + + AbsolutePosition = posLastSignificantMove = m_CameraCenter = + m_lastCameraCenter = m_controllingClient.StartPos; + + m_reprioritization_timer = new Timer(world.ReprioritizationInterval); + m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); + m_reprioritization_timer.AutoReset = false; + + AdjustKnownSeeds(); + Animator.TrySetMovementAnimation("STAND"); + // we created a new ScenePresence (a new child agent) in a fresh region. + // Request info about all the (root) agents in this region + // Note: This won't send data *to* other clients in that region (children don't send) + SendInitialFullUpdateToAllClients(); + RegisterToEvents(); + if (m_controllingClient != null) + { + m_controllingClient.ProcessPendingPackets(); + } + SetDirectionVectors(); + } + + public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, + AvatarWearable[] wearables) + : this(client, world, reginfo) + { + m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); + } + + public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) + : this(client, world, reginfo) + { + m_appearance = appearance; + } + + private void CreateSceneViewer() + { + m_sceneViewer = new SceneViewer(this); + } + + public void RegisterToEvents() + { + m_controllingClient.OnRequestWearables += SendWearables; + m_controllingClient.OnSetAppearance += SetAppearance; + m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; + //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; + m_controllingClient.OnAgentUpdate += HandleAgentUpdate; + m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit; + m_controllingClient.OnAgentSit += HandleAgentSit; + m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; + m_controllingClient.OnStartAnim += HandleStartAnim; + m_controllingClient.OnStopAnim += HandleStopAnim; + m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls; + m_controllingClient.OnAutoPilotGo += DoAutoPilot; + m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition); + + // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); + // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); + } + + private void SetDirectionVectors() + { + Dir_Vectors[0] = Vector3.UnitX; //FORWARD + Dir_Vectors[1] = -Vector3.UnitX; //BACK + Dir_Vectors[2] = Vector3.UnitY; //LEFT + Dir_Vectors[3] = -Vector3.UnitY; //RIGHT + Dir_Vectors[4] = Vector3.UnitZ; //UP + Dir_Vectors[5] = -Vector3.UnitZ; //DOWN + Dir_Vectors[6] = new Vector3(0.5f, 0f, 0f); //FORWARD_NUDGE + Dir_Vectors[7] = new Vector3(-0.5f, 0f, 0f); //BACK_NUDGE + Dir_Vectors[8] = new Vector3(0f, 0.5f, 0f); //LEFT_NUDGE + Dir_Vectors[9] = new Vector3(0f, -0.5f, 0f); //RIGHT_NUDGE + Dir_Vectors[10] = new Vector3(0f, 0f, -0.5f); //DOWN_Nudge + } + + private Vector3[] GetWalkDirectionVectors() + { + Vector3[] vector = new Vector3[11]; + vector[0] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD + vector[1] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK + vector[2] = Vector3.UnitY; //LEFT + vector[3] = -Vector3.UnitY; //RIGHT + vector[4] = new Vector3(m_CameraAtAxis.Z, 0f, m_CameraUpAxis.Z); //UP + vector[5] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN + vector[6] = new Vector3(m_CameraUpAxis.Z, 0f, -m_CameraAtAxis.Z); //FORWARD_NUDGE + vector[7] = new Vector3(-m_CameraUpAxis.Z, 0f, m_CameraAtAxis.Z); //BACK_NUDGE + vector[8] = Vector3.UnitY; //LEFT_NUDGE + vector[9] = -Vector3.UnitY; //RIGHT_NUDGE + vector[10] = new Vector3(-m_CameraAtAxis.Z, 0f, -m_CameraUpAxis.Z); //DOWN_NUDGE + return vector; + } + + private bool[] GetDirectionIsNudge() + { + bool[] isNudge = new bool[11]; + isNudge[0] = false; //FORWARD + isNudge[1] = false; //BACK + isNudge[2] = false; //LEFT + isNudge[3] = false; //RIGHT + isNudge[4] = false; //UP + isNudge[5] = false; //DOWN + isNudge[6] = true; //FORWARD_NUDGE + isNudge[7] = true; //BACK_NUDGE + isNudge[8] = true; //LEFT_NUDGE + isNudge[9] = true; //RIGHT_NUDGE + isNudge[10] = true; //DOWN_Nudge + return isNudge; + } + + + #endregion + + public uint GenerateClientFlags(UUID ObjectID) + { + return m_scene.Permissions.GenerateClientFlags(m_uuid, ObjectID); + } + + /// + /// Send updates to the client about prims which have been placed on the update queue. We don't + /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent + /// timestamp has already been sent. + /// + public void SendPrimUpdates() + { + m_perfMonMS = Util.EnvironmentTickCount(); + + m_sceneViewer.SendPrimUpdates(); + + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + #region Status Methods + + /// + /// This turns a child agent, into a root agent + /// This is called when an agent teleports into a region, or if an + /// agent crosses into this region from a neighbor over the border + /// + public void MakeRootAgent(Vector3 pos, bool isFlying) + { + m_log.DebugFormat( + "[SCENE]: Upgrading child to root agent for {0} in {1}", + Name, m_scene.RegionInfo.RegionName); + + //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); + + IGroupsModule gm = m_scene.RequestModuleInterface(); + if (gm != null) + m_grouptitle = gm.GetGroupTitle(m_uuid); + + m_rootRegionHandle = m_scene.RegionInfo.RegionHandle; + m_scene.SetRootAgentScene(m_uuid); + + // Moved this from SendInitialData to ensure that m_appearance is initialized + // before the inventory is processed in MakeRootAgent. This fixes a race condition + // related to the handling of attachments + //m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); + if (m_scene.TestBorderCross(pos, Cardinals.E)) + { + Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); + pos.X = crossedBorder.BorderLine.Z - 1; + } + + if (m_scene.TestBorderCross(pos, Cardinals.N)) + { + Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); + pos.Y = crossedBorder.BorderLine.Z - 1; + } + + //If they're TP'ing in or logging in, we haven't had time to add any known child regions yet. + //This has the unfortunate consequence that if somebody is TP'ing who is already a child agent, + //they'll bypass the landing point. But I can't think of any decent way of fixing this. + if (KnownChildRegionHandles.Count == 0) + { + ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); + if (land != null) + { + //Don't restrict gods, estate managers, or land owners to the TP point. This behaviour mimics agni. + if (land.LandData.LandingType == (byte)1 && land.LandData.UserLocation != Vector3.Zero && UserLevel < 200 && !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid) && land.LandData.OwnerID != m_uuid) + { + pos = land.LandData.UserLocation; + } + } + } + + if (pos.X < 0 || pos.Y < 0 || pos.Z < 0) + { + Vector3 emergencyPos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 128); + + if (pos.X < 0) + { + emergencyPos.X = (int)Constants.RegionSize + pos.X; + if (!(pos.Y < 0)) + emergencyPos.Y = pos.Y; + if (!(pos.Z < 0)) + emergencyPos.Z = pos.Z; + } + if (pos.Y < 0) + { + emergencyPos.Y = (int)Constants.RegionSize + pos.Y; + if (!(pos.X < 0)) + emergencyPos.X = pos.X; + if (!(pos.Z < 0)) + emergencyPos.Z = pos.Z; + } + if (pos.Z < 0) + { + emergencyPos.Z = 128; + if (!(pos.Y < 0)) + emergencyPos.Y = pos.Y; + if (!(pos.X < 0)) + emergencyPos.X = pos.X; + } + } + + if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) + { + m_log.WarnFormat( + "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", + pos, Name, UUID); + + if (pos.X < 0f) pos.X = 0f; + if (pos.Y < 0f) pos.Y = 0f; + if (pos.Z < 0f) pos.Z = 0f; + } + + float localAVHeight = 1.56f; + if (m_avHeight != 127.0f) + { + localAVHeight = m_avHeight; + } + + float posZLimit = 0; + + if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) + posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; + + float newPosZ = posZLimit + localAVHeight / 2; + if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) + { + pos.Z = newPosZ; + } + AbsolutePosition = pos; + + AddToPhysicalScene(isFlying); + + if (m_forceFly) + { + m_physicsActor.Flying = true; + } + else if (m_flyDisabled) + { + m_physicsActor.Flying = false; + } + + if (m_appearance != null) + { + if (m_appearance.AvatarHeight > 0) + SetHeight(m_appearance.AvatarHeight); + } + else + { + m_log.ErrorFormat("[SCENE PRESENCE]: null appearance in MakeRoot in {0}", Scene.RegionInfo.RegionName); + // emergency; this really shouldn't happen + m_appearance = new AvatarAppearance(UUID); + } + + // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying + // avatar to return to the standing position in mid-air. On login it looks like this is being sent + // elsewhere anyway + // Animator.SendAnimPack(); + + m_scene.SwapRootAgentCount(false); + + //CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); + //if (userInfo != null) + // userInfo.FetchInventory(); + //else + // m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid); + + // On the next prim update, all objects will be sent + // + m_sceneViewer.Reset(); + + m_isChildAgent = false; + + // send the animations of the other presences to me + m_scene.ForEachScenePresence(delegate(ScenePresence presence) + { + if (presence != this) + presence.Animator.SendAnimPackToClient(ControllingClient); + }); + + m_scene.EventManager.TriggerOnMakeRootAgent(this); + } + + /// + /// This turns a root agent into a child agent + /// when an agent departs this region for a neighbor, this gets called. + /// + /// It doesn't get called for a teleport. Reason being, an agent that + /// teleports out may not end up anywhere near this region + /// + public void MakeChildAgent() + { + // It looks like m_animator is set to null somewhere, and MakeChild + // is called after that. Probably in aborted teleports. + if (m_animator == null) + m_animator = new ScenePresenceAnimator(this); + else + Animator.ResetAnimations(); + +// m_log.DebugFormat( +// "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", +// Name, UUID, m_scene.RegionInfo.RegionName); + + // Don't zero out the velocity since this can cause problems when an avatar is making a region crossing, + // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated. + //Velocity = new Vector3(0, 0, 0); + + m_isChildAgent = true; + m_scene.SwapRootAgentCount(true); + RemoveFromPhysicalScene(); + + // FIXME: Set m_rootRegionHandle to the region handle of the scene this agent is moving into + + m_scene.EventManager.TriggerOnMakeChildAgent(this); + } + + /// + /// Removes physics plugin scene representation of this agent if it exists. + /// + private void RemoveFromPhysicalScene() + { + if (PhysicsActor != null) + { + m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; + m_physicsActor.OnOutOfBounds -= OutOfBoundsCall; + m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); + m_physicsActor.UnSubscribeEvents(); + m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; + PhysicsActor = null; + } + } + + /// + /// + /// + /// + public void Teleport(Vector3 pos) + { + bool isFlying = false; + + if (m_physicsActor != null) + isFlying = m_physicsActor.Flying; + + RemoveFromPhysicalScene(); + Velocity = Vector3.Zero; + AbsolutePosition = pos; + AddToPhysicalScene(isFlying); + if (m_appearance != null) + { + if (m_appearance.AvatarHeight > 0) + SetHeight(m_appearance.AvatarHeight); + } + + SendTerseUpdateToAllClients(); + + } + + public void TeleportWithMomentum(Vector3 pos) + { + bool isFlying = false; + if (m_physicsActor != null) + isFlying = m_physicsActor.Flying; + + RemoveFromPhysicalScene(); + AbsolutePosition = pos; + AddToPhysicalScene(isFlying); + if (m_appearance != null) + { + if (m_appearance.AvatarHeight > 0) + SetHeight(m_appearance.AvatarHeight); + } + + SendTerseUpdateToAllClients(); + } + + /// + /// + /// + public void StopMovement() + { + } + + public void StopFlying() + { + ControllingClient.StopFlying(this); + } + + public void AddNeighbourRegion(ulong regionHandle, string cap) + { + lock (m_knownChildRegions) + { + if (!m_knownChildRegions.ContainsKey(regionHandle)) + { + uint x, y; + Utils.LongToUInts(regionHandle, out x, out y); + m_knownChildRegions.Add(regionHandle, cap); + } + } + } + + public void RemoveNeighbourRegion(ulong regionHandle) + { + lock (m_knownChildRegions) + { + if (m_knownChildRegions.ContainsKey(regionHandle)) + { + m_knownChildRegions.Remove(regionHandle); + //m_log.Debug(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count); + } + } + } + + public void DropOldNeighbours(List oldRegions) + { + foreach (ulong handle in oldRegions) + { + RemoveNeighbourRegion(handle); + Scene.CapsModule.DropChildSeed(UUID, handle); + } + } + + public List GetKnownRegionList() + { + return new List(m_knownChildRegions.Keys); + } + + #endregion + + #region Event Handlers + + /// + /// Sets avatar height in the phyiscs plugin + /// + internal void SetHeight(float height) + { + m_avHeight = height; + if (PhysicsActor != null && !IsChildAgent) + { + Vector3 SetSize = new Vector3(0.45f, 0.6f, m_avHeight); + PhysicsActor.Size = SetSize; + } + } + + /// + /// Complete Avatar's movement into the region. + /// This is called upon a very important packet sent from the client, + /// so it's client-controlled. Never call this method directly. + /// + public void CompleteMovement(IClientAPI client) + { + //m_log.Debug("[SCENE PRESENCE]: CompleteMovement"); + + Vector3 look = Velocity; + if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) + { + look = new Vector3(0.99f, 0.042f, 0); + } + + // Prevent teleporting to an underground location + // (may crash client otherwise) + // + Vector3 pos = AbsolutePosition; + float ground = m_scene.GetGroundHeight(pos.X, pos.Y); + if (pos.Z < ground + 1.5f) + { + pos.Z = ground + 1.5f; + AbsolutePosition = pos; + } + m_isChildAgent = false; + bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); + MakeRootAgent(AbsolutePosition, m_flying); + + if ((m_callbackURI != null) && !m_callbackURI.Equals("")) + { + m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); + Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI); + m_callbackURI = null; + } + + //m_log.DebugFormat("Completed movement"); + + m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); + SendInitialData(); + + // Create child agents in neighbouring regions + if (!m_isChildAgent) + { + IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); + if (m_agentTransfer != null) + m_agentTransfer.EnableChildAgents(this); + else + m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active"); + + IFriendsModule friendsModule = m_scene.RequestModuleInterface(); + if (friendsModule != null) + friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); + } + + } + + /// + /// Callback for the Camera view block check. Gets called with the results of the camera view block test + /// hitYN is true when there's something in the way. + /// + /// + /// + /// + /// + public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) + { + const float POSITION_TOLERANCE = 0.02f; + const float VELOCITY_TOLERANCE = 0.02f; + const float ROTATION_TOLERANCE = 0.02f; + + if (m_followCamAuto) + { + if (hitYN) + { + CameraConstraintActive = true; + //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); + + Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); + ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); + } + else + { + if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || + !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || + !m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) + { + if (CameraConstraintActive) + { + ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); + CameraConstraintActive = false; + } + } + } + } + } + + /// + /// This is the event handler for client movement. If a client is moving, this event is triggering. + /// + public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) + { + //if (m_isChildAgent) + //{ + // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); + // return; + //} + + m_perfMonMS = Util.EnvironmentTickCount(); + + ++m_movementUpdateCount; + if (m_movementUpdateCount < 1) + m_movementUpdateCount = 1; + + #region Sanity Checking + + // This is irritating. Really. + if (!AbsolutePosition.IsFinite()) + { + RemoveFromPhysicalScene(); + m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999902"); + + m_pos = m_LastFinitePos; + + if (!m_pos.IsFinite()) + { + m_pos.X = 127f; + m_pos.Y = 127f; + m_pos.Z = 127f; + m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903"); + } + + AddToPhysicalScene(false); + } + else + { + m_LastFinitePos = m_pos; + } + + #endregion Sanity Checking + + #region Inputs + + AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; + Quaternion bodyRotation = agentData.BodyRotation; + + // Camera location in world. We'll need to raytrace + // from this location from time to time. + m_CameraCenter = agentData.CameraCenter; + if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) + { + ReprioritizeUpdates(); + m_lastCameraCenter = m_CameraCenter; + } + + // Use these three vectors to figure out what the agent is looking at + // Convert it to a Matrix and/or Quaternion + m_CameraAtAxis = agentData.CameraAtAxis; + m_CameraLeftAxis = agentData.CameraLeftAxis; + m_CameraUpAxis = agentData.CameraUpAxis; + + // The Agent's Draw distance setting + m_DrawDistance = agentData.Far; + + // Check if Client has camera in 'follow cam' or 'build' mode. + Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); + + m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) + && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; + + m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; + m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; + + #endregion Inputs + + if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) + { + StandUp(); + } + + //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); + // Raycast from the avatar's head to the camera to see if there's anything blocking the view + if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) + { + if (m_followCamAuto) + { + Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; + m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(m_CameraCenter - posAdjusted), Vector3.Distance(m_CameraCenter, posAdjusted) + 0.3f, RayCastCameraCallback); + } + } + lock (scriptedcontrols) + { + if (scriptedcontrols.Count > 0) + { + SendControlToScripts((uint)flags); + flags = RemoveIgnoredControls(flags, IgnoredControls); + } + } + + if (m_autopilotMoving) + CheckAtSitTarget(); + + if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) + { + m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. + Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); + + // TODO: This doesn't prevent the user from walking yet. + // Setting parent ID would fix this, if we knew what value + // to use. Or we could add a m_isSitting variable. + //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); + SitGround = true; + } + + // In the future, these values might need to go global. + // Here's where you get them. + m_AgentControlFlags = flags; + m_headrotation = agentData.HeadRotation; + m_state = agentData.State; + + PhysicsActor actor = PhysicsActor; + if (actor == null) + { + return; + } + + bool update_movementflag = false; + + if (m_allowMovement && !SitGround) + { + if (agentData.UseClientAgentPosition) + { + m_moveToPositionInProgress = (agentData.ClientAgentPosition - AbsolutePosition).Length() > 0.2f; + m_moveToPositionTarget = agentData.ClientAgentPosition; + } + + int i = 0; + + bool update_rotation = false; + bool DCFlagKeyPressed = false; + Vector3 agent_control_v3 = Vector3.Zero; + Quaternion q = bodyRotation; + + bool oldflying = PhysicsActor.Flying; + + if (m_forceFly) + actor.Flying = true; + else if (m_flyDisabled) + actor.Flying = false; + else + actor.Flying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); + + if (actor.Flying != oldflying) + update_movementflag = true; + + if (q != m_bodyRot) + { + m_bodyRot = q; + update_rotation = true; + } + + //guilty until proven innocent.. + bool Nudging = true; + //Basically, if there is at least one non-nudge control then we don't need + //to worry about stopping the avatar + + if (m_parentID == 0) + { + bool bAllowUpdateMoveToPosition = false; + bool bResetMoveToPosition = false; + + Vector3[] dirVectors; + + // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying + // this prevents 'jumping' in inappropriate situations. + if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) + dirVectors = GetWalkDirectionVectors(); + else + dirVectors = Dir_Vectors; + + bool[] isNudge = GetDirectionIsNudge(); + + + + + + foreach (Dir_ControlFlags DCF in DIR_CONTROL_FLAGS) + { + if (((uint)flags & (uint)DCF) != 0) + { + bResetMoveToPosition = true; + DCFlagKeyPressed = true; + try + { + agent_control_v3 += dirVectors[i]; + if (isNudge[i] == false) + { + Nudging = false; + } + } + catch (IndexOutOfRangeException) + { + // Why did I get this? + } + + if ((m_movementflag & (uint)DCF) == 0) + { + m_movementflag += (byte)(uint)DCF; + update_movementflag = true; + } + } + else + { + if ((m_movementflag & (uint)DCF) != 0) + { + m_movementflag -= (byte)(uint)DCF; + update_movementflag = true; + } + else + { + bAllowUpdateMoveToPosition = true; + } + } + i++; + } + //Paupaw:Do Proper PID for Autopilot here + if (bResetMoveToPosition) + { + m_moveToPositionTarget = Vector3.Zero; + m_moveToPositionInProgress = false; + update_movementflag = true; + bAllowUpdateMoveToPosition = false; + } + + if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving)) + { + //Check the error term of the current position in relation to the target position + if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 0.5f) + { + // we are close enough to the target + m_moveToPositionTarget = Vector3.Zero; + m_moveToPositionInProgress = false; + update_movementflag = true; + } + else + { + try + { + // move avatar in 2D at one meter/second towards target, in avatar coordinate frame. + // This movement vector gets added to the velocity through AddNewMovement(). + // Theoretically we might need a more complex PID approach here if other + // unknown forces are acting on the avatar and we need to adaptively respond + // to such forces, but the following simple approach seems to works fine. + Vector3 LocalVectorToTarget3D = + (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords + * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords + // Ignore z component of vector + Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); + LocalVectorToTarget2D.Normalize(); + + //We're not nudging + Nudging = false; + agent_control_v3 += LocalVectorToTarget2D; + + // update avatar movement flags. the avatar coordinate system is as follows: + // + // +X (forward) + // + // ^ + // | + // | + // | + // | + // (left) +Y <--------o--------> -Y + // avatar + // | + // | + // | + // | + // v + // -X + // + + // based on the above avatar coordinate system, classify the movement into + // one of left/right/back/forward. + if (LocalVectorToTarget2D.Y > 0)//MoveLeft + { + m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; + //AgentControlFlags + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; + update_movementflag = true; + } + else if (LocalVectorToTarget2D.Y < 0) //MoveRight + { + m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; + update_movementflag = true; + } + if (LocalVectorToTarget2D.X < 0) //MoveBack + { + m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; + update_movementflag = true; + } + else if (LocalVectorToTarget2D.X > 0) //Move Forward + { + m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; + update_movementflag = true; + } + } + catch (Exception e) + { + //Avoid system crash, can be slower but... + m_log.DebugFormat("Crash! {0}", e.ToString()); + } + } + } + } + + // Cause the avatar to stop flying if it's colliding + // with something with the down arrow pressed. + + // Only do this if we're flying + if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) + { + // Landing detection code + + // Are the landing controls requirements filled? + bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || + ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); + + // Are the collision requirements fulfilled? + bool colliding = (m_physicsActor.IsColliding == true); + + if (m_physicsActor.Flying && colliding && controlland) + { + // nesting this check because LengthSquared() is expensive and we don't + // want to do it every step when flying. + if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX)) + StopFlying(); + } + } + + if (update_movementflag || (update_rotation && DCFlagKeyPressed)) + { + // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed)); + // m_log.DebugFormat( + // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); + + AddNewMovement(agent_control_v3, q, Nudging); + + + } + } + + if (update_movementflag && !SitGround) + Animator.UpdateMovementAnimations(); + + m_scene.EventManager.TriggerOnClientMovement(this); + + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client) + { + m_autopilotMoving = true; + m_autoPilotTarget = Pos; + m_sitAtAutoTarget = false; + PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; + //proxy.PCode = (byte)PCode.ParticleSystem; + proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy); + proxyObjectGroup.AttachToScene(m_scene); + + // Commented out this code since it could never have executed, but might still be informative. +// if (proxyObjectGroup != null) +// { + proxyObjectGroup.SendGroupFullUpdate(); + remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); + m_scene.DeleteSceneObject(proxyObjectGroup, false); +// } +// else +// { +// m_autopilotMoving = false; +// m_autoPilotTarget = Vector3.Zero; +// ControllingClient.SendAlertMessage("Autopilot cancelled"); +// } + } + + public void DoMoveToPosition(Object sender, string method, List args) + { + try + { + float locx = 0f; + float locy = 0f; + float locz = 0f; + uint regionX = 0; + uint regionY = 0; + try + { + Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY); + locx = Convert.ToSingle(args[0]) - (float)regionX; + locy = Convert.ToSingle(args[1]) - (float)regionY; + locz = Convert.ToSingle(args[2]); + } + catch (InvalidCastException) + { + m_log.Error("[CLIENT]: Invalid autopilot request"); + return; + } + m_moveToPositionInProgress = true; + m_moveToPositionTarget = new Vector3(locx, locy, locz); + } + catch (Exception ex) + { + //Why did I get this error? + m_log.Error("[SCENEPRESENCE]: DoMoveToPosition" + ex); + } + } + + private void CheckAtSitTarget() + { + //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); + if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5) + { + if (m_sitAtAutoTarget) + { + SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID); + if (part != null) + { + AbsolutePosition = part.AbsolutePosition; + Velocity = Vector3.Zero; + SendFullUpdateToAllClients(); + + HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); //KF ?? + } + //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); + m_requestedSitTargetUUID = UUID.Zero; + } + /* + else + { + //ControllingClient.SendAlertMessage("Autopilot cancelled"); + //SendTerseUpdateToAllClients(); + //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; + //proxy.PCode = (byte)PCode.ParticleSystem; + ////uint nextUUID = m_scene.NextLocalId; + + //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy); + //if (proxyObjectGroup != null) + //{ + //proxyObjectGroup.SendGroupFullUpdate(); + //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); + //m_scene.DeleteSceneObject(proxyObjectGroup); + //} + } + */ + m_autoPilotTarget = Vector3.Zero; + m_autopilotMoving = false; + } + } + /// + /// Perform the logic necessary to stand the avatar up. This method also executes + /// the stand animation. + /// + public void StandUp() + { + SitGround = false; + + if (m_parentID != 0) + { + SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); + if (part != null) + { + part.TaskInventory.LockItemsForRead(true); + TaskInventoryDictionary taskIDict = part.TaskInventory; + if (taskIDict != null) + { + foreach (UUID taskID in taskIDict.Keys) + { + UnRegisterControlEventsToScript(LocalId, taskID); + taskIDict[taskID].PermsMask &= ~( + 2048 | //PERMISSION_CONTROL_CAMERA + 4); // PERMISSION_TAKE_CONTROLS + } + } + part.TaskInventory.LockItemsForRead(false); + // Reset sit target. + if (part.GetAvatarOnSitTarget() == UUID) + part.SetAvatarOnSitTarget(UUID.Zero); + m_parentPosition = part.GetWorldPosition(); + ControllingClient.SendClearFollowCamProperties(part.ParentUUID); + } + // part.GetWorldRotation() is the rotation of the object being sat on + // Rotation is the sittiing Av's rotation + + Quaternion partRot; +// if (part.LinkNum == 1) +// { // Root prim of linkset +// partRot = part.ParentGroup.RootPart.RotationOffset; +// } +// else +// { // single or child prim + +// } + if (part == null) //CW: Part may be gone. llDie() for example. + { + partRot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + } + else + { + partRot = part.GetWorldRotation(); + } + + Quaternion partIRot = Quaternion.Inverse(partRot); + + Quaternion avatarRot = Quaternion.Inverse(Quaternion.Inverse(Rotation) * partIRot); // world or. of the av + Vector3 avStandUp = new Vector3(1.0f, 0f, 0f) * avatarRot; // 1M infront of av + + + if (m_physicsActor == null) + { + AddToPhysicalScene(false); + } + //CW: If the part isn't null then we can set the current position + if (part != null) + { + Vector3 avWorldStandUp = avStandUp + part.GetWorldPosition() + ((m_pos - part.OffsetPosition) * partRot); // + av sit offset! + AbsolutePosition = avWorldStandUp; //KF: Fix stand up. + part.IsOccupied = false; + part.ParentGroup.DeleteAvatar(ControllingClient.AgentId); + } + else + { + //CW: Since the part doesn't exist, a coarse standup position isn't an issue + AbsolutePosition = m_lastWorldPosition; + } + + m_parentPosition = Vector3.Zero; + m_parentID = 0; + m_linkedPrim = UUID.Zero; + m_offsetRotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + SendFullUpdateToAllClients(); + m_requestedSitTargetID = 0; + + if ((m_physicsActor != null) && (m_avHeight > 0)) + { + SetHeight(m_avHeight); + } + } + Animator.TrySetMovementAnimation("STAND"); + } + + private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) + { + SceneObjectPart targetPart = m_scene.GetSceneObjectPart(targetID); + if (targetPart == null) + return null; + + // If the primitive the player clicked on has a sit target and that sit target is not full, that sit target is used. + // If the primitive the player clicked on has no sit target, and one or more other linked objects have sit targets that are not full, the sit target of the object with the lowest link number will be used. + + // Get our own copy of the part array, and sort into the order we want to test + SceneObjectPart[] partArray = targetPart.ParentGroup.GetParts(); + Array.Sort(partArray, delegate(SceneObjectPart p1, SceneObjectPart p2) + { + // we want the originally selected part first, then the rest in link order -- so make the selected part link num (-1) + int linkNum1 = p1==targetPart ? -1 : p1.LinkNum; + int linkNum2 = p2==targetPart ? -1 : p2.LinkNum; + return linkNum1 - linkNum2; + } + ); + + //look for prims with explicit sit targets that are available + foreach (SceneObjectPart part in partArray) + { + // Is a sit target available? + Vector3 avSitOffSet = part.SitTargetPosition; + Quaternion avSitOrientation = part.SitTargetOrientation; + UUID avOnTargetAlready = part.GetAvatarOnSitTarget(); + bool SitTargetOccupied = (avOnTargetAlready != UUID.Zero); + bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. + if (SitTargetisSet && !SitTargetOccupied) + { + //switch the target to this prim + return part; + } + } + + // no explicit sit target found - use original target + return targetPart; + } + + private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) + { + bool autopilot = true; + Vector3 autopilotTarget = new Vector3(); + Quaternion sitOrientation = Quaternion.Identity; + Vector3 pos = new Vector3(); + Vector3 cameraEyeOffset = Vector3.Zero; + Vector3 cameraAtOffset = Vector3.Zero; + bool forceMouselook = false; + + //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); + SceneObjectPart part = FindNextAvailableSitTarget(targetID); + if (part == null) return; + + // TODO: determine position to sit at based on scene geometry; don't trust offset from client + // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it + + // part is the prim to sit on + // offset is the world-ref vector distance from that prim center to the click-spot + // UUID is the UUID of the Avatar doing the clicking + + m_avInitialPos = AbsolutePosition; // saved to calculate unscripted sit rotation + + // Is a sit target available? + Vector3 avSitOffSet = part.SitTargetPosition; + Quaternion avSitOrientation = part.SitTargetOrientation; + + bool SitTargetisSet = (Vector3.Zero != avSitOffSet); //NB Latest SL Spec shows Sit Rotation setting is ignored. + // Quaternion partIRot = Quaternion.Inverse(part.GetWorldRotation()); + Quaternion partRot; +// if (part.LinkNum == 1) +// { // Root prim of linkset +// partRot = part.ParentGroup.RootPart.RotationOffset; +// } +// else +// { // single or child prim + partRot = part.GetWorldRotation(); +// } + Quaternion partIRot = Quaternion.Inverse(partRot); +//Console.WriteLine("SendSitResponse offset=" + offset + " Occup=" + part.IsOccupied + " TargSet=" + SitTargetisSet); + // Sit analysis rewritten by KF 091125 + if (SitTargetisSet) // scipted sit + { + if (!part.IsOccupied) + { +//Console.WriteLine("Scripted, unoccupied"); + part.SetAvatarOnSitTarget(UUID); // set that Av will be on it + offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); // change ofset to the scripted one + + Quaternion nrot = avSitOrientation; + if (!part.IsRoot) + { + nrot = part.RotationOffset * avSitOrientation; + } + sitOrientation = nrot; // Change rotatione to the scripted one + OffsetRotation = nrot; + autopilot = false; // Jump direct to scripted llSitPos() + } + else + { +//Console.WriteLine("Scripted, occupied"); + return; + } + } + else // Not Scripted + { + if ( (Math.Abs(offset.X) > 0.5f) || (Math.Abs(offset.Y) > 0.5f) ) + { + // large prim & offset, ignore if other Avs sitting +// offset.Z -= 0.05f; + m_avUnscriptedSitPos = offset * partIRot; // (non-zero) sit where clicked + autopilotTarget = part.AbsolutePosition + offset; // World location of clicked point + +//Console.WriteLine(" offset ={0}", offset); +//Console.WriteLine(" UnscriptedSitPos={0}", m_avUnscriptedSitPos); +//Console.WriteLine(" autopilotTarget={0}", autopilotTarget); + + } + else // small offset + { +//Console.WriteLine("Small offset"); + if (!part.IsOccupied) + { + m_avUnscriptedSitPos = Vector3.Zero; // Zero = Sit on prim center + autopilotTarget = part.AbsolutePosition; +//Console.WriteLine("UsSmall autopilotTarget={0}", autopilotTarget); + } + else return; // occupied small + } // end large/small + } // end Scripted/not + cameraAtOffset = part.GetCameraAtOffset(); + cameraEyeOffset = part.GetCameraEyeOffset(); + forceMouselook = part.GetForceMouselook(); + if(cameraAtOffset == Vector3.Zero) cameraAtOffset = new Vector3(0f, 0f, 0.1f); // + if(cameraEyeOffset == Vector3.Zero) cameraEyeOffset = new Vector3(0f, 0f, 0.1f); // + + if (m_physicsActor != null) + { + // If we're not using the client autopilot, we're immediately warping the avatar to the location + // We can remove the physicsActor until they stand up. + m_sitAvatarHeight = m_physicsActor.Size.Z; + if (autopilot) + { // its not a scripted sit +// if (Util.GetDistanceTo(AbsolutePosition, autopilotTarget) < 4.5) + if( (Math.Abs(AbsolutePosition.X - autopilotTarget.X) < 10.0f) && (Math.Abs(AbsolutePosition.Y - autopilotTarget.Y) < 10.0f) ) + { + autopilot = false; // close enough + m_lastWorldPosition = m_pos; /* CW - This give us a position to return the avatar to if the part is killed before standup. + Not using the part's position because returning the AV to the last known standing + position is likely to be more friendly, isn't it? */ + RemoveFromPhysicalScene(); + Velocity = Vector3.Zero; + AbsolutePosition = autopilotTarget + new Vector3(0.0f, 0.0f, (m_sitAvatarHeight / 2.0f)); // Warp av to over sit target + } // else the autopilot will get us close + } + else + { // its a scripted sit + m_lastWorldPosition = part.AbsolutePosition; /* CW - This give us a position to return the avatar to if the part is killed before standup. + I *am* using the part's position this time because we have no real idea how far away + the avatar is from the sit target. */ + RemoveFromPhysicalScene(); + Velocity = Vector3.Zero; + } + } + else return; // physactor is null! + + Vector3 offsetr; // = offset * partIRot; + // KF: In a linkset, offsetr needs to be relative to the group root! 091208 + // offsetr = (part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + (offset * partIRot); + // if (part.LinkNum < 2) 091216 All this was necessary because of the GetWorldRotation error. + // { // Single, or Root prim of linkset, target is ClickOffset * RootRot + //offsetr = offset * partIRot; +// + // else + // { // Child prim, offset is (ChildOffset * RootRot) + (ClickOffset * ChildRot) + // offsetr = //(part.OffsetPosition * Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset)) + + // (offset * partRot); + // } + +//Console.WriteLine(" "); +//Console.WriteLine("link number ={0}", part.LinkNum); +//Console.WriteLine("Prim offset ={0}", part.OffsetPosition ); +//Console.WriteLine("Root Rotate ={0}", part.ParentGroup.RootPart.RotationOffset); +//Console.WriteLine("Click offst ={0}", offset); +//Console.WriteLine("Prim Rotate ={0}", part.GetWorldRotation()); +//Console.WriteLine("offsetr ={0}", offsetr); +//Console.WriteLine("Camera At ={0}", cameraAtOffset); +//Console.WriteLine("Camera Eye ={0}", cameraEyeOffset); + + //NOTE: SendSitResponse should be relative to the GROUP *NOT* THE PRIM if we're sitting on a child + ControllingClient.SendSitResponse(part.ParentGroup.UUID, ((offset * part.RotationOffset) + part.OffsetPosition), sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); + + m_requestedSitTargetUUID = part.UUID; //KF: Correct autopilot target + // This calls HandleAgentSit twice, once from here, and the client calls + // HandleAgentSit itself after it gets to the location + // It doesn't get to the location until we've moved them there though + // which happens in HandleAgentSit :P + m_autopilotMoving = autopilot; + m_autoPilotTarget = autopilotTarget; + m_sitAtAutoTarget = autopilot; + m_initialSitTarget = autopilotTarget; + if (!autopilot) + HandleAgentSit(remoteClient, UUID); + } + + public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) + { + if (m_parentID != 0) + { + StandUp(); + } + m_nextSitAnimation = "SIT"; + + //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); + SceneObjectPart part = FindNextAvailableSitTarget(targetID); + + if (part != null) + { + if (!String.IsNullOrEmpty(part.SitAnimation)) + { + m_nextSitAnimation = part.SitAnimation; + } + m_requestedSitTargetID = part.LocalId; + //m_requestedSitOffset = offset; + m_requestedSitTargetUUID = targetID; + + m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); + + if (m_scene.PhysicsScene.SupportsRayCast()) + { + //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); + //SitRayCastAvatarPosition(part); + //return; + } + } + else + { + + m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); + } + + + + SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); + } + /* + public void SitRayCastAvatarPosition(SceneObjectPart part) + { + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = AbsolutePosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse); + } + + public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); + } + else + { + SitRayCastAvatarPositionCameraZ(part); + } + } + else + { + SitRayCastAvatarPositionCameraZ(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) + { + // Next, try to raycast from the camera Z position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse); + } + + public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal); + } + else + { + SitRayCastCameraPosition(part); + } + } + else + { + SitRayCastCameraPosition(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + public void SitRayCastCameraPosition(SceneObjectPart part) + { + // Next, try to raycast from the camera position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse); + } + + public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); + } + else + { + SitRayHorizontal(part); + } + } + else + { + SitRayHorizontal(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + public void SitRayHorizontal(SceneObjectPart part) + { + // Next, try to raycast from the avatar position to fwd + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); + } + + public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); + // Next, try to raycast from the camera position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition); + } + else + { + ControllingClient.SendAlertMessage("Sit position not accessable."); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + } + else + { + ControllingClient.SendAlertMessage("Sit position not accessable."); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) + { + int i = 0; + //throw new NotImplementedException(); + //m_requestedSitTargetUUID = UUID.Zero; + //m_requestedSitTargetID = 0; + //m_requestedSitOffset = Vector3.Zero; + + SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); + } + */ + public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) + { + if (m_parentID != 0) + { + StandUp(); + } + if (!String.IsNullOrEmpty(sitAnimation)) + { + m_nextSitAnimation = sitAnimation; + } + else + { + m_nextSitAnimation = "SIT"; + } + + //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID); + SceneObjectPart part = FindNextAvailableSitTarget(targetID); + if (part != null) + { + m_requestedSitTargetID = part.LocalId; + //m_requestedSitOffset = offset; + m_requestedSitTargetUUID = targetID; + + m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); + + if (m_scene.PhysicsScene.SupportsRayCast()) + { + //SitRayCastAvatarPosition(part); + //return; + } + } + else + { + m_log.Warn("Sit requested on unknown object: " + targetID); + } + + SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); + } + + public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) + { + if (!String.IsNullOrEmpty(m_nextSitAnimation)) + { + HandleAgentSit(remoteClient, agentID, m_nextSitAnimation); + } + else + { + HandleAgentSit(remoteClient, agentID, "SIT"); + } + } + + public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation) + { + SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); + + if (m_sitAtAutoTarget || !m_autopilotMoving) + { + if (part != null) + { +//Console.WriteLine("Link #{0}, Rot {1}", part.LinkNum, part.GetWorldRotation()); + if (part.GetAvatarOnSitTarget() == UUID) + { +//Console.WriteLine("Scripted Sit"); + // Scripted sit + Vector3 sitTargetPos = part.SitTargetPosition; + Quaternion sitTargetOrient = part.SitTargetOrientation; + m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z); + m_pos += SIT_TARGET_ADJUSTMENT; + if (!part.IsRoot) + { + m_pos *= part.RotationOffset; + } + m_bodyRot = sitTargetOrient; + m_parentPosition = part.AbsolutePosition; + part.IsOccupied = true; + part.ParentGroup.AddAvatar(agentID); +Console.WriteLine("Scripted Sit ofset {0}", m_pos); + } + else + { + // if m_avUnscriptedSitPos is zero then Av sits above center + // Else Av sits at m_avUnscriptedSitPos + + // Non-scripted sit by Kitto Flora 21Nov09 + // Calculate angle of line from prim to Av + Quaternion partIRot; +// if (part.LinkNum == 1) +// { // Root prim of linkset +// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); +// } +// else +// { // single or child prim + partIRot = Quaternion.Inverse(part.GetWorldRotation()); +// } + Vector3 sitTargetPos= part.AbsolutePosition + m_avUnscriptedSitPos; + float y_diff = (m_avInitialPos.Y - sitTargetPos.Y); + float x_diff = ( m_avInitialPos.X - sitTargetPos.X); + if(Math.Abs(x_diff) < 0.001f) x_diff = 0.001f; // avoid div by 0 + if(Math.Abs(y_diff) < 0.001f) y_diff = 0.001f; // avoid pol flip at 0 + float sit_angle = (float)Math.Atan2( (double)y_diff, (double)x_diff); + // NOTE: when sitting m_ pos and m_bodyRot are *relative* to the prim location/rotation, not 'World'. + // Av sits at world euler <0,0, z>, translated by part rotation + m_bodyRot = partIRot * Quaternion.CreateFromEulers(0f, 0f, sit_angle); // sit at 0,0,inv-click + + m_parentPosition = part.AbsolutePosition; + part.IsOccupied = true; + part.ParentGroup.AddAvatar(agentID); + m_pos = new Vector3(0f, 0f, 0.05f) + // corrections to get Sit Animation + (new Vector3(0.0f, 0f, 0.61f) * partIRot) + // located on center + (new Vector3(0.34f, 0f, 0.0f) * m_bodyRot) + + m_avUnscriptedSitPos; // adds click offset, if any + //Set up raytrace to find top surface of prim + Vector3 size = part.Scale; + float mag = 2.0f; // 0.1f + (float)Math.Sqrt((size.X * size.X) + (size.Y * size.Y) + (size.Z * size.Z)); + Vector3 start = part.AbsolutePosition + new Vector3(0f, 0f, mag); + Vector3 down = new Vector3(0f, 0f, -1f); +//Console.WriteLine("st={0} do={1} ma={2}", start, down, mag); + m_scene.PhysicsScene.RaycastWorld( + start, // Vector3 position, + down, // Vector3 direction, + mag, // float length, + SitAltitudeCallback); // retMethod + } // end scripted/not + } + else // no Av + { + return; + } + } + + //We want our offsets to reference the root prim, not the child we may have sat on + if (!part.IsRoot) + { + m_parentID = part.ParentGroup.RootPart.LocalId; + m_pos += part.OffsetPosition; + } + else + { + m_parentID = m_requestedSitTargetID; + } + + m_linkedPrim = part.UUID; + + Velocity = Vector3.Zero; + RemoveFromPhysicalScene(); + Animator.TrySetMovementAnimation(sitAnimation); + SendFullUpdateToAllClients(); + SendTerseUpdateToAllClients(); + } + + public void SitAltitudeCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal) + { + // KF: 091202 There appears to be a bug in Prim Edit Size - the process sometimes make a prim that RayTrace no longer + // sees. Take/re-rez, or sim restart corrects the condition. Result of bug is incorrect sit height. + if(hitYN) + { + // m_pos = Av offset from prim center to make look like on center + // m_parentPosition = Actual center pos of prim + // collisionPoint = spot on prim where we want to sit + // collisionPoint.Z = global sit surface height + SceneObjectPart part = m_scene.GetSceneObjectPart(localid); + Quaternion partIRot; +// if (part.LinkNum == 1) +/// { // Root prim of linkset +// partIRot = Quaternion.Inverse(part.ParentGroup.RootPart.RotationOffset); +// } +// else +// { // single or child prim + partIRot = Quaternion.Inverse(part.GetWorldRotation()); +// } + if (m_initialSitTarget != null) + { + float offZ = collisionPoint.Z - m_initialSitTarget.Z; + Vector3 offset = new Vector3(0.0f, 0.0f, offZ) * partIRot; // Altitude correction + //Console.WriteLine("sitPoint={0}, offset={1}", sitPoint, offset); + m_pos += offset; + // ControllingClient.SendClearFollowCamProperties(part.UUID); + } + + } + } // End SitAltitudeCallback KF. + + /// + /// Event handler for the 'Always run' setting on the client + /// Tells the physics plugin to increase speed of movement. + /// + public void HandleSetAlwaysRun(IClientAPI remoteClient, bool pSetAlwaysRun) + { + m_setAlwaysRun = pSetAlwaysRun; + if (PhysicsActor != null) + { + PhysicsActor.SetAlwaysRun = pSetAlwaysRun; + } + } + + public void HandleStartAnim(IClientAPI remoteClient, UUID animID) + { + Animator.AddAnimation(animID, UUID.Zero); + } + + public void HandleStopAnim(IClientAPI remoteClient, UUID animID) + { + Animator.RemoveAnimation(animID); + } + + /// + /// Rotate the avatar to the given rotation and apply a movement in the given relative vector + /// + /// The vector in which to move. This is relative to the rotation argument + /// The direction in which this avatar should now face. + public void AddNewMovement(Vector3 vec, Quaternion rotation, bool Nudging) + { + if (m_isChildAgent) + { + // WHAT??? + m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); + + // we have to reset the user's child agent connections. + // Likely, here they've lost the eventqueue for other regions so border + // crossings will fail at this point unless we reset them. + + List regions = new List(KnownChildRegionHandles); + regions.Remove(m_scene.RegionInfo.RegionHandle); + + MakeRootAgent(new Vector3(127f, 127f, 127f), true); + + // Async command + if (m_scene.SceneGridService != null) + { + m_scene.SceneGridService.SendCloseChildAgentConnections(UUID, regions); + + // Give the above command some time to try and close the connections. + // this is really an emergency.. so sleep, or we'll get all discombobulated. + System.Threading.Thread.Sleep(500); + } + + if (m_scene.SceneGridService != null) + { + IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); + if (m_agentTransfer != null) + m_agentTransfer.EnableChildAgents(this); + } + + return; + } + + m_perfMonMS = Util.EnvironmentTickCount(); + + Rotation = rotation; + Vector3 direc = vec * rotation; + direc.Normalize(); + PhysicsActor actor = m_physicsActor; + if ((vec.Z == 0f) && !actor.Flying) direc.Z = 0f; // Prevent camera WASD up. + + direc *= 0.03f * 128f * m_speedModifier; + + if (actor != null) + { + if (actor.Flying) + { + direc *= 4.0f; + //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); + //bool colliding = (m_physicsActor.IsColliding==true); + //if (controlland) + // m_log.Info("[AGENT]: landCommand"); + //if (colliding) + // m_log.Info("[AGENT]: colliding"); + //if (m_physicsActor.Flying && colliding && controlland) + //{ + // StopFlying(); + // m_log.Info("[AGENT]: Stop FLying"); + //} + } + else if (!actor.Flying && actor.IsColliding) + { + if (direc.Z > 2.0f) + { + if(m_animator.m_animTickJump == -1) + { + direc.Z *= 3.0f; // jump + } + else + { + direc.Z *= 0.1f; // prejump + } + /* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs + Animator.TrySetMovementAnimation("PREJUMP"); + Animator.TrySetMovementAnimation("JUMP"); + */ + } + } + } + + // TODO: Add the force instead of only setting it to support multiple forces per frame? + m_forceToApply = direc; + m_isNudging = Nudging; + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + #endregion + + #region Overridden Methods + + public override void Update() + { + const float ROTATION_TOLERANCE = 0.01f; + const float VELOCITY_TOLERANCE = 0.001f; + const float POSITION_TOLERANCE = 0.05f; + //const int TIME_MS_TOLERANCE = 3000; + + + + if (m_isChildAgent == false) + { +// PhysicsActor actor = m_physicsActor; + + // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to + // grab the latest PhysicsActor velocity, whereas m_velocity is often + // storing a requested force instead of an actual traveling velocity + + // Throw away duplicate or insignificant updates + if (!m_bodyRot.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) || + !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || + !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) + //Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE) + { + SendTerseUpdateToAllClients(); + + // Update the "last" values + m_lastPosition = m_pos; + m_lastRotation = m_bodyRot; + m_lastVelocity = Velocity; + //m_lastTerseSent = Environment.TickCount; + } + + // followed suggestion from mic bowman. reversed the two lines below. + if (m_parentID == 0 && m_physicsActor != null || m_parentID != 0) // Check that we have a physics actor or we're sitting on something + CheckForBorderCrossing(); + CheckForSignificantMovement(); // sends update to the modules. + } + + //Sending prim updates AFTER the avatar terse updates are sent + SendPrimUpdates(); + } + + #endregion + + #region Update Client(s) + + /// + /// Sends a location update to the client connected to this scenePresence + /// + /// + public void SendTerseUpdateToClient(IClientAPI remoteClient) + { + // If the client is inactive, it's getting its updates from another + // server. + if (remoteClient.IsActive) + { + m_perfMonMS = Util.EnvironmentTickCount(); + + PhysicsActor actor = m_physicsActor; + Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero; + + Vector3 pos = m_pos; + pos.Z += m_appearance.HipOffset; + + //m_log.DebugFormat("[SCENEPRESENCE]: TerseUpdate: Pos={0} Rot={1} Vel={2}", m_pos, m_bodyRot, m_velocity); + + remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity); + + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + m_scene.StatsReporter.AddAgentUpdates(1); + } + } + + /// + /// Send a location/velocity/accelleration update to all agents in scene + /// + public void SendTerseUpdateToAllClients() + { + m_perfMonMS = Util.EnvironmentTickCount(); + + m_scene.ForEachClient(SendTerseUpdateToClient); + + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + public void SendCoarseLocations(List coarseLocations, List avatarUUIDs) + { + SendCourseLocationsMethod d = m_sendCourseLocationsMethod; + if (d != null) + { + d.Invoke(m_scene.RegionInfo.originRegionID, this, coarseLocations, avatarUUIDs); + } + } + + public void SetSendCourseLocationMethod(SendCourseLocationsMethod d) + { + if (d != null) + m_sendCourseLocationsMethod = d; + } + + public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p, List coarseLocations, List avatarUUIDs) + { + m_perfMonMS = Util.EnvironmentTickCount(); + m_controllingClient.SendCoarseLocationUpdate(avatarUUIDs, coarseLocations); + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + /// + /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar) + /// + /// + public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) + { + // 2 stage check is needed. + if (remoteAvatar == null) + return; + IClientAPI cl=remoteAvatar.ControllingClient; + if (cl == null) + return; + if (m_appearance.Texture == null) + return; + + Vector3 pos = m_pos; + pos.Z += m_appearance.HipOffset; + + remoteAvatar.m_controllingClient.SendAvatarDataImmediate(this); + m_scene.StatsReporter.AddAgentUpdates(1); + } + + /// + /// Tell *ALL* agents about this agent + /// + public void SendInitialFullUpdateToAllClients() + { + m_perfMonMS = Util.EnvironmentTickCount(); + int avUpdates = 0; + m_scene.ForEachScenePresence(delegate(ScenePresence avatar) + { + ++avUpdates; + // only send if this is the root (children are only "listening posts" in a foreign region) + if (!IsChildAgent) + { + SendFullUpdateToOtherClient(avatar); + } + + if (avatar.LocalId != LocalId) + { + if (!avatar.IsChildAgent) + { + avatar.SendFullUpdateToOtherClient(this); + avatar.SendAppearanceToOtherAgent(this); + avatar.Animator.SendAnimPackToClient(ControllingClient); + } + } + }); + + m_scene.StatsReporter.AddAgentUpdates(avUpdates); + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + + //Animator.SendAnimPack(); + } + + public void SendFullUpdateToAllClients() + { + m_perfMonMS = Util.EnvironmentTickCount(); + + // only send update from root agents to other clients; children are only "listening posts" + int count = 0; + m_scene.ForEachScenePresence(delegate(ScenePresence sp) + { + if (sp.IsChildAgent) + return; + SendFullUpdateToOtherClient(sp); + ++count; + }); + m_scene.StatsReporter.AddAgentUpdates(count); + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + + Animator.SendAnimPack(); + } + + /// + /// Do everything required once a client completes its movement into a region + /// + public void SendInitialData() + { + // Moved this into CompleteMovement to ensure that m_appearance is initialized before + // the inventory arrives + // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); + + Vector3 pos = m_pos; + pos.Z += m_appearance.HipOffset; + + m_controllingClient.SendAvatarDataImmediate(this); + + SendInitialFullUpdateToAllClients(); + SendAppearanceToAllOtherAgents(); + } + + /// + /// Tell the client for this scene presence what items it should be wearing now + /// + public void SendWearables() + { + m_log.DebugFormat("[SCENE]: Received request for wearables of {0}", Name); + + ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); + } + + /// + /// + /// + public void SendAppearanceToAllOtherAgents() + { + m_perfMonMS = Util.EnvironmentTickCount(); + + m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) + { + if (scenePresence.UUID != UUID) + { + SendAppearanceToOtherAgent(scenePresence); + } + }); + + m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS)); + } + + /// + /// Send appearance data to an agent that isn't this one. + /// + /// + public void SendAppearanceToOtherAgent(ScenePresence avatar) + { + avatar.ControllingClient.SendAppearance( + m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); + } + + /// + /// Set appearance data (textureentry and slider settings) received from the client + /// + /// + /// + public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) + { + if (m_physicsActor != null) + { + if (!IsChildAgent) + { + // This may seem like it's redundant, remove the avatar from the physics scene + // just to add it back again, but it saves us from having to update + // 3 variables 10 times a second. + bool flyingTemp = m_physicsActor.Flying; + RemoveFromPhysicalScene(); + //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); + + //PhysicsActor = null; + + AddToPhysicalScene(flyingTemp); + } + } + + #region Bake Cache Check + + if (textureEntry != null) + { + for (int i = 0; i < BAKE_INDICES.Length; i++) + { + int j = BAKE_INDICES[i]; + Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; + + if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) + { + if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) + { + m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); + this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); + } + } + } + + } + + + #endregion Bake Cache Check + + m_appearance.SetAppearance(textureEntry, visualParams); + if (m_appearance.AvatarHeight > 0) + SetHeight(m_appearance.AvatarHeight); + + // This is not needed, because only the transient data changed + //AvatarData adata = new AvatarData(m_appearance); + //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); + + SendAppearanceToAllOtherAgents(); + if (!m_startAnimationSet) + { + Animator.UpdateMovementAnimations(); + m_startAnimationSet = true; + } + + Vector3 pos = m_pos; + pos.Z += m_appearance.HipOffset; + + m_controllingClient.SendAvatarDataImmediate(this); + } + + public void SetWearable(int wearableId, AvatarWearable wearable) + { + m_appearance.SetWearable(wearableId, wearable); + AvatarData adata = new AvatarData(m_appearance); + m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); + m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); + } + + // Because appearance setting is in a module, we actually need + // to give it access to our appearance directly, otherwise we + // get a synchronization issue. + public AvatarAppearance Appearance + { + get { return m_appearance; } + set { m_appearance = value; } + } + + #endregion + + #region Significant Movement Method + + /// + /// This checks for a significant movement and sends a courselocationchange update + /// + protected void CheckForSignificantMovement() + { + // Movement updates for agents in neighboring regions are sent directly to clients. + // This value only affects how often agent positions are sent to neighbor regions + // for things such as distance-based update prioritization + const float SIGNIFICANT_MOVEMENT = 2.0f; + + if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > SIGNIFICANT_MOVEMENT) + { + posLastSignificantMove = AbsolutePosition; + m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient); + } + + // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m + if (Util.GetDistanceTo(AbsolutePosition, m_lastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance || + Util.GetDistanceTo(CameraPosition, m_lastChildAgentUpdateCamPosition) >= Scene.ChildReprioritizationDistance) + { + m_lastChildAgentUpdatePosition = AbsolutePosition; + m_lastChildAgentUpdateCamPosition = CameraPosition; + + ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); + cadu.ActiveGroupID = UUID.Zero.Guid; + cadu.AgentID = UUID.Guid; + cadu.alwaysrun = m_setAlwaysRun; + cadu.AVHeight = m_avHeight; + Vector3 tempCameraCenter = m_CameraCenter; + cadu.cameraPosition = tempCameraCenter; + cadu.drawdistance = m_DrawDistance; + cadu.GroupAccess = 0; + cadu.Position = AbsolutePosition; + cadu.regionHandle = m_rootRegionHandle; + float multiplier = 1; + int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); + if (innacurateNeighbors != 0) + { + multiplier = 1f / (float)innacurateNeighbors; + } + if (multiplier <= 0f) + { + multiplier = 0.25f; + } + + //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); + cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier); + cadu.Velocity = Velocity; + + AgentPosition agentpos = new AgentPosition(); + agentpos.CopyFrom(cadu); + + m_scene.SendOutChildAgentUpdates(agentpos, this); + } + } + + #endregion + + #region Border Crossing Methods + + /// + /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion + /// + protected void CheckForBorderCrossing() + { + if (IsChildAgent) + return; + + Vector3 pos2 = AbsolutePosition; + Vector3 vel = Velocity; + int neighbor = 0; + int[] fix = new int[2]; + + float timeStep = 0.1f; + pos2.X = pos2.X + (vel.X*timeStep); + pos2.Y = pos2.Y + (vel.Y*timeStep); + pos2.Z = pos2.Z + (vel.Z*timeStep); + + if (!IsInTransit) + { + // Checks if where it's headed exists a region + + bool needsTransit = false; + if (m_scene.TestBorderCross(pos2, Cardinals.W)) + { + if (m_scene.TestBorderCross(pos2, Cardinals.S)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.SW, ref fix); + } + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.NW, ref fix); + } + else + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.W, ref fix); + } + } + else if (m_scene.TestBorderCross(pos2, Cardinals.E)) + { + if (m_scene.TestBorderCross(pos2, Cardinals.S)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.SE, ref fix); + } + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.NE, ref fix); + } + else + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.E, ref fix); + } + } + else if (m_scene.TestBorderCross(pos2, Cardinals.S)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.S, ref fix); + } + else if (m_scene.TestBorderCross(pos2, Cardinals.N)) + { + needsTransit = true; + neighbor = HaveNeighbor(Cardinals.N, ref fix); + } + + + // Makes sure avatar does not end up outside region + if (neighbor <= 0) + { + if (!needsTransit) + { + if (m_requestedSitTargetUUID == UUID.Zero) + { + Vector3 pos = AbsolutePosition; + if (AbsolutePosition.X < 0) + pos.X += Velocity.X; + else if (AbsolutePosition.X > Constants.RegionSize) + pos.X -= Velocity.X; + if (AbsolutePosition.Y < 0) + pos.Y += Velocity.Y; + else if (AbsolutePosition.Y > Constants.RegionSize) + pos.Y -= Velocity.Y; + AbsolutePosition = pos; + } + } + } + else if (neighbor > 0) + CrossToNewRegion(); + } + else + { + RemoveFromPhysicalScene(); + // This constant has been inferred from experimentation + // I'm not sure what this value should be, so I tried a few values. + timeStep = 0.04f; + pos2 = AbsolutePosition; + pos2.X = pos2.X + (vel.X * timeStep); + pos2.Y = pos2.Y + (vel.Y * timeStep); + pos2.Z = pos2.Z + (vel.Z * timeStep); + m_pos = pos2; + } + } + + protected int HaveNeighbor(Cardinals car, ref int[] fix) + { + uint neighbourx = m_regionInfo.RegionLocX; + uint neighboury = m_regionInfo.RegionLocY; + + int dir = (int)car; + + if (dir > 1 && dir < 5) //Heading East + neighbourx++; + else if (dir > 5) // Heading West + neighbourx--; + + if (dir < 3 || dir == 8) // Heading North + neighboury++; + else if (dir > 3 && dir < 7) // Heading Sout + neighboury--; + + int x = (int)(neighbourx * Constants.RegionSize); + int y = (int)(neighboury * Constants.RegionSize); + GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, x, y); + + if (neighbourRegion == null) + { + fix[0] = (int)(m_regionInfo.RegionLocX - neighbourx); + fix[1] = (int)(m_regionInfo.RegionLocY - neighboury); + return dir * (-1); + } + else + return dir; + } + + /// + /// Moves the agent outside the region bounds + /// Tells neighbor region that we're crossing to it + /// If the neighbor accepts, remove the agent's viewable avatar from this scene + /// set them to a child agent. + /// + protected void CrossToNewRegion() + { + InTransit(); + try + { + m_scene.CrossAgentToNewRegion(this, m_physicsActor.Flying); + } + catch + { + m_scene.CrossAgentToNewRegion(this, false); + } + } + + public void InTransit() + { + m_inTransit = true; + + if ((m_physicsActor != null) && m_physicsActor.Flying) + m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY; + else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) + m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY; + } + + public void NotInTransit() + { + m_inTransit = false; + } + + public void RestoreInCurrentScene() + { + AddToPhysicalScene(false); // not exactly false + } + + public void Reset() + { + // Put the child agent back at the center + AbsolutePosition + = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); + Animator.ResetAnimations(); + } + + /// + /// Computes which child agents to close when the scene presence moves to another region. + /// Removes those regions from m_knownRegions. + /// + /// The new region's x on the map + /// The new region's y on the map + /// + public void CloseChildAgents(uint newRegionX, uint newRegionY) + { + List byebyeRegions = new List(); + m_log.DebugFormat( + "[SCENE PRESENCE]: Closing child agents. Checking {0} regions in {1}", + m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName); + //DumpKnownRegions(); + + lock (m_knownChildRegions) + { + foreach (ulong handle in m_knownChildRegions.Keys) + { + // Don't close the agent on this region yet + if (handle != Scene.RegionInfo.RegionHandle) + { + uint x, y; + Utils.LongToUInts(handle, out x, out y); + x = x / Constants.RegionSize; + y = y / Constants.RegionSize; + + //m_log.Debug("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX))); + //m_log.Debug("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY))); + if (Util.IsOutsideView(x, newRegionX, y, newRegionY)) + { + byebyeRegions.Add(handle); + } + } + } + } + + if (byebyeRegions.Count > 0) + { + m_log.Debug("[SCENE PRESENCE]: Closing " + byebyeRegions.Count + " child agents"); + m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions); + } + + foreach (ulong handle in byebyeRegions) + { + RemoveNeighbourRegion(handle); + } + } + + #endregion + + /// + /// This allows the Sim owner the abiility to kick users from their sim currently. + /// It tells the client that the agent has permission to do so. + /// + public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus) + { + if (godStatus) + { + // For now, assign god level 200 to anyone + // who is granted god powers, but has no god level set. + // + UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID); + if (account != null) + { + if (account.UserLevel > 0) + m_godLevel = account.UserLevel; + else + m_godLevel = 200; + } + } + else + { + m_godLevel = 0; + } + + ControllingClient.SendAdminResponse(token, (uint)m_godLevel); + } + + #region Child Agent Updates + + public void ChildAgentDataUpdate(AgentData cAgentData) + { + //m_log.Debug(" >>> ChildAgentDataUpdate <<< " + Scene.RegionInfo.RegionName); + if (!IsChildAgent) + return; + + CopyFrom(cAgentData); + } + + /// + /// This updates important decision making data about a child agent + /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region + /// + public void ChildAgentDataUpdate(AgentPosition cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY) + { + if (!IsChildAgent) + return; + + //m_log.Debug(" >>> ChildAgentPositionUpdate <<< " + rRegionX + "-" + rRegionY); + int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; + int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; + + Vector3 offset = new Vector3(shiftx, shifty, 0f); + + m_DrawDistance = cAgentData.Far; + if (cAgentData.Position != new Vector3(-1f, -1f, -1f)) // UGH!! + m_pos = cAgentData.Position + offset; + + if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) + { + posLastSignificantMove = AbsolutePosition; + ReprioritizeUpdates(); + } + + m_CameraCenter = cAgentData.Center + offset; + + m_avHeight = cAgentData.Size.Z; + //SetHeight(cAgentData.AVHeight); + + if ((cAgentData.Throttles != null) && cAgentData.Throttles.Length > 0) + ControllingClient.SetChildAgentThrottle(cAgentData.Throttles); + + // Sends out the objects in the user's draw distance if m_sendTasksToChild is true. + if (m_scene.m_seeIntoRegionFromNeighbor) + m_sceneViewer.Reset(); + + //cAgentData.AVHeight; + m_rootRegionHandle = cAgentData.RegionHandle; + //m_velocity = cAgentData.Velocity; + } + + public void CopyTo(AgentData cAgent) + { + cAgent.AgentID = UUID; + cAgent.RegionID = Scene.RegionInfo.RegionID; + + cAgent.Position = AbsolutePosition; + cAgent.Velocity = m_velocity; + cAgent.Center = m_CameraCenter; + // Don't copy the size; it is inferred from apearance parameters + //cAgent.Size = new Vector3(0, 0, m_avHeight); + cAgent.AtAxis = m_CameraAtAxis; + cAgent.LeftAxis = m_CameraLeftAxis; + cAgent.UpAxis = m_CameraUpAxis; + + cAgent.Far = m_DrawDistance; + + // Throttles + float multiplier = 1; + int innacurateNeighbors = m_scene.GetInaccurateNeighborCount(); + if (innacurateNeighbors != 0) + { + multiplier = 1f / innacurateNeighbors; + } + if (multiplier <= 0f) + { + multiplier = 0.25f; + } + //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString()); + cAgent.Throttles = ControllingClient.GetThrottlesPacked(multiplier); + + cAgent.HeadRotation = m_headrotation; + cAgent.BodyRotation = m_bodyRot; + cAgent.ControlFlags = (uint)m_AgentControlFlags; + + if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) + cAgent.GodLevel = (byte)m_godLevel; + else + cAgent.GodLevel = (byte) 0; + + cAgent.AlwaysRun = m_setAlwaysRun; + + try + { + // We might not pass the Wearables in all cases... + // They're only needed so that persistent changes to the appearance + // are preserved in the new region where the user is moving to. + // But in Hypergrid we might not let this happen. + int i = 0; + UUID[] wears = new UUID[m_appearance.Wearables.Length * 2]; + foreach (AvatarWearable aw in m_appearance.Wearables) + { + if (aw != null) + { + wears[i++] = aw.ItemID; + wears[i++] = aw.AssetID; + } + else + { + wears[i++] = UUID.Zero; + wears[i++] = UUID.Zero; + } + } + cAgent.Wearables = wears; + + cAgent.VisualParams = m_appearance.VisualParams; + + if (m_appearance.Texture != null) + cAgent.AgentTextures = m_appearance.Texture.GetBytes(); + } + catch (Exception e) + { + m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message); + } + + //Attachments + List attPoints = m_appearance.GetAttachedPoints(); + if (attPoints != null) + { + //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); + int i = 0; + AttachmentData[] attachs = new AttachmentData[attPoints.Count]; + foreach (int point in attPoints) + { + attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); + } + cAgent.Attachments = attachs; + } + + lock (scriptedcontrols) + { + ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; + int i = 0; + + foreach (ScriptControllers c in scriptedcontrols.Values) + { + controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); + } + cAgent.Controllers = controls; + } + + // Animations + try + { + cAgent.Anims = Animator.Animations.ToArray(); + } + catch { } + + // cAgent.GroupID = ?? + // Groups??? + + } + + public void CopyFrom(AgentData cAgent) + { + m_originRegionID = cAgent.RegionID; + + m_callbackURI = cAgent.CallbackURI; + + m_pos = cAgent.Position; + + m_velocity = cAgent.Velocity; + m_CameraCenter = cAgent.Center; + //m_avHeight = cAgent.Size.Z; + m_CameraAtAxis = cAgent.AtAxis; + m_CameraLeftAxis = cAgent.LeftAxis; + m_CameraUpAxis = cAgent.UpAxis; + + m_DrawDistance = cAgent.Far; + + if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0) + ControllingClient.SetChildAgentThrottle(cAgent.Throttles); + + m_headrotation = cAgent.HeadRotation; + m_bodyRot = cAgent.BodyRotation; + m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; + + if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID))) + m_godLevel = cAgent.GodLevel; + m_setAlwaysRun = cAgent.AlwaysRun; + + uint i = 0; + try + { + if (cAgent.Wearables == null) + cAgent.Wearables = new UUID[0]; + AvatarWearable[] wears = new AvatarWearable[cAgent.Wearables.Length / 2]; + for (uint n = 0; n < cAgent.Wearables.Length; n += 2) + { + UUID itemId = cAgent.Wearables[n]; + UUID assetId = cAgent.Wearables[n + 1]; + wears[i++] = new AvatarWearable(itemId, assetId); + } + m_appearance.Wearables = wears; + Primitive.TextureEntry te; + if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1) + te = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); + else + te = AvatarAppearance.GetDefaultTexture(); + if ((cAgent.VisualParams == null) || (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) + cAgent.VisualParams = AvatarAppearance.GetDefaultVisualParams(); + m_appearance.SetAppearance(te, (byte[])cAgent.VisualParams.Clone()); + } + catch (Exception e) + { + m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message); + } + + // Attachments + try + { + if (cAgent.Attachments != null) + { + m_appearance.ClearAttachments(); + foreach (AttachmentData att in cAgent.Attachments) + { + m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); + } + } + } + catch { } + + try + { + lock (scriptedcontrols) + { + if (cAgent.Controllers != null) + { + scriptedcontrols.Clear(); + + foreach (ControllerData c in cAgent.Controllers) + { + ScriptControllers sc = new ScriptControllers(); + sc.itemID = c.ItemID; + sc.ignoreControls = (ScriptControlled)c.IgnoreControls; + sc.eventControls = (ScriptControlled)c.EventControls; + + scriptedcontrols[sc.itemID] = sc; + } + } + } + } + catch { } + // Animations + try + { + Animator.ResetAnimations(); + Animator.Animations.FromArray(cAgent.Anims); + } + catch { } + + //cAgent.GroupID = ?? + //Groups??? + } + + public bool CopyAgent(out IAgentData agent) + { + agent = new CompleteAgentData(); + CopyTo((AgentData)agent); + return true; + } + + #endregion Child Agent Updates + + /// + /// Handles part of the PID controller function for moving an avatar. + /// + public override void UpdateMovement() + { + if (m_forceToApply.HasValue) + { + + Vector3 force = m_forceToApply.Value; + m_updateflag = true; + Velocity = force; + + m_forceToApply = null; + } + else + { + if (m_isNudging) + { + Vector3 force = Vector3.Zero; + + m_updateflag = true; + Velocity = force; + m_isNudging = false; + m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND" + } + } + } + + public override void SetText(string text, Vector3 color, double alpha) + { + throw new Exception("Can't set Text on avatar."); + } + + /// + /// Adds a physical representation of the avatar to the Physics plugin + /// + public void AddToPhysicalScene(bool isFlying) + { + PhysicsScene scene = m_scene.PhysicsScene; + + Vector3 pVec = AbsolutePosition; + + // Old bug where the height was in centimeters instead of meters + if (m_avHeight == 127.0f) + { + m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new Vector3(0f, 0f, 1.56f), + isFlying); + } + else + { + m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, + new Vector3(0f, 0f, m_avHeight), isFlying); + } + scene.AddPhysicsActorTaint(m_physicsActor); + //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; + m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; + m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong + m_physicsActor.SubscribeEvents(500); + m_physicsActor.LocalID = LocalId; + } + + private void OutOfBoundsCall(Vector3 pos) + { + //bool flying = m_physicsActor.Flying; + //RemoveFromPhysicalScene(); + + //AddToPhysicalScene(flying); + if (ControllingClient != null) + ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); + } + + // Event called by the physics plugin to tell the avatar about a collision. + private void PhysicsCollisionUpdate(EventArgs e) + { + if (e == null) + return; + + // The Physics Scene will send (spam!) updates every 500 ms grep: m_physicsActor.SubscribeEvents( + // as of this comment the interval is set in AddToPhysicalScene + if (Animator!=null) + { + if (m_updateCount > 0) //KF: DO NOT call UpdateMovementAnimations outside of the m_updateCount wrapper, + { // else its will lock out other animation changes, like ground sit. + Animator.UpdateMovementAnimations(); + m_updateCount--; + } + } + + CollisionEventUpdate collisionData = (CollisionEventUpdate)e; + Dictionary coldata = collisionData.m_objCollisionList; + + CollisionPlane = Vector4.UnitW; + + if (m_lastColCount != coldata.Count) + { + m_updateCount = UPDATE_COUNT; + m_lastColCount = coldata.Count; + } + + if (coldata.Count != 0 && Animator != null) + { + switch (Animator.CurrentMovementAnimation) + { + case "STAND": + case "WALK": + case "RUN": + case "CROUCH": + case "CROUCHWALK": + { + ContactPoint lowest; + lowest.SurfaceNormal = Vector3.Zero; + lowest.Position = Vector3.Zero; + lowest.Position.Z = Single.NaN; + + foreach (ContactPoint contact in coldata.Values) + { + if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) + { + lowest = contact; + } + } + + CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); + } + break; + } + } + + List thisHitColliders = new List(); + List endedColliders = new List(); + List startedColliders = new List(); + + foreach (uint localid in coldata.Keys) + { + thisHitColliders.Add(localid); + if (!m_lastColliders.Contains(localid)) + { + startedColliders.Add(localid); + } + //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); + } + + // calculate things that ended colliding + foreach (uint localID in m_lastColliders) + { + if (!thisHitColliders.Contains(localID)) + { + endedColliders.Add(localID); + } + } + //add the items that started colliding this time to the last colliders list. + foreach (uint localID in startedColliders) + { + m_lastColliders.Add(localID); + } + // remove things that ended colliding from the last colliders list + foreach (uint localID in endedColliders) + { + m_lastColliders.Remove(localID); + } + + // do event notification + if (startedColliders.Count > 0) + { + ColliderArgs StartCollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in startedColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + StartCollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in Attachments) + Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); + } + } + + if (endedColliders.Count > 0) + { + ColliderArgs EndCollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in endedColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + EndCollidingMessage.Colliders = colliding; + + foreach (SceneObjectGroup att in Attachments) + Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); + } + } + + if (thisHitColliders.Count > 0) + { + ColliderArgs CollidingMessage = new ColliderArgs(); + List colliding = new List(); + foreach (uint localId in thisHitColliders) + { + if (localId == 0) + continue; + + SceneObjectPart obj = Scene.GetSceneObjectPart(localId); + string data = ""; + if (obj != null) + { + DetectedObject detobj = new DetectedObject(); + detobj.keyUUID = obj.UUID; + detobj.nameStr = obj.Name; + detobj.ownerUUID = obj.OwnerID; + detobj.posVector = obj.AbsolutePosition; + detobj.rotQuat = obj.GetWorldRotation(); + detobj.velVector = obj.Velocity; + detobj.colliderType = 0; + detobj.groupUUID = obj.GroupID; + colliding.Add(detobj); + } + } + + if (colliding.Count > 0) + { + CollidingMessage.Colliders = colliding; + + lock (m_attachments) + { + foreach (SceneObjectGroup att in m_attachments) + Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage); + } + } + } + + if (m_invulnerable) + return; + + float starthealth = Health; + uint killerObj = 0; + foreach (uint localid in coldata.Keys) + { + SceneObjectPart part = Scene.GetSceneObjectPart(localid); + + if (part != null && part.ParentGroup.Damage != -1.0f) + Health -= part.ParentGroup.Damage; + else + { + if (coldata[localid].PenetrationDepth >= 0.10f) + Health -= coldata[localid].PenetrationDepth * 5.0f; + } + + if (Health <= 0.0f) + { + if (localid != 0) + killerObj = localid; + } + //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString()); + } + //Health = 100; + if (!m_invulnerable) + { + if (starthealth != Health) + { + ControllingClient.SendHealth(Health); + } + if (m_health <= 0) + m_scene.EventManager.TriggerAvatarKill(killerObj, this); + } + } + + public void setHealthWithUpdate(float health) + { + Health = health; + ControllingClient.SendHealth(Health); + } + + public void Close() + { + lock (m_attachments) + { + // Delete attachments from scene + // Don't try to save, as this thread won't live long + // enough to complete the save. This would cause no copy + // attachments to poof! + // + foreach (SceneObjectGroup grp in m_attachments) + { + m_scene.DeleteSceneObject(grp, false); + } + m_attachments.Clear(); + } + + lock (m_knownChildRegions) + { + m_knownChildRegions.Clear(); + } + + lock (m_reprioritization_timer) + { + m_reprioritization_timer.Enabled = false; + m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); + } + + // I don't get it but mono crashes when you try to dispose of this timer, + // unsetting the elapsed callback should be enough to allow for cleanup however. + // m_reprioritizationTimer.Dispose(); + + m_sceneViewer.Close(); + + RemoveFromPhysicalScene(); + m_animator.Close(); + m_animator = null; + } + + public void AddAttachment(SceneObjectGroup gobj) + { + lock (m_attachments) + { + m_attachments.Add(gobj); + } + } + + public bool HasAttachments() + { + return m_attachments.Count > 0; + } + + public bool HasScriptedAttachments() + { + lock (m_attachments) + { + foreach (SceneObjectGroup gobj in m_attachments) + { + if (gobj != null) + { + if (gobj.RootPart.Inventory.ContainsScripts()) + return true; + } + } + } + return false; + } + + public void RemoveAttachment(SceneObjectGroup gobj) + { + lock (m_attachments) + { + if (m_attachments.Contains(gobj)) + { + m_attachments.Remove(gobj); + } + } + } + + public bool ValidateAttachments() + { + lock (m_attachments) + { + // Validate + foreach (SceneObjectGroup gobj in m_attachments) + { + if (gobj == null) + return false; + + if (gobj.IsDeleted) + return false; + } + } + return true; + } + + /// + /// Send a script event to this scene presence's attachments + /// + /// The name of the event + /// The arguments for the event + public void SendScriptEventToAttachments(string eventName, Object[] args) + { + if (m_scriptEngines != null) + { + lock (m_attachments) + { + foreach (SceneObjectGroup grp in m_attachments) + { + // 16384 is CHANGED_ANIMATION + // + // Send this to all attachment root prims + // + foreach (IScriptModule m in m_scriptEngines) + { + if (m == null) // No script engine loaded + continue; + + m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); + } + } + } + } + } + + + public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene) + { + m_controllingClient = client; + m_regionInfo = region; + m_scene = scene; + + RegisterToEvents(); + if (m_controllingClient != null) + { + m_controllingClient.ProcessPendingPackets(); + } + /* + AbsolutePosition = client.StartPos; + + Animations = new AvatarAnimations(); + Animations.LoadAnims(); + + m_animations = new List(); + m_animations.Add(Animations.AnimsUUID["STAND"]); + m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber); + + SetDirectionVectors(); + */ + } + + internal void PushForce(Vector3 impulse) + { + if (PhysicsActor != null) + { + PhysicsActor.AddForce(impulse,true); + } + } + + public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) + { + ScriptControllers obj = new ScriptControllers(); + obj.ignoreControls = ScriptControlled.CONTROL_ZERO; + obj.eventControls = ScriptControlled.CONTROL_ZERO; + + obj.itemID = Script_item_UUID; + if (pass_on == 0 && accept == 0) + { + IgnoredControls |= (ScriptControlled)controls; + obj.ignoreControls = (ScriptControlled)controls; + } + + if (pass_on == 0 && accept == 1) + { + IgnoredControls |= (ScriptControlled)controls; + obj.ignoreControls = (ScriptControlled)controls; + obj.eventControls = (ScriptControlled)controls; + } + if (pass_on == 1 && accept == 1) + { + IgnoredControls = ScriptControlled.CONTROL_ZERO; + obj.eventControls = (ScriptControlled)controls; + obj.ignoreControls = ScriptControlled.CONTROL_ZERO; + } + + lock (scriptedcontrols) + { + if (pass_on == 1 && accept == 0) + { + IgnoredControls &= ~(ScriptControlled)controls; + if (scriptedcontrols.ContainsKey(Script_item_UUID)) + scriptedcontrols.Remove(Script_item_UUID); + } + else + { + scriptedcontrols[Script_item_UUID] = obj; + } + } + ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); + } + + public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID) + { + IgnoredControls = ScriptControlled.CONTROL_ZERO; + lock (scriptedcontrols) + { + scriptedcontrols.Clear(); + } + ControllingClient.SendTakeControls(int.MaxValue, false, false); + } + + public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) + { + ScriptControllers takecontrols; + + lock (scriptedcontrols) + { + if (scriptedcontrols.TryGetValue(Script_item_UUID, out takecontrols)) + { + ScriptControlled sctc = takecontrols.eventControls; + + ControllingClient.SendTakeControls((int)sctc, false, false); + ControllingClient.SendTakeControls((int)sctc, true, false); + + scriptedcontrols.Remove(Script_item_UUID); + IgnoredControls = ScriptControlled.CONTROL_ZERO; + foreach (ScriptControllers scData in scriptedcontrols.Values) + { + IgnoredControls |= scData.ignoreControls; + } + } + } + } + + internal void SendControlToScripts(uint flags) + { + ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; + + if (MouseDown) + { + allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) + { + allflags = ScriptControlled.CONTROL_ZERO; + MouseDown = true; + } + } + + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) + { + allflags |= ScriptControlled.CONTROL_ML_LBUTTON; + MouseDown = true; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0) + { + allflags |= ScriptControlled.CONTROL_LBUTTON; + MouseDown = true; + } + + // find all activated controls, whether the scripts are interested in them or not + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) + { + allflags |= ScriptControlled.CONTROL_FWD; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0) + { + allflags |= ScriptControlled.CONTROL_BACK; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0) + { + allflags |= ScriptControlled.CONTROL_UP; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0) + { + allflags |= ScriptControlled.CONTROL_DOWN; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0) + { + allflags |= ScriptControlled.CONTROL_LEFT; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0) + { + allflags |= ScriptControlled.CONTROL_RIGHT; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0) + { + allflags |= ScriptControlled.CONTROL_ROT_RIGHT; + } + if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) + { + allflags |= ScriptControlled.CONTROL_ROT_LEFT; + } + // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that + if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands) + { + lock (scriptedcontrols) + { + foreach (KeyValuePair kvp in scriptedcontrols) + { + UUID scriptUUID = kvp.Key; + ScriptControllers scriptControlData = kvp.Value; + + ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us + ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle + ScriptControlled localChange = localHeld ^ localLast; // the changed bits + if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) + { + // only send if still pressed or just changed + m_scene.EventManager.TriggerControlEvent(scriptUUID, UUID, (uint)localHeld, (uint)localChange); + } + } + } + } + + LastCommands = allflags; + } + + internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) + { + if (ignored == ScriptControlled.CONTROL_ZERO) + return flags; + + if ((ignored & ScriptControlled.CONTROL_BACK) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); + if ((ignored & ScriptControlled.CONTROL_FWD) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_AT_POS); + if ((ignored & ScriptControlled.CONTROL_DOWN) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG); + if ((ignored & ScriptControlled.CONTROL_UP) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | AgentManager.ControlFlags.AGENT_CONTROL_UP_POS); + if ((ignored & ScriptControlled.CONTROL_LEFT) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); + if ((ignored & ScriptControlled.CONTROL_RIGHT) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG); + if ((ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG); + if ((ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS); + if ((ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN); + if ((ignored & ScriptControlled.CONTROL_LBUTTON) != 0) + flags &= ~(AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN); + + //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, + //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG, + //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS, + //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG, + //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS, + //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, + //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG + + return flags; + } + + /// + /// RezAttachments. This should only be called upon login on the first region. + /// Attachment rezzings on crossings and TPs are done in a different way. + /// + public void RezAttachments() + { + if (null == m_appearance) + { + m_log.WarnFormat("[ATTACHMENT]: Appearance has not been initialized for agent {0}", UUID); + return; + } + + XmlDocument doc = new XmlDocument(); + string stateData = String.Empty; + + IAttachmentsService attServ = m_scene.RequestModuleInterface(); + if (attServ != null) + { + m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service"); + stateData = attServ.Get(ControllingClient.AgentId.ToString()); + if (stateData != String.Empty) + { + try + { + doc.LoadXml(stateData); + } + catch { } + } + } + + Dictionary itemData = new Dictionary(); + + XmlNodeList nodes = doc.GetElementsByTagName("Attachment"); + if (nodes.Count > 0) + { + foreach (XmlNode n in nodes) + { + XmlElement elem = (XmlElement)n; + string itemID = elem.GetAttribute("ItemID"); + string xml = elem.InnerXml; + + itemData[new UUID(itemID)] = xml; + } + } + + List attPoints = m_appearance.GetAttachedPoints(); + foreach (int p in attPoints) + { + if (m_isDeleted) + return; + + UUID itemID = m_appearance.GetAttachedItem(p); + UUID assetID = m_appearance.GetAttachedAsset(p); + + // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down + // But they're not used anyway, the item is being looked up for now, so let's proceed. + //if (UUID.Zero == assetID) + //{ + // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); + // continue; + //} + + try + { + string xmlData; + XmlDocument d = new XmlDocument(); + UUID asset; + if (itemData.TryGetValue(itemID, out xmlData)) + { + d.LoadXml(xmlData); + m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", itemID); + + // Rez from inventory + asset + = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, d); + + } + else + { + // Rez from inventory (with a null doc to let + // CHANGED_OWNER happen) + asset + = m_scene.AttachmentsModule.RezSingleAttachmentFromInventory(ControllingClient, itemID, (uint)p, true, null); + } + + m_log.InfoFormat( + "[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", + p, itemID, assetID, asset); + } + catch (Exception e) + { + m_log.ErrorFormat("[ATTACHMENT]: Unable to rez attachment: {0}", e.ToString()); + } + } + } + + private void ReprioritizeUpdates() + { + if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time) + { + lock (m_reprioritization_timer) + { + if (!m_reprioritizing) + m_reprioritization_timer.Enabled = m_reprioritizing = true; + else + m_reprioritization_called = true; + } + } + } + + private void Reprioritize(object sender, ElapsedEventArgs e) + { + m_controllingClient.ReprioritizeUpdates(); + + lock (m_reprioritization_timer) + { + m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called; + m_reprioritization_called = false; + } + } + + private Vector3 Quat2Euler(Quaternion rot){ + float x = Utils.RAD_TO_DEG * (float)Math.Atan2((double)((2.0f * rot.X * rot.W) - (2.0f * rot.Y * rot.Z)) , + (double)(1 - (2.0f * rot.X * rot.X) - (2.0f * rot.Z * rot.Z))); + float y = Utils.RAD_TO_DEG * (float)Math.Asin ((double)((2.0f * rot.X * rot.Y) + (2.0f * rot.Z * rot.W))); + float z = Utils.RAD_TO_DEG * (float)Math.Atan2(((double)(2.0f * rot.Y * rot.W) - (2.0f * rot.X * rot.Z)) , + (double)(1 - (2.0f * rot.Y * rot.Y) - (2.0f * rot.Z * rot.Z))); + return(new Vector3(x,y,z)); + } + + + } +} diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 5da6bb9a21..6e8435d362 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -279,6 +279,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART public const int CHANGED_MEDIA = 2048; public const int CHANGED_ANIMATION = 16384; + public const int CHANGED_POSITION = 32768; public const int TYPE_INVALID = 0; public const int TYPE_INTEGER = 1; public const int TYPE_FLOAT = 2; diff --git a/bin/ICSharpCode.SharpZipLib.xml b/bin/ICSharpCode.SharpZipLib.xml deleted file mode 100644 index 98cb51eba4..0000000000 --- a/bin/ICSharpCode.SharpZipLib.xml +++ /dev/null @@ -1,9055 +0,0 @@ - - - - ICSharpCode.SharpZipLib - - - - - FastZipEvents supports all events applicable to FastZip operations. - - - - - Delegate to invoke when processing directories. - - - - - Delegate to invoke when processing files. - - - - - Delegate to invoke during processing of files. - - - - - Delegate to invoke when processing for a file has been completed. - - - - - Delegate to invoke when processing directory failures. - - - - - Delegate to invoke when processing file failures. - - - - - Raise the directory failure event. - - The directory causing the failure. - The exception for this event. - A boolean indicating if execution should continue or not. - - - - Raises the file failure delegate. - - The file causing the failure. - The exception for this failure. - A boolean indicating if execution should continue or not. - - - - Fires the Process File delegate. - - The file being processed. - A boolean indicating if execution should continue or not. - - - - Fires the CompletedFile delegate - - The file whose processing has been completed. - A boolean indicating if execution should continue or not. - - - - Fires the process directory delegate. - - The directory being processed. - Flag indicating if the directory has matching files as determined by the current filter. - A of true if the operation should continue; false otherwise. - - - - The minimum timespan between events. - - The minimum period of time between events. - - - - - FastZip provides facilities for creating and extracting zip files. - - - - - Initialise a default instance of . - - - - - Initialise a new instance of - - The events to use during operations. - - - - Create a zip file. - - The name of the zip file to create. - The directory to source files from. - True to recurse directories, false for no recursion. - The file filter to apply. - The directory filter to apply. - - - - Create a zip file/archive. - - The name of the zip file to create. - The directory to obtain files and directories from. - True to recurse directories, false for no recursion. - The file filter to apply. - - - - Create a zip archive sending output to the passed. - - The stream to write archive data to. - The directory to source files from. - True to recurse directories, false for no recursion. - The file filter to apply. - The directory filter to apply. - - - - Extract the contents of a zip file. - - The zip file to extract from. - The directory to save extracted information in. - A filter to apply to files. - - - - Extract the contents of a zip file. - - The zip file to extract from. - The directory to save extracted information in. - The style of overwriting to apply. - A delegate to invoke when confirming overwriting. - A filter to apply to files. - A filter to apply to directories. - Flag indicating wether to restore the date and time for extracted files. - - - - Get/set a value indicating wether empty directories should be created. - - - - - Get / set the password value. - - - - - Get or set the active when creating Zip files. - - - - - - Get or set the active when creating Zip files. - - - - - Get/set a value indicating wether file dates and times should - be restored when extracting files from an archive. - - The default value is false. - - - - Get/set a value indicating wether file attributes should - be restored during extract operations - - - - - Defines the desired handling when overwriting files during extraction. - - - - - Prompt the user to confirm overwriting - - - - - Never overwrite files. - - - - - Always overwrite files. - - - - - Delegate called when confirming overwriting of files. - - - - - NameFilter is a string matching class which allows for both positive and negative - matching. - A filter is a sequence of independant regular expressions separated by semi-colons ';' - Each expression can be prefixed by a plus '+' sign or a minus '-' sign to denote the expression - is intended to include or exclude names. If neither a plus or minus sign is found include is the default - A given name is tested for inclusion before checking exclusions. Only names matching an include spec - and not matching an exclude spec are deemed to match the filter. - An empty filter matches any name. - - The following expression includes all name ending in '.dat' with the exception of 'dummy.dat' - "+\.dat$;-^dummy\.dat$" - - - - - Scanning filters support filtering of names. - - - - - Test a name to see if it 'matches' the filter. - - The name to test. - Returns true if the name matches the filter, false if it does not match. - - - - Construct an instance based on the filter expression passed - - The filter expression. - - - - Test a string to see if it is a valid regular expression. - - The expression to test. - True if expression is a valid false otherwise. - - - - Test an expression to see if it is valid as a filter. - - The filter expression to test. - True if the expression is valid, false otherwise. - - - - Convert this filter to its string equivalent. - - The string equivalent for this filter. - - - - Test a value to see if it is included by the filter. - - The value to test. - True if the value is included, false otherwise. - - - - Test a value to see if it is excluded by the filter. - - The value to test. - True if the value is excluded, false otherwise. - - - - Test a value to see if it matches the filter. - - The value to test. - True if the value matches, false otherwise. - - - - Compile this filter. - - - - - Huffman tree used for inflation - - - - - Literal length tree - - - - - Distance tree - - - - - Constructs a Huffman tree from the array of code lengths. - - - the array of code lengths - - - - - Reads the next symbol from input. The symbol is encoded using the - huffman tree. - - - input the input source. - - - the next symbol, or -1 if not enough input is available. - - - - - This class is general purpose class for writing data to a buffer. - - It allows you to write bits as well as bytes - Based on DeflaterPending.java - - author of the original java version : Jochen Hoenicke - - - - - Internal work buffer - - - - - construct instance using default buffer size of 4096 - - - - - construct instance using specified buffer size - - - size to use for internal buffer - - - - - Clear internal state/buffers - - - - - Write a byte to buffer - - - The value to write - - - - - Write a short value to buffer LSB first - - - The value to write. - - - - - write an integer LSB first - - The value to write. - - - - Write a block of data to buffer - - data to write - offset of first byte to write - number of bytes to write - - - - Align internal buffer on a byte boundary - - - - - Write bits to internal buffer - - source of bits - number of bits to write - - - - Write a short value to internal buffer most significant byte first - - value to write - - - - Flushes the pending buffer into the given output array. If the - output array is to small, only a partial flush is done. - - The output array. - The offset into output array. - The maximum number of bytes to store. - The number of bytes flushed. - - - - Convert internal buffer to byte array. - Buffer is empty on completion - - - The internal buffer contents converted to a byte array. - - - - - The number of bits written to the buffer - - - - - Indicates if buffer has been flushed - - - - - Used to advise clients of 'events' while processing archives - - - - - The TarArchive class implements the concept of a - 'Tape Archive'. A tar archive is a series of entries, each of - which represents a file system object. Each entry in - the archive consists of a header block followed by 0 or more data blocks. - Directory entries consist only of the header block, and are followed by entries - for the directory's contents. File entries consist of a - header followed by the number of blocks needed to - contain the file's contents. All entries are written on - block boundaries. Blocks are 512 bytes long. - - TarArchives are instantiated in either read or write mode, - based upon whether they are instantiated with an InputStream - or an OutputStream. Once instantiated TarArchives read/write - mode can not be changed. - - There is currently no support for random access to tar archives. - However, it seems that subclassing TarArchive, and using the - TarBuffer.CurrentRecord and TarBuffer.CurrentBlock - properties, this would be rather trivial. - - - - - Raises the ProgressMessage event - - The TarEntry for this event - message for this event. Null is no message - - - - Constructor for a default . - - - - - Initalise a TarArchive for input. - - The to use for input. - - - - Initialise a TarArchive for output. - - The to use for output. - - - - The InputStream based constructors create a TarArchive for the - purposes of extracting or listing a tar archive. Thus, use - these constructors when you wish to extract files from or list - the contents of an existing tar archive. - - The stream to retrieve archive data from. - Returns a new suitable for reading from. - - - - Create TarArchive for reading setting block factor - - Stream for tar archive contents - The blocking factor to apply - Returns a suitable for reading. - - - - Create a TarArchive for writing to, using the default blocking factor - - The to write to - Returns a suitable for writing. - - - - Create a TarArchive for writing to - - The stream to write to - The blocking factor to use for buffering. - Returns a suitable for writing. - - - - Set the flag that determines whether existing files are - kept, or overwritten during extraction. - - - If true, do not overwrite existing files. - - - - - Set the ascii file translation flag. - - - If true, translate ascii text files. - - - - - Set user and group information that will be used to fill in the - tar archive's entry headers. This information based on that available - for the linux operating system, which is not always available on other - operating systems. TarArchive allows the programmer to specify values - to be used in their place. - is set to true by this call. - - - The user id to use in the headers. - - - The user name to use in the headers. - - - The group id to use in the headers. - - - The group name to use in the headers. - - - - - Close the archive. - - - - - Perform the "list" command for the archive contents. - - NOTE That this method uses the progress event to actually list - the contents. If the progress display event is not set, nothing will be listed! - - - - - Perform the "extract" command and extract the contents of the archive. - - - The destination directory into which to extract. - - - - - Extract an entry from the archive. This method assumes that the - tarIn stream has been properly set with a call to GetNextEntry(). - - - The destination directory into which to extract. - - - The TarEntry returned by tarIn.GetNextEntry(). - - - - - Write an entry to the archive. This method will call the putNextEntry - and then write the contents of the entry, and finally call closeEntry() - for entries that are files. For directories, it will call putNextEntry(), - and then, if the recurse flag is true, process each entry that is a - child of the directory. - - - The TarEntry representing the entry to write to the archive. - - - If true, process the children of directory entries. - - - - - Write an entry to the archive. This method will call the putNextEntry - and then write the contents of the entry, and finally call closeEntry() - for entries that are files. For directories, it will call putNextEntry(), - and then, if the recurse flag is true, process each entry that is a - child of the directory. - - - The TarEntry representing the entry to write to the archive. - - - If true, process the children of directory entries. - - - - - Releases the unmanaged resources used by the FileStream and optionally releases the managed resources. - - true to release both managed and unmanaged resources; - false to release only unmanaged resources. - - - - Closes the archive and releases any associated resources. - - - - - Ensures that resources are freed and other cleanup operations are performed - when the garbage collector reclaims the . - - - - - Client hook allowing detailed information to be reported during processing - - - - - Get/set the ascii file translation flag. If ascii file translation - is true, then the file is checked to see if it a binary file or not. - If the flag is true and the test indicates it is ascii text - file, it will be translated. The translation converts the local - operating system's concept of line ends into the UNIX line end, - '\n', which is the defacto standard for a TAR archive. This makes - text files compatible with UNIX. - - - - - PathPrefix is added to entry names as they are written if the value is not null. - A slash character is appended after PathPrefix - - - - - RootPath is removed from entry names if it is found at the - beginning of the name. - - - - - Get or set a value indicating if overrides defined by SetUserInfo should be applied. - - If overrides are not applied then the values as set in each header will be used. - - - - Get the archive user id. - See ApplyUserInfoOverrides for detail - on how to allow setting values on a per entry basis. - - - The current user id. - - - - - Get the archive user name. - See ApplyUserInfoOverrides for detail - on how to allow setting values on a per entry basis. - - - The current user name. - - - - - Get the archive group id. - See ApplyUserInfoOverrides for detail - on how to allow setting values on a per entry basis. - - - The current group id. - - - - - Get the archive group name. - See ApplyUserInfoOverrides for detail - on how to allow setting values on a per entry basis. - - - The current group name. - - - - - Get the archive's record size. Tar archives are composed of - a series of RECORDS each containing a number of BLOCKS. - This allowed tar archives to match the IO characteristics of - the physical device being used. Archives are expected - to be properly "blocked". - - - The record size this archive is using. - - - - - An output stream that compresses into the BZip2 format - including file header chars into another stream. - - - - - Construct a default output stream with maximum block size - - The stream to write BZip data onto. - - - - Initialise a new instance of the - for the specified stream, using the given blocksize. - - The stream to write compressed data to. - The block size to use. - - Valid block sizes are in the range 1..9, with 1 giving - the lowest compression and 9 the highest. - - - - - Ensures that resources are freed and other cleanup operations - are performed when the garbage collector reclaims the BZip2OutputStream. - - - - - Sets the current position of this stream to the given value. - - The point relative to the offset from which to being seeking. - The reference point from which to begin seeking. - The new position in the stream. - - - - Sets the length of this stream to the given value. - - The new stream length. - - - - Read a byte from the stream advancing the position. - - The byte read cast to an int; -1 if end of stream. - - - - Read a block of bytes - - The buffer to read into. - The offset in the buffer to start storing data at. - The maximum number of bytes to read. - The total number of bytes read. This might be less than the number of bytes - requested if that number of bytes are not currently available, or zero - if the end of the stream is reached. - - - - Write a block of bytes to the stream - - The buffer containing data to write. - The offset of the first byte to write. - The number of bytes to write. - - - - Write a byte to the stream. - - The byte to write to the stream. - - - - End the current block and end compression. - Close the stream and free any resources - - - - - Get the number of bytes written to output. - - - - - Releases the unmanaged resources used by the and optionally releases the managed resources. - - true to release both managed and unmanaged resources; false to release only unmanaged resources. - - - - Flush output buffers - - - - - Get/set flag indicating ownership of underlying stream. - When the flag is true will close the underlying stream also. - - - - - Gets a value indicating whether the current stream supports reading - - - - - Gets a value indicating whether the current stream supports seeking - - - - - Gets a value indicating whether the current stream supports writing - - - - - Gets the length in bytes of the stream - - - - - Gets or sets the current position of this stream. - - - - - Get the number of bytes written to the output. - - - - - Represents exception conditions specific to Zip archive handling - - - - - SharpZipBaseException is the base exception class for the SharpZipLibrary. - All library exceptions are derived from this. - - NOTE: Not all exceptions thrown will be derived from this class. - A variety of other exceptions are possible for example - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initializes a new instance of the SharpZipBaseException class. - - - - - Initializes a new instance of the SharpZipBaseException class with a specified error message. - - A message describing the exception. - - - - Initializes a new instance of the SharpZipBaseException class with a specified - error message and a reference to the inner exception that is the cause of this exception. - - A message describing the exception. - The inner exception - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initializes a new instance of the ZipException class. - - - - - Initializes a new instance of the ZipException class with a specified error message. - - The error message that explains the reason for the exception. - - - - Initialise a new instance of ZipException. - - A message describing the error. - The exception that is the cause of the current exception. - - - - A helper class to simplify compressing and decompressing streams. - - - - - Decompress input writing - decompressed data to the output stream - - The stream containing data to decompress. - The stream to write decompressed data to. - Both streams are closed on completion - - - - Compress input stream sending - result to output stream - - The stream to compress. - The stream to write compressed data to. - The block size to use. - Both streams are closed on completion - - - - Initialise a default instance of this class. - - - - - Determines how entries are tested to see if they should use Zip64 extensions or not. - - - - - Zip64 will not be forced on entries during processing. - - An entry can have this overridden if required - - - - Zip64 should always be used. - - - - - #ZipLib will determine use based on entry values when added to archive. - - - - - The kind of compression used for an entry in an archive - - - - - A direct copy of the file contents is held in the archive - - - - - Common Zip compression method using a sliding dictionary - of up to 32KB and secondary compression from Huffman/Shannon-Fano trees - - - - - An extension to deflate with a 64KB window. Not supported by #Zip currently - - - - - Not supported by #Zip currently - - - - - WinZip special for AES encryption, Not supported by #Zip - - - - - Identifies the encryption algorithm used for an entry - - - - - No encryption has been used. - - - - - Encrypted using PKZIP 2.0 or 'classic' encryption. - - - - - DES encryption has been used. - - - - - RCS encryption has been used for encryption. - - - - - Triple DES encryption with 168 bit keys has been used for this entry. - - - - - Triple DES with 112 bit keys has been used for this entry. - - - - - AES 128 has been used for encryption. - - - - - AES 192 has been used for encryption. - - - - - AES 256 has been used for encryption. - - - - - RC2 corrected has been used for encryption. - - - - - Blowfish has been used for encryption. - - - - - Twofish has been used for encryption. - - - - - RCS has been used for encryption. - - - - - An unknown algorithm has been used for encryption. - - - - - Defines the contents of the general bit flags field for an archive entry. - - - - - Bit 0 if set indicates that the file is encrypted - - - - - Bits 1 and 2 - Two bits defining the compression method (only for Method 6 Imploding and 8,9 Deflating) - - - - - Bit 3 if set indicates a trailing data desciptor is appended to the entry data - - - - - Bit 4 is reserved for use with method 8 for enhanced deflation - - - - - Bit 5 if set indicates the file contains Pkzip compressed patched data. - Requires version 2.7 or greater. - - - - - Bit 6 if set strong encryption has been used for this entry. - - - - - Bit 7 is currently unused - - - - - Bit 8 is currently unused - - - - - Bit 9 is currently unused - - - - - Bit 10 is currently unused - - - - - Bit 11 if set indicates the filename and - comment fields for this file must be encoded using UTF-8. - - - - - Bit 12 is documented as being reserved by PKware for enhanced compression. - - - - - Bit 13 if set indicates that values in the local header are masked to hide - their actual values, and the central directory is encrypted. - - - Used when encrypting the central directory contents. - - - - - Bit 14 is documented as being reserved for use by PKware - - - - - Bit 15 is documented as being reserved for use by PKware - - - - - This class contains constants used for Zip format files - - - - - The version made by field for entries in the central header when created by this library - - - This is also the Zip version for the library when comparing against the version required to extract - for an entry. See . - - - - - The version made by field for entries in the central header when created by this library - - - This is also the Zip version for the library when comparing against the version required to extract - for an entry. See ZipInputStream.CanDecompressEntry. - - - - - The minimum version required to support strong encryption - - - - - The minimum version required to support strong encryption - - - - - The version required for Zip64 extensions - - - - - Size of local entry header (excluding variable length fields at end) - - - - - Size of local entry header (excluding variable length fields at end) - - - - - Size of Zip64 data descriptor - - - - - Size of data descriptor - - - - - Size of data descriptor - - - - - Size of central header entry (excluding variable fields) - - - - - Size of central header entry - - - - - Size of end of central record (excluding variable fields) - - - - - Size of end of central record (excluding variable fields) - - - - - Size of 'classic' cryptographic header stored before any entry data - - - - - Size of cryptographic header stored before entry data - - - - - Signature for local entry header - - - - - Signature for local entry header - - - - - Signature for spanning entry - - - - - Signature for spanning entry - - - - - Signature for temporary spanning entry - - - - - Signature for temporary spanning entry - - - - - Signature for data descriptor - - - This is only used where the length, Crc, or compressed size isnt known when the - entry is created and the output stream doesnt support seeking. - The local entry cannot be 'patched' with the correct values in this case - so the values are recorded after the data prefixed by this header, as well as in the central directory. - - - - - Signature for data descriptor - - - This is only used where the length, Crc, or compressed size isnt known when the - entry is created and the output stream doesnt support seeking. - The local entry cannot be 'patched' with the correct values in this case - so the values are recorded after the data prefixed by this header, as well as in the central directory. - - - - - Signature for central header - - - - - Signature for central header - - - - - Signature for Zip64 central file header - - - - - Signature for Zip64 central file header - - - - - Signature for Zip64 central directory locator - - - - - Signature for archive extra data signature (were headers are encrypted). - - - - - Central header digitial signature - - - - - Central header digitial signature - - - - - End of central directory record signature - - - - - End of central directory record signature - - - - - Convert a portion of a byte array to a string. - - - Data to convert to string - - - Number of bytes to convert starting from index 0 - - - data[0]..data[length - 1] converted to a string - - - - - Convert a byte array to string - - - Byte array to convert - - - dataconverted to a string - - - - - Convert a byte array to string - - The applicable general purpose bits flags - - Byte array to convert - - The number of bytes to convert. - - dataconverted to a string - - - - - Convert a byte array to string - - - Byte array to convert - - The applicable general purpose bits flags - - dataconverted to a string - - - - - Convert a string to a byte array - - - String to convert to an array - - Converted array - - - - Convert a string to a byte array - - The applicable general purpose bits flags - - String to convert to an array - - Converted array - - - - Initialise default instance of ZipConstants - - - Private to prevent instances being created. - - - - - Default encoding used for string conversion. 0 gives the default system OEM code page. - Dont use unicode encodings if you want to be Zip compatible! - Using the default code page isnt the full solution neccessarily - there are many variable factors, codepage 850 is often a good choice for - European users, however be careful about compatability. - - - - - This is a DeflaterOutputStream that writes the files into a zip - archive one after another. It has a special method to start a new - zip entry. The zip entries contains information about the file name - size, compressed size, CRC, etc. - - It includes support for Stored and Deflated entries. - This class is not thread safe. -
-
Author of the original java version : Jochen Hoenicke -
- This sample shows how to create a zip file - - using System; - using System.IO; - - using ICSharpCode.SharpZipLib.Core; - using ICSharpCode.SharpZipLib.Zip; - - class MainClass - { - public static void Main(string[] args) - { - string[] filenames = Directory.GetFiles(args[0]); - byte[] buffer = new byte[4096]; - - using ( ZipOutputStream s = new ZipOutputStream(File.Create(args[1])) ) { - - s.SetLevel(9); // 0 - store only to 9 - means best compression - - foreach (string file in filenames) { - ZipEntry entry = new ZipEntry(file); - s.PutNextEntry(entry); - - using (FileStream fs = File.OpenRead(file)) { - StreamUtils.Copy(fs, s, buffer); - } - } - } - } - } - - -
- - - A special stream deflating or compressing the bytes that are - written to it. It uses a Deflater to perform actual deflating.
- Authors of the original java version : Tom Tromey, Jochen Hoenicke -
-
- - - Creates a new DeflaterOutputStream with a default Deflater and default buffer size. - - - the output stream where deflated output should be written. - - - - - Creates a new DeflaterOutputStream with the given Deflater and - default buffer size. - - - the output stream where deflated output should be written. - - - the underlying deflater. - - - - - Creates a new DeflaterOutputStream with the given Deflater and - buffer size. - - - The output stream where deflated output is written. - - - The underlying deflater to use - - - The buffer size to use when deflating - - - bufsize is less than or equal to zero. - - - baseOutputStream does not support writing - - - deflater instance is null - - - - - Finishes the stream by calling finish() on the deflater. - - - Not all input is deflated - - - - - Encrypt a block of data - - - Data to encrypt. NOTE the original contents of the buffer are lost - - - Offset of first byte in buffer to encrypt - - - Number of bytes in buffer to encrypt - - - - - Initializes encryption keys based on given password - - The password. - - - - Deflates everything in the input buffers. This will call - def.deflate() until all bytes from the input buffers - are processed. - - - - - Sets the current position of this stream to the given value. Not supported by this class! - - The offset relative to the to seek. - The to seek from. - The new position in the stream. - Any access - - - - Sets the length of this stream to the given value. Not supported by this class! - - The new stream length. - Any access - - - - Read a byte from stream advancing position by one - - The byte read cast to an int. THe value is -1 if at the end of the stream. - Any access - - - - Read a block of bytes from stream - - The buffer to store read data in. - The offset to start storing at. - The maximum number of bytes to read. - The actual number of bytes read. Zero if end of stream is detected. - Any access - - - - Asynchronous reads are not supported a NotSupportedException is always thrown - - The buffer to read into. - The offset to start storing data at. - The number of bytes to read - The async callback to use. - The state to use. - Returns an - Any access - - - - Asynchronous writes arent supported, a NotSupportedException is always thrown - - The buffer to write. - The offset to begin writing at. - The number of bytes to write. - The to use. - The state object. - Returns an IAsyncResult. - Any access - - - - Flushes the stream by calling Flush on the deflater and then - on the underlying stream. This ensures that all bytes are flushed. - - - - - Calls and closes the underlying - stream when is true. - - - - - Writes a single byte to the compressed output stream. - - - The byte value. - - - - - Writes bytes from an array to the compressed stream. - - - The byte array - - - The offset into the byte array where to start. - - - The number of bytes to write. - - - - - This buffer is used temporarily to retrieve the bytes from the - deflater and write them to the underlying output stream. - - - - - The deflater which is used to deflate the stream. - - - - - Base stream the deflater depends on. - - - - - Get/set flag indicating ownership of the underlying stream. - When the flag is true will close the underlying stream also. - - - - - Allows client to determine if an entry can be patched after its added - - - - - Get/set the password used for encryption. - - When set to null or if the password is empty no encryption is performed - - - - Gets value indicating stream can be read from - - - - - Gets a value indicating if seeking is supported for this stream - This property always returns false - - - - - Get value indicating if this stream supports writing - - - - - Get current length of stream - - - - - Gets the current position within the stream. - - Any attempt to set position - - - - Creates a new Zip output stream, writing a zip archive. - - - The output stream to which the archive contents are written. - - - - - Set the zip file comment. - - - The comment text for the entire archive. - - - The converted comment is longer than 0xffff bytes. - - - - - Sets the compression level. The new level will be activated - immediately. - - The new compression level (1 to 9). - - Level specified is not supported. - - - - - - Get the current deflater compression level - - The current compression level - - - - Write an unsigned short in little endian byte order. - - - - - Write an int in little endian byte order. - - - - - Write an int in little endian byte order. - - - - - Starts a new Zip entry. It automatically closes the previous - entry if present. - All entry elements bar name are optional, but must be correct if present. - If the compression method is stored and the output is not patchable - the compression for that entry is automatically changed to deflate level 0 - - - the entry. - - - if entry passed is null. - - - if an I/O error occured. - - - if stream was finished - - - Too many entries in the Zip file
- Entry name is too long
- Finish has already been called
-
-
- - - Closes the current entry, updating header and footer information as required - - - An I/O error occurs. - - - No entry is active. - - - - - Writes the given buffer to the current entry. - - The buffer containing data to write. - The offset of the first byte to write. - The number of bytes to write. - Archive size is invalid - No entry is active. - - - - Finishes the stream. This will write the central directory at the - end of the zip file and flush the stream. - - - This is automatically called when the stream is closed. - - - An I/O error occurs. - - - Comment exceeds the maximum length
- Entry name exceeds the maximum length -
-
- - - The entries for the archive. - - - - - Used to track the crc of data added to entries. - - - - - The current entry being added. - - - - - Used to track the size of data for an entry during writing. - - - - - Offset to be recorded for each entry in the central header. - - - - - Comment for the entire archive recorded in central header. - - - - - Flag indicating that header patching is required for the current entry. - - - - - Position to patch crc - - - - - Position to patch size. - - - - - Gets a flag value of true if the central header has been added for this archive; false if it has not been added. - - No further entries can be added once this has been done. - - - - Get / set a value indicating how Zip64 Extension usage is determined when adding entries. - - Older archivers may not understand Zip64 extensions. - If backwards compatability is an issue be careful when adding entries to an archive. - Setting this property to off is workable but less desirable as in those circumstances adding a file - larger then 4GB will fail. - - - - INameTransform defines how file system names are transformed for use with archives. - - - - - Given a file name determine the transformed value. - - The name to transform. - The transformed file name. - - - - Given a directory name determine the transformed value. - - The name to transform. - The transformed directory name - - - - This class contains constants used for deflation. - - - - - Set to true to enable debugging - - - - - Written to Zip file to identify a stored block - - - - - Identifies static tree in Zip file - - - - - Identifies dynamic tree in Zip file - - - - - Header flag indicating a preset dictionary for deflation - - - - - Sets internal buffer sizes for Huffman encoding - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - Internal compression engine constant - - - - - This class stores the pending output of the Deflater. - - author of the original java version : Jochen Hoenicke - - - - - Construct instance with default buffer size - - - - - PathFilter filters directories and files using a form of regular expressions - by full path name. - See NameFilter for more detail on filtering. - - - - - Initialise a new instance of . - - The filter expression to apply. - - - - Test a name to see if it matches the filter. - - The name to test. - True if the name matches, false otherwise. - - - - ExtendedPathFilter filters based on name, file size, and the last write time of the file. - - Provides an example of how to customise filtering. - - - - Initialise a new instance of ExtendedPathFilter. - - The filter to apply. - The minimum file size to include. - The maximum file size to include. - - - - Initialise a new instance of ExtendedPathFilter. - - The filter to apply. - The minimum to include. - The maximum to include. - - - - Initialise a new instance of ExtendedPathFilter. - - The filter to apply. - The minimum file size to include. - The maximum file size to include. - The minimum to include. - The maximum to include. - - - - Test a filename to see if it matches the filter. - - The filename to test. - True if the filter matches, false otherwise. - - - - Get/set the minimum size for a file that will match this filter. - - - - - Get/set the maximum size for a file that will match this filter. - - - - - Get/set the minimum value that will match for this filter. - - Files with a LastWrite time less than this value are excluded by the filter. - - - - Get/set the maximum value that will match for this filter. - - Files with a LastWrite time greater than this value are excluded by the filter. - - - - NameAndSizeFilter filters based on name and file size. - - A sample showing how filters might be extended. - - - - Initialise a new instance of NameAndSizeFilter. - - The filter to apply. - The minimum file size to include. - The maximum file size to include. - - - - Test a filename to see if it matches the filter. - - The filename to test. - True if the filter matches, false otherwise. - - - - Get/set the minimum size for a file that will match this filter. - - - - - Get/set the maximum size for a file that will match this filter. - - - - - BZip2Exception represents exceptions specific to Bzip2 algorithm - - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initialise a new instance of BZip2Exception. - - - - - Initialise a new instance of BZip2Exception with its message set to message. - - The message describing the error. - - - - Initialise an instance of BZip2Exception - - A message describing the error. - The exception that is the cause of the current exception. - - - - GZipException represents a Gzip specific exception - - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initialise a new instance of GZipException - - - - - Initialise a new instance of GZipException with its message string. - - A that describes the error. - - - - Initialise a new instance of . - - A that describes the error. - The that caused this exception. - - - - Contains the output from the Inflation process. - We need to have a window so that we can refer backwards into the output stream - to repeat stuff.
- Author of the original java version : John Leuner -
-
- - - Write a byte to this output window - - value to write - - if window is full - - - - - Append a byte pattern already in the window itself - - length of pattern to copy - distance from end of window pattern occurs - - If the repeated data overflows the window - - - - - Copy from input manipulator to internal window - - source of data - length of data to copy - the number of bytes copied - - - - Copy dictionary to window - - source dictionary - offset of start in source dictionary - length of dictionary - - If window isnt empty - - - - - Get remaining unfilled space in window - - Number of bytes left in window - - - - Get bytes available for output in window - - Number of bytes filled - - - - Copy contents of window to output - - buffer to copy to - offset to start at - number of bytes to count - The number of bytes copied - - If a window underflow occurs - - - - - Reset by clearing window so GetAvailable returns 0 - - - - - Defines internal values for both compression and decompression - - - - - When multiplied by compression parameter (1-9) gives the block size for compression - 9 gives the best compresssion but uses the most memory. - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Backend constant - - - - - Random numbers used to randomise repetitive blocks - - - - - This filter stream is used to compress a stream into a "GZIP" stream. - The "GZIP" format is described in RFC 1952. - - author of the original java version : John Leuner - - This sample shows how to gzip a file - - using System; - using System.IO; - - using ICSharpCode.SharpZipLib.GZip; - using ICSharpCode.SharpZipLib.Core; - - class MainClass - { - public static void Main(string[] args) - { - using (Stream s = new GZipOutputStream(File.Create(args[0] + ".gz"))) - using (FileStream fs = File.OpenRead(args[0])) { - byte[] writeData = new byte[4096]; - Streamutils.Copy(s, fs, writeData); - } - } - } - } - - - - - - CRC-32 value for uncompressed data - - - - - Creates a GzipOutputStream with the default buffer size - - - The stream to read data (to be compressed) from - - - - - Creates a GZipOutputStream with the specified buffer size - - - The stream to read data (to be compressed) from - - - Size of the buffer to use - - - - - Sets the active compression level (1-9). The new level will be activated - immediately. - - The compression level to set. - - Level specified is not supported. - - - - - - Get the current compression level. - - The current compression level. - - - - Write given buffer to output updating crc - - Buffer to write - Offset of first byte in buf to write - Number of bytes to write - - - - Writes remaining compressed output data to the output stream - and closes it. - - - - - Finish compression and write any footer information required to stream - - - - - Arguments used with KeysRequiredEvent - - - - - Initialise a new instance of - - The name of the file for which keys are required. - - - - Initialise a new instance of - - The name of the file for which keys are required. - The current key value. - - - - Get the name of the file for which keys are required. - - - - - Get/set the key value - - - - - The strategy to apply to testing. - - - - - Find the first error only. - - - - - Find all possible errors. - - - - - The operation in progress reported by a during testing. - - TestArchive - - - - Setting up testing. - - - - - Testing an individual entries header - - - - - Testing an individual entries data - - - - - Testing an individual entry has completed. - - - - - Running miscellaneous tests - - - - - Testing is complete - - - - - Status returned returned by during testing. - - TestArchive - - - - Initialise a new instance of - - The this status applies to. - - - - Get the current in progress. - - - - - Get the this status is applicable to. - - - - - Get the current/last entry tested. - - - - - Get the number of errors detected so far. - - - - - Get the number of bytes tested so far for the current entry. - - - - - Get a value indicating wether the last entry test was valid. - - - - - Delegate invoked during testing if supplied indicating current progress and status. - - If the message is non-null an error has occured. If the message is null - the operation as found in status has started. - - - - The possible ways of applying updates to an archive. - - - - - Perform all updates on temporary files ensuring that the original file is saved. - - - - - Update the archive directly, which is faster but less safe. - - - - - This class represents a Zip archive. You can ask for the contained - entries, or get an input stream for a file entry. The entry is - automatically decompressed. - - You can also update the archive adding or deleting entries. - - This class is thread safe for input: You can open input streams for arbitrary - entries in different threads. -
-
Author of the original java version : Jochen Hoenicke -
- - - using System; - using System.Text; - using System.Collections; - using System.IO; - - using ICSharpCode.SharpZipLib.Zip; - - class MainClass - { - static public void Main(string[] args) - { - using (ZipFile zFile = new ZipFile(args[0])) { - Console.WriteLine("Listing of : " + zFile.Name); - Console.WriteLine(""); - Console.WriteLine("Raw Size Size Date Time Name"); - Console.WriteLine("-------- -------- -------- ------ ---------"); - foreach (ZipEntry e in zFile) { - if ( e.IsFile ) { - DateTime d = e.DateTime; - Console.WriteLine("{0, -10}{1, -10}{2} {3} {4}", e.Size, e.CompressedSize, - d.ToString("dd-MM-yy"), d.ToString("HH:mm"), - e.Name); - } - } - } - } - } - - -
- - - Event handler for handling encryption keys. - - - - - Handles getting of encryption keys when required. - - The file for which encryption keys are required. - - - - Opens a Zip file with the given name for reading. - - The name of the file to open. - - An i/o error occurs - - - The file doesn't contain a valid zip archive. - - - - - Opens a Zip file reading the given . - - The to read archive data from. - - An i/o error occurs. - - - The file doesn't contain a valid zip archive. - - - - - Opens a Zip file reading the given . - - The to read archive data from. - - An i/o error occurs - - - The file doesn't contain a valid zip archive.
- The stream provided cannot seek -
-
- - - Initialises a default instance with no entries and no file storage. - - - - - Finalize this instance. - - - - - Closes the ZipFile. If the stream is owned then this also closes the underlying input stream. - Once closed, no further instance methods should be called. - - - An i/o error occurs. - - - - - Create a new whose data will be stored in a file. - - The name of the archive to create. - Returns the newly created - - - - Create a new whose data will be stored on a stream. - - The stream providing data storage. - Returns the newly created - - - - Gets an enumerator for the Zip entries in this Zip file. - - Returns an for this archive. - - The Zip file has been closed. - - - - - Return the index of the entry with a matching name - - Entry name to find - If true the comparison is case insensitive - The index position of the matching entry or -1 if not found - - The Zip file has been closed. - - - - - Searches for a zip entry in this archive with the given name. - String comparisons are case insensitive - - - The name to find. May contain directory components separated by slashes ('/'). - - - A clone of the zip entry, or null if no entry with that name exists. - - - The Zip file has been closed. - - - - - Gets an input stream for reading the given zip entry data in an uncompressed form. - Normally the should be an entry returned by GetEntry(). - - The to obtain a data for - An input containing data for this - - The ZipFile has already been closed - - - The compression method for the entry is unknown - - - The entry is not found in the ZipFile - - - - - Creates an input stream reading a zip entry - - The index of the entry to obtain an input stream for. - - An input containing data for this - - - The ZipFile has already been closed - - - The compression method for the entry is unknown - - - The entry is not found in the ZipFile - - - - - Test an archive for integrity/validity - - Perform low level data Crc check - true if all tests pass, false otherwise - Testing will terminate on the first error found. - - - - Test an archive for integrity/validity - - Perform low level data Crc check - The to apply. - The handler to call during testing. - true if all tests pass, false otherwise - - - - Test a local header against that provided from the central directory - - - The entry to test against - - The type of tests to carry out. - The offset of the entries data in the file - - - - Begin updating this archive. - - The archive storage for use during the update. - The data source to utilise during updating. - - - - Begin updating to this archive. - - The storage to use during the update. - - - - Begin updating this archive. - - - - - - - - Commit current updates, updating this archive. - - - - - - - Abort updating leaving the archive unchanged. - - - - - - - Set the file comment to be recorded when the current update is commited. - - The comment to record. - - - - Add a new entry to the archive. - - The name of the file to add. - The compression method to use. - Ensure Unicode text is used for name and comment for this entry. - - - - Add a new entry to the archive. - - The name of the file to add. - The compression method to use. - - - - Add a file to the archive. - - The name of the file to add. - - - - Add a file entry with data. - - The source of the data for this entry. - The name to give to the entry. - - - - Add a file entry with data. - - The source of the data for this entry. - The name to give to the entry. - The compression method to use. - - - - Add a file entry with data. - - The source of the data for this entry. - The name to give to the entry. - The compression method to use. - Ensure Unicode text is used for name and comments for this entry. - - - - Add a that contains no data. - - The entry to add. - This can be used to add directories, volume labels, or empty file entries. - - - - Add a directory entry to the archive. - - The directory to add. - - - - Delete an entry by name - - The filename to delete - True if the entry was found and deleted; false otherwise. - - - - Delete a from the archive. - - The entry to delete. - - - - Write an unsigned short in little endian byte order. - - - - - Write an int in little endian byte order. - - - - - Write an unsigned int in little endian byte order. - - - - - Write a long in little endian byte order. - - - - - Get a raw memory buffer. - - Returns a raw memory buffer. - - - - Get the size of the source descriptor for a . - - The update to get the size for. - The descriptor size, zero if there isnt one. - - - - Get an output stream for the specified - - The entry to get an output stream for. - The output stream obtained for the entry. - - - - Releases the unmanaged resources used by the this instance and optionally releases the managed resources. - - true to release both managed and unmanaged resources; - false to release only unmanaged resources. - - - - Read an unsigned short in little endian byte order. - - Returns the value read. - - The stream ends prematurely - - - - - Read a uint in little endian byte order. - - Returns the value read. - - An i/o error occurs. - - - The file ends prematurely - - - - - Search for and read the central directory of a zip file filling the entries array. - - - An i/o error occurs. - - - The central directory is malformed or cannot be found - - - - - Locate the data for a given entry. - - - The start offset of the data. - - - The stream ends prematurely - - - The local header signature is invalid, the entry and central header file name lengths are different - or the local and entry compression methods dont match - - - - - Get/set the encryption key value. - - - - - Password to be used for encrypting/decrypting files. - - Set to null if no password is required. - - - - Get a value indicating wether encryption keys are currently available. - - - - - Get/set a flag indicating if the underlying stream is owned by the ZipFile instance. - If the flag is true then the stream will be closed when Close is called. - - - The default value is true in all cases. - - - - - Get a value indicating wether - this archive is embedded in another file or not. - - - - - Get a value indicating that this archive is a new one. - - - - - Gets the comment for the zip file. - - - - - Gets the name of this zip file. - - - - - Gets the number of entries in this zip file. - - - The Zip file has been closed. - - - - - Get the number of entries contained in this . - - - - - Indexer property for ZipEntries - - - - - Get / set the to apply to names when updating. - - - - - Get/set the used to generate values - during updates. - - - - - Get /set the buffer size to be used when updating this zip file. - - - - - Get a value indicating an update has been started. - - - - - Get / set a value indicating how Zip64 Extension usage is determined when adding entries. - - - - - Delegate for handling keys/password setting during compresion/decompression. - - - - - The kind of update to apply. - - - - - Class used to sort updates. - - - - - Compares two objects and returns a value indicating whether one is - less than, equal to or greater than the other. - - First object to compare - Second object to compare. - Compare result. - - - - Represents a pending update to a Zip file. - - - - - Copy an existing entry. - - The existing entry to copy. - - - - Get the for this update. - - This is the source or original entry. - - - - Get the that will be written to the updated/new file. - - - - - Get the command for this update. - - - - - Get the filename if any for this update. Null if none exists. - - - - - Get/set the location of the size patch for this update. - - - - - Get /set the location of the crc patch for this update. - - - - - Represents a string from a which is stored as an array of bytes. - - - - - Initialise a with a string. - - The textual string form. - - - - Initialise a using a string in its binary 'raw' form. - - - - - - Reset the comment to its initial state. - - - - - Implicit conversion of comment to a string. - - The to convert to a string. - The textual equivalent for the input value. - - - - Get a value indicating the original source of data for this instance. - True if the source was a string; false if the source was binary data. - - - - - Get the length of the comment when represented as raw bytes. - - - - - Get the comment in its 'raw' form as plain bytes. - - - - - An enumerator for Zip entries - - - - - An is a stream that you can write uncompressed data - to and flush, but cannot read, seek or do anything else to. - - - - - Close this stream instance. - - - - - Write any buffered data to underlying storage. - - - - - Gets a value indicating whether the current stream supports reading. - - - - - Gets a value indicating whether the current stream supports writing. - - - - - Gets a value indicating whether the current stream supports seeking. - - - - - Get the length in bytes of the stream. - - - - - Gets or sets the position within the current stream. - - - - - A is an - whose data is only a part or subsection of a file. - - - - - This filter stream is used to decompress data compressed using the "deflate" - format. The "deflate" format is described in RFC 1951. - - This stream may form the basis for other decompression filters, such - as the GZipInputStream. - - Author of the original java version : John Leuner. - - - - - Create an InflaterInputStream with the default decompressor - and a default buffer size of 4KB. - - - The InputStream to read bytes from - - - - - Create an InflaterInputStream with the specified decompressor - and a default buffer size of 4KB. - - - The source of input data - - - The decompressor used to decompress data read from baseInputStream - - - - - Create an InflaterInputStream with the specified decompressor - and the specified buffer size. - - - The InputStream to read bytes from - - - The decompressor to use - - - Size of the buffer to use - - - - - Skip specified number of bytes of uncompressed data - - - Number of bytes to skip - - - The number of bytes skipped, zero if the end of - stream has been reached - - - Number of bytes to skip is less than zero - - - - - Clear any cryptographic state. - - - - - Fills the buffer with more data to decompress. - - - Stream ends early - - - - - Flushes the baseInputStream - - - - - Sets the position within the current stream - Always throws a NotSupportedException - - The relative offset to seek to. - The defining where to seek from. - The new position in the stream. - Any access - - - - Set the length of the current stream - Always throws a NotSupportedException - - The new length value for the stream. - Any access - - - - Writes a sequence of bytes to stream and advances the current position - This method always throws a NotSupportedException - - Thew buffer containing data to write. - The offset of the first byte to write. - The number of bytes to write. - Any access - - - - Writes one byte to the current stream and advances the current position - Always throws a NotSupportedException - - The byte to write. - Any access - - - - Entry point to begin an asynchronous write. Always throws a NotSupportedException. - - The buffer to write data from - Offset of first byte to write - The maximum number of bytes to write - The method to be called when the asynchronous write operation is completed - A user-provided object that distinguishes this particular asynchronous write request from other requests - An IAsyncResult that references the asynchronous write - Any access - - - - Closes the input stream. When - is true the underlying stream is also closed. - - - - - Reads decompressed data into the provided buffer byte array - - - The array to read and decompress data into - - - The offset indicating where the data should be placed - - - The number of bytes to decompress - - The number of bytes read. Zero signals the end of stream - - Inflater needs a dictionary - - - - - Decompressor for this stream - - - - - Input buffer for this stream. - - - - - Base stream the inflater reads from. - - - - - The compressed size - - - - - Flag indicating wether this instance has been closed or not. - - - - - Flag indicating wether this instance is designated the stream owner. - When closing if this flag is true the underlying stream is closed. - - - - - Get/set flag indicating ownership of underlying stream. - When the flag is true will close the underlying stream also. - - - The default value is true. - - - - - Returns 0 once the end of the stream (EOF) has been reached. - Otherwise returns 1. - - - - - Gets a value indicating whether the current stream supports reading - - - - - Gets a value of false indicating seeking is not supported for this stream. - - - - - Gets a value of false indicating that this stream is not writeable. - - - - - A value representing the length of the stream in bytes. - - - - - The current position within the stream. - Throws a NotSupportedException when attempting to set the position - - Attempting to set the position - - - - Initialise a new instance of the class. - - The underlying stream to use for IO. - The start of the partial data. - The length of the partial data. - - - - Skip the specified number of input bytes. - - The maximum number of input bytes to skip. - The actuial number of input bytes skipped. - - - - Read a byte from this stream. - - Returns the byte read or -1 on end of stream. - - - - Close this partial input stream. - - - The underlying stream is not closed. Close the parent ZipFile class to do that. - - - - - Provides a static way to obtain a source of data for an entry. - - - - - Get a source of data by creating a new stream. - - Returns a to use for compression input. - Ideally a new stream is created and opened to achieve this, to avoid locking problems. - - - - Represents a source of data that can dynamically provide - multiple data sources based on the parameters passed. - - - - - Get a data source. - - The to get a source for. - The name for data if known. - Returns a to use for compression input. - Ideally a new stream is created and opened to achieve this, to avoid locking problems. - - - - Default implementation of a for use with files stored on disk. - - - - - Initialise a new instnace of - - The name of the file to obtain data from. - - - - Get a providing data. - - Returns a provising data. - - - - Default implementation of for files stored on disk. - - - - - Initialise a default instance of . - - - - - Get a providing data for an entry. - - The entry to provide data for. - The file name for data if known. - Returns a stream providing data; or null if not available - - - - Defines facilities for data storage when updating Zip Archives. - - - - - Get an empty that can be used for temporary output. - - Returns a temporary output - - - - - Convert a temporary output stream to a final stream. - - The resulting final - - - - - Make a temporary copy of the original stream. - - The to copy. - Returns a temporary output that is a copy of the input. - - - - Return a stream suitable for performing direct updates on the original source. - - The current stream. - Returns a stream suitable for direct updating. - This may be the current stream passed. - - - - Dispose of this instance. - - - - - Get the to apply during updates. - - - - - An abstract suitable for extension by inheritance. - - - - - Initializes a new instance of the class. - - The update mode. - - - - Gets a temporary output - - Returns the temporary output stream. - - - - - Converts the temporary to its final form. - - Returns a that can be used to read - the final storage for the archive. - - - - - Make a temporary copy of a . - - The to make a copy of. - Returns a temporary output that is a copy of the input. - - - - Return a stream suitable for performing direct updates on the original source. - - The to open for direct update. - Returns a stream suitable for direct updating. - - - - Disposes this instance. - - - - - Gets the update mode applicable. - - The update mode. - - - - An implementation suitable for hard disks. - - - - - Initializes a new instance of the class. - - The file. - The update mode. - - - - Initializes a new instance of the class. - - The file. - - - - Gets a temporary output for performing updates on. - - Returns the temporary output stream. - - - - Converts a temporary to its final form. - - Returns a that can be used to read - the final storage for the archive. - - - - Make a temporary copy of a stream. - - The to copy. - Returns a temporary output that is a copy of the input. - - - - Return a stream suitable for performing direct updates on the original source. - - The current stream. - Returns a stream suitable for direct updating. - If the stream is not null this is used as is. - - - - Disposes this instance. - - - - - An implementation suitable for in memory streams. - - - - - Initializes a new instance of the class. - - - - - Initializes a new instance of the class. - - The to use - This constructor is for testing as memory streams dont really require safe mode. - - - - Gets the temporary output - - Returns the temporary output stream. - - - - Converts the temporary to its final form. - - Returns a that can be used to read - the final storage for the archive. - - - - Make a temporary copy of the original stream. - - The to copy. - Returns a temporary output that is a copy of the input. - - - - Return a stream suitable for performing direct updates on the original source. - - The original source stream - Returns a stream suitable for direct updating. - If the passed is not null this is used; - otherwise a new is returned. - - - - Disposes this instance. - - - - - Get the stream returned by if this was in fact called. - - - - - Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The table is simply the CRC of all possible eight bit values. This is all - the information needed to generate CRC's on data a byte at a time for all - combinations of CRC register values and incoming bytes. - - - - - Interface to compute a data checksum used by checked input/output streams. - A data checksum can be updated by one byte or with a byte array. After each - update the value of the current checksum can be returned by calling - getValue. The complete checksum object can also be reset - so it can be used again with new data. - - - - - Resets the data checksum as if no update was ever called. - - - - - Adds one byte to the data checksum. - - - the data value to add. The high byte of the int is ignored. - - - - - Updates the data checksum with the bytes taken from the array. - - - buffer an array of bytes - - - - - Adds the byte array to the data checksum. - - - The buffer which contains the data - - - The offset in the buffer where the data starts - - - the number of data bytes to add. - - - - - Returns the data checksum computed so far. - - - - - The crc data checksum so far. - - - - - Resets the CRC32 data checksum as if no update was ever called. - - - - - Updates the checksum with the int bval. - - - the byte is taken as the lower 8 bits of value - - - - - Updates the checksum with the bytes taken from the array. - - - buffer an array of bytes - - - - - Adds the byte array to the data checksum. - - - The buffer which contains the data - - - The offset in the buffer where the data starts - - - The number of data bytes to update the CRC with. - - - - - Returns the CRC32 data checksum computed so far. - - - - - Basic implementation of - - - - - Defines factory methods for creating new values. - - - - - Create a for a file given its name - - The name of the file to create an entry for. - Returns a file entry based on the passed. - - - - Create a for a file given its name - - The name of the file to create an entry for. - If true get details from the file system if the file exists. - Returns a file entry based on the passed. - - - - Create a for a directory given its name - - The name of the directory to create an entry for. - Returns a directory entry based on the passed. - - - - Create a for a directory given its name - - The name of the directory to create an entry for. - If true get details from the file system for this directory if it exists. - Returns a directory entry based on the passed. - - - - Get/set the applicable. - - - - - Initialise a new instance of the class. - - A default , and the LastWriteTime for files is used. - - - - Initialise a new instance of using the specified - - The time setting to use when creating Zip entries. - - - - Initialise a new instance of using the specified - - The time to set all values to. - - - - Make a new for a file. - - The name of the file to create a new entry for. - Returns a new based on the . - - - - Make a new from a name. - - The name of the file to create a new entry for. - If true entry detail is retrieved from the file system if the file exists. - Returns a new based on the . - - - - Make a new for a directory. - - The raw untransformed name for the new directory - Returns a new representing a directory. - - - - Make a new for a directory. - - The raw untransformed name for the new directory - If true entry detail is retrieved from the file system if the file exists. - Returns a new representing a directory. - - - - Get / set the to be used when creating new values. - - - Setting this property to null will cause a default name transform to be used. - - - - - Get / set the in use. - - - - - Get / set the value to use when is set to - - - - - A bitmask defining the attributes to be retrieved from the actual file. - - The default is to get all possible attributes from the actual file. - - - - A bitmask defining which attributes are to be set on. - - By default no attributes are set on. - - - - Get set a value indicating wether unidoce text should be set on. - - - - - Defines the possible values to be used for the . - - - - - Use the recorded LastWriteTime value for the file. - - - - - Use the recorded LastWriteTimeUtc value for the file - - - - - Use the recorded CreateTime value for the file. - - - - - Use the recorded CreateTimeUtc value for the file. - - - - - Use the recorded LastAccessTime value for the file. - - - - - Use the recorded LastAccessTimeUtc value for the file. - - - - - Use a fixed value. - - The actual value used can be - specified via the constructor or - using the with the setting set - to which will use the when this class was constructed. - The property can also be used to set this value. - - - - PkzipClassic embodies the classic or original encryption facilities used in Pkzip archives. - While it has been superceded by more recent and more powerful algorithms, its still in use and - is viable for preventing casual snooping - - - - - Generates new encryption keys based on given seed - - The seed value to initialise keys with. - A new key value. - - - - PkzipClassicCryptoBase provides the low level facilities for encryption - and decryption using the PkzipClassic algorithm. - - - - - Transform a single byte - - - The transformed value - - - - - Set the key schedule for encryption/decryption. - - The data use to set the keys from. - - - - Update encryption keys - - - - - Reset the internal state. - - - - - PkzipClassic CryptoTransform for encryption. - - - - - Initialise a new instance of - - The key block to use. - - - - Transforms the specified region of the specified byte array. - - The input for which to compute the transform. - The offset into the byte array from which to begin using data. - The number of bytes in the byte array to use as data. - The computed transform. - - - - Transforms the specified region of the input byte array and copies - the resulting transform to the specified region of the output byte array. - - The input for which to compute the transform. - The offset into the input byte array from which to begin using data. - The number of bytes in the input byte array to use as data. - The output to which to write the transform. - The offset into the output byte array from which to begin writing data. - The number of bytes written. - - - - Cleanup internal state. - - - - - Gets a value indicating whether the current transform can be reused. - - - - - Gets the size of the input data blocks in bytes. - - - - - Gets the size of the output data blocks in bytes. - - - - - Gets a value indicating whether multiple blocks can be transformed. - - - - - PkzipClassic CryptoTransform for decryption. - - - - - Initialise a new instance of . - - The key block to decrypt with. - - - - Transforms the specified region of the specified byte array. - - The input for which to compute the transform. - The offset into the byte array from which to begin using data. - The number of bytes in the byte array to use as data. - The computed transform. - - - - Transforms the specified region of the input byte array and copies - the resulting transform to the specified region of the output byte array. - - The input for which to compute the transform. - The offset into the input byte array from which to begin using data. - The number of bytes in the input byte array to use as data. - The output to which to write the transform. - The offset into the output byte array from which to begin writing data. - The number of bytes written. - - - - Cleanup internal state. - - - - - Gets a value indicating whether the current transform can be reused. - - - - - Gets the size of the input data blocks in bytes. - - - - - Gets the size of the output data blocks in bytes. - - - - - Gets a value indicating whether multiple blocks can be transformed. - - - - - Defines a wrapper object to access the Pkzip algorithm. - This class cannot be inherited. - - - - - Generate an initial vector. - - - - - Generate a new random key. - - - - - Create an encryptor. - - The key to use for this encryptor. - Initialisation vector for the new encryptor. - Returns a new PkzipClassic encryptor - - - - Create a decryptor. - - Keys to use for this new decryptor. - Initialisation vector for the new decryptor. - Returns a new decryptor. - - - - Get / set the applicable block size in bits. - - The only valid block size is 8. - - - - Get an array of legal key sizes. - - - - - Get an array of legal block sizes. - - - - - Get / set the key value applicable. - - - - - This class represents an entry in a Tar archive. It consists - of the entry's header, as well as the entry's File. Entries - can be instantiated in one of three ways, depending on how - they are to be used. -

- TarEntries that are created from the header bytes read from - an archive are instantiated with the TarEntry( byte[] ) - constructor. These entries will be used when extracting from - or listing the contents of an archive. These entries have their - header filled in using the header bytes. They also set the File - to null, since they reference an archive entry not a file.

-

- TarEntries that are created from files that are to be written - into an archive are instantiated with the CreateEntryFromFile(string) - pseudo constructor. These entries have their header filled in using - the File's information. They also keep a reference to the File - for convenience when writing entries.

-

- Finally, TarEntries can be constructed from nothing but a name. - This allows the programmer to construct the entry by hand, for - instance when only an InputStream is available for writing to - the archive, and the header information is constructed from - other information. In this case the header fields are set to - defaults and the File is set to null.

- -
-
- - - Initialise a default instance of . - - - - - Construct an entry from an archive's header bytes. File is set - to null. - - - The header bytes from a tar archive entry. - - - - - Construct a TarEntry using the header provided - - Header details for entry - - - - Clone this tar entry. - - Returns a clone of this entry. - - - - Construct an entry with only a name. - This allows the programmer to construct the entry's header "by hand". - - The name to use for the entry - Returns the newly created - - - - Construct an entry for a file. File is set to file, and the - header is constructed from information from the file. - - The file name that the entry represents. - Returns the newly created - - - - Determine if the two entries are equal. Equality is determined - by the header names being equal. - - The to compare with the current Object. - - True if the entries are equal; false if not. - - - - - Derive a Hash value for the current - - A Hash code for the current - - - - Determine if the given entry is a descendant of this entry. - Descendancy is determined by the name of the descendant - starting with this entry's name. - - - Entry to be checked as a descendent of this. - - - True if entry is a descendant of this. - - - - - Convenience method to set this entry's group and user ids. - - - This entry's new user id. - - - This entry's new group id. - - - - - Convenience method to set this entry's group and user names. - - - This entry's new user name. - - - This entry's new group name. - - - - - Fill in a TarHeader with information from a File. - - - The TarHeader to fill in. - - - The file from which to get the header information. - - - - - Get entries for all files present in this entries directory. - If this entry doesnt represent a directory zero entries are returned. - - - An array of TarEntry's for this entry's children. - - - - - Write an entry's header information to a header buffer. - - - The tar entry header buffer to fill in. - - - - - Convenience method that will modify an entry's name directly - in place in an entry header buffer byte array. - - - The buffer containing the entry header to modify. - - - The new name to place into the header buffer. - - - - - Fill in a TarHeader given only the entry's name. - - - The TarHeader to fill in. - - - The tar entry name. - - - - - The name of the file this entry represents or null if the entry is not based on a file. - - - - - The entry's header information. - - - - - Get this entry's header. - - - This entry's TarHeader. - - - - - Get/Set this entry's name. - - - - - Get/set this entry's user id. - - - - - Get/set this entry's group id. - - - - - Get/set this entry's user name. - - - - - Get/set this entry's group name. - - - - - Get/Set the modification time for this entry - - - - - Get this entry's file. - - - This entry's file. - - - - - Get/set this entry's recorded file size. - - - - - Return true if this entry represents a directory, false otherwise - - - True if this entry is a directory. - - - - - This filter stream is used to decompress a "GZIP" format stream. - The "GZIP" format is described baseInputStream RFC 1952. - - author of the original java version : John Leuner - - This sample shows how to unzip a gzipped file - - using System; - using System.IO; - - using ICSharpCode.SharpZipLib.Core; - using ICSharpCode.SharpZipLib.GZip; - - class MainClass - { - public static void Main(string[] args) - { - using (Stream inStream = new GZipInputStream(File.OpenRead(args[0]))) - using (FileStream outStream = File.Create(Path.GetFileNameWithoutExtension(args[0]))) { - byte[] buffer = new byte[4096]; - StreamUtils.Copy(inStream, outStream, buffer); - } - } - } - - - - - - CRC-32 value for uncompressed data - - - - - Indicates end of stream - - - - - Creates a GZipInputStream with the default buffer size - - - The stream to read compressed data from (baseInputStream GZIP format) - - - - - Creates a GZIPInputStream with the specified buffer size - - - The stream to read compressed data from (baseInputStream GZIP format) - - - Size of the buffer to use - - - - - Reads uncompressed data into an array of bytes - - - The buffer to read uncompressed data into - - - The offset indicating where the data should be placed - - - The number of uncompressed bytes to be read - - Returns the number of bytes actually read. - - - - Provides simple " utilities. - - - - - Read from a ensuring all the required data is read. - - The stream to read. - The buffer to fill. - - - - Read from a " ensuring all the required data is read. - - The stream to read data from. - The buffer to store data in. - The offset at which to begin storing data. - The number of bytes of data to store. - - - - Copy the contents of one to another. - - The stream to source data from. - The stream to write data to. - The buffer to use during copying. - The progress handler delegate to use. - The minimum between progress updates. - The source for this event. - The name to use with the event. - - - - Copy the contents of one to another. - - The stream to source data from. - The stream to write data to. - The buffer to use during copying. - - - - Initialise an instance of - - - - - This is the DeflaterHuffman class. - - This class is not thread safe. This is inherent in the API, due - to the split of Deflate and SetInput. - - author of the original java version : Jochen Hoenicke - - - - - Pending buffer to use - - - - - Construct instance with pending buffer - - Pending buffer to use - - - - Reset internal state - - - - - Write all trees to pending buffer - - The number/rank of treecodes to send. - - - - Compress current buffer writing data to pending buffer - - - - - Flush block to output with no compression - - Data to write - Index of first byte to write - Count of bytes to write - True if this is the last block - - - - Flush block to output with compression - - Data to flush - Index of first byte to flush - Count of bytes to flush - True if this is the last block - - - - Get value indicating if internal buffer is full - - true if buffer is full - - - - Add literal to buffer - - Literal value to add to buffer. - Value indicating internal buffer is full - - - - Add distance code and length to literal and distance trees - - Distance code - Length - Value indicating if internal buffer is full - - - - Reverse the bits of a 16 bit value. - - Value to reverse bits - Value with bits reversed - - - - Resets the internal state of the tree - - - - - Check that all frequencies are zero - - - At least one frequency is non-zero - - - - - Set static codes and length - - new codes - length for new codes - - - - Build dynamic codes and lengths - - - - - Get encoded length - - Encoded length, the sum of frequencies * lengths - - - - Scan a literal or distance tree to determine the frequencies of the codes - in the bit length tree. - - - - - Write tree values - - Tree to write - - - - This class contains constants used for gzip. - - - - - Magic number found at start of GZIP header - - - - - Flag bit mask for text - - - - - Flag bitmask for Crc - - - - - Flag bit mask for extra - - - - - flag bitmask for name - - - - - flag bit mask indicating comment is present - - - - - Initialise default instance. - - Constructor is private to prevent instances being created. - - - - TarExceptions are used for exceptions specific to tar classes and code. - - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initialises a new instance of the TarException class. - - - - - Initialises a new instance of the TarException class with a specified message. - - The message that describes the error. - - - - - - A message describing the error. - The exception that is the cause of the current exception. - - - - Bzip2 checksum algorithm - - - - - Initialise a default instance of - - - - - Reset the state of Crc. - - - - - Update the Crc value. - - data update is based on - - - - Update Crc based on a block of data - - The buffer containing data to update the crc with. - - - - Update Crc based on a portion of a block of data - - block of data - index of first byte to use - number of bytes to use - - - - Get the current Crc value. - - - - - This is an InflaterInputStream that reads the files baseInputStream an zip archive - one after another. It has a special method to get the zip entry of - the next file. The zip entry contains information about the file name - size, compressed size, Crc, etc. - It includes support for Stored and Deflated entries. -
-
Author of the original java version : Jochen Hoenicke -
- - This sample shows how to read a zip file - - using System; - using System.Text; - using System.IO; - - using ICSharpCode.SharpZipLib.Zip; - - class MainClass - { - public static void Main(string[] args) - { - using ( ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]))) { - - ZipEntry theEntry; - while ((theEntry = s.GetNextEntry()) != null) { - int size = 2048; - byte[] data = new byte[2048]; - - Console.Write("Show contents (y/n) ?"); - if (Console.ReadLine() == "y") { - while (true) { - size = s.Read(data, 0, data.Length); - if (size > 0) { - Console.Write(new ASCIIEncoding().GetString(data, 0, size)); - } else { - break; - } - } - } - } - } - } - } - - -
- - - The current reader this instance. - - - - - Creates a new Zip input stream, for reading a zip archive. - - The underlying providing data. - - - - Advances to the next entry in the archive - - - The next entry in the archive or null if there are no more entries. - - - If the previous entry is still open CloseEntry is called. - - - Input stream is closed - - - Password is not set, password is invalid, compression method is invalid, - version required to extract is not supported - - - - - Read data descriptor at the end of compressed data. - - - - - Complete cleanup as the final part of closing. - - True if the crc value should be tested - - - - Closes the current zip entry and moves to the next one. - - - The stream is closed - - - The Zip stream ends early - - - - - Reads a byte from the current zip entry. - - - The byte or -1 if end of stream is reached. - - - - - Handle attempts to read by throwing an . - - The destination array to store data in. - The offset at which data read should be stored. - The maximum number of bytes to read. - Returns the number of bytes actually read. - - - - Handle attempts to read from this entry by throwing an exception - - - - - Perform the initial read on an entry which may include - reading encryption headers and setting up inflation. - - The destination to fill with data read. - The offset to start reading at. - The maximum number of bytes to read. - The actual number of bytes read. - - - - Read a block of bytes from the stream. - - The destination for the bytes. - The index to start storing data. - The number of bytes to attempt to read. - Returns the number of bytes read. - Zero bytes read means end of stream. - - - - Reads a block of bytes from the current zip entry. - - - The number of bytes read (this may be less than the length requested, even before the end of stream), or 0 on end of stream. - - - An i/o error occured. - - - The deflated stream is corrupted. - - - The stream is not open. - - - - - Closes the zip input stream - - - - - Optional password used for encryption when non-null - - A password for all encrypted entries in this - - - - Gets a value indicating if there is a current entry and it can be decompressed - - - The entry can only be decompressed if the library supports the zip features required to extract it. - See the ZipEntry Version property for more details. - - - - - Returns 1 if there is an entry available - Otherwise returns 0. - - - - - Returns the current size that can be read from the current entry if available - - Thrown if the entry size is not known. - Thrown if no entry is currently available. - - - - ZipNameTransform transforms names as per the Zip file naming convention. - - The use of absolute names is supported although its use is not valid - according to Zip naming conventions, and should not be used if maximum compatability is desired. - - - - Initialize a new instance of - - - - - Initialize a new instance of - - The string to trim from front of paths if found. - - - - Static constructor. - - - - - Transform a directory name according to the Zip file naming conventions. - - The directory name to transform. - The transformed name. - - - - Transform a windows file name according to the Zip file naming conventions. - - The file name to transform. - The transformed name. - - - - Force a name to be valid by replacing invalid characters with a fixed value - - The name to force valid - The replacement character to use. - Returns a valid name - - - - Test a name to see if it is a valid name for a zip entry. - - The name to test. - If true checking is relaxed about windows file names and absolute paths. - Returns true if the name is a valid zip name; false otherwise. - Zip path names are actually in Unix format, and should only contain relative paths. - This means that any path stored should not contain a drive or - device letter, or a leading slash. All slashes should forward slashes '/'. - An empty name is valid for a file where the input comes from standard input. - A null name is not considered valid. - - - - - Test a name to see if it is a valid name for a zip entry. - - The name to test. - Returns true if the name is a valid zip name; false otherwise. - Zip path names are actually in unix format, - and should only contain relative paths if a path is present. - This means that the path stored should not contain a drive or - device letter, or a leading slash. All slashes should forward slashes '/'. - An empty name is valid where the input comes from standard input. - A null name is not considered valid. - - - - - Get/set the path prefix to be trimmed from paths if present. - - The prefix is trimmed before any conversion from - a windows path is done. - - - - This exception is used to indicate that there is a problem - with a TAR archive header. - - - - - Deserialization constructor - - for this constructor - for this constructor - - - - Initialise a new instance of the InvalidHeaderException class. - - - - - Initialises a new instance of the InvalidHeaderException class with a specified message. - - Message describing the exception cause. - - - - Initialise a new instance of InvalidHeaderException - - Message describing the problem. - The exception that is the cause of the current exception. - - - - This class allows us to retrieve a specified number of bits from - the input buffer, as well as copy big byte blocks. - - It uses an int buffer to store up to 31 bits for direct - manipulation. This guarantees that we can get at least 16 bits, - but we only need at most 15, so this is all safe. - - There are some optimizations in this class, for example, you must - never peek more than 8 bits more than needed, and you must first - peek bits before you may drop them. This is not a general purpose - class but optimized for the behaviour of the Inflater. - - authors of the original java version : John Leuner, Jochen Hoenicke - - - - - Constructs a default StreamManipulator with all buffers empty - - - - - Get the next sequence of bits but don't increase input pointer. bitCount must be - less or equal 16 and if this call succeeds, you must drop - at least n - 8 bits in the next call. - - The number of bits to peek. - - the value of the bits, or -1 if not enough bits available. */ - - - - - Drops the next n bits from the input. You should have called PeekBits - with a bigger or equal n before, to make sure that enough bits are in - the bit buffer. - - The number of bits to drop. - - - - Gets the next n bits and increases input pointer. This is equivalent - to followed by , except for correct error handling. - - The number of bits to retrieve. - - the value of the bits, or -1 if not enough bits available. - - - - - Skips to the next byte boundary. - - - - - Copies bytes from input buffer to output buffer starting - at output[offset]. You have to make sure, that the buffer is - byte aligned. If not enough bytes are available, copies fewer - bytes. - - - The buffer to copy bytes to. - - - The offset in the buffer at which copying starts - - - The length to copy, 0 is allowed. - - - The number of bytes copied, 0 if no bytes were available. - - - Length is less than zero - - - Bit buffer isnt byte aligned - - - - - Resets state and empties internal buffers - - - - - Add more input for consumption. - Only call when IsNeedingInput returns true - - data to be input - offset of first byte of input - number of bytes of input to add. - - - - Gets the number of bits available in the bit buffer. This must be - only called when a previous PeekBits() returned -1. - - - the number of bits available. - - - - - Gets the number of bytes available. - - - The number of bytes available. - - - - - Returns true when SetInput can be called - - - - - Strategies for deflater - - - - - The default strategy - - - - - This strategy will only allow longer string repetitions. It is - useful for random data with a small character set. - - - - - This strategy will not look for string repetitions at all. It - only encodes with Huffman trees (which means, that more common - characters get a smaller encoding. - - - - - Low level compression engine for deflate algorithm which uses a 32K sliding window - with secondary compression from Huffman/Shannon-Fano codes. - - - - - Construct instance with pending buffer - - - Pending buffer to use - > - - - - Deflate drives actual compression of data - - True to flush input buffers - Finish deflation with the current input. - Returns true if progress has been made. - - - - Sets input data to be deflated. Should only be called when NeedsInput() - returns true - - The buffer containing input data. - The offset of the first byte of data. - The number of bytes of data to use as input. - - - - Determines if more input is needed. - - Return true if input is needed via SetInput - - - - Set compression dictionary - - The buffer containing the dictionary data - The offset in the buffer for the first byte of data - The length of the dictionary data. - - - - Reset internal state - - - - - Reset Adler checksum - - - - - Set the deflate level (0-9) - - The value to set the level to. - - - - Fill the window - - - - - Inserts the current string in the head hash and returns the previous - value for this hash. - - The previous hash value - - - - Find the best (longest) string in the window matching the - string starting at strstart. - - Preconditions: - - strstart + MAX_MATCH <= window.length. - - - True if a match greater than the minimum length is found - - - - Hashtable, hashing three characters to an index for window, so - that window[index]..window[index+2] have this hash code. - Note that the array should really be unsigned short, so you need - to and the values with 0xffff. - - - - - prev[index & WMASK] points to the previous index that has the - same hash code as the string starting at index. This way - entries with the same hash code are in a linked list. - Note that the array should really be unsigned short, so you need - to and the values with 0xffff. - - - - - Points to the current character in the window. - - - - - lookahead is the number of characters starting at strstart in - window that are valid. - So window[strstart] until window[strstart+lookahead-1] are valid - characters. - - - - - This array contains the part of the uncompressed stream that - is of relevance. The current character is indexed by strstart. - - - - - The current compression function. - - - - - The input data for compression. - - - - - The total bytes of input read. - - - - - The offset into inputBuf, where input data starts. - - - - - The end offset of the input data. - - - - - The adler checksum - - - - - Get current value of Adler checksum - - - - - Total data processed - - - - - Get/set the deflate strategy - - - - - The TarBuffer class implements the tar archive concept - of a buffered input stream. This concept goes back to the - days of blocked tape drives and special io devices. In the - C# universe, the only real function that this class - performs is to ensure that files have the correct "record" - size, or other tars will complain. -

- You should never have a need to access this class directly. - TarBuffers are created by Tar IO Streams. -

-
-
- - - The size of a block in a tar archive in bytes. - - This is 512 bytes. - - - - The number of blocks in a default record. - - - The default value is 20 blocks per record. - - - - - The size in bytes of a default record. - - - The default size is 10KB. - - - - - Get the TAR Buffer's record size. - - The record size in bytes. - This is equal to the multiplied by the - - - - Get the TAR Buffer's block factor - - The block factor; the number of blocks per record. - - - - Construct a default TarBuffer - - - - - Create TarBuffer for reading with default BlockFactor - - Stream to buffer - A new suitable for input. - - - - Construct TarBuffer for reading inputStream setting BlockFactor - - Stream to buffer - Blocking factor to apply - A new suitable for input. - - - - Construct TarBuffer for writing with default BlockFactor - - output stream for buffer - A new suitable for output. - - - - Construct TarBuffer for writing Tar output to streams. - - Output stream to write to. - Blocking factor to apply - A new suitable for output. - - - - Initialization common to all constructors. - - - - - Determine if an archive block indicates End of Archive. End of - archive is indicated by a block that consists entirely of null bytes. - All remaining blocks for the record should also be null's - However some older tars only do a couple of null blocks (Old GNU tar for one) - and also partial records - - The data block to check. - Returns true if the block is an EOF block; false otherwise. - - - - Skip over a block on the input stream. - - - - - Read a block from the input stream. - - - The block of data read. - - - - - Read a record from data stream. - - - false if End-Of-File, else true. - - - - - Get the current block number, within the current record, zero based. - - - The current zero based block number. - - - The absolute block number = (record number * block factor) + block number. - - - - - Get the current record number. - - - The current zero based record number. - - - - - Write a block of data to the archive. - - - The data to write to the archive. - - - - - Write an archive record to the archive, where the record may be - inside of a larger array buffer. The buffer must be "offset plus - record size" long. - - - The buffer containing the record data to write. - - - The offset of the record data within buffer. - - - - - Write a TarBuffer record to the archive. - - - - - Flush the current record if it has any data in it. - - - - - Close the TarBuffer. If this is an output buffer, also flush the - current block before closing. - - - - - Get the record size for this buffer - - The record size in bytes. - This is equal to the multiplied by the - - - - Get the Blocking factor for the buffer - - This is the number of block in each record. - - - - Get the current block number, within the current record, zero based. - - - - - Get the current record number. - - - The current zero based record number. - - - - - This class encapsulates the Tar Entry Header used in Tar Archives. - The class also holds a number of tar constants, used mostly in headers. - - - - - The length of the name field in a header buffer. - - - - - The length of the mode field in a header buffer. - - - - - The length of the user id field in a header buffer. - - - - - The length of the group id field in a header buffer. - - - - - The length of the checksum field in a header buffer. - - - - - Offset of checksum in a header buffer. - - - - - The length of the size field in a header buffer. - - - - - The length of the magic field in a header buffer. - - - - - The length of the version field in a header buffer. - - - - - The length of the modification time field in a header buffer. - - - - - The length of the user name field in a header buffer. - - - - - The length of the group name field in a header buffer. - - - - - The length of the devices field in a header buffer. - - - - - The "old way" of indicating a normal file. - - - - - Normal file type. - - - - - Link file type. - - - - - Symbolic link file type. - - - - - Character device file type. - - - - - Block device file type. - - - - - Directory file type. - - - - - FIFO (pipe) file type. - - - - - Contiguous file type. - - - - - Posix.1 2001 global extended header - - - - - Posix.1 2001 extended header - - - - - Solaris access control list file type - - - - - GNU dir dump file type - This is a dir entry that contains the names of files that were in the - dir at the time the dump was made - - - - - Solaris Extended Attribute File - - - - - Inode (metadata only) no file content - - - - - Identifies the next file on the tape as having a long link name - - - - - Identifies the next file on the tape as having a long name - - - - - Continuation of a file that began on another volume - - - - - For storing filenames that dont fit in the main header (old GNU) - - - - - GNU Sparse file - - - - - GNU Tape/volume header ignore on extraction - - - - - The magic tag representing a POSIX tar archive. (includes trailing NULL) - - - - - The magic tag representing an old GNU tar archive where version is included in magic and overwrites it - - - - - Initialise a default TarHeader instance - - - - - Get the name of this entry. - - The entry's name. - - - - Create a new that is a copy of the current instance. - - A new that is a copy of the current instance. - - - - Parse TarHeader information from a header buffer. - - - The tar entry header buffer to get information from. - - - - - 'Write' header information to buffer provided, updating the check sum. - - output buffer for header information - - - - Get a hash code for the current object. - - A hash code for the current object. - - - - Determines if this instance is equal to the specified object. - - The object to compare with. - true if the objects are equal, false otherwise. - - - - Set defaults for values used when constructing a TarHeader instance. - - Value to apply as a default for userId. - Value to apply as a default for userName. - Value to apply as a default for groupId. - Value to apply as a default for groupName. - - - - Parse an octal string from a header buffer. - - The header buffer from which to parse. - The offset into the buffer from which to parse. - The number of header bytes to parse. - The long equivalent of the octal string. - - - - Parse a name from a header buffer. - - - The header buffer from which to parse. - - - The offset into the buffer from which to parse. - - - The number of header bytes to parse. - - - The name parsed. - - - - - Add name to the buffer as a collection of bytes - - The name to add - The offset of the first character - The buffer to add to - The index of the first byte to add - The number of characters/bytes to add - The next free index in the buffer - - - - Add name to the buffer as a collection of bytes - - The name to add - The offset of the first character - The buffer to add to - The index of the first byte to add - The number of characters/bytes to add - The next free index in the buffer - - - - Add an entry name to the buffer - - - The name to add - - - The buffer to add to - - - The offset into the buffer from which to start adding - - - The number of header bytes to add - - - The index of the next free byte in the buffer - - - - - Add an entry name to the buffer - - The name to add - The buffer to add to - The offset into the buffer from which to start adding - The number of header bytes to add - The index of the next free byte in the buffer - - - - Add a string to a buffer as a collection of ascii bytes. - - The string to add - The offset of the first character to add. - The buffer to add to. - The offset to start adding at. - The number of ascii characters to add. - The next free index in the buffer. - - - - Put an octal representation of a value into a buffer - - - the value to be converted to octal - - - buffer to store the octal string - - - The offset into the buffer where the value starts - - - The length of the octal string to create - - - The offset of the character next byte after the octal string - - - - - Put an octal representation of a value into a buffer - - Value to be convert to octal - The buffer to update - The offset into the buffer to store the value - The length of the octal string - Index of next byte - - - - Add the checksum integer to header buffer. - - - The header buffer to set the checksum for - The offset into the buffer for the checksum - The number of header bytes to update. - It's formatted differently from the other fields: it has 6 digits, a - null, then a space -- rather than digits, a space, then a null. - The final space is already there, from checksumming - - The modified buffer offset - - - - Compute the checksum for a tar entry header. - The checksum field must be all spaces prior to this happening - - The tar entry's header buffer. - The computed checksum. - - - - Make a checksum for a tar entry ignoring the checksum contents. - - The tar entry's header buffer. - The checksum for the buffer - - - - Get/set the name for this tar entry. - - Thrown when attempting to set the property to null. - - - - Get/set the entry's Unix style permission mode. - - - - - The entry's user id. - - - This is only directly relevant to unix systems. - The default is zero. - - - - - Get/set the entry's group id. - - - This is only directly relevant to linux/unix systems. - The default value is zero. - - - - - Get/set the entry's size. - - Thrown when setting the size to less than zero. - - - - Get/set the entry's modification time. - - - The modification time is only accurate to within a second. - - Thrown when setting the date time to less than 1/1/1970. - - - - Get the entry's checksum. This is only valid/updated after writing or reading an entry. - - - - - Get value of true if the header checksum is valid, false otherwise. - - - - - Get/set the entry's type flag. - - - - - The entry's link name. - - Thrown when attempting to set LinkName to null. - - - - Get/set the entry's magic tag. - - Thrown when attempting to set Magic to null. - - - - The entry's version. - - Thrown when attempting to set Version to null. - - - - The entry's user name. - - - - - Get/set the entry's group name. - - - This is only directly relevant to unix systems. - - - - - Get/set the entry's major device number. - - - - - Get/set the entry's minor device number. - - - - - Event arguments for scanning. - - - - - Initialise a new instance of - - The file or directory name. - - - - The fie or directory name for this event. - - - - - Get set a value indicating if scanning should continue or not. - - - - - Event arguments during processing of a single file or directory. - - - - - Initialise a new instance of - - The file or directory name if known. - The number of bytes processed so far - The total number of bytes to process, 0 if not known - - - - The name for this event if known. - - - - - Get set a value indicating wether scanning should continue or not. - - - - - Get a percentage representing how much of the has been processed - - 0.0 to 100.0 percent; 0 if target is not known. - - - - The number of bytes processed so far - - - - - The number of bytes to process. - - Target may be 0 or negative if the value isnt known. - - - - Event arguments for directories. - - - - - Initialize an instance of . - - The name for this directory. - Flag value indicating if any matching files are contained in this directory. - - - - Get a value indicating if the directory contains any matching files or not. - - - - - Arguments passed when scan failures are detected. - - - - - Initialise a new instance of - - The name to apply. - The exception to use. - - - - The applicable name. - - - - - The applicable exception. - - - - - Get / set a value indicating wether scanning should continue. - - - - - Delegate invoked before starting to process a directory. - - - - - Delegate invoked before starting to process a file. - - The source of the event - The event arguments. - - - - Delegate invoked during processing of a file or directory - - The source of the event - The event arguments. - - - - Delegate invoked when a file has been completely processed. - - The source of the event - The event arguments. - - - - Delegate invoked when a directory failure is detected. - - The source of the event - The event arguments. - - - - Delegate invoked when a file failure is detected. - - The source of the event - The event arguments. - - - - FileSystemScanner provides facilities scanning of files and directories. - - - - - Initialise a new instance of - - The file filter to apply when scanning. - - - - Initialise a new instance of - - The file filter to apply. - The directory filter to apply. - - - - Initialise a new instance of - - The file filter to apply. - - - - Initialise a new instance of - - The file filter to apply. - The directory filter to apply. - - - - Delegate to invoke when a directory is processed. - - - - - Delegate to invoke when a file is processed. - - - - - Delegate to invoke when processing for a file has finished. - - - - - Delegate to invoke when a directory failure is detected. - - - - - Delegate to invoke when a file failure is detected. - - - - - Raise the DirectoryFailure event. - - The directory name. - The exception detected. - - - - Raise the FileFailure event. - - The file name. - The exception detected. - - - - Raise the ProcessFile event. - - The file name. - - - - Raise the complete file event - - The file name - - - - Raise the ProcessDirectory event. - - The directory name. - Flag indicating if the directory has matching files. - - - - Scan a directory. - - The base directory to scan. - True to recurse subdirectories, false to scan a single directory. - - - - The file filter currently in use. - - - - - The directory filter currently in use. - - - - - Flag indicating if scanning should continue running. - - - - - An input buffer customised for use by - - - The buffer supports decryption of incoming data. - - - - - Initialise a new instance of with a default buffer size - - The stream to buffer. - - - - Initialise a new instance of - - The stream to buffer. - The size to use for the buffer - A minimum buffer size of 1KB is permitted. Lower sizes are treated as 1KB. - - - - Call passing the current clear text buffer contents. - - The inflater to set input for. - - - - Fill the buffer from the underlying input stream. - - - - - Read a buffer directly from the input stream - - The buffer to fill - Returns the number of bytes read. - - - - Read a buffer directly from the input stream - - The buffer to read into - The offset to start reading data into. - The number of bytes to read. - Returns the number of bytes read. - - - - Read clear text data from the input stream. - - The buffer to add data to. - The offset to start adding data at. - The number of bytes to read. - Returns the number of bytes actually read. - - - - Read a from the input stream. - - Returns the byte read. - - - - Read an in little endian byte order. - - The short value read case to an int. - - - - Read an in little endian byte order. - - The int value read. - - - - Read a in little endian byte order. - - The long value read. - - - - Get the length of bytes bytes in the - - - - - Get the contents of the raw data buffer. - - This may contain encrypted data. - - - - Get the number of useable bytes in - - - - - Get the contents of the clear text buffer. - - - - - Get/set the number of bytes available - - - - - Get/set the to apply to any data. - - Set this value to null to have no transform applied. - - - - The TarOutputStream writes a UNIX tar archive as an OutputStream. - Methods are provided to put entries, and then write their contents - by writing to this stream using write(). - - public - - - - Construct TarOutputStream using default block factor - - stream to write to - - - - Construct TarOutputStream with user specified block factor - - stream to write to - blocking factor - - - - set the position within the current stream - - The offset relative to the to seek to - The to seek from. - The new position in the stream. - - - - Set the length of the current stream - - The new stream length. - - - - Read a byte from the stream and advance the position within the stream - by one byte or returns -1 if at the end of the stream. - - The byte value or -1 if at end of stream - - - - read bytes from the current stream and advance the position within the - stream by the number of bytes read. - - The buffer to store read bytes in. - The index into the buffer to being storing bytes at. - The desired number of bytes to read. - The total number of bytes read, or zero if at the end of the stream. - The number of bytes may be less than the count - requested if data is not avialable. - - - - All buffered data is written to destination - - - - - Ends the TAR archive without closing the underlying OutputStream. - The result is that the EOF block of nulls is written. - - - - - Ends the TAR archive and closes the underlying OutputStream. - - This means that Finish() is called followed by calling the - TarBuffer's Close(). - - - - Get the record size being used by this stream's TarBuffer. - - - The TarBuffer record size. - - - - - Put an entry on the output stream. This writes the entry's - header and positions the output stream for writing - the contents of the entry. Once this method is called, the - stream is ready for calls to write() to write the entry's - contents. Once the contents are written, closeEntry() - MUST be called to ensure that all buffered data - is completely written to the output stream. - - - The TarEntry to be written to the archive. - - - - - Close an entry. This method MUST be called for all file - entries that contain data. The reason is that we must - buffer data written to the stream in order to satisfy - the buffer's block based writes. Thus, there may be - data fragments still being assembled that must be written - to the output stream before this entry is closed and the - next entry written. - - - - - Writes a byte to the current tar archive entry. - This method simply calls Write(byte[], int, int). - - - The byte to be written. - - - - - Writes bytes to the current tar archive entry. This method - is aware of the current entry and will throw an exception if - you attempt to write bytes past the length specified for the - current entry. The method is also (painfully) aware of the - record buffering required by TarBuffer, and manages buffers - that are not a multiple of recordsize in length, including - assembling records from small buffers. - - - The buffer to write to the archive. - - - The offset in the buffer from which to get bytes. - - - The number of bytes to write. - - - - - Write an EOF (end of archive) block to the tar archive. - An EOF block consists of all zeros. - - - - - bytes written for this entry so far - - - - - current 'Assembly' buffer length - - - - - Flag indicating wether this instance has been closed or not. - - - - - Size for the current entry - - - - - single block working buffer - - - - - 'Assembly' buffer used to assemble data before writing - - - - - TarBuffer used to provide correct blocking factor - - - - - the destination stream for the archive contents - - - - - true if the stream supports reading; otherwise, false. - - - - - true if the stream supports seeking; otherwise, false. - - - - - true if stream supports writing; otherwise, false. - - - - - length of stream in bytes - - - - - gets or sets the position within the current stream. - - - - - Get the record size being used by this stream's TarBuffer. - - - - - Get a value indicating wether an entry is open, requiring more data to be written. - - - - - This is the Deflater class. The deflater class compresses input - with the deflate algorithm described in RFC 1951. It has several - compression levels and three different strategies described below. - - This class is not thread safe. This is inherent in the API, due - to the split of deflate and setInput. - - author of the original java version : Jochen Hoenicke - - - - - The best and slowest compression level. This tries to find very - long and distant string repetitions. - - - - - The worst but fastest compression level. - - - - - The default compression level. - - - - - This level won't compress at all but output uncompressed blocks. - - - - - The compression method. This is the only method supported so far. - There is no need to use this constant at all. - - - - - Creates a new deflater with default compression level. - - - - - Creates a new deflater with given compression level. - - - the compression level, a value between NO_COMPRESSION - and BEST_COMPRESSION, or DEFAULT_COMPRESSION. - - if lvl is out of range. - - - - Creates a new deflater with given compression level. - - - the compression level, a value between NO_COMPRESSION - and BEST_COMPRESSION. - - - true, if we should suppress the Zlib/RFC1950 header at the - beginning and the adler checksum at the end of the output. This is - useful for the GZIP/PKZIP formats. - - if lvl is out of range. - - - - Resets the deflater. The deflater acts afterwards as if it was - just created with the same compression level and strategy as it - had before. - - - - - Flushes the current input block. Further calls to deflate() will - produce enough output to inflate everything in the current input - block. This is not part of Sun's JDK so I have made it package - private. It is used by DeflaterOutputStream to implement - flush(). - - - - - Finishes the deflater with the current input block. It is an error - to give more input after this method was called. This method must - be called to force all bytes to be flushed. - - - - - Sets the data which should be compressed next. This should be only - called when needsInput indicates that more input is needed. - If you call setInput when needsInput() returns false, the - previous input that is still pending will be thrown away. - The given byte array should not be changed, before needsInput() returns - true again. - This call is equivalent to setInput(input, 0, input.length). - - - the buffer containing the input data. - - - if the buffer was finished() or ended(). - - - - - Sets the data which should be compressed next. This should be - only called when needsInput indicates that more input is needed. - The given byte array should not be changed, before needsInput() returns - true again. - - - the buffer containing the input data. - - - the start of the data. - - - the number of data bytes of input. - - - if the buffer was Finish()ed or if previous input is still pending. - - - - - Sets the compression level. There is no guarantee of the exact - position of the change, but if you call this when needsInput is - true the change of compression level will occur somewhere near - before the end of the so far given input. - - - the new compression level. - - - - - Get current compression level - - Returns the current compression level - - - - Sets the compression strategy. Strategy is one of - DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact - position where the strategy is changed, the same as for - SetLevel() applies. - - - The new compression strategy. - - - - - Deflates the current input block with to the given array. - - - The buffer where compressed data is stored - - - The number of compressed bytes added to the output, or 0 if either - IsNeedingInput() or IsFinished returns true or length is zero. - - - - - Deflates the current input block to the given array. - - - Buffer to store the compressed data. - - - Offset into the output array. - - - The maximum number of bytes that may be stored. - - - The number of compressed bytes added to the output, or 0 if either - needsInput() or finished() returns true or length is zero. - - - If Finish() was previously called. - - - If offset or length don't match the array length. - - - - - Sets the dictionary which should be used in the deflate process. - This call is equivalent to setDictionary(dict, 0, dict.Length). - - - the dictionary. - - - if SetInput () or Deflate () were already called or another dictionary was already set. - - - - - Sets the dictionary which should be used in the deflate process. - The dictionary is a byte array containing strings that are - likely to occur in the data which should be compressed. The - dictionary is not stored in the compressed output, only a - checksum. To decompress the output you need to supply the same - dictionary again. - - - The dictionary data - - - The index where dictionary information commences. - - - The number of bytes in the dictionary. - - - If SetInput () or Deflate() were already called or another dictionary was already set. - - - - - Compression level. - - - - - If true no Zlib/RFC1950 headers or footers are generated - - - - - The current state. - - - - - The total bytes of output written. - - - - - The pending output. - - - - - The deflater engine. - - - - - Gets the current adler checksum of the data that was processed so far. - - - - - Gets the number of input bytes processed so far. - - - - - Gets the number of output bytes so far. - - - - - Returns true if the stream was finished and no more output bytes - are available. - - - - - Returns true, if the input buffer is empty. - You should then call setInput(). - NOTE: This method can also return true when the stream - was finished. - - - - - The TarInputStream reads a UNIX tar archive as an InputStream. - methods are provided to position at each successive entry in - the archive, and the read each entry as a normal input stream - using read(). - - - - - Construct a TarInputStream with default block factor - - stream to source data from - - - - Construct a TarInputStream with user specified block factor - - stream to source data from - block factor to apply to archive - - - - Flushes the baseInputStream - - - - - Set the streams position. This operation is not supported and will throw a NotSupportedException - - The offset relative to the origin to seek to. - The to start seeking from. - The new position in the stream. - Any access - - - - Sets the length of the stream - This operation is not supported and will throw a NotSupportedException - - The new stream length. - Any access - - - - Writes a block of bytes to this stream using data from a buffer. - This operation is not supported and will throw a NotSupportedException - - The buffer containing bytes to write. - The offset in the buffer of the frist byte to write. - The number of bytes to write. - Any access - - - - Writes a byte to the current position in the file stream. - This operation is not supported and will throw a NotSupportedException - - The byte value to write. - Any access - - - - Reads a byte from the current tar archive entry. - - A byte cast to an int; -1 if the at the end of the stream. - - - - Reads bytes from the current tar archive entry. - - This method is aware of the boundaries of the current - entry in the archive and will deal with them appropriately - - - The buffer into which to place bytes read. - - - The offset at which to place bytes read. - - - The number of bytes to read. - - - The number of bytes read, or 0 at end of stream/EOF. - - - - - Closes this stream. Calls the TarBuffer's close() method. - The underlying stream is closed by the TarBuffer. - - - - - Set the entry factory for this instance. - - The factory for creating new entries - - - - Get the record size being used by this stream's TarBuffer. - - - TarBuffer record size. - - - - - Skip bytes in the input buffer. This skips bytes in the - current entry's data, not the entire archive, and will - stop at the end of the current entry's data if the number - to skip extends beyond that point. - - - The number of bytes to skip. - - - - - Since we do not support marking just yet, we do nothing. - - - The limit to mark. - - - - - Since we do not support marking just yet, we do nothing. - - - - - Get the next entry in this tar archive. This will skip - over any remaining data in the current entry, if there - is one, and place the input stream at the header of the - next entry, and read the header and instantiate a new - TarEntry from the header bytes and return that entry. - If there are no more entries in the archive, null will - be returned to indicate that the end of the archive has - been reached. - - - The next TarEntry in the archive, or null. - - - - - Copies the contents of the current tar archive entry directly into - an output stream. - - - The OutputStream into which to write the entry's data. - - - - - Flag set when last block has been read - - - - - Size of this entry as recorded in header - - - - - Number of bytes read for this entry so far - - - - - Buffer used with calls to Read() - - - - - Working buffer - - - - - Current entry being read - - - - - Factory used to create TarEntry or descendant class instance - - - - - Stream used as the source of input data. - - - - - Gets a value indicating whether the current stream supports reading - - - - - Gets a value indicating whether the current stream supports seeking - This property always returns false. - - - - - Gets a value indicating if the stream supports writing. - This property always returns false. - - - - - The length in bytes of the stream - - - - - Gets or sets the position within the stream. - Setting the Position is not supported and throws a NotSupportedExceptionNotSupportedException - - Any attempt to set position - - - - Get the record size being used by this stream's TarBuffer. - - - - - Get the available data that can be read from the current - entry in the archive. This does not indicate how much data - is left in the entire archive, only in the current entry. - This value is determined from the entry's size header field - and the amount of data already read from the current entry. - - - The number of available bytes for the current entry. - - - - - Return a value of true if marking is supported; false otherwise. - - Currently marking is not supported, the return value is always false. - - - - This interface is provided, along with the method , to allow - the programmer to have their own subclass instantiated for the - entries return from . - - - - - Create an entry based on name alone - - - Name of the new EntryPointNotFoundException to create - - created TarEntry or descendant class - - - - Create an instance based on an actual file - - - Name of file to represent in the entry - - - Created TarEntry or descendant class - - - - - Create a tar entry based on the header information passed - - - Buffer containing header information to base entry on - - - Created TarEntry or descendant class - - - - - Standard entry factory class creating instances of the class TarEntry - - - - - Create a based on named - - The name to use for the entry - A new - - - - Create a tar entry with details obtained from file - - The name of the file to retrieve details from. - A new - - - - Create an entry based on details in header - - The buffer containing entry details. - A new - - - - Defines known values for the property. - - - - - Host system = MSDOS - - - - - Host system = Amiga - - - - - Host system = Open VMS - - - - - Host system = Unix - - - - - Host system = VMCms - - - - - Host system = Atari ST - - - - - Host system = OS2 - - - - - Host system = Macintosh - - - - - Host system = ZSystem - - - - - Host system = Cpm - - - - - Host system = Windows NT - - - - - Host system = MVS - - - - - Host system = VSE - - - - - Host system = Acorn RISC - - - - - Host system = VFAT - - - - - Host system = Alternate MVS - - - - - Host system = BEOS - - - - - Host system = Tandem - - - - - Host system = OS400 - - - - - Host system = OSX - - - - - Host system = WinZIP AES - - - - - This class represents an entry in a zip archive. This can be a file - or a directory - ZipFile and ZipInputStream will give you instances of this class as - information about the members in an archive. ZipOutputStream - uses an instance of this class when creating an entry in a Zip file. -
-
Author of the original java version : Jochen Hoenicke -
-
- - - Creates a zip entry with the given name. - - - The name for this entry. Can include directory components. - The convention for names is 'unix' style paths with relative names only. - There are with no device names and path elements are separated by '/' characters. - - - The name passed is null - - - - - Creates a zip entry with the given name and version required to extract - - - The name for this entry. Can include directory components. - The convention for names is 'unix' style paths with no device names and - path elements separated by '/' characters. This is not enforced see CleanName - on how to ensure names are valid if this is desired. - - - The minimum 'feature version' required this entry - - - The name passed is null - - - - - Initializes an entry with the given name and made by information - - Name for this entry - Version and HostSystem Information - Minimum required zip feature version required to extract this entry - Compression method for this entry. - - The name passed is null - - - versionRequiredToExtract should be 0 (auto-calculate) or > 10 - - - This constructor is used by the ZipFile class when reading from the central header - It is not generally useful, use the constructor specifying the name only. - - - - - Creates a deep copy of the given zip entry. - - - The entry to copy. - - - - - Test the external attributes for this to - see if the external attributes are Dos based (including WINNT and variants) - and match the values - - The attributes to test. - Returns true if the external attributes are known to be DOS/Windows - based and have the same attributes set as the value passed. - - - - Force this entry to be recorded using Zip64 extensions. - - - - - Get a value indicating wether Zip64 extensions were forced. - - A value of true if Zip64 extensions have been forced on; false if not. - - - - Process extra data fields updating the entry based on the contents. - - True if the extra data fields should be handled - for a local header, rather than for a central header. - - - - - Test entry to see if data can be extracted. - - Returns true if data can be extracted for this entry; false otherwise. - - - - Creates a copy of this zip entry. - - An that is a copy of the current instance. - - - - Gets a string representation of this ZipEntry. - - A readable textual representation of this - - - - Test a compression method to see if this library - supports extracting data compressed with that method - - The compression method to test. - Returns true if the compression method is supported; false otherwise - - - - Cleans a name making it conform to Zip file conventions. - Devices names ('c:\') and UNC share names ('\\server\share') are removed - and forward slashes ('\') are converted to back slashes ('/'). - Names are made relative by trimming leading slashes which is compatible - with the ZIP naming convention. - - The name to clean - The 'cleaned' name. - - The Zip name transform class is more flexible. - - - - - Get a value indicating wether the entry has a CRC value available. - - - - - Get/Set flag indicating if entry is encrypted. - A simple helper routine to aid interpretation of flags - - This is an assistant that interprets the flags property. - - - - Get / set a flag indicating wether entry name and comment text are - encoded in unicode UTF8. - - This is an assistant that interprets the flags property. - - - - Value used during password checking for PKZIP 2.0 / 'classic' encryption. - - - - - Get/Set general purpose bit flag for entry - - - General purpose bit flag
-
- Bit 0: If set, indicates the file is encrypted
- Bit 1-2 Only used for compression type 6 Imploding, and 8, 9 deflating
- Imploding:
- Bit 1 if set indicates an 8K sliding dictionary was used. If clear a 4k dictionary was used
- Bit 2 if set indicates 3 Shannon-Fanno trees were used to encode the sliding dictionary, 2 otherwise
-
- Deflating:
- Bit 2 Bit 1
- 0 0 Normal compression was used
- 0 1 Maximum compression was used
- 1 0 Fast compression was used
- 1 1 Super fast compression was used
-
- Bit 3: If set, the fields crc-32, compressed size - and uncompressed size are were not able to be written during zip file creation - The correct values are held in a data descriptor immediately following the compressed data.
- Bit 4: Reserved for use by PKZIP for enhanced deflating
- Bit 5: If set indicates the file contains compressed patch data
- Bit 6: If set indicates strong encryption was used.
- Bit 7-10: Unused or reserved
- Bit 11: If set the name and comments for this entry are in unicode.
- Bit 12-15: Unused or reserved
-
- - -
- - - Get/Set index of this entry in Zip file - - This is only valid when the entry is part of a - - - - Get/set offset for use in central header - - - - - Get/Set external file attributes as an integer. - The values of this are operating system dependant see - HostSystem for details - - - - - Get the version made by for this entry or zero if unknown. - The value / 10 indicates the major version number, and - the value mod 10 is the minor version number - - - - - Get a value indicating this entry is for a DOS/Windows system. - - - - - Gets the compatability information for the external file attribute - If the external file attributes are compatible with MS-DOS and can be read - by PKZIP for DOS version 2.04g then this value will be zero. Otherwise the value - will be non-zero and identify the host system on which the attributes are compatible. - - - - The values for this as defined in the Zip File format and by others are shown below. The values are somewhat - misleading in some cases as they are not all used as shown. You should consult the relevant documentation - to obtain up to date and correct information. The modified appnote by the infozip group is - particularly helpful as it documents a lot of peculiarities. The document is however a little dated. - - 0 - MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems) - 1 - Amiga - 2 - OpenVMS - 3 - Unix - 4 - VM/CMS - 5 - Atari ST - 6 - OS/2 HPFS - 7 - Macintosh - 8 - Z-System - 9 - CP/M - 10 - Windows NTFS - 11 - MVS (OS/390 - Z/OS) - 12 - VSE - 13 - Acorn Risc - 14 - VFAT - 15 - Alternate MVS - 16 - BeOS - 17 - Tandem - 18 - OS/400 - 19 - OS/X (Darwin) - 99 - WinZip AES - remainder - unused - - - - - - Get minimum Zip feature version required to extract this entry - - - Minimum features are defined as:
- 1.0 - Default value
- 1.1 - File is a volume label
- 2.0 - File is a folder/directory
- 2.0 - File is compressed using Deflate compression
- 2.0 - File is encrypted using traditional encryption
- 2.1 - File is compressed using Deflate64
- 2.5 - File is compressed using PKWARE DCL Implode
- 2.7 - File is a patch data set
- 4.5 - File uses Zip64 format extensions
- 4.6 - File is compressed using BZIP2 compression
- 5.0 - File is encrypted using DES
- 5.0 - File is encrypted using 3DES
- 5.0 - File is encrypted using original RC2 encryption
- 5.0 - File is encrypted using RC4 encryption
- 5.1 - File is encrypted using AES encryption
- 5.1 - File is encrypted using corrected RC2 encryption
- 5.1 - File is encrypted using corrected RC2-64 encryption
- 6.1 - File is encrypted using non-OAEP key wrapping
- 6.2 - Central directory encryption (not confirmed yet)
- 6.3 - File is compressed using LZMA
- 6.3 - File is compressed using PPMD+
- 6.3 - File is encrypted using Blowfish
- 6.3 - File is encrypted using Twofish
-
- -
- - - Get a value indicating wether this entry can be decompressed by the library. - - This is based on the and - wether the compression method is supported. - - - - Gets a value indicating if the entry requires Zip64 extensions - to store the full entry values. - - A value of true if a local header requires Zip64 extensions; false if not. - - - - Get a value indicating wether the central directory entry requires Zip64 extensions to be stored. - - - - - Get/Set DosTime value. - - - The MS-DOS date format can only represent dates between 1/1/1980 and 12/31/2107. - - - - - Gets/Sets the time of last modification of the entry. - - - The property is updated to match this as far as possible. - - - - - Returns the entry name. - - - The unix naming convention is followed. - Path components in the entry should always separated by forward slashes ('/'). - Dos device names like C: should also be removed. - See the class, or - - - - - Gets/Sets the size of the uncompressed data. - - - The size or -1 if unknown. - - Setting the size before adding an entry to an archive can help - avoid compatability problems with some archivers which dont understand Zip64 extensions. - - - - Gets/Sets the size of the compressed data. - - - The compressed entry size or -1 if unknown. - - - - - Gets/Sets the crc of the uncompressed data. - - - Crc is not in the range 0..0xffffffffL - - - The crc value or -1 if unknown. - - - - - Gets/Sets the compression method. Only Deflated and Stored are supported. - - - The compression method for this entry - - - - - - - Gets/Sets the extra data. - - - Extra data is longer than 64KB (0xffff) bytes. - - - Extra data or null if not set. - - - - - Gets/Sets the entry comment. - - - If comment is longer than 0xffff. - - - The comment or null if not set. - - - A comment is only available for entries when read via the class. - The class doesnt have the comment data available. - - - - - Gets a value indicating if the entry is a directory. - however. - - - A directory is determined by an entry name with a trailing slash '/'. - The external file attributes can also indicate an entry is for a directory. - Currently only dos/windows attributes are tested in this manner. - The trailing slash convention should always be followed. - - - - - Get a value of true if the entry appears to be a file; false otherwise - - - This only takes account of DOS/Windows attributes. Other operating systems are ignored. - For linux and others the result may be incorrect. - - - - - ExtraData tagged value interface. - - - - - Set the contents of this instance from the data passed. - - The data to extract contents from. - The offset to begin extracting data from. - The number of bytes to extract. - - - - Get the data representing this instance. - - Returns the data for this instance. - - - - Get the ID for this tagged data value. - - - - - A raw binary tagged value - - - - - Initialise a new instance. - - The tag ID. - - - - Set the data from the raw values provided. - - The raw data to extract values from. - The index to start extracting values from. - The number of bytes available. - - - - Get the binary data representing this instance. - - The raw binary data representing this instance. - - - - The tag ID for this instance. - - - - - Get the ID for this tagged data value. - - - - - Get /set the binary data representing this instance. - - The raw binary data representing this instance. - - - - Class representing extended unix date time values. - - - - - Set the data from the raw values provided. - - The raw data to extract values from. - The index to start extracting values from. - The number of bytes available. - - - - Get the binary data representing this instance. - - The raw binary data representing this instance. - - - - Test a value to see if is valid and can be represented here. - - The value to test. - Returns true if the value is valid and can be represented; false if not. - The standard Unix time is a signed integer data type, directly encoding the Unix time number, - which is the number of seconds since 1970-01-01. - Being 32 bits means the values here cover a range of about 136 years. - The minimum representable time is 1901-12-13 20:45:52, - and the maximum representable time is 2038-01-19 03:14:07. - - - - - Get the ID - - - - - Get /set the Modification Time - - - - - - - Get / set the Access Time - - - - - - - Get / Set the Create Time - - - - - - - Get/set the values to include. - - - - - Flags indicate which values are included in this instance. - - - - - The modification time is included - - - - - The access time is included - - - - - The create time is included. - - - - - Class handling NT date time values. - - - - - Set the data from the raw values provided. - - The raw data to extract values from. - The index to start extracting values from. - The number of bytes available. - - - - Get the binary data representing this instance. - - The raw binary data representing this instance. - - - - Test a valuie to see if is valid and can be represented here. - - The value to test. - Returns true if the value is valid and can be represented; false if not. - - NTFS filetimes are 64-bit unsigned integers, stored in Intel - (least significant byte first) byte order. They determine the - number of 1.0E-07 seconds (1/10th microseconds!) past WinNT "epoch", - which is "01-Jan-1601 00:00:00 UTC". 28 May 60056 is the upper limit - - - - - Get the ID for this tagged data value. - - - - - Get/set the last modification time. - - - - - Get /set the create time - - - - - Get /set the last access time. - - - - - A factory that creates tagged data instances. - - - - - Get data for a specific tag value. - - The tag ID to find. - The data to search. - The offset to begin extracting data from. - The number of bytes to extract. - The located value found, or null if not found. - - - - - A class to handle the extra data field for Zip entries - - - Extra data contains 0 or more values each prefixed by a header tag and length. - They contain zero or more bytes of actual data. - The data is held internally using a copy on write strategy. This is more efficient but - means that for extra data created by passing in data can have the values modified by the caller - in some circumstances. - - - - - Initialise a default instance. - - - - - Initialise with known extra data. - - The extra data. - - - - Get the raw extra data value - - Returns the raw byte[] extra data this instance represents. - - - - Clear the stored data. - - - - - Get a read-only for the associated tag. - - The tag to locate data for. - Returns a containing tag data or null if no tag was found. - - - - Get the tagged data for a tag. - - The tag to search for. - Returns a tagged value or null if none found. - - - - Find an extra data value - - The identifier for the value to find. - Returns true if the value was found; false otherwise. - - - - Add a new entry to extra data. - - The value to add. - - - - Add a new entry to extra data - - The ID for this entry. - The data to add. - If the ID already exists its contents are replaced. - - - - Start adding a new entry. - - Add data using , , , or . - The new entry is completed and actually added by calling - - - - - Add entry data added since using the ID passed. - - The identifier to use for this entry. - - - - Add a byte of data to the pending new entry. - - The byte to add. - - - - - Add data to a pending new entry. - - The data to add. - - - - - Add a short value in little endian order to the pending new entry. - - The data to add. - - - - - Add an integer value in little endian order to the pending new entry. - - The data to add. - - - - - Add a long value in little endian order to the pending new entry. - - The data to add. - - - - - Delete an extra data field. - - The identifier of the field to delete. - Returns true if the field was found and deleted. - - - - Read a long in little endian form from the last found data value - - Returns the long value read. - - - - Read an integer in little endian form from the last found data value. - - Returns the integer read. - - - - Read a short value in little endian form from the last found data value. - - Returns the short value read. - - - - Read a byte from an extra data - - The byte value read or -1 if the end of data has been reached. - - - - Skip data during reading. - - The number of bytes to skip. - - - - Internal form of that reads data at any location. - - Returns the short value read. - - - - Dispose of this instance. - - - - - Gets the current extra data length. - - - - - Get the length of the last value found by - - This is only value if has previsouly returned true. - - - - Get the index for the current read value. - - This is only valid if has previously returned true. - Initially it will be the index of the first byte of actual data. The value is updated after calls to - , and . - - - - Get the number of bytes remaining to be read for the current value; - - - - - Holds data pertinent to a data descriptor. - - - - - Get /set the compressed size of data. - - - - - Get / set the uncompressed size of data - - - - - Get /set the crc value. - - - - - This class assists with writing/reading from Zip files. - - - - - Initialise an instance of this class. - - The name of the file to open. - - - - Initialise a new instance of . - - The stream to use. - - - - Close the stream. - - - The underlying stream is closed only if is true. - - - - - Locates a block with the desired . - - The signature to find. - Location, marking the end of block. - Minimum size of the block. - The maximum variable data. - Eeturns the offset of the first byte after the signature; -1 if not found - - - - Write Zip64 end of central directory records (File header and locator). - - The number of entries in the central directory. - The size of entries in the central directory. - The offset of the dentral directory. - - - - Write the required records to end the central directory. - - The number of entries in the directory. - The size of the entries in the directory. - The start of the central directory. - The archive comment. (This can be null). - - - - Read an unsigned short in little endian byte order. - - Returns the value read. - - An i/o error occurs. - - - The file ends prematurely - - - - - Read an int in little endian byte order. - - Returns the value read. - - An i/o error occurs. - - - The file ends prematurely - - - - - Read a long in little endian byte order. - - The value read. - - - - Write an unsigned short in little endian byte order. - - The value to write. - - - - Write a ushort in little endian byte order. - - The value to write. - - - - Write an int in little endian byte order. - - The value to write. - - - - Write a uint in little endian byte order. - - The value to write. - - - - Write a long in little endian byte order. - - The value to write. - - - - Write a ulong in little endian byte order. - - The value to write. - - - - Write a data descriptor. - - The entry to write a descriptor for. - Returns the number of descriptor bytes written. - - - - Read data descriptor at the end of compressed data. - - if set to true [zip64]. - The data to fill in. - Returns the number of bytes read in the descriptor. - - - - Get / set a value indicating wether the the underlying stream is owned or not. - - If the stream is owned it is closed when this instance is closed. - - - - Inflater is used to decompress data that has been compressed according - to the "deflate" standard described in rfc1951. - - By default Zlib (rfc1950) headers and footers are expected in the input. - You can use constructor public Inflater(bool noHeader) passing true - if there is no Zlib header information - - The usage is as following. First you have to set some input with - SetInput(), then Inflate() it. If inflate doesn't - inflate any bytes there may be three reasons: -
    -
  • IsNeedingInput() returns true because the input buffer is empty. - You have to provide more input with SetInput(). - NOTE: IsNeedingInput() also returns true when, the stream is finished. -
  • -
  • IsNeedingDictionary() returns true, you have to provide a preset - dictionary with SetDictionary().
  • -
  • IsFinished returns true, the inflater has finished.
  • -
- Once the first output byte is produced, a dictionary will not be - needed at a later stage. - - author of the original java version : John Leuner, Jochen Hoenicke -
-
- - - These are the possible states for an inflater - - - - - Copy lengths for literal codes 257..285 - - - - - Extra bits for literal codes 257..285 - - - - - Copy offsets for distance codes 0..29 - - - - - Extra bits for distance codes - - - - - This variable contains the current state. - - - - - The adler checksum of the dictionary or of the decompressed - stream, as it is written in the header resp. footer of the - compressed stream. - Only valid if mode is DECODE_DICT or DECODE_CHKSUM. - - - - - The number of bits needed to complete the current state. This - is valid, if mode is DECODE_DICT, DECODE_CHKSUM, - DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS. - - - - - True, if the last block flag was set in the last block of the - inflated stream. This means that the stream ends after the - current block. - - - - - The total number of inflated bytes. - - - - - The total number of bytes set with setInput(). This is not the - value returned by the TotalIn property, since this also includes the - unprocessed input. - - - - - This variable stores the noHeader flag that was given to the constructor. - True means, that the inflated stream doesn't contain a Zlib header or - footer. - - - - - Creates a new inflater or RFC1951 decompressor - RFC1950/Zlib headers and footers will be expected in the input data - - - - - Creates a new inflater. - - - True if no RFC1950/Zlib header and footer fields are expected in the input data - - This is used for GZIPed/Zipped input. - - For compatibility with - Sun JDK you should provide one byte of input more than needed in - this case. - - - - - Resets the inflater so that a new stream can be decompressed. All - pending input and output will be discarded. - - - - - Decodes a zlib/RFC1950 header. - - - False if more input is needed. - - - The header is invalid. - - - - - Decodes the dictionary checksum after the deflate header. - - - False if more input is needed. - - - - - Decodes the huffman encoded symbols in the input stream. - - - false if more input is needed, true if output window is - full or the current block ends. - - - if deflated stream is invalid. - - - - - Decodes the adler checksum after the deflate stream. - - - false if more input is needed. - - - If checksum doesn't match. - - - - - Decodes the deflated stream. - - - false if more input is needed, or if finished. - - - if deflated stream is invalid. - - - - - Sets the preset dictionary. This should only be called, if - needsDictionary() returns true and it should set the same - dictionary, that was used for deflating. The getAdler() - function returns the checksum of the dictionary needed. - - - The dictionary. - - - - - Sets the preset dictionary. This should only be called, if - needsDictionary() returns true and it should set the same - dictionary, that was used for deflating. The getAdler() - function returns the checksum of the dictionary needed. - - - The dictionary. - - - The index into buffer where the dictionary starts. - - - The number of bytes in the dictionary. - - - No dictionary is needed. - - - The adler checksum for the buffer is invalid - - - - - Sets the input. This should only be called, if needsInput() - returns true. - - - the input. - - - - - Sets the input. This should only be called, if needsInput() - returns true. - - - The source of input data - - - The index into buffer where the input starts. - - - The number of bytes of input to use. - - - No input is needed. - - - The index and/or count are wrong. - - - - - Inflates the compressed stream to the output buffer. If this - returns 0, you should check, whether IsNeedingDictionary(), - IsNeedingInput() or IsFinished() returns true, to determine why no - further output is produced. - - - the output buffer. - - - The number of bytes written to the buffer, 0 if no further - output can be produced. - - - if buffer has length 0. - - - if deflated stream is invalid. - - - - - Inflates the compressed stream to the output buffer. If this - returns 0, you should check, whether needsDictionary(), - needsInput() or finished() returns true, to determine why no - further output is produced. - - - the output buffer. - - - the offset in buffer where storing starts. - - - the maximum number of bytes to output. - - - the number of bytes written to the buffer, 0 if no further output can be produced. - - - if count is less than 0. - - - if the index and / or count are wrong. - - - if deflated stream is invalid. - - - - - Returns true, if the input buffer is empty. - You should then call setInput(). - NOTE: This method also returns true when the stream is finished. - - - - - Returns true, if a preset dictionary is needed to inflate the input. - - - - - Returns true, if the inflater has finished. This means, that no - input is needed and no output can be produced. - - - - - Gets the adler checksum. This is either the checksum of all - uncompressed bytes returned by inflate(), or if needsDictionary() - returns true (and thus no output was yet produced) this is the - adler checksum of the expected dictionary. - - - the adler checksum. - - - - - Gets the total number of output bytes returned by Inflate(). - - - the total number of output bytes. - - - - - Gets the total number of processed compressed input bytes. - - - The total number of bytes of processed input bytes. - - - - - Gets the number of unprocessed input bytes. Useful, if the end of the - stream is reached and you want to further process the bytes after - the deflate stream. - - - The number of bytes of the input which have not been processed. - - - - - An input stream that decompresses files in the BZip2 format - - - - - Construct instance for reading from stream - - Data source - - - - Flushes the stream. - - - - - Set the streams position. This operation is not supported and will throw a NotSupportedException - - A byte offset relative to the parameter. - A value of type indicating the reference point used to obtain the new position. - The new position of the stream. - Any access - - - - Sets the length of this stream to the given value. - This operation is not supported and will throw a NotSupportedExceptionortedException - - The new length for the stream. - Any access - - - - Writes a block of bytes to this stream using data from a buffer. - This operation is not supported and will throw a NotSupportedException - - The buffer to source data from. - The offset to start obtaining data from. - The number of bytes of data to write. - Any access - - - - Writes a byte to the current position in the file stream. - This operation is not supported and will throw a NotSupportedException - - The value to write. - Any access - - - - Read a sequence of bytes and advances the read position by one byte. - - Array of bytes to store values in - Offset in array to begin storing data - The maximum number of bytes to read - The total number of bytes read into the buffer. This might be less - than the number of bytes requested if that number of bytes are not - currently available or zero if the end of the stream is reached. - - - - - Closes the stream, releasing any associated resources. - - - - - Read a byte from stream advancing position - - byte read or -1 on end of stream - - - - Get/set flag indicating ownership of underlying stream. - When the flag is true will close the underlying stream also. - - - - - Gets a value indicating if the stream supports reading - - - - - Gets a value indicating whether the current stream supports seeking. - - - - - Gets a value indicating whether the current stream supports writing. - This property always returns false - - - - - Gets the length in bytes of the stream. - - - - - Gets or sets the streams position. - Setting the position is not supported and will throw a NotSupportException - - Any attempt to set the position - - - - Computes Adler32 checksum for a stream of data. An Adler32 - checksum is not as reliable as a CRC32 checksum, but a lot faster to - compute. - - The specification for Adler32 may be found in RFC 1950. - ZLIB Compressed Data Format Specification version 3.3) - - - From that document: - - "ADLER32 (Adler-32 checksum) - This contains a checksum value of the uncompressed data - (excluding any dictionary data) computed according to Adler-32 - algorithm. This algorithm is a 32-bit extension and improvement - of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 - standard. - - Adler-32 is composed of two sums accumulated per byte: s1 is - the sum of all bytes, s2 is the sum of all s1 values. Both sums - are done modulo 65521. s1 is initialized to 1, s2 to zero. The - Adler-32 checksum is stored as s2*65536 + s1 in most- - significant-byte first (network) order." - - "8.2. The Adler-32 algorithm - - The Adler-32 algorithm is much faster than the CRC32 algorithm yet - still provides an extremely low probability of undetected errors. - - The modulo on unsigned long accumulators can be delayed for 5552 - bytes, so the modulo operation time is negligible. If the bytes - are a, b, c, the second sum is 3a + 2b + c + 3, and so is position - and order sensitive, unlike the first sum, which is just a - checksum. That 65521 is prime is important to avoid a possible - large class of two-byte errors that leave the check unchanged. - (The Fletcher checksum uses 255, which is not prime and which also - makes the Fletcher check insensitive to single byte changes 0 - - 255.) - - The sum s1 is initialized to 1 instead of zero to make the length - of the sequence part of s2, so that the length does not have to be - checked separately. (Any sequence of zeroes has a Fletcher - checksum of zero.)" - - - - - - - largest prime smaller than 65536 - - - - - Creates a new instance of the Adler32 class. - The checksum starts off with a value of 1. - - - - - Resets the Adler32 checksum to the initial value. - - - - - Updates the checksum with a byte value. - - - The data value to add. The high byte of the int is ignored. - - - - - Updates the checksum with an array of bytes. - - - The source of the data to update with. - - - - - Updates the checksum with the bytes taken from the array. - - - an array of bytes - - - the start of the data used for this update - - - the number of bytes to use for this update - - - - - Returns the Adler32 data checksum computed so far. - - -
-
diff --git a/bin/hdfsdll.dll.config b/bin/hdfsdll.dll.config deleted file mode 100644 index f1805fdaf6..0000000000 --- a/bin/hdfsdll.dll.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/bin/hdfsdll.so b/bin/hdfsdll.so deleted file mode 100755 index cf79ffcb57..0000000000 Binary files a/bin/hdfsdll.so and /dev/null differ diff --git a/bin/xmrhelpers.so b/bin/xmrhelpers.so deleted file mode 100755 index 6074da26a9..0000000000 Binary files a/bin/xmrhelpers.so and /dev/null differ