aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs151
1 files changed, 0 insertions, 151 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs b/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs
deleted file mode 100644
index 747730c..0000000
--- a/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs
+++ /dev/null
@@ -1,151 +0,0 @@
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.RegionServer.Simulator
39{
40 public partial class World
41 {
42 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
43
44 private void LoadScriptEngines()
45 {
46 this.LoadScriptPlugins();
47 }
48
49 public void LoadScriptPlugins()
50 {
51 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
52 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
53
54
55 for (int i = 0; i < pluginFiles.Length; i++)
56 {
57 this.AddPlugin(pluginFiles[i]);
58 }
59 }
60
61 private void AddPlugin(string FileName)
62 {
63 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
64
65 foreach (Type pluginType in pluginAssembly.GetTypes())
66 {
67 if (pluginType.IsPublic)
68 {
69 if (!pluginType.IsAbstract)
70 {
71 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
72
73 if (typeInterface != null)
74 {
75 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
76 plug.Init(this);
77 this.scriptEngines.Add(plug.GetName(), plug);
78
79 }
80
81 typeInterface = null;
82 }
83 }
84 }
85
86 pluginAssembly = null;
87 }
88
89 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
90 {
91 if(this.scriptEngines.ContainsKey(scriptType))
92 {
93 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
94 }
95 }
96
97 #region IScriptAPI Methods
98
99 public OSVector3 GetEntityPosition(uint localID)
100 {
101 OSVector3 res = new OSVector3();
102 // Console.WriteLine("script- getting entity " + localID + " position");
103 foreach (Entity entity in this.Entities.Values)
104 {
105 if (entity.localid == localID)
106 {
107 res.X = entity.Pos.X;
108 res.Y = entity.Pos.Y;
109 res.Z = entity.Pos.Z;
110 }
111 }
112 return res;
113 }
114
115 public void SetEntityPosition(uint localID, float x , float y, float z)
116 {
117 foreach (Entity entity in this.Entities.Values)
118 {
119 if (entity.localid == localID && entity is Primitive)
120 {
121 LLVector3 pos = entity.Pos;
122 pos.X = x;
123 pos.Y = y;
124 Primitive prim = entity as Primitive;
125 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
126 prim.UpdatePosition(pos);
127 // Console.WriteLine("script- setting entity " + localID + " positon");
128 }
129 }
130
131 }
132
133 public uint GetRandomAvatarID()
134 {
135 //Console.WriteLine("script- getting random avatar id");
136 uint res = 0;
137 foreach (Entity entity in this.Entities.Values)
138 {
139 if (entity is Avatar)
140 {
141 res = entity.localid;
142 }
143 }
144 return res;
145 }
146
147 #endregion
148
149
150 }
151}