aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs')
-rw-r--r--OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs184
1 files changed, 184 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs b/OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs
new file mode 100644
index 0000000..df5ca9b
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Scene.Scripting.cs
@@ -0,0 +1,184 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.IO;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using libsecondlife;
37
38namespace OpenSim.Region
39{
40 public partial class Scene
41 {
42 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
43
44 /// <summary>
45 ///
46 /// </summary>
47 private void LoadScriptEngines()
48 {
49 this.LoadScriptPlugins();
50 }
51
52 /// <summary>
53 ///
54 /// </summary>
55 public void LoadScriptPlugins()
56 {
57 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
58 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
59
60
61 for (int i = 0; i < pluginFiles.Length; i++)
62 {
63 this.AddPlugin(pluginFiles[i]);
64 }
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 /// <param name="FileName"></param>
71 private void AddPlugin(string FileName)
72 {
73 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
74
75 foreach (Type pluginType in pluginAssembly.GetTypes())
76 {
77 if (pluginType.IsPublic)
78 {
79 if (!pluginType.IsAbstract)
80 {
81 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
82
83 if (typeInterface != null)
84 {
85 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
86 plug.Init(this);
87 this.scriptEngines.Add(plug.GetName(), plug);
88
89 }
90
91 typeInterface = null;
92 }
93 }
94 }
95
96 pluginAssembly = null;
97 }
98
99 /// <summary>
100 ///
101 /// </summary>
102 /// <param name="scriptType"></param>
103 /// <param name="scriptName"></param>
104 /// <param name="script"></param>
105 /// <param name="ent"></param>
106 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
107 {
108 if(this.scriptEngines.ContainsKey(scriptType))
109 {
110 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
111 }
112 }
113
114 #region IScriptAPI Methods
115
116 /// <summary>
117 ///
118 /// </summary>
119 /// <param name="localID"></param>
120 /// <returns></returns>
121 public LLVector3 GetEntityPosition(uint localID)
122 {
123 LLVector3 res = new LLVector3();
124 // Console.WriteLine("script- getting entity " + localID + " position");
125 foreach (Entity entity in this.Entities.Values)
126 {
127 if (entity.localid == localID)
128 {
129 res.X = entity.Pos.X;
130 res.Y = entity.Pos.Y;
131 res.Z = entity.Pos.Z;
132 }
133 }
134 return res;
135 }
136
137 /// <summary>
138 ///
139 /// </summary>
140 /// <param name="localID"></param>
141 /// <param name="x"></param>
142 /// <param name="y"></param>
143 /// <param name="z"></param>
144 public void SetEntityPosition(uint localID, float x , float y, float z)
145 {
146 foreach (Entity entity in this.Entities.Values)
147 {
148 if (entity.localid == localID && entity is Primitive)
149 {
150 LLVector3 pos = entity.Pos;
151 pos.X = x;
152 pos.Y = y;
153 Primitive prim = entity as Primitive;
154 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
155 //prim.UpdatePosition(pos);
156 // Console.WriteLine("script- setting entity " + localID + " positon");
157 }
158 }
159
160 }
161
162 /// <summary>
163 ///
164 /// </summary>
165 /// <returns></returns>
166 public uint GetRandomAvatarID()
167 {
168 //Console.WriteLine("script- getting random avatar id");
169 uint res = 0;
170 foreach (Entity entity in this.Entities.Values)
171 {
172 if (entity is Avatar)
173 {
174 res = entity.localid;
175 }
176 }
177 return res;
178 }
179
180 #endregion
181
182
183 }
184}