aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/world/WorldScripting.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.RegionServer/world/WorldScripting.cs')
-rw-r--r--OpenSim.RegionServer/world/WorldScripting.cs122
1 files changed, 122 insertions, 0 deletions
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}