diff options
author | Adam Frisby | 2008-04-30 21:16:36 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:16:36 +0000 |
commit | f5c312bc3c2567449c7268a54a08a54119f58d53 (patch) | |
tree | 424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz |
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.)
* This should be moved into a seperate project file.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs (renamed from OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs) | 2981 |
1 files changed, 1491 insertions, 1490 deletions
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs index 3a8906e..0e058ec 100644 --- a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs | |||
@@ -1,1490 +1,1491 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | 31 | using System.Net; |
32 | using System.Net.Sockets; | 32 | using System.Net.Sockets; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using System.Xml; | 34 | using System.Xml; |
35 | using libsecondlife; | 35 | using libsecondlife; |
36 | using log4net; | 36 | using log4net; |
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | using Nwc.XmlRpc; | 38 | using Nwc.XmlRpc; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using OpenSim.Region.Environment.Interfaces; | 40 | using OpenSim.Region.Environment.Interfaces; |
41 | using OpenSim.Region.Environment.Scenes; | 41 | using OpenSim.Region.Environment.Scenes; |
42 | 42 | ||
43 | namespace OpenSim.Region.Environment.Modules | 43 | namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney |
44 | { | 44 | { |
45 | /// <summary> | 45 | /// <summary> |
46 | /// Demo Economy/Money Module. This is not a production quality money/economy module! | 46 | /// Demo Economy/Money Module. This is not a production quality money/economy module! |
47 | /// This is a demo for you to use when making one that works for you. | 47 | /// This is a demo for you to use when making one that works for you. |
48 | /// // To use the following you need to add: | 48 | /// // To use the following you need to add: |
49 | /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> | 49 | /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> |
50 | /// to the command line parameters you use to start up your client | 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/ | 51 | /// This commonly looks like -helperuri http://127.0.0.1:9000/ |
52 | /// | 52 | /// |
53 | /// Centralized grid structure example using OpenSimWi Redux revision 9+ | 53 | /// Centralized grid structure example using OpenSimWi Redux revision 9+ |
54 | /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux | 54 | /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux |
55 | /// </summary> | 55 | /// </summary> |
56 | 56 | ||
57 | public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount); | 57 | public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount); |
58 | 58 | ||
59 | public interface IMoneyModule : IRegionModule | 59 | public interface IMoneyModule : IRegionModule |
60 | { | 60 | { |
61 | bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount); | 61 | bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount); |
62 | 62 | ||
63 | event ObjectPaid OnObjectPaid; | 63 | event ObjectPaid OnObjectPaid; |
64 | } | 64 | } |
65 | 65 | ||
66 | public class BetaGridLikeMoneyModule: IMoneyModule | 66 | public class SampleMoneyModule : IMoneyModule |
67 | { | 67 | { |
68 | public event ObjectPaid OnObjectPaid; | 68 | public event ObjectPaid OnObjectPaid; |
69 | 69 | ||
70 | private ObjectPaid handerOnObjectPaid; | 70 | private ObjectPaid handerOnObjectPaid; |
71 | 71 | ||
72 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 72 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
73 | 73 | ||
74 | /// <summary> | 74 | /// <summary> |
75 | /// Region UUIDS indexed by AgentID | 75 | /// Region UUIDS indexed by AgentID |
76 | /// </summary> | 76 | /// </summary> |
77 | Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>(); | 77 | Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>(); |
78 | 78 | ||
79 | /// <summary> | 79 | /// <summary> |
80 | /// Scenes by Region Handle | 80 | /// Scenes by Region Handle |
81 | /// </summary> | 81 | /// </summary> |
82 | private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>(); | 82 | private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>(); |
83 | 83 | ||
84 | private IConfigSource m_gConfig; | 84 | private IConfigSource m_gConfig; |
85 | 85 | ||
86 | private bool m_keepMoneyAcrossLogins = true; | 86 | private bool m_keepMoneyAcrossLogins = true; |
87 | 87 | ||
88 | private int m_minFundsBeforeRefresh = 100; | 88 | private int m_minFundsBeforeRefresh = 100; |
89 | 89 | ||
90 | private int m_stipend = 1000; | 90 | private int m_stipend = 1000; |
91 | 91 | ||
92 | private bool m_enabled = true; | 92 | private bool m_enabled = true; |
93 | 93 | ||
94 | private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); | 94 | private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); |
95 | 95 | ||
96 | private bool gridmode = false; | 96 | private bool gridmode = false; |
97 | private Scene XMLRPCHandler; | 97 | private Scene XMLRPCHandler; |
98 | private float EnergyEfficiency = 0f; | 98 | private float EnergyEfficiency = 0f; |
99 | private int ObjectCapacity = 45000; | 99 | private int ObjectCapacity = 45000; |
100 | private int ObjectCount = 0; | 100 | private int ObjectCount = 0; |
101 | private int PriceEnergyUnit = 0; | 101 | private int PriceEnergyUnit = 0; |
102 | private int PriceGroupCreate = 0; | 102 | private int PriceGroupCreate = 0; |
103 | private int PriceObjectClaim = 0; | 103 | private int PriceObjectClaim = 0; |
104 | private float PriceObjectRent = 0f; | 104 | private float PriceObjectRent = 0f; |
105 | private float PriceObjectScaleFactor = 0f; | 105 | private float PriceObjectScaleFactor = 0f; |
106 | private int PriceParcelClaim = 0; | 106 | private int PriceParcelClaim = 0; |
107 | private float PriceParcelClaimFactor = 0f; | 107 | private float PriceParcelClaimFactor = 0f; |
108 | private int PriceParcelRent = 0; | 108 | private int PriceParcelRent = 0; |
109 | private int PricePublicObjectDecay = 0; | 109 | private int PricePublicObjectDecay = 0; |
110 | private int PricePublicObjectDelete = 0; | 110 | private int PricePublicObjectDelete = 0; |
111 | private int PriceRentLight = 0; | 111 | private int PriceRentLight = 0; |
112 | private int PriceUpload = 0; | 112 | private int PriceUpload = 0; |
113 | private int TeleportMinPrice = 0; | 113 | private int TeleportMinPrice = 0; |
114 | private int UserLevelPaysFees = 2; | 114 | private int UserLevelPaysFees = 2; |
115 | private string m_MoneyAddress = String.Empty; | 115 | private string m_MoneyAddress = String.Empty; |
116 | private string m_LandAddress = String.Empty; | 116 | private string m_LandAddress = String.Empty; |
117 | 117 | ||
118 | float TeleportPriceExponent = 0f; | 118 | float TeleportPriceExponent = 0f; |
119 | 119 | ||
120 | /// <summary> | 120 | /// <summary> |
121 | /// Where Stipends come from and Fees go to. | 121 | /// Where Stipends come from and Fees go to. |
122 | /// </summary> | 122 | /// </summary> |
123 | LLUUID EconomyBaseAccount = LLUUID.Zero; | 123 | LLUUID EconomyBaseAccount = LLUUID.Zero; |
124 | 124 | ||
125 | /// <summary> | 125 | /// <summary> |
126 | /// Startup | 126 | /// Startup |
127 | /// </summary> | 127 | /// </summary> |
128 | /// <param name="scene"></param> | 128 | /// <param name="scene"></param> |
129 | /// <param name="config"></param> | 129 | /// <param name="config"></param> |
130 | public void Initialise(Scene scene, IConfigSource config) | 130 | public void Initialise(Scene scene, IConfigSource config) |
131 | { | 131 | { |
132 | m_gConfig = config; | 132 | m_gConfig = config; |
133 | 133 | ||
134 | IConfig startupConfig = m_gConfig.Configs["Startup"]; | 134 | IConfig startupConfig = m_gConfig.Configs["Startup"]; |
135 | IConfig economyConfig = m_gConfig.Configs["Economy"]; | 135 | IConfig economyConfig = m_gConfig.Configs["Economy"]; |
136 | 136 | ||
137 | scene.RegisterModuleInterface<IMoneyModule>(this); | 137 | scene.RegisterModuleInterface<IMoneyModule>(this); |
138 | 138 | ||
139 | ReadConfigAndPopulate(scene, startupConfig, "Startup"); | 139 | ReadConfigAndPopulate(scene, startupConfig, "Startup"); |
140 | ReadConfigAndPopulate(scene, economyConfig, "Economy"); | 140 | ReadConfigAndPopulate(scene, economyConfig, "Economy"); |
141 | 141 | ||
142 | if (m_enabled) | 142 | if (m_enabled) |
143 | { | 143 | { |
144 | lock (m_scenel) | 144 | lock (m_scenel) |
145 | { | 145 | { |
146 | if (m_scenel.Count == 0) | 146 | if (m_scenel.Count == 0) |
147 | { | 147 | { |
148 | XMLRPCHandler = scene; | 148 | XMLRPCHandler = scene; |
149 | 149 | ||
150 | // To use the following you need to add: | 150 | // To use the following you need to add: |
151 | // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> | 151 | // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> |
152 | // to the command line parameters you use to start up your client | 152 | // to the command line parameters you use to start up your client |
153 | // This commonly looks like -helperuri http://127.0.0.1:9000/ | 153 | // This commonly looks like -helperuri http://127.0.0.1:9000/ |
154 | 154 | ||
155 | if (m_MoneyAddress.Length > 0) | 155 | if (m_MoneyAddress.Length > 0) |
156 | { | 156 | { |
157 | // Centralized grid structure using OpenSimWi Redux revision 9+ | 157 | // Centralized grid structure using OpenSimWi Redux revision 9+ |
158 | // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux | 158 | // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux |
159 | scene.AddXmlRPCHandler("balanceUpdateRequest", GridMoneyUpdate); | 159 | scene.AddXmlRPCHandler("balanceUpdateRequest", GridMoneyUpdate); |
160 | scene.AddXmlRPCHandler("userAlert", UserAlert); | 160 | scene.AddXmlRPCHandler("userAlert", UserAlert); |
161 | } | 161 | } |
162 | else | 162 | else |
163 | { | 163 | { |
164 | // Local Server.. enables functionality only. | 164 | // Local Server.. enables functionality only. |
165 | scene.AddXmlRPCHandler("getCurrencyQuote", quote_func); | 165 | scene.AddXmlRPCHandler("getCurrencyQuote", quote_func); |
166 | scene.AddXmlRPCHandler("buyCurrency", buy_func); | 166 | scene.AddXmlRPCHandler("buyCurrency", buy_func); |
167 | scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func); | 167 | scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func); |
168 | scene.AddXmlRPCHandler("buyLandPrep", landBuy_func); | 168 | scene.AddXmlRPCHandler("buyLandPrep", landBuy_func); |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | } | 172 | } |
173 | 173 | ||
174 | if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) | 174 | if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) |
175 | { | 175 | { |
176 | m_scenel[scene.RegionInfo.RegionHandle] = scene; | 176 | m_scenel[scene.RegionInfo.RegionHandle] = scene; |
177 | } | 177 | } |
178 | else | 178 | else |
179 | { | 179 | { |
180 | m_scenel.Add(scene.RegionInfo.RegionHandle, scene); | 180 | m_scenel.Add(scene.RegionInfo.RegionHandle, scene); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | scene.EventManager.OnNewClient += OnNewClient; | 184 | scene.EventManager.OnNewClient += OnNewClient; |
185 | scene.EventManager.OnMoneyTransfer += MoneyTransferAction; | 185 | scene.EventManager.OnMoneyTransfer += MoneyTransferAction; |
186 | scene.EventManager.OnClientClosed += ClientClosed; | 186 | scene.EventManager.OnClientClosed += ClientClosed; |
187 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | 187 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; |
188 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | 188 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; |
189 | scene.EventManager.OnClientClosed += ClientLoggedOut; | 189 | scene.EventManager.OnClientClosed += ClientLoggedOut; |
190 | scene.EventManager.OnValidateLandBuy += ValidateLandBuy; | 190 | scene.EventManager.OnValidateLandBuy += ValidateLandBuy; |
191 | scene.EventManager.OnLandBuy += processLandBuy; | 191 | scene.EventManager.OnLandBuy += processLandBuy; |
192 | 192 | ||
193 | } | 193 | } |
194 | } | 194 | } |
195 | /// <summary> | 195 | /// <summary> |
196 | /// Parse Configuration | 196 | /// Parse Configuration |
197 | /// </summary> | 197 | /// </summary> |
198 | /// <param name="scene"></param> | 198 | /// <param name="scene"></param> |
199 | /// <param name="startupConfig"></param> | 199 | /// <param name="startupConfig"></param> |
200 | /// <param name="config"></param> | 200 | /// <param name="config"></param> |
201 | private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config) | 201 | private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config) |
202 | { | 202 | { |
203 | if (config == "Startup" && startupConfig != null) | 203 | if (config == "Startup" && startupConfig != null) |
204 | { | 204 | { |
205 | gridmode = startupConfig.GetBoolean("gridmode", false); | 205 | gridmode = startupConfig.GetBoolean("gridmode", false); |
206 | m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule"); | 206 | m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule"); |
207 | } | 207 | } |
208 | 208 | ||
209 | if (config == "Economy" && startupConfig != null) | 209 | if (config == "Economy" && startupConfig != null) |
210 | { | 210 | { |
211 | ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000); | 211 | ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000); |
212 | PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100); | 212 | PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100); |
213 | PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10); | 213 | PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10); |
214 | PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4); | 214 | PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4); |
215 | PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4); | 215 | PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4); |
216 | PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1); | 216 | PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1); |
217 | PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f); | 217 | PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f); |
218 | PriceUpload = startupConfig.GetInt("PriceUpload", 0); | 218 | PriceUpload = startupConfig.GetInt("PriceUpload", 0); |
219 | PriceRentLight = startupConfig.GetInt("PriceRentLight", 5); | 219 | PriceRentLight = startupConfig.GetInt("PriceRentLight", 5); |
220 | TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2); | 220 | TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2); |
221 | TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f); | 221 | TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f); |
222 | EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1); | 222 | EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1); |
223 | PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1); | 223 | PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1); |
224 | PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10); | 224 | PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10); |
225 | PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1); | 225 | PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1); |
226 | PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1); | 226 | PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1); |
227 | string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString()); | 227 | string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString()); |
228 | Helpers.TryParse(EBA,out EconomyBaseAccount); | 228 | Helpers.TryParse(EBA,out EconomyBaseAccount); |
229 | 229 | ||
230 | UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); | 230 | UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); |
231 | m_stipend = startupConfig.GetInt("UserStipend", 500); | 231 | m_stipend = startupConfig.GetInt("UserStipend", 500); |
232 | m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10); | 232 | m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10); |
233 | m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true); | 233 | m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true); |
234 | m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty); | 234 | m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty); |
235 | m_LandAddress = startupConfig.GetString("LandServer", String.Empty); | 235 | m_LandAddress = startupConfig.GetString("LandServer", String.Empty); |
236 | } | 236 | } |
237 | 237 | ||
238 | // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. | 238 | // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. |
239 | scene.SetObjectCapacity(ObjectCapacity); | 239 | scene.SetObjectCapacity(ObjectCapacity); |
240 | } | 240 | } |
241 | 241 | ||
242 | /// <summary> | 242 | /// <summary> |
243 | /// New Client Event Handler | 243 | /// New Client Event Handler |
244 | /// </summary> | 244 | /// </summary> |
245 | /// <param name="client"></param> | 245 | /// <param name="client"></param> |
246 | private void OnNewClient(IClientAPI client) | 246 | private void OnNewClient(IClientAPI client) |
247 | { | 247 | { |
248 | // Here we check if we're in grid mode | 248 | // Here we check if we're in grid mode |
249 | // I imagine that the 'check balance' | 249 | // I imagine that the 'check balance' |
250 | // function for the client should be here or shortly after | 250 | // function for the client should be here or shortly after |
251 | 251 | ||
252 | if (gridmode) | 252 | if (gridmode) |
253 | { | 253 | { |
254 | if (m_MoneyAddress.Length == 0) | 254 | if (m_MoneyAddress.Length == 0) |
255 | { | 255 | { |
256 | 256 | ||
257 | CheckExistAndRefreshFunds(client.AgentId); | 257 | CheckExistAndRefreshFunds(client.AgentId); |
258 | } | 258 | } |
259 | else | 259 | else |
260 | { | 260 | { |
261 | bool childYN = true; | 261 | bool childYN = true; |
262 | ScenePresence agent = null; | 262 | ScenePresence agent = null; |
263 | //client.SecureSessionId; | 263 | //client.SecureSessionId; |
264 | Scene s = LocateSceneClientIn(client.AgentId); | 264 | Scene s = LocateSceneClientIn(client.AgentId); |
265 | if (s != null) | 265 | if (s != null) |
266 | { | 266 | { |
267 | agent = s.GetScenePresence(client.AgentId); | 267 | agent = s.GetScenePresence(client.AgentId); |
268 | if (agent != null) | 268 | if (agent != null) |
269 | childYN = agent.IsChildAgent; | 269 | childYN = agent.IsChildAgent; |
270 | } | 270 | } |
271 | if (s != null && agent != null && childYN == false) | 271 | if (s != null && agent != null && childYN == false) |
272 | { | 272 | { |
273 | //s.RegionInfo.RegionHandle; | 273 | //s.RegionInfo.RegionHandle; |
274 | LLUUID agentID = LLUUID.Zero; | 274 | LLUUID agentID = LLUUID.Zero; |
275 | int funds = 0; | 275 | int funds = 0; |
276 | 276 | ||
277 | Hashtable hbinfo = GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); | 277 | Hashtable hbinfo = GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); |
278 | if ((bool)hbinfo["success"] == true) | 278 | if ((bool)hbinfo["success"] == true) |
279 | { | 279 | { |
280 | 280 | ||
281 | Helpers.TryParse((string)hbinfo["agentId"], out agentID); | 281 | Helpers.TryParse((string)hbinfo["agentId"], out agentID); |
282 | try | 282 | try |
283 | { | 283 | { |
284 | funds = (Int32)hbinfo["funds"]; | 284 | funds = (Int32)hbinfo["funds"]; |
285 | } | 285 | } |
286 | catch (ArgumentException) | 286 | catch (ArgumentException) |
287 | { | 287 | { |
288 | } | 288 | } |
289 | catch (FormatException) | 289 | catch (FormatException) |
290 | { | 290 | { |
291 | } | 291 | } |
292 | catch (OverflowException) | 292 | catch (OverflowException) |
293 | { | 293 | { |
294 | m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID); | 294 | m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID); |
295 | client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); | 295 | client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); |
296 | } | 296 | } |
297 | catch (InvalidCastException) | 297 | catch (InvalidCastException) |
298 | { | 298 | { |
299 | funds = 0; | 299 | funds = 0; |
300 | } | 300 | } |
301 | 301 | ||
302 | m_KnownClientFunds[agentID] = funds; | 302 | m_KnownClientFunds[agentID] = funds; |
303 | } | 303 | } |
304 | else | 304 | else |
305 | { | 305 | { |
306 | m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, (string)hbinfo["errorMessage"]); | 306 | m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, (string)hbinfo["errorMessage"]); |
307 | client.SendAlertMessage((string)hbinfo["errorMessage"]); | 307 | client.SendAlertMessage((string)hbinfo["errorMessage"]); |
308 | } | 308 | } |
309 | SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero); | 309 | SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero); |
310 | 310 | ||
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | } | 314 | } |
315 | else | 315 | else |
316 | { | 316 | { |
317 | CheckExistAndRefreshFunds(client.AgentId); | 317 | CheckExistAndRefreshFunds(client.AgentId); |
318 | } | 318 | } |
319 | 319 | ||
320 | // Subscribe to Money messages | 320 | // Subscribe to Money messages |
321 | client.OnEconomyDataRequest += EconomyDataRequestHandler; | 321 | client.OnEconomyDataRequest += EconomyDataRequestHandler; |
322 | client.OnMoneyBalanceRequest += SendMoneyBalance; | 322 | client.OnMoneyBalanceRequest += SendMoneyBalance; |
323 | client.OnRequestPayPrice += requestPayPrice; | 323 | client.OnRequestPayPrice += requestPayPrice; |
324 | client.OnLogout += ClientClosed; | 324 | client.OnLogout += ClientClosed; |
325 | 325 | ||
326 | 326 | ||
327 | } | 327 | } |
328 | 328 | ||
329 | #region event Handlers | 329 | #region event Handlers |
330 | 330 | ||
331 | public void requestPayPrice(IClientAPI client, LLUUID objectID) | 331 | public void requestPayPrice(IClientAPI client, LLUUID objectID) |
332 | { | 332 | { |
333 | Scene scene=LocateSceneClientIn(client.AgentId); | 333 | Scene scene=LocateSceneClientIn(client.AgentId); |
334 | if(scene == null) | 334 | if(scene == null) |
335 | return; | 335 | return; |
336 | 336 | ||
337 | SceneObjectPart task=scene.GetSceneObjectPart(objectID); | 337 | SceneObjectPart task=scene.GetSceneObjectPart(objectID); |
338 | if(task == null) | 338 | if(task == null) |
339 | return; | 339 | return; |
340 | SceneObjectGroup group=task.ParentGroup; | 340 | SceneObjectGroup group=task.ParentGroup; |
341 | SceneObjectPart root=group.RootPart; | 341 | SceneObjectPart root=group.RootPart; |
342 | 342 | ||
343 | client.SendPayPrice(objectID, root.PayPrice); | 343 | client.SendPayPrice(objectID, root.PayPrice); |
344 | } | 344 | } |
345 | 345 | ||
346 | /// <summary> | 346 | /// <summary> |
347 | /// When the client closes the connection we remove their accounting info from memory to free up resources. | 347 | /// When the client closes the connection we remove their accounting info from memory to free up resources. |
348 | /// </summary> | 348 | /// </summary> |
349 | /// <param name="AgentID"></param> | 349 | /// <param name="AgentID"></param> |
350 | public void ClientClosed(LLUUID AgentID) | 350 | public void ClientClosed(LLUUID AgentID) |
351 | { | 351 | { |
352 | lock (m_KnownClientFunds) | 352 | lock (m_KnownClientFunds) |
353 | { | 353 | { |
354 | if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0) | 354 | if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0) |
355 | { | 355 | { |
356 | } | 356 | } |
357 | else | 357 | else |
358 | { | 358 | { |
359 | m_KnownClientFunds.Remove(AgentID); | 359 | m_KnownClientFunds.Remove(AgentID); |
360 | } | 360 | } |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | /// <summary> | 364 | /// <summary> |
365 | /// Event called Economy Data Request handler. | 365 | /// Event called Economy Data Request handler. |
366 | /// </summary> | 366 | /// </summary> |
367 | /// <param name="agentId"></param> | 367 | /// <param name="agentId"></param> |
368 | public void EconomyDataRequestHandler(LLUUID agentId) | 368 | public void EconomyDataRequestHandler(LLUUID agentId) |
369 | { | 369 | { |
370 | IClientAPI user = LocateClientObject(agentId); | 370 | IClientAPI user = LocateClientObject(agentId); |
371 | 371 | ||
372 | if (user != null) | 372 | if (user != null) |
373 | { | 373 | { |
374 | user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate, | 374 | user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate, |
375 | PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor, | 375 | PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor, |
376 | PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload, | 376 | PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload, |
377 | TeleportMinPrice, TeleportPriceExponent); | 377 | TeleportMinPrice, TeleportPriceExponent); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | private void ValidateLandBuy (Object osender, EventManager.LandBuyArgs e) | 381 | private void ValidateLandBuy (Object osender, EventManager.LandBuyArgs e) |
382 | { | 382 | { |
383 | if (m_MoneyAddress.Length == 0) | 383 | if (m_MoneyAddress.Length == 0) |
384 | { | 384 | { |
385 | lock (m_KnownClientFunds) | 385 | lock (m_KnownClientFunds) |
386 | { | 386 | { |
387 | if (m_KnownClientFunds.ContainsKey(e.agentId)) | 387 | if (m_KnownClientFunds.ContainsKey(e.agentId)) |
388 | { | 388 | { |
389 | // Does the sender have enough funds to give? | 389 | // Does the sender have enough funds to give? |
390 | if (m_KnownClientFunds[e.agentId] >= e.parcelPrice) | 390 | if (m_KnownClientFunds[e.agentId] >= e.parcelPrice) |
391 | { | 391 | { |
392 | lock(e) | 392 | lock(e) |
393 | { | 393 | { |
394 | e.economyValidated=true; | 394 | e.economyValidated=true; |
395 | } | 395 | } |
396 | } | 396 | } |
397 | } | 397 | } |
398 | } | 398 | } |
399 | } | 399 | } |
400 | else | 400 | else |
401 | { | 401 | { |
402 | if(GetRemoteBalance(e.agentId) >= e.parcelPrice) | 402 | if(GetRemoteBalance(e.agentId) >= e.parcelPrice) |
403 | { | 403 | { |
404 | lock(e) | 404 | lock(e) |
405 | { | 405 | { |
406 | e.economyValidated=true; | 406 | e.economyValidated=true; |
407 | } | 407 | } |
408 | } | 408 | } |
409 | } | 409 | } |
410 | } | 410 | } |
411 | 411 | ||
412 | private void processLandBuy(Object osender, EventManager.LandBuyArgs e) | 412 | private void processLandBuy(Object osender, EventManager.LandBuyArgs e) |
413 | { | 413 | { |
414 | lock(e) | 414 | lock(e) |
415 | { | 415 | { |
416 | if(e.economyValidated == true && e.transactionID == 0) | 416 | if(e.economyValidated == true && e.transactionID == 0) |
417 | { | 417 | { |
418 | e.transactionID=Util.UnixTimeSinceEpoch(); | 418 | e.transactionID=Util.UnixTimeSinceEpoch(); |
419 | 419 | ||
420 | if(doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase")) | 420 | if(doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase")) |
421 | { | 421 | { |
422 | lock (e) | 422 | lock (e) |
423 | { | 423 | { |
424 | e.amountDebited = e.parcelPrice; | 424 | e.amountDebited = e.parcelPrice; |
425 | } | 425 | } |
426 | } | 426 | } |
427 | } | 427 | } |
428 | } | 428 | } |
429 | } | 429 | } |
430 | 430 | ||
431 | /// <summary> | 431 | /// <summary> |
432 | /// THis method gets called when someone pays someone else as a gift. | 432 | /// THis method gets called when someone pays someone else as a gift. |
433 | /// </summary> | 433 | /// </summary> |
434 | /// <param name="osender"></param> | 434 | /// <param name="osender"></param> |
435 | /// <param name="e"></param> | 435 | /// <param name="e"></param> |
436 | private void MoneyTransferAction (Object osender, EventManager.MoneyTransferArgs e) | 436 | private void MoneyTransferAction (Object osender, EventManager.MoneyTransferArgs e) |
437 | { | 437 | { |
438 | IClientAPI sender = null; | 438 | IClientAPI sender = null; |
439 | IClientAPI receiver = null; | 439 | IClientAPI receiver = null; |
440 | 440 | ||
441 | if(m_MoneyAddress.Length > 0) // Handled on server | 441 | if(m_MoneyAddress.Length > 0) // Handled on server |
442 | e.description=String.Empty; | 442 | e.description=String.Empty; |
443 | 443 | ||
444 | if(e.transactiontype == 5008) // Object gets paid | 444 | if(e.transactiontype == 5008) // Object gets paid |
445 | { | 445 | { |
446 | sender = LocateClientObject(e.sender); | 446 | sender = LocateClientObject(e.sender); |
447 | if (sender != null) | 447 | if (sender != null) |
448 | { | 448 | { |
449 | SceneObjectPart part=findPrim(e.receiver); | 449 | SceneObjectPart part=findPrim(e.receiver); |
450 | if(part == null) | 450 | if(part == null) |
451 | return; | 451 | return; |
452 | 452 | ||
453 | string name=resolveAgentName(part.OwnerID); | 453 | string name=resolveAgentName(part.OwnerID); |
454 | if(name == String.Empty) | 454 | if(name == String.Empty) |
455 | name="(hippos)"; | 455 | name="(hippos)"; |
456 | 456 | ||
457 | receiver = LocateClientObject(part.OwnerID); | 457 | receiver = LocateClientObject(part.OwnerID); |
458 | 458 | ||
459 | string description=String.Format("Paid {0} via object {1}", name, e.description); | 459 | string description=String.Format("Paid {0} via object {1}", name, e.description); |
460 | bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description); | 460 | bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description); |
461 | 461 | ||
462 | if(transactionresult) | 462 | if(transactionresult) |
463 | { | 463 | { |
464 | ObjectPaid handlerOnObjectPaid = OnObjectPaid; | 464 | ObjectPaid handlerOnObjectPaid = OnObjectPaid; |
465 | if(handlerOnObjectPaid != null) | 465 | if(handlerOnObjectPaid != null) |
466 | { | 466 | { |
467 | handlerOnObjectPaid(e.receiver, e.sender, e.amount); | 467 | handlerOnObjectPaid(e.receiver, e.sender, e.amount); |
468 | } | 468 | } |
469 | } | 469 | } |
470 | 470 | ||
471 | if (e.sender != e.receiver) | 471 | if (e.sender != e.receiver) |
472 | { | 472 | { |
473 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); | 473 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); |
474 | } | 474 | } |
475 | if(receiver != null) | 475 | if(receiver != null) |
476 | { | 476 | { |
477 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID)); | 477 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID)); |
478 | } | 478 | } |
479 | } | 479 | } |
480 | return; | 480 | return; |
481 | } | 481 | } |
482 | 482 | ||
483 | sender = LocateClientObject(e.sender); | 483 | sender = LocateClientObject(e.sender); |
484 | if (sender != null) | 484 | if (sender != null) |
485 | { | 485 | { |
486 | receiver = LocateClientObject(e.receiver); | 486 | receiver = LocateClientObject(e.receiver); |
487 | 487 | ||
488 | bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description); | 488 | bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description); |
489 | 489 | ||
490 | if (e.sender != e.receiver) | 490 | if (e.sender != e.receiver) |
491 | { | 491 | { |
492 | if (sender != null) | 492 | if (sender != null) |
493 | { | 493 | { |
494 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); | 494 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); |
495 | } | 495 | } |
496 | } | 496 | } |
497 | 497 | ||
498 | if (receiver != null) | 498 | if (receiver != null) |
499 | { | 499 | { |
500 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver)); | 500 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver)); |
501 | } | 501 | } |
502 | } | 502 | } |
503 | else | 503 | else |
504 | { | 504 | { |
505 | m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString()); | 505 | m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString()); |
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | /// <summary> | 509 | /// <summary> |
510 | /// Event Handler for when a root agent becomes a child agent | 510 | /// Event Handler for when a root agent becomes a child agent |
511 | /// </summary> | 511 | /// </summary> |
512 | /// <param name="avatar"></param> | 512 | /// <param name="avatar"></param> |
513 | private void MakeChildAgent(ScenePresence avatar) | 513 | private void MakeChildAgent(ScenePresence avatar) |
514 | { | 514 | { |
515 | lock (m_rootAgents) | 515 | lock (m_rootAgents) |
516 | { | 516 | { |
517 | if (m_rootAgents.ContainsKey(avatar.UUID)) | 517 | if (m_rootAgents.ContainsKey(avatar.UUID)) |
518 | { | 518 | { |
519 | if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID) | 519 | if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID) |
520 | { | 520 | { |
521 | m_rootAgents.Remove(avatar.UUID); | 521 | m_rootAgents.Remove(avatar.UUID); |
522 | m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); | 522 | m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); |
523 | } | 523 | } |
524 | 524 | ||
525 | } | 525 | } |
526 | } | 526 | } |
527 | 527 | ||
528 | } | 528 | } |
529 | 529 | ||
530 | /// <summary> | 530 | /// <summary> |
531 | /// Event Handler for when the client logs out. | 531 | /// Event Handler for when the client logs out. |
532 | /// </summary> | 532 | /// </summary> |
533 | /// <param name="AgentId"></param> | 533 | /// <param name="AgentId"></param> |
534 | private void ClientLoggedOut(LLUUID AgentId) | 534 | private void ClientLoggedOut(LLUUID AgentId) |
535 | { | 535 | { |
536 | lock (m_rootAgents) | 536 | lock (m_rootAgents) |
537 | { | 537 | { |
538 | if (m_rootAgents.ContainsKey(AgentId)) | 538 | if (m_rootAgents.ContainsKey(AgentId)) |
539 | { | 539 | { |
540 | m_rootAgents.Remove(AgentId); | 540 | m_rootAgents.Remove(AgentId); |
541 | //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out."); | 541 | //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out."); |
542 | } | 542 | } |
543 | } | 543 | } |
544 | } | 544 | } |
545 | 545 | ||
546 | /// <summary> | 546 | /// <summary> |
547 | /// Call this when the client disconnects. | 547 | /// Call this when the client disconnects. |
548 | /// </summary> | 548 | /// </summary> |
549 | /// <param name="client"></param> | 549 | /// <param name="client"></param> |
550 | public void ClientClosed(IClientAPI client) | 550 | public void ClientClosed(IClientAPI client) |
551 | { | 551 | { |
552 | ClientClosed(client.AgentId); | 552 | ClientClosed(client.AgentId); |
553 | } | 553 | } |
554 | 554 | ||
555 | /// <summary> | 555 | /// <summary> |
556 | /// Event Handler for when an Avatar enters one of the parcels in the simulator. | 556 | /// Event Handler for when an Avatar enters one of the parcels in the simulator. |
557 | /// </summary> | 557 | /// </summary> |
558 | /// <param name="avatar"></param> | 558 | /// <param name="avatar"></param> |
559 | /// <param name="localLandID"></param> | 559 | /// <param name="localLandID"></param> |
560 | /// <param name="regionID"></param> | 560 | /// <param name="regionID"></param> |
561 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) | 561 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) |
562 | { | 562 | { |
563 | lock (m_rootAgents) | 563 | lock (m_rootAgents) |
564 | { | 564 | { |
565 | if (m_rootAgents.ContainsKey(avatar.UUID)) | 565 | if (m_rootAgents.ContainsKey(avatar.UUID)) |
566 | { | 566 | { |
567 | if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID]) | 567 | if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID]) |
568 | { | 568 | { |
569 | m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID; | 569 | m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID; |
570 | //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); | 570 | //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); |
571 | // Claim User! my user! Mine mine mine! | 571 | // Claim User! my user! Mine mine mine! |
572 | if (m_MoneyAddress.Length > 0) | 572 | if (m_MoneyAddress.Length > 0) |
573 | { | 573 | { |
574 | Scene RegionItem = GetSceneByUUID(regionID); | 574 | Scene RegionItem = GetSceneByUUID(regionID); |
575 | if (RegionItem != null) | 575 | if (RegionItem != null) |
576 | { | 576 | { |
577 | Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); | 577 | Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); |
578 | if ((bool)hresult["success"] == true) | 578 | if ((bool)hresult["success"] == true) |
579 | { | 579 | { |
580 | int funds = 0; | 580 | int funds = 0; |
581 | try | 581 | try |
582 | { | 582 | { |
583 | funds = (Int32)hresult["funds"]; | 583 | funds = (Int32)hresult["funds"]; |
584 | } | 584 | } |
585 | catch (InvalidCastException) | 585 | catch (InvalidCastException) |
586 | { | 586 | { |
587 | 587 | ||
588 | } | 588 | } |
589 | SetLocalFundsForAgentID(avatar.UUID, funds); | 589 | SetLocalFundsForAgentID(avatar.UUID, funds); |
590 | } | 590 | } |
591 | else | 591 | else |
592 | { | 592 | { |
593 | avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true); | 593 | avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true); |
594 | } | 594 | } |
595 | } | 595 | } |
596 | } | 596 | } |
597 | } | 597 | } |
598 | } | 598 | } |
599 | else | 599 | else |
600 | { | 600 | { |
601 | lock (m_rootAgents) | 601 | lock (m_rootAgents) |
602 | { | 602 | { |
603 | m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID); | 603 | m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID); |
604 | } | 604 | } |
605 | if (m_MoneyAddress.Length > 0) | 605 | if (m_MoneyAddress.Length > 0) |
606 | { | 606 | { |
607 | Scene RegionItem = GetSceneByUUID(regionID); | 607 | Scene RegionItem = GetSceneByUUID(regionID); |
608 | if (RegionItem != null) | 608 | if (RegionItem != null) |
609 | { | 609 | { |
610 | Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); | 610 | Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); |
611 | if ((bool)hresult["success"] == true) | 611 | if ((bool)hresult["success"] == true) |
612 | { | 612 | { |
613 | int funds = 0; | 613 | int funds = 0; |
614 | try | 614 | try |
615 | { | 615 | { |
616 | funds = (Int32)hresult["funds"]; | 616 | funds = (Int32)hresult["funds"]; |
617 | } | 617 | } |
618 | catch (InvalidCastException) | 618 | catch (InvalidCastException) |
619 | { | 619 | { |
620 | 620 | ||
621 | } | 621 | } |
622 | SetLocalFundsForAgentID(avatar.UUID, funds); | 622 | SetLocalFundsForAgentID(avatar.UUID, funds); |
623 | } | 623 | } |
624 | else | 624 | else |
625 | { | 625 | { |
626 | avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true); | 626 | avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | } | 629 | } |
630 | 630 | ||
631 | //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); | 631 | //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); |
632 | } | 632 | } |
633 | } | 633 | } |
634 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); | 634 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); |
635 | } | 635 | } |
636 | 636 | ||
637 | #endregion | 637 | #endregion |
638 | 638 | ||
639 | /// <summary> | 639 | /// <summary> |
640 | /// Transfer money | 640 | /// Transfer money |
641 | /// </summary> | 641 | /// </summary> |
642 | /// <param name="Sender"></param> | 642 | /// <param name="Sender"></param> |
643 | /// <param name="Receiver"></param> | 643 | /// <param name="Receiver"></param> |
644 | /// <param name="amount"></param> | 644 | /// <param name="amount"></param> |
645 | /// <returns></returns> | 645 | /// <returns></returns> |
646 | private bool doMoneyTransfer(LLUUID Sender, LLUUID Receiver, int amount, int transactiontype, string description) | 646 | private bool doMoneyTransfer(LLUUID Sender, LLUUID Receiver, int amount, int transactiontype, string description) |
647 | { | 647 | { |
648 | bool result = false; | 648 | bool result = false; |
649 | if (amount >= 0) | 649 | if (amount >= 0) |
650 | { | 650 | { |
651 | lock (m_KnownClientFunds) | 651 | lock (m_KnownClientFunds) |
652 | { | 652 | { |
653 | // If we don't know about the sender, then the sender can't | 653 | // If we don't know about the sender, then the sender can't |
654 | // actually be here and therefore this is likely fraud or outdated. | 654 | // actually be here and therefore this is likely fraud or outdated. |
655 | if (m_MoneyAddress.Length == 0) | 655 | if (m_MoneyAddress.Length == 0) |
656 | { | 656 | { |
657 | if (m_KnownClientFunds.ContainsKey(Sender)) | 657 | if (m_KnownClientFunds.ContainsKey(Sender)) |
658 | { | 658 | { |
659 | // Does the sender have enough funds to give? | 659 | // Does the sender have enough funds to give? |
660 | if (m_KnownClientFunds[Sender] >= amount) | 660 | if (m_KnownClientFunds[Sender] >= amount) |
661 | { | 661 | { |
662 | // Subtract the funds from the senders account | 662 | // Subtract the funds from the senders account |
663 | m_KnownClientFunds[Sender] -= amount; | 663 | m_KnownClientFunds[Sender] -= amount; |
664 | 664 | ||
665 | // do we know about the receiver? | 665 | // do we know about the receiver? |
666 | if (!m_KnownClientFunds.ContainsKey(Receiver)) | 666 | if (!m_KnownClientFunds.ContainsKey(Receiver)) |
667 | { | 667 | { |
668 | // Make a record for them so they get the updated balance when they login | 668 | // Make a record for them so they get the updated balance when they login |
669 | CheckExistAndRefreshFunds(Receiver); | 669 | CheckExistAndRefreshFunds(Receiver); |
670 | } | 670 | } |
671 | if (m_enabled) | 671 | if (m_enabled) |
672 | { | 672 | { |
673 | //Add the amount to the Receiver's funds | 673 | //Add the amount to the Receiver's funds |
674 | m_KnownClientFunds[Receiver] += amount; | 674 | m_KnownClientFunds[Receiver] += amount; |
675 | result = true; | 675 | result = true; |
676 | } | 676 | } |
677 | } | 677 | } |
678 | else | 678 | else |
679 | { | 679 | { |
680 | // These below are redundant to make this clearer to read | 680 | // These below are redundant to make this clearer to read |
681 | result = false; | 681 | result = false; |
682 | } | 682 | } |
683 | } | 683 | } |
684 | else | 684 | else |
685 | { | 685 | { |
686 | result = false; | 686 | result = false; |
687 | } | 687 | } |
688 | } | 688 | } |
689 | else | 689 | else |
690 | { | 690 | { |
691 | result = TransferMoneyonMoneyServer(Sender, Receiver, amount, transactiontype, description); | 691 | result = TransferMoneyonMoneyServer(Sender, Receiver, amount, transactiontype, description); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | } | 694 | } |
695 | return result; | 695 | return result; |
696 | } | 696 | } |
697 | 697 | ||
698 | #region Utility Helpers | 698 | #region Utility Helpers |
699 | /// <summary> | 699 | /// <summary> |
700 | /// Locates a IClientAPI for the client specified | 700 | /// Locates a IClientAPI for the client specified |
701 | /// </summary> | 701 | /// </summary> |
702 | /// <param name="AgentID"></param> | 702 | /// <param name="AgentID"></param> |
703 | /// <returns></returns> | 703 | /// <returns></returns> |
704 | private IClientAPI LocateClientObject(LLUUID AgentID) | 704 | private IClientAPI LocateClientObject(LLUUID AgentID) |
705 | { | 705 | { |
706 | ScenePresence tPresence = null; | 706 | ScenePresence tPresence = null; |
707 | IClientAPI rclient = null; | 707 | IClientAPI rclient = null; |
708 | 708 | ||
709 | lock (m_scenel) | 709 | lock (m_scenel) |
710 | { | 710 | { |
711 | foreach (Scene _scene in m_scenel.Values) | 711 | foreach (Scene _scene in m_scenel.Values) |
712 | { | 712 | { |
713 | tPresence = _scene.GetScenePresence(AgentID); | 713 | tPresence = _scene.GetScenePresence(AgentID); |
714 | if (tPresence != null) | 714 | if (tPresence != null) |
715 | { | 715 | { |
716 | if (!tPresence.IsChildAgent) | 716 | if (!tPresence.IsChildAgent) |
717 | { | 717 | { |
718 | rclient = tPresence.ControllingClient; | 718 | rclient = tPresence.ControllingClient; |
719 | } | 719 | } |
720 | } | 720 | } |
721 | if (rclient != null) | 721 | if (rclient != null) |
722 | { | 722 | { |
723 | return rclient; | 723 | return rclient; |
724 | } | 724 | } |
725 | } | 725 | } |
726 | 726 | ||
727 | } | 727 | } |
728 | return null; | 728 | return null; |
729 | } | 729 | } |
730 | 730 | ||
731 | private Scene LocateSceneClientIn(LLUUID AgentId) | 731 | private Scene LocateSceneClientIn(LLUUID AgentId) |
732 | { | 732 | { |
733 | lock (m_scenel) | 733 | lock (m_scenel) |
734 | { | 734 | { |
735 | foreach (Scene _scene in m_scenel.Values) | 735 | foreach (Scene _scene in m_scenel.Values) |
736 | { | 736 | { |
737 | ScenePresence tPresence = _scene.GetScenePresence(AgentId); | 737 | ScenePresence tPresence = _scene.GetScenePresence(AgentId); |
738 | if (tPresence != null) | 738 | if (tPresence != null) |
739 | { | 739 | { |
740 | if (!tPresence.IsChildAgent) | 740 | if (!tPresence.IsChildAgent) |
741 | { | 741 | { |
742 | return _scene; | 742 | return _scene; |
743 | } | 743 | } |
744 | } | 744 | } |
745 | 745 | ||
746 | } | 746 | } |
747 | 747 | ||
748 | } | 748 | } |
749 | return null; | 749 | return null; |
750 | } | 750 | } |
751 | 751 | ||
752 | /// <summary> | 752 | /// <summary> |
753 | /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter | 753 | /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter |
754 | /// </summary> | 754 | /// </summary> |
755 | /// <returns></returns> | 755 | /// <returns></returns> |
756 | public Scene GetRandomScene() | 756 | public Scene GetRandomScene() |
757 | { | 757 | { |
758 | lock (m_scenel) | 758 | lock (m_scenel) |
759 | { | 759 | { |
760 | foreach (Scene rs in m_scenel.Values) | 760 | foreach (Scene rs in m_scenel.Values) |
761 | return rs; | 761 | return rs; |
762 | } | 762 | } |
763 | return null; | 763 | return null; |
764 | 764 | ||
765 | } | 765 | } |
766 | /// <summary> | 766 | /// <summary> |
767 | /// Utility function to get a Scene by RegionID in a module | 767 | /// Utility function to get a Scene by RegionID in a module |
768 | /// </summary> | 768 | /// </summary> |
769 | /// <param name="RegionID"></param> | 769 | /// <param name="RegionID"></param> |
770 | /// <returns></returns> | 770 | /// <returns></returns> |
771 | public Scene GetSceneByUUID(LLUUID RegionID) | 771 | public Scene GetSceneByUUID(LLUUID RegionID) |
772 | { | 772 | { |
773 | lock (m_scenel) | 773 | lock (m_scenel) |
774 | { | 774 | { |
775 | foreach (Scene rs in m_scenel.Values) | 775 | foreach (Scene rs in m_scenel.Values) |
776 | { | 776 | { |
777 | if (rs.RegionInfo.originRegionID == RegionID) | 777 | if (rs.RegionInfo.originRegionID == RegionID) |
778 | { | 778 | { |
779 | return rs; | 779 | return rs; |
780 | } | 780 | } |
781 | } | 781 | } |
782 | } | 782 | } |
783 | return null; | 783 | return null; |
784 | } | 784 | } |
785 | #endregion | 785 | #endregion |
786 | 786 | ||
787 | 787 | ||
788 | 788 | ||
789 | /// <summary> | 789 | /// <summary> |
790 | /// Sends the the stored money balance to the client | 790 | /// Sends the the stored money balance to the client |
791 | /// </summary> | 791 | /// </summary> |
792 | /// <param name="client"></param> | 792 | /// <param name="client"></param> |
793 | /// <param name="agentID"></param> | 793 | /// <param name="agentID"></param> |
794 | /// <param name="SessionID"></param> | 794 | /// <param name="SessionID"></param> |
795 | /// <param name="TransactionID"></param> | 795 | /// <param name="TransactionID"></param> |
796 | public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID) | 796 | public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID) |
797 | { | 797 | { |
798 | if (client.AgentId == agentID && client.SessionId == SessionID) | 798 | if (client.AgentId == agentID && client.SessionId == SessionID) |
799 | { | 799 | { |
800 | int returnfunds = 0; | 800 | int returnfunds = 0; |
801 | 801 | ||
802 | try | 802 | try |
803 | { | 803 | { |
804 | returnfunds = GetFundsForAgentID(agentID); | 804 | returnfunds = GetFundsForAgentID(agentID); |
805 | } | 805 | } |
806 | catch (Exception e) | 806 | catch (Exception e) |
807 | { | 807 | { |
808 | client.SendAlertMessage(e.Message + " "); | 808 | client.SendAlertMessage(e.Message + " "); |
809 | } | 809 | } |
810 | 810 | ||
811 | client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds); | 811 | client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds); |
812 | } | 812 | } |
813 | else | 813 | else |
814 | { | 814 | { |
815 | client.SendAlertMessage("Unable to send your money balance to you!"); | 815 | client.SendAlertMessage("Unable to send your money balance to you!"); |
816 | } | 816 | } |
817 | } | 817 | } |
818 | 818 | ||
819 | #region local Fund Management | 819 | #region local Fund Management |
820 | /// <summary> | 820 | /// <summary> |
821 | /// Ensures that the agent accounting data is set up in this instance. | 821 | /// Ensures that the agent accounting data is set up in this instance. |
822 | /// </summary> | 822 | /// </summary> |
823 | /// <param name="agentID"></param> | 823 | /// <param name="agentID"></param> |
824 | private void CheckExistAndRefreshFunds(LLUUID agentID) | 824 | private void CheckExistAndRefreshFunds(LLUUID agentID) |
825 | { | 825 | { |
826 | lock (m_KnownClientFunds) | 826 | lock (m_KnownClientFunds) |
827 | { | 827 | { |
828 | if (!m_KnownClientFunds.ContainsKey(agentID)) | 828 | if (!m_KnownClientFunds.ContainsKey(agentID)) |
829 | { | 829 | { |
830 | m_KnownClientFunds.Add(agentID, m_stipend); | 830 | m_KnownClientFunds.Add(agentID, m_stipend); |
831 | } | 831 | } |
832 | else | 832 | else |
833 | { | 833 | { |
834 | if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh) | 834 | if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh) |
835 | { | 835 | { |
836 | m_KnownClientFunds[agentID] = m_stipend; | 836 | m_KnownClientFunds[agentID] = m_stipend; |
837 | } | 837 | } |
838 | } | 838 | } |
839 | } | 839 | } |
840 | } | 840 | } |
841 | /// <summary> | 841 | /// <summary> |
842 | /// Gets the amount of Funds for an agent | 842 | /// Gets the amount of Funds for an agent |
843 | /// </summary> | 843 | /// </summary> |
844 | /// <param name="AgentID"></param> | 844 | /// <param name="AgentID"></param> |
845 | /// <returns></returns> | 845 | /// <returns></returns> |
846 | private int GetFundsForAgentID(LLUUID AgentID) | 846 | private int GetFundsForAgentID(LLUUID AgentID) |
847 | { | 847 | { |
848 | int returnfunds = 0; | 848 | int returnfunds = 0; |
849 | lock (m_KnownClientFunds) | 849 | lock (m_KnownClientFunds) |
850 | { | 850 | { |
851 | if (m_KnownClientFunds.ContainsKey(AgentID)) | 851 | if (m_KnownClientFunds.ContainsKey(AgentID)) |
852 | { | 852 | { |
853 | returnfunds = m_KnownClientFunds[AgentID]; | 853 | returnfunds = m_KnownClientFunds[AgentID]; |
854 | } | 854 | } |
855 | else | 855 | else |
856 | { | 856 | { |
857 | //throw new Exception("Unable to get funds."); | 857 | //throw new Exception("Unable to get funds."); |
858 | } | 858 | } |
859 | } | 859 | } |
860 | return returnfunds; | 860 | return returnfunds; |
861 | } | 861 | } |
862 | private void SetLocalFundsForAgentID(LLUUID AgentID, int amount) | 862 | private void SetLocalFundsForAgentID(LLUUID AgentID, int amount) |
863 | { | 863 | { |
864 | lock (m_KnownClientFunds) | 864 | lock (m_KnownClientFunds) |
865 | { | 865 | { |
866 | if (m_KnownClientFunds.ContainsKey(AgentID)) | 866 | if (m_KnownClientFunds.ContainsKey(AgentID)) |
867 | { | 867 | { |
868 | m_KnownClientFunds[AgentID] = amount; | 868 | m_KnownClientFunds[AgentID] = amount; |
869 | } | 869 | } |
870 | else | 870 | else |
871 | { | 871 | { |
872 | m_KnownClientFunds.Add(AgentID, amount); | 872 | m_KnownClientFunds.Add(AgentID, amount); |
873 | } | 873 | } |
874 | } | 874 | } |
875 | 875 | ||
876 | } | 876 | } |
877 | 877 | ||
878 | #endregion | 878 | #endregion |
879 | 879 | ||
880 | /// <summary> | 880 | /// <summary> |
881 | /// Gets the current balance for the user from the Grid Money Server | 881 | /// Gets the current balance for the user from the Grid Money Server |
882 | /// </summary> | 882 | /// </summary> |
883 | /// <param name="agentId"></param> | 883 | /// <param name="agentId"></param> |
884 | /// <param name="secureSessionID"></param> | 884 | /// <param name="secureSessionID"></param> |
885 | /// <param name="regionId"></param> | 885 | /// <param name="regionId"></param> |
886 | /// <param name="regionSecret"></param> | 886 | /// <param name="regionSecret"></param> |
887 | /// <returns></returns> | 887 | /// <returns></returns> |
888 | public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) | 888 | public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) |
889 | { | 889 | { |
890 | 890 | ||
891 | Hashtable MoneyBalanceRequestParams = new Hashtable(); | 891 | Hashtable MoneyBalanceRequestParams = new Hashtable(); |
892 | MoneyBalanceRequestParams["agentId"] = agentId.ToString(); | 892 | MoneyBalanceRequestParams["agentId"] = agentId.ToString(); |
893 | MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); | 893 | MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); |
894 | MoneyBalanceRequestParams["regionId"] = regionId.ToString(); | 894 | MoneyBalanceRequestParams["regionId"] = regionId.ToString(); |
895 | MoneyBalanceRequestParams["secret"] = regionSecret; | 895 | MoneyBalanceRequestParams["secret"] = regionSecret; |
896 | MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system | 896 | MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system |
897 | 897 | ||
898 | Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorUserBalanceRequest"); | 898 | Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorUserBalanceRequest"); |
899 | 899 | ||
900 | return MoneyRespData; | 900 | return MoneyRespData; |
901 | } | 901 | } |
902 | 902 | ||
903 | 903 | ||
904 | 904 | ||
905 | /// <summary> | 905 | /// <summary> |
906 | /// Generic XMLRPC client abstraction | 906 | /// Generic XMLRPC client abstraction |
907 | /// </summary> | 907 | /// </summary> |
908 | /// <param name="ReqParams">Hashtable containing parameters to the method</param> | 908 | /// <param name="ReqParams">Hashtable containing parameters to the method</param> |
909 | /// <param name="method">Method to invoke</param> | 909 | /// <param name="method">Method to invoke</param> |
910 | /// <returns>Hashtable with success=>bool and other values</returns> | 910 | /// <returns>Hashtable with success=>bool and other values</returns> |
911 | public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method) | 911 | public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method) |
912 | { | 912 | { |
913 | ArrayList SendParams = new ArrayList(); | 913 | ArrayList SendParams = new ArrayList(); |
914 | SendParams.Add(ReqParams); | 914 | SendParams.Add(ReqParams); |
915 | // Send Request | 915 | // Send Request |
916 | XmlRpcResponse MoneyResp; | 916 | XmlRpcResponse MoneyResp; |
917 | try | 917 | try |
918 | { | 918 | { |
919 | XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams); | 919 | XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams); |
920 | MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000); | 920 | MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000); |
921 | } | 921 | } |
922 | catch (WebException ex) | 922 | catch (WebException ex) |
923 | { | 923 | { |
924 | 924 | ||
925 | m_log.ErrorFormat( | 925 | m_log.ErrorFormat( |
926 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", | 926 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", |
927 | m_MoneyAddress, ex); | 927 | m_MoneyAddress, ex); |
928 | 928 | ||
929 | Hashtable ErrorHash = new Hashtable(); | 929 | Hashtable ErrorHash = new Hashtable(); |
930 | ErrorHash["success"] = false; | 930 | ErrorHash["success"] = false; |
931 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; | 931 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; |
932 | ErrorHash["errorURI"] = ""; | 932 | ErrorHash["errorURI"] = ""; |
933 | 933 | ||
934 | return ErrorHash; | 934 | return ErrorHash; |
935 | //throw (ex); | 935 | //throw (ex); |
936 | } | 936 | } |
937 | catch (SocketException ex) | 937 | catch (SocketException ex) |
938 | { | 938 | { |
939 | 939 | ||
940 | m_log.ErrorFormat( | 940 | m_log.ErrorFormat( |
941 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", | 941 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", |
942 | m_MoneyAddress, ex); | 942 | m_MoneyAddress, ex); |
943 | 943 | ||
944 | Hashtable ErrorHash = new Hashtable(); | 944 | Hashtable ErrorHash = new Hashtable(); |
945 | ErrorHash["success"] = false; | 945 | ErrorHash["success"] = false; |
946 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; | 946 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; |
947 | ErrorHash["errorURI"] = ""; | 947 | ErrorHash["errorURI"] = ""; |
948 | 948 | ||
949 | return ErrorHash; | 949 | return ErrorHash; |
950 | //throw (ex); | 950 | //throw (ex); |
951 | } | 951 | } |
952 | catch (XmlException ex) | 952 | catch (XmlException ex) |
953 | { | 953 | { |
954 | m_log.ErrorFormat( | 954 | m_log.ErrorFormat( |
955 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", | 955 | "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", |
956 | m_MoneyAddress, ex); | 956 | m_MoneyAddress, ex); |
957 | 957 | ||
958 | Hashtable ErrorHash = new Hashtable(); | 958 | Hashtable ErrorHash = new Hashtable(); |
959 | ErrorHash["success"] = false; | 959 | ErrorHash["success"] = false; |
960 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; | 960 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; |
961 | ErrorHash["errorURI"] = ""; | 961 | ErrorHash["errorURI"] = ""; |
962 | 962 | ||
963 | return ErrorHash; | 963 | return ErrorHash; |
964 | 964 | ||
965 | } | 965 | } |
966 | if (MoneyResp.IsFault) | 966 | if (MoneyResp.IsFault) |
967 | { | 967 | { |
968 | Hashtable ErrorHash = new Hashtable(); | 968 | Hashtable ErrorHash = new Hashtable(); |
969 | ErrorHash["success"] = false; | 969 | ErrorHash["success"] = false; |
970 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; | 970 | ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; |
971 | ErrorHash["errorURI"] = ""; | 971 | ErrorHash["errorURI"] = ""; |
972 | 972 | ||
973 | return ErrorHash; | 973 | return ErrorHash; |
974 | 974 | ||
975 | } | 975 | } |
976 | Hashtable MoneyRespData = (Hashtable)MoneyResp.Value; | 976 | Hashtable MoneyRespData = (Hashtable)MoneyResp.Value; |
977 | 977 | ||
978 | return MoneyRespData; | 978 | return MoneyRespData; |
979 | } | 979 | } |
980 | /// <summary> | 980 | /// <summary> |
981 | /// This informs the Money Grid Server that the avatar is in this simulator | 981 | /// This informs the Money Grid Server that the avatar is in this simulator |
982 | /// </summary> | 982 | /// </summary> |
983 | /// <param name="agentId"></param> | 983 | /// <param name="agentId"></param> |
984 | /// <param name="secureSessionID"></param> | 984 | /// <param name="secureSessionID"></param> |
985 | /// <param name="regionId"></param> | 985 | /// <param name="regionId"></param> |
986 | /// <param name="regionSecret"></param> | 986 | /// <param name="regionSecret"></param> |
987 | /// <returns></returns> | 987 | /// <returns></returns> |
988 | public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) | 988 | public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) |
989 | { | 989 | { |
990 | 990 | ||
991 | Hashtable MoneyBalanceRequestParams = new Hashtable(); | 991 | Hashtable MoneyBalanceRequestParams = new Hashtable(); |
992 | MoneyBalanceRequestParams["agentId"] = agentId.ToString(); | 992 | MoneyBalanceRequestParams["agentId"] = agentId.ToString(); |
993 | MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); | 993 | MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); |
994 | MoneyBalanceRequestParams["regionId"] = regionId.ToString(); | 994 | MoneyBalanceRequestParams["regionId"] = regionId.ToString(); |
995 | MoneyBalanceRequestParams["secret"] = regionSecret; | 995 | MoneyBalanceRequestParams["secret"] = regionSecret; |
996 | 996 | ||
997 | Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorClaimUserRequest"); | 997 | Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorClaimUserRequest"); |
998 | IClientAPI sendMoneyBal = LocateClientObject(agentId); | 998 | IClientAPI sendMoneyBal = LocateClientObject(agentId); |
999 | if (sendMoneyBal != null) | 999 | if (sendMoneyBal != null) |
1000 | { | 1000 | { |
1001 | SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, LLUUID.Zero); | 1001 | SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, LLUUID.Zero); |
1002 | } | 1002 | } |
1003 | return MoneyRespData; | 1003 | return MoneyRespData; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | private SceneObjectPart findPrim(LLUUID objectID) | 1006 | private SceneObjectPart findPrim(LLUUID objectID) |
1007 | { | 1007 | { |
1008 | lock (m_scenel) | 1008 | lock (m_scenel) |
1009 | { | 1009 | { |
1010 | foreach (Scene s in m_scenel.Values) | 1010 | foreach (Scene s in m_scenel.Values) |
1011 | { | 1011 | { |
1012 | SceneObjectPart part=s.GetSceneObjectPart(objectID); | 1012 | SceneObjectPart part=s.GetSceneObjectPart(objectID); |
1013 | if(part != null) | 1013 | if(part != null) |
1014 | { | 1014 | { |
1015 | return part; | 1015 | return part; |
1016 | } | 1016 | } |
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | return null; | 1019 | return null; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | private string resolveObjectName(LLUUID objectID) | 1022 | private string resolveObjectName(LLUUID objectID) |
1023 | { | 1023 | { |
1024 | SceneObjectPart part=findPrim(objectID); | 1024 | SceneObjectPart part=findPrim(objectID); |
1025 | if(part != null) | 1025 | if(part != null) |
1026 | { | 1026 | { |
1027 | return part.Name; | 1027 | return part.Name; |
1028 | } | 1028 | } |
1029 | return String.Empty; | 1029 | return String.Empty; |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | private string resolveAgentName(LLUUID agentID) | 1032 | private string resolveAgentName(LLUUID agentID) |
1033 | { | 1033 | { |
1034 | // try avatar username surname | 1034 | // try avatar username surname |
1035 | Scene scene=GetRandomScene(); | 1035 | Scene scene=GetRandomScene(); |
1036 | UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID); | 1036 | UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID); |
1037 | if (profile != null) | 1037 | if (profile != null) |
1038 | { | 1038 | { |
1039 | string avatarname = profile.FirstName + " " + profile.SurName; | 1039 | string avatarname = profile.FirstName + " " + profile.SurName; |
1040 | return avatarname; | 1040 | return avatarname; |
1041 | } | 1041 | } |
1042 | return String.Empty; | 1042 | return String.Empty; |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount) | 1045 | public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount) |
1046 | { | 1046 | { |
1047 | string description=String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID)); | 1047 | string description=String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID)); |
1048 | 1048 | ||
1049 | bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description); | 1049 | bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description); |
1050 | 1050 | ||
1051 | if (m_MoneyAddress.Length == 0) | 1051 | if (m_MoneyAddress.Length == 0) |
1052 | BalanceUpdate(fromID, toID, give_result, description); | 1052 | BalanceUpdate(fromID, toID, give_result, description); |
1053 | 1053 | ||
1054 | return give_result; | 1054 | return give_result; |
1055 | 1055 | ||
1056 | 1056 | ||
1057 | } | 1057 | } |
1058 | private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description) | 1058 | private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description) |
1059 | { | 1059 | { |
1060 | IClientAPI sender = LocateClientObject(senderID); | 1060 | IClientAPI sender = LocateClientObject(senderID); |
1061 | IClientAPI receiver = LocateClientObject(receiverID); | 1061 | IClientAPI receiver = LocateClientObject(receiverID); |
1062 | 1062 | ||
1063 | if (senderID != receiverID) | 1063 | if (senderID != receiverID) |
1064 | { | 1064 | { |
1065 | if (sender != null) | 1065 | if (sender != null) |
1066 | { | 1066 | { |
1067 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(senderID)); | 1067 | sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(senderID)); |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | if (receiver != null) | 1070 | if (receiver != null) |
1071 | { | 1071 | { |
1072 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(receiverID)); | 1072 | receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(receiverID)); |
1073 | } | 1073 | } |
1074 | } | 1074 | } |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | /// <summary> | 1077 | /// <summary> |
1078 | /// Informs the Money Grid Server of a transfer. | 1078 | /// Informs the Money Grid Server of a transfer. |
1079 | /// </summary> | 1079 | /// </summary> |
1080 | /// <param name="sourceId"></param> | 1080 | /// <param name="sourceId"></param> |
1081 | /// <param name="destId"></param> | 1081 | /// <param name="destId"></param> |
1082 | /// <param name="amount"></param> | 1082 | /// <param name="amount"></param> |
1083 | /// <returns></returns> | 1083 | /// <returns></returns> |
1084 | public bool TransferMoneyonMoneyServer(LLUUID sourceId, LLUUID destId, int amount, int transactiontype, string description) | 1084 | public bool TransferMoneyonMoneyServer(LLUUID sourceId, LLUUID destId, int amount, int transactiontype, string description) |
1085 | { | 1085 | { |
1086 | int aggregatePermInventory = 0; | 1086 | int aggregatePermInventory = 0; |
1087 | int aggregatePermNextOwner = 0; | 1087 | int aggregatePermNextOwner = 0; |
1088 | int flags = 0; | 1088 | int flags = 0; |
1089 | bool rvalue = false; | 1089 | bool rvalue = false; |
1090 | 1090 | ||
1091 | IClientAPI cli = LocateClientObject(sourceId); | 1091 | IClientAPI cli = LocateClientObject(sourceId); |
1092 | if (cli != null) | 1092 | if (cli != null) |
1093 | { | 1093 | { |
1094 | 1094 | ||
1095 | Scene userScene = null; | 1095 | Scene userScene = null; |
1096 | lock (m_rootAgents) | 1096 | lock (m_rootAgents) |
1097 | { | 1097 | { |
1098 | userScene = GetSceneByUUID(m_rootAgents[sourceId]); | 1098 | userScene = GetSceneByUUID(m_rootAgents[sourceId]); |
1099 | } | 1099 | } |
1100 | if (userScene != null) | 1100 | if (userScene != null) |
1101 | { | 1101 | { |
1102 | Hashtable ht = new Hashtable(); | 1102 | Hashtable ht = new Hashtable(); |
1103 | ht["agentId"] = sourceId.ToString(); | 1103 | ht["agentId"] = sourceId.ToString(); |
1104 | ht["secureSessionId"] = cli.SecureSessionId.ToString(); | 1104 | ht["secureSessionId"] = cli.SecureSessionId.ToString(); |
1105 | ht["regionId"] = userScene.RegionInfo.originRegionID.ToString(); | 1105 | ht["regionId"] = userScene.RegionInfo.originRegionID.ToString(); |
1106 | ht["secret"] = userScene.RegionInfo.regionSecret; | 1106 | ht["secret"] = userScene.RegionInfo.regionSecret; |
1107 | ht["currencySecret"] = " "; | 1107 | ht["currencySecret"] = " "; |
1108 | ht["destId"] = destId.ToString(); | 1108 | ht["destId"] = destId.ToString(); |
1109 | ht["cash"] = amount; | 1109 | ht["cash"] = amount; |
1110 | ht["aggregatePermInventory"] = aggregatePermInventory; | 1110 | ht["aggregatePermInventory"] = aggregatePermInventory; |
1111 | ht["aggregatePermNextOwner"] = aggregatePermNextOwner; | 1111 | ht["aggregatePermNextOwner"] = aggregatePermNextOwner; |
1112 | ht["flags"] = flags; | 1112 | ht["flags"] = flags; |
1113 | ht["transactionType"] = transactiontype; | 1113 | ht["transactionType"] = transactiontype; |
1114 | ht["description"] = description; | 1114 | ht["description"] = description; |
1115 | 1115 | ||
1116 | Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney"); | 1116 | Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney"); |
1117 | 1117 | ||
1118 | if ((bool)hresult["success"] == true) | 1118 | if ((bool)hresult["success"] == true) |
1119 | { | 1119 | { |
1120 | int funds1 = 0; | 1120 | int funds1 = 0; |
1121 | int funds2 = 0; | 1121 | int funds2 = 0; |
1122 | try | 1122 | try |
1123 | { | 1123 | { |
1124 | funds1 = (Int32)hresult["funds"]; | 1124 | funds1 = (Int32)hresult["funds"]; |
1125 | } | 1125 | } |
1126 | catch(InvalidCastException) | 1126 | catch(InvalidCastException) |
1127 | { | 1127 | { |
1128 | funds1 = 0; | 1128 | funds1 = 0; |
1129 | } | 1129 | } |
1130 | SetLocalFundsForAgentID(sourceId, funds1); | 1130 | SetLocalFundsForAgentID(sourceId, funds1); |
1131 | if (m_KnownClientFunds.ContainsKey(destId)) | 1131 | if (m_KnownClientFunds.ContainsKey(destId)) |
1132 | { | 1132 | { |
1133 | try | 1133 | try |
1134 | { | 1134 | { |
1135 | funds2 = (Int32)hresult["funds2"]; | 1135 | funds2 = (Int32)hresult["funds2"]; |
1136 | } | 1136 | } |
1137 | catch (InvalidCastException) | 1137 | catch (InvalidCastException) |
1138 | { | 1138 | { |
1139 | funds2 = 0; | 1139 | funds2 = 0; |
1140 | } | 1140 | } |
1141 | SetLocalFundsForAgentID(destId, funds2); | 1141 | SetLocalFundsForAgentID(destId, funds2); |
1142 | } | 1142 | } |
1143 | 1143 | ||
1144 | 1144 | ||
1145 | rvalue = true; | 1145 | rvalue = true; |
1146 | } | 1146 | } |
1147 | else | 1147 | else |
1148 | { | 1148 | { |
1149 | cli.SendAgentAlertMessage((string)hresult["errorMessage"], true); | 1149 | cli.SendAgentAlertMessage((string)hresult["errorMessage"], true); |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | } | 1152 | } |
1153 | } | 1153 | } |
1154 | else | 1154 | else |
1155 | { | 1155 | { |
1156 | m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString()); | 1156 | m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString()); |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | return rvalue; | 1159 | return rvalue; |
1160 | 1160 | ||
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | public int GetRemoteBalance(LLUUID agentId) | 1163 | public int GetRemoteBalance(LLUUID agentId) |
1164 | { | 1164 | { |
1165 | int funds = 0; | 1165 | int funds = 0; |
1166 | 1166 | ||
1167 | IClientAPI aClient = LocateClientObject(agentId); | 1167 | IClientAPI aClient = LocateClientObject(agentId); |
1168 | if (aClient != null) | 1168 | if (aClient != null) |
1169 | { | 1169 | { |
1170 | Scene s = LocateSceneClientIn(agentId); | 1170 | Scene s = LocateSceneClientIn(agentId); |
1171 | if (s != null) | 1171 | if (s != null) |
1172 | { | 1172 | { |
1173 | if (m_MoneyAddress.Length > 0) | 1173 | if (m_MoneyAddress.Length > 0) |
1174 | { | 1174 | { |
1175 | Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); | 1175 | Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); |
1176 | if ((bool)hbinfo["success"] == true) | 1176 | if ((bool)hbinfo["success"] == true) |
1177 | { | 1177 | { |
1178 | try | 1178 | try |
1179 | { | 1179 | { |
1180 | funds = (Int32)hbinfo["funds"]; | 1180 | funds = (Int32)hbinfo["funds"]; |
1181 | } | 1181 | } |
1182 | catch (ArgumentException) | 1182 | catch (ArgumentException) |
1183 | { | 1183 | { |
1184 | } | 1184 | } |
1185 | catch (FormatException) | 1185 | catch (FormatException) |
1186 | { | 1186 | { |
1187 | } | 1187 | } |
1188 | catch (OverflowException) | 1188 | catch (OverflowException) |
1189 | { | 1189 | { |
1190 | m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId); | 1190 | m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId); |
1191 | aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); | 1191 | aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); |
1192 | } | 1192 | } |
1193 | catch (InvalidCastException) | 1193 | catch (InvalidCastException) |
1194 | { | 1194 | { |
1195 | funds = 0; | 1195 | funds = 0; |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | } | 1198 | } |
1199 | else | 1199 | else |
1200 | { | 1200 | { |
1201 | m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]); | 1201 | m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]); |
1202 | aClient.SendAlertMessage((string)hbinfo["errorMessage"]); | 1202 | aClient.SendAlertMessage((string)hbinfo["errorMessage"]); |
1203 | } | 1203 | } |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | SetLocalFundsForAgentID(agentId, funds); | 1206 | SetLocalFundsForAgentID(agentId, funds); |
1207 | SendMoneyBalance(aClient, agentId, aClient.SessionId, LLUUID.Zero); | 1207 | SendMoneyBalance(aClient, agentId, aClient.SessionId, LLUUID.Zero); |
1208 | } | 1208 | } |
1209 | else | 1209 | else |
1210 | { | 1210 | { |
1211 | m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene."); | 1211 | m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene."); |
1212 | } | 1212 | } |
1213 | } | 1213 | } |
1214 | else | 1214 | else |
1215 | { | 1215 | { |
1216 | m_log.Debug("[MONEY]: Got balance request update for agent that isn't here."); | 1216 | m_log.Debug("[MONEY]: Got balance request update for agent that isn't here."); |
1217 | } | 1217 | } |
1218 | return funds; | 1218 | return funds; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request) | 1221 | public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request) |
1222 | { | 1222 | { |
1223 | m_log.Debug("[MONEY]: Dynamic balance update called."); | 1223 | m_log.Debug("[MONEY]: Dynamic balance update called."); |
1224 | Hashtable requestData = (Hashtable)request.Params[0]; | 1224 | Hashtable requestData = (Hashtable)request.Params[0]; |
1225 | 1225 | ||
1226 | if (requestData.ContainsKey("agentId")) | 1226 | if (requestData.ContainsKey("agentId")) |
1227 | { | 1227 | { |
1228 | LLUUID agentId = LLUUID.Zero; | 1228 | LLUUID agentId = LLUUID.Zero; |
1229 | 1229 | ||
1230 | Helpers.TryParse((string)requestData["agentId"], out agentId); | 1230 | Helpers.TryParse((string)requestData["agentId"], out agentId); |
1231 | if (agentId != LLUUID.Zero) | 1231 | if (agentId != LLUUID.Zero) |
1232 | { | 1232 | { |
1233 | GetRemoteBalance(agentId); | 1233 | GetRemoteBalance(agentId); |
1234 | 1234 | ||
1235 | } | 1235 | } |
1236 | else | 1236 | else |
1237 | { | 1237 | { |
1238 | m_log.Debug("[MONEY]: invalid agentId specified, dropping."); | 1238 | m_log.Debug("[MONEY]: invalid agentId specified, dropping."); |
1239 | } | 1239 | } |
1240 | } | 1240 | } |
1241 | else | 1241 | else |
1242 | { | 1242 | { |
1243 | m_log.Debug("[MONEY]: no agentId specified, dropping."); | 1243 | m_log.Debug("[MONEY]: no agentId specified, dropping."); |
1244 | } | 1244 | } |
1245 | XmlRpcResponse r = new XmlRpcResponse(); | 1245 | XmlRpcResponse r = new XmlRpcResponse(); |
1246 | Hashtable rparms = new Hashtable(); | 1246 | Hashtable rparms = new Hashtable(); |
1247 | rparms["success"] = true; | 1247 | rparms["success"] = true; |
1248 | 1248 | ||
1249 | r.Value = rparms; | 1249 | r.Value = rparms; |
1250 | return r; | 1250 | return r; |
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | /// <summary> | 1253 | /// <summary> |
1254 | /// XMLRPC handler to send alert message and sound to client | 1254 | /// XMLRPC handler to send alert message and sound to client |
1255 | /// </summary> | 1255 | /// </summary> |
1256 | public XmlRpcResponse UserAlert(XmlRpcRequest request) | 1256 | public XmlRpcResponse UserAlert(XmlRpcRequest request) |
1257 | { | 1257 | { |
1258 | XmlRpcResponse ret = new XmlRpcResponse(); | 1258 | XmlRpcResponse ret = new XmlRpcResponse(); |
1259 | Hashtable retparam = new Hashtable(); | 1259 | Hashtable retparam = new Hashtable(); |
1260 | Hashtable requestData = (Hashtable)request.Params[0]; | 1260 | Hashtable requestData = (Hashtable)request.Params[0]; |
1261 | 1261 | ||
1262 | LLUUID agentId = LLUUID.Zero; | 1262 | LLUUID agentId = LLUUID.Zero; |
1263 | LLUUID soundId = LLUUID.Zero; | 1263 | LLUUID soundId = LLUUID.Zero; |
1264 | 1264 | ||
1265 | Helpers.TryParse((string)requestData["agentId"], out agentId); | 1265 | Helpers.TryParse((string)requestData["agentId"], out agentId); |
1266 | Helpers.TryParse((string)requestData["soundId"], out soundId); | 1266 | Helpers.TryParse((string)requestData["soundId"], out soundId); |
1267 | string text=(string)requestData["text"]; | 1267 | string text=(string)requestData["text"]; |
1268 | string secret=(string)requestData["secret"]; | 1268 | string secret=(string)requestData["secret"]; |
1269 | 1269 | ||
1270 | Scene userScene = GetRandomScene(); | 1270 | Scene userScene = GetRandomScene(); |
1271 | if(userScene.RegionInfo.regionSecret.ToString() == secret) | 1271 | if(userScene.RegionInfo.regionSecret.ToString() == secret) |
1272 | { | 1272 | { |
1273 | IClientAPI client = LocateClientObject(agentId); | 1273 | IClientAPI client = LocateClientObject(agentId); |
1274 | 1274 | ||
1275 | if (client != null) | 1275 | if (client != null) |
1276 | { | 1276 | { |
1277 | if(soundId != LLUUID.Zero) | 1277 | if(soundId != LLUUID.Zero) |
1278 | client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0); | 1278 | client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0); |
1279 | client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text); | 1279 | client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text); |
1280 | retparam.Add("success", true); | 1280 | retparam.Add("success", true); |
1281 | } | 1281 | } |
1282 | else | 1282 | else |
1283 | { | 1283 | { |
1284 | retparam.Add("success", false); | 1284 | retparam.Add("success", false); |
1285 | } | 1285 | } |
1286 | } | 1286 | } |
1287 | else | 1287 | else |
1288 | { | 1288 | { |
1289 | retparam.Add("success", false); | 1289 | retparam.Add("success", false); |
1290 | } | 1290 | } |
1291 | ret.Value = retparam; | 1291 | ret.Value = retparam; |
1292 | 1292 | ||
1293 | return ret; | 1293 | return ret; |
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | 1296 | ||
1297 | # region Standalone box enablers only | 1297 | # region Standalone box enablers only |
1298 | 1298 | ||
1299 | public XmlRpcResponse quote_func(XmlRpcRequest request) | 1299 | public XmlRpcResponse quote_func(XmlRpcRequest request) |
1300 | { | 1300 | { |
1301 | Hashtable requestData = (Hashtable)request.Params[0]; | 1301 | Hashtable requestData = (Hashtable)request.Params[0]; |
1302 | LLUUID agentId = LLUUID.Zero; | 1302 | LLUUID agentId = LLUUID.Zero; |
1303 | int amount = 0; | 1303 | int amount = 0; |
1304 | Hashtable quoteResponse = new Hashtable(); | 1304 | Hashtable quoteResponse = new Hashtable(); |
1305 | XmlRpcResponse returnval = new XmlRpcResponse(); | 1305 | XmlRpcResponse returnval = new XmlRpcResponse(); |
1306 | 1306 | ||
1307 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) | 1307 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) |
1308 | { | 1308 | { |
1309 | Helpers.TryParse((string)requestData["agentId"], out agentId); | 1309 | Helpers.TryParse((string)requestData["agentId"], out agentId); |
1310 | try | 1310 | try |
1311 | { | 1311 | { |
1312 | amount = (Int32)requestData["currencyBuy"]; | 1312 | amount = (Int32)requestData["currencyBuy"]; |
1313 | } | 1313 | } |
1314 | catch (InvalidCastException) | 1314 | catch (InvalidCastException) |
1315 | { | 1315 | { |
1316 | 1316 | ||
1317 | } | 1317 | } |
1318 | Hashtable currencyResponse = new Hashtable(); | 1318 | Hashtable currencyResponse = new Hashtable(); |
1319 | currencyResponse.Add("estimatedCost", 0); | 1319 | currencyResponse.Add("estimatedCost", 0); |
1320 | currencyResponse.Add("currencyBuy", amount); | 1320 | currencyResponse.Add("currencyBuy", amount); |
1321 | 1321 | ||
1322 | quoteResponse.Add("success", true); | 1322 | quoteResponse.Add("success", true); |
1323 | quoteResponse.Add("currency", currencyResponse); | 1323 | quoteResponse.Add("currency", currencyResponse); |
1324 | quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); | 1324 | quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); |
1325 | 1325 | ||
1326 | returnval.Value = quoteResponse; | 1326 | returnval.Value = quoteResponse; |
1327 | return returnval; | 1327 | return returnval; |
1328 | } | 1328 | } |
1329 | 1329 | ||
1330 | 1330 | ||
1331 | 1331 | ||
1332 | quoteResponse.Add("success", false); | 1332 | quoteResponse.Add("success", false); |
1333 | quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box"); | 1333 | quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box"); |
1334 | quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki"); | 1334 | quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki"); |
1335 | returnval.Value = quoteResponse; | 1335 | returnval.Value = quoteResponse; |
1336 | return returnval; | 1336 | return returnval; |
1337 | } | 1337 | } |
1338 | public XmlRpcResponse buy_func(XmlRpcRequest request) | 1338 | public XmlRpcResponse buy_func(XmlRpcRequest request) |
1339 | { | 1339 | { |
1340 | 1340 | ||
1341 | Hashtable requestData = (Hashtable)request.Params[0]; | 1341 | Hashtable requestData = (Hashtable)request.Params[0]; |
1342 | LLUUID agentId = LLUUID.Zero; | 1342 | LLUUID agentId = LLUUID.Zero; |
1343 | int amount = 0; | 1343 | int amount = 0; |
1344 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) | 1344 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) |
1345 | { | 1345 | { |
1346 | Helpers.TryParse((string)requestData["agentId"], out agentId); | 1346 | Helpers.TryParse((string)requestData["agentId"], out agentId); |
1347 | try | 1347 | try |
1348 | { | 1348 | { |
1349 | amount = (Int32)requestData["currencyBuy"]; | 1349 | amount = (Int32)requestData["currencyBuy"]; |
1350 | } | 1350 | } |
1351 | catch (InvalidCastException) | 1351 | catch (InvalidCastException) |
1352 | { | 1352 | { |
1353 | 1353 | ||
1354 | } | 1354 | } |
1355 | if (agentId != LLUUID.Zero) | 1355 | if (agentId != LLUUID.Zero) |
1356 | { | 1356 | { |
1357 | lock (m_KnownClientFunds) | 1357 | lock (m_KnownClientFunds) |
1358 | { | 1358 | { |
1359 | if (m_KnownClientFunds.ContainsKey(agentId)) | 1359 | if (m_KnownClientFunds.ContainsKey(agentId)) |
1360 | { | 1360 | { |
1361 | m_KnownClientFunds[agentId] += amount; | 1361 | m_KnownClientFunds[agentId] += amount; |
1362 | } | 1362 | } |
1363 | else | 1363 | else |
1364 | { | 1364 | { |
1365 | m_KnownClientFunds.Add(agentId, amount); | 1365 | m_KnownClientFunds.Add(agentId, amount); |
1366 | } | 1366 | } |
1367 | } | 1367 | } |
1368 | IClientAPI client = LocateClientObject(agentId); | 1368 | IClientAPI client = LocateClientObject(agentId); |
1369 | if (client != null) | 1369 | if (client != null) |
1370 | { | 1370 | { |
1371 | SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); | 1371 | SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); |
1372 | } | 1372 | } |
1373 | } | 1373 | } |
1374 | } | 1374 | } |
1375 | XmlRpcResponse returnval = new XmlRpcResponse(); | 1375 | XmlRpcResponse returnval = new XmlRpcResponse(); |
1376 | Hashtable returnresp = new Hashtable(); | 1376 | Hashtable returnresp = new Hashtable(); |
1377 | returnresp.Add("success", true); | 1377 | returnresp.Add("success", true); |
1378 | returnval.Value = returnresp; | 1378 | returnval.Value = returnresp; |
1379 | return returnval; | 1379 | return returnval; |
1380 | } | 1380 | } |
1381 | 1381 | ||
1382 | public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request) | 1382 | public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request) |
1383 | { | 1383 | { |
1384 | XmlRpcResponse ret = new XmlRpcResponse(); | 1384 | XmlRpcResponse ret = new XmlRpcResponse(); |
1385 | Hashtable retparam = new Hashtable(); | 1385 | Hashtable retparam = new Hashtable(); |
1386 | Hashtable membershiplevels = new Hashtable(); | 1386 | Hashtable membershiplevels = new Hashtable(); |
1387 | ArrayList levels = new ArrayList(); | 1387 | ArrayList levels = new ArrayList(); |
1388 | Hashtable level = new Hashtable(); | 1388 | Hashtable level = new Hashtable(); |
1389 | level.Add("id", "00000000-0000-0000-0000-000000000000"); | 1389 | level.Add("id", "00000000-0000-0000-0000-000000000000"); |
1390 | level.Add("description", "some level"); | 1390 | level.Add("description", "some level"); |
1391 | levels.Add(level); | 1391 | levels.Add(level); |
1392 | //membershiplevels.Add("levels",levels); | 1392 | //membershiplevels.Add("levels",levels); |
1393 | 1393 | ||
1394 | Hashtable landuse = new Hashtable(); | 1394 | Hashtable landuse = new Hashtable(); |
1395 | landuse.Add("upgrade", false); | 1395 | landuse.Add("upgrade", false); |
1396 | landuse.Add("action", "http://invaliddomaininvalid.com/"); | 1396 | landuse.Add("action", "http://invaliddomaininvalid.com/"); |
1397 | 1397 | ||
1398 | Hashtable currency = new Hashtable(); | 1398 | Hashtable currency = new Hashtable(); |
1399 | currency.Add("estimatedCost", 0); | 1399 | currency.Add("estimatedCost", 0); |
1400 | 1400 | ||
1401 | Hashtable membership = new Hashtable(); | 1401 | Hashtable membership = new Hashtable(); |
1402 | membershiplevels.Add("upgrade", false); | 1402 | membershiplevels.Add("upgrade", false); |
1403 | membershiplevels.Add("action", "http://invaliddomaininvalid.com/"); | 1403 | membershiplevels.Add("action", "http://invaliddomaininvalid.com/"); |
1404 | membershiplevels.Add("levels", membershiplevels); | 1404 | membershiplevels.Add("levels", membershiplevels); |
1405 | 1405 | ||
1406 | retparam.Add("success", true); | 1406 | retparam.Add("success", true); |
1407 | retparam.Add("currency", currency); | 1407 | retparam.Add("currency", currency); |
1408 | retparam.Add("membership", membership); | 1408 | retparam.Add("membership", membership); |
1409 | retparam.Add("landuse", landuse); | 1409 | retparam.Add("landuse", landuse); |
1410 | retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf"); | 1410 | retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf"); |
1411 | 1411 | ||
1412 | ret.Value = retparam; | 1412 | ret.Value = retparam; |
1413 | 1413 | ||
1414 | return ret; | 1414 | return ret; |
1415 | 1415 | ||
1416 | } | 1416 | } |
1417 | public XmlRpcResponse landBuy_func(XmlRpcRequest request) | 1417 | public XmlRpcResponse landBuy_func(XmlRpcRequest request) |
1418 | { | 1418 | { |
1419 | XmlRpcResponse ret = new XmlRpcResponse(); | 1419 | XmlRpcResponse ret = new XmlRpcResponse(); |
1420 | Hashtable retparam = new Hashtable(); | 1420 | Hashtable retparam = new Hashtable(); |
1421 | Hashtable requestData = (Hashtable)request.Params[0]; | 1421 | Hashtable requestData = (Hashtable)request.Params[0]; |
1422 | 1422 | ||
1423 | LLUUID agentId = LLUUID.Zero; | 1423 | LLUUID agentId = LLUUID.Zero; |
1424 | int amount = 0; | 1424 | int amount = 0; |
1425 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) | 1425 | if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) |
1426 | { | 1426 | { |
1427 | Helpers.TryParse((string)requestData["agentId"], out agentId); | 1427 | Helpers.TryParse((string)requestData["agentId"], out agentId); |
1428 | try | 1428 | try |
1429 | { | 1429 | { |
1430 | amount = (Int32)requestData["currencyBuy"]; | 1430 | amount = (Int32)requestData["currencyBuy"]; |
1431 | } | 1431 | } |
1432 | catch (InvalidCastException) | 1432 | catch (InvalidCastException) |
1433 | { | 1433 | { |
1434 | 1434 | ||
1435 | } | 1435 | } |
1436 | if (agentId != LLUUID.Zero) | 1436 | if (agentId != LLUUID.Zero) |
1437 | { | 1437 | { |
1438 | lock (m_KnownClientFunds) | 1438 | lock (m_KnownClientFunds) |
1439 | { | 1439 | { |
1440 | if (m_KnownClientFunds.ContainsKey(agentId)) | 1440 | if (m_KnownClientFunds.ContainsKey(agentId)) |
1441 | { | 1441 | { |
1442 | m_KnownClientFunds[agentId] += amount; | 1442 | m_KnownClientFunds[agentId] += amount; |
1443 | } | 1443 | } |
1444 | else | 1444 | else |
1445 | { | 1445 | { |
1446 | m_KnownClientFunds.Add(agentId, amount); | 1446 | m_KnownClientFunds.Add(agentId, amount); |
1447 | } | 1447 | } |
1448 | } | 1448 | } |
1449 | IClientAPI client = LocateClientObject(agentId); | 1449 | IClientAPI client = LocateClientObject(agentId); |
1450 | if (client != null) | 1450 | if (client != null) |
1451 | { | 1451 | { |
1452 | SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); | 1452 | SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); |
1453 | } | 1453 | } |
1454 | } | 1454 | } |
1455 | } | 1455 | } |
1456 | retparam.Add("success", true); | 1456 | retparam.Add("success", true); |
1457 | ret.Value = retparam; | 1457 | ret.Value = retparam; |
1458 | 1458 | ||
1459 | return ret; | 1459 | return ret; |
1460 | 1460 | ||
1461 | } | 1461 | } |
1462 | #endregion | 1462 | #endregion |
1463 | 1463 | ||
1464 | public void PostInitialise() | 1464 | public void PostInitialise() |
1465 | { | 1465 | { |
1466 | } | 1466 | } |
1467 | 1467 | ||
1468 | public void Close() | 1468 | public void Close() |
1469 | { | 1469 | { |
1470 | } | 1470 | } |
1471 | 1471 | ||
1472 | public string Name | 1472 | public string Name |
1473 | { | 1473 | { |
1474 | get { return "BetaGridLikeMoneyModule"; } | 1474 | get { return "BetaGridLikeMoneyModule"; } |
1475 | } | 1475 | } |
1476 | 1476 | ||
1477 | public bool IsSharedModule | 1477 | public bool IsSharedModule |
1478 | { | 1478 | { |
1479 | get { return true; } | 1479 | get { return true; } |
1480 | } | 1480 | } |
1481 | } | 1481 | } |
1482 | public enum TransactionType : int | 1482 | |
1483 | { | 1483 | public enum TransactionType : int |
1484 | SystemGenerated=0, | 1484 | { |
1485 | RegionMoneyRequest=1, | 1485 | SystemGenerated=0, |
1486 | Gift=2, | 1486 | RegionMoneyRequest=1, |
1487 | Purchase=3 | 1487 | Gift=2, |
1488 | 1488 | Purchase=3 | |
1489 | } | 1489 | |
1490 | } | 1490 | } |
1491 | } \ No newline at end of file | ||