aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer
diff options
context:
space:
mode:
authorMW2007-04-11 12:13:21 +0000
committerMW2007-04-11 12:13:21 +0000
commit5ad6d5a939fb7bf0fdfdc6925d4afed306e08641 (patch)
tree8bcf302b69297a27ab254d087f73fe88fecab464 /OpenSim.RegionServer
parentChanged so that a bin\ScriptEngines\ directory will be searched for scripting... (diff)
downloadopensim-SC-5ad6d5a939fb7bf0fdfdc6925d4afed306e08641.zip
opensim-SC-5ad6d5a939fb7bf0fdfdc6925d4afed306e08641.tar.gz
opensim-SC-5ad6d5a939fb7bf0fdfdc6925d4afed306e08641.tar.bz2
opensim-SC-5ad6d5a939fb7bf0fdfdc6925d4afed306e08641.tar.xz
First basic test script now works in the jvm scripting engine.
For it to work you need to have a java sdk installed and the javac.exe somewhere in the environment Path variable. Then To test, copy the text from bin/script1.text into a note card and then add that note to a prim.
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/world/World.cs10
-rw-r--r--OpenSim.RegionServer/world/WorldScripting.cs122
2 files changed, 127 insertions, 5 deletions
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
index 74325b0..a973c6c 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -87,22 +87,22 @@ namespace OpenSim.world
87 //Console.WriteLine("searching for script to add: " + substring); 87 //Console.WriteLine("searching for script to add: " + substring);
88 88
89 ScriptFactory scriptFactory; 89 ScriptFactory scriptFactory;
90 Console.WriteLine("script string is " + substring); 90 //Console.WriteLine("script string is " + substring);
91 if(substring.StartsWith("<ScriptEngine:")) 91 if(substring.StartsWith("<ScriptEngine:"))
92 { 92 {
93 string substring1 = ""; 93 string substring1 = "";
94 string script = ""; 94 string script = "";
95 Console.WriteLine("searching for script engine"); 95 // Console.WriteLine("searching for script engine");
96 substring1 = substring.Remove(0, 14); 96 substring1 = substring.Remove(0, 14);
97 int dev = substring1.IndexOf(','); 97 int dev = substring1.IndexOf(',');
98 string sEngine = substring1.Substring(0, dev); 98 string sEngine = substring1.Substring(0, dev);
99 substring1 = substring1.Remove(0, dev+1); 99 substring1 = substring1.Remove(0, dev+1);
100 int end = substring1.IndexOf('>'); 100 int end = substring1.IndexOf('>');
101 string sName = substring1.Substring(0, end); 101 string sName = substring1.Substring(0, end);
102 Console.WriteLine(" script info : " + sEngine + " , " + sName); 102 //Console.WriteLine(" script info : " + sEngine + " , " + sName);
103 int startscript = substring.IndexOf('>'); 103 int startscript = substring.IndexOf('>');
104 script = substring.Remove(0, startscript + 1); 104 script = substring.Remove(0, startscript + 1);
105 Console.WriteLine("script data is " + script); 105 // Console.WriteLine("script data is " + script);
106 if (this.scriptEngines.ContainsKey(sEngine)) 106 if (this.scriptEngines.ContainsKey(sEngine))
107 { 107 {
108 this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); 108 this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid);
@@ -172,7 +172,7 @@ namespace OpenSim.world
172 } 172 }
173 foreach (IScriptEngine scripteng in this.scriptEngines.Values) 173 foreach (IScriptEngine scripteng in this.scriptEngines.Values)
174 { 174 {
175 //scripteng.OnFrame(); 175 scripteng.OnFrame();
176 } 176 }
177 //backup world data 177 //backup world data
178 this.storageCount++; 178 this.storageCount++;
diff --git a/OpenSim.RegionServer/world/WorldScripting.cs b/OpenSim.RegionServer/world/WorldScripting.cs
new file mode 100644
index 0000000..83838b4
--- /dev/null
+++ b/OpenSim.RegionServer/world/WorldScripting.cs
@@ -0,0 +1,122 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Reflection;
6using OpenSim.Framework;
7using OpenSim.Framework.Interfaces;
8using libsecondlife;
9
10namespace OpenSim.world
11{
12 public partial class World
13 {
14 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
15
16 private void LoadScriptEngines()
17 {
18 this.LoadScriptPlugins();
19 }
20
21 public void LoadScriptPlugins()
22 {
23 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
24 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
25
26
27 for (int i = 0; i < pluginFiles.Length; i++)
28 {
29 this.AddPlugin(pluginFiles[i]);
30 }
31 }
32
33 private void AddPlugin(string FileName)
34 {
35 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
36
37 foreach (Type pluginType in pluginAssembly.GetTypes())
38 {
39 if (pluginType.IsPublic)
40 {
41 if (!pluginType.IsAbstract)
42 {
43 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
44
45 if (typeInterface != null)
46 {
47 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
48 plug.Init(this);
49 this.scriptEngines.Add(plug.GetName(), plug);
50
51 }
52
53 typeInterface = null;
54 }
55 }
56 }
57
58 pluginAssembly = null;
59 }
60
61 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
62 {
63 if(this.scriptEngines.ContainsKey(scriptType))
64 {
65 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
66 }
67 }
68
69 #region IScriptAPI Methods
70
71 public OSVector3 GetEntityPosition(uint localID)
72 {
73 OSVector3 res = new OSVector3();
74 // Console.WriteLine("script- getting entity " + localID + " position");
75 foreach (Entity entity in this.Entities.Values)
76 {
77 if (entity.localid == localID)
78 {
79 res.X = entity.Pos.X;
80 res.Y = entity.Pos.Y;
81 res.Z = entity.Pos.Z;
82 }
83 }
84 return res;
85 }
86
87 public void SetEntityPosition(uint localID, float x , float y, float z)
88 {
89 foreach (Entity entity in this.Entities.Values)
90 {
91 if (entity.localid == localID && entity is Primitive)
92 {
93 LLVector3 pos = entity.Pos;
94 pos.X = x;
95 Primitive prim = entity as Primitive;
96 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
97 prim.UpdatePosition(pos);
98 // Console.WriteLine("script- setting entity " + localID + " positon");
99 }
100 }
101
102 }
103
104 public uint GetRandomAvatarID()
105 {
106 //Console.WriteLine("script- getting random avatar id");
107 uint res = 0;
108 foreach (Entity entity in this.Entities.Values)
109 {
110 if (entity is Avatar)
111 {
112 res = entity.localid;
113 }
114 }
115 return res;
116 }
117
118 #endregion
119
120
121 }
122}