aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs21
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs87
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs30
3 files changed, 115 insertions, 23 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index 84055cc..6d40a92 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -31,24 +31,32 @@ using System.Net;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenMetaverse.Packets; 32using OpenMetaverse.Packets;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.CoreModules.World.Estate;
35 37
36namespace OpenSim.Region.OptionalModules.World.NPC 38namespace OpenSim.Region.OptionalModules.World.NPC
37{ 39{
38 public class NPCAvatar : IClientAPI 40 public class NPCAvatar : IClientAPI, INPC
39 { 41 {
42 public bool SenseAsAgent { get; set; }
43
40 private readonly string m_firstname; 44 private readonly string m_firstname;
41 private readonly string m_lastname; 45 private readonly string m_lastname;
42 private readonly Vector3 m_startPos; 46 private readonly Vector3 m_startPos;
43 private readonly UUID m_uuid = UUID.Random(); 47 private readonly UUID m_uuid = UUID.Random();
44 private readonly Scene m_scene; 48 private readonly Scene m_scene;
49 private readonly UUID m_ownerID;
45 50
46 public NPCAvatar(string firstname, string lastname, Vector3 position, Scene scene) 51 public NPCAvatar(
52 string firstname, string lastname, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene)
47 { 53 {
48 m_firstname = firstname; 54 m_firstname = firstname;
49 m_lastname = lastname; 55 m_lastname = lastname;
50 m_startPos = position; 56 m_startPos = position;
51 m_scene = scene; 57 m_scene = scene;
58 m_ownerID = ownerID;
59 SenseAsAgent = senseAsAgent;
52 } 60 }
53 61
54 public IScene Scene 62 public IScene Scene
@@ -56,6 +64,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
56 get { return m_scene; } 64 get { return m_scene; }
57 } 65 }
58 66
67 public UUID OwnerID
68 {
69 get { return m_ownerID; }
70 }
71
59 public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } } 72 public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } }
60 73
61 public void Say(string message) 74 public void Say(string message)
@@ -327,6 +340,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
327 public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest; 340 public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest;
328 public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; 341 public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
329 public event EstateChangeInfo OnEstateChangeInfo; 342 public event EstateChangeInfo OnEstateChangeInfo;
343 public event EstateManageTelehub OnEstateManageTelehub;
330 public event ScriptReset OnScriptReset; 344 public event ScriptReset OnScriptReset;
331 public event GetScriptRunning OnGetScriptRunning; 345 public event GetScriptRunning OnGetScriptRunning;
332 public event SetScriptRunning OnSetScriptRunning; 346 public event SetScriptRunning OnSetScriptRunning;
@@ -916,6 +930,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
916 public void SendEstateCovenantInformation(UUID covenant) 930 public void SendEstateCovenantInformation(UUID covenant)
917 { 931 {
918 } 932 }
933 public void SendTelehubInfo(UUID ObjectID, string ObjectName, Vector3 ObjectPos, Quaternion ObjectRot, List<Vector3> SpawnPoint)
934 {
935 }
919 public void SendDetailedEstateData(UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition, UUID covenant, string abuseEmail, UUID estateOwner) 936 public void SendDetailedEstateData(UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition, UUID covenant, string abuseEmail, UUID estateOwner)
920 { 937 {
921 } 938 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 56ff367..3831d7a 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -56,6 +56,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC
56 } 56 }
57 } 57 }
58 58
59 public void PostInitialise()
60 {
61 }
62
63 public void Close()
64 {
65 }
66
67 public string Name
68 {
69 get { return "NPCModule"; }
70 }
71
72 public bool IsSharedModule
73 {
74 get { return true; }
75 }
76
59 public bool IsNPC(UUID agentId, Scene scene) 77 public bool IsNPC(UUID agentId, Scene scene)
60 { 78 {
61 // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect 79 // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect
@@ -91,9 +109,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC
91 } 109 }
92 110
93 public UUID CreateNPC( 111 public UUID CreateNPC(
94 string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance) 112 string firstname,
113 string lastname,
114 Vector3 position,
115 UUID owner,
116 bool senseAsAgent,
117 Scene scene,
118 AvatarAppearance appearance)
95 { 119 {
96 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); 120 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene);
97 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); 121 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
98 122
99 m_log.DebugFormat( 123 m_log.DebugFormat(
@@ -234,38 +258,69 @@ namespace OpenSim.Region.OptionalModules.World.NPC
234 return false; 258 return false;
235 } 259 }
236 260
237 public bool DeleteNPC(UUID agentID, Scene scene) 261 public UUID GetOwner(UUID agentID)
238 { 262 {
239 lock (m_avatars) 263 lock (m_avatars)
240 { 264 {
241 if (m_avatars.ContainsKey(agentID)) 265 NPCAvatar av;
266 if (m_avatars.TryGetValue(agentID, out av))
242 { 267 {
243 scene.RemoveClient(agentID, false); 268 return av.OwnerID;
244 m_avatars.Remove(agentID);
245
246 return true;
247 } 269 }
248 } 270 }
249 271
250 return false; 272 return UUID.Zero;
251 } 273 }
252 274
253 public void PostInitialise() 275 public INPC GetNPC(UUID agentID, Scene scene)
254 { 276 {
277 lock (m_avatars)
278 {
279 if (m_avatars.ContainsKey(agentID))
280 return m_avatars[agentID];
281 else
282 return null;
283 }
255 } 284 }
256 285
257 public void Close() 286 public bool DeleteNPC(UUID agentID, Scene scene)
258 { 287 {
288 lock (m_avatars)
289 {
290 NPCAvatar av;
291 if (m_avatars.TryGetValue(agentID, out av))
292 {
293 scene.RemoveClient(agentID, false);
294 m_avatars.Remove(agentID);
295
296 return true;
297 }
298 }
299
300 return false;
259 } 301 }
260 302
261 public string Name 303 public bool CheckPermissions(UUID npcID, UUID callerID)
262 { 304 {
263 get { return "NPCModule"; } 305 lock (m_avatars)
306 {
307 NPCAvatar av;
308 if (m_avatars.TryGetValue(npcID, out av))
309 return CheckPermissions(av, callerID);
310 else
311 return false;
312 }
264 } 313 }
265 314
266 public bool IsSharedModule 315 /// <summary>
316 /// Check if the caller has permission to manipulate the given NPC.
317 /// </summary>
318 /// <param name="av"></param>
319 /// <param name="callerID"></param>
320 /// <returns>true if they do, false if they don't.</returns>
321 private bool CheckPermissions(NPCAvatar av, UUID callerID)
267 { 322 {
268 get { return true; } 323 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID;
269 } 324 }
270 } 325 }
271} \ No newline at end of file 326}
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 9c66b25..d507822 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -109,7 +109,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
109 afm.SetAppearance(sp, originalTe, null); 109 afm.SetAppearance(sp, originalTe, null);
110 110
111 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 111 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
112 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); 112 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance);
113 113
114 ScenePresence npc = scene.GetScenePresence(npcId); 114 ScenePresence npc = scene.GetScenePresence(npcId);
115 115
@@ -119,6 +119,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
119 } 119 }
120 120
121 [Test] 121 [Test]
122 public void TestRemove()
123 {
124 TestHelpers.InMethod();
125// log4net.Config.XmlConfigurator.Configure();
126
127 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
128// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
129
130 Vector3 startPos = new Vector3(128, 128, 30);
131 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
132 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance);
133
134 npcModule.DeleteNPC(npcId, scene);
135
136 ScenePresence deletedNpc = scene.GetScenePresence(npcId);
137
138 Assert.That(deletedNpc, Is.Null);
139 }
140
141 [Test]
122 public void TestAttachments() 142 public void TestAttachments()
123 { 143 {
124 TestHelpers.InMethod(); 144 TestHelpers.InMethod();
@@ -137,7 +157,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
137 am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); 157 am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest);
138 158
139 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 159 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
140 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); 160 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance);
141 161
142 ScenePresence npc = scene.GetScenePresence(npcId); 162 ScenePresence npc = scene.GetScenePresence(npcId);
143 163
@@ -169,7 +189,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
169 189
170 Vector3 startPos = new Vector3(128, 128, 30); 190 Vector3 startPos = new Vector3(128, 128, 30);
171 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 191 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
172 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); 192 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance);
173 193
174 ScenePresence npc = scene.GetScenePresence(npcId); 194 ScenePresence npc = scene.GetScenePresence(npcId);
175 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 195 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
@@ -240,7 +260,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
240 260
241 Vector3 startPos = new Vector3(128, 128, 30); 261 Vector3 startPos = new Vector3(128, 128, 30);
242 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 262 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
243 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); 263 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance);
244 264
245 ScenePresence npc = scene.GetScenePresence(npcId); 265 ScenePresence npc = scene.GetScenePresence(npcId);
246 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 266 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
@@ -273,7 +293,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
273 Vector3 startPos = new Vector3(1, 1, 1); 293 Vector3 startPos = new Vector3(1, 1, 1);
274 294
275 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 295 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
276 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); 296 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance);
277 297
278 ScenePresence npc = scene.GetScenePresence(npcId); 298 ScenePresence npc = scene.GetScenePresence(npcId);
279 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 299 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);