OSSL_Api.cs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  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.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Net;
  33. using System.Threading;
  34. using OpenMetaverse;
  35. using Nini.Config;
  36. using OpenSim;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Region.CoreModules.Avatar.NPC;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.ScriptEngine.Shared;
  43. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  44. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  45. using OpenSim.Region.ScriptEngine.Interfaces;
  46. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  47. using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
  48. using OpenSim.Services.Interfaces;
  49. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  50. using System.Text.RegularExpressions;
  51. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  52. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  53. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  54. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  55. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  56. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  57. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  58. namespace OpenSim.Region.ScriptEngine.Shared.Api
  59. {
  60. //////////////////////////////////////////////////////////////
  61. //
  62. // Level description
  63. //
  64. // None - Function is no threat at all. It doesn't constitute
  65. // an threat to either users or the system and has no
  66. // known side effects
  67. //
  68. // Nuisance - Abuse of this command can cause a nuisance to the
  69. // region operator, such as log message spew
  70. //
  71. // VeryLow - Extreme levels ob abuse of this function can cause
  72. // impaired functioning of the region, or very gullible
  73. // users can be tricked into experiencing harmless effects
  74. //
  75. // Low - Intentional abuse can cause crashes or malfunction
  76. // under certain circumstances, which can easily be rectified,
  77. // or certain users can be tricked into certain situations
  78. // in an avoidable manner.
  79. //
  80. // Moderate - Intentional abuse can cause denial of service and crashes
  81. // with potential of data or state loss, or trusting users
  82. // can be tricked into embarrassing or uncomfortable
  83. // situationsa.
  84. //
  85. // High - Casual abuse can cause impaired functionality or temporary
  86. // denial of service conditions. Intentional abuse can easily
  87. // cause crashes with potential data loss, or can be used to
  88. // trick experienced and cautious users into unwanted situations,
  89. // or changes global data permanently and without undo ability
  90. // Malicious scripting can allow theft of content
  91. //
  92. // VeryHigh - Even normal use may, depending on the number of instances,
  93. // or frequency of use, result in severe service impairment
  94. // or crash with loss of data, or can be used to cause
  95. // unwanted or harmful effects on users without giving the
  96. // user a means to avoid it.
  97. //
  98. // Severe - Even casual use is a danger to region stability, or function
  99. // allows console or OS command execution, or function allows
  100. // taking money without consent, or allows deletion or
  101. // modification of user data, or allows the compromise of
  102. // sensitive data by design.
  103. class FunctionPerms
  104. {
  105. public List<UUID> AllowedCreators;
  106. public List<UUID> AllowedOwners;
  107. public FunctionPerms()
  108. {
  109. AllowedCreators = new List<UUID>();
  110. AllowedOwners = new List<UUID>();
  111. }
  112. }
  113. [Serializable]
  114. public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
  115. {
  116. internal IScriptEngine m_ScriptEngine;
  117. internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
  118. internal SceneObjectPart m_host;
  119. internal uint m_localID;
  120. internal UUID m_itemID;
  121. internal bool m_OSFunctionsEnabled = false;
  122. internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
  123. internal float m_ScriptDelayFactor = 1.0f;
  124. internal float m_ScriptDistanceFactor = 1.0f;
  125. internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
  126. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
  127. {
  128. m_ScriptEngine = ScriptEngine;
  129. m_host = host;
  130. m_localID = localID;
  131. m_itemID = itemID;
  132. if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
  133. m_OSFunctionsEnabled = true;
  134. m_ScriptDelayFactor =
  135. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  136. m_ScriptDistanceFactor =
  137. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  138. string risk = m_ScriptEngine.Config.GetString("OSFunctionThreatLevel", "VeryLow");
  139. switch (risk)
  140. {
  141. case "None":
  142. m_MaxThreatLevel = ThreatLevel.None;
  143. break;
  144. case "VeryLow":
  145. m_MaxThreatLevel = ThreatLevel.VeryLow;
  146. break;
  147. case "Low":
  148. m_MaxThreatLevel = ThreatLevel.Low;
  149. break;
  150. case "Moderate":
  151. m_MaxThreatLevel = ThreatLevel.Moderate;
  152. break;
  153. case "High":
  154. m_MaxThreatLevel = ThreatLevel.High;
  155. break;
  156. case "VeryHigh":
  157. m_MaxThreatLevel = ThreatLevel.VeryHigh;
  158. break;
  159. case "Severe":
  160. m_MaxThreatLevel = ThreatLevel.Severe;
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. public override Object InitializeLifetimeService()
  167. {
  168. ILease lease = (ILease)base.InitializeLifetimeService();
  169. if (lease.CurrentState == LeaseState.Initial)
  170. {
  171. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  172. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  173. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  174. }
  175. return lease;
  176. }
  177. public Scene World
  178. {
  179. get { return m_ScriptEngine.World; }
  180. }
  181. internal void OSSLError(string msg)
  182. {
  183. throw new Exception("OSSL Runtime Error: " + msg);
  184. }
  185. private void InitLSL()
  186. {
  187. if (m_LSL_Api != null)
  188. return;
  189. m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_itemID, "LSL");
  190. }
  191. //
  192. //Dumps an error message on the debug console.
  193. //
  194. internal void OSSLShoutError(string message)
  195. {
  196. if (message.Length > 1023)
  197. message = message.Substring(0, 1023);
  198. World.SimChat(Utils.StringToBytes(message),
  199. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  200. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  201. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  202. }
  203. public void CheckThreatLevel(ThreatLevel level, string function)
  204. {
  205. if (!m_OSFunctionsEnabled)
  206. OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws
  207. if (!m_FunctionPerms.ContainsKey(function))
  208. {
  209. FunctionPerms perms = new FunctionPerms();
  210. m_FunctionPerms[function] = perms;
  211. string ownerPerm = m_ScriptEngine.Config.GetString("Allow_" + function, "");
  212. string creatorPerm = m_ScriptEngine.Config.GetString("Creators_" + function, "");
  213. if (ownerPerm == "" && creatorPerm == "")
  214. {
  215. // Default behavior
  216. perms.AllowedOwners = null;
  217. perms.AllowedCreators = null;
  218. }
  219. else
  220. {
  221. bool allowed;
  222. if (bool.TryParse(ownerPerm, out allowed))
  223. {
  224. // Boolean given
  225. if (allowed)
  226. {
  227. // Allow globally
  228. perms.AllowedOwners.Add(UUID.Zero);
  229. }
  230. }
  231. else
  232. {
  233. string[] ids = ownerPerm.Split(new char[] {','});
  234. foreach (string id in ids)
  235. {
  236. string current = id.Trim();
  237. UUID uuid;
  238. if (UUID.TryParse(current, out uuid))
  239. {
  240. if (uuid != UUID.Zero)
  241. perms.AllowedOwners.Add(uuid);
  242. }
  243. }
  244. ids = creatorPerm.Split(new char[] {','});
  245. foreach (string id in ids)
  246. {
  247. string current = id.Trim();
  248. UUID uuid;
  249. if (UUID.TryParse(current, out uuid))
  250. {
  251. if (uuid != UUID.Zero)
  252. perms.AllowedCreators.Add(uuid);
  253. }
  254. }
  255. }
  256. }
  257. }
  258. // If the list is null, then the value was true / undefined
  259. // Threat level governs permissions in this case
  260. //
  261. // If the list is non-null, then it is a list of UUIDs allowed
  262. // to use that particular function. False causes an empty
  263. // list and therefore means "no one"
  264. //
  265. // To allow use by anyone, the list contains UUID.Zero
  266. //
  267. if (m_FunctionPerms[function].AllowedOwners == null)
  268. {
  269. // Allow / disallow by threat level
  270. if (level > m_MaxThreatLevel)
  271. OSSLError(
  272. String.Format(
  273. "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.",
  274. function, m_MaxThreatLevel, level));
  275. }
  276. else
  277. {
  278. if (!m_FunctionPerms[function].AllowedOwners.Contains(UUID.Zero))
  279. {
  280. // Not anyone. Do detailed checks
  281. if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID))
  282. {
  283. // prim owner is in the list of allowed owners
  284. return;
  285. }
  286. TaskInventoryItem ti = m_host.Inventory.GetInventoryItem(m_itemID);
  287. if (ti == null)
  288. {
  289. OSSLError(
  290. String.Format("{0} permission error. Can't find script in prim inventory.",
  291. function));
  292. }
  293. if (!m_FunctionPerms[function].AllowedCreators.Contains(ti.CreatorID))
  294. OSSLError(
  295. String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.",
  296. function));
  297. if (ti.CreatorID != ti.OwnerID)
  298. {
  299. if ((ti.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
  300. OSSLError(
  301. String.Format("{0} permission denied. Script permissions error.",
  302. function));
  303. }
  304. }
  305. }
  306. }
  307. protected void ScriptSleep(int delay)
  308. {
  309. delay = (int)((float)delay * m_ScriptDelayFactor);
  310. if (delay == 0)
  311. return;
  312. System.Threading.Thread.Sleep(delay);
  313. }
  314. //
  315. // OpenSim functions
  316. //
  317. public LSL_Integer osTerrainSetHeight(int x, int y, double val)
  318. {
  319. CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
  320. m_host.AddScriptLPS(1);
  321. if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0)
  322. OSSLError("osTerrainSetHeight: Coordinate out of bounds");
  323. if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0)))
  324. {
  325. World.Heightmap[x, y] = val;
  326. return 1;
  327. }
  328. else
  329. {
  330. return 0;
  331. }
  332. }
  333. public LSL_Float osTerrainGetHeight(int x, int y)
  334. {
  335. CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
  336. m_host.AddScriptLPS(1);
  337. if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0)
  338. OSSLError("osTerrainGetHeight: Coordinate out of bounds");
  339. return World.Heightmap[x, y];
  340. }
  341. public void osTerrainFlush()
  342. {
  343. CheckThreatLevel(ThreatLevel.VeryLow, "osTerrainFlush");
  344. ITerrainModule terrainModule = World.RequestModuleInterface<ITerrainModule>();
  345. if (terrainModule != null) terrainModule.TaintTerrain();
  346. }
  347. public int osRegionRestart(double seconds)
  348. {
  349. // This is High here because region restart is not reliable
  350. // it may result in the region staying down or becoming
  351. // unstable. This should be changed to Low or VeryLow once
  352. // The underlying functionality is fixed, since the security
  353. // as such is sound
  354. //
  355. CheckThreatLevel(ThreatLevel.High, "osRegionRestart");
  356. m_host.AddScriptLPS(1);
  357. if (World.Permissions.CanIssueEstateCommand(m_host.OwnerID, false))
  358. {
  359. World.Restart((float)seconds);
  360. return 1;
  361. }
  362. else
  363. {
  364. return 0;
  365. }
  366. }
  367. public void osRegionNotice(string msg)
  368. {
  369. // This implementation provides absolutely no security
  370. // It's high griefing potential makes this classification
  371. // necessary
  372. //
  373. CheckThreatLevel(ThreatLevel.VeryHigh, "osRegionNotice");
  374. m_host.AddScriptLPS(1);
  375. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  376. if (dm != null)
  377. dm.SendGeneralAlert(msg);
  378. }
  379. public void osSetRot(UUID target, Quaternion rotation)
  380. {
  381. // This function has no security. It can be used to destroy
  382. // arbitrary builds the user would normally have no rights to
  383. //
  384. CheckThreatLevel(ThreatLevel.VeryHigh, "osSetRot");
  385. m_host.AddScriptLPS(1);
  386. if (World.Entities.ContainsKey(target))
  387. {
  388. EntityBase entity;
  389. if (World.Entities.TryGetValue(target, out entity))
  390. {
  391. if (entity is SceneObjectGroup)
  392. ((SceneObjectGroup)entity).Rotation = rotation;
  393. else if (entity is ScenePresence)
  394. ((ScenePresence)entity).Rotation = rotation;
  395. }
  396. }
  397. else
  398. {
  399. OSSLError("osSetRot: Invalid target");
  400. }
  401. }
  402. public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams,
  403. int timer)
  404. {
  405. // This may be upgraded depending on the griefing or DOS
  406. // potential, or guarded with a delay
  407. //
  408. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURL");
  409. m_host.AddScriptLPS(1);
  410. if (dynamicID == String.Empty)
  411. {
  412. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  413. UUID createdTexture =
  414. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  415. extraParams, timer);
  416. return createdTexture.ToString();
  417. }
  418. else
  419. {
  420. //TODO update existing dynamic textures
  421. }
  422. return UUID.Zero.ToString();
  423. }
  424. public string osSetDynamicTextureURLBlend(string dynamicID, string contentType, string url, string extraParams,
  425. int timer, int alpha)
  426. {
  427. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlend");
  428. m_host.AddScriptLPS(1);
  429. if (dynamicID == String.Empty)
  430. {
  431. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  432. UUID createdTexture =
  433. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  434. extraParams, timer, true, (byte) alpha);
  435. return createdTexture.ToString();
  436. }
  437. else
  438. {
  439. //TODO update existing dynamic textures
  440. }
  441. return UUID.Zero.ToString();
  442. }
  443. public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
  444. bool blend, int disp, int timer, int alpha, int face)
  445. {
  446. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureURLBlendFace");
  447. m_host.AddScriptLPS(1);
  448. if (dynamicID == String.Empty)
  449. {
  450. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  451. UUID createdTexture =
  452. textureManager.AddDynamicTextureURL(World.RegionInfo.RegionID, m_host.UUID, contentType, url,
  453. extraParams, timer, blend, disp, (byte) alpha, face);
  454. return createdTexture.ToString();
  455. }
  456. else
  457. {
  458. //TODO update existing dynamic textures
  459. }
  460. return UUID.Zero.ToString();
  461. }
  462. public string osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams,
  463. int timer)
  464. {
  465. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureData");
  466. m_host.AddScriptLPS(1);
  467. if (dynamicID == String.Empty)
  468. {
  469. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  470. if (textureManager != null)
  471. {
  472. if (extraParams == String.Empty)
  473. {
  474. extraParams = "256";
  475. }
  476. UUID createdTexture =
  477. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  478. extraParams, timer);
  479. return createdTexture.ToString();
  480. }
  481. }
  482. else
  483. {
  484. //TODO update existing dynamic textures
  485. }
  486. return UUID.Zero.ToString();
  487. }
  488. public string osSetDynamicTextureDataBlend(string dynamicID, string contentType, string data, string extraParams,
  489. int timer, int alpha)
  490. {
  491. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlend");
  492. m_host.AddScriptLPS(1);
  493. if (dynamicID == String.Empty)
  494. {
  495. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  496. if (textureManager != null)
  497. {
  498. if (extraParams == String.Empty)
  499. {
  500. extraParams = "256";
  501. }
  502. UUID createdTexture =
  503. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  504. extraParams, timer, true, (byte) alpha);
  505. return createdTexture.ToString();
  506. }
  507. }
  508. else
  509. {
  510. //TODO update existing dynamic textures
  511. }
  512. return UUID.Zero.ToString();
  513. }
  514. public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
  515. bool blend, int disp, int timer, int alpha, int face)
  516. {
  517. CheckThreatLevel(ThreatLevel.VeryLow, "osSetDynamicTextureDataBlendFace");
  518. m_host.AddScriptLPS(1);
  519. if (dynamicID == String.Empty)
  520. {
  521. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  522. if (textureManager != null)
  523. {
  524. if (extraParams == String.Empty)
  525. {
  526. extraParams = "256";
  527. }
  528. UUID createdTexture =
  529. textureManager.AddDynamicTextureData(World.RegionInfo.RegionID, m_host.UUID, contentType, data,
  530. extraParams, timer, blend, disp, (byte) alpha, face);
  531. return createdTexture.ToString();
  532. }
  533. }
  534. else
  535. {
  536. //TODO update existing dynamic textures
  537. }
  538. return UUID.Zero.ToString();
  539. }
  540. public bool osConsoleCommand(string command)
  541. {
  542. CheckThreatLevel(ThreatLevel.Severe, "osConsoleCommand");
  543. m_host.AddScriptLPS(1);
  544. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  545. {
  546. MainConsole.Instance.RunCommand(command);
  547. return true;
  548. }
  549. return false;
  550. }
  551. public void osSetPrimFloatOnWater(int floatYN)
  552. {
  553. CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
  554. m_host.AddScriptLPS(1);
  555. if (m_host.ParentGroup != null)
  556. {
  557. if (m_host.ParentGroup.RootPart != null)
  558. {
  559. m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
  560. }
  561. }
  562. }
  563. // Teleport functions
  564. public void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  565. {
  566. // High because there is no security check. High griefer potential
  567. //
  568. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  569. m_host.AddScriptLPS(1);
  570. UUID agentId = new UUID();
  571. if (UUID.TryParse(agent, out agentId))
  572. {
  573. ScenePresence presence = World.GetScenePresence(agentId);
  574. if (presence != null)
  575. {
  576. // agent must be over owners land to avoid abuse
  577. if (m_host.OwnerID
  578. == World.LandChannel.GetLandObject(
  579. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  580. {
  581. // Check for hostname , attempt to make a hglink
  582. // and convert the regionName to the target region
  583. if (regionName.Contains(".") && regionName.Contains(":"))
  584. {
  585. List<GridRegion> regions = World.GridService.GetRegionsByName(World.RegionInfo.ScopeID, regionName, 1);
  586. // Try to link the region
  587. if (regions != null && regions.Count > 0)
  588. {
  589. GridRegion regInfo = regions[0];
  590. regionName = regInfo.RegionName;
  591. }
  592. }
  593. World.RequestTeleportLocation(presence.ControllingClient, regionName,
  594. new Vector3((float)position.x, (float)position.y, (float)position.z),
  595. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  596. ScriptSleep(5000);
  597. }
  598. }
  599. }
  600. }
  601. // Teleport functions
  602. public void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  603. {
  604. // High because there is no security check. High griefer potential
  605. //
  606. CheckThreatLevel(ThreatLevel.High, "osTeleportAgent");
  607. ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize));
  608. m_host.AddScriptLPS(1);
  609. UUID agentId = new UUID();
  610. if (UUID.TryParse(agent, out agentId))
  611. {
  612. ScenePresence presence = World.GetScenePresence(agentId);
  613. if (presence != null)
  614. {
  615. // agent must be over owners land to avoid abuse
  616. if (m_host.OwnerID
  617. == World.LandChannel.GetLandObject(
  618. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  619. {
  620. World.RequestTeleportLocation(presence.ControllingClient, regionHandle,
  621. new Vector3((float)position.x, (float)position.y, (float)position.z),
  622. new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation);
  623. ScriptSleep(5000);
  624. }
  625. }
  626. }
  627. }
  628. public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat)
  629. {
  630. osTeleportAgent(agent, World.RegionInfo.RegionName, position, lookat);
  631. }
  632. // Functions that get information from the agent itself.
  633. //
  634. // osGetAgentIP - this is used to determine the IP address of
  635. //the client. This is needed to help configure other in world
  636. //resources based on the IP address of the clients connected.
  637. //I think High is a good risk level for this, as it is an
  638. //information leak.
  639. public string osGetAgentIP(string agent)
  640. {
  641. CheckThreatLevel(ThreatLevel.High, "osGetAgentIP");
  642. UUID avatarID = (UUID)agent;
  643. m_host.AddScriptLPS(1);
  644. if (World.Entities.ContainsKey((UUID)agent) && World.Entities[avatarID] is ScenePresence)
  645. {
  646. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  647. EndPoint ep = target.ControllingClient.GetClientEP();
  648. if (ep is IPEndPoint)
  649. {
  650. IPEndPoint ip = (IPEndPoint)ep;
  651. return ip.Address.ToString();
  652. }
  653. }
  654. // fall through case, just return nothing
  655. return "";
  656. }
  657. // Get a list of all the avatars/agents in the region
  658. public LSL_List osGetAgents()
  659. {
  660. // threat level is None as we could get this information with an
  661. // in-world script as well, just not as efficient
  662. CheckThreatLevel(ThreatLevel.None, "osGetAgents");
  663. LSL_List result = new LSL_List();
  664. World.ForEachScenePresence(delegate(ScenePresence sp)
  665. {
  666. if (!sp.IsChildAgent)
  667. result.Add(sp.Name);
  668. });
  669. return result;
  670. }
  671. // Adam's super super custom animation functions
  672. public void osAvatarPlayAnimation(string avatar, string animation)
  673. {
  674. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation");
  675. UUID avatarID = (UUID)avatar;
  676. m_host.AddScriptLPS(1);
  677. if (World.Entities.ContainsKey((UUID)avatar) && World.Entities[avatarID] is ScenePresence)
  678. {
  679. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  680. if (target != null)
  681. {
  682. UUID animID=UUID.Zero;
  683. lock (m_host.TaskInventory)
  684. {
  685. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  686. {
  687. if (inv.Value.Name == animation)
  688. {
  689. if (inv.Value.Type == (int)AssetType.Animation)
  690. animID = inv.Value.AssetID;
  691. continue;
  692. }
  693. }
  694. }
  695. if (animID == UUID.Zero)
  696. target.Animator.AddAnimation(animation, m_host.UUID);
  697. else
  698. target.Animator.AddAnimation(animID, m_host.UUID);
  699. }
  700. }
  701. }
  702. public void osAvatarStopAnimation(string avatar, string animation)
  703. {
  704. CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation");
  705. UUID avatarID = (UUID)avatar;
  706. m_host.AddScriptLPS(1);
  707. if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
  708. {
  709. ScenePresence target = (ScenePresence)World.Entities[avatarID];
  710. if (target != null)
  711. {
  712. UUID animID=UUID.Zero;
  713. lock (m_host.TaskInventory)
  714. {
  715. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  716. {
  717. if (inv.Value.Name == animation)
  718. {
  719. if (inv.Value.Type == (int)AssetType.Animation)
  720. animID = inv.Value.AssetID;
  721. continue;
  722. }
  723. }
  724. }
  725. if (animID == UUID.Zero)
  726. target.Animator.RemoveAnimation(animation);
  727. else
  728. target.Animator.RemoveAnimation(animID);
  729. }
  730. }
  731. }
  732. //Texture draw functions
  733. public string osMovePen(string drawList, int x, int y)
  734. {
  735. CheckThreatLevel(ThreatLevel.None, "osMovePen");
  736. m_host.AddScriptLPS(1);
  737. drawList += "MoveTo " + x + "," + y + ";";
  738. return drawList;
  739. }
  740. public string osDrawLine(string drawList, int startX, int startY, int endX, int endY)
  741. {
  742. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  743. m_host.AddScriptLPS(1);
  744. drawList += "MoveTo "+ startX+","+ startY +"; LineTo "+endX +","+endY +"; ";
  745. return drawList;
  746. }
  747. public string osDrawLine(string drawList, int endX, int endY)
  748. {
  749. CheckThreatLevel(ThreatLevel.None, "osDrawLine");
  750. m_host.AddScriptLPS(1);
  751. drawList += "LineTo " + endX + "," + endY + "; ";
  752. return drawList;
  753. }
  754. public string osDrawText(string drawList, string text)
  755. {
  756. CheckThreatLevel(ThreatLevel.None, "osDrawText");
  757. m_host.AddScriptLPS(1);
  758. drawList += "Text " + text + "; ";
  759. return drawList;
  760. }
  761. public string osDrawEllipse(string drawList, int width, int height)
  762. {
  763. CheckThreatLevel(ThreatLevel.None, "osDrawEllipse");
  764. m_host.AddScriptLPS(1);
  765. drawList += "Ellipse " + width + "," + height + "; ";
  766. return drawList;
  767. }
  768. public string osDrawRectangle(string drawList, int width, int height)
  769. {
  770. CheckThreatLevel(ThreatLevel.None, "osDrawRectangle");
  771. m_host.AddScriptLPS(1);
  772. drawList += "Rectangle " + width + "," + height + "; ";
  773. return drawList;
  774. }
  775. public string osDrawFilledRectangle(string drawList, int width, int height)
  776. {
  777. CheckThreatLevel(ThreatLevel.None, "osDrawFilledRectangle");
  778. m_host.AddScriptLPS(1);
  779. drawList += "FillRectangle " + width + "," + height + "; ";
  780. return drawList;
  781. }
  782. public string osDrawFilledPolygon(string drawList, LSL_List x, LSL_List y)
  783. {
  784. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  785. m_host.AddScriptLPS(1);
  786. if (x.Length != y.Length || x.Length < 3)
  787. {
  788. return "";
  789. }
  790. drawList += "FillPolygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  791. for (int i = 1; i < x.Length; i++)
  792. {
  793. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  794. }
  795. drawList += "; ";
  796. return drawList;
  797. }
  798. public string osDrawPolygon(string drawList, LSL_List x, LSL_List y)
  799. {
  800. CheckThreatLevel(ThreatLevel.None, "osDrawFilledPolygon");
  801. m_host.AddScriptLPS(1);
  802. if (x.Length != y.Length || x.Length < 3)
  803. {
  804. return "";
  805. }
  806. drawList += "Polygon " + x.GetLSLStringItem(0) + "," + y.GetLSLStringItem(0);
  807. for (int i = 1; i < x.Length; i++)
  808. {
  809. drawList += "," + x.GetLSLStringItem(i) + "," + y.GetLSLStringItem(i);
  810. }
  811. drawList += "; ";
  812. return drawList;
  813. }
  814. public string osSetFontSize(string drawList, int fontSize)
  815. {
  816. CheckThreatLevel(ThreatLevel.None, "osSetFontSize");
  817. m_host.AddScriptLPS(1);
  818. drawList += "FontSize "+ fontSize +"; ";
  819. return drawList;
  820. }
  821. public string osSetFontName(string drawList, string fontName)
  822. {
  823. CheckThreatLevel(ThreatLevel.None, "osSetFontName");
  824. m_host.AddScriptLPS(1);
  825. drawList += "FontName "+ fontName +"; ";
  826. return drawList;
  827. }
  828. public string osSetPenSize(string drawList, int penSize)
  829. {
  830. CheckThreatLevel(ThreatLevel.None, "osSetPenSize");
  831. m_host.AddScriptLPS(1);
  832. drawList += "PenSize " + penSize + "; ";
  833. return drawList;
  834. }
  835. public string osSetPenColour(string drawList, string colour)
  836. {
  837. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  838. m_host.AddScriptLPS(1);
  839. drawList += "PenColour " + colour + "; ";
  840. return drawList;
  841. }
  842. public string osSetPenCap(string drawList, string direction, string type)
  843. {
  844. CheckThreatLevel(ThreatLevel.None, "osSetPenColour");
  845. m_host.AddScriptLPS(1);
  846. drawList += "PenCap " + direction + "," + type + "; ";
  847. return drawList;
  848. }
  849. public string osDrawImage(string drawList, int width, int height, string imageUrl)
  850. {
  851. CheckThreatLevel(ThreatLevel.None, "osDrawImage");
  852. m_host.AddScriptLPS(1);
  853. drawList +="Image " +width + "," + height+ ","+ imageUrl +"; " ;
  854. return drawList;
  855. }
  856. public LSL_Vector osGetDrawStringSize(string contentType, string text, string fontName, int fontSize)
  857. {
  858. CheckThreatLevel(ThreatLevel.VeryLow, "osGetDrawStringSize");
  859. m_host.AddScriptLPS(1);
  860. LSL_Vector vec = new LSL_Vector(0,0,0);
  861. IDynamicTextureManager textureManager = World.RequestModuleInterface<IDynamicTextureManager>();
  862. if (textureManager != null)
  863. {
  864. double xSize, ySize;
  865. textureManager.GetDrawStringSize(contentType, text, fontName, fontSize,
  866. out xSize, out ySize);
  867. vec.x = xSize;
  868. vec.y = ySize;
  869. }
  870. return vec;
  871. }
  872. public void osSetStateEvents(int events)
  873. {
  874. // This function is a hack. There is no reason for it's existence
  875. // anymore, since state events now work properly.
  876. // It was probably added as a crutch or debugging aid, and
  877. // should be removed
  878. //
  879. CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
  880. m_host.SetScriptEvents(m_itemID, events);
  881. }
  882. public void osSetRegionWaterHeight(double height)
  883. {
  884. CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
  885. m_host.AddScriptLPS(1);
  886. //Check to make sure that the script's owner is the estate manager/master
  887. //World.Permissions.GenericEstatePermission(
  888. if (World.Permissions.IsGod(m_host.OwnerID))
  889. {
  890. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  891. }
  892. }
  893. /// <summary>
  894. /// Changes the Region Sun Settings, then Triggers a Sun Update
  895. /// </summary>
  896. /// <param name="useEstateSun">True to use Estate Sun instead of Region Sun</param>
  897. /// <param name="sunFixed">True to keep the sun stationary</param>
  898. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  899. public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
  900. {
  901. CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings");
  902. m_host.AddScriptLPS(1);
  903. //Check to make sure that the script's owner is the estate manager/master
  904. //World.Permissions.GenericEstatePermission(
  905. if (World.Permissions.IsGod(m_host.OwnerID))
  906. {
  907. while (sunHour > 24.0)
  908. sunHour -= 24.0;
  909. while (sunHour < 0)
  910. sunHour += 24.0;
  911. World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
  912. World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
  913. World.RegionInfo.RegionSettings.FixedSun = sunFixed;
  914. World.RegionInfo.RegionSettings.Save();
  915. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour);
  916. }
  917. }
  918. /// <summary>
  919. /// Changes the Estate Sun Settings, then Triggers a Sun Update
  920. /// </summary>
  921. /// <param name="sunFixed">True to keep the sun stationary, false to use global time</param>
  922. /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
  923. public void osSetEstateSunSettings(bool sunFixed, double sunHour)
  924. {
  925. CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings");
  926. m_host.AddScriptLPS(1);
  927. //Check to make sure that the script's owner is the estate manager/master
  928. //World.Permissions.GenericEstatePermission(
  929. if (World.Permissions.IsGod(m_host.OwnerID))
  930. {
  931. while (sunHour > 24.0)
  932. sunHour -= 24.0;
  933. while (sunHour < 0)
  934. sunHour += 24.0;
  935. World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
  936. World.RegionInfo.EstateSettings.SunPosition = sunHour;
  937. World.RegionInfo.EstateSettings.FixedSun = sunFixed;
  938. World.RegionInfo.EstateSettings.Save();
  939. World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour);
  940. }
  941. }
  942. /// <summary>
  943. /// Return the current Sun Hour 0...24, with 0 being roughly sun-rise
  944. /// </summary>
  945. /// <returns></returns>
  946. public double osGetCurrentSunHour()
  947. {
  948. CheckThreatLevel(ThreatLevel.None, "osGetCurrentSunHour");
  949. m_host.AddScriptLPS(1);
  950. // Must adjust for the fact that Region Sun Settings are still LL offset
  951. double sunHour = World.RegionInfo.RegionSettings.SunPosition - 6;
  952. // See if the sun module has registered itself, if so it's authoritative
  953. ISunModule module = World.RequestModuleInterface<ISunModule>();
  954. if (module != null)
  955. {
  956. sunHour = module.GetCurrentSunHour();
  957. }
  958. return sunHour;
  959. }
  960. public double osSunGetParam(string param)
  961. {
  962. CheckThreatLevel(ThreatLevel.None, "osSunGetParam");
  963. m_host.AddScriptLPS(1);
  964. double value = 0.0;
  965. ISunModule module = World.RequestModuleInterface<ISunModule>();
  966. if (module != null)
  967. {
  968. value = module.GetSunParameter(param);
  969. }
  970. return value;
  971. }
  972. public void osSunSetParam(string param, double value)
  973. {
  974. CheckThreatLevel(ThreatLevel.None, "osSunSetParam");
  975. m_host.AddScriptLPS(1);
  976. ISunModule module = World.RequestModuleInterface<ISunModule>();
  977. if (module != null)
  978. {
  979. module.SetSunParameter(param, value);
  980. }
  981. }
  982. public string osWindActiveModelPluginName()
  983. {
  984. CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
  985. m_host.AddScriptLPS(1);
  986. IWindModule module = World.RequestModuleInterface<IWindModule>();
  987. if (module != null)
  988. {
  989. return module.WindActiveModelPluginName;
  990. }
  991. return String.Empty;
  992. }
  993. public void osWindParamSet(string plugin, string param, float value)
  994. {
  995. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamSet");
  996. m_host.AddScriptLPS(1);
  997. IWindModule module = World.RequestModuleInterface<IWindModule>();
  998. if (module != null)
  999. {
  1000. try
  1001. {
  1002. module.WindParamSet(plugin, param, value);
  1003. }
  1004. catch (Exception) { }
  1005. }
  1006. }
  1007. public float osWindParamGet(string plugin, string param)
  1008. {
  1009. CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamGet");
  1010. m_host.AddScriptLPS(1);
  1011. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1012. if (module != null)
  1013. {
  1014. return module.WindParamGet(plugin, param);
  1015. }
  1016. return 0.0f;
  1017. }
  1018. // Routines for creating and managing parcels programmatically
  1019. public void osParcelJoin(LSL_Vector pos1, LSL_Vector pos2)
  1020. {
  1021. CheckThreatLevel(ThreatLevel.High, "osParcelJoin");
  1022. m_host.AddScriptLPS(1);
  1023. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1024. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1025. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1026. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1027. World.LandChannel.Join(startx,starty,endx,endy,m_host.OwnerID);
  1028. }
  1029. public void osParcelSubdivide(LSL_Vector pos1, LSL_Vector pos2)
  1030. {
  1031. CheckThreatLevel(ThreatLevel.High, "osParcelSubdivide");
  1032. m_host.AddScriptLPS(1);
  1033. int startx = (int)(pos1.x < pos2.x ? pos1.x : pos2.x);
  1034. int starty = (int)(pos1.y < pos2.y ? pos1.y : pos2.y);
  1035. int endx = (int)(pos1.x > pos2.x ? pos1.x : pos2.x);
  1036. int endy = (int)(pos1.y > pos2.y ? pos1.y : pos2.y);
  1037. World.LandChannel.Subdivide(startx,starty,endx,endy,m_host.OwnerID);
  1038. }
  1039. public void osParcelSetDetails(LSL_Vector pos, LSL_List rules)
  1040. {
  1041. CheckThreatLevel(ThreatLevel.High, "osParcelSetDetails");
  1042. m_host.AddScriptLPS(1);
  1043. // Get a reference to the land data and make sure the owner of the script
  1044. // can modify it
  1045. ILandObject startLandObject = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y);
  1046. if (startLandObject == null)
  1047. {
  1048. OSSLShoutError("There is no land at that location");
  1049. return;
  1050. }
  1051. if (! World.Permissions.CanEditParcel(m_host.OwnerID, startLandObject))
  1052. {
  1053. OSSLShoutError("You do not have permission to modify the parcel");
  1054. return;
  1055. }
  1056. // Create a new land data object we can modify
  1057. LandData newLand = startLandObject.LandData.Copy();
  1058. UUID uuid;
  1059. // Process the rules, not sure what the impact would be of changing owner or group
  1060. for (int idx = 0; idx < rules.Length; )
  1061. {
  1062. int code = rules.GetLSLIntegerItem(idx++);
  1063. string arg = rules.GetLSLStringItem(idx++);
  1064. switch (code)
  1065. {
  1066. case 0:
  1067. newLand.Name = arg;
  1068. break;
  1069. case 1:
  1070. newLand.Description = arg;
  1071. break;
  1072. case 2:
  1073. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1074. if (UUID.TryParse(arg , out uuid))
  1075. newLand.OwnerID = uuid;
  1076. break;
  1077. case 3:
  1078. CheckThreatLevel(ThreatLevel.VeryHigh, "osParcelSetDetails");
  1079. if (UUID.TryParse(arg , out uuid))
  1080. newLand.GroupID = uuid;
  1081. break;
  1082. }
  1083. }
  1084. World.LandChannel.UpdateLandObject(newLand.LocalID,newLand);
  1085. }
  1086. public double osList2Double(LSL_Types.list src, int index)
  1087. {
  1088. // There is really no double type in OSSL. C# and other
  1089. // have one, but the current implementation of LSL_Types.list
  1090. // is not allowed to contain any.
  1091. // This really should be removed.
  1092. //
  1093. CheckThreatLevel(ThreatLevel.None, "osList2Double");
  1094. m_host.AddScriptLPS(1);
  1095. if (index < 0)
  1096. {
  1097. index = src.Length + index;
  1098. }
  1099. if (index >= src.Length)
  1100. {
  1101. return 0.0;
  1102. }
  1103. return Convert.ToDouble(src.Data[index]);
  1104. }
  1105. public void osSetParcelMediaURL(string url)
  1106. {
  1107. // What actually is the difference to the LL function?
  1108. //
  1109. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1110. m_host.AddScriptLPS(1);
  1111. ILandObject land
  1112. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1113. if (land.LandData.OwnerID != m_host.OwnerID)
  1114. return;
  1115. land.SetMediaUrl(url);
  1116. }
  1117. public void osSetParcelSIPAddress(string SIPAddress)
  1118. {
  1119. // What actually is the difference to the LL function?
  1120. //
  1121. CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
  1122. m_host.AddScriptLPS(1);
  1123. ILandObject land
  1124. = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  1125. if (land.LandData.OwnerID != m_host.OwnerID)
  1126. {
  1127. OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
  1128. return;
  1129. }
  1130. // get the voice module
  1131. IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
  1132. if (voiceModule != null)
  1133. voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
  1134. else
  1135. OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
  1136. }
  1137. public string osGetScriptEngineName()
  1138. {
  1139. // This gets a "high" because knowing the engine may be used
  1140. // to exploit engine-specific bugs or induce usage patterns
  1141. // that trigger engine-specific failures.
  1142. // Besides, public grid users aren't supposed to know.
  1143. //
  1144. CheckThreatLevel(ThreatLevel.High, "osGetScriptEngineName");
  1145. m_host.AddScriptLPS(1);
  1146. int scriptEngineNameIndex = 0;
  1147. if (!String.IsNullOrEmpty(m_ScriptEngine.ScriptEngineName))
  1148. {
  1149. // parse off the "ScriptEngine."
  1150. scriptEngineNameIndex = m_ScriptEngine.ScriptEngineName.IndexOf(".", scriptEngineNameIndex);
  1151. scriptEngineNameIndex++; // get past delimiter
  1152. int scriptEngineNameLength = m_ScriptEngine.ScriptEngineName.Length - scriptEngineNameIndex;
  1153. // create char array then a string that is only the script engine name
  1154. Char[] scriptEngineNameCharArray = m_ScriptEngine.ScriptEngineName.ToCharArray(scriptEngineNameIndex, scriptEngineNameLength);
  1155. String scriptEngineName = new String(scriptEngineNameCharArray);
  1156. return scriptEngineName;
  1157. }
  1158. else
  1159. {
  1160. return String.Empty;
  1161. }
  1162. }
  1163. public string osGetSimulatorVersion()
  1164. {
  1165. // High because it can be used to target attacks to known weaknesses
  1166. // This would allow a new class of griefer scripts that don't even
  1167. // require their user to know what they are doing (see script
  1168. // kiddie)
  1169. //
  1170. CheckThreatLevel(ThreatLevel.High,"osGetSimulatorVersion");
  1171. m_host.AddScriptLPS(1);
  1172. return m_ScriptEngine.World.GetSimulatorVersion();
  1173. }
  1174. public Hashtable osParseJSON(string JSON)
  1175. {
  1176. CheckThreatLevel(ThreatLevel.None, "osParseJSON");
  1177. m_host.AddScriptLPS(1);
  1178. // see http://www.json.org/ for more details on JSON
  1179. string currentKey = null;
  1180. Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
  1181. Hashtable jsondata = new Hashtable(); // the hashtable to be returned
  1182. int i = 0;
  1183. try
  1184. {
  1185. // iterate through the serialised stream of tokens and store at the right depth in the hashtable
  1186. // the top level hashtable may contain more nested hashtables within it each containing an objects representation
  1187. for (i = 0; i < JSON.Length; i++)
  1188. {
  1189. // m_log.Debug(""+JSON[i]);
  1190. switch (JSON[i])
  1191. {
  1192. case '{':
  1193. // create hashtable and add it to the stack or array if we are populating one, we can have a lot of nested objects in JSON
  1194. Hashtable currentObject = new Hashtable();
  1195. if (objectStack.Count == 0) // the stack should only be empty for the first outer object
  1196. {
  1197. objectStack.Push(jsondata);
  1198. }
  1199. else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1200. {
  1201. // add it to the parent array
  1202. ((ArrayList)objectStack.Peek()).Add(currentObject);
  1203. objectStack.Push(currentObject);
  1204. }
  1205. else
  1206. {
  1207. // add it to the parent hashtable
  1208. ((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
  1209. objectStack.Push(currentObject);
  1210. }
  1211. // clear the key
  1212. currentKey = null;
  1213. break;
  1214. case '}':
  1215. // pop the hashtable off the stack
  1216. objectStack.Pop();
  1217. break;
  1218. case '"':// string boundary
  1219. string tokenValue = "";
  1220. i++; // move to next char
  1221. // just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
  1222. while (JSON[i] != '"')
  1223. {
  1224. tokenValue += JSON[i];
  1225. // handle escaped double quotes \"
  1226. if (JSON[i] == '\\' && JSON[i+1] == '"')
  1227. {
  1228. tokenValue += JSON[i+1];
  1229. i++;
  1230. }
  1231. i++;
  1232. }
  1233. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1234. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1235. {
  1236. ((ArrayList)objectStack.Peek()).Add(tokenValue);
  1237. }
  1238. else if (currentKey == null) // no key stored and its not an array this must be a key so store it
  1239. {
  1240. currentKey = tokenValue;
  1241. }
  1242. else
  1243. {
  1244. // we have a key so lets store this value
  1245. ((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
  1246. // now lets clear the key, we're done with it and moving on
  1247. currentKey = null;
  1248. }
  1249. break;
  1250. case ':':// key : value separator
  1251. // just ignore
  1252. break;
  1253. case ' ':// spaces
  1254. // just ignore
  1255. break;
  1256. case '[': // array start
  1257. ArrayList currentArray = new ArrayList();
  1258. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1259. {
  1260. ((ArrayList)objectStack.Peek()).Add(currentArray);
  1261. }
  1262. else
  1263. {
  1264. ((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
  1265. // clear the key
  1266. currentKey = null;
  1267. }
  1268. objectStack.Push(currentArray);
  1269. break;
  1270. case ',':// seperator
  1271. // just ignore
  1272. break;
  1273. case ']'://Array end
  1274. // pop the array off the stack
  1275. objectStack.Pop();
  1276. break;
  1277. case 't': // we've found a character start not in quotes, it must be a boolean true
  1278. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1279. {
  1280. ((ArrayList)objectStack.Peek()).Add(true);
  1281. }
  1282. else
  1283. {
  1284. ((Hashtable)objectStack.Peek()).Add(currentKey,true);
  1285. currentKey = null;
  1286. }
  1287. //advance the counter to the letter 'e'
  1288. i = i + 3;
  1289. break;
  1290. case 'f': // we've found a character start not in quotes, it must be a boolean false
  1291. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1292. {
  1293. ((ArrayList)objectStack.Peek()).Add(false);
  1294. }
  1295. else
  1296. {
  1297. ((Hashtable)objectStack.Peek()).Add(currentKey,false);
  1298. currentKey = null;
  1299. }
  1300. //advance the counter to the letter 'e'
  1301. i = i + 4;
  1302. break;
  1303. case '\n':// carriage return
  1304. // just ignore
  1305. break;
  1306. case '\r':// carriage return
  1307. // just ignore
  1308. break;
  1309. default:
  1310. // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
  1311. // but for now we'll just do them as strings
  1312. string numberValue = "";
  1313. // just loop through until the next known marker quote mark storing the string
  1314. while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
  1315. {
  1316. numberValue += "" + JSON[i++];
  1317. }
  1318. i--; // we want to process this caracter that marked the end of this string in the main loop
  1319. // ok we've got a string, if we've got an array on the top of the stack then we store it
  1320. if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
  1321. {
  1322. ((ArrayList)objectStack.Peek()).Add(numberValue);
  1323. }
  1324. else
  1325. {
  1326. // we have a key so lets store this value
  1327. ((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
  1328. // now lets clear the key, we're done with it and moving on
  1329. currentKey = null;
  1330. }
  1331. break;
  1332. }
  1333. }
  1334. }
  1335. catch(Exception)
  1336. {
  1337. OSSLError("osParseJSON: The JSON string is not valid " + JSON) ;
  1338. }
  1339. return jsondata;
  1340. }
  1341. // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function
  1342. // the dataserver function is passed the ID of the calling function and a string message
  1343. public void osMessageObject(LSL_Key objectUUID, string message)
  1344. {
  1345. CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
  1346. m_host.AddScriptLPS(1);
  1347. object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
  1348. SceneObjectPart sceneOP = World.GetSceneObjectPart(new UUID(objectUUID));
  1349. m_ScriptEngine.PostObjectEvent(
  1350. sceneOP.LocalId, new EventParams(
  1351. "dataserver", resobj, new DetectParams[0]));
  1352. }
  1353. // This needs ThreatLevel high. It is an excellent griefer tool,
  1354. // In a loop, it can cause asset bloat and DOS levels of asset
  1355. // writes.
  1356. //
  1357. public void osMakeNotecard(string notecardName, LSL_Types.list contents)
  1358. {
  1359. CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
  1360. m_host.AddScriptLPS(1);
  1361. // Create new asset
  1362. AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
  1363. asset.Description = "Script Generated Notecard";
  1364. string notecardData = String.Empty;
  1365. for (int i = 0; i < contents.Length; i++) {
  1366. notecardData += contents.GetLSLStringItem(i) + "\n";
  1367. }
  1368. int textLength = notecardData.Length;
  1369. notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  1370. + textLength.ToString() + "\n" + notecardData + "}\n";
  1371. asset.Data = Util.UTF8.GetBytes(notecardData);
  1372. World.AssetService.Store(asset);
  1373. // Create Task Entry
  1374. TaskInventoryItem taskItem=new TaskInventoryItem();
  1375. taskItem.ResetIDs(m_host.UUID);
  1376. taskItem.ParentID = m_host.UUID;
  1377. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  1378. taskItem.Name = asset.Name;
  1379. taskItem.Description = asset.Description;
  1380. taskItem.Type = (int)AssetType.Notecard;
  1381. taskItem.InvType = (int)InventoryType.Notecard;
  1382. taskItem.OwnerID = m_host.OwnerID;
  1383. taskItem.CreatorID = m_host.OwnerID;
  1384. taskItem.BasePermissions = (uint)PermissionMask.All;
  1385. taskItem.CurrentPermissions = (uint)PermissionMask.All;
  1386. taskItem.EveryonePermissions = 0;
  1387. taskItem.NextPermissions = (uint)PermissionMask.All;
  1388. taskItem.GroupID = m_host.GroupID;
  1389. taskItem.GroupPermissions = 0;
  1390. taskItem.Flags = 0;
  1391. taskItem.PermsGranter = UUID.Zero;
  1392. taskItem.PermsMask = 0;
  1393. taskItem.AssetID = asset.FullID;
  1394. m_host.Inventory.AddInventoryItem(taskItem, false);
  1395. }
  1396. /*Instead of using the LSL Dataserver event to pull notecard data,
  1397. this will simply read the requested line and return its data as a string.
  1398. Warning - due to the synchronous method this function uses to fetch assets, its use
  1399. may be dangerous and unreliable while running in grid mode.
  1400. */
  1401. public string osGetNotecardLine(string name, int line)
  1402. {
  1403. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
  1404. m_host.AddScriptLPS(1);
  1405. UUID assetID = UUID.Zero;
  1406. if (!UUID.TryParse(name, out assetID))
  1407. {
  1408. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1409. {
  1410. if (item.Type == 7 && item.Name == name)
  1411. {
  1412. assetID = item.AssetID;
  1413. }
  1414. }
  1415. }
  1416. if (assetID == UUID.Zero)
  1417. {
  1418. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1419. return "ERROR!";
  1420. }
  1421. if (!NotecardCache.IsCached(assetID))
  1422. {
  1423. AssetBase a = World.AssetService.Get(assetID.ToString());
  1424. if (a != null)
  1425. {
  1426. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1427. string data = enc.GetString(a.Data);
  1428. NotecardCache.Cache(assetID, data);
  1429. }
  1430. else
  1431. {
  1432. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1433. return "ERROR!";
  1434. }
  1435. };
  1436. return NotecardCache.GetLine(assetID, line, 255);
  1437. }
  1438. /*Instead of using the LSL Dataserver event to pull notecard data line by line,
  1439. this will simply read the entire notecard and return its data as a string.
  1440. Warning - due to the synchronous method this function uses to fetch assets, its use
  1441. may be dangerous and unreliable while running in grid mode.
  1442. */
  1443. public string osGetNotecard(string name)
  1444. {
  1445. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
  1446. m_host.AddScriptLPS(1);
  1447. UUID assetID = UUID.Zero;
  1448. string NotecardData = "";
  1449. if (!UUID.TryParse(name, out assetID))
  1450. {
  1451. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1452. {
  1453. if (item.Type == 7 && item.Name == name)
  1454. {
  1455. assetID = item.AssetID;
  1456. }
  1457. }
  1458. }
  1459. if (assetID == UUID.Zero)
  1460. {
  1461. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1462. return "ERROR!";
  1463. }
  1464. if (!NotecardCache.IsCached(assetID))
  1465. {
  1466. AssetBase a = World.AssetService.Get(assetID.ToString());
  1467. if (a != null)
  1468. {
  1469. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1470. string data = enc.GetString(a.Data);
  1471. NotecardCache.Cache(assetID, data);
  1472. }
  1473. else
  1474. {
  1475. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1476. return "ERROR!";
  1477. }
  1478. };
  1479. for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
  1480. {
  1481. NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n";
  1482. }
  1483. return NotecardData;
  1484. }
  1485. /*Instead of using the LSL Dataserver event to pull notecard data,
  1486. this will simply read the number of note card lines and return this data as an integer.
  1487. Warning - due to the synchronous method this function uses to fetch assets, its use
  1488. may be dangerous and unreliable while running in grid mode.
  1489. */
  1490. public int osGetNumberOfNotecardLines(string name)
  1491. {
  1492. CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
  1493. m_host.AddScriptLPS(1);
  1494. UUID assetID = UUID.Zero;
  1495. if (!UUID.TryParse(name, out assetID))
  1496. {
  1497. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  1498. {
  1499. if (item.Type == 7 && item.Name == name)
  1500. {
  1501. assetID = item.AssetID;
  1502. }
  1503. }
  1504. }
  1505. if (assetID == UUID.Zero)
  1506. {
  1507. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1508. return -1;
  1509. }
  1510. if (!NotecardCache.IsCached(assetID))
  1511. {
  1512. AssetBase a = World.AssetService.Get(assetID.ToString());
  1513. if (a != null)
  1514. {
  1515. System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  1516. string data = enc.GetString(a.Data);
  1517. NotecardCache.Cache(assetID, data);
  1518. }
  1519. else
  1520. {
  1521. OSSLShoutError("Notecard '" + name + "' could not be found.");
  1522. return -1;
  1523. }
  1524. };
  1525. return NotecardCache.GetLines(assetID);
  1526. }
  1527. public string osAvatarName2Key(string firstname, string lastname)
  1528. {
  1529. CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");
  1530. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname);
  1531. if (null == account)
  1532. {
  1533. return UUID.Zero.ToString();
  1534. }
  1535. else
  1536. {
  1537. return account.PrincipalID.ToString();
  1538. }
  1539. }
  1540. public string osKey2Name(string id)
  1541. {
  1542. CheckThreatLevel(ThreatLevel.Low, "osKey2Name");
  1543. UUID key = new UUID();
  1544. if (UUID.TryParse(id, out key))
  1545. {
  1546. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key);
  1547. if (null == account)
  1548. {
  1549. return "";
  1550. }
  1551. else
  1552. {
  1553. return account.Name;
  1554. }
  1555. }
  1556. else
  1557. {
  1558. return "";
  1559. }
  1560. }
  1561. /// Threat level is Moderate because intentional abuse, for instance
  1562. /// scripts that are written to be malicious only on one grid,
  1563. /// for instance in a HG scenario, are a distinct possibility.
  1564. ///
  1565. /// Use value from the config file and return it.
  1566. ///
  1567. public string osGetGridNick()
  1568. {
  1569. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
  1570. m_host.AddScriptLPS(1);
  1571. string nick = "hippogrid";
  1572. IConfigSource config = m_ScriptEngine.ConfigSource;
  1573. if (config.Configs["GridInfo"] != null)
  1574. nick = config.Configs["GridInfo"].GetString("gridnick", nick);
  1575. return nick;
  1576. }
  1577. public string osGetGridName()
  1578. {
  1579. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridName");
  1580. m_host.AddScriptLPS(1);
  1581. string name = "the lost continent of hippo";
  1582. IConfigSource config = m_ScriptEngine.ConfigSource;
  1583. if (config.Configs["GridInfo"] != null)
  1584. name = config.Configs["GridInfo"].GetString("gridname", name);
  1585. return name;
  1586. }
  1587. public string osGetGridLoginURI()
  1588. {
  1589. CheckThreatLevel(ThreatLevel.Moderate, "osGetGridLoginURI");
  1590. m_host.AddScriptLPS(1);
  1591. string loginURI = "http://127.0.0.1:9000/";
  1592. IConfigSource config = m_ScriptEngine.ConfigSource;
  1593. if (config.Configs["GridInfo"] != null)
  1594. loginURI = config.Configs["GridInfo"].GetString("login", loginURI);
  1595. return loginURI;
  1596. }
  1597. public LSL_String osFormatString(string str, LSL_List strings)
  1598. {
  1599. CheckThreatLevel(ThreatLevel.Low, "osFormatString");
  1600. m_host.AddScriptLPS(1);
  1601. return String.Format(str, strings.Data);
  1602. }
  1603. public LSL_List osMatchString(string src, string pattern, int start)
  1604. {
  1605. CheckThreatLevel(ThreatLevel.High, "osMatchString");
  1606. m_host.AddScriptLPS(1);
  1607. LSL_List result = new LSL_List();
  1608. // Normalize indices (if negative).
  1609. // After normlaization they may still be
  1610. // negative, but that is now relative to
  1611. // the start, rather than the end, of the
  1612. // sequence.
  1613. if (start < 0)
  1614. {
  1615. start = src.Length + start;
  1616. }
  1617. if (start < 0 || start >= src.Length)
  1618. {
  1619. return result; // empty list
  1620. }
  1621. // Find matches beginning at start position
  1622. Regex matcher = new Regex(pattern);
  1623. Match match = matcher.Match(src, start);
  1624. if (match.Success)
  1625. {
  1626. foreach (System.Text.RegularExpressions.Group g in match.Groups)
  1627. {
  1628. if (g.Success)
  1629. {
  1630. result.Add(g.Value);
  1631. result.Add(g.Index);
  1632. }
  1633. }
  1634. }
  1635. return result;
  1636. }
  1637. public string osLoadedCreationDate()
  1638. {
  1639. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationDate");
  1640. m_host.AddScriptLPS(1);
  1641. return World.RegionInfo.RegionSettings.LoadedCreationDate;
  1642. }
  1643. public string osLoadedCreationTime()
  1644. {
  1645. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationTime");
  1646. m_host.AddScriptLPS(1);
  1647. return World.RegionInfo.RegionSettings.LoadedCreationTime;
  1648. }
  1649. public string osLoadedCreationID()
  1650. {
  1651. CheckThreatLevel(ThreatLevel.Low, "osLoadedCreationID");
  1652. m_host.AddScriptLPS(1);
  1653. return World.RegionInfo.RegionSettings.LoadedCreationID;
  1654. }
  1655. // Threat level is 'Low' because certain users could possibly be tricked into
  1656. // dropping an unverified script into one of their own objects, which could
  1657. // then gather the physical construction details of the object and transmit it
  1658. // to an unscrupulous third party, thus permitting unauthorized duplication of
  1659. // the object's form.
  1660. //
  1661. public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  1662. {
  1663. CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
  1664. m_host.AddScriptLPS(1);
  1665. InitLSL();
  1666. LSL_List retVal = new LSL_List();
  1667. List<SceneObjectPart> parts = ((LSL_Api)m_LSL_Api).GetLinkParts(linknumber);
  1668. foreach (SceneObjectPart part in parts)
  1669. {
  1670. retVal += ((LSL_Api)m_LSL_Api).GetLinkPrimitiveParams(part, rules);
  1671. }
  1672. return retVal;
  1673. }
  1674. public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
  1675. {
  1676. CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
  1677. //QueueUserWorkItem
  1678. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1679. if (module != null)
  1680. {
  1681. UUID x = module.CreateNPC(firstname,
  1682. lastname,
  1683. new Vector3((float) position.x, (float) position.y, (float) position.z),
  1684. World,
  1685. new UUID(cloneFrom));
  1686. return new LSL_Key(x.ToString());
  1687. }
  1688. return new LSL_Key(UUID.Zero.ToString());
  1689. }
  1690. public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
  1691. {
  1692. CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
  1693. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1694. if (module != null)
  1695. {
  1696. Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
  1697. module.Autopilot(new UUID(npc.m_string), World, pos);
  1698. }
  1699. }
  1700. public void osNpcSay(LSL_Key npc, string message)
  1701. {
  1702. CheckThreatLevel(ThreatLevel.High, "osNpcSay");
  1703. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1704. if (module != null)
  1705. {
  1706. module.Say(new UUID(npc.m_string), World, message);
  1707. }
  1708. }
  1709. public void osNpcRemove(LSL_Key npc)
  1710. {
  1711. CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
  1712. INPCModule module = World.RequestModuleInterface<INPCModule>();
  1713. if (module != null)
  1714. {
  1715. module.DeleteNPC(new UUID(npc.m_string), World);
  1716. }
  1717. }
  1718. /// <summary>
  1719. /// Get current region's map texture UUID
  1720. /// </summary>
  1721. /// <returns></returns>
  1722. public LSL_Key osGetMapTexture()
  1723. {
  1724. CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
  1725. return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
  1726. }
  1727. /// <summary>
  1728. /// Get a region's map texture UUID by region UUID or name.
  1729. /// </summary>
  1730. /// <param name="regionName"></param>
  1731. /// <returns></returns>
  1732. public LSL_Key osGetRegionMapTexture(string regionName)
  1733. {
  1734. CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
  1735. Scene scene = m_ScriptEngine.World;
  1736. UUID key = UUID.Zero;
  1737. GridRegion region;
  1738. //If string is a key, use it. Otherwise, try to locate region by name.
  1739. if (UUID.TryParse(regionName, out key))
  1740. region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
  1741. else
  1742. region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
  1743. // If region was found, return the regions map texture key.
  1744. if (region != null)
  1745. key = region.TerrainImage;
  1746. ScriptSleep(1000);
  1747. return key.ToString();
  1748. }
  1749. /// <summary>
  1750. /// Return information regarding various simulator statistics (sim fps, physics fps, time
  1751. /// dilation, total number of prims, total number of active scripts, script lps, various
  1752. /// timing data, packets in/out, etc. Basically much the information that's shown in the
  1753. /// client's Statistics Bar (Ctrl-Shift-1)
  1754. /// </summary>
  1755. /// <returns>List of floats</returns>
  1756. public LSL_List osGetRegionStats()
  1757. {
  1758. CheckThreatLevel(ThreatLevel.Moderate, "osGetRegionStats");
  1759. m_host.AddScriptLPS(1);
  1760. LSL_List ret = new LSL_List();
  1761. float[] stats = World.SimulatorStats;
  1762. for (int i = 0; i < 21; i++)
  1763. {
  1764. ret.Add(new LSL_Float(stats[i]));
  1765. }
  1766. return ret;
  1767. }
  1768. public int osGetSimulatorMemory()
  1769. {
  1770. CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory");
  1771. m_host.AddScriptLPS(1);
  1772. long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
  1773. if (pws > Int32.MaxValue)
  1774. return Int32.MaxValue;
  1775. if (pws < 0)
  1776. return 0;
  1777. return (int)pws;
  1778. }
  1779. public void osSetSpeed(string UUID, float SpeedModifier)
  1780. {
  1781. CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed");
  1782. m_host.AddScriptLPS(1);
  1783. ScenePresence avatar = World.GetScenePresence(new UUID(UUID));
  1784. avatar.SpeedModifier = SpeedModifier;
  1785. }
  1786. public void osKickAvatar(string FirstName,string SurName,string alert)
  1787. {
  1788. CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
  1789. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  1790. {
  1791. World.ForEachScenePresence(delegate(ScenePresence sp)
  1792. {
  1793. if (!sp.IsChildAgent &&
  1794. sp.Firstname == FirstName &&
  1795. sp.Lastname == SurName)
  1796. {
  1797. // kick client...
  1798. if (alert != null)
  1799. sp.ControllingClient.Kick(alert);
  1800. // ...and close on our side
  1801. sp.Scene.IncomingCloseAgent(sp.UUID);
  1802. }
  1803. });
  1804. }
  1805. }
  1806. public void osCauseDamage(string avatar, double damage)
  1807. {
  1808. CheckThreatLevel(ThreatLevel.High, "osCauseDamage");
  1809. m_host.AddScriptLPS(1);
  1810. UUID avatarId = new UUID(avatar);
  1811. Vector3 pos = m_host.GetWorldPosition();
  1812. ScenePresence presence = World.GetScenePresence(avatarId);
  1813. if (presence != null)
  1814. {
  1815. LandData land = World.GetLandData((float)pos.X, (float)pos.Y);
  1816. if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
  1817. {
  1818. float health = presence.Health;
  1819. health -= (float)damage;
  1820. presence.setHealthWithUpdate(health);
  1821. if (health <= 0)
  1822. {
  1823. float healthliveagain = 100;
  1824. presence.ControllingClient.SendAgentAlertMessage("You died!", true);
  1825. presence.setHealthWithUpdate(healthliveagain);
  1826. presence.Scene.TeleportClientHome(presence.UUID, presence.ControllingClient);
  1827. }
  1828. }
  1829. }
  1830. }
  1831. public void osCauseHealing(string avatar, double healing)
  1832. {
  1833. CheckThreatLevel(ThreatLevel.High, "osCauseHealing");
  1834. m_host.AddScriptLPS(1);
  1835. UUID avatarId = new UUID(avatar);
  1836. ScenePresence presence = World.GetScenePresence(avatarId);
  1837. Vector3 pos = m_host.GetWorldPosition();
  1838. bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.X, (float)pos.Y, (float)pos.Z));
  1839. if (result)
  1840. {
  1841. if (presence != null)
  1842. {
  1843. float health = presence.Health;
  1844. health += (float)healing;
  1845. if (health >= 100)
  1846. {
  1847. health = 100;
  1848. }
  1849. presence.setHealthWithUpdate(health);
  1850. }
  1851. }
  1852. }
  1853. public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1854. {
  1855. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1856. m_host.AddScriptLPS(1);
  1857. return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules);
  1858. }
  1859. public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
  1860. {
  1861. CheckThreatLevel(ThreatLevel.High, "osGetPrimitiveParams");
  1862. m_host.AddScriptLPS(1);
  1863. m_LSL_Api.SetPrimitiveParamsEx(prim, rules);
  1864. }
  1865. /// <summary>
  1866. /// Like osGetAgents but returns enough info for a radar
  1867. /// </summary>
  1868. /// <returns>Strided list of the UUID, position and name of each avatar in the region</returns>
  1869. public LSL_List osGetAvatarList()
  1870. {
  1871. CheckThreatLevel(ThreatLevel.None, "osGetAvatarList");
  1872. LSL_List result = new LSL_List();
  1873. World.ForEachScenePresence(delegate (ScenePresence avatar)
  1874. {
  1875. if (avatar != null && avatar.UUID != m_host.OwnerID)
  1876. {
  1877. if (avatar.IsChildAgent == false)
  1878. {
  1879. result.Add(avatar.UUID);
  1880. result.Add(avatar.AbsolutePosition);
  1881. result.Add(avatar.Name);
  1882. }
  1883. }
  1884. });
  1885. return result;
  1886. }
  1887. }
  1888. }