From ad398971445a3aad5490ad4c3e6b7319f201bb8f Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 3 Apr 2007 16:50:17 +0000 Subject: * Script prototype --- OpenSim.RegionServer/CAPS/AdminWebFront.cs | 98 ++++++++++++++++------ OpenSim.RegionServer/OpenSim.RegionServer.csproj | 9 ++ .../OpenSim.RegionServer.dll.build | 3 + OpenSim.RegionServer/world/World.cs | 37 +++++--- .../world/scripting/IScriptContext.cs | 13 +++ .../world/scripting/IScriptHandler.cs | 62 ++++++++++++++ OpenSim.RegionServer/world/scripting/Script.cs | 27 ++++++ 7 files changed, 213 insertions(+), 36 deletions(-) create mode 100644 OpenSim.RegionServer/world/scripting/IScriptContext.cs create mode 100644 OpenSim.RegionServer/world/scripting/IScriptHandler.cs create mode 100644 OpenSim.RegionServer/world/scripting/Script.cs (limited to 'OpenSim.RegionServer') diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs index 7f00225..43996d0 100644 --- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs +++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs @@ -7,6 +7,8 @@ using OpenSim.UserServer; using OpenSim.Servers; using OpenSim.Assets; using OpenSim.Framework.Inventory; +using libsecondlife; +using OpenSim.RegionServer.world.scripting; namespace OpenSim.CAPS { @@ -34,7 +36,10 @@ namespace OpenSim.CAPS server.AddRestHandler("GET", "/Admin", GetAdminPage); server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage); server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage ); - server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage ); + server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage); + server.AddRestHandler("GET", "/Admin/Entities", GetEntitiesPage); + server.AddRestHandler("GET", "/Admin/Scripts", GetScriptsPage); + server.AddRestHandler("GET", "/Admin/AddTestScript", AddTestScript ); server.AddRestHandler("GET", "/ClientInventory", GetClientsInventory); server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount ); @@ -133,6 +138,68 @@ namespace OpenSim.CAPS return responseString; } + + private class TestScript : Script + { + int toggle = 0; + + public TestScript() + : base(LLUUID.Random()) + { + OnFrame += MyOnFrame; + } + + private void MyOnFrame(IScriptContext context) + { + toggle = 2 - toggle; + + LLVector3 pos = context.GetPos(); + + pos.X += (toggle - 1); + + context.MoveTo(pos); + } + } + + private string AddTestScript(string request, string path) + { + int index = path.LastIndexOf('/'); + + string lluidStr = path.Substring(index+1); + + LLUUID id; + + if( LLUUID.TryParse( lluidStr, out id ) ) + { + // This is just here for concept purposes... Remove! + m_world.AddScript( m_world.Entities[id], new TestScript()); + return String.Format("Added new script to object [{0}]", id); + } + else + { + return String.Format("Couldn't parse [{0}]", lluidStr ); + } + } + + private string GetScriptsPage(string request, string path) + { + return String.Empty; + } + + private string GetEntitiesPage(string request, string path) + { + string responseString; + responseString = "

Listing current entities

"; + return responseString; + } + private string GetClientsInventory(string request, string path) { string[] line; @@ -187,38 +254,17 @@ namespace OpenSim.CAPS try { StreamReader SR; - string lines; - AdminPage = ""; - NewAccountForm = ""; - LoginForm = ""; + SR = File.OpenText("testadmin.htm"); - - while (!SR.EndOfStream) - { - lines = SR.ReadLine(); - AdminPage += lines + "\n"; - - } + AdminPage = SR.ReadToEnd(); SR.Close(); SR = File.OpenText("newaccountform.htm"); - - while (!SR.EndOfStream) - { - lines = SR.ReadLine(); - NewAccountForm += lines + "\n"; - - } + NewAccountForm = SR.ReadToEnd(); SR.Close(); SR = File.OpenText("login.htm"); - - while (!SR.EndOfStream) - { - lines = SR.ReadLine(); - LoginForm += lines + "\n"; - - } + LoginForm = SR.ReadToEnd(); SR.Close(); } catch (Exception e) diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj index b9b440f..73b627e 100644 --- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj +++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj @@ -184,6 +184,15 @@ Code + + Code + + + Code + + + Code + diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build index 926a310..bee15fd 100644 --- a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build +++ b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build @@ -35,6 +35,9 @@ + + + diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index e848cad..6bc485f 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -11,6 +11,8 @@ using OpenSim.Framework.Assets; using OpenSim.Framework.Terrain; using OpenSim.Framework.Inventory; using OpenSim.Assets; +using OpenSim.world.scripting; +using OpenSim.RegionServer.world.scripting; namespace OpenSim.world { @@ -29,6 +31,7 @@ namespace OpenSim.world private uint _primCount = 702000; private int storageCount; private Dictionary m_clientThreads; + private Dictionary m_scriptHandlers; private ulong m_regionHandle; private string m_regionName; private InventoryCache _inventoryCache; @@ -40,6 +43,8 @@ namespace OpenSim.world m_regionHandle = regionHandle; m_regionName = regionName; + m_scriptHandlers = new Dictionary(); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); Entities = new Dictionary(); @@ -52,6 +57,12 @@ namespace OpenSim.world Avatar.LoadAnims(); } + public void AddScript(Entity entity, Script script) + { + ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); + m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); + } + public InventoryCache InventoryCache { set @@ -102,6 +113,11 @@ namespace OpenSim.world Entities[UUID].update(); } + foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) + { + scriptHandler.OnFrame(); + } + //backup world data this.storageCount++; if (storageCount > 1200) //set to how often you want to backup @@ -194,7 +210,7 @@ namespace OpenSim.world foreach (SimClient client in m_clientThreads.Values) { - this.SendLayerData(pointx , pointy , client); + this.SendLayerData(pointx, pointy, client); } } } @@ -251,10 +267,10 @@ namespace OpenSim.world int[] patches = new int[1]; int patchx, patchy; patchx = px / 16; - /* if (patchx > 12) - { - patchx = 12; - }*/ + /* if (patchx > 12) + { + patchx = 12; + }*/ patchy = py / 16; patches[0] = patchx + 0 + patchy * 16; @@ -270,9 +286,10 @@ namespace OpenSim.world { foreach (libsecondlife.LLUUID UUID in Entities.Keys) { - if (Entities[UUID].ToString() == "OpenSim.world.Primitive") + if (Entities[UUID] is Primitive) { - ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient); + Primitive primitive = Entities[UUID] as Primitive; + primitive.UpdateClient(RemoteClient); } } } @@ -306,7 +323,7 @@ namespace OpenSim.world prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); } } - //prim.PhysicsEnabled = true; + this.Entities.Add(prim.uuid, prim); this._primCount++; } @@ -314,7 +331,7 @@ namespace OpenSim.world public bool DeRezObject(SimClient simClient, Packet packet) { DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; - // Console.WriteLine(DeRezPacket); + // Console.WriteLine(DeRezPacket); //Needs to delete object from physics at a later date if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) { @@ -414,7 +431,7 @@ namespace OpenSim.world public bool ModifyTerrain(SimClient simClient, Packet packet) { ModifyLandPacket modify = (ModifyLandPacket)packet; - + switch (modify.ModifyBlock.Action) { case 1: diff --git a/OpenSim.RegionServer/world/scripting/IScriptContext.cs b/OpenSim.RegionServer/world/scripting/IScriptContext.cs new file mode 100644 index 0000000..80878ef --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/IScriptContext.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; + +namespace OpenSim.RegionServer.world.scripting +{ + public interface IScriptContext + { + bool MoveTo(LLVector3 newPos); + LLVector3 GetPos(); + } +} diff --git a/OpenSim.RegionServer/world/scripting/IScriptHandler.cs b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs new file mode 100644 index 0000000..5addb35 --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using OpenSim.Physics.Manager; +using OpenSim.world; +using Primitive=OpenSim.world.Primitive; + +namespace OpenSim.RegionServer.world.scripting +{ + public delegate void ScriptEventHandler( IScriptContext context ); + + public class ScriptHandler : IScriptContext + { + private World m_world; + private Script m_script; + private Entity m_entity; + + public LLUUID ScriptId + { + get + { + return m_script.ScriptId; + } + } + + public void OnFrame() + { + m_script.OnFrame(this); + } + + public ScriptHandler( Script script, Entity entity, World world ) + { + m_script = script; + m_entity = entity; + m_world = world; + } + + #region IScriptContext Members + + bool IScriptContext.MoveTo(LLVector3 newPos) + { + if (m_entity is Primitive) + { + Primitive prim = m_entity as Primitive; + // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. + prim.UpdatePosition( newPos ); + return true; + } + + return false; + } + + LLVector3 IScriptContext.GetPos() + { + return m_entity.position; + } + + #endregion + } + +} diff --git a/OpenSim.RegionServer/world/scripting/Script.cs b/OpenSim.RegionServer/world/scripting/Script.cs new file mode 100644 index 0000000..3997b41 --- /dev/null +++ b/OpenSim.RegionServer/world/scripting/Script.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; + +namespace OpenSim.RegionServer.world.scripting +{ + public class Script + { + private LLUUID m_scriptId; + + public virtual LLUUID ScriptId + { + get + { + return m_scriptId; + } + } + + public Script( LLUUID scriptId ) + { + m_scriptId = scriptId; + } + + public ScriptEventHandler OnFrame; + } +} -- cgit v1.1