aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs98
1 files changed, 67 insertions, 31 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index d6cf1ab..9232db9 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -116,7 +116,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
116 return false; 116 return false;
117 117
118 // Delete existing npc attachments 118 // Delete existing npc attachments
119 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); 119 if(scene.AttachmentsModule != null)
120 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false);
120 121
121 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet 122 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet
122 // since it doesn't transfer attachments 123 // since it doesn't transfer attachments
@@ -125,7 +126,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
125 npc.Appearance = npcAppearance; 126 npc.Appearance = npcAppearance;
126 127
127 // Rez needed npc attachments 128 // Rez needed npc attachments
128 scene.AttachmentsModule.RezAttachments(npc); 129 if (scene.AttachmentsModule != null)
130 scene.AttachmentsModule.RezAttachments(npc);
129 131
130 IAvatarFactoryModule module = 132 IAvatarFactoryModule module =
131 scene.RequestModuleInterface<IAvatarFactoryModule>(); 133 scene.RequestModuleInterface<IAvatarFactoryModule>();
@@ -138,15 +140,37 @@ namespace OpenSim.Region.OptionalModules.World.NPC
138 Vector3 position, UUID owner, bool senseAsAgent, Scene scene, 140 Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
139 AvatarAppearance appearance) 141 AvatarAppearance appearance)
140 { 142 {
141 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, 143 return CreateNPC(firstname, lastname, position, UUID.Zero, owner, senseAsAgent, scene, appearance);
142 owner, senseAsAgent, scene); 144 }
145
146 public UUID CreateNPC(string firstname, string lastname,
147 Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene,
148 AvatarAppearance appearance)
149 {
150 NPCAvatar npcAvatar = null;
151
152 try
153 {
154 if (agentID == UUID.Zero)
155 npcAvatar = new NPCAvatar(firstname, lastname, position,
156 owner, senseAsAgent, scene);
157 else
158 npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
159 owner, senseAsAgent, scene);
160 }
161 catch (Exception e)
162 {
163 m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
164 return UUID.Zero;
165 }
166
143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, 167 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
144 int.MaxValue); 168 int.MaxValue);
145 169
146 m_log.DebugFormat( 170 m_log.DebugFormat(
147 "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", 171 "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
148 firstname, lastname, npcAvatar.AgentId, owner, 172 firstname, lastname, npcAvatar.AgentId, owner,
149 senseAsAgent, position, scene.RegionInfo.RegionName); 173 senseAsAgent, position, scene.RegionInfo.RegionName);
150 174
151 AgentCircuitData acd = new AgentCircuitData(); 175 AgentCircuitData acd = new AgentCircuitData();
152 acd.AgentID = npcAvatar.AgentId; 176 acd.AgentID = npcAvatar.AgentId;
@@ -154,8 +178,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
154 acd.lastname = lastname; 178 acd.lastname = lastname;
155 acd.ServiceURLs = new Dictionary<string, object>(); 179 acd.ServiceURLs = new Dictionary<string, object>();
156 180
157 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, 181 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
158 true);
159 acd.Appearance = npcAppearance; 182 acd.Appearance = npcAppearance;
160 183
161 /* 184 /*
@@ -173,7 +196,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
173 { 196 {
174 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, 197 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
175 acd); 198 acd);
176 scene.AddNewClient(npcAvatar, PresenceType.Npc); 199 scene.AddNewAgent(npcAvatar, PresenceType.Npc);
177 200
178 ScenePresence sp; 201 ScenePresence sp;
179 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 202 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
@@ -186,16 +209,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC
186 209
187 sp.CompleteMovement(npcAvatar, false); 210 sp.CompleteMovement(npcAvatar, false);
188 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 211 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
189 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", 212 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
190 npcAvatar.AgentId, sp.Name);
191 213
192 return npcAvatar.AgentId; 214 return npcAvatar.AgentId;
193 } 215 }
194 else 216 else
195 { 217 {
196 m_log.WarnFormat( 218 m_log.WarnFormat(
197 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", 219 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
198 sp.Name, sp.UUID); 220 sp.Name, sp.UUID);
221
199 return UUID.Zero; 222 return UUID.Zero;
200 } 223 }
201 } 224 }
@@ -211,12 +234,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
211 ScenePresence sp; 234 ScenePresence sp;
212 if (scene.TryGetScenePresence(agentID, out sp)) 235 if (scene.TryGetScenePresence(agentID, out sp))
213 { 236 {
214 /* 237 if (sp.IsSatOnObject || sp.SitGround)
215 m_log.DebugFormat( 238 return false;
216 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 239
217 sp.Name, pos, scene.RegionInfo.RegionName, 240// m_log.DebugFormat(
218 noFly, landAtTarget); 241// "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
219 */ 242// sp.Name, pos, scene.RegionInfo.RegionName,
243// noFly, landAtTarget);
220 244
221 sp.MoveToTarget(pos, noFly, landAtTarget); 245 sp.MoveToTarget(pos, noFly, landAtTarget);
222 sp.SetAlwaysRun = running; 246 sp.SetAlwaysRun = running;
@@ -293,9 +317,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
293 ScenePresence sp; 317 ScenePresence sp;
294 if (scene.TryGetScenePresence(agentID, out sp)) 318 if (scene.TryGetScenePresence(agentID, out sp))
295 { 319 {
296 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, 320 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
297 partID, Vector3.Zero);
298 //sp.HandleAgentSit(m_avatars[agentID], agentID);
299 321
300 return true; 322 return true;
301 } 323 }
@@ -376,23 +398,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC
376 398
377 public bool DeleteNPC(UUID agentID, Scene scene) 399 public bool DeleteNPC(UUID agentID, Scene scene)
378 { 400 {
401 bool doRemove = false;
402 NPCAvatar av;
379 lock (m_avatars) 403 lock (m_avatars)
380 { 404 {
381 NPCAvatar av;
382 if (m_avatars.TryGetValue(agentID, out av)) 405 if (m_avatars.TryGetValue(agentID, out av))
383 { 406 {
384 /* 407 /*
385 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", 408 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
386 agentID, av.Name); 409 agentID, av.Name);
387 */ 410 */
388 scene.RemoveClient(agentID, false); 411 doRemove = true;
412 }
413 }
414
415 if (doRemove)
416 {
417 scene.CloseAgent(agentID, false);
418 lock (m_avatars)
419 {
389 m_avatars.Remove(agentID); 420 m_avatars.Remove(agentID);
390 /*
391 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
392 agentID, av.Name);
393 */
394 return true;
395 } 421 }
422 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
423 agentID, av.Name);
424 return true;
396 } 425 }
397 /* 426 /*
398 m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", 427 m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove",
@@ -416,13 +445,20 @@ namespace OpenSim.Region.OptionalModules.World.NPC
416 /// <summary> 445 /// <summary>
417 /// Check if the caller has permission to manipulate the given NPC. 446 /// Check if the caller has permission to manipulate the given NPC.
418 /// </summary> 447 /// </summary>
448 /// <remarks>
449 /// A caller has permission if
450 /// * The caller UUID given is UUID.Zero.
451 /// * The avatar is unowned (owner is UUID.Zero).
452 /// * The avatar is owned and the owner and callerID match.
453 /// * The avatar is owned and the callerID matches its agentID.
454 /// </remarks>
419 /// <param name="av"></param> 455 /// <param name="av"></param>
420 /// <param name="callerID"></param> 456 /// <param name="callerID"></param>
421 /// <returns>true if they do, false if they don't.</returns> 457 /// <returns>true if they do, false if they don't.</returns>
422 private bool CheckPermissions(NPCAvatar av, UUID callerID) 458 private bool CheckPermissions(NPCAvatar av, UUID callerID)
423 { 459 {
424 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || 460 return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
425 av.OwnerID == callerID; 461 av.OwnerID == callerID || av.AgentId == callerID;
426 } 462 }
427 } 463 }
428} 464}