SampleMoneyModule.cs 30 KB

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