* Script prototype

0.1-prestable
lbsa71 2007-04-03 16:50:17 +00:00
parent ba2c94721c
commit ad39897144
12 changed files with 219 additions and 47 deletions

View File

@ -70,10 +70,6 @@
<HintPath>System.Xml.dll</HintPath> <HintPath>System.Xml.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="OpenSim.Framework.Interfaces" >
<HintPath>OpenSim.Framework.Interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="libsecondlife.dll" > <Reference Include="libsecondlife.dll" >
<HintPath>..\bin\libsecondlife.dll</HintPath> <HintPath>..\bin\libsecondlife.dll</HintPath>
<Private>False</Private> <Private>False</Private>

View File

@ -25,7 +25,6 @@
<include name="System.Data.dll" /> <include name="System.Data.dll" />
<include name="System.Xml.dll" /> <include name="System.Xml.dll" />
<include name="../bin/OpenSim.Framework.dll" /> <include name="../bin/OpenSim.Framework.dll" />
<include name="OpenSim.Framework.Interfaces.dll" />
<include name="../bin/OpenSim.Framework.Console.dll" /> <include name="../bin/OpenSim.Framework.Console.dll" />
<include name="../bin/libsecondlife.dll" /> <include name="../bin/libsecondlife.dll" />
<include name="../bin/Db4objects.Db4o.dll" /> <include name="../bin/Db4objects.Db4o.dll" />

View File

@ -7,6 +7,8 @@ using OpenSim.UserServer;
using OpenSim.Servers; using OpenSim.Servers;
using OpenSim.Assets; using OpenSim.Assets;
using OpenSim.Framework.Inventory; using OpenSim.Framework.Inventory;
using libsecondlife;
using OpenSim.RegionServer.world.scripting;
namespace OpenSim.CAPS namespace OpenSim.CAPS
{ {
@ -34,7 +36,10 @@ namespace OpenSim.CAPS
server.AddRestHandler("GET", "/Admin", GetAdminPage); server.AddRestHandler("GET", "/Admin", GetAdminPage);
server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage); server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage);
server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage ); 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("GET", "/ClientInventory", GetClientsInventory);
server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount ); server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount );
@ -133,6 +138,68 @@ namespace OpenSim.CAPS
return responseString; 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 = " <p> Listing current entities</p><ul>";
foreach (Entity entity in m_world.Entities.Values)
{
string testScriptLink = "javascript:loadXMLDoc('Admin/AddTestScript/" + entity.uuid.ToString() + "');";
responseString += String.Format( "<li>[{0}] \"{1}\" @ {2} <a href=\"{3}\">add test script</a></li>", entity.uuid, entity.getName(), entity.position, testScriptLink );
}
responseString += "</ul>";
return responseString;
}
private string GetClientsInventory(string request, string path) private string GetClientsInventory(string request, string path)
{ {
string[] line; string[] line;
@ -187,38 +254,17 @@ namespace OpenSim.CAPS
try try
{ {
StreamReader SR; StreamReader SR;
string lines;
AdminPage = "";
NewAccountForm = "";
LoginForm = "";
SR = File.OpenText("testadmin.htm"); SR = File.OpenText("testadmin.htm");
AdminPage = SR.ReadToEnd();
while (!SR.EndOfStream)
{
lines = SR.ReadLine();
AdminPage += lines + "\n";
}
SR.Close(); SR.Close();
SR = File.OpenText("newaccountform.htm"); SR = File.OpenText("newaccountform.htm");
NewAccountForm = SR.ReadToEnd();
while (!SR.EndOfStream)
{
lines = SR.ReadLine();
NewAccountForm += lines + "\n";
}
SR.Close(); SR.Close();
SR = File.OpenText("login.htm"); SR = File.OpenText("login.htm");
LoginForm = SR.ReadToEnd();
while (!SR.EndOfStream)
{
lines = SR.ReadLine();
LoginForm += lines + "\n";
}
SR.Close(); SR.Close();
} }
catch (Exception e) catch (Exception e)

View File

@ -184,6 +184,15 @@
<Compile Include="world\scripting\IScript.cs"> <Compile Include="world\scripting\IScript.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="world\scripting\IScriptContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="world\scripting\IScriptHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="world\scripting\Script.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup> <PropertyGroup>

View File

@ -35,6 +35,9 @@
<include name="world/SurfacePatch.cs" /> <include name="world/SurfacePatch.cs" />
<include name="world/World.cs" /> <include name="world/World.cs" />
<include name="world/scripting/IScript.cs" /> <include name="world/scripting/IScript.cs" />
<include name="world/scripting/IScriptContext.cs" />
<include name="world/scripting/IScriptHandler.cs" />
<include name="world/scripting/Script.cs" />
</sources> </sources>
<references basedir="${project::get-base-directory()}"> <references basedir="${project::get-base-directory()}">
<lib> <lib>

View File

@ -11,6 +11,8 @@ using OpenSim.Framework.Assets;
using OpenSim.Framework.Terrain; using OpenSim.Framework.Terrain;
using OpenSim.Framework.Inventory; using OpenSim.Framework.Inventory;
using OpenSim.Assets; using OpenSim.Assets;
using OpenSim.world.scripting;
using OpenSim.RegionServer.world.scripting;
namespace OpenSim.world namespace OpenSim.world
{ {
@ -29,6 +31,7 @@ namespace OpenSim.world
private uint _primCount = 702000; private uint _primCount = 702000;
private int storageCount; private int storageCount;
private Dictionary<uint, SimClient> m_clientThreads; private Dictionary<uint, SimClient> m_clientThreads;
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
private ulong m_regionHandle; private ulong m_regionHandle;
private string m_regionName; private string m_regionName;
private InventoryCache _inventoryCache; private InventoryCache _inventoryCache;
@ -40,6 +43,8 @@ namespace OpenSim.world
m_regionHandle = regionHandle; m_regionHandle = regionHandle;
m_regionName = regionName; m_regionName = regionName;
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
@ -52,6 +57,12 @@ namespace OpenSim.world
Avatar.LoadAnims(); 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 public InventoryCache InventoryCache
{ {
set set
@ -102,6 +113,11 @@ namespace OpenSim.world
Entities[UUID].update(); Entities[UUID].update();
} }
foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
{
scriptHandler.OnFrame();
}
//backup world data //backup world data
this.storageCount++; this.storageCount++;
if (storageCount > 1200) //set to how often you want to backup 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) 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[] patches = new int[1];
int patchx, patchy; int patchx, patchy;
patchx = px / 16; patchx = px / 16;
/* if (patchx > 12) /* if (patchx > 12)
{ {
patchx = 12; patchx = 12;
}*/ }*/
patchy = py / 16; patchy = py / 16;
patches[0] = patchx + 0 + patchy * 16; patches[0] = patchx + 0 + patchy * 16;
@ -270,9 +286,10 @@ namespace OpenSim.world
{ {
foreach (libsecondlife.LLUUID UUID in Entities.Keys) 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.PhysActor = this.phyScene.AddPrim(pVec, pSize);
} }
} }
//prim.PhysicsEnabled = true;
this.Entities.Add(prim.uuid, prim); this.Entities.Add(prim.uuid, prim);
this._primCount++; this._primCount++;
} }
@ -314,7 +331,7 @@ namespace OpenSim.world
public bool DeRezObject(SimClient simClient, Packet packet) public bool DeRezObject(SimClient simClient, Packet packet)
{ {
DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet;
// Console.WriteLine(DeRezPacket); // Console.WriteLine(DeRezPacket);
//Needs to delete object from physics at a later date //Needs to delete object from physics at a later date
if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
{ {
@ -414,7 +431,7 @@ namespace OpenSim.world
public bool ModifyTerrain(SimClient simClient, Packet packet) public bool ModifyTerrain(SimClient simClient, Packet packet)
{ {
ModifyLandPacket modify = (ModifyLandPacket)packet; ModifyLandPacket modify = (ModifyLandPacket)packet;
switch (modify.ModifyBlock.Action) switch (modify.ModifyBlock.Action)
{ {
case 1: case 1:

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim", "OpenSim\OpenSim.csproj", "{438A9556-0000-0000-0000-000000000000}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Physics.OdePlugin", "OpenSim.Physics\OdePlugin\OpenSim.Physics.OdePlugin.csproj", "{63A05FE9-0000-0000-0000-000000000000}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Physics.OdePlugin", "OpenSim.Physics\OdePlugin\OpenSim.Physics.OdePlugin.csproj", "{63A05FE9-0000-0000-0000-000000000000}"

View File

@ -69,7 +69,7 @@ if (http_request.readyState==4)
alert('Cannot create XMLHTTP instance'); alert('Cannot create XMLHTTP instance');
return false; return false;
} }
http_request.onreadystatechange =state_Change http_request.onreadystatechange =state_Change
http_request.open('POST', url, true); http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
@ -83,14 +83,14 @@ if (http_request.readyState==4)
if (http_request.status == 200) { if (http_request.status == 200) {
//alert(http_request.responseText); //alert(http_request.responseText);
result = http_request.responseText; result = http_request.responseText;
document.getElementById('T1').innerHTML = result; document.getElementById('T1').innerHTML = result;
} else { } else {
alert('There was a problem with the request.'); alert('There was a problem with the request.');
} }
} }
} }
function get(obj) { function get(obj) {
var poststr = "FirstName=" + encodeURI( document.getElementById("FirstName").value ) + var poststr = "FirstName=" + encodeURI( document.getElementById("FirstName").value ) +
"&LastName=" + encodeURI( document.getElementById("LastName").value ) "&LastName=" + encodeURI( document.getElementById("LastName").value )
@ -98,7 +98,7 @@ if (http_request.readyState==4)
+ "&AdminPass=" + adminpass; + "&AdminPass=" + adminpass;
makePOSTRequest('Admin/NewAccount', poststr); makePOSTRequest('Admin/NewAccount', poststr);
} }
function setpass(obj) function setpass(obj)
{ {
adminpass = encodeURI( document.getElementById("Adminpss").value ); adminpass = encodeURI( document.getElementById("Adminpss").value );
@ -115,6 +115,7 @@ if (http_request.readyState==4)
</div><br /> </div><br />
<button onclick="loadXMLDoc('Admin/Clients')">Clients</button> <button onclick="loadXMLDoc('Admin/Clients')">Clients</button>
<button onclick="loadXMLDoc('Admin/Accounts')">Accounts</button> <button onclick="loadXMLDoc('Admin/Accounts')">Accounts</button>
<button onclick="loadXMLDoc('Admin/Entities')">Entities</button>
</body> </body>

View File

@ -118,7 +118,6 @@
<Reference name="System.Data" localCopy="false"/> <Reference name="System.Data" localCopy="false"/>
<Reference name="System.Xml" localCopy="false"/> <Reference name="System.Xml" localCopy="false"/>
<Reference name="OpenSim.Framework"/> <Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Interfaces"/>
<Reference name="OpenSim.Framework.Console"/> <Reference name="OpenSim.Framework.Console"/>
<Reference name="libsecondlife.dll"/> <Reference name="libsecondlife.dll"/>
<Reference name="Db4objects.Db4o.dll"/> <Reference name="Db4objects.Db4o.dll"/>