SampleMoneyModule.cs 29 KB

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