Merge branch 'master' of /home/opensim/var/repo/opensim
commit
acbff305f5
|
@ -413,68 +413,71 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
|||
user.Id = uuid;
|
||||
user.FirstName = first;
|
||||
user.LastName = last;
|
||||
// user.ProfileURL = we should initialize this to the default
|
||||
|
||||
AddUserInternal(user);
|
||||
}
|
||||
|
||||
public void AddUser(UUID uuid, string first, string last, string profileURL)
|
||||
public void AddUser(UUID uuid, string first, string last, string homeURL)
|
||||
{
|
||||
AddUser(uuid, profileURL + ";" + first + " " + last);
|
||||
AddUser(uuid, homeURL + ";" + first + " " + last);
|
||||
}
|
||||
|
||||
public void AddUser(UUID id, string creatorData)
|
||||
public void AddUser (UUID id, string creatorData)
|
||||
{
|
||||
lock (m_UserCache)
|
||||
{
|
||||
if (m_UserCache.ContainsKey(id))
|
||||
UserData oldUser;
|
||||
//lock the whole block - prevent concurrent update
|
||||
lock (m_UserCache) {
|
||||
m_UserCache.TryGetValue (id, out oldUser);
|
||||
if (oldUser != null) {
|
||||
if (creatorData == null || creatorData == String.Empty) {
|
||||
//ignore updates without creator data
|
||||
return;
|
||||
}
|
||||
|
||||
// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, craetorData {1}", id, creatorData);
|
||||
|
||||
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id);
|
||||
|
||||
if (account != null)
|
||||
{
|
||||
AddUser(id, account.FirstName, account.LastName);
|
||||
//try update unknown users
|
||||
//and creator's home URL's
|
||||
if ((oldUser.FirstName == "Unknown" && !creatorData.Contains ("Unknown")) || (oldUser.HomeURL != null && !creatorData.StartsWith (oldUser.HomeURL))) {
|
||||
m_UserCache.Remove (id);
|
||||
// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData,oldUser.HomeURL);
|
||||
} else {
|
||||
//we have already a valid user within the cache
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserData user = new UserData();
|
||||
}
|
||||
// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData);
|
||||
|
||||
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount (m_Scenes[0].RegionInfo.ScopeID, id);
|
||||
|
||||
if (account != null) {
|
||||
AddUser (id, account.FirstName, account.LastName);
|
||||
} else {
|
||||
UserData user = new UserData ();
|
||||
user.Id = id;
|
||||
user.Flags = -1;
|
||||
user.Created = -1;
|
||||
|
||||
if (creatorData != null && creatorData != string.Empty)
|
||||
{
|
||||
if (creatorData != null && creatorData != string.Empty) {
|
||||
//creatorData = <endpoint>;<name>
|
||||
|
||||
string[] parts = creatorData.Split(';');
|
||||
if (parts.Length >= 1)
|
||||
{
|
||||
string[] parts = creatorData.Split (';');
|
||||
if (parts.Length >= 1) {
|
||||
user.HomeURL = parts[0];
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(parts[0]);
|
||||
try {
|
||||
Uri uri = new Uri (parts[0]);
|
||||
user.LastName = "@" + uri.Authority;
|
||||
}
|
||||
catch (UriFormatException)
|
||||
{
|
||||
m_log.DebugFormat("[SCENE]: Unable to parse Uri {0}", parts[0]);
|
||||
} catch (UriFormatException) {
|
||||
m_log.DebugFormat ("[SCENE]: Unable to parse Uri {0}", parts[0]);
|
||||
user.LastName = "@unknown";
|
||||
}
|
||||
}
|
||||
if (parts.Length >= 2)
|
||||
user.FirstName = parts[1].Replace(' ', '.');
|
||||
}
|
||||
else
|
||||
{
|
||||
user.FirstName = parts[1].Replace (' ', '.');
|
||||
} else {
|
||||
user.FirstName = "Unknown";
|
||||
user.LastName = "User";
|
||||
}
|
||||
|
||||
AddUserInternal(user);
|
||||
AddUserInternal (user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,36 +491,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
|||
// user.Id, user.FirstName, user.LastName, user.HomeURL);
|
||||
}
|
||||
|
||||
//public void AddUser(UUID uuid, string userData)
|
||||
//{
|
||||
// if (m_UserCache.ContainsKey(uuid))
|
||||
// return;
|
||||
|
||||
// UserData user = new UserData();
|
||||
// user.Id = uuid;
|
||||
|
||||
// // userData = <profile url>;<name>
|
||||
// string[] parts = userData.Split(';');
|
||||
// if (parts.Length >= 1)
|
||||
// user.ProfileURL = parts[0].Trim();
|
||||
// if (parts.Length >= 2)
|
||||
// {
|
||||
// string[] name = parts[1].Trim().Split(' ');
|
||||
// if (name.Length >= 1)
|
||||
// user.FirstName = name[0];
|
||||
// if (name.Length >= 2)
|
||||
// user.LastName = name[1];
|
||||
// else
|
||||
// user.LastName = "?";
|
||||
// }
|
||||
|
||||
// lock (m_UserCache)
|
||||
// m_UserCache.Add(uuid, user);
|
||||
|
||||
// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}", user.Id, user.FirstName, user.LastName, user.ProfileURL);
|
||||
|
||||
//}
|
||||
|
||||
public bool IsLocalGridUser(UUID uuid)
|
||||
{
|
||||
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
|
||||
|
|
|
@ -52,6 +52,14 @@ namespace OpenSim.Region.Framework.Interfaces
|
|||
/// <returns>True if the agent is an NPC in the given scene. False otherwise.</returns>
|
||||
bool IsNPC(UUID agentID, Scene scene);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the caller has permission to manipulate the given NPC.
|
||||
/// </summary>
|
||||
/// <param name="npcID"></param>
|
||||
/// <param name="callerID"></param>
|
||||
/// <returns>true if they do, false if they don't or if there's no NPC with the given ID.</returns>
|
||||
bool CheckPermissions(UUID npcID, UUID callerID);
|
||||
|
||||
/// <summary>
|
||||
/// Set the appearance for an NPC.
|
||||
/// </summary>
|
||||
|
@ -117,7 +125,7 @@ namespace OpenSim.Region.Framework.Interfaces
|
|||
/// <param name="agentID">The UUID of the NPC</param>
|
||||
/// <param name="scene"></param>
|
||||
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
|
||||
bool DeleteNPC(UUID agentID, UUID CallerID, Scene scene);
|
||||
bool DeleteNPC(UUID agentID, Scene scene);
|
||||
|
||||
/// <summary>
|
||||
/// Get the owner of a NPC
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace OpenSim.Region.Framework.Interfaces
|
|||
/// <param name="uuid"></param>
|
||||
/// <param name="firstName"></param>
|
||||
/// <param name="profileURL"></param>
|
||||
void AddUser(UUID uuid, string firstName, string lastName, string profileURL);
|
||||
void AddUser(UUID uuid, string firstName, string lastName, string homeURL);
|
||||
|
||||
bool IsLocalGridUser(UUID uuid);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
|||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "NPCModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsNPC(UUID agentId, Scene scene)
|
||||
{
|
||||
// FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect
|
||||
|
@ -248,16 +266,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
|||
return UUID.Zero;
|
||||
}
|
||||
|
||||
public bool DeleteNPC(UUID agentID, UUID callerID, Scene scene)
|
||||
public bool DeleteNPC(UUID agentID, Scene scene)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
NPCAvatar av;
|
||||
if (m_avatars.TryGetValue(agentID, out av))
|
||||
{
|
||||
if (av.OwnerID != UUID.Zero && callerID != UUID.Zero && av.OwnerID != callerID)
|
||||
return false;
|
||||
|
||||
scene.RemoveClient(agentID, false);
|
||||
m_avatars.Remove(agentID);
|
||||
|
||||
|
@ -268,22 +283,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
|||
return false;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
public bool CheckPermissions(UUID npcID, UUID callerID)
|
||||
{
|
||||
lock (m_avatars)
|
||||
{
|
||||
NPCAvatar av;
|
||||
if (m_avatars.TryGetValue(npcID, out av))
|
||||
return CheckPermissions(av, callerID);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
/// <summary>
|
||||
/// Check if the caller has permission to manipulate the given NPC.
|
||||
/// </summary>
|
||||
/// <param name="av"></param>
|
||||
/// <param name="callerID"></param>
|
||||
/// <returns>true if they do, false if they don't.</returns>
|
||||
private bool CheckPermissions(NPCAvatar av, UUID callerID)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "NPCModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
|||
Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRemove()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
|
||||
// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
|
||||
|
||||
Vector3 startPos = new Vector3(128, 128, 30);
|
||||
INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
|
||||
UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance);
|
||||
|
||||
npcModule.DeleteNPC(npcId, scene);
|
||||
|
||||
ScenePresence deletedNpc = scene.GetScenePresence(npcId);
|
||||
|
||||
Assert.That(deletedNpc, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAttachments()
|
||||
{
|
||||
|
|
|
@ -2077,16 +2077,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
return retVal;
|
||||
}
|
||||
|
||||
public LSL_Key osNpcCreateOwned(string firstname, string lastname, LSL_Vector position, string notecard)
|
||||
{
|
||||
CheckThreatLevel(ThreatLevel.High, "osNpcCreateOwned");
|
||||
return NpcCreate(firstname, lastname, position, notecard, true);
|
||||
}
|
||||
|
||||
public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
|
||||
{
|
||||
CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
|
||||
return NpcCreate(firstname, lastname, position, notecard, false);
|
||||
return NpcCreate(firstname, lastname, position, notecard, true);
|
||||
}
|
||||
|
||||
public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
|
||||
{
|
||||
CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
|
||||
return NpcCreate(firstname, lastname, position, notecard, (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0);
|
||||
}
|
||||
|
||||
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
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return new LSL_Key(UUID.Zero.ToString());
|
||||
|
||||
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
|
||||
return new LSL_Key(UUID.Zero.ToString());
|
||||
|
||||
UUID ownerID = npcModule.GetOwner(npcId);
|
||||
if (ownerID != UUID.Zero && ownerID != m_host.OwnerID)
|
||||
if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return new LSL_Key(UUID.Zero.ToString());
|
||||
|
||||
return SaveAppearanceToNotecard(npcId, notecard);
|
||||
|
@ -2177,6 +2173,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return;
|
||||
|
||||
if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
string appearanceSerialized = LoadNotecard(notecard);
|
||||
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
||||
// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
||||
|
@ -2200,7 +2199,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return new LSL_Vector(0, 0, 0);
|
||||
|
||||
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
|
||||
if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return new LSL_Vector(0, 0, 0);
|
||||
|
||||
Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition;
|
||||
|
@ -2221,6 +2220,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return;
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
|
||||
module.MoveToTarget(npcId, World, pos, false, true);
|
||||
}
|
||||
|
@ -2237,6 +2239,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return;
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z);
|
||||
module.MoveToTarget(
|
||||
new UUID(npc.m_string),
|
||||
|
@ -2258,7 +2263,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
|
||||
|
||||
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
|
||||
if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
|
||||
|
||||
ScenePresence sp = World.GetScenePresence(npcId);
|
||||
|
@ -2281,7 +2286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (!UUID.TryParse(npc.m_string, out npcId))
|
||||
return;
|
||||
|
||||
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
|
||||
if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
ScenePresence sp = World.GetScenePresence(npcId);
|
||||
|
@ -2295,7 +2300,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
|
||||
INPCModule module = World.RequestModuleInterface<INPCModule>();
|
||||
if (module != null)
|
||||
module.StopMoveToTarget(new UUID(npc.m_string), World);
|
||||
{
|
||||
UUID npcId = new UUID(npc.m_string);
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
module.StopMoveToTarget(npcId, World);
|
||||
}
|
||||
}
|
||||
|
||||
public void osNpcSay(LSL_Key npc, string message)
|
||||
|
@ -2305,7 +2317,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
INPCModule module = World.RequestModuleInterface<INPCModule>();
|
||||
if (module != null)
|
||||
{
|
||||
module.Say(new UUID(npc.m_string), World, message);
|
||||
UUID npcId = new UUID(npc.m_string);
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
module.Say(npcId, World, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2316,7 +2333,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
INPCModule module = World.RequestModuleInterface<INPCModule>();
|
||||
if (module != null)
|
||||
{
|
||||
module.Sit(new UUID(npc.m_string), new UUID(target.m_string), World);
|
||||
UUID npcId = new UUID(npc.m_string);
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
module.Sit(npcId, new UUID(target.m_string), World);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2327,7 +2349,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
INPCModule module = World.RequestModuleInterface<INPCModule>();
|
||||
if (module != null)
|
||||
{
|
||||
module.Stand(new UUID(npc.m_string), World);
|
||||
UUID npcId = new UUID(npc.m_string);
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
module.Stand(npcId, World);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2338,7 +2365,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
INPCModule module = World.RequestModuleInterface<INPCModule>();
|
||||
if (module != null)
|
||||
{
|
||||
module.DeleteNPC(new UUID(npc.m_string), m_host.OwnerID, World);
|
||||
UUID npcId = new UUID(npc.m_string);
|
||||
|
||||
if (!module.CheckPermissions(npcId, m_host.OwnerID))
|
||||
return;
|
||||
|
||||
module.DeleteNPC(npcId, World);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2350,14 +2382,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (module != null)
|
||||
{
|
||||
UUID npcID = new UUID(npc.m_string);
|
||||
if (module.IsNPC(npcID, m_host.ParentGroup.Scene))
|
||||
{
|
||||
UUID ownerID = module.GetOwner(npcID);
|
||||
if (ownerID == UUID.Zero || ownerID == m_host.OwnerID)
|
||||
|
||||
if (module.CheckPermissions(npcID, m_host.OwnerID))
|
||||
AvatarPlayAnimation(npcID.ToString(), animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void osNpcStopAnimation(LSL_Key npc, string animation)
|
||||
{
|
||||
|
@ -2367,12 +2396,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
if (module != null)
|
||||
{
|
||||
UUID npcID = new UUID(npc.m_string);
|
||||
if (module.IsNPC(npcID, m_host.ParentGroup.Scene))
|
||||
{
|
||||
UUID ownerID = module.GetOwner(npcID);
|
||||
if (ownerID == UUID.Zero || ownerID == m_host.OwnerID)
|
||||
AvatarStopAnimation(npcID.ToString(), animation);
|
||||
}
|
||||
|
||||
if (module.CheckPermissions(npcID, m_host.OwnerID))
|
||||
AvatarPlayAnimation(npcID.ToString(), animation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -463,12 +463,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
|
|||
toRegionPos = presence.AbsolutePosition;
|
||||
dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));
|
||||
|
||||
if (presence.PresenceType == PresenceType.Npc && npcModule != null)
|
||||
{
|
||||
UUID npcOwner = npcModule.GetOwner(presence.UUID);
|
||||
if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
|
||||
return;
|
||||
}
|
||||
// Disabled for now since all osNpc* methods check for appropriate ownership permission.
|
||||
// Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
|
||||
// sensed might be useful.
|
||||
// if (presence.PresenceType == PresenceType.Npc && npcModule != null)
|
||||
// {
|
||||
// UUID npcOwner = npcModule.GetOwner(presence.UUID);
|
||||
// if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
|
||||
// return;
|
||||
// }
|
||||
|
||||
// are they in range
|
||||
if (dis <= ts.range)
|
||||
|
|
|
@ -172,7 +172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
|||
LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
|
||||
|
||||
key osNpcCreate(string user, string name, vector position, string notecard);
|
||||
key osNpcCreateOwned(string user, string name, vector position, string notecard);
|
||||
key osNpcCreate(string user, string name, vector position, string notecard, int options);
|
||||
LSL_Key osNpcSaveAppearance(key npc, string notecard);
|
||||
void osNpcLoadAppearance(key npc, string notecard);
|
||||
vector osNpcGetPos(key npc);
|
||||
|
|
|
@ -606,6 +606,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
|||
|
||||
public const int OS_NPC_SIT_NOW = 0;
|
||||
|
||||
public const int OS_NPC_CREATOR_OWNED = 0x1;
|
||||
public const int OS_NPC_NOT_OWNED = 0x2;
|
||||
|
||||
public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
|
||||
public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
|
||||
|
||||
|
|
|
@ -488,9 +488,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
|||
return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom);
|
||||
}
|
||||
|
||||
public key osNpcCreateOwned(string user, string name, vector position, key cloneFrom)
|
||||
public key osNpcCreate(string user, string name, vector position, key cloneFrom, int options)
|
||||
{
|
||||
return m_OSSL_Functions.osNpcCreateOwned(user, name, position, cloneFrom);
|
||||
return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom, options);
|
||||
}
|
||||
|
||||
public key osNpcSaveAppearance(key npc, string notecard)
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
using NUnit.Framework;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Assets;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
|
||||
using OpenSim.Region.OptionalModules.World.NPC;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.ScriptEngine.Shared;
|
||||
using OpenSim.Region.ScriptEngine.Shared.Api;
|
||||
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using OpenSim.Tests.Common;
|
||||
using OpenSim.Tests.Common.Mock;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for OSSL NPC API
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class OSSL_NpcApiAppearanceTest
|
||||
{
|
||||
protected Scene m_scene;
|
||||
protected XEngine.XEngine m_engine;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
IConfigSource initConfigSource = new IniConfigSource();
|
||||
IConfig config = initConfigSource.AddConfig("XEngine");
|
||||
config.Set("Enabled", "true");
|
||||
config.Set("AllowOSFunctions", "true");
|
||||
config.Set("OSFunctionThreatLevel", "Severe");
|
||||
config = initConfigSource.AddConfig("NPC");
|
||||
config.Set("Enabled", "true");
|
||||
|
||||
m_scene = SceneHelpers.SetupScene();
|
||||
SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
|
||||
|
||||
m_engine = new XEngine.XEngine();
|
||||
m_engine.Initialise(initConfigSource);
|
||||
m_engine.AddRegion(m_scene);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test removal of an owned NPC.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOsNpcRemoveOwned()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
// Store an avatar with a different height from default in a notecard.
|
||||
UUID userId = TestHelpers.ParseTail(0x1);
|
||||
UUID otherUserId = TestHelpers.ParseTail(0x2);
|
||||
float newHeight = 1.9f;
|
||||
|
||||
SceneHelpers.AddScenePresence(m_scene, otherUserId);
|
||||
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
||||
sp.Appearance.AvatarHeight = newHeight;
|
||||
|
||||
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
|
||||
SceneObjectPart part = so.RootPart;
|
||||
m_scene.AddSceneObject(so);
|
||||
|
||||
SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId);
|
||||
SceneObjectPart otherPart = otherSo.RootPart;
|
||||
m_scene.AddSceneObject(otherSo);
|
||||
|
||||
OSSL_Api osslApi = new OSSL_Api();
|
||||
osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
|
||||
|
||||
OSSL_Api otherOsslApi = new OSSL_Api();
|
||||
otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID);
|
||||
|
||||
string notecardName = "appearanceNc";
|
||||
osslApi.osOwnerSaveAppearance(notecardName);
|
||||
|
||||
string npcRaw
|
||||
= osslApi.osNpcCreate(
|
||||
"Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED);
|
||||
|
||||
otherOsslApi.osNpcRemove(npcRaw);
|
||||
|
||||
// Should still be around
|
||||
UUID npcId = new UUID(npcRaw);
|
||||
ScenePresence npc = m_scene.GetScenePresence(npcId);
|
||||
Assert.That(npc, Is.Not.Null);
|
||||
|
||||
osslApi.osNpcRemove(npcRaw);
|
||||
|
||||
npc = m_scene.GetScenePresence(npcId);
|
||||
|
||||
// Now the owner deleted it and it's gone
|
||||
Assert.That(npc, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test removal of an unowned NPC.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOsNpcRemoveUnowned()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
// Store an avatar with a different height from default in a notecard.
|
||||
UUID userId = TestHelpers.ParseTail(0x1);
|
||||
float newHeight = 1.9f;
|
||||
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
||||
sp.Appearance.AvatarHeight = newHeight;
|
||||
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
|
||||
SceneObjectPart part = so.RootPart;
|
||||
m_scene.AddSceneObject(so);
|
||||
|
||||
OSSL_Api osslApi = new OSSL_Api();
|
||||
osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
|
||||
|
||||
string notecardName = "appearanceNc";
|
||||
osslApi.osOwnerSaveAppearance(notecardName);
|
||||
|
||||
string npcRaw
|
||||
= osslApi.osNpcCreate(
|
||||
"Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED);
|
||||
|
||||
osslApi.osNpcRemove(npcRaw);
|
||||
|
||||
UUID npcId = new UUID(npcRaw);
|
||||
ScenePresence npc = m_scene.GetScenePresence(npcId);
|
||||
Assert.That(npc, Is.Null);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue