SampleMoneyModule.cs 28 KB

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