1
0

SampleMoneyModule.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. 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. /// Called on startup so the module can be configured.
  103. /// </summary>
  104. /// <param name="config">Configuration source.</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, MoneyTransactionType type, string extraData)
  163. {
  164. }
  165. public void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type)
  166. {
  167. }
  168. public void ApplyUploadCharge(UUID agentID, int amount, string text)
  169. {
  170. }
  171. public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount)
  172. {
  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. /// <param name="scene"></param>
  197. /// <param name="startupConfig"></param>
  198. /// <param name="config"></param>
  199. private void ReadConfigAndPopulate(IConfig startupConfig, string config)
  200. {
  201. if (config == "Startup" && startupConfig != null)
  202. {
  203. m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
  204. }
  205. if (config == "Economy" && startupConfig != null)
  206. {
  207. PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
  208. PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
  209. PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4);
  210. PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4);
  211. PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1);
  212. PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f);
  213. PriceUpload = startupConfig.GetInt("PriceUpload", 0);
  214. PriceRentLight = startupConfig.GetInt("PriceRentLight", 5);
  215. TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2);
  216. TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f);
  217. EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1);
  218. PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1);
  219. PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10);
  220. PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
  221. PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
  222. m_sellEnabled = startupConfig.GetBoolean("SellEnabled", false);
  223. }
  224. }
  225. private void GetClientFunds(IClientAPI client)
  226. {
  227. CheckExistAndRefreshFunds(client.AgentId);
  228. }
  229. /// <summary>
  230. /// New Client Event Handler
  231. /// </summary>
  232. /// <param name="client"></param>
  233. private void OnNewClient(IClientAPI client)
  234. {
  235. GetClientFunds(client);
  236. // Subscribe to Money messages
  237. client.OnEconomyDataRequest += EconomyDataRequestHandler;
  238. client.OnMoneyBalanceRequest += SendMoneyBalance;
  239. client.OnRequestPayPrice += requestPayPrice;
  240. client.OnObjectBuy += ObjectBuy;
  241. client.OnLogout += ClientClosed;
  242. }
  243. /// <summary>
  244. /// Transfer money
  245. /// </summary>
  246. /// <param name="Sender"></param>
  247. /// <param name="Receiver"></param>
  248. /// <param name="amount"></param>
  249. /// <returns></returns>
  250. private bool doMoneyTransfer(UUID Sender, UUID Receiver, int amount, int transactiontype, string description)
  251. {
  252. bool result = true;
  253. return result;
  254. }
  255. /// <summary>
  256. /// Sends the the stored money balance to the client
  257. /// </summary>
  258. /// <param name="client"></param>
  259. /// <param name="agentID"></param>
  260. /// <param name="SessionID"></param>
  261. /// <param name="TransactionID"></param>
  262. public void SendMoneyBalance(IClientAPI client, UUID agentID, UUID SessionID, UUID TransactionID)
  263. {
  264. if (client.AgentId == agentID && client.SessionId == SessionID)
  265. {
  266. int returnfunds = 0;
  267. try
  268. {
  269. returnfunds = GetFundsForAgentID(agentID);
  270. }
  271. catch (Exception e)
  272. {
  273. client.SendAlertMessage(e.Message + " ");
  274. }
  275. client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds, 0, UUID.Zero, false, UUID.Zero, false, 0, String.Empty);
  276. }
  277. else
  278. {
  279. client.SendAlertMessage("Unable to send your money balance to you!");
  280. }
  281. }
  282. private SceneObjectPart findPrim(UUID objectID)
  283. {
  284. lock (m_scenel)
  285. {
  286. foreach (Scene s in m_scenel.Values)
  287. {
  288. SceneObjectPart part = s.GetSceneObjectPart(objectID);
  289. if (part != null)
  290. {
  291. return part;
  292. }
  293. }
  294. }
  295. return null;
  296. }
  297. private string resolveObjectName(UUID objectID)
  298. {
  299. SceneObjectPart part = findPrim(objectID);
  300. if (part != null)
  301. {
  302. return part.Name;
  303. }
  304. return String.Empty;
  305. }
  306. private string resolveAgentName(UUID agentID)
  307. {
  308. // try avatar username surname
  309. Scene scene = GetRandomScene();
  310. UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, agentID);
  311. if (account != null)
  312. {
  313. string avatarname = account.FirstName + " " + account.LastName;
  314. return avatarname;
  315. }
  316. else
  317. {
  318. m_log.ErrorFormat(
  319. "[MONEY]: Could not resolve user {0}",
  320. agentID);
  321. }
  322. return String.Empty;
  323. }
  324. private void BalanceUpdate(UUID senderID, UUID receiverID, bool transactionresult, string description)
  325. {
  326. IClientAPI sender = LocateClientObject(senderID);
  327. IClientAPI receiver = LocateClientObject(receiverID);
  328. if (senderID != receiverID)
  329. {
  330. if (sender != null)
  331. {
  332. sender.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(senderID), 0, UUID.Zero, false, UUID.Zero, false, 0, String.Empty);
  333. }
  334. if (receiver != null)
  335. {
  336. receiver.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(receiverID), 0, UUID.Zero, false, UUID.Zero, false, 0, String.Empty);
  337. }
  338. }
  339. }
  340. /// <summary>
  341. /// XMLRPC handler to send alert message and sound to client
  342. /// </summary>
  343. public XmlRpcResponse UserAlert(XmlRpcRequest request, IPEndPoint remoteClient)
  344. {
  345. XmlRpcResponse ret = new XmlRpcResponse();
  346. Hashtable retparam = new Hashtable();
  347. Hashtable requestData = (Hashtable) request.Params[0];
  348. UUID agentId;
  349. UUID soundId;
  350. UUID regionId;
  351. UUID.TryParse((string) requestData["agentId"], out agentId);
  352. UUID.TryParse((string) requestData["soundId"], out soundId);
  353. UUID.TryParse((string) requestData["regionId"], out regionId);
  354. string text = (string) requestData["text"];
  355. string secret = (string) requestData["secret"];
  356. Scene userScene = GetSceneByUUID(regionId);
  357. if (userScene != null)
  358. {
  359. if (userScene.RegionInfo.regionSecret == secret)
  360. {
  361. IClientAPI client = LocateClientObject(agentId);
  362. if (client != null)
  363. {
  364. if (soundId != UUID.Zero)
  365. client.SendPlayAttachedSound(soundId, UUID.Zero, UUID.Zero, 1.0f, 0);
  366. client.SendBlueBoxMessage(UUID.Zero, "", text);
  367. retparam.Add("success", true);
  368. }
  369. else
  370. {
  371. retparam.Add("success", false);
  372. }
  373. }
  374. else
  375. {
  376. retparam.Add("success", false);
  377. }
  378. }
  379. ret.Value = retparam;
  380. return ret;
  381. }
  382. # region Standalone box enablers only
  383. public XmlRpcResponse quote_func(XmlRpcRequest request, IPEndPoint remoteClient)
  384. {
  385. // Hashtable requestData = (Hashtable) request.Params[0];
  386. // UUID agentId = UUID.Zero;
  387. int amount = 0;
  388. Hashtable quoteResponse = new Hashtable();
  389. XmlRpcResponse returnval = new XmlRpcResponse();
  390. Hashtable currencyResponse = new Hashtable();
  391. currencyResponse.Add("estimatedCost", 0);
  392. currencyResponse.Add("currencyBuy", amount);
  393. quoteResponse.Add("success", true);
  394. quoteResponse.Add("currency", currencyResponse);
  395. quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
  396. returnval.Value = quoteResponse;
  397. return returnval;
  398. }
  399. public XmlRpcResponse buy_func(XmlRpcRequest request, IPEndPoint remoteClient)
  400. {
  401. // Hashtable requestData = (Hashtable) request.Params[0];
  402. // UUID agentId = UUID.Zero;
  403. // int amount = 0;
  404. XmlRpcResponse returnval = new XmlRpcResponse();
  405. Hashtable returnresp = new Hashtable();
  406. returnresp.Add("success", true);
  407. returnval.Value = returnresp;
  408. return returnval;
  409. }
  410. public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request, IPEndPoint remoteClient)
  411. {
  412. XmlRpcResponse ret = new XmlRpcResponse();
  413. Hashtable retparam = new Hashtable();
  414. Hashtable membershiplevels = new Hashtable();
  415. ArrayList levels = new ArrayList();
  416. Hashtable level = new Hashtable();
  417. level.Add("id", "00000000-0000-0000-0000-000000000000");
  418. level.Add("description", "some level");
  419. levels.Add(level);
  420. //membershiplevels.Add("levels",levels);
  421. Hashtable landuse = new Hashtable();
  422. landuse.Add("upgrade", false);
  423. landuse.Add("action", "http://invaliddomaininvalid.com/");
  424. Hashtable currency = new Hashtable();
  425. currency.Add("estimatedCost", 0);
  426. Hashtable membership = new Hashtable();
  427. membershiplevels.Add("upgrade", false);
  428. membershiplevels.Add("action", "http://invaliddomaininvalid.com/");
  429. membershiplevels.Add("levels", membershiplevels);
  430. retparam.Add("success", true);
  431. retparam.Add("currency", currency);
  432. retparam.Add("membership", membership);
  433. retparam.Add("landuse", landuse);
  434. retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf");
  435. ret.Value = retparam;
  436. return ret;
  437. }
  438. public XmlRpcResponse landBuy_func(XmlRpcRequest request, IPEndPoint remoteClient)
  439. {
  440. XmlRpcResponse ret = new XmlRpcResponse();
  441. Hashtable retparam = new Hashtable();
  442. // Hashtable requestData = (Hashtable) request.Params[0];
  443. // UUID agentId = UUID.Zero;
  444. // int amount = 0;
  445. retparam.Add("success", true);
  446. ret.Value = retparam;
  447. return ret;
  448. }
  449. #endregion
  450. #region local Fund Management
  451. /// <summary>
  452. /// Ensures that the agent accounting data is set up in this instance.
  453. /// </summary>
  454. /// <param name="agentID"></param>
  455. private void CheckExistAndRefreshFunds(UUID agentID)
  456. {
  457. }
  458. /// <summary>
  459. /// Gets the amount of Funds for an agent
  460. /// </summary>
  461. /// <param name="AgentID"></param>
  462. /// <returns></returns>
  463. private int GetFundsForAgentID(UUID AgentID)
  464. {
  465. int returnfunds = 0;
  466. return returnfunds;
  467. }
  468. // private void SetLocalFundsForAgentID(UUID AgentID, int amount)
  469. // {
  470. // }
  471. #endregion
  472. #region Utility Helpers
  473. /// <summary>
  474. /// Locates a IClientAPI for the client specified
  475. /// </summary>
  476. /// <param name="AgentID"></param>
  477. /// <returns></returns>
  478. private IClientAPI LocateClientObject(UUID AgentID)
  479. {
  480. ScenePresence tPresence = null;
  481. IClientAPI rclient = null;
  482. lock (m_scenel)
  483. {
  484. foreach (Scene _scene in m_scenel.Values)
  485. {
  486. tPresence = _scene.GetScenePresence(AgentID);
  487. if (tPresence != null)
  488. {
  489. if (!tPresence.IsChildAgent)
  490. {
  491. rclient = tPresence.ControllingClient;
  492. }
  493. }
  494. if (rclient != null)
  495. {
  496. return rclient;
  497. }
  498. }
  499. }
  500. return null;
  501. }
  502. private Scene LocateSceneClientIn(UUID AgentId)
  503. {
  504. lock (m_scenel)
  505. {
  506. foreach (Scene _scene in m_scenel.Values)
  507. {
  508. ScenePresence tPresence = _scene.GetScenePresence(AgentId);
  509. if (tPresence != null)
  510. {
  511. if (!tPresence.IsChildAgent)
  512. {
  513. return _scene;
  514. }
  515. }
  516. }
  517. }
  518. return null;
  519. }
  520. /// <summary>
  521. /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
  522. /// </summary>
  523. /// <returns></returns>
  524. public Scene GetRandomScene()
  525. {
  526. lock (m_scenel)
  527. {
  528. foreach (Scene rs in m_scenel.Values)
  529. return rs;
  530. }
  531. return null;
  532. }
  533. /// <summary>
  534. /// Utility function to get a Scene by RegionID in a module
  535. /// </summary>
  536. /// <param name="RegionID"></param>
  537. /// <returns></returns>
  538. public Scene GetSceneByUUID(UUID RegionID)
  539. {
  540. lock (m_scenel)
  541. {
  542. foreach (Scene rs in m_scenel.Values)
  543. {
  544. if (rs.RegionInfo.originRegionID == RegionID)
  545. {
  546. return rs;
  547. }
  548. }
  549. }
  550. return null;
  551. }
  552. #endregion
  553. #region event Handlers
  554. public void requestPayPrice(IClientAPI client, UUID objectID)
  555. {
  556. Scene scene = LocateSceneClientIn(client.AgentId);
  557. if (scene == null)
  558. return;
  559. SceneObjectPart task = scene.GetSceneObjectPart(objectID);
  560. if (task == null)
  561. return;
  562. SceneObjectGroup group = task.ParentGroup;
  563. SceneObjectPart root = group.RootPart;
  564. client.SendPayPrice(objectID, root.PayPrice);
  565. }
  566. /// <summary>
  567. /// When the client closes the connection we remove their accounting
  568. /// info from memory to free up resources.
  569. /// </summary>
  570. /// <param name="AgentID">UUID of agent</param>
  571. /// <param name="scene">Scene the agent was connected to.</param>
  572. /// <see cref="OpenSim.Region.Framework.Scenes.EventManager.ClientClosed"/>
  573. public void ClientClosed(UUID AgentID, Scene scene)
  574. {
  575. }
  576. /// <summary>
  577. /// Event called Economy Data Request handler.
  578. /// </summary>
  579. /// <param name="agentId"></param>
  580. public void EconomyDataRequestHandler(IClientAPI user)
  581. {
  582. Scene s = (Scene)user.Scene;
  583. user.SendEconomyData(EnergyEfficiency, s.RegionInfo.ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
  584. PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
  585. PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
  586. TeleportMinPrice, TeleportPriceExponent);
  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(UUID agentID, int amount)
  646. {
  647. return true;
  648. }
  649. public bool AmountCovered(UUID agentID, 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. // Implmenting base sale data checking here so the default OpenSimulator implementation isn't useless
  670. // combined with other implementations. We're actually validating that the client is sending the data
  671. // that it should. In theory, the client should already know what to send here because it'll see it when it
  672. // gets the object data. If the data sent by the client doesn't match the object, the viewer probably has an
  673. // old idea of what the object properties are. Viewer developer Hazim informed us that the base module
  674. // didn't check the client sent data against the object do any. Since the base modules are the
  675. // 'crowning glory' examples of good practice..
  676. // Validate that the object exists in the scene the user is in
  677. SceneObjectPart part = s.GetSceneObjectPart(localID);
  678. if (part == null)
  679. {
  680. remoteClient.SendAgentAlertMessage("Unable to buy now. The object was not found.", false);
  681. return;
  682. }
  683. // Validate that the client sent the price that the object is being sold for
  684. if (part.SalePrice != salePrice)
  685. {
  686. remoteClient.SendAgentAlertMessage("Cannot buy at this price. Buy Failed. If you continue to get this relog.", false);
  687. return;
  688. }
  689. // Validate that the client sent the proper sale type the object has set
  690. if (part.ObjectSaleType != saleType)
  691. {
  692. remoteClient.SendAgentAlertMessage("Cannot buy this way. Buy Failed. If you continue to get this relog.", false);
  693. return;
  694. }
  695. IBuySellModule module = s.RequestModuleInterface<IBuySellModule>();
  696. if (module != null)
  697. module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice);
  698. }
  699. }
  700. public enum TransactionType : int
  701. {
  702. SystemGenerated = 0,
  703. RegionMoneyRequest = 1,
  704. Gift = 2,
  705. Purchase = 3
  706. }
  707. }