MOD_Api.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. using System;
  28. using System.Reflection;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Runtime.Remoting.Lifetime;
  32. using OpenMetaverse;
  33. using Nini.Config;
  34. using OpenSim;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Region.ScriptEngine.Shared;
  39. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  40. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  41. using OpenSim.Region.ScriptEngine.Interfaces;
  42. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  43. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  44. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  45. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  46. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  47. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  48. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  49. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  50. namespace OpenSim.Region.ScriptEngine.Shared.Api
  51. {
  52. [Serializable]
  53. public class MOD_Api : MarshalByRefObject, IMOD_Api, IScriptApi
  54. {
  55. internal IScriptEngine m_ScriptEngine;
  56. internal SceneObjectPart m_host;
  57. internal uint m_localID;
  58. internal UUID m_itemID;
  59. internal bool m_MODFunctionsEnabled = false;
  60. internal IScriptModuleComms m_comms = null;
  61. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
  62. {
  63. m_ScriptEngine = ScriptEngine;
  64. m_host = host;
  65. m_localID = localID;
  66. m_itemID = itemID;
  67. if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
  68. m_MODFunctionsEnabled = true;
  69. m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
  70. if (m_comms == null)
  71. m_MODFunctionsEnabled = false;
  72. }
  73. public override Object InitializeLifetimeService()
  74. {
  75. ILease lease = (ILease)base.InitializeLifetimeService();
  76. if (lease.CurrentState == LeaseState.Initial)
  77. {
  78. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  79. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  80. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  81. }
  82. return lease;
  83. }
  84. public Scene World
  85. {
  86. get { return m_ScriptEngine.World; }
  87. }
  88. internal void MODError(string msg)
  89. {
  90. throw new Exception("MOD Runtime Error: " + msg);
  91. }
  92. //
  93. //Dumps an error message on the debug console.
  94. //
  95. internal void MODShoutError(string message)
  96. {
  97. if (message.Length > 1023)
  98. message = message.Substring(0, 1023);
  99. World.SimChat(Utils.StringToBytes(message),
  100. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  101. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  102. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  103. }
  104. public string modSendCommand(string module, string command, string k)
  105. {
  106. if (!m_MODFunctionsEnabled)
  107. {
  108. MODShoutError("Module command functions not enabled");
  109. return UUID.Zero.ToString();;
  110. }
  111. UUID req = UUID.Random();
  112. m_comms.RaiseEvent(m_itemID, req.ToString(), module, command, k);
  113. return req.ToString();
  114. }
  115. }
  116. }