From f12ceff6925236ca184c5a7a9c010b5e4bdb1b70 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 3 Apr 2007 20:08:30 +0000 Subject: * The world can not contain ScriptFactories that creates unique instances of scripts for entities. * Created Scripts folder to house trusted Scripts * The test script now lives in Scripts/FollowRandomAvatar.cs --- OpenSim.RegionServer/CAPS/AdminWebFront.cs | 32 +------------- OpenSim.RegionServer/OpenSim.RegionServer.csproj | 6 +++ .../OpenSim.RegionServer.dll.build | 2 + OpenSim.RegionServer/world/World.cs | 49 +++++++++------------- .../world/scripting/ScriptFactory.cs | 8 ++++ .../world/scripting/Scripts/FollowRandomAvatar.cs | 37 ++++++++++++++++ 6 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 OpenSim.RegionServer/world/scripting/ScriptFactory.cs create mode 100644 OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs index 0d03a57..d4519e8 100644 --- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs +++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs @@ -10,6 +10,7 @@ using OpenSim.Framework.Inventory; using libsecondlife; using OpenSim.RegionServer.world.scripting; using Avatar=libsecondlife.Avatar; +using OpenSim.RegionServer.world.scripting.Scripts; namespace OpenSim.CAPS { @@ -139,35 +140,6 @@ namespace OpenSim.CAPS return responseString; } - - private class TestScript : Script - { - public TestScript() - : base(LLUUID.Random()) - { - OnFrame += MyOnFrame; - } - - private void MyOnFrame(IScriptContext context) - { - LLVector3 pos = context.Entity.Pos; - - IScriptReadonlyEntity avatar; - - if( context.TryGetRandomAvatar( out avatar ) ) - { - LLVector3 avatarPos = avatar.Pos; - - float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X))/2; - float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y))/2; - - LLVector3 newPos = new LLVector3( x, y, pos.Z ); - - context.Entity.Pos = newPos; - } - } - } - private string AddTestScript(string request, string path) { int index = path.LastIndexOf('/'); @@ -179,7 +151,7 @@ namespace OpenSim.CAPS if( LLUUID.TryParse( lluidStr, out id ) ) { // This is just here for concept purposes... Remove! - m_world.AddScript( m_world.Entities[id], new TestScript()); + m_world.AddScript( m_world.Entities[id], new FollowRandomAvatar()); return String.Format("Added new script to object [{0}]", id); } else diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj index 165b123..6c0f2da 100644 --- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj +++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj @@ -196,6 +196,12 @@ Code + + Code + + + Code + diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build index 47a983b..4a08551 100644 --- a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build +++ b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build @@ -39,6 +39,8 @@ + + diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index c775429..0799e38 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -13,6 +13,7 @@ using OpenSim.Framework.Inventory; using OpenSim.Assets; using OpenSim.world.scripting; using OpenSim.RegionServer.world.scripting; +using OpenSim.RegionServer.world.scripting.Scripts; namespace OpenSim.world { @@ -32,20 +33,20 @@ namespace OpenSim.world private int storageCount; private Dictionary m_clientThreads; private Dictionary m_scriptHandlers; - private Dictionary m_scripts; + private Dictionary m_scripts; private ulong m_regionHandle; private string m_regionName; private InventoryCache _inventoryCache; private AssetCache _assetCache; public World(Dictionary clientThreads, ulong regionHandle, string regionName) - { + { m_clientThreads = clientThreads; m_regionHandle = regionHandle; m_regionName = regionName; m_scriptHandlers = new Dictionary(); - m_scripts = new Dictionary(); + m_scripts = new Dictionary(); OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); Entities = new Dictionary(); @@ -75,11 +76,17 @@ namespace OpenSim.world scriptend = scriptData.LastIndexOf(""); substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); substring = substring.Trim(); - Console.WriteLine("searching for script to add: " + substring); - if (this.m_scripts.ContainsKey(substring)) + Console.WriteLine("searching for script to add: " + substring); + + ScriptFactory scriptFactory; + + if (this.m_scripts.TryGetValue(substring, out scriptFactory )) { Console.WriteLine("added script"); - this.AddScript(entity, this.m_scripts[substring]); + + + + this.AddScript(entity, scriptFactory()); } /*string delimStr = " "; char[] delimiter = delimStr.ToCharArray(); @@ -357,7 +364,7 @@ namespace OpenSim.world prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); } } - + this.Entities.Add(prim.uuid, prim); this._primCount++; } @@ -557,31 +564,13 @@ namespace OpenSim.world public void SetDefaultScripts() { - this.m_scripts.Add("Test", new TestScript1()); - } - - #endregion - } - - public class TestScript1 : Script - { - int toggle = 0; - - public TestScript1() - : base(LLUUID.Random()) - { - OnFrame += MyOnFrame; + this.m_scripts.Add("FollowRandomAvatar", delegate() + { + return new FollowRandomAvatar(); + }); } - private void MyOnFrame(IScriptContext context) - { - toggle = 2 - toggle; - LLVector3 pos = context.GetPos(); - - pos.X += (toggle - 1); - - context.MoveTo(pos); - } + #endregion } } diff --git a/OpenSim.RegionServer/world/scripting/ScriptFactory.cs b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs new file mode 100644 index 0000000..4c6d373 --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs @@ -0,0 +1,8 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.RegionServer.world.scripting +{ + public delegate Script ScriptFactory(); +} diff --git a/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs new file mode 100644 index 0000000..388a95c --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; + +namespace OpenSim.RegionServer.world.scripting.Scripts +{ + public class FollowRandomAvatar : Script + { + public FollowRandomAvatar() + : base(LLUUID.Random()) + { + OnFrame += MyOnFrame; + } + + private void MyOnFrame(IScriptContext context) + { + LLVector3 pos = context.Entity.Pos; + + IScriptReadonlyEntity avatar; + + if (context.TryGetRandomAvatar(out avatar)) + { + LLVector3 avatarPos = avatar.Pos; + + float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2; + float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2; + + LLVector3 newPos = new LLVector3(x, y, pos.Z); + + context.Entity.Pos = newPos; + } + } + } + + +} -- cgit v1.1