OSSL_Api.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 Axiom.Math;
  29. using libsecondlife;
  30. using Nini.Config;
  31. using OpenSim.Framework.Console;
  32. using OpenSim.Region.Environment.Interfaces;
  33. using OpenSim.Region.Environment.Scenes;
  34. using OpenSim.Region.ScriptEngine.Shared;
  35. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  36. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  37. using OpenSim.Region.ScriptEngine.Interfaces;
  38. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  39. namespace OpenSim.Region.ScriptEngine.Shared.Api
  40. {
  41. [Serializable]
  42. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  43. {
  44. internal IScriptEngine m_ScriptEngine;
  45. internal SceneObjectPart m_host;
  46. internal uint m_localID;
  47. internal LLUUID m_itemID;
  48. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, LLUUID itemID)
  49. {
  50. m_ScriptEngine = ScriptEngine;
  51. m_host = host;
  52. m_localID = localID;
  53. m_itemID = itemID;
  54. }
  55. //
  56. // OpenSim functions
  57. //
  58. public int osTerrainSetHeight(int x, int y, double val)
  59. {
  60. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  61. {
  62. OSSLError("osTerrainSetHeight: permission denied");
  63. return 0;
  64. }
  65. m_host.AddScriptLPS(1);
  66. if (x > 255 || x < 0 || y > 255 || y < 0)
  67. OSSLError("osTerrainSetHeight: Coordinate out of bounds");
  68. if (World.ExternalChecks.ExternalChecksCanTerraformLand(m_host.OwnerID, new LLVector3(x, y, 0)))
  69. {
  70. World.Heightmap[x, y] = val;
  71. return 1;
  72. }
  73. else
  74. {
  75. return 0;
  76. }
  77. }
  78. public double osTerrainGetHeight(int x, int y)
  79. {
  80. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  81. {
  82. OSSLError("osTerrainGetHeight: permission denied");
  83. return 0.0;
  84. }
  85. m_host.AddScriptLPS(1);
  86. if (x > 255 || x < 0 || y > 255 || y < 0)
  87. OSSLError("osTerrainGetHeight: Coordinate out of bounds");
  88. return World.Heightmap[x, y];
  89. }
  90. public int osRegionRestart(double seconds)
  91. {
  92. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  93. {
  94. OSSLError("osRegionRestart: permission denied");
  95. return 0;
  96. }
  97. m_host.AddScriptLPS(1);
  98. if (World.ExternalChecks.ExternalChecksCanIssueEstateCommand(m_host.OwnerID))
  99. {
  100. World.Restart((float)seconds);
  101. return 1;
  102. }
  103. else
  104. {
  105. return 0;
  106. }
  107. }
  108. public void osRegionNotice(string msg)
  109. {
  110. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  111. {
  112. OSSLError("osRegionNotice: permission denied");
  113. return;
  114. }
  115. m_host.AddScriptLPS(1);
  116. World.SendGeneralAlert(msg);
  117. }
  118. public void osSetRot(LLUUID target, Quaternion rotation)
  119. {
  120. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  121. {
  122. OSSLError("osSetRot: permission denied");
  123. return;
  124. }
  125. m_host.AddScriptLPS(1);
  126. if (World.Entities.ContainsKey(target))
  127. {
  128. World.Entities[target].Rotation = rotation;
  129. }
  130. else
  131. {
  132. OSSLError("osSetRot: Invalid target");
  133. }
  134. }
  135. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  136. int timer)
  137. {
  138. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  139. {
  140. OSSLError("osSetDynamicTextureURL: permission denied");
  141. return String.Empty;
  142. }
  143. m_host.AddScriptLPS(1);
  144. if (dynamicID == String.Empty)
  145. {
  146. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  147. LLUUID createdTexture =
  148. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  149. extraParams, timer);
  150. return createdTexture.ToString();
  151. }
  152. else
  153. {
  154. //TODO update existing dynamic textures
  155. }
  156. return LLUUID.Zero.ToString();
  157. }
  158. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  159. int timer, int alpha)
  160. {
  161. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  162. {
  163. OSSLError("osSetDynamicTextureURLBlend: permission denied");
  164. return String.Empty;
  165. }
  166. m_host.AddScriptLPS(1);
  167. if (dynamicID == String.Empty)
  168. {
  169. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  170. LLUUID createdTexture =
  171. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  172. extraParams, timer, true, (byte) alpha);
  173. return createdTexture.ToString();
  174. }
  175. else
  176. {
  177. //TODO update existing dynamic textures
  178. }
  179. return LLUUID.Zero.ToString();
  180. }
  181. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  182. int timer)
  183. {
  184. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  185. {
  186. OSSLError("osSetDynamicTextureData: permission denied");
  187. return String.Empty;
  188. }
  189. m_host.AddScriptLPS(1);
  190. if (dynamicID == String.Empty)
  191. {
  192. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  193. if (textureManager != null)
  194. {
  195. LLUUID createdTexture =
  196. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  197. extraParams, timer);
  198. return createdTexture.ToString();
  199. }
  200. }
  201. else
  202. {
  203. //TODO update existing dynamic textures
  204. }
  205. return LLUUID.Zero.ToString();
  206. }
  207. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  208. int timer, int alpha)
  209. {
  210. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  211. {
  212. OSSLError("osSetDynamicTextureDataBlend: permission denied");
  213. return String.Empty;
  214. }
  215. m_host.AddScriptLPS(1);
  216. if (dynamicID == String.Empty)
  217. {
  218. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  219. if (textureManager != null)
  220. {
  221. LLUUID createdTexture =
  222. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  223. extraParams, timer, true, (byte) alpha);
  224. return createdTexture.ToString();
  225. }
  226. }
  227. else
  228. {
  229. //TODO update existing dynamic textures
  230. }
  231. return LLUUID.Zero.ToString();
  232. }
  233. public bool osConsoleCommand(string command)
  234. {
  235. m_host.AddScriptLPS(1);
  236. if (m_ScriptEngine.Config.GetBoolean("AllowosConsoleCommand", false))
  237. {
  238. if (World.ExternalChecks.ExternalChecksCanRunConsoleCommand(m_host.OwnerID))
  239. {
  240. MainConsole.Instance.RunCommand(command);
  241. return true;
  242. }
  243. return false;
  244. }
  245. return false;
  246. }
  247. public void osSetPrimFloatOnWater(int floatYN)
  248. {
  249. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  250. {
  251. OSSLError("osSetPrimFloatOnWater: permission denied");
  252. return;
  253. }
  254. m_host.AddScriptLPS(1);
  255. if (m_host.ParentGroup != null)
  256. {
  257. if (m_host.ParentGroup.RootPart != null)
  258. {
  259. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  260. }
  261. }
  262. }
  263. // Adam's super super custom animation functions
  264. public void osAvatarPlayAnimation(string avatar, string animation)
  265. {
  266. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  267. {
  268. OSSLError("osAvatarPlayAnimation: permission denied");
  269. return;
  270. }
  271. m_host.AddScriptLPS(1);
  272. if (World.Entities.ContainsKey(avatar) && World.Entities[avatar] is ScenePresence)
  273. {
  274. ScenePresence target = (ScenePresence)World.Entities[avatar];
  275. target.AddAnimation(avatar);
  276. }
  277. }
  278. public void osAvatarStopAnimation(string avatar, string animation)
  279. {
  280. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  281. {
  282. OSSLError("osAvatarStopAnimation: permission denied");
  283. return;
  284. }
  285. m_host.AddScriptLPS(1);
  286. if (World.Entities.ContainsKey(avatar) && World.Entities[avatar] is ScenePresence)
  287. {
  288. ScenePresence target = (ScenePresence)World.Entities[avatar];
  289. target.RemoveAnimation(animation);
  290. }
  291. }
  292. //Texture draw functions
  293. public string osMovePen(string drawList, int x, int y)
  294. {
  295. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  296. {
  297. OSSLError("osMovePen: permission denied");
  298. return String.Empty;
  299. }
  300. m_host.AddScriptLPS(1);
  301. drawList += "MoveTo " + x + "," + y + ";";
  302. return drawList;
  303. }
  304. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  305. {
  306. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  307. {
  308. OSSLError("osDrawLine: permission denied");
  309. return String.Empty;
  310. }
  311. m_host.AddScriptLPS(1);
  312. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  313. return drawList;
  314. }
  315. public string osDrawLine(string drawList, int endX, int endY)
  316. {
  317. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  318. {
  319. OSSLError("osDrawLine: permission denied");
  320. return String.Empty;
  321. }
  322. m_host.AddScriptLPS(1);
  323. drawList += "LineTo " + endX + "," + endY + "; ";
  324. return drawList;
  325. }
  326. public string osDrawText(string drawList, string text)
  327. {
  328. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  329. {
  330. OSSLError("osDrawText: permission denied");
  331. return String.Empty;
  332. }
  333. m_host.AddScriptLPS(1);
  334. drawList += "Text " + text + "; ";
  335. return drawList;
  336. }
  337. public string osDrawEllipse(string drawList, int width, int height)
  338. {
  339. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  340. {
  341. OSSLError("osDrawEllipse: permission denied");
  342. return String.Empty;
  343. }
  344. m_host.AddScriptLPS(1);
  345. drawList += "Ellipse " + width + "," + height + "; ";
  346. return drawList;
  347. }
  348. public string osDrawRectangle(string drawList, int width, int height)
  349. {
  350. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  351. {
  352. OSSLError("osDrawRectangle: permission denied");
  353. return String.Empty;
  354. }
  355. m_host.AddScriptLPS(1);
  356. drawList += "Rectangle " + width + "," + height + "; ";
  357. return drawList;
  358. }
  359. public string osDrawFilledRectangle(string drawList, int width, int height)
  360. {
  361. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  362. {
  363. OSSLError("osDrawFilledRectangle: permission denied");
  364. return String.Empty;
  365. }
  366. m_host.AddScriptLPS(1);
  367. drawList += "FillRectangle " + width + "," + height + "; ";
  368. return drawList;
  369. }
  370. public string osSetFontSize(string drawList, int fontSize)
  371. {
  372. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  373. {
  374. OSSLError("osSetFontSize: permission denied");
  375. return String.Empty;
  376. }
  377. m_host.AddScriptLPS(1);
  378. drawList += "FontSize "+ fontSize +"; ";
  379. return drawList;
  380. }
  381. public string osSetPenSize(string drawList, int penSize)
  382. {
  383. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  384. {
  385. OSSLError("osSetPenSize: permission denied");
  386. return String.Empty;
  387. }
  388. m_host.AddScriptLPS(1);
  389. drawList += "PenSize " + penSize + "; ";
  390. return drawList;
  391. }
  392. public string osSetPenColour(string drawList, string colour)
  393. {
  394. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  395. {
  396. OSSLError("osSetPenColour: permission denied");
  397. return String.Empty;
  398. }
  399. m_host.AddScriptLPS(1);
  400. drawList += "PenColour " + colour + "; ";
  401. return drawList;
  402. }
  403. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  404. {
  405. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  406. {
  407. OSSLError("osDrawImage: permission denied");
  408. return String.Empty;
  409. }
  410. m_host.AddScriptLPS(1);
  411. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  412. return drawList;
  413. }
  414. public void osSetStateEvents(int events)
  415. {
  416. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  417. {
  418. OSSLError("osSetStateEvents: permission denied");
  419. return;
  420. }
  421. m_host.SetScriptEvents(m_itemID, events);
  422. }
  423. public void osSetRegionWaterHeight(double height)
  424. {
  425. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  426. {
  427. OSSLError("osSetRegionWaterHeight: permission denied");
  428. return;
  429. }
  430. m_host.AddScriptLPS(1);
  431. //Check to make sure that the script's owner is the estate manager/master
  432. //World.Permissions.GenericEstatePermission(
  433. if (World.ExternalChecks.ExternalChecksCanBeGodLike(m_host.OwnerID))
  434. {
  435. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  436. }
  437. }
  438. public double osList2Double(LSL_Types.list src, int index)
  439. {
  440. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  441. {
  442. OSSLError("osList2Double: permission denied");
  443. return 0.0;
  444. }
  445. m_host.AddScriptLPS(1);
  446. if (index < 0)
  447. {
  448. index = src.Length + index;
  449. }
  450. if (index >= src.Length)
  451. {
  452. return 0.0;
  453. }
  454. return Convert.ToDouble(src.Data[index]);
  455. }
  456. public void osSetParcelMediaURL(string url)
  457. {
  458. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  459. {
  460. OSSLError("osSetParcelMediaURL: permission denied");
  461. return;
  462. }
  463. m_host.AddScriptLPS(1);
  464. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  465. if (landowner == LLUUID.Zero)
  466. {
  467. return;
  468. }
  469. if (landowner != m_host.ObjectOwner)
  470. {
  471. return;
  472. }
  473. World.SetLandMediaURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  474. }
  475. public Scene World
  476. {
  477. get { return m_ScriptEngine.World; }
  478. }
  479. internal void OSSLError(string msg)
  480. {
  481. throw new Exception("OSSL Runtime Error: " + msg);
  482. }
  483. public string osGetScriptEngineName()
  484. {
  485. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  486. {
  487. OSSLError("osGetScriptEngineName: permission denied");
  488. return "";
  489. }
  490. m_host.AddScriptLPS(1);
  491. int scriptEngineNameIndex = 0;
  492. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  493. {
  494. // parse off the "ScriptEngine."
  495. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  496. scriptEngineNameIndex++; // get past delimiter
  497. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  498. // create char array then a string that is only the script engine name
  499. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  500. String scriptEngineName = new String(scriptEngineNameCharArray);
  501. return scriptEngineName;
  502. }
  503. else
  504. {
  505. return String.Empty;
  506. }
  507. }
  508. //for testing purposes only
  509. public void osSetParcelMediaTime(double time)
  510. {
  511. if (!m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  512. {
  513. OSSLError("osSetParcelMediaTime: permission denied");
  514. return;
  515. }
  516. m_host.AddScriptLPS(1);
  517. World.ParcelMediaSetTime((float)time);
  518. }
  519. }
  520. }