1
0

SampleMoneyModule.cs 30 KB

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