aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs135
-rw-r--r--OpenSim/Region/Framework/Interfaces/INPCModule.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IUserManagement.cs2
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs52
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs84
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs15
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs170
11 files changed, 360 insertions, 137 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
index 37292d6..80ab30c 100644
--- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
@@ -413,68 +413,71 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
413 user.Id = uuid; 413 user.Id = uuid;
414 user.FirstName = first; 414 user.FirstName = first;
415 user.LastName = last; 415 user.LastName = last;
416 // user.ProfileURL = we should initialize this to the default
417 416
418 AddUserInternal(user); 417 AddUserInternal(user);
419 } 418 }
420 419
421 public void AddUser(UUID uuid, string first, string last, string profileURL) 420 public void AddUser(UUID uuid, string first, string last, string homeURL)
422 { 421 {
423 AddUser(uuid, profileURL + ";" + first + " " + last); 422 AddUser(uuid, homeURL + ";" + first + " " + last);
424 } 423 }
425 424
426 public void AddUser(UUID id, string creatorData) 425 public void AddUser (UUID id, string creatorData)
427 { 426 {
428 lock (m_UserCache) 427 UserData oldUser;
429 { 428 //lock the whole block - prevent concurrent update
430 if (m_UserCache.ContainsKey(id)) 429 lock (m_UserCache) {
431 return; 430 m_UserCache.TryGetValue (id, out oldUser);
432 } 431 if (oldUser != null) {
433 432 if (creatorData == null || creatorData == String.Empty) {
434// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, craetorData {1}", id, creatorData); 433 //ignore updates without creator data
435 434 return;
436 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id); 435 }
437 436 //try update unknown users
438 if (account != null) 437 //and creator's home URL's
439 { 438 if ((oldUser.FirstName == "Unknown" && !creatorData.Contains ("Unknown")) || (oldUser.HomeURL != null && !creatorData.StartsWith (oldUser.HomeURL))) {
440 AddUser(id, account.FirstName, account.LastName); 439 m_UserCache.Remove (id);
441 } 440// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData,oldUser.HomeURL);
442 else 441 } else {
443 { 442 //we have already a valid user within the cache
444 UserData user = new UserData(); 443 return;
445 user.Id = id;
446 user.Flags = -1;
447 user.Created = -1;
448
449 if (creatorData != null && creatorData != string.Empty)
450 {
451 //creatorData = <endpoint>;<name>
452
453 string[] parts = creatorData.Split(';');
454 if (parts.Length >= 1)
455 {
456 user.HomeURL = parts[0];
457 try
458 {
459 Uri uri = new Uri(parts[0]);
460 user.LastName = "@" + uri.Authority;
461 }
462 catch (UriFormatException)
463 {
464 m_log.DebugFormat("[SCENE]: Unable to parse Uri {0}", parts[0]);
465 user.LastName = "@unknown";
466 }
467 } 444 }
468 if (parts.Length >= 2)
469 user.FirstName = parts[1].Replace(' ', '.');
470 } 445 }
471 else 446// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData);
472 { 447
473 user.FirstName = "Unknown"; 448 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount (m_Scenes[0].RegionInfo.ScopeID, id);
474 user.LastName = "User"; 449
450 if (account != null) {
451 AddUser (id, account.FirstName, account.LastName);
452 } else {
453 UserData user = new UserData ();
454 user.Id = id;
455 user.Flags = -1;
456 user.Created = -1;
457
458 if (creatorData != null && creatorData != string.Empty) {
459 //creatorData = <endpoint>;<name>
460
461 string[] parts = creatorData.Split (';');
462 if (parts.Length >= 1) {
463 user.HomeURL = parts[0];
464 try {
465 Uri uri = new Uri (parts[0]);
466 user.LastName = "@" + uri.Authority;
467 } catch (UriFormatException) {
468 m_log.DebugFormat ("[SCENE]: Unable to parse Uri {0}", parts[0]);
469 user.LastName = "@unknown";
470 }
471 }
472 if (parts.Length >= 2)
473 user.FirstName = parts[1].Replace (' ', '.');
474 } else {
475 user.FirstName = "Unknown";
476 user.LastName = "User";
477 }
478
479 AddUserInternal (user);
475 } 480 }
476
477 AddUserInternal(user);
478 } 481 }
479 } 482 }
480 483
@@ -488,36 +491,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
488// user.Id, user.FirstName, user.LastName, user.HomeURL); 491// user.Id, user.FirstName, user.LastName, user.HomeURL);
489 } 492 }
490 493
491 //public void AddUser(UUID uuid, string userData)
492 //{
493 // if (m_UserCache.ContainsKey(uuid))
494 // return;
495
496 // UserData user = new UserData();
497 // user.Id = uuid;
498
499 // // userData = <profile url>;<name>
500 // string[] parts = userData.Split(';');
501 // if (parts.Length >= 1)
502 // user.ProfileURL = parts[0].Trim();
503 // if (parts.Length >= 2)
504 // {
505 // string[] name = parts[1].Trim().Split(' ');
506 // if (name.Length >= 1)
507 // user.FirstName = name[0];
508 // if (name.Length >= 2)
509 // user.LastName = name[1];
510 // else
511 // user.LastName = "?";
512 // }
513
514 // lock (m_UserCache)
515 // m_UserCache.Add(uuid, user);
516
517 // m_log.DebugFormat("[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}", user.Id, user.FirstName, user.LastName, user.ProfileURL);
518
519 //}
520
521 public bool IsLocalGridUser(UUID uuid) 494 public bool IsLocalGridUser(UUID uuid)
522 { 495 {
523 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid); 496 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
index cac8479..c50e734 100644
--- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
@@ -53,6 +53,14 @@ namespace OpenSim.Region.Framework.Interfaces
53 bool IsNPC(UUID agentID, Scene scene); 53 bool IsNPC(UUID agentID, Scene scene);
54 54
55 /// <summary> 55 /// <summary>
56 /// Check if the caller has permission to manipulate the given NPC.
57 /// </summary>
58 /// <param name="npcID"></param>
59 /// <param name="callerID"></param>
60 /// <returns>true if they do, false if they don't or if there's no NPC with the given ID.</returns>
61 bool CheckPermissions(UUID npcID, UUID callerID);
62
63 /// <summary>
56 /// Set the appearance for an NPC. 64 /// Set the appearance for an NPC.
57 /// </summary> 65 /// </summary>
58 /// <param name="agentID"></param> 66 /// <param name="agentID"></param>
@@ -117,7 +125,7 @@ namespace OpenSim.Region.Framework.Interfaces
117 /// <param name="agentID">The UUID of the NPC</param> 125 /// <param name="agentID">The UUID of the NPC</param>
118 /// <param name="scene"></param> 126 /// <param name="scene"></param>
119 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns> 127 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
120 bool DeleteNPC(UUID agentID, UUID CallerID, Scene scene); 128 bool DeleteNPC(UUID agentID, Scene scene);
121 129
122 /// <summary> 130 /// <summary>
123 /// Get the owner of a NPC 131 /// Get the owner of a NPC
diff --git a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs
index 54dfaf4..4f62e28 100644
--- a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs
+++ b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Interfaces
50 /// <param name="uuid"></param> 50 /// <param name="uuid"></param>
51 /// <param name="firstName"></param> 51 /// <param name="firstName"></param>
52 /// <param name="profileURL"></param> 52 /// <param name="profileURL"></param>
53 void AddUser(UUID uuid, string firstName, string lastName, string profileURL); 53 void AddUser(UUID uuid, string firstName, string lastName, string homeURL);
54 54
55 bool IsLocalGridUser(UUID uuid); 55 bool IsLocalGridUser(UUID uuid);
56 } 56 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index e874417..d90309f 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
@@ -248,16 +266,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
248 return UUID.Zero; 266 return UUID.Zero;
249 } 267 }
250 268
251 public bool DeleteNPC(UUID agentID, UUID callerID, Scene scene) 269 public bool DeleteNPC(UUID agentID, Scene scene)
252 { 270 {
253 lock (m_avatars) 271 lock (m_avatars)
254 { 272 {
255 NPCAvatar av; 273 NPCAvatar av;
256 if (m_avatars.TryGetValue(agentID, out av)) 274 if (m_avatars.TryGetValue(agentID, out av))
257 { 275 {
258 if (av.OwnerID != UUID.Zero && callerID != UUID.Zero && av.OwnerID != callerID)
259 return false;
260
261 scene.RemoveClient(agentID, false); 276 scene.RemoveClient(agentID, false);
262 m_avatars.Remove(agentID); 277 m_avatars.Remove(agentID);
263 278
@@ -268,22 +283,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
268 return false; 283 return false;
269 } 284 }
270 285
271 public void PostInitialise() 286 public bool CheckPermissions(UUID npcID, UUID callerID)
272 {
273 }
274
275 public void Close()
276 {
277 }
278
279 public string Name
280 { 287 {
281 get { return "NPCModule"; } 288 lock (m_avatars)
289 {
290 NPCAvatar av;
291 if (m_avatars.TryGetValue(npcID, out av))
292 return CheckPermissions(av, callerID);
293 else
294 return false;
295 }
282 } 296 }
283 297
284 public bool IsSharedModule 298 /// <summary>
299 /// Check if the caller has permission to manipulate the given NPC.
300 /// </summary>
301 /// <param name="av"></param>
302 /// <param name="callerID"></param>
303 /// <returns>true if they do, false if they don't.</returns>
304 private bool CheckPermissions(NPCAvatar av, UUID callerID)
285 { 305 {
286 get { return true; } 306 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID;
287 } 307 }
288 } 308 }
289} 309}
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 571d33d..d21d601 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -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, 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();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e2a045b..40d9d6f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -2077,16 +2077,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2077 return retVal; 2077 return retVal;
2078 } 2078 }
2079 2079
2080 public LSL_Key osNpcCreateOwned(string firstname, string lastname, LSL_Vector position, string notecard) 2080 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
2081 { 2081 {
2082 CheckThreatLevel(ThreatLevel.High, "osNpcCreateOwned"); 2082 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2083 return NpcCreate(firstname, lastname, position, notecard, true); 2083 return NpcCreate(firstname, lastname, position, notecard, true);
2084 } 2084 }
2085 2085
2086 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) 2086 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
2087 { 2087 {
2088 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 2088 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2089 return NpcCreate(firstname, lastname, position, notecard, false); 2089 return NpcCreate(firstname, lastname, position, notecard, (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0);
2090 } 2090 }
2091 2091
2092 private LSL_Key NpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, bool owned) 2092 private LSL_Key NpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, bool owned)
@@ -2152,11 +2152,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2152 if (!UUID.TryParse(npc.m_string, out npcId)) 2152 if (!UUID.TryParse(npc.m_string, out npcId))
2153 return new LSL_Key(UUID.Zero.ToString()); 2153 return new LSL_Key(UUID.Zero.ToString());
2154 2154
2155 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) 2155 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2156 return new LSL_Key(UUID.Zero.ToString());
2157
2158 UUID ownerID = npcModule.GetOwner(npcId);
2159 if (ownerID != UUID.Zero && ownerID != m_host.OwnerID)
2160 return new LSL_Key(UUID.Zero.ToString()); 2156 return new LSL_Key(UUID.Zero.ToString());
2161 2157
2162 return SaveAppearanceToNotecard(npcId, notecard); 2158 return SaveAppearanceToNotecard(npcId, notecard);
@@ -2177,6 +2173,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2177 if (!UUID.TryParse(npc.m_string, out npcId)) 2173 if (!UUID.TryParse(npc.m_string, out npcId))
2178 return; 2174 return;
2179 2175
2176 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2177 return;
2178
2180 string appearanceSerialized = LoadNotecard(notecard); 2179 string appearanceSerialized = LoadNotecard(notecard);
2181 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2180 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2182// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); 2181// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
@@ -2200,7 +2199,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2200 if (!UUID.TryParse(npc.m_string, out npcId)) 2199 if (!UUID.TryParse(npc.m_string, out npcId))
2201 return new LSL_Vector(0, 0, 0); 2200 return new LSL_Vector(0, 0, 0);
2202 2201
2203 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) 2202 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2204 return new LSL_Vector(0, 0, 0); 2203 return new LSL_Vector(0, 0, 0);
2205 2204
2206 Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition; 2205 Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition;
@@ -2220,6 +2219,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2220 UUID npcId; 2219 UUID npcId;
2221 if (!UUID.TryParse(npc.m_string, out npcId)) 2220 if (!UUID.TryParse(npc.m_string, out npcId))
2222 return; 2221 return;
2222
2223 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2224 return;
2223 2225
2224 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2226 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2225 module.MoveToTarget(npcId, World, pos, false, true); 2227 module.MoveToTarget(npcId, World, pos, false, true);
@@ -2237,6 +2239,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2237 if (!UUID.TryParse(npc.m_string, out npcId)) 2239 if (!UUID.TryParse(npc.m_string, out npcId))
2238 return; 2240 return;
2239 2241
2242 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2243 return;
2244
2240 Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); 2245 Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z);
2241 module.MoveToTarget( 2246 module.MoveToTarget(
2242 new UUID(npc.m_string), 2247 new UUID(npc.m_string),
@@ -2258,7 +2263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2258 if (!UUID.TryParse(npc.m_string, out npcId)) 2263 if (!UUID.TryParse(npc.m_string, out npcId))
2259 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); 2264 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2260 2265
2261 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) 2266 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2262 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); 2267 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2263 2268
2264 ScenePresence sp = World.GetScenePresence(npcId); 2269 ScenePresence sp = World.GetScenePresence(npcId);
@@ -2281,7 +2286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2281 if (!UUID.TryParse(npc.m_string, out npcId)) 2286 if (!UUID.TryParse(npc.m_string, out npcId))
2282 return; 2287 return;
2283 2288
2284 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) 2289 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2285 return; 2290 return;
2286 2291
2287 ScenePresence sp = World.GetScenePresence(npcId); 2292 ScenePresence sp = World.GetScenePresence(npcId);
@@ -2295,7 +2300,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2295 2300
2296 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2301 INPCModule module = World.RequestModuleInterface<INPCModule>();
2297 if (module != null) 2302 if (module != null)
2298 module.StopMoveToTarget(new UUID(npc.m_string), World); 2303 {
2304 UUID npcId = new UUID(npc.m_string);
2305
2306 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2307 return;
2308
2309 module.StopMoveToTarget(npcId, World);
2310 }
2299 } 2311 }
2300 2312
2301 public void osNpcSay(LSL_Key npc, string message) 2313 public void osNpcSay(LSL_Key npc, string message)
@@ -2305,7 +2317,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2305 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2317 INPCModule module = World.RequestModuleInterface<INPCModule>();
2306 if (module != null) 2318 if (module != null)
2307 { 2319 {
2308 module.Say(new UUID(npc.m_string), World, message); 2320 UUID npcId = new UUID(npc.m_string);
2321
2322 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2323 return;
2324
2325 module.Say(npcId, World, message);
2309 } 2326 }
2310 } 2327 }
2311 2328
@@ -2316,7 +2333,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2316 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2333 INPCModule module = World.RequestModuleInterface<INPCModule>();
2317 if (module != null) 2334 if (module != null)
2318 { 2335 {
2319 module.Sit(new UUID(npc.m_string), new UUID(target.m_string), World); 2336 UUID npcId = new UUID(npc.m_string);
2337
2338 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2339 return;
2340
2341 module.Sit(npcId, new UUID(target.m_string), World);
2320 } 2342 }
2321 } 2343 }
2322 2344
@@ -2327,7 +2349,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2327 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2349 INPCModule module = World.RequestModuleInterface<INPCModule>();
2328 if (module != null) 2350 if (module != null)
2329 { 2351 {
2330 module.Stand(new UUID(npc.m_string), World); 2352 UUID npcId = new UUID(npc.m_string);
2353
2354 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2355 return;
2356
2357 module.Stand(npcId, World);
2331 } 2358 }
2332 } 2359 }
2333 2360
@@ -2338,7 +2365,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2338 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2365 INPCModule module = World.RequestModuleInterface<INPCModule>();
2339 if (module != null) 2366 if (module != null)
2340 { 2367 {
2341 module.DeleteNPC(new UUID(npc.m_string), m_host.OwnerID, World); 2368 UUID npcId = new UUID(npc.m_string);
2369
2370 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2371 return;
2372
2373 module.DeleteNPC(npcId, World);
2342 } 2374 }
2343 } 2375 }
2344 2376
@@ -2350,12 +2382,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2350 if (module != null) 2382 if (module != null)
2351 { 2383 {
2352 UUID npcID = new UUID(npc.m_string); 2384 UUID npcID = new UUID(npc.m_string);
2353 if (module.IsNPC(npcID, m_host.ParentGroup.Scene)) 2385
2354 { 2386 if (module.CheckPermissions(npcID, m_host.OwnerID))
2355 UUID ownerID = module.GetOwner(npcID); 2387 AvatarPlayAnimation(npcID.ToString(), animation);
2356 if (ownerID == UUID.Zero || ownerID == m_host.OwnerID)
2357 AvatarPlayAnimation(npcID.ToString(), animation);
2358 }
2359 } 2388 }
2360 } 2389 }
2361 2390
@@ -2367,12 +2396,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2367 if (module != null) 2396 if (module != null)
2368 { 2397 {
2369 UUID npcID = new UUID(npc.m_string); 2398 UUID npcID = new UUID(npc.m_string);
2370 if (module.IsNPC(npcID, m_host.ParentGroup.Scene)) 2399
2371 { 2400 if (module.CheckPermissions(npcID, m_host.OwnerID))
2372 UUID ownerID = module.GetOwner(npcID); 2401 AvatarPlayAnimation(npcID.ToString(), animation);
2373 if (ownerID == UUID.Zero || ownerID == m_host.OwnerID)
2374 AvatarStopAnimation(npcID.ToString(), animation);
2375 }
2376 } 2402 }
2377 } 2403 }
2378 2404
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 7d7813d..8356dce 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -463,12 +463,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
463 toRegionPos = presence.AbsolutePosition; 463 toRegionPos = presence.AbsolutePosition;
464 dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); 464 dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));
465 465
466 if (presence.PresenceType == PresenceType.Npc && npcModule != null) 466 // Disabled for now since all osNpc* methods check for appropriate ownership permission.
467 { 467 // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
468 UUID npcOwner = npcModule.GetOwner(presence.UUID); 468 // sensed might be useful.
469 if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID) 469// if (presence.PresenceType == PresenceType.Npc && npcModule != null)
470 return; 470// {
471 } 471// UUID npcOwner = npcModule.GetOwner(presence.UUID);
472// if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
473// return;
474// }
472 475
473 // are they in range 476 // are they in range
474 if (dis <= ts.range) 477 if (dis <= ts.range)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index f92f51f..af6be5f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -172,7 +172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
172 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); 172 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
173 173
174 key osNpcCreate(string user, string name, vector position, string notecard); 174 key osNpcCreate(string user, string name, vector position, string notecard);
175 key osNpcCreateOwned(string user, string name, vector position, string notecard); 175 key osNpcCreate(string user, string name, vector position, string notecard, int options);
176 LSL_Key osNpcSaveAppearance(key npc, string notecard); 176 LSL_Key osNpcSaveAppearance(key npc, string notecard);
177 void osNpcLoadAppearance(key npc, string notecard); 177 void osNpcLoadAppearance(key npc, string notecard);
178 vector osNpcGetPos(key npc); 178 vector osNpcGetPos(key npc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index b58cf57..176dc56 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -606,6 +606,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
606 606
607 public const int OS_NPC_SIT_NOW = 0; 607 public const int OS_NPC_SIT_NOW = 0;
608 608
609 public const int OS_NPC_CREATOR_OWNED = 0x1;
610 public const int OS_NPC_NOT_OWNED = 0x2;
611
609 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; 612 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
610 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; 613 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
611 614
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index a94392a..0c05ea4 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -488,9 +488,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
488 return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); 488 return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom);
489 } 489 }
490 490
491 public key osNpcCreateOwned(string user, string name, vector position, key cloneFrom) 491 public key osNpcCreate(string user, string name, vector position, key cloneFrom, int options)
492 { 492 {
493 return m_OSSL_Functions.osNpcCreateOwned(user, name, position, cloneFrom); 493 return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom, options);
494 } 494 }
495 495
496 public key osNpcSaveAppearance(key npc, string notecard) 496 public key osNpcSaveAppearance(key npc, string notecard)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
new file mode 100644
index 0000000..9d9fc51
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -0,0 +1,170 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
45using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock;
48
49namespace OpenSim.Region.ScriptEngine.Shared.Tests
50{
51 /// <summary>
52 /// Tests for OSSL NPC API
53 /// </summary>
54 [TestFixture]
55 public class OSSL_NpcApiAppearanceTest
56 {
57 protected Scene m_scene;
58 protected XEngine.XEngine m_engine;
59
60 [SetUp]
61 public void SetUp()
62 {
63 IConfigSource initConfigSource = new IniConfigSource();
64 IConfig config = initConfigSource.AddConfig("XEngine");
65 config.Set("Enabled", "true");
66 config.Set("AllowOSFunctions", "true");
67 config.Set("OSFunctionThreatLevel", "Severe");
68 config = initConfigSource.AddConfig("NPC");
69 config.Set("Enabled", "true");
70
71 m_scene = SceneHelpers.SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
73
74 m_engine = new XEngine.XEngine();
75 m_engine.Initialise(initConfigSource);
76 m_engine.AddRegion(m_scene);
77 }
78
79 /// <summary>
80 /// Test removal of an owned NPC.
81 /// </summary>
82 [Test]
83 public void TestOsNpcRemoveOwned()
84 {
85 TestHelpers.InMethod();
86// log4net.Config.XmlConfigurator.Configure();
87
88 // Store an avatar with a different height from default in a notecard.
89 UUID userId = TestHelpers.ParseTail(0x1);
90 UUID otherUserId = TestHelpers.ParseTail(0x2);
91 float newHeight = 1.9f;
92
93 SceneHelpers.AddScenePresence(m_scene, otherUserId);
94
95 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
96 sp.Appearance.AvatarHeight = newHeight;
97
98 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
99 SceneObjectPart part = so.RootPart;
100 m_scene.AddSceneObject(so);
101
102 SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId);
103 SceneObjectPart otherPart = otherSo.RootPart;
104 m_scene.AddSceneObject(otherSo);
105
106 OSSL_Api osslApi = new OSSL_Api();
107 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
108
109 OSSL_Api otherOsslApi = new OSSL_Api();
110 otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID);
111
112 string notecardName = "appearanceNc";
113 osslApi.osOwnerSaveAppearance(notecardName);
114
115 string npcRaw
116 = osslApi.osNpcCreate(
117 "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED);
118
119 otherOsslApi.osNpcRemove(npcRaw);
120
121 // Should still be around
122 UUID npcId = new UUID(npcRaw);
123 ScenePresence npc = m_scene.GetScenePresence(npcId);
124 Assert.That(npc, Is.Not.Null);
125
126 osslApi.osNpcRemove(npcRaw);
127
128 npc = m_scene.GetScenePresence(npcId);
129
130 // Now the owner deleted it and it's gone
131 Assert.That(npc, Is.Null);
132 }
133
134 /// <summary>
135 /// Test removal of an unowned NPC.
136 /// </summary>
137 [Test]
138 public void TestOsNpcRemoveUnowned()
139 {
140 TestHelpers.InMethod();
141// log4net.Config.XmlConfigurator.Configure();
142
143 // Store an avatar with a different height from default in a notecard.
144 UUID userId = TestHelpers.ParseTail(0x1);
145 float newHeight = 1.9f;
146
147 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
148 sp.Appearance.AvatarHeight = newHeight;
149 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
150 SceneObjectPart part = so.RootPart;
151 m_scene.AddSceneObject(so);
152
153 OSSL_Api osslApi = new OSSL_Api();
154 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
155
156 string notecardName = "appearanceNc";
157 osslApi.osOwnerSaveAppearance(notecardName);
158
159 string npcRaw
160 = osslApi.osNpcCreate(
161 "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED);
162
163 osslApi.osNpcRemove(npcRaw);
164
165 UUID npcId = new UUID(npcRaw);
166 ScenePresence npc = m_scene.GetScenePresence(npcId);
167 Assert.That(npc, Is.Null);
168 }
169 }
170} \ No newline at end of file