From ad398971445a3aad5490ad4c3e6b7319f201bb8f Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 3 Apr 2007 16:50:17 +0000 Subject: [PATCH] * Script prototype --- .../OpenGridServices.GridServer.csproj | 4 - .../OpenGridServices.GridServer.exe.build | 1 - OpenSim.RegionServer/CAPS/AdminWebFront.cs | 98 ++++++++++++++----- .../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 ++++++++++++ .../world/scripting/Script.cs | 27 +++++ OpenSim.sln | 2 +- bin/testadmin.htm | 9 +- prebuild.xml | 1 - 12 files changed, 219 insertions(+), 47 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 diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj index 6eac766afc..836a98b8f0 100644 --- a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj +++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj @@ -70,10 +70,6 @@ System.Xml.dll False - - OpenSim.Framework.Interfaces.dll - False - ..\bin\libsecondlife.dll False diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build index ca4e929f2d..90eaf1fbf5 100644 --- a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build +++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build @@ -25,7 +25,6 @@ - diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs index 7f00225650..43996d0949 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

    "; + + foreach (Entity entity in m_world.Entities.Values) + { + string testScriptLink = "javascript:loadXMLDoc('Admin/AddTestScript/" + entity.uuid.ToString() + "');"; + responseString += String.Format( "
  • [{0}] \"{1}\" @ {2} add test script
  • ", entity.uuid, entity.getName(), entity.position, testScriptLink ); + } + responseString += "
"; + 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 b9b440f67c..73b627e4b7 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 926a310d02..bee15fd3e6 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 e848cad2f8..6bc485f848 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 0000000000..80878eff5a --- /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 0000000000..5addb3527e --- /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 0000000000..3997b41e70 --- /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; + } +} diff --git a/OpenSim.sln b/OpenSim.sln index 01a2df21a9..5df577f7c5 100644 --- a/OpenSim.sln +++ b/OpenSim.sln @@ -1,5 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual C# Express 2005 +# Visual Studio 2005 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim", "OpenSim\OpenSim.csproj", "{438A9556-0000-0000-0000-000000000000}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Physics.OdePlugin", "OpenSim.Physics\OdePlugin\OpenSim.Physics.OdePlugin.csproj", "{63A05FE9-0000-0000-0000-000000000000}" diff --git a/bin/testadmin.htm b/bin/testadmin.htm index 1e34cf768a..62a860d9e2 100644 --- a/bin/testadmin.htm +++ b/bin/testadmin.htm @@ -69,7 +69,7 @@ if (http_request.readyState==4) alert('Cannot create XMLHTTP instance'); return false; } - + http_request.onreadystatechange =state_Change http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); @@ -83,14 +83,14 @@ if (http_request.readyState==4) if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; - document.getElementById('T1').innerHTML = result; + document.getElementById('T1').innerHTML = result; } else { alert('There was a problem with the request.'); } } } - + function get(obj) { var poststr = "FirstName=" + encodeURI( document.getElementById("FirstName").value ) + "&LastName=" + encodeURI( document.getElementById("LastName").value ) @@ -98,7 +98,7 @@ if (http_request.readyState==4) + "&AdminPass=" + adminpass; makePOSTRequest('Admin/NewAccount', poststr); } - + function setpass(obj) { adminpass = encodeURI( document.getElementById("Adminpss").value ); @@ -115,6 +115,7 @@ if (http_request.readyState==4)
+ diff --git a/prebuild.xml b/prebuild.xml index 793da74d3c..54acc4b0b7 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -118,7 +118,6 @@ -