diff options
author | lbsa71 | 2007-04-03 16:50:17 +0000 |
---|---|---|
committer | lbsa71 | 2007-04-03 16:50:17 +0000 |
commit | ad398971445a3aad5490ad4c3e6b7319f201bb8f (patch) | |
tree | 746655b671e158b1e578983d68eeb96976ebdf8f /OpenSim.RegionServer | |
parent | Limited (hacked) object linking. Note: once you have linked a set of prims to... (diff) | |
download | opensim-SC_OLD-ad398971445a3aad5490ad4c3e6b7319f201bb8f.zip opensim-SC_OLD-ad398971445a3aad5490ad4c3e6b7319f201bb8f.tar.gz opensim-SC_OLD-ad398971445a3aad5490ad4c3e6b7319f201bb8f.tar.bz2 opensim-SC_OLD-ad398971445a3aad5490ad4c3e6b7319f201bb8f.tar.xz |
* Script prototype
Diffstat (limited to 'OpenSim.RegionServer')
-rw-r--r-- | OpenSim.RegionServer/CAPS/AdminWebFront.cs | 98 | ||||
-rw-r--r-- | OpenSim.RegionServer/OpenSim.RegionServer.csproj | 9 | ||||
-rw-r--r-- | OpenSim.RegionServer/OpenSim.RegionServer.dll.build | 3 | ||||
-rw-r--r-- | OpenSim.RegionServer/world/World.cs | 37 | ||||
-rw-r--r-- | OpenSim.RegionServer/world/scripting/IScriptContext.cs | 13 | ||||
-rw-r--r-- | OpenSim.RegionServer/world/scripting/IScriptHandler.cs | 62 | ||||
-rw-r--r-- | OpenSim.RegionServer/world/scripting/Script.cs | 27 |
7 files changed, 213 insertions, 36 deletions
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; | |||
7 | using OpenSim.Servers; | 7 | using OpenSim.Servers; |
8 | using OpenSim.Assets; | 8 | using OpenSim.Assets; |
9 | using OpenSim.Framework.Inventory; | 9 | using OpenSim.Framework.Inventory; |
10 | using libsecondlife; | ||
11 | using OpenSim.RegionServer.world.scripting; | ||
10 | 12 | ||
11 | namespace OpenSim.CAPS | 13 | namespace OpenSim.CAPS |
12 | { | 14 | { |
@@ -34,7 +36,10 @@ namespace OpenSim.CAPS | |||
34 | server.AddRestHandler("GET", "/Admin", GetAdminPage); | 36 | server.AddRestHandler("GET", "/Admin", GetAdminPage); |
35 | server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage); | 37 | server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage); |
36 | server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage ); | 38 | server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage ); |
37 | server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage ); | 39 | server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage); |
40 | server.AddRestHandler("GET", "/Admin/Entities", GetEntitiesPage); | ||
41 | server.AddRestHandler("GET", "/Admin/Scripts", GetScriptsPage); | ||
42 | server.AddRestHandler("GET", "/Admin/AddTestScript", AddTestScript ); | ||
38 | server.AddRestHandler("GET", "/ClientInventory", GetClientsInventory); | 43 | server.AddRestHandler("GET", "/ClientInventory", GetClientsInventory); |
39 | 44 | ||
40 | server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount ); | 45 | server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount ); |
@@ -133,6 +138,68 @@ namespace OpenSim.CAPS | |||
133 | return responseString; | 138 | return responseString; |
134 | } | 139 | } |
135 | 140 | ||
141 | |||
142 | private class TestScript : Script | ||
143 | { | ||
144 | int toggle = 0; | ||
145 | |||
146 | public TestScript() | ||
147 | : base(LLUUID.Random()) | ||
148 | { | ||
149 | OnFrame += MyOnFrame; | ||
150 | } | ||
151 | |||
152 | private void MyOnFrame(IScriptContext context) | ||
153 | { | ||
154 | toggle = 2 - toggle; | ||
155 | |||
156 | LLVector3 pos = context.GetPos(); | ||
157 | |||
158 | pos.X += (toggle - 1); | ||
159 | |||
160 | context.MoveTo(pos); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | private string AddTestScript(string request, string path) | ||
165 | { | ||
166 | int index = path.LastIndexOf('/'); | ||
167 | |||
168 | string lluidStr = path.Substring(index+1); | ||
169 | |||
170 | LLUUID id; | ||
171 | |||
172 | if( LLUUID.TryParse( lluidStr, out id ) ) | ||
173 | { | ||
174 | // This is just here for concept purposes... Remove! | ||
175 | m_world.AddScript( m_world.Entities[id], new TestScript()); | ||
176 | return String.Format("Added new script to object [{0}]", id); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | return String.Format("Couldn't parse [{0}]", lluidStr ); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | private string GetScriptsPage(string request, string path) | ||
185 | { | ||
186 | return String.Empty; | ||
187 | } | ||
188 | |||
189 | private string GetEntitiesPage(string request, string path) | ||
190 | { | ||
191 | string responseString; | ||
192 | responseString = " <p> Listing current entities</p><ul>"; | ||
193 | |||
194 | foreach (Entity entity in m_world.Entities.Values) | ||
195 | { | ||
196 | string testScriptLink = "javascript:loadXMLDoc('Admin/AddTestScript/" + entity.uuid.ToString() + "');"; | ||
197 | responseString += String.Format( "<li>[{0}] \"{1}\" @ {2} <a href=\"{3}\">add test script</a></li>", entity.uuid, entity.getName(), entity.position, testScriptLink ); | ||
198 | } | ||
199 | responseString += "</ul>"; | ||
200 | return responseString; | ||
201 | } | ||
202 | |||
136 | private string GetClientsInventory(string request, string path) | 203 | private string GetClientsInventory(string request, string path) |
137 | { | 204 | { |
138 | string[] line; | 205 | string[] line; |
@@ -187,38 +254,17 @@ namespace OpenSim.CAPS | |||
187 | try | 254 | try |
188 | { | 255 | { |
189 | StreamReader SR; | 256 | StreamReader SR; |
190 | string lines; | 257 | |
191 | AdminPage = ""; | ||
192 | NewAccountForm = ""; | ||
193 | LoginForm = ""; | ||
194 | SR = File.OpenText("testadmin.htm"); | 258 | SR = File.OpenText("testadmin.htm"); |
195 | 259 | AdminPage = SR.ReadToEnd(); | |
196 | while (!SR.EndOfStream) | ||
197 | { | ||
198 | lines = SR.ReadLine(); | ||
199 | AdminPage += lines + "\n"; | ||
200 | |||
201 | } | ||
202 | SR.Close(); | 260 | SR.Close(); |
203 | 261 | ||
204 | SR = File.OpenText("newaccountform.htm"); | 262 | SR = File.OpenText("newaccountform.htm"); |
205 | 263 | NewAccountForm = SR.ReadToEnd(); | |
206 | while (!SR.EndOfStream) | ||
207 | { | ||
208 | lines = SR.ReadLine(); | ||
209 | NewAccountForm += lines + "\n"; | ||
210 | |||
211 | } | ||
212 | SR.Close(); | 264 | SR.Close(); |
213 | 265 | ||
214 | SR = File.OpenText("login.htm"); | 266 | SR = File.OpenText("login.htm"); |
215 | 267 | LoginForm = SR.ReadToEnd(); | |
216 | while (!SR.EndOfStream) | ||
217 | { | ||
218 | lines = SR.ReadLine(); | ||
219 | LoginForm += lines + "\n"; | ||
220 | |||
221 | } | ||
222 | SR.Close(); | 268 | SR.Close(); |
223 | } | 269 | } |
224 | catch (Exception e) | 270 | 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 @@ | |||
184 | <Compile Include="world\scripting\IScript.cs"> | 184 | <Compile Include="world\scripting\IScript.cs"> |
185 | <SubType>Code</SubType> | 185 | <SubType>Code</SubType> |
186 | </Compile> | 186 | </Compile> |
187 | <Compile Include="world\scripting\IScriptContext.cs"> | ||
188 | <SubType>Code</SubType> | ||
189 | </Compile> | ||
190 | <Compile Include="world\scripting\IScriptHandler.cs"> | ||
191 | <SubType>Code</SubType> | ||
192 | </Compile> | ||
193 | <Compile Include="world\scripting\Script.cs"> | ||
194 | <SubType>Code</SubType> | ||
195 | </Compile> | ||
187 | </ItemGroup> | 196 | </ItemGroup> |
188 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | 197 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
189 | <PropertyGroup> | 198 | <PropertyGroup> |
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 @@ | |||
35 | <include name="world/SurfacePatch.cs" /> | 35 | <include name="world/SurfacePatch.cs" /> |
36 | <include name="world/World.cs" /> | 36 | <include name="world/World.cs" /> |
37 | <include name="world/scripting/IScript.cs" /> | 37 | <include name="world/scripting/IScript.cs" /> |
38 | <include name="world/scripting/IScriptContext.cs" /> | ||
39 | <include name="world/scripting/IScriptHandler.cs" /> | ||
40 | <include name="world/scripting/Script.cs" /> | ||
38 | </sources> | 41 | </sources> |
39 | <references basedir="${project::get-base-directory()}"> | 42 | <references basedir="${project::get-base-directory()}"> |
40 | <lib> | 43 | <lib> |
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; | |||
11 | using OpenSim.Framework.Terrain; | 11 | using OpenSim.Framework.Terrain; |
12 | using OpenSim.Framework.Inventory; | 12 | using OpenSim.Framework.Inventory; |
13 | using OpenSim.Assets; | 13 | using OpenSim.Assets; |
14 | using OpenSim.world.scripting; | ||
15 | using OpenSim.RegionServer.world.scripting; | ||
14 | 16 | ||
15 | namespace OpenSim.world | 17 | namespace OpenSim.world |
16 | { | 18 | { |
@@ -29,6 +31,7 @@ namespace OpenSim.world | |||
29 | private uint _primCount = 702000; | 31 | private uint _primCount = 702000; |
30 | private int storageCount; | 32 | private int storageCount; |
31 | private Dictionary<uint, SimClient> m_clientThreads; | 33 | private Dictionary<uint, SimClient> m_clientThreads; |
34 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; | ||
32 | private ulong m_regionHandle; | 35 | private ulong m_regionHandle; |
33 | private string m_regionName; | 36 | private string m_regionName; |
34 | private InventoryCache _inventoryCache; | 37 | private InventoryCache _inventoryCache; |
@@ -40,6 +43,8 @@ namespace OpenSim.world | |||
40 | m_regionHandle = regionHandle; | 43 | m_regionHandle = regionHandle; |
41 | m_regionName = regionName; | 44 | m_regionName = regionName; |
42 | 45 | ||
46 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | ||
47 | |||
43 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); | 48 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); |
44 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | 49 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); |
45 | 50 | ||
@@ -52,6 +57,12 @@ namespace OpenSim.world | |||
52 | Avatar.LoadAnims(); | 57 | Avatar.LoadAnims(); |
53 | } | 58 | } |
54 | 59 | ||
60 | public void AddScript(Entity entity, Script script) | ||
61 | { | ||
62 | ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); | ||
63 | m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); | ||
64 | } | ||
65 | |||
55 | public InventoryCache InventoryCache | 66 | public InventoryCache InventoryCache |
56 | { | 67 | { |
57 | set | 68 | set |
@@ -102,6 +113,11 @@ namespace OpenSim.world | |||
102 | Entities[UUID].update(); | 113 | Entities[UUID].update(); |
103 | } | 114 | } |
104 | 115 | ||
116 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) | ||
117 | { | ||
118 | scriptHandler.OnFrame(); | ||
119 | } | ||
120 | |||
105 | //backup world data | 121 | //backup world data |
106 | this.storageCount++; | 122 | this.storageCount++; |
107 | if (storageCount > 1200) //set to how often you want to backup | 123 | if (storageCount > 1200) //set to how often you want to backup |
@@ -194,7 +210,7 @@ namespace OpenSim.world | |||
194 | 210 | ||
195 | foreach (SimClient client in m_clientThreads.Values) | 211 | foreach (SimClient client in m_clientThreads.Values) |
196 | { | 212 | { |
197 | this.SendLayerData(pointx , pointy , client); | 213 | this.SendLayerData(pointx, pointy, client); |
198 | } | 214 | } |
199 | } | 215 | } |
200 | } | 216 | } |
@@ -251,10 +267,10 @@ namespace OpenSim.world | |||
251 | int[] patches = new int[1]; | 267 | int[] patches = new int[1]; |
252 | int patchx, patchy; | 268 | int patchx, patchy; |
253 | patchx = px / 16; | 269 | patchx = px / 16; |
254 | /* if (patchx > 12) | 270 | /* if (patchx > 12) |
255 | { | 271 | { |
256 | patchx = 12; | 272 | patchx = 12; |
257 | }*/ | 273 | }*/ |
258 | patchy = py / 16; | 274 | patchy = py / 16; |
259 | 275 | ||
260 | patches[0] = patchx + 0 + patchy * 16; | 276 | patches[0] = patchx + 0 + patchy * 16; |
@@ -270,9 +286,10 @@ namespace OpenSim.world | |||
270 | { | 286 | { |
271 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 287 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
272 | { | 288 | { |
273 | if (Entities[UUID].ToString() == "OpenSim.world.Primitive") | 289 | if (Entities[UUID] is Primitive) |
274 | { | 290 | { |
275 | ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient); | 291 | Primitive primitive = Entities[UUID] as Primitive; |
292 | primitive.UpdateClient(RemoteClient); | ||
276 | } | 293 | } |
277 | } | 294 | } |
278 | } | 295 | } |
@@ -306,7 +323,7 @@ namespace OpenSim.world | |||
306 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | 323 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); |
307 | } | 324 | } |
308 | } | 325 | } |
309 | //prim.PhysicsEnabled = true; | 326 | |
310 | this.Entities.Add(prim.uuid, prim); | 327 | this.Entities.Add(prim.uuid, prim); |
311 | this._primCount++; | 328 | this._primCount++; |
312 | } | 329 | } |
@@ -314,7 +331,7 @@ namespace OpenSim.world | |||
314 | public bool DeRezObject(SimClient simClient, Packet packet) | 331 | public bool DeRezObject(SimClient simClient, Packet packet) |
315 | { | 332 | { |
316 | DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; | 333 | DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; |
317 | // Console.WriteLine(DeRezPacket); | 334 | // Console.WriteLine(DeRezPacket); |
318 | //Needs to delete object from physics at a later date | 335 | //Needs to delete object from physics at a later date |
319 | if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) | 336 | if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) |
320 | { | 337 | { |
@@ -414,7 +431,7 @@ namespace OpenSim.world | |||
414 | public bool ModifyTerrain(SimClient simClient, Packet packet) | 431 | public bool ModifyTerrain(SimClient simClient, Packet packet) |
415 | { | 432 | { |
416 | ModifyLandPacket modify = (ModifyLandPacket)packet; | 433 | ModifyLandPacket modify = (ModifyLandPacket)packet; |
417 | 434 | ||
418 | switch (modify.ModifyBlock.Action) | 435 | switch (modify.ModifyBlock.Action) |
419 | { | 436 | { |
420 | case 1: | 437 | 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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | |||
6 | namespace OpenSim.RegionServer.world.scripting | ||
7 | { | ||
8 | public interface IScriptContext | ||
9 | { | ||
10 | bool MoveTo(LLVector3 newPos); | ||
11 | LLVector3 GetPos(); | ||
12 | } | ||
13 | } | ||
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | using OpenSim.Physics.Manager; | ||
6 | using OpenSim.world; | ||
7 | using Primitive=OpenSim.world.Primitive; | ||
8 | |||
9 | namespace OpenSim.RegionServer.world.scripting | ||
10 | { | ||
11 | public delegate void ScriptEventHandler( IScriptContext context ); | ||
12 | |||
13 | public class ScriptHandler : IScriptContext | ||
14 | { | ||
15 | private World m_world; | ||
16 | private Script m_script; | ||
17 | private Entity m_entity; | ||
18 | |||
19 | public LLUUID ScriptId | ||
20 | { | ||
21 | get | ||
22 | { | ||
23 | return m_script.ScriptId; | ||
24 | } | ||
25 | } | ||
26 | |||
27 | public void OnFrame() | ||
28 | { | ||
29 | m_script.OnFrame(this); | ||
30 | } | ||
31 | |||
32 | public ScriptHandler( Script script, Entity entity, World world ) | ||
33 | { | ||
34 | m_script = script; | ||
35 | m_entity = entity; | ||
36 | m_world = world; | ||
37 | } | ||
38 | |||
39 | #region IScriptContext Members | ||
40 | |||
41 | bool IScriptContext.MoveTo(LLVector3 newPos) | ||
42 | { | ||
43 | if (m_entity is Primitive) | ||
44 | { | ||
45 | Primitive prim = m_entity as Primitive; | ||
46 | // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. | ||
47 | prim.UpdatePosition( newPos ); | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | return false; | ||
52 | } | ||
53 | |||
54 | LLVector3 IScriptContext.GetPos() | ||
55 | { | ||
56 | return m_entity.position; | ||
57 | } | ||
58 | |||
59 | #endregion | ||
60 | } | ||
61 | |||
62 | } | ||
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | |||
6 | namespace OpenSim.RegionServer.world.scripting | ||
7 | { | ||
8 | public class Script | ||
9 | { | ||
10 | private LLUUID m_scriptId; | ||
11 | |||
12 | public virtual LLUUID ScriptId | ||
13 | { | ||
14 | get | ||
15 | { | ||
16 | return m_scriptId; | ||
17 | } | ||
18 | } | ||
19 | |||
20 | public Script( LLUUID scriptId ) | ||
21 | { | ||
22 | m_scriptId = scriptId; | ||
23 | } | ||
24 | |||
25 | public ScriptEventHandler OnFrame; | ||
26 | } | ||
27 | } | ||