1
0

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