aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-06-29 00:28:22 +0100
committerJustin Clark-Casey (justincc)2011-06-29 00:28:22 +0100
commit22f25fae387a801e8545f6ab6e2c9700926ae6e4 (patch)
tree5a0e57a655aaecba82f7819896dfef7c9a52705a /OpenSim/Region/OptionalModules/World
parent[PATCH 2/2] [FIX] osGetPrimitiveParams() and osSetPrimitiveParams() (diff)
downloadopensim-SC_OLD-22f25fae387a801e8545f6ab6e2c9700926ae6e4.zip
opensim-SC_OLD-22f25fae387a801e8545f6ab6e2c9700926ae6e4.tar.gz
opensim-SC_OLD-22f25fae387a801e8545f6ab6e2c9700926ae6e4.tar.bz2
opensim-SC_OLD-22f25fae387a801e8545f6ab6e2c9700926ae6e4.tar.xz
Hack around with the NPC module to get osNpcCreate() partially working again.
This now creates an avatar but appearance is always cloudy. Move doesn't work. Really, creating an NPC should only involve a ScenePresence rather than doing anything with IClientAPI, since an NPC has no viewer to communicate with!
Diffstat (limited to 'OpenSim/Region/OptionalModules/World')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs107
1 files changed, 74 insertions, 33 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index c471636..48d236f 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -25,10 +25,13 @@
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
28using System;
28using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection;
29using System.Threading; 31using System.Threading;
30using OpenMetaverse; 32using log4net;
31using Nini.Config; 33using Nini.Config;
34using OpenMetaverse;
32using OpenSim.Region.Framework.Interfaces; 35using OpenSim.Region.Framework.Interfaces;
33using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
34using OpenSim.Region.CoreModules.Avatar.NPC; 37using OpenSim.Region.CoreModules.Avatar.NPC;
@@ -40,6 +43,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
40{ 43{
41 public class NPCModule : IRegionModule, INPCModule 44 public class NPCModule : IRegionModule, INPCModule
42 { 45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
43 // private const bool m_enabled = false; 48 // private const bool m_enabled = false;
44 49
45 private Mutex m_createMutex; 50 private Mutex m_createMutex;
@@ -59,6 +64,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC
59 private UUID p_cloneAppearanceFrom; 64 private UUID p_cloneAppearanceFrom;
60 private UUID p_returnUuid; 65 private UUID p_returnUuid;
61 66
67 public void Initialise(Scene scene, IConfigSource source)
68 {
69 m_createMutex = new Mutex(false);
70
71 m_timer = new Timer(500);
72 m_timer.Elapsed += m_timer_Elapsed;
73 m_timer.Start();
74
75 scene.RegisterModuleInterface<INPCModule>(this);
76 }
77
62 private AvatarAppearance GetAppearance(UUID target, Scene scene) 78 private AvatarAppearance GetAppearance(UUID target, Scene scene)
63 { 79 {
64 if (m_appearanceCache.ContainsKey(target)) 80 if (m_appearanceCache.ContainsKey(target))
@@ -76,6 +92,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
76 92
77 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) 93 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom)
78 { 94 {
95 m_log.DebugFormat(
96 "[NPC MODULE]: Queueing request to create NPC {0} {1} at {2} in {3} cloning appearance of {4}",
97 firstname, lastname, position, scene.RegionInfo.RegionName, cloneAppearanceFrom);
98
79 // Block. 99 // Block.
80 m_createMutex.WaitOne(); 100 m_createMutex.WaitOne();
81 101
@@ -137,46 +157,67 @@ namespace OpenSim.Region.OptionalModules.World.NPC
137 } 157 }
138 } 158 }
139 159
140
141 public void Initialise(Scene scene, IConfigSource source)
142 {
143 m_createMutex = new Mutex(false);
144
145 m_timer = new Timer(500);
146 m_timer.Elapsed += m_timer_Elapsed;
147 m_timer.Start();
148
149 scene.RegisterModuleInterface<INPCModule>(this);
150 }
151
152 void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 160 void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
153 { 161 {
154 lock (p_lock) 162 try
155 { 163 {
156 if (p_inUse) 164 lock (p_lock)
157 { 165 {
158 p_inUse = false; 166 if (p_inUse)
159
160 NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene);
161 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue);
162
163 p_scene.AddNewClient(npcAvatar);
164
165 ScenePresence sp;
166 if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
167 { 167 {
168 AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene); 168 p_inUse = false;
169 169
170 sp.Appearance.SetTextureEntries(x.Texture); 170 NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene);
171 sp.Appearance.SetVisualParams((byte[])x.VisualParams.Clone()); 171 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue);
172 sp.SendAppearanceToAllOtherAgents(); 172
173 m_log.DebugFormat(
174 "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}",
175 p_firstname, p_lastname, npcAvatar.AgentId, p_position, p_scene.RegionInfo.RegionName);
176
177 AgentCircuitData acd = new AgentCircuitData();
178 acd.AgentID = npcAvatar.AgentId;
179 acd.firstname = p_firstname;
180 acd.lastname = p_lastname;
181 acd.ServiceURLs = new Dictionary<string, object>();
182
183 AvatarAppearance originalAppearance = GetAppearance(p_cloneAppearanceFrom, p_scene);
184 AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
185 acd.Appearance = npcAppearance;
186
187 p_scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
188 p_scene.AddNewClient(npcAvatar);
189
190 ScenePresence sp;
191 if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
192 {
193 m_log.DebugFormat(
194 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
195
196 // Shouldn't call this - temporary.
197 sp.CompleteMovement(npcAvatar);
198
199 // sp.SendAppearanceToAllOtherAgents();
200 //
201 // // Send animations back to the avatar as well
202 // sp.Animator.SendAnimPack();
203 }
204 else
205 {
206 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
207 }
208
209 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
210
211 p_returnUuid = npcAvatar.AgentId;
212
213 m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", p_returnUuid);
173 } 214 }
174
175 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
176
177 p_returnUuid = npcAvatar.AgentId;
178 } 215 }
179 } 216 }
217 catch (Exception ex)
218 {
219 m_log.ErrorFormat("[NPC MODULE]: NPC creation failed with exception {0} {1}", ex.Message, ex.StackTrace);
220 }
180 } 221 }
181 222
182 public void PostInitialise() 223 public void PostInitialise()