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!
bulletsim
Justin Clark-Casey (justincc) 2011-06-29 00:28:22 +01:00
parent ee92f22f2a
commit 22f25fae38
7 changed files with 84 additions and 42 deletions

View File

@ -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);

View File

@ -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)

View File

@ -36,4 +36,4 @@ namespace OpenSim.Region.Framework.Interfaces
void QueueAppearanceSend(UUID agentid);
void QueueAppearanceSave(UUID agentid);
}
}
}

View File

@ -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);

View File

@ -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
/// <param name="remoteClient"></param>
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)

View File

@ -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");
}
});
}

View File

@ -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<INPCModule>(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<INPCModule>(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);
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<string, object>();
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;
sp.Appearance.SetTextureEntries(x.Texture);
sp.Appearance.SetVisualParams((byte[])x.VisualParams.Clone());
sp.SendAppearanceToAllOtherAgents();
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()