aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs90
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs2
2 files changed, 75 insertions, 17 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index eeb74d9..a43a5f5 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -26,12 +26,14 @@
26 */ 26 */
27 27
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Threading;
29using OpenMetaverse; 30using OpenMetaverse;
30using Nini.Config; 31using Nini.Config;
31using OpenSim.Region.Framework.Interfaces; 32using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33using OpenSim.Region.CoreModules.Avatar.NPC; 34using OpenSim.Region.CoreModules.Avatar.NPC;
34using OpenSim.Framework; 35using OpenSim.Framework;
36using Timer=System.Timers.Timer;
35 37
36namespace OpenSim.Region.OptionalModules.World.NPC 38namespace OpenSim.Region.OptionalModules.World.NPC
37{ 39{
@@ -39,10 +41,25 @@ namespace OpenSim.Region.OptionalModules.World.NPC
39 { 41 {
40 // private const bool m_enabled = false; 42 // private const bool m_enabled = false;
41 43
44 private Mutex m_createMutex = new Mutex(false);
45
46 private Timer m_timer = new Timer(500);
47
42 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 48 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
43 49
44 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); 50 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
45 51
52 // Timer vars.
53 private bool p_inUse = false;
54 private readonly object p_lock = new object();
55 // Private Temporary Variables.
56 private string p_firstname;
57 private string p_lastname;
58 private Vector3 p_position;
59 private Scene p_scene;
60 private UUID p_cloneAppearanceFrom;
61 private UUID p_returnUuid;
62
46 private AvatarAppearance GetAppearance(UUID target, Scene scene) 63 private AvatarAppearance GetAppearance(UUID target, Scene scene)
47 { 64 {
48 if (m_appearanceCache.ContainsKey(target)) 65 if (m_appearanceCache.ContainsKey(target))
@@ -57,29 +74,29 @@ namespace OpenSim.Region.OptionalModules.World.NPC
57 74
58 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) 75 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom)
59 { 76 {
60 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); 77 // Block.
61 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); 78 m_createMutex.WaitOne();
62
63 scene.ClientManager.Add(npcAvatar.CircuitCode, npcAvatar);
64 scene.AddNewClient(npcAvatar);
65 79
66 ScenePresence sp; 80 // Copy Temp Variables for Timer to pick up.
67 if(scene.TryGetAvatar(npcAvatar.AgentId, out sp)) 81 lock (p_lock)
68 { 82 {
69 AvatarAppearance x = GetAppearance(cloneAppearanceFrom, scene); 83 p_firstname = firstname;
70 84 p_lastname = lastname;
71 List<byte> wearbyte = new List<byte>(); 85 p_position = position;
72 for (int i = 0; i < x.VisualParams.Length; i++) 86 p_scene = scene;
73 { 87 p_cloneAppearanceFrom = cloneAppearanceFrom;
74 wearbyte.Add(x.VisualParams[i]); 88 p_inUse = true;
75 } 89 p_returnUuid = UUID.Zero;
90 }
76 91
77 sp.SetAppearance(x.Texture.GetBytes(), wearbyte); 92 while(p_returnUuid == UUID.Zero)
93 {
94 Thread.Sleep(250);
78 } 95 }
79 96
80 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 97 m_createMutex.ReleaseMutex();
81 98
82 return npcAvatar.AgentId; 99 return p_returnUuid;
83 } 100 }
84 101
85 public void Autopilot(UUID agentID, Scene scene, Vector3 pos) 102 public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
@@ -116,6 +133,45 @@ namespace OpenSim.Region.OptionalModules.World.NPC
116 public void Initialise(Scene scene, IConfigSource source) 133 public void Initialise(Scene scene, IConfigSource source)
117 { 134 {
118 scene.RegisterModuleInterface<INPCModule>(this); 135 scene.RegisterModuleInterface<INPCModule>(this);
136
137 m_timer.Elapsed += m_timer_Elapsed;
138 m_timer.Start();
139 }
140
141 void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
142 {
143 lock (p_lock)
144 {
145 if (p_inUse)
146 {
147 p_inUse = false;
148
149
150 NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene);
151 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue);
152
153 p_scene.ClientManager.Add(npcAvatar.CircuitCode, npcAvatar);
154 p_scene.AddNewClient(npcAvatar);
155
156 ScenePresence sp;
157 if (p_scene.TryGetAvatar(npcAvatar.AgentId, out sp))
158 {
159 AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene);
160
161 List<byte> wearbyte = new List<byte>();
162 for (int i = 0; i < x.VisualParams.Length; i++)
163 {
164 wearbyte.Add(x.VisualParams[i]);
165 }
166
167 sp.SetAppearance(x.Texture.GetBytes(), wearbyte);
168 }
169
170 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
171
172 p_returnUuid = npcAvatar.AgentId;
173 }
174 }
119 } 175 }
120 176
121 public void PostInitialise() 177 public void PostInitialise()
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index fcfa9fc..6190349 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
31using System.Runtime.Remoting.Lifetime; 31using System.Runtime.Remoting.Lifetime;
32using System.Text; 32using System.Text;
33using System.Net; 33using System.Net;
34using System.Threading;
34using OpenMetaverse; 35using OpenMetaverse;
35using Nini.Config; 36using Nini.Config;
36using OpenSim; 37using OpenSim;
@@ -1766,6 +1767,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1766 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) 1767 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
1767 { 1768 {
1768 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 1769 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
1770 //QueueUserWorkItem
1769 1771
1770 INPCModule module = World.RequestModuleInterface<INPCModule>(); 1772 INPCModule module = World.RequestModuleInterface<INPCModule>();
1771 if (module != null) 1773 if (module != null)