OSSL_Api.cs 102 KB

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