diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules')
5 files changed, 230 insertions, 124 deletions
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/IRCStackModule.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/IRCStackModule.cs index cfe1278..406b715 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/IRCStackModule.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/IRCStackModule.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Net; | 29 | using System.Net; |
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using log4net; | 31 | using log4net; |
@@ -33,49 +34,51 @@ using OpenSim.Region.Framework.Interfaces; | |||
33 | using OpenSim.Region.Framework.Scenes; | 34 | using OpenSim.Region.Framework.Scenes; |
34 | using OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server; | 35 | using OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server; |
35 | 36 | ||
37 | using Mono.Addins; | ||
38 | |||
36 | namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView | 39 | namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView |
37 | { | 40 | { |
38 | public class IRCStackModule : IRegionModule | 41 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "IRCStackModule")] |
42 | public class IRCStackModule : INonSharedRegionModule | ||
39 | { | 43 | { |
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | 45 | ||
42 | private IRCServer m_server; | 46 | private IRCServer m_server; |
47 | private int m_Port; | ||
43 | // private Scene m_scene; | 48 | // private Scene m_scene; |
49 | private bool m_Enabled; | ||
44 | 50 | ||
45 | #region Implementation of IRegionModule | 51 | #region Implementation of INonSharedRegionModule |
46 | 52 | ||
47 | public void Initialise(Scene scene, IConfigSource source) | 53 | public void Initialise(IConfigSource source) |
48 | { | 54 | { |
49 | if (null != source.Configs["IRCd"] && | 55 | if (null != source.Configs["IRCd"] && |
50 | source.Configs["IRCd"].GetBoolean("Enabled",false)) | 56 | source.Configs["IRCd"].GetBoolean("Enabled", false)) |
51 | { | 57 | { |
52 | int portNo = source.Configs["IRCd"].GetInt("Port",6666); | 58 | m_Enabled = true; |
53 | // m_scene = scene; | 59 | m_Port = source.Configs["IRCd"].GetInt("Port", 6666); |
54 | m_server = new IRCServer(IPAddress.Parse("0.0.0.0"), portNo, scene); | ||
55 | m_server.OnNewIRCClient += m_server_OnNewIRCClient; | ||
56 | } | 60 | } |
57 | } | 61 | } |
58 | 62 | ||
59 | void m_server_OnNewIRCClient(IRCClientView user) | 63 | public void AddRegion(Scene scene) |
60 | { | 64 | { |
61 | user.OnIRCReady += user_OnIRCReady; | 65 | if (!m_Enabled) |
66 | return; | ||
67 | |||
68 | m_server = new IRCServer(IPAddress.Parse("0.0.0.0"), m_Port, scene); | ||
69 | m_server.OnNewIRCClient += m_server_OnNewIRCClient; | ||
62 | } | 70 | } |
63 | 71 | ||
64 | void user_OnIRCReady(IRCClientView cv) | 72 | public void RegionLoaded(Scene scene) |
65 | { | 73 | { |
66 | m_log.Info("[IRCd] Adding user..."); | ||
67 | cv.Start(); | ||
68 | m_log.Info("[IRCd] Added user to Scene"); | ||
69 | } | 74 | } |
70 | 75 | ||
71 | public void PostInitialise() | 76 | public void RemoveRegion(Scene scene) |
72 | { | 77 | { |
73 | |||
74 | } | 78 | } |
75 | 79 | ||
76 | public void Close() | 80 | public void Close() |
77 | { | 81 | { |
78 | |||
79 | } | 82 | } |
80 | 83 | ||
81 | public string Name | 84 | public string Name |
@@ -83,11 +86,24 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView | |||
83 | get { return "IRCClientStackModule"; } | 86 | get { return "IRCClientStackModule"; } |
84 | } | 87 | } |
85 | 88 | ||
86 | public bool IsSharedModule | 89 | public Type ReplaceableInterface |
87 | { | 90 | { |
88 | get { return false; } | 91 | get { return null; } |
89 | } | 92 | } |
90 | 93 | ||
91 | #endregion | 94 | #endregion |
95 | |||
96 | void m_server_OnNewIRCClient(IRCClientView user) | ||
97 | { | ||
98 | user.OnIRCReady += user_OnIRCReady; | ||
99 | } | ||
100 | |||
101 | void user_OnIRCReady(IRCClientView cv) | ||
102 | { | ||
103 | m_log.Info("[IRCd] Adding user..."); | ||
104 | cv.Start(); | ||
105 | m_log.Info("[IRCd] Added user to Scene"); | ||
106 | } | ||
107 | |||
92 | } | 108 | } |
93 | } | 109 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs index 03481d2..6fb28e2 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs | |||
@@ -43,13 +43,17 @@ using OpenMetaverse; | |||
43 | using OpenSim.Framework; | 43 | using OpenSim.Framework; |
44 | using OpenSim.Region.Framework.Interfaces; | 44 | using OpenSim.Region.Framework.Interfaces; |
45 | using OpenSim.Region.Framework.Scenes; | 45 | using OpenSim.Region.Framework.Scenes; |
46 | using Mono.Addins; | ||
46 | 47 | ||
47 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | 48 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule |
48 | { | 49 | { |
49 | public class MRMModule : IRegionModule, IMRMModule | 50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MRMModule")] |
51 | public class MRMModule : INonSharedRegionModule, IMRMModule | ||
50 | { | 52 | { |
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
52 | private Scene m_scene; | 54 | private Scene m_scene; |
55 | private bool m_Enabled; | ||
56 | private bool m_Hidden; | ||
53 | 57 | ||
54 | private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>(); | 58 | private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>(); |
55 | 59 | ||
@@ -67,7 +71,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
67 | m_extensions[typeof (T)] = instance; | 71 | m_extensions[typeof (T)] = instance; |
68 | } | 72 | } |
69 | 73 | ||
70 | public void Initialise(Scene scene, IConfigSource source) | 74 | #region INonSharedRegionModule |
75 | |||
76 | public void Initialise(IConfigSource source) | ||
71 | { | 77 | { |
72 | if (source.Configs["MRM"] != null) | 78 | if (source.Configs["MRM"] != null) |
73 | { | 79 | { |
@@ -76,23 +82,60 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
76 | if (source.Configs["MRM"].GetBoolean("Enabled", false)) | 82 | if (source.Configs["MRM"].GetBoolean("Enabled", false)) |
77 | { | 83 | { |
78 | m_log.Info("[MRM]: Enabling MRM Module"); | 84 | m_log.Info("[MRM]: Enabling MRM Module"); |
79 | m_scene = scene; | 85 | m_Enabled = true; |
86 | m_Hidden = source.Configs["MRM"].GetBoolean("Hidden", false); | ||
87 | } | ||
88 | } | ||
89 | } | ||
80 | 90 | ||
81 | // when hidden, we don't listen for client initiated script events | 91 | public void AddRegion(Scene scene) |
82 | // only making the MRM engine available for region modules | 92 | { |
83 | if (!source.Configs["MRM"].GetBoolean("Hidden", false)) | 93 | if (!m_Enabled) |
84 | { | 94 | return; |
85 | scene.EventManager.OnRezScript += EventManager_OnRezScript; | ||
86 | scene.EventManager.OnStopScript += EventManager_OnStopScript; | ||
87 | } | ||
88 | 95 | ||
89 | scene.EventManager.OnFrame += EventManager_OnFrame; | 96 | m_scene = scene; |
90 | 97 | ||
91 | scene.RegisterModuleInterface<IMRMModule>(this); | 98 | // when hidden, we don't listen for client initiated script events |
92 | } | 99 | // only making the MRM engine available for region modules |
100 | if (!m_Hidden) | ||
101 | { | ||
102 | scene.EventManager.OnRezScript += EventManager_OnRezScript; | ||
103 | scene.EventManager.OnStopScript += EventManager_OnStopScript; | ||
93 | } | 104 | } |
105 | |||
106 | scene.EventManager.OnFrame += EventManager_OnFrame; | ||
107 | |||
108 | scene.RegisterModuleInterface<IMRMModule>(this); | ||
109 | } | ||
110 | |||
111 | public void RegionLoaded(Scene scene) | ||
112 | { | ||
94 | } | 113 | } |
95 | 114 | ||
115 | public void RemoveRegion(Scene scene) | ||
116 | { | ||
117 | } | ||
118 | |||
119 | public void Close() | ||
120 | { | ||
121 | foreach (KeyValuePair<UUID, MRMBase> pair in m_scripts) | ||
122 | { | ||
123 | pair.Value.Stop(); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public string Name | ||
128 | { | ||
129 | get { return "MiniRegionModule"; } | ||
130 | } | ||
131 | |||
132 | public Type ReplaceableInterface | ||
133 | { | ||
134 | get { return null; } | ||
135 | } | ||
136 | |||
137 | #endregion | ||
138 | |||
96 | void EventManager_OnStopScript(uint localID, UUID itemID) | 139 | void EventManager_OnStopScript(uint localID, UUID itemID) |
97 | { | 140 | { |
98 | if (m_scripts.ContainsKey(itemID)) | 141 | if (m_scripts.ContainsKey(itemID)) |
@@ -293,28 +336,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
293 | mmb.InitMiniModule(world, host, itemID); | 336 | mmb.InitMiniModule(world, host, itemID); |
294 | } | 337 | } |
295 | 338 | ||
296 | public void PostInitialise() | ||
297 | { | ||
298 | } | ||
299 | |||
300 | public void Close() | ||
301 | { | ||
302 | foreach (KeyValuePair<UUID, MRMBase> pair in m_scripts) | ||
303 | { | ||
304 | pair.Value.Stop(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | public string Name | ||
309 | { | ||
310 | get { return "MiniRegionModule"; } | ||
311 | } | ||
312 | |||
313 | public bool IsSharedModule | ||
314 | { | ||
315 | get { return false; } | ||
316 | } | ||
317 | |||
318 | /// <summary> | 339 | /// <summary> |
319 | /// Stolen from ScriptEngine Common | 340 | /// Stolen from ScriptEngine Common |
320 | /// </summary> | 341 | /// </summary> |
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs index 2187449..6120a81 100644 --- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs | |||
@@ -32,6 +32,7 @@ using System.Reflection; | |||
32 | using log4net; | 32 | using log4net; |
33 | using Nini.Config; | 33 | using Nini.Config; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using Mono.Addins; | ||
35 | 36 | ||
36 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
@@ -49,7 +50,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
49 | public string uri; | 50 | public string uri; |
50 | } | 51 | } |
51 | 52 | ||
52 | public class XmlRpcGridRouter : IRegionModule, IXmlRpcRouter | 53 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcGridRouter")] |
54 | public class XmlRpcGridRouter : INonSharedRegionModule, IXmlRpcRouter | ||
53 | { | 55 | { |
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 56 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | 57 | ||
@@ -59,9 +61,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
59 | private bool m_Enabled = false; | 61 | private bool m_Enabled = false; |
60 | private string m_ServerURI = String.Empty; | 62 | private string m_ServerURI = String.Empty; |
61 | 63 | ||
62 | public void Initialise(Scene scene, IConfigSource config) | 64 | #region INonSharedRegionModule |
65 | |||
66 | public void Initialise(IConfigSource config) | ||
63 | { | 67 | { |
64 | IConfig startupConfig = config.Configs["Startup"]; | 68 | IConfig startupConfig = config.Configs["XMLRPC"]; |
65 | if (startupConfig == null) | 69 | if (startupConfig == null) |
66 | return; | 70 | return; |
67 | 71 | ||
@@ -74,16 +78,30 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
74 | m_log.Error("[XMLRPC GRID ROUTER] Module configured but no URI given. Disabling"); | 78 | m_log.Error("[XMLRPC GRID ROUTER] Module configured but no URI given. Disabling"); |
75 | return; | 79 | return; |
76 | } | 80 | } |
77 | |||
78 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); | ||
79 | m_Enabled = true; | 81 | m_Enabled = true; |
80 | } | 82 | } |
81 | } | 83 | } |
82 | 84 | ||
83 | public void PostInitialise() | 85 | public void AddRegion(Scene scene) |
86 | { | ||
87 | if (!m_Enabled) | ||
88 | return; | ||
89 | |||
90 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); | ||
91 | } | ||
92 | |||
93 | public void RegionLoaded(Scene scene) | ||
84 | { | 94 | { |
85 | } | 95 | } |
86 | 96 | ||
97 | public void RemoveRegion(Scene scene) | ||
98 | { | ||
99 | if (!m_Enabled) | ||
100 | return; | ||
101 | |||
102 | scene.UnregisterModuleInterface<IXmlRpcRouter>(this); | ||
103 | } | ||
104 | |||
87 | public void Close() | 105 | public void Close() |
88 | { | 106 | { |
89 | } | 107 | } |
@@ -93,11 +111,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule | |||
93 | get { return "XmlRpcGridRouterModule"; } | 111 | get { return "XmlRpcGridRouterModule"; } |
94 | } | 112 | } |
95 | 113 | ||
96 | public bool IsSharedModule | 114 | public Type ReplaceableInterface |
97 | { | 115 | { |
98 | get { return false; } | 116 | get { return null; } |
99 | } | 117 | } |
100 | 118 | ||
119 | #endregion | ||
120 | |||
101 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) | 121 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) |
102 | { | 122 | { |
103 | if (!m_Channels.ContainsKey(itemID)) | 123 | if (!m_Channels.ContainsKey(itemID)) |
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs index 11c87f8..4bde52a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcRouterModule.cs | |||
@@ -31,6 +31,7 @@ using System.Reflection; | |||
31 | using log4net; | 31 | using log4net; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using Mono.Addins; | ||
34 | 35 | ||
35 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
@@ -39,32 +40,46 @@ using OpenSim.Region.Framework.Scenes; | |||
39 | 40 | ||
40 | namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule | 41 | namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule |
41 | { | 42 | { |
42 | public class XmlRpcRouter : IRegionModule, IXmlRpcRouter | 43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcRouter")] |
44 | public class XmlRpcRouter : INonSharedRegionModule, IXmlRpcRouter | ||
43 | { | 45 | { |
44 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | private bool m_enabled = false; | 47 | |
46 | public void Initialise(Scene scene, IConfigSource config) | 48 | private bool m_Enabled; |
49 | |||
50 | #region INonSharedRegionModule | ||
51 | |||
52 | public void Initialise(IConfigSource config) | ||
47 | { | 53 | { |
48 | IConfig startupConfig = config.Configs["XMLRPC"]; | 54 | IConfig startupConfig = config.Configs["XMLRPC"]; |
49 | if (startupConfig == null) | 55 | if (startupConfig == null) |
50 | return; | 56 | return; |
51 | 57 | ||
52 | if (startupConfig.GetString("XmlRpcRouterModule", | 58 | if (startupConfig.GetString("XmlRpcRouterModule", |
53 | "") == "XmlRpcRouterModule") | 59 | "XmlRpcRouterModule") == "XmlRpcRouterModule") |
54 | { | 60 | m_Enabled = true; |
55 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); | 61 | } |
56 | m_enabled = true; | 62 | |
57 | } | 63 | public void AddRegion(Scene scene) |
58 | else | 64 | { |
59 | { | 65 | if (!m_Enabled) |
60 | m_enabled = false; | 66 | return; |
61 | } | 67 | |
68 | scene.RegisterModuleInterface<IXmlRpcRouter>(this); | ||
62 | } | 69 | } |
63 | 70 | ||
64 | public void PostInitialise() | 71 | public void RegionLoaded(Scene scene) |
65 | { | 72 | { |
66 | } | 73 | } |
67 | 74 | ||
75 | public void RemoveRegion(Scene scene) | ||
76 | { | ||
77 | if (!m_Enabled) | ||
78 | return; | ||
79 | |||
80 | scene.UnregisterModuleInterface<IXmlRpcRouter>(this); | ||
81 | } | ||
82 | |||
68 | public void Close() | 83 | public void Close() |
69 | { | 84 | { |
70 | } | 85 | } |
@@ -74,14 +89,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcRouterModule | |||
74 | get { return "XmlRpcRouterModule"; } | 89 | get { return "XmlRpcRouterModule"; } |
75 | } | 90 | } |
76 | 91 | ||
77 | public bool IsSharedModule | 92 | public Type ReplaceableInterface |
78 | { | 93 | { |
79 | get { return false; } | 94 | get { return null; } |
80 | } | 95 | } |
81 | 96 | ||
97 | #endregion | ||
98 | |||
82 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) | 99 | public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri) |
83 | { | 100 | { |
84 | if (m_enabled) | 101 | if (m_Enabled) |
85 | { | 102 | { |
86 | scriptEngine.PostScriptEvent(itemID, "xmlrpc_uri", new Object[] { uri }); | 103 | scriptEngine.PostScriptEvent(itemID, "xmlrpc_uri", new Object[] { uri }); |
87 | } | 104 | } |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index f16927c..b07ae5b 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -29,37 +29,57 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using Timer = System.Timers.Timer; | ||
33 | |||
32 | using log4net; | 34 | using log4net; |
33 | using Nini.Config; | 35 | using Nini.Config; |
36 | using Mono.Addins; | ||
34 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | |||
35 | using OpenSim.Region.Framework.Interfaces; | 39 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 40 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
38 | using Timer=System.Timers.Timer; | ||
39 | using OpenSim.Services.Interfaces; | 42 | using OpenSim.Services.Interfaces; |
40 | 43 | ||
41 | namespace OpenSim.Region.OptionalModules.World.NPC | 44 | namespace OpenSim.Region.OptionalModules.World.NPC |
42 | { | 45 | { |
43 | public class NPCModule : IRegionModule, INPCModule | 46 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] |
47 | public class NPCModule : INPCModule, ISharedRegionModule | ||
44 | { | 48 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger( |
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private Dictionary<UUID, NPCAvatar> m_avatars = | ||
53 | new Dictionary<UUID, NPCAvatar>(); | ||
46 | 54 | ||
47 | private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); | 55 | public bool Enabled { get; private set; } |
48 | 56 | ||
49 | public void Initialise(Scene scene, IConfigSource source) | 57 | public void Initialise(IConfigSource source) |
50 | { | 58 | { |
51 | IConfig config = source.Configs["NPC"]; | 59 | IConfig config = source.Configs["NPC"]; |
52 | 60 | ||
53 | if (config != null && config.GetBoolean("Enabled", false)) | 61 | Enabled = (config != null && config.GetBoolean("Enabled", false)); |
54 | { | 62 | } |
63 | |||
64 | public void AddRegion(Scene scene) | ||
65 | { | ||
66 | if (Enabled) | ||
55 | scene.RegisterModuleInterface<INPCModule>(this); | 67 | scene.RegisterModuleInterface<INPCModule>(this); |
56 | } | 68 | } |
69 | |||
70 | public void RegionLoaded(Scene scene) | ||
71 | { | ||
57 | } | 72 | } |
58 | 73 | ||
59 | public void PostInitialise() | 74 | public void PostInitialise() |
60 | { | 75 | { |
61 | } | 76 | } |
62 | 77 | ||
78 | public void RemoveRegion(Scene scene) | ||
79 | { | ||
80 | scene.UnregisterModuleInterface<INPCModule>(this); | ||
81 | } | ||
82 | |||
63 | public void Close() | 83 | public void Close() |
64 | { | 84 | { |
65 | } | 85 | } |
@@ -69,15 +89,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
69 | get { return "NPCModule"; } | 89 | get { return "NPCModule"; } |
70 | } | 90 | } |
71 | 91 | ||
72 | public bool IsSharedModule | 92 | public Type ReplaceableInterface { get { return null; } } |
73 | { | ||
74 | get { return true; } | ||
75 | } | ||
76 | 93 | ||
77 | public bool IsNPC(UUID agentId, Scene scene) | 94 | public bool IsNPC(UUID agentId, Scene scene) |
78 | { | 95 | { |
79 | // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect | 96 | // FIXME: This implementation could not just use the |
80 | // that directly). | 97 | // ScenePresence.PresenceType (and callers could inspect that |
98 | // directly). | ||
81 | ScenePresence sp = scene.GetScenePresence(agentId); | 99 | ScenePresence sp = scene.GetScenePresence(agentId); |
82 | if (sp == null || sp.IsChildAgent) | 100 | if (sp == null || sp.IsChildAgent) |
83 | return false; | 101 | return false; |
@@ -86,7 +104,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
86 | return m_avatars.ContainsKey(agentId); | 104 | return m_avatars.ContainsKey(agentId); |
87 | } | 105 | } |
88 | 106 | ||
89 | public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene) | 107 | public bool SetNPCAppearance(UUID agentId, |
108 | AvatarAppearance appearance, Scene scene) | ||
90 | { | 109 | { |
91 | ScenePresence npc = scene.GetScenePresence(agentId); | 110 | ScenePresence npc = scene.GetScenePresence(agentId); |
92 | if (npc == null || npc.IsChildAgent) | 111 | if (npc == null || npc.IsChildAgent) |
@@ -99,30 +118,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
99 | // Delete existing npc attachments | 118 | // Delete existing npc attachments |
100 | scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); | 119 | scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); |
101 | 120 | ||
102 | // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments | 121 | // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet |
103 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); | 122 | // since it doesn't transfer attachments |
123 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, | ||
124 | true); | ||
104 | npc.Appearance = npcAppearance; | 125 | npc.Appearance = npcAppearance; |
105 | 126 | ||
106 | // Rez needed npc attachments | 127 | // Rez needed npc attachments |
107 | scene.AttachmentsModule.RezAttachments(npc); | 128 | scene.AttachmentsModule.RezAttachments(npc); |
108 | 129 | ||
109 | IAvatarFactoryModule module = scene.RequestModuleInterface<IAvatarFactoryModule>(); | 130 | IAvatarFactoryModule module = |
131 | scene.RequestModuleInterface<IAvatarFactoryModule>(); | ||
110 | module.SendAppearance(npc.UUID); | 132 | module.SendAppearance(npc.UUID); |
111 | 133 | ||
112 | return true; | 134 | return true; |
113 | } | 135 | } |
114 | 136 | ||
115 | public UUID CreateNPC( | 137 | public UUID CreateNPC(string firstname, string lastname, |
116 | string firstname, | 138 | Vector3 position, UUID owner, bool senseAsAgent, Scene scene, |
117 | string lastname, | 139 | AvatarAppearance appearance) |
118 | Vector3 position, | ||
119 | UUID owner, | ||
120 | bool senseAsAgent, | ||
121 | Scene scene, | ||
122 | AvatarAppearance appearance) | ||
123 | { | 140 | { |
124 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); | 141 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, |
125 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); | 142 | owner, senseAsAgent, scene); |
143 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, | ||
144 | int.MaxValue); | ||
126 | 145 | ||
127 | // m_log.DebugFormat( | 146 | // m_log.DebugFormat( |
128 | // "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", | 147 | // "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", |
@@ -134,15 +153,20 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
134 | acd.lastname = lastname; | 153 | acd.lastname = lastname; |
135 | acd.ServiceURLs = new Dictionary<string, object>(); | 154 | acd.ServiceURLs = new Dictionary<string, object>(); |
136 | 155 | ||
137 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); | 156 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, |
157 | true); | ||
138 | acd.Appearance = npcAppearance; | 158 | acd.Appearance = npcAppearance; |
139 | 159 | ||
140 | // for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) | 160 | /* |
141 | // { | 161 | for (int i = 0; |
142 | // m_log.DebugFormat( | 162 | i < acd.Appearance.Texture.FaceTextures.Length; i++) |
143 | // "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", | 163 | { |
144 | // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); | 164 | m_log.DebugFormat( |
145 | // } | 165 | "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", |
166 | acd.AgentID, i, | ||
167 | acd.Appearance.Texture.FaceTextures[i]); | ||
168 | } | ||
169 | */ | ||
146 | 170 | ||
147 | ManualResetEvent ev = new ManualResetEvent(false); | 171 | ManualResetEvent ev = new ManualResetEvent(false); |
148 | 172 | ||
@@ -170,7 +194,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
170 | return npcAvatar.AgentId; | 194 | return npcAvatar.AgentId; |
171 | } | 195 | } |
172 | 196 | ||
173 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) | 197 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, |
198 | bool noFly, bool landAtTarget, bool running) | ||
174 | { | 199 | { |
175 | lock (m_avatars) | 200 | lock (m_avatars) |
176 | { | 201 | { |
@@ -185,7 +210,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
185 | 210 | ||
186 | sp.MoveToTarget(pos, noFly, landAtTarget); | 211 | sp.MoveToTarget(pos, noFly, landAtTarget); |
187 | sp.SetAlwaysRun = running; | 212 | sp.SetAlwaysRun = running; |
188 | 213 | ||
189 | return true; | 214 | return true; |
190 | } | 215 | } |
191 | } | 216 | } |
@@ -258,9 +283,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
258 | ScenePresence sp; | 283 | ScenePresence sp; |
259 | if (scene.TryGetScenePresence(agentID, out sp)) | 284 | if (scene.TryGetScenePresence(agentID, out sp)) |
260 | { | 285 | { |
261 | sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); | 286 | sp.HandleAgentRequestSit(m_avatars[agentID], agentID, |
262 | // sp.HandleAgentSit(m_avatars[agentID], agentID); | 287 | partID, Vector3.Zero); |
263 | 288 | //sp.HandleAgentSit(m_avatars[agentID], agentID); | |
289 | |||
264 | return true; | 290 | return true; |
265 | } | 291 | } |
266 | } | 292 | } |
@@ -269,7 +295,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
269 | return false; | 295 | return false; |
270 | } | 296 | } |
271 | 297 | ||
272 | public bool Whisper(UUID agentID, Scene scene, string text, int channel) | 298 | public bool Whisper(UUID agentID, Scene scene, string text, |
299 | int channel) | ||
273 | { | 300 | { |
274 | lock (m_avatars) | 301 | lock (m_avatars) |
275 | { | 302 | { |
@@ -344,7 +371,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
344 | NPCAvatar av; | 371 | NPCAvatar av; |
345 | if (m_avatars.TryGetValue(agentID, out av)) | 372 | if (m_avatars.TryGetValue(agentID, out av)) |
346 | { | 373 | { |
347 | // m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); | 374 | /* |
375 | m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", | ||
376 | agentID, av.Name); | ||
377 | */ | ||
348 | scene.RemoveClient(agentID, false); | 378 | scene.RemoveClient(agentID, false); |
349 | m_avatars.Remove(agentID); | 379 | m_avatars.Remove(agentID); |
350 | 380 | ||
@@ -352,8 +382,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
352 | return true; | 382 | return true; |
353 | } | 383 | } |
354 | } | 384 | } |
355 | 385 | /* | |
356 | // m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); | 386 | m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", |
387 | agentID); | ||
388 | */ | ||
357 | return false; | 389 | return false; |
358 | } | 390 | } |
359 | 391 | ||