diff --git a/libsecondlife/AgentManager.cs b/libsecondlife/AgentManager.cs
index 4dbe7c79..f3a6a993 100644
--- a/libsecondlife/AgentManager.cs
+++ b/libsecondlife/AgentManager.cs
@@ -469,6 +469,36 @@ namespace libsecondlife
PhysicalObjectCollide
}
+ ///
+ /// Flags sent when a script takes or releases a control
+ ///
+ /// NOTE: (need to verify) These might be a subset of the ControlFlags enum in Movement,
+ [Flags]
+ public enum ScriptControlChange : uint
+ {
+ /// No Flags set
+ None = 0,
+ /// Forward (W or up Arrow)
+ Forward = 1,
+ /// Back (S or down arrow)
+ Back = 2,
+ /// Move left (shift+A or left arrow)
+ Left = 4,
+ /// Move right (shift+D or right arrow)
+ Right = 8,
+ /// Up (E or PgUp)
+ Up = 16,
+ /// Down (C or PgDown
+ Down = 32,
+ /// Rotate left (A or left arrow)
+ RotateLeft = 256,
+ /// Rotate right (D or right arrow)
+ RotateRight = 512,
+ /// Left Mouse Button
+ LeftButton = 268435456,
+ /// Left Mouse button in MouseLook
+ MouseLookLeftButton = 1073741824
+ }
#endregion Enums
#region Structs
@@ -785,6 +815,15 @@ namespace libsecondlife
/// the message sent from the grid to our avatar.
public delegate void AlertMessage(string message);
+ ///
+ /// Fired when a script wants to give or release controls.
+ ///
+ /// Control to give or take
+ /// true of passing control to agent
+ /// true of taking control from agent
+ /// TODO: controls should be an enum
+ public delegate void ScriptControlEvent(ScriptControlChange controls, bool pass, bool take);
+
/// Callback for incoming chat packets
public event ChatCallback OnChat;
/// Callback for pop-up dialogs from scripts
@@ -817,6 +856,8 @@ namespace libsecondlife
public event GroupChatLeft OnGroupChatLeft;
/// Alert messages sent to client from simulator
public event AlertMessage OnAlertMessage;
+ /// Fired when a script wants to take or release control of your avatar.
+ public event ScriptControlEvent OnScriptControlChange;
#endregion
/// Reference to the SecondLife client object
@@ -1066,6 +1107,8 @@ namespace libsecondlife
Client.Network.RegisterLoginResponseCallback(new NetworkManager.LoginResponseCallback(Network_OnLoginResponse));
// Alert Messages
Client.Network.RegisterCallback(PacketType.AlertMessage, new NetworkManager.PacketCallback(AlertMessageHandler));
+ // script control change messages, ie: when an in-world LSL script wants to take control of your agent.
+ Client.Network.RegisterCallback(PacketType.ScriptControlChange, new NetworkManager.PacketCallback(ScriptControlChangeHandler));
}
@@ -2359,6 +2402,29 @@ namespace libsecondlife
}
}
+ ///
+ /// Handles Script Control changes when Script with permissions releases or takes a control
+ ///
+ ///
+ ///
+ private void ScriptControlChangeHandler(Packet packet, Simulator simulator)
+ {
+ if (OnScriptControlChange != null)
+ {
+ ScriptControlChangePacket change = (ScriptControlChangePacket)packet;
+ for (int i = 0; i < change.Data.Length; i++)
+ {
+ try
+ {
+ OnScriptControlChange((ScriptControlChange)change.Data[i].Controls,
+ change.Data[i].PassToAgent,
+ change.Data[i].TakeControls);
+ }
+ catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
+ }
+ }
+ }
+
///
/// Used for parsing llLoadURL Dialogs
///