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