RexScriptInterface.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. using Axiom.Math;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.IO;
  6. using OpenSim.Framework;
  7. using OpenSim.Framework.Console;
  8. using OpenSim.Framework.Communications.Cache;
  9. using OpenSim.Region.Environment.Scenes;
  10. using OpenSim.Region.Environment.Scenes.Scripting;
  11. using OpenSim.Region.Environment.Interfaces;
  12. using OpenSim.Region.ScriptEngine.Common;
  13. using OpenSim.Region.ScriptEngine.DotNetEngine;
  14. using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler;
  15. using libsecondlife;
  16. namespace OpenSim.Region.RexScriptModule
  17. {
  18. public class RexScriptInterface : LSL_BuiltIn_Commands
  19. {
  20. private RexScriptEngine myScriptEngine;
  21. public RexScriptInterface(OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine ScriptEngine, SceneObjectPart host, uint localID, LLUUID itemID, RexScriptEngine vScriptEngine)
  22. : base(ScriptEngine, host, localID, itemID)
  23. {
  24. myScriptEngine = vScriptEngine;
  25. m_ScriptEngine = new OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine();
  26. m_ScriptEngine.World = myScriptEngine.World;
  27. }
  28. private EntityBase GetEntityBase(uint vId)
  29. {
  30. SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(vId);
  31. if (part != null && (EntityBase)(part.ParentGroup) != null)
  32. return (EntityBase)(part.ParentGroup);
  33. else
  34. return null;
  35. }
  36. // Functions exposed to Python!
  37. // *********************************
  38. public bool SetScriptRunner(string vId)
  39. {
  40. uint id = System.Convert.ToUInt32(vId, 10);
  41. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(id);
  42. if (tempobj != null)
  43. {
  44. m_host = tempobj;
  45. m_localID = tempobj.LocalID;
  46. m_itemID = tempobj.UUID;
  47. return true;
  48. }
  49. else
  50. return false;
  51. }
  52. public void CommandToClient(string vPresenceId, string vUnit, string vCommand, string vCmdParams)
  53. {
  54. LLUUID TempId = new LLUUID(vPresenceId);
  55. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  56. if (temppre != null)
  57. temppre.ControllingClient.SendRexScriptCommand(vUnit,vCommand,vCmdParams);
  58. }
  59. public bool GetPhysics(string vId)
  60. {
  61. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  62. if (tempobj != null)
  63. return ((tempobj.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) != 0);
  64. else
  65. return false;
  66. }
  67. public void SetPhysics(string vId, bool vbUsePhysics)
  68. {
  69. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  70. if (tempobj != null)
  71. {
  72. if (vbUsePhysics)
  73. tempobj.AddFlag(LLObject.ObjectFlags.Physics);
  74. else
  75. tempobj.RemFlag(LLObject.ObjectFlags.Physics);
  76. tempobj.DoPhysicsPropertyUpdate(vbUsePhysics, false);
  77. tempobj.ScheduleFullUpdate();
  78. }
  79. else
  80. myScriptEngine.Log.Verbose("PythonScript", "SetPhysics for nonexisting object:" + vId);
  81. }
  82. public void SetMass(string vId, float vMass)
  83. {
  84. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  85. if (tempobj != null)
  86. tempobj.SetMass(vMass);
  87. else
  88. myScriptEngine.Log.Verbose("PythonScript", "SetMass for nonexisting object:" + vId);
  89. }
  90. public void SetVelocity(string vId, LSL_Types.Vector3 vVelocity)
  91. {
  92. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  93. if (((SceneObjectPart)tempobj) != null)
  94. {
  95. LLVector3 tempvel = new LLVector3((float)vVelocity.x, (float)vVelocity.y, (float)vVelocity.z);
  96. tempobj.Velocity = tempvel;
  97. }
  98. }
  99. public bool GetUsePrimVolumeCollision(string vId)
  100. {
  101. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  102. if (tempobj != null)
  103. return tempobj.GetUsePrimVolumeCollision();
  104. else
  105. return false;
  106. }
  107. public void SetUsePrimVolumeCollision(string vId, bool vUseVolumeCollision)
  108. {
  109. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  110. if (tempobj != null)
  111. tempobj.SetUsePrimVolumeCollision(vUseVolumeCollision);
  112. else
  113. myScriptEngine.Log.Verbose("PythonScript", "SetPrimVolumeCollision for nonexisting object:" + vId);
  114. }
  115. // text messaging
  116. // ******************************
  117. public void SendGeneralAlertAll(string vId, string vMessage)
  118. {
  119. myScriptEngine.World.SendGeneralAlert(vMessage);
  120. }
  121. public void SendAlertToAvatar(string vId,string vPresenceId, string vMessage, bool vbModal)
  122. {
  123. LLUUID TempId = new LLUUID(vPresenceId);
  124. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  125. if (temppre != null)
  126. {
  127. temppre.ControllingClient.SendAgentAlertMessage(vMessage, vbModal);
  128. }
  129. }
  130. // Actor finding.
  131. public List<string> GetRadiusActors(string vId,float vRadius)
  132. {
  133. List<string> TempList = new List<string>();
  134. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  135. if (tempobj != null)
  136. {
  137. List<EntityBase> EntitiesList = myScriptEngine.World.GetEntities();
  138. foreach (EntityBase ent in EntitiesList)
  139. {
  140. if (ent is SceneObjectGroup || ent is ScenePresence)
  141. {
  142. if (Util.GetDistanceTo(ent.AbsolutePosition, tempobj.AbsolutePosition) < vRadius)
  143. TempList.Add(ent.LocalId.ToString());
  144. }
  145. }
  146. }
  147. return TempList;
  148. }
  149. public List<string> GetRadiusAvatars(string vId, float vRadius)
  150. {
  151. List<string> TempList = new List<string>();
  152. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  153. if (tempobj != null)
  154. {
  155. List<EntityBase> EntitiesList = myScriptEngine.World.GetEntities();
  156. foreach (EntityBase ent in EntitiesList)
  157. {
  158. if (ent is ScenePresence)
  159. {
  160. if (Util.GetDistanceTo(ent.AbsolutePosition, tempobj.AbsolutePosition) < vRadius)
  161. TempList.Add(ent.LocalId.ToString());
  162. }
  163. }
  164. }
  165. return TempList;
  166. }
  167. public string SpawnActor(LSL_Types.Vector3 vLoc, int vShape, bool vbTemporary, string vPyClass)
  168. {
  169. LLUUID TempID = myScriptEngine.World.RegionInfo.MasterAvatarAssignedUUID;
  170. LLVector3 pos = new LLVector3((float)vLoc.x, (float)vLoc.y, (float)vLoc.z);
  171. LLQuaternion rot = new LLQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
  172. uint AddResult = myScriptEngine.World.AddNewPrimReturningId(TempID, pos, rot, GetShape(vShape),vbTemporary,vPyClass);
  173. return AddResult.ToString();
  174. }
  175. public bool DestroyActor(string vId)
  176. {
  177. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  178. if (((SceneObjectGroup)tempobj) != null)
  179. {
  180. ((SceneObjectGroup)tempobj).DeleteMe = true; // Do not call DeleteSceneObjectGroup for deleting directly
  181. return true;
  182. }
  183. else
  184. return false;
  185. }
  186. public bool SetMesh(string vId,string vsName)
  187. {
  188. try
  189. {
  190. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  191. if (tempobj != null)
  192. {
  193. if (vsName.Length > 0)
  194. {
  195. LLUUID tempid = myScriptEngine.World.AssetCache.ExistsAsset(43, vsName);
  196. if (tempid != LLUUID.Zero)
  197. {
  198. tempobj.m_RexFlags |= SceneObjectPart.REXFLAGS_ISMESH | SceneObjectPart.REXFLAGS_ISVISIBLE;
  199. tempobj.m_RexMeshUUID = tempid;
  200. tempobj.UpdateRexParameters();
  201. return true;
  202. }
  203. }
  204. else
  205. {
  206. tempobj.m_RexFlags &= SceneObjectPart.REXFLAGS_ISMESH & SceneObjectPart.REXFLAGS_ISVISIBLE;
  207. tempobj.UpdateRexParameters();
  208. return true;
  209. }
  210. }
  211. }
  212. catch (Exception e)
  213. {
  214. myScriptEngine.Log.Verbose("RexScriptEngine", "SetMeshByLLUUID exception:" + e.ToString());
  215. }
  216. return false;
  217. }
  218. public bool SetMeshByLLUUID(string vId, string vsLLUUID)
  219. {
  220. try
  221. {
  222. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  223. if (tempobj != null)
  224. {
  225. if (vsLLUUID.Length > 0)
  226. {
  227. tempobj.m_RexFlags |= SceneObjectPart.REXFLAGS_ISMESH | SceneObjectPart.REXFLAGS_ISVISIBLE;
  228. tempobj.m_RexMeshUUID = new LLUUID(vsLLUUID);
  229. tempobj.UpdateRexParameters();
  230. return true;
  231. }
  232. else
  233. {
  234. tempobj.m_RexFlags &= SceneObjectPart.REXFLAGS_ISMESH & SceneObjectPart.REXFLAGS_ISVISIBLE;
  235. tempobj.UpdateRexParameters();
  236. return true;
  237. }
  238. }
  239. }
  240. catch (Exception e)
  241. {
  242. myScriptEngine.Log.Verbose("RexScriptEngine", "SetMeshByLLUUID exception:" + e.ToString());
  243. }
  244. return false;
  245. }
  246. public bool SetMaterial(string vId,int vIndex,string vsName)
  247. {
  248. try
  249. {
  250. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  251. if (tempobj != null)
  252. {
  253. if (vsName.Length > 0)
  254. {
  255. LLUUID tempid = myScriptEngine.World.AssetCache.ExistsAsset(0, vsName);
  256. if (tempid != LLUUID.Zero)
  257. {
  258. if (vIndex < tempobj.m_RexMaterialUUID.Count)
  259. {
  260. tempobj.m_RexMaterialUUID[vIndex] = tempid;
  261. }
  262. else
  263. {
  264. for (int i = tempobj.m_RexMaterialUUID.Count; i < (vIndex + 1); i++)
  265. tempobj.m_RexMaterialUUID.Add(LLUUID.Zero);
  266. tempobj.m_RexMaterialUUID[vIndex] = tempid;
  267. }
  268. tempobj.UpdateRexParameters();
  269. return true;
  270. }
  271. }
  272. else
  273. {
  274. tempobj.UpdateRexParameters();
  275. return true;
  276. }
  277. }
  278. }
  279. catch (Exception e)
  280. {
  281. myScriptEngine.Log.Verbose("RexScriptEngine", "SetMaterial exception:" + e.ToString());
  282. }
  283. return false;
  284. }
  285. private static PrimitiveBaseShape GetShape(int vShape)
  286. {
  287. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  288. shape.PCode = 9;
  289. shape.PathBegin = 0;
  290. shape.PathEnd = 0;
  291. shape.PathScaleX = 100;
  292. shape.PathScaleY = 100;
  293. shape.PathShearX = 0;
  294. shape.PathShearY = 0;
  295. shape.PathSkew = 0;
  296. shape.ProfileBegin = 0;
  297. shape.ProfileEnd = 0;
  298. shape.Scale.X = shape.Scale.Y = shape.Scale.Z = 0.5f;
  299. shape.PathCurve = 16;
  300. shape.ProfileCurve = 1;
  301. shape.ProfileHollow = 0;
  302. shape.PathRadiusOffset = 0;
  303. shape.PathRevolutions = 0;
  304. shape.PathTaperX = 0;
  305. shape.PathTaperY = 0;
  306. shape.PathTwist = 0;
  307. shape.PathTwistBegin = 0;
  308. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-1111-9999-000000000005"));
  309. shape.TextureEntry = ntex.ToBytes();
  310. return shape;
  311. }
  312. // Scenepresence related
  313. public string SPGetFullName(string vPresenceId)
  314. {
  315. LLUUID TempId = new LLUUID(vPresenceId);
  316. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  317. if (temppre != null)
  318. {
  319. string TempString = temppre.Firstname + " " + temppre.Lastname;
  320. return TempString;
  321. }
  322. else
  323. return "";
  324. }
  325. public string SPGetFirstName(string vPresenceId)
  326. {
  327. LLUUID TempId = new LLUUID(vPresenceId);
  328. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  329. if (temppre != null)
  330. return temppre.Firstname;
  331. else
  332. return "";
  333. }
  334. public string SPGetLastName(string vPresenceId)
  335. {
  336. LLUUID TempId = new LLUUID(vPresenceId);
  337. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  338. if (temppre != null)
  339. return temppre.Lastname;
  340. else
  341. return "";
  342. }
  343. public void SPDoLocalTeleport(string vPresenceId, LSL_Types.Vector3 vLocation)
  344. {
  345. LLUUID TempId = new LLUUID(vPresenceId);
  346. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  347. if (temppre != null)
  348. {
  349. LLVector3 position = new LLVector3((float)vLocation.x, (float)vLocation.y, (float)vLocation.z);
  350. LLVector3 lookAt = new LLVector3(0,0,0);
  351. temppre.ControllingClient.SendTeleportLocationStart();
  352. temppre.ControllingClient.SendLocalTeleport(position, lookAt,0);
  353. temppre.Teleport(position);
  354. }
  355. }
  356. public float SPGetMovementModifier(string vPresenceId)
  357. {
  358. LLUUID TempId = new LLUUID(vPresenceId);
  359. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  360. if (temppre != null)
  361. return temppre.MovementSpeedMod;
  362. else
  363. return 0.0f;
  364. }
  365. public void SPSetMovementModifier(string vPresenceId,float vSpeedModifier)
  366. {
  367. LLUUID TempId = new LLUUID(vPresenceId);
  368. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  369. if (temppre != null)
  370. temppre.MovementSpeedMod = vSpeedModifier;
  371. }
  372. public LSL_Types.Vector3 SPGetPos(string vPresenceId)
  373. {
  374. LSL_Types.Vector3 loc = new LSL_Types.Vector3(0, 0, 0);
  375. LLUUID TempId = new LLUUID(vPresenceId);
  376. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  377. if (temppre != null)
  378. {
  379. loc.x = temppre.AbsolutePosition.X;
  380. loc.y = temppre.AbsolutePosition.Y;
  381. loc.z = temppre.AbsolutePosition.Z;
  382. }
  383. return loc;
  384. }
  385. public LSL_Types.Quaternion SPGetRot(string vPresenceId)
  386. {
  387. LSL_Types.Quaternion rot = new LSL_Types.Quaternion(0, 0, 0, 1);
  388. LLUUID TempId = new LLUUID(vPresenceId);
  389. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  390. if (temppre != null)
  391. {
  392. rot.x = temppre.Rotation.x;
  393. rot.y = temppre.Rotation.y;
  394. rot.z = temppre.Rotation.y;
  395. rot.s = temppre.Rotation.w;
  396. }
  397. return rot;
  398. }
  399. public void SPSetRot(string vPresenceId,LSL_Types.Quaternion vRot, bool vbRelative)
  400. {
  401. LLUUID TempId = new LLUUID(vPresenceId);
  402. ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
  403. if (temppre != null)
  404. {
  405. string sparams = vRot.x.ToString() + " " + vRot.y.ToString() + " " + vRot.z.ToString() + " " + vRot.s.ToString();
  406. sparams = sparams.Replace(",", ".");
  407. if (vbRelative)
  408. temppre.ControllingClient.SendRexScriptCommand("client", "setrelrot", sparams);
  409. else
  410. temppre.ControllingClient.SendRexScriptCommand("client", "setrot", sparams);
  411. }
  412. }
  413. // Functions not supported at the moment.
  414. /*
  415. public bool GetFreezed(string vId)
  416. {
  417. tucofixme
  418. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  419. if (tempobj != null)
  420. {
  421. return tempobj.IsFreezed;
  422. }
  423. else
  424. {
  425. return false;
  426. }
  427. return false;
  428. }
  429. public void SetFreezed(string vId, bool vbFreeze)
  430. {
  431. tucofixme
  432. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  433. if (tempobj != null)
  434. {
  435. tempobj.IsFreezed = vbFreeze;
  436. if (tempobj is ScenePresence && vbFreeze)
  437. ((ScenePresence)tempobj).rxStopAvatarMovement();
  438. }
  439. } */
  440. /*
  441. public int GetPhysicsMode(string vId)
  442. {
  443. // tucofixme
  444. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  445. if (tempobj != null)
  446. return tempobj.GetPhysicsMode();
  447. else
  448. return 0;
  449. return 0;
  450. }
  451. public void SetPhysicsMode(string vId, int vPhysicsMode)
  452. {
  453. // tucofixme
  454. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  455. if (tempobj != null)
  456. {
  457. tempobj.SetPhysicsMode(vPhysicsMode);
  458. }
  459. else
  460. myScriptEngine.Log.Verbose("PythonScript", "SetPhysicsMode for nonexisting object:" + vId);
  461. }
  462. */
  463. /*
  464. public bool GetUseGravity(string vId)
  465. {
  466. // tucofixme
  467. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  468. if (tempobj != null)
  469. return tempobj.GetUseGravity();
  470. else
  471. return false;
  472. return false;
  473. }
  474. public void SetUseGravity(string vId, bool vbUseGravity)
  475. {
  476. // tucofixme
  477. SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10));
  478. if (tempobj != null)
  479. tempobj.SetUseGravity(vbUseGravity);
  480. else
  481. myScriptEngine.Log.Verbose("PythonScript", "SetUseGravity for nonexisting object:" + vId);
  482. }
  483. */
  484. /*
  485. public void SetLocationFast(string vId,rxVector vLoc)
  486. {
  487. EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10));
  488. if (((SceneObjectGroup)tempobj) != null)
  489. {
  490. bool hasPrim = ((SceneObjectGroup)tempobj).HasChildPrim(tempobj.UUID);
  491. if (hasPrim != false)
  492. {
  493. LLVector3 TempLoc = new LLVector3((float)vLoc.x, (float)vLoc.y, (float)vLoc.z);
  494. LLVector3 TempOffset = new LLVector3(0, 0, 0);
  495. ((SceneObjectGroup)tempobj).GrabMovement(TempOffset, TempLoc, null); // tucofixme, might break some day, because sending null remoteClient parameter
  496. }
  497. }
  498. }
  499. */
  500. }
  501. }