OSSL_BuilIn_Commands.cs 18 KB

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