ExecutorBase.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 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. using System;
  28. using System.Collections.Generic;
  29. using System.Runtime.Remoting.Lifetime;
  30. using OpenSim.Region.ScriptEngine.XEngine.Script;
  31. namespace OpenSim.Region.ScriptEngine.XEngine
  32. {
  33. public abstract class ExecutorBase : MarshalByRefObject
  34. {
  35. /// <summary>
  36. /// Contains the script to execute functions in.
  37. /// </summary>
  38. protected IScript m_Script;
  39. protected Dictionary<string, scriptEvents> m_eventFlagsMap = new Dictionary<string, scriptEvents>();
  40. [Flags]
  41. public enum scriptEvents : int
  42. {
  43. None = 0,
  44. attach = 1,
  45. collision = 15,
  46. collision_end = 32,
  47. collision_start = 64,
  48. control = 128,
  49. dataserver = 256,
  50. email = 512,
  51. http_response = 1024,
  52. land_collision = 2048,
  53. land_collision_end = 4096,
  54. land_collision_start = 8192,
  55. at_target = 16384,
  56. listen = 32768,
  57. money = 65536,
  58. moving_end = 131072,
  59. moving_start = 262144,
  60. not_at_rot_target = 524288,
  61. not_at_target = 1048576,
  62. remote_data = 8388608,
  63. run_time_permissions = 268435456,
  64. state_entry = 1073741824,
  65. state_exit = 2,
  66. timer = 4,
  67. touch = 8,
  68. touch_end = 536870912,
  69. touch_start = 2097152,
  70. object_rez = 4194304
  71. }
  72. /// <summary>
  73. /// Create a new instance of ExecutorBase
  74. /// </summary>
  75. /// <param name="Script"></param>
  76. public ExecutorBase(IScript Script)
  77. {
  78. m_Script = Script;
  79. initEventFlags();
  80. }
  81. /// <summary>
  82. /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class)
  83. /// </summary>
  84. /// <returns></returns>
  85. public override Object InitializeLifetimeService()
  86. {
  87. //Console.WriteLine("Executor: InitializeLifetimeService()");
  88. // return null;
  89. ILease lease = (ILease)base.InitializeLifetimeService();
  90. if (lease.CurrentState == LeaseState.Initial)
  91. {
  92. lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
  93. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
  94. // lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
  95. }
  96. return lease;
  97. }
  98. /// <summary>
  99. /// Get current AppDomain
  100. /// </summary>
  101. /// <returns>Current AppDomain</returns>
  102. public AppDomain GetAppDomain()
  103. {
  104. return AppDomain.CurrentDomain;
  105. }
  106. /// <summary>
  107. /// Execute a specific function/event in script.
  108. /// </summary>
  109. /// <param name="FunctionName">Name of function to execute</param>
  110. /// <param name="args">Arguments to pass to function</param>
  111. public void ExecuteEvent(string FunctionName, object[] args)
  112. {
  113. DoExecuteEvent(FunctionName, args);
  114. }
  115. protected abstract void DoExecuteEvent(string FunctionName, object[] args);
  116. /// <summary>
  117. /// Compute the events handled by the current state of the script
  118. /// </summary>
  119. /// <returns>state mask</returns>
  120. public scriptEvents GetStateEventFlags()
  121. {
  122. return DoGetStateEventFlags();
  123. }
  124. protected abstract scriptEvents DoGetStateEventFlags();
  125. protected void initEventFlags()
  126. {
  127. // Initialize the table if it hasn't already been done
  128. if (m_eventFlagsMap.Count > 0)
  129. {
  130. return;
  131. }
  132. m_eventFlagsMap.Add("attach", scriptEvents.attach);
  133. // m_eventFlagsMap.Add("at_rot_target",(long)scriptEvents.at_rot_target);
  134. m_eventFlagsMap.Add("at_target", scriptEvents.at_target);
  135. // m_eventFlagsMap.Add("changed",(long)scriptEvents.changed);
  136. m_eventFlagsMap.Add("collision", scriptEvents.collision);
  137. m_eventFlagsMap.Add("collision_end", scriptEvents.collision_end);
  138. m_eventFlagsMap.Add("collision_start", scriptEvents.collision_start);
  139. m_eventFlagsMap.Add("control", scriptEvents.control);
  140. m_eventFlagsMap.Add("dataserver", scriptEvents.dataserver);
  141. m_eventFlagsMap.Add("email", scriptEvents.email);
  142. m_eventFlagsMap.Add("http_response", scriptEvents.http_response);
  143. m_eventFlagsMap.Add("land_collision", scriptEvents.land_collision);
  144. m_eventFlagsMap.Add("land_collision_end", scriptEvents.land_collision_end);
  145. m_eventFlagsMap.Add("land_collision_start", scriptEvents.land_collision_start);
  146. // m_eventFlagsMap.Add("link_message",scriptEvents.link_message);
  147. m_eventFlagsMap.Add("listen", scriptEvents.listen);
  148. m_eventFlagsMap.Add("money", scriptEvents.money);
  149. m_eventFlagsMap.Add("moving_end", scriptEvents.moving_end);
  150. m_eventFlagsMap.Add("moving_start", scriptEvents.moving_start);
  151. m_eventFlagsMap.Add("not_at_rot_target", scriptEvents.not_at_rot_target);
  152. m_eventFlagsMap.Add("not_at_target", scriptEvents.not_at_target);
  153. // m_eventFlagsMap.Add("no_sensor",(long)scriptEvents.no_sensor);
  154. // m_eventFlagsMap.Add("on_rez",(long)scriptEvents.on_rez);
  155. m_eventFlagsMap.Add("remote_data", scriptEvents.remote_data);
  156. m_eventFlagsMap.Add("run_time_permissions", scriptEvents.run_time_permissions);
  157. // m_eventFlagsMap.Add("sensor",(long)scriptEvents.sensor);
  158. m_eventFlagsMap.Add("state_entry", scriptEvents.state_entry);
  159. m_eventFlagsMap.Add("state_exit", scriptEvents.state_exit);
  160. m_eventFlagsMap.Add("timer", scriptEvents.timer);
  161. m_eventFlagsMap.Add("touch", scriptEvents.touch);
  162. m_eventFlagsMap.Add("touch_end", scriptEvents.touch_end);
  163. m_eventFlagsMap.Add("touch_start", scriptEvents.touch_start);
  164. m_eventFlagsMap.Add("object_rez", scriptEvents.object_rez);
  165. }
  166. }
  167. }