From 22f25fae387a801e8545f6ab6e2c9700926ae6e4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 29 Jun 2011 00:28:22 +0100 Subject: 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! --- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 4 +- .../UserManagement/UserManagementModule.cs | 3 +- .../Region/Framework/Interfaces/IAvatarFactory.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 4 +- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 6 +- .../Avatar/Appearance/AppearanceInfoModule.cs | 2 +- .../Region/OptionalModules/World/NPC/NPCModule.cs | 107 ++++++++++++++------- 7 files changed, 85 insertions(+), 43 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index e92f072..d02a305 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -162,12 +162,12 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory // one and we're done otherwise, ask for a rebake if (checkonly) return false; - m_log.InfoFormat("[AVFACTORY]: missing baked texture {0}, requesting rebake",face.TextureID); + m_log.InfoFormat("[AVFACTORY]: missing baked texture {0}, requesting rebake", face.TextureID); client.SendRebakeAvatarTextures(face.TextureID); } } - m_log.DebugFormat("[AVFACTORY]: completed texture check for {0}", client.AgentId); + m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0}", client.AgentId); // If we only found default textures, then the appearance is not cached return (defonly ? false : true); diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index accd094..a4861ec 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -297,9 +297,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement if (m_UserCache.ContainsKey(id)) return; +// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, craetorData {1}", id, creatorData); + UserData user = new UserData(); user.Id = id; - UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id); if (account != null) diff --git a/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs b/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs index 22795fc..d0e5609 100644 --- a/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs +++ b/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs @@ -36,4 +36,4 @@ namespace OpenSim.Region.Framework.Interfaces void QueueAppearanceSend(UUID agentid); void QueueAppearanceSave(UUID agentid); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index bdf3d1d..ad41e88 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2593,8 +2593,10 @@ namespace OpenSim.Region.Framework.Scenes { string homeURL = string.Empty; string first = aCircuit.firstname, last = aCircuit.lastname; + if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) homeURL = aCircuit.ServiceURLs["HomeURI"].ToString(); + if (aCircuit.lastname.StartsWith("@")) { string[] parts = aCircuit.firstname.Split('.'); @@ -2604,6 +2606,7 @@ namespace OpenSim.Region.Framework.Scenes last = parts[1]; } } + uMan.AddUser(aCircuit.AgentID, first, last, homeURL); } } @@ -3389,7 +3392,6 @@ namespace OpenSim.Region.Framework.Scenes } } - // In all cases, add or update the circuit data with the new agent circuit data and teleport flags agent.teleportFlags = teleportFlags; m_authenticateHandler.AddNewCircuit(agent.circuitcode, agent); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 80aafd0..83b761c 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1944,10 +1944,9 @@ namespace OpenSim.Region.Framework.Scenes m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); } - - SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); } + /* public void SitRayCastAvatarPosition(SceneObjectPart part) { @@ -2380,7 +2379,6 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendTerseUpdateToClient(IClientAPI remoteClient) { - // If the client is inactive, it's getting its updates from another // server. if (remoteClient.IsActive) @@ -2495,7 +2493,7 @@ namespace OpenSim.Region.Framework.Scenes } // If we aren't using a cached appearance, then clear out the baked textures - if (! cachedappearance) + if (!cachedappearance) { m_appearance.ResetAppearance(); if (m_scene.AvatarFactory != null) diff --git a/OpenSim/Region/OptionalModules/Avatar/Appearance/AppearanceInfoModule.cs b/OpenSim/Region/OptionalModules/Avatar/Appearance/AppearanceInfoModule.cs index 7304145..77e7acf 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Appearance/AppearanceInfoModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Appearance/AppearanceInfoModule.cs @@ -113,7 +113,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance { bool bakedTextureValid = scene.AvatarFactory.ValidateBakedTextureCache(client); MainConsole.Instance.OutputFormat( - "{0} baked apperance texture is {1}", client.Name, bakedTextureValid ? "OK" : "corrupt"); + "{0} baked appearance texture is {1}", client.Name, bakedTextureValid ? "OK" : "corrupt"); } }); } 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 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; +using System.Reflection; using System.Threading; -using OpenMetaverse; +using log4net; using Nini.Config; +using OpenMetaverse; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.CoreModules.Avatar.NPC; @@ -40,6 +43,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC { public class NPCModule : IRegionModule, INPCModule { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // private const bool m_enabled = false; private Mutex m_createMutex; @@ -59,6 +64,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC private UUID p_cloneAppearanceFrom; private UUID p_returnUuid; + public void Initialise(Scene scene, IConfigSource source) + { + m_createMutex = new Mutex(false); + + m_timer = new Timer(500); + m_timer.Elapsed += m_timer_Elapsed; + m_timer.Start(); + + scene.RegisterModuleInterface(this); + } + private AvatarAppearance GetAppearance(UUID target, Scene scene) { if (m_appearanceCache.ContainsKey(target)) @@ -76,6 +92,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) { + m_log.DebugFormat( + "[NPC MODULE]: Queueing request to create NPC {0} {1} at {2} in {3} cloning appearance of {4}", + firstname, lastname, position, scene.RegionInfo.RegionName, cloneAppearanceFrom); + // Block. m_createMutex.WaitOne(); @@ -137,46 +157,67 @@ namespace OpenSim.Region.OptionalModules.World.NPC } } - - public void Initialise(Scene scene, IConfigSource source) - { - m_createMutex = new Mutex(false); - - m_timer = new Timer(500); - m_timer.Elapsed += m_timer_Elapsed; - m_timer.Start(); - - scene.RegisterModuleInterface(this); - } - void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { - lock (p_lock) + try { - if (p_inUse) + lock (p_lock) { - p_inUse = false; - - NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene); - npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); - - p_scene.AddNewClient(npcAvatar); - - ScenePresence sp; - if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + if (p_inUse) { - AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene); - - sp.Appearance.SetTextureEntries(x.Texture); - sp.Appearance.SetVisualParams((byte[])x.VisualParams.Clone()); - sp.SendAppearanceToAllOtherAgents(); + p_inUse = false; + + NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene); + npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); + + m_log.DebugFormat( + "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}", + p_firstname, p_lastname, npcAvatar.AgentId, p_position, p_scene.RegionInfo.RegionName); + + AgentCircuitData acd = new AgentCircuitData(); + acd.AgentID = npcAvatar.AgentId; + acd.firstname = p_firstname; + acd.lastname = p_lastname; + acd.ServiceURLs = new Dictionary(); + + AvatarAppearance originalAppearance = GetAppearance(p_cloneAppearanceFrom, p_scene); + AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); + acd.Appearance = npcAppearance; + + p_scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); + p_scene.AddNewClient(npcAvatar); + + ScenePresence sp; + if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + { + m_log.DebugFormat( + "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + + // Shouldn't call this - temporary. + sp.CompleteMovement(npcAvatar); + + // sp.SendAppearanceToAllOtherAgents(); + // + // // Send animations back to the avatar as well + // sp.Animator.SendAnimPack(); + } + else + { + m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); + } + + m_avatars.Add(npcAvatar.AgentId, npcAvatar); + + p_returnUuid = npcAvatar.AgentId; + + m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", p_returnUuid); } - - m_avatars.Add(npcAvatar.AgentId, npcAvatar); - - p_returnUuid = npcAvatar.AgentId; } } + catch (Exception ex) + { + m_log.ErrorFormat("[NPC MODULE]: NPC creation failed with exception {0} {1}", ex.Message, ex.StackTrace); + } } public void PostInitialise() -- cgit v1.1