SampleMoneyModule.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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.Net;
  31. using System.Reflection;
  32. using log4net;
  33. using Nini.Config;
  34. using Nwc.XmlRpc;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications.Cache;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.ReplaceableModules.MoneyModule
  42. {
  43. /// <summary>
  44. /// This is only the functionality required to make the functionality associated with money work
  45. /// (such as land transfers). There is no money code here! Use FORGE as an example for money code.
  46. /// Demo Economy/Money Module. This is a purposely crippled module!
  47. /// // To land transfer you need to add:
  48. /// -helperuri <ADDRESS TO THIS SERVER>
  49. /// to the command line parameters you use to start up your client
  50. /// This commonly looks like -helperuri http://127.0.0.1:9000/
  51. ///
  52. /// </summary>
  53. public class SampleMoneyModule : IMoneyModule, IRegionModule
  54. {
  55. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  56. /// <summary>
  57. /// Where Stipends come from and Fees go to.
  58. /// </summary>
  59. // private UUID EconomyBaseAccount = UUID.Zero;
  60. private float EnergyEfficiency = 0f;
  61. private bool gridmode = false;
  62. // private ObjectPaid handerOnObjectPaid;
  63. private bool m_enabled = true;
  64. private bool m_sellEnabled = false;
  65. private IConfigSource m_gConfig;
  66. /// <summary>
  67. /// Region UUIDS indexed by AgentID
  68. /// </summary>
  69. /// <summary>
  70. /// Scenes by Region Handle
  71. /// </summary>
  72. private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
  73. // private int m_stipend = 1000;
  74. private int ObjectCapacity = 45000;
  75. private int ObjectCount = 0;
  76. private int PriceEnergyUnit = 0;
  77. private int PriceGroupCreate = 0;
  78. private int PriceObjectClaim = 0;
  79. private float PriceObjectRent = 0f;
  80. private float PriceObjectScaleFactor = 0f;
  81. private int PriceParcelClaim = 0;
  82. private float PriceParcelClaimFactor = 0f;
  83. private int PriceParcelRent = 0;
  84. private int PricePublicObjectDecay = 0;
  85. private int PricePublicObjectDelete = 0;
  86. private int PriceRentLight = 0;
  87. private int PriceUpload = 0;
  88. private int TeleportMinPrice = 0;
  89. private float TeleportPriceExponent = 0f;
  90. #region IMoneyModule Members
  91. public event ObjectPaid OnObjectPaid;
  92. /// <summary>
  93. /// Startup
  94. /// </summary>
  95. /// <param name="scene"></param>
  96. /// <param name="config"></param>
  97. public void Initialise(Scene scene, IConfigSource config)
  98. {
  99. m_gConfig = config;
  100. IConfig startupConfig = m_gConfig.Configs["Startup"];
  101. IConfig economyConfig = m_gConfig.Configs["Economy"];
  102. ReadConfigAndPopulate(scene, startupConfig, "Startup");
  103. ReadConfigAndPopulate(scene, economyConfig, "Economy");
  104. if (m_enabled)
  105. {
  106. scene.RegisterModuleInterface<IMoneyModule>(this);
  107. IHttpServer httpServer = scene.CommsManager.HttpServer;
  108. lock (m_scenel)
  109. {
  110. if (m_scenel.Count == 0)
  111. {
  112. // XMLRPCHandler = scene;
  113. // To use the following you need to add:
  114. // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER>
  115. // to the command line parameters you use to start up your client
  116. // This commonly looks like -helperuri http://127.0.0.1:9000/
  117. // Local Server.. enables functionality only.
  118. httpServer.AddXmlRPCHandler("getCurrencyQuote", quote_func);
  119. httpServer.AddXmlRPCHandler("buyCurrency", buy_func);
  120. httpServer.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
  121. httpServer.AddXmlRPCHandler("buyLandPrep", landBuy_func);
  122. }
  123. if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
  124. {
  125. m_scenel[scene.RegionInfo.RegionHandle] = scene;
  126. }
  127. else
  128. {
  129. m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
  130. }
  131. }
  132. scene.EventManager.OnNewClient += OnNewClient;
  133. scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
  134. scene.EventManager.OnClientClosed += ClientClosed;
  135. scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
  136. scene.EventManager.OnMakeChildAgent += MakeChildAgent;
  137. scene.EventManager.OnClientClosed += ClientLoggedOut;
  138. scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
  139. scene.EventManager.OnLandBuy += processLandBuy;
  140. }
  141. }
  142. // Please do not refactor these to be just one method
  143. // Existing implementations need the distinction
  144. //
  145. public void ApplyUploadCharge(UUID agentID)
  146. {
  147. }
  148. public void ApplyGroupCreationCharge(UUID agentID)
  149. {
  150. }
  151. public void ApplyCharge(UUID agentID, int amount, string text)
  152. {
  153. }
  154. public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount)
  155. {
  156. string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
  157. bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
  158. BalanceUpdate(fromID, toID, give_result, description);
  159. return give_result;
  160. }
  161. public void PostInitialise()
  162. {
  163. }
  164. public void Close()
  165. {
  166. }
  167. public string Name
  168. {
  169. get { return "BetaGridLikeMoneyModule"; }
  170. }
  171. public bool IsSharedModule
  172. {
  173. get { return true; }
  174. }
  175. #endregion
  176. /// <summary>
  177. /// Parse Configuration
  178. /// </summary>
  179. /// <param name="scene"></param>
  180. /// <param name="startupConfig"></param>
  181. /// <param name="config"></param>
  182. private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config)
  183. {
  184. if (config == "Startup" && startupConfig != null)
  185. {
  186. gridmode = startupConfig.GetBoolean("gridmode", false);
  187. m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
  188. }
  189. if (config == "Economy" && startupConfig != null)
  190. {
  191. ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000);
  192. PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
  193. PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
  194. PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4);
  195. PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4);
  196. PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1);
  197. PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f);
  198. PriceUpload = startupConfig.GetInt("PriceUpload", 0);
  199. PriceRentLight = startupConfig.GetInt("PriceRentLight", 5);
  200. TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2);
  201. TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f);
  202. EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1);
  203. PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1);
  204. PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10);
  205. PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
  206. PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
  207. m_sellEnabled = startupConfig.GetBoolean("SellEnabled", false);
  208. }
  209. // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
  210. scene.SetObjectCapacity(ObjectCapacity);
  211. }
  212. public EconomyData GetEconomyData()
  213. {
  214. EconomyData edata = new EconomyData();
  215. edata.ObjectCapacity = ObjectCapacity;
  216. edata.ObjectCount = ObjectCount;
  217. edata.PriceEnergyUnit = PriceEnergyUnit;
  218. edata.PriceGroupCreate = PriceGroupCreate;
  219. edata.PriceObjectClaim = PriceObjectClaim;
  220. edata.PriceObjectRent = PriceObjectRent;
  221. edata.PriceObjectScaleFactor = PriceObjectScaleFactor;
  222. edata.PriceParcelClaim = PriceParcelClaim;
  223. edata.PriceParcelClaimFactor = PriceParcelClaimFactor;
  224. edata.PriceParcelRent = PriceParcelRent;
  225. edata.PricePublicObjectDecay = PricePublicObjectDecay;
  226. edata.PricePublicObjectDelete = PricePublicObjectDelete;
  227. edata.PriceRentLight = PriceRentLight;
  228. edata.PriceUpload = PriceUpload;
  229. edata.TeleportMinPrice = TeleportMinPrice;
  230. return edata;
  231. }
  232. private void GetClientFunds(IClientAPI client)
  233. {
  234. // Here we check if we're in grid mode
  235. // I imagine that the 'check balance'
  236. // function for the client should be here or shortly after
  237. if (gridmode)
  238. {
  239. CheckExistAndRefreshFunds(client.AgentId);
  240. }
  241. else
  242. {
  243. CheckExistAndRefreshFunds(client.AgentId);
  244. }
  245. }
  246. /// <summary>
  247. /// New Client Event Handler
  248. /// </summary>
  249. /// <param name="client"></param>
  250. private void OnNewClient(IClientAPI client)
  251. {
  252. GetClientFunds(client);
  253. // Subscribe to Money messages
  254. client.OnEconomyDataRequest += EconomyDataRequestHandler;
  255. client.OnMoneyBalanceRequest += SendMoneyBalance;
  256. client.OnRequestPayPrice += requestPayPrice;
  257. client.OnObjectBuy += ObjectBuy;
  258. client.OnLogout += ClientClosed;
  259. }
  260. /// <summary>
  261. /// Transfer money
  262. /// </summary>
  263. /// <param name="Sender"></param>
  264. /// <param name="Receiver"></param>
  265. /// <param name="amount"></param>
  266. /// <returns></returns>
  267. private bool doMoneyTransfer(UUID Sender, UUID Receiver, int amount, int transactiontype, string description)
  268. {
  269. bool result = true;
  270. return result;
  271. }
  272. /// <summary>
  273. /// Sends the the stored money balance to the client
  274. /// </summary>
  275. /// <param name="client"></param>
  276. /// <param name="agentID"></param>
  277. /// <param name="SessionID"></param>
  278. /// <param name="TransactionID"></param>
  279. public void SendMoneyBalance(IClientAPI client, UUID agentID, UUID SessionID, UUID TransactionID)
  280. {
  281. if (client.AgentId == agentID && client.SessionId == SessionID)
  282. {
  283. int returnfunds = 0;
  284. try
  285. {
  286. returnfunds = GetFundsForAgentID(agentID);
  287. }
  288. catch (Exception e)
  289. {
  290. client.SendAlertMessage(e.Message + " ");
  291. }
  292. client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
  293. }
  294. else
  295. {
  296. client.SendAlertMessage("Unable to send your money balance to you!");
  297. }
  298. }
  299. private SceneObjectPart findPrim(UUID objectID)
  300. {
  301. lock (m_scenel)
  302. {
  303. foreach (Scene s in m_scenel.Values)
  304. {
  305. SceneObjectPart part = s.GetSceneObjectPart(objectID);
  306. if (part != null)
  307. {
  308. return part;
  309. }
  310. }
  311. }
  312. return null;
  313. }
  314. private string resolveObjectName(UUID objectID)
  315. {
  316. SceneObjectPart part = findPrim(objectID);
  317. if (part != null)
  318. {
  319. return part.Name;
  320. }
  321. return String.Empty;
  322. }
  323. private string resolveAgentName(UUID agentID)
  324. {
  325. // try avatar username surname
  326. Scene scene = GetRandomScene();
  327. CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  328. if (profile != null && profile.UserProfile != null)
  329. {
  330. string avatarname = profile.UserProfile.FirstName + " " + profile.UserProfile.SurName;
  331. return avatarname;
  332. }
  333. else
  334. {
  335. m_log.ErrorFormat(
  336. "[MONEY]: Could not resolve user {0}",
  337. agentID);
  338. }
  339. return String.Empty;
  340. }
  341. private void BalanceUpdate(UUID senderID, UUID receiverID, bool transactionresult, string description)
  342. {
  343. IClientAPI sender = LocateClientObject(senderID);
  344. IClientAPI receiver = LocateClientObject(receiverID);
  345. if (senderID != receiverID)
  346. {
  347. if (sender != null)
  348. {
  349. sender.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(senderID));
  350. }
  351. if (receiver != null)
  352. {
  353. receiver.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(receiverID));
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// XMLRPC handler to send alert message and sound to client
  359. /// </summary>
  360. public XmlRpcResponse UserAlert(XmlRpcRequest request, IPEndPoint remoteClient)
  361. {
  362. XmlRpcResponse ret = new XmlRpcResponse();
  363. Hashtable retparam = new Hashtable();
  364. Hashtable requestData = (Hashtable) request.Params[0];
  365. UUID agentId;
  366. UUID soundId;
  367. UUID regionId;
  368. UUID.TryParse((string) requestData["agentId"], out agentId);
  369. UUID.TryParse((string) requestData["soundId"], out soundId);
  370. UUID.TryParse((string) requestData["regionId"], out regionId);
  371. string text = (string) requestData["text"];
  372. string secret = (string) requestData["secret"];
  373. Scene userScene = GetSceneByUUID(regionId);
  374. if (userScene != null)
  375. {
  376. if (userScene.RegionInfo.regionSecret == secret)
  377. {
  378. IClientAPI client = LocateClientObject(agentId);
  379. if (client != null)
  380. {
  381. if (soundId != UUID.Zero)
  382. client.SendPlayAttachedSound(soundId, UUID.Zero, UUID.Zero, 1.0f, 0);
  383. client.SendBlueBoxMessage(UUID.Zero, "", text);
  384. retparam.Add("success", true);
  385. }
  386. else
  387. {
  388. retparam.Add("success", false);
  389. }
  390. }
  391. else
  392. {
  393. retparam.Add("success", false);
  394. }
  395. }
  396. ret.Value = retparam;
  397. return ret;
  398. }
  399. # region Standalone box enablers only
  400. public XmlRpcResponse quote_func(XmlRpcRequest request, IPEndPoint remoteClient)
  401. {
  402. // Hashtable requestData = (Hashtable) request.Params[0];
  403. // UUID agentId = UUID.Zero;
  404. int amount = 0;
  405. Hashtable quoteResponse = new Hashtable();
  406. XmlRpcResponse returnval = new XmlRpcResponse();
  407. Hashtable currencyResponse = new Hashtable();
  408. currencyResponse.Add("estimatedCost", 0);
  409. currencyResponse.Add("currencyBuy", amount);
  410. quoteResponse.Add("success", true);
  411. quoteResponse.Add("currency", currencyResponse);
  412. quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
  413. returnval.Value = quoteResponse;
  414. return returnval;
  415. }
  416. public XmlRpcResponse buy_func(XmlRpcRequest request, IPEndPoint remoteClient)
  417. {
  418. // Hashtable requestData = (Hashtable) request.Params[0];
  419. // UUID agentId = UUID.Zero;
  420. // int amount = 0;
  421. XmlRpcResponse returnval = new XmlRpcResponse();
  422. Hashtable returnresp = new Hashtable();
  423. returnresp.Add("success", true);
  424. returnval.Value = returnresp;
  425. return returnval;
  426. }
  427. public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request, IPEndPoint remoteClient)
  428. {
  429. XmlRpcResponse ret = new XmlRpcResponse();
  430. Hashtable retparam = new Hashtable();
  431. Hashtable membershiplevels = new Hashtable();
  432. ArrayList levels = new ArrayList();
  433. Hashtable level = new Hashtable();
  434. level.Add("id", "00000000-0000-0000-0000-000000000000");
  435. level.Add("description", "some level");
  436. levels.Add(level);
  437. //membershiplevels.Add("levels",levels);
  438. Hashtable landuse = new Hashtable();
  439. landuse.Add("upgrade", false);
  440. landuse.Add("action", "http://invaliddomaininvalid.com/");
  441. Hashtable currency = new Hashtable();
  442. currency.Add("estimatedCost", 0);
  443. Hashtable membership = new Hashtable();
  444. membershiplevels.Add("upgrade", false);
  445. membershiplevels.Add("action", "http://invaliddomaininvalid.com/");
  446. membershiplevels.Add("levels", membershiplevels);
  447. retparam.Add("success", true);
  448. retparam.Add("currency", currency);
  449. retparam.Add("membership", membership);
  450. retparam.Add("landuse", landuse);
  451. retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf");
  452. ret.Value = retparam;
  453. return ret;
  454. }
  455. public XmlRpcResponse landBuy_func(XmlRpcRequest request, IPEndPoint remoteClient)
  456. {
  457. XmlRpcResponse ret = new XmlRpcResponse();
  458. Hashtable retparam = new Hashtable();
  459. // Hashtable requestData = (Hashtable) request.Params[0];
  460. // UUID agentId = UUID.Zero;
  461. // int amount = 0;
  462. retparam.Add("success", true);
  463. ret.Value = retparam;
  464. return ret;
  465. }
  466. #endregion
  467. #region local Fund Management
  468. /// <summary>
  469. /// Ensures that the agent accounting data is set up in this instance.
  470. /// </summary>
  471. /// <param name="agentID"></param>
  472. private void CheckExistAndRefreshFunds(UUID agentID)
  473. {
  474. }
  475. /// <summary>
  476. /// Gets the amount of Funds for an agent
  477. /// </summary>
  478. /// <param name="AgentID"></param>
  479. /// <returns></returns>
  480. private int GetFundsForAgentID(UUID AgentID)
  481. {
  482. int returnfunds = 0;
  483. return returnfunds;
  484. }
  485. // private void SetLocalFundsForAgentID(UUID AgentID, int amount)
  486. // {
  487. // }
  488. #endregion
  489. #region Utility Helpers
  490. /// <summary>
  491. /// Locates a IClientAPI for the client specified
  492. /// </summary>
  493. /// <param name="AgentID"></param>
  494. /// <returns></returns>
  495. private IClientAPI LocateClientObject(UUID AgentID)
  496. {
  497. ScenePresence tPresence = null;
  498. IClientAPI rclient = null;
  499. lock (m_scenel)
  500. {
  501. foreach (Scene _scene in m_scenel.Values)
  502. {
  503. tPresence = _scene.GetScenePresence(AgentID);
  504. if (tPresence != null)
  505. {
  506. if (!tPresence.IsChildAgent)
  507. {
  508. rclient = tPresence.ControllingClient;
  509. }
  510. }
  511. if (rclient != null)
  512. {
  513. return rclient;
  514. }
  515. }
  516. }
  517. return null;
  518. }
  519. private Scene LocateSceneClientIn(UUID AgentId)
  520. {
  521. lock (m_scenel)
  522. {
  523. foreach (Scene _scene in m_scenel.Values)
  524. {
  525. ScenePresence tPresence = _scene.GetScenePresence(AgentId);
  526. if (tPresence != null)
  527. {
  528. if (!tPresence.IsChildAgent)
  529. {
  530. return _scene;
  531. }
  532. }
  533. }
  534. }
  535. return null;
  536. }
  537. /// <summary>
  538. /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
  539. /// </summary>
  540. /// <returns></returns>
  541. public Scene GetRandomScene()
  542. {
  543. lock (m_scenel)
  544. {
  545. foreach (Scene rs in m_scenel.Values)
  546. return rs;
  547. }
  548. return null;
  549. }
  550. /// <summary>
  551. /// Utility function to get a Scene by RegionID in a module
  552. /// </summary>
  553. /// <param name="RegionID"></param>
  554. /// <returns></returns>
  555. public Scene GetSceneByUUID(UUID RegionID)
  556. {
  557. lock (m_scenel)
  558. {
  559. foreach (Scene rs in m_scenel.Values)
  560. {
  561. if (rs.RegionInfo.originRegionID == RegionID)
  562. {
  563. return rs;
  564. }
  565. }
  566. }
  567. return null;
  568. }
  569. #endregion
  570. #region event Handlers
  571. public void requestPayPrice(IClientAPI client, UUID objectID)
  572. {
  573. Scene scene = LocateSceneClientIn(client.AgentId);
  574. if (scene == null)
  575. return;
  576. SceneObjectPart task = scene.GetSceneObjectPart(objectID);
  577. if (task == null)
  578. return;
  579. SceneObjectGroup group = task.ParentGroup;
  580. SceneObjectPart root = group.RootPart;
  581. client.SendPayPrice(objectID, root.PayPrice);
  582. }
  583. /// <summary>
  584. /// When the client closes the connection we remove their accounting info from memory to free up resources.
  585. /// </summary>
  586. /// <param name="AgentID"></param>
  587. public void ClientClosed(UUID AgentID, Scene scene)
  588. {
  589. }
  590. /// <summary>
  591. /// Event called Economy Data Request handler.
  592. /// </summary>
  593. /// <param name="agentId"></param>
  594. public void EconomyDataRequestHandler(UUID agentId)
  595. {
  596. IClientAPI user = LocateClientObject(agentId);
  597. if (user != null)
  598. {
  599. user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
  600. PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
  601. PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
  602. TeleportMinPrice, TeleportPriceExponent);
  603. }
  604. }
  605. private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
  606. {
  607. lock (e)
  608. {
  609. e.economyValidated = true;
  610. }
  611. }
  612. private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
  613. {
  614. }
  615. /// <summary>
  616. /// THis method gets called when someone pays someone else as a gift.
  617. /// </summary>
  618. /// <param name="osender"></param>
  619. /// <param name="e"></param>
  620. private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
  621. {
  622. }
  623. /// <summary>
  624. /// Event Handler for when a root agent becomes a child agent
  625. /// </summary>
  626. /// <param name="avatar"></param>
  627. private void MakeChildAgent(ScenePresence avatar)
  628. {
  629. }
  630. /// <summary>
  631. /// Event Handler for when the client logs out.
  632. /// </summary>
  633. /// <param name="AgentId"></param>
  634. private void ClientLoggedOut(UUID AgentId, Scene scene)
  635. {
  636. }
  637. /// <summary>
  638. /// Call this when the client disconnects.
  639. /// </summary>
  640. /// <param name="client"></param>
  641. public void ClientClosed(IClientAPI client)
  642. {
  643. ClientClosed(client.AgentId, null);
  644. }
  645. /// <summary>
  646. /// Event Handler for when an Avatar enters one of the parcels in the simulator.
  647. /// </summary>
  648. /// <param name="avatar"></param>
  649. /// <param name="localLandID"></param>
  650. /// <param name="regionID"></param>
  651. private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
  652. {
  653. //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
  654. }
  655. public int GetBalance(IClientAPI client)
  656. {
  657. return 0;
  658. }
  659. // Please do not refactor these to be just one method
  660. // Existing implementations need the distinction
  661. //
  662. public bool UploadCovered(IClientAPI client)
  663. {
  664. return AmountCovered(client, PriceUpload);
  665. }
  666. public bool GroupCreationCovered(IClientAPI client)
  667. {
  668. return AmountCovered(client, PriceGroupCreate);
  669. }
  670. public bool AmountCovered(IClientAPI client, int amount)
  671. {
  672. return true;
  673. }
  674. #endregion
  675. public void ObjectBuy(IClientAPI remoteClient, UUID agentID,
  676. UUID sessionID, UUID groupID, UUID categoryID,
  677. uint localID, byte saleType, int salePrice)
  678. {
  679. if (!m_sellEnabled)
  680. {
  681. remoteClient.SendBlueBoxMessage(UUID.Zero, "", "Buying is not implemented in this version");
  682. return;
  683. }
  684. if (salePrice != 0)
  685. {
  686. remoteClient.SendBlueBoxMessage(UUID.Zero, "", "Buying anything for a price other than zero is not implemented");
  687. return;
  688. }
  689. Scene s = LocateSceneClientIn(remoteClient.AgentId);
  690. SceneObjectPart part = s.GetSceneObjectPart(localID);
  691. if (part == null)
  692. {
  693. remoteClient.SendAgentAlertMessage("Unable to buy now. The object was not found.", false);
  694. return;
  695. }
  696. s.PerformObjectBuy(remoteClient, categoryID, localID, saleType);
  697. }
  698. }
  699. public enum TransactionType : int
  700. {
  701. SystemGenerated = 0,
  702. RegionMoneyRequest = 1,
  703. Gift = 2,
  704. Purchase = 3
  705. }
  706. }