OSSL_BuilIn_Commands.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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.DotNetEngine.Compiler.LSL;
  35. namespace OpenSim.Region.ScriptEngine.Common
  36. {
  37. public class OSSL_BuilIn_Commands : LSL_BuiltIn_Commands, OSSL_BuilIn_Commands_Interface
  38. {
  39. public OSSL_BuilIn_Commands(ScriptEngineBase.ScriptEngine scriptEngine, SceneObjectPart host, uint localID,
  40. LLUUID itemID)
  41. : base(scriptEngine, host, localID, itemID)
  42. {
  43. Prim = new OSSLPrim(this);
  44. }
  45. public OSSLPrim Prim;
  46. [Serializable]
  47. public class OSSLPrim
  48. {
  49. internal OSSL_BuilIn_Commands OSSL;
  50. public OSSLPrim(OSSL_BuilIn_Commands bc)
  51. {
  52. OSSL = bc;
  53. Position = new OSSLPrim_Position(this);
  54. Rotation = new OSSLPrim_Rotation(this);
  55. }
  56. public OSSLPrim_Position Position;
  57. public OSSLPrim_Rotation Rotation;
  58. //public LSL_Types.Vector3 Position
  59. //{
  60. // get { return OSSL.llGetPos(); }
  61. // set { OSSL.llSetPos(value); }
  62. //}
  63. //public LSL_Types.Quaternion Rotation
  64. //{
  65. // get { return OSSL.llGetRot(); }
  66. // set { OSSL.llSetRot(value); }
  67. //}
  68. private TextStruct _text;
  69. public TextStruct Text
  70. {
  71. get { return _text; }
  72. set
  73. {
  74. _text = value;
  75. OSSL.llSetText(_text.Text, _text.color, _text.alpha);
  76. }
  77. }
  78. [Serializable]
  79. public struct TextStruct
  80. {
  81. public string Text;
  82. public LSL_Types.Vector3 color;
  83. public double alpha;
  84. }
  85. }
  86. [Serializable]
  87. public class OSSLPrim_Position
  88. {
  89. private OSSLPrim prim;
  90. private LSL_Types.Vector3 Position;
  91. public OSSLPrim_Position(OSSLPrim _prim)
  92. {
  93. prim = _prim;
  94. }
  95. private void Load()
  96. {
  97. Position = prim.OSSL.llGetPos();
  98. }
  99. private void Save()
  100. {
  101. if (Position.x > 255)
  102. Position.x = 255;
  103. if (Position.x < 0)
  104. Position.x = 0;
  105. if (Position.y > 255)
  106. Position.y = 255;
  107. if (Position.y < 0)
  108. Position.y = 0;
  109. if (Position.z > 768)
  110. Position.z = 768;
  111. if (Position.z < 0)
  112. Position.z = 0;
  113. prim.OSSL.llSetPos(Position);
  114. }
  115. public double x
  116. {
  117. get
  118. {
  119. Load();
  120. return Position.x;
  121. }
  122. set
  123. {
  124. Load();
  125. Position.x = value;
  126. Save();
  127. }
  128. }
  129. public double y
  130. {
  131. get
  132. {
  133. Load();
  134. return Position.y;
  135. }
  136. set
  137. {
  138. Load();
  139. Position.y = value;
  140. Save();
  141. }
  142. }
  143. public double z
  144. {
  145. get
  146. {
  147. Load();
  148. return Position.z;
  149. }
  150. set
  151. {
  152. Load();
  153. Position.z = value;
  154. Save();
  155. }
  156. }
  157. }
  158. [Serializable]
  159. public class OSSLPrim_Rotation
  160. {
  161. private OSSLPrim prim;
  162. private LSL_Types.Quaternion Rotation;
  163. public OSSLPrim_Rotation(OSSLPrim _prim)
  164. {
  165. prim = _prim;
  166. }
  167. private void Load()
  168. {
  169. Rotation = prim.OSSL.llGetRot();
  170. }
  171. private void Save()
  172. {
  173. prim.OSSL.llSetRot(Rotation);
  174. }
  175. public double x
  176. {
  177. get
  178. {
  179. Load();
  180. return Rotation.x;
  181. }
  182. set
  183. {
  184. Load();
  185. Rotation.x = value;
  186. Save();
  187. }
  188. }
  189. public double y
  190. {
  191. get
  192. {
  193. Load();
  194. return Rotation.y;
  195. }
  196. set
  197. {
  198. Load();
  199. Rotation.y = value;
  200. Save();
  201. }
  202. }
  203. public double z
  204. {
  205. get
  206. {
  207. Load();
  208. return Rotation.z;
  209. }
  210. set
  211. {
  212. Load();
  213. Rotation.z = value;
  214. Save();
  215. }
  216. }
  217. public double s
  218. {
  219. get
  220. {
  221. Load();
  222. return Rotation.s;
  223. }
  224. set
  225. {
  226. Load();
  227. Rotation.s = value;
  228. Save();
  229. }
  230. }
  231. }
  232. //public struct OSSLPrim_Rotation
  233. //{
  234. // public double X;
  235. // public double Y;
  236. // public double Z;
  237. // public double R;
  238. //}
  239. //
  240. // OpenSim functions
  241. //
  242. public int osTerrainSetHeight(int x, int y, double val)
  243. {
  244. m_host.AddScriptLPS(1);
  245. if (x > 255 || x < 0 || y > 255 || y < 0)
  246. LSLError("osTerrainSetHeight: Coordinate out of bounds");
  247. if (World.PermissionsMngr.CanTerraform(m_host.OwnerID, new LLVector3(x, y, 0)))
  248. {
  249. World.Heightmap[x, y] = val;
  250. return 1;
  251. }
  252. else
  253. {
  254. return 0;
  255. }
  256. }
  257. public double osTerrainGetHeight(int x, int y)
  258. {
  259. m_host.AddScriptLPS(1);
  260. if (x > 255 || x < 0 || y > 255 || y < 0)
  261. LSLError("osTerrainGetHeight: Coordinate out of bounds");
  262. return World.Heightmap[x, y];
  263. }
  264. public int osRegionRestart(double seconds)
  265. {
  266. m_host.AddScriptLPS(1);
  267. if (World.PermissionsMngr.CanRestartSim(m_host.OwnerID))
  268. {
  269. World.Restart((float)seconds);
  270. return 1;
  271. }
  272. else
  273. {
  274. return 0;
  275. }
  276. }
  277. public void osRegionNotice(string msg)
  278. {
  279. m_host.AddScriptLPS(1);
  280. World.SendGeneralAlert(msg);
  281. }
  282. public void osSetRot(LLUUID target, Quaternion rotation)
  283. {
  284. m_host.AddScriptLPS(1);
  285. if (World.Entities.ContainsKey(target))
  286. {
  287. World.Entities[target].Rotation = rotation;
  288. }
  289. else
  290. {
  291. LSLError("osSetRot: Invalid target");
  292. }
  293. }
  294. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  295. int timer)
  296. {
  297. m_host.AddScriptLPS(1);
  298. if (dynamicID == String.Empty)
  299. {
  300. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  301. LLUUID createdTexture =
  302. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  303. extraParams, timer);
  304. return createdTexture.ToString();
  305. }
  306. else
  307. {
  308. //TODO update existing dynamic textures
  309. }
  310. return LLUUID.Zero.ToString();
  311. }
  312. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  313. int timer, int alpha)
  314. {
  315. m_host.AddScriptLPS(1);
  316. if (dynamicID == String.Empty)
  317. {
  318. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  319. LLUUID createdTexture =
  320. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  321. extraParams, timer, true, (byte) alpha );
  322. return createdTexture.ToString();
  323. }
  324. else
  325. {
  326. //TODO update existing dynamic textures
  327. }
  328. return LLUUID.Zero.ToString();
  329. }
  330. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  331. int timer)
  332. {
  333. m_host.AddScriptLPS(1);
  334. if (dynamicID == String.Empty)
  335. {
  336. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  337. if (textureManager != null)
  338. {
  339. LLUUID createdTexture =
  340. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  341. extraParams, timer);
  342. return createdTexture.ToString();
  343. }
  344. }
  345. else
  346. {
  347. //TODO update existing dynamic textures
  348. }
  349. return LLUUID.Zero.ToString();
  350. }
  351. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  352. int timer, int alpha)
  353. {
  354. m_host.AddScriptLPS(1);
  355. if (dynamicID == String.Empty)
  356. {
  357. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  358. if (textureManager != null)
  359. {
  360. LLUUID createdTexture =
  361. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  362. extraParams, timer, true, (byte) alpha);
  363. return createdTexture.ToString();
  364. }
  365. }
  366. else
  367. {
  368. //TODO update existing dynamic textures
  369. }
  370. return LLUUID.Zero.ToString();
  371. }
  372. public bool osConsoleCommand(string command)
  373. {
  374. m_host.AddScriptLPS(1);
  375. IConfigSource config = new IniConfigSource(Application.iniFilePath);
  376. if (config.Configs["LL-Functions"] == null)
  377. config.AddConfig("LL-Functions");
  378. if (config.Configs["LL-Functions"].GetBoolean("AllowosConsoleCommand", false))
  379. {
  380. if (World.PermissionsMngr.CanRunConsoleCommand(m_host.OwnerID))
  381. {
  382. MainConsole.Instance.RunCommand(command);
  383. return true;
  384. }
  385. return false;
  386. }
  387. return false;
  388. }
  389. public void osSetPrimFloatOnWater(int floatYN)
  390. {
  391. m_host.AddScriptLPS(1);
  392. if (m_host.ParentGroup != null)
  393. {
  394. if (m_host.ParentGroup.RootPart != null)
  395. {
  396. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  397. }
  398. }
  399. }
  400. // Adam's super super custom animation functions
  401. public void osAvatarPlayAnimation(string avatar, string animation)
  402. {
  403. m_host.AddScriptLPS(1);
  404. if (World.Entities.ContainsKey(avatar) && World.Entities[avatar] is ScenePresence)
  405. {
  406. ScenePresence target = (ScenePresence)World.Entities[avatar];
  407. target.AddAnimation(avatar);
  408. }
  409. }
  410. public void osAvatarStopAnimation(string avatar, string animation)
  411. {
  412. m_host.AddScriptLPS(1);
  413. if (World.Entities.ContainsKey(avatar) && World.Entities[avatar] is ScenePresence)
  414. {
  415. ScenePresence target = (ScenePresence)World.Entities[avatar];
  416. target.RemoveAnimation(animation);
  417. }
  418. }
  419. //Texture draw functions
  420. public string osMovePen(string drawList, int x, int y)
  421. {
  422. m_host.AddScriptLPS(1);
  423. drawList += "MoveTo " + x + "," + y + ";";
  424. return drawList;
  425. }
  426. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  427. {
  428. m_host.AddScriptLPS(1);
  429. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  430. return drawList;
  431. }
  432. public string osDrawLine(string drawList, int endX, int endY)
  433. {
  434. m_host.AddScriptLPS(1);
  435. drawList += "LineTo " + endX + "," + endY + "; ";
  436. return drawList;
  437. }
  438. public string osDrawText(string drawList, string text)
  439. {
  440. m_host.AddScriptLPS(1);
  441. drawList += "Text " + text + "; ";
  442. return drawList;
  443. }
  444. public string osDrawEllipse(string drawList, int width, int height)
  445. {
  446. m_host.AddScriptLPS(1);
  447. drawList += "Ellipse " + width + "," + height + "; ";
  448. return drawList;
  449. }
  450. public string osDrawRectangle(string drawList, int width, int height)
  451. {
  452. m_host.AddScriptLPS(1);
  453. drawList += "Rectangle " + width + "," + height + "; ";
  454. return drawList;
  455. }
  456. public string osDrawFilledRectangle(string drawList, int width, int height)
  457. {
  458. m_host.AddScriptLPS(1);
  459. drawList += "FillRectangle " + width + "," + height + "; ";
  460. return drawList;
  461. }
  462. public string osSetFontSize(string drawList, int fontSize)
  463. {
  464. m_host.AddScriptLPS(1);
  465. drawList += "FontSize "+ fontSize +"; ";
  466. return drawList;
  467. }
  468. public string osSetPenSize(string drawList, int penSize)
  469. {
  470. m_host.AddScriptLPS(1);
  471. drawList += "PenSize " + penSize + "; ";
  472. return drawList;
  473. }
  474. public string osSetPenColour(string drawList, string colour)
  475. {
  476. m_host.AddScriptLPS(1);
  477. drawList += "PenColour " + colour + "; ";
  478. return drawList;
  479. }
  480. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  481. {
  482. m_host.AddScriptLPS(1);
  483. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  484. return drawList;
  485. }
  486. public void osSetStateEvents(int events)
  487. {
  488. m_host.SetScriptEvents(m_itemID, events);
  489. }
  490. }
  491. }