aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ScriptEngine/Shared/ScriptStructure.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/ScriptEngine/Shared/ScriptStructure.cs137
1 files changed, 0 insertions, 137 deletions
diff --git a/OpenSim/ScriptEngine/Shared/ScriptStructure.cs b/OpenSim/ScriptEngine/Shared/ScriptStructure.cs
deleted file mode 100644
index 1095a8b..0000000
--- a/OpenSim/ScriptEngine/Shared/ScriptStructure.cs
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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.Reflection;
31using System.Text;
32using log4net;
33using OpenMetaverse;
34using OpenSim.Region.ScriptEngine.Interfaces;
35using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
36using OpenSim.ScriptEngine.Shared;
37
38namespace OpenSim.ScriptEngine.Shared
39{
40 public struct ScriptStructure
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 public RegionInfoStructure RegionInfo;
45 public ScriptMetaData ScriptMetaData;
46
47 public ScriptAssemblies.IScript ScriptObject;
48 public string State;
49 public bool Running;
50 public bool Disabled;
51 public string Source;
52 public int StartParam;
53 public AppDomain AppDomain;
54 public Dictionary<string, IScriptApi> Apis;
55 public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap;
56 public uint LocalID;
57 public UUID ItemID;
58 public string AssemblyFileName;
59
60 public string ScriptID { get { return LocalID.ToString() + "." + ItemID.ToString(); } }
61 public string Name { get { return "Script:" + ScriptID; } }
62 private bool Initialized;
63 private Dictionary<string, Delegate> InternalFunctions;
64 public string AssemblyName;
65
66 public void ExecuteEvent(EventParams p)
67 {
68 ExecuteMethod(p, true);
69 }
70
71 public void ExecuteMethod(EventParams p)
72 {
73 ExecuteMethod(p, false);
74 }
75 private void ExecuteMethod(EventParams p, bool isEvent)
76 {
77 // First time initialization?
78 if (!Initialized)
79 {
80 Initialized = true;
81 CacheInternalFunctions();
82 }
83
84 lock (InternalFunctions)
85 {
86 // Make function name
87 string FunctionName;
88 if (isEvent)
89 FunctionName = State + "_event_" + p.EventName;
90 else
91 FunctionName = p.EventName;
92
93 // Check if this function exist
94 if (!InternalFunctions.ContainsKey(FunctionName))
95 {
96 // TODO: Send message in-world
97 m_log.ErrorFormat("[{0}] Script function \"{1}\" was not found.", Name, FunctionName);
98 return;
99 }
100
101 // Execute script function
102 try
103 {
104 InternalFunctions[FunctionName].DynamicInvoke(p.Params);
105 }
106 catch (Exception e)
107 {
108 m_log.ErrorFormat("[{0}] Execute \"{1}\" failed: {2}", Name, FunctionName, e.ToString());
109 }
110 }
111 }
112
113 /// <summary>
114 /// Cache functions into a dictionary with delegates. Should be faster than reflection.
115 /// </summary>
116 private void CacheInternalFunctions()
117 {
118 Type scriptObjectType = ScriptObject.GetType();
119 InternalFunctions = new Dictionary<string, Delegate>();
120
121 MethodInfo[] methods = scriptObjectType.GetMethods();
122 lock (InternalFunctions)
123 {
124 // Read all methods into a dictionary
125 foreach (MethodInfo mi in methods)
126 {
127 // TODO: We don't support overloading
128 if (!InternalFunctions.ContainsKey(mi.Name))
129 InternalFunctions.Add(mi.Name, Delegate.CreateDelegate(scriptObjectType, ScriptObject, mi));
130 else
131 m_log.ErrorFormat("[{0}] Error: Script function \"{1}\" is already added. We do not support overloading.",
132 Name, mi.Name);
133 }
134 }
135 }
136 }
137}