1
0

SampleMoneyModule.cs 30 KB

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