public void ObjectBuy(IClientAPI remoteClient, UUID agentID, UUID sessionID, UUID groupID,
UUID categoryID, uint localID, byte saleType, int salePrice)
{
if (!m_active)
return;
IClientAPI user = null;
Scene scene = null;
// Find the user's controlling client.
lock (m_scenes) {
foreach (Scene sc in m_scenes) {
ScenePresence av = sc.GetScenePresence (agentID);
if ((av != null) && (av.IsChildAgent == false)) {
// Found the client,
// and their root scene.
user = av.ControllingClient;
scene = sc;
}
}
}
if (scene == null || user == null) {
m_log.Warn ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
return;
}
if (salePrice == 0) {
IBuySellModule module = scene.RequestModuleInterface<IBuySellModule> ();
if (module == null) {
m_log.Error ("[FreeMoney] Missing BuySellModule! Transaction failed.");
return;
}
module.BuyObject (remoteClient, categoryID, localID, saleType, salePrice);
return;
}
SceneObjectPart sop = scene.GetSceneObjectPart (localID);
if (sop == null) {
m_log.Error ("[FreeMoney] Unable to find SceneObjectPart that was paid. Aborting transaction.");
return;
}
string email = "";
if (m_allowPayPal) {
if (sop.OwnerID == sop.GroupID) {
if (m_allowGroups) {
if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
m_log.Warn ("[FreeMoney] Unknown email address of group " + sop.OwnerID);
if (!m_allowBitcoin) {
return;
}
}
} else {
m_log.Warn ("[FreeMoney] Purchase of group owned objects is disabled.");
if (!m_allowBitcoin) {
return;
}
}
} else {
if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
m_log.Warn ("[FreeMoney] Unknown email address of user " + sop.OwnerID);
if (!m_allowBitcoin) {
return;
}
}
}
}
m_log.Info ("[FreeMoney] Start: " + agentID + " wants to buy object " + sop.UUID + " from " + sop.OwnerID +
" with email " + email + " costing " + m_gridCurrencySmallDenominationText + " " + salePrice);
FreeMoneyTransaction txn = new FreeMoneyTransaction (agentID, sop.OwnerID, email, salePrice, scene, sop.UUID,
"Item Purchase - " + sop.Name + " (" + saleType + ")",
FreeMoneyTransaction.InternalTransactionType.Purchase,
categoryID, saleType);
// Add transaction to queue
lock (m_transactionsInProgress)
m_transactionsInProgress.Add (txn.TxID, txn);
string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;
// If we're definitely going to use Bitcoin for this transaction, go ahead and initialize it and show the page page.
// Otherwise, show an intermediate page to choose the payment type, and only initialize for Bitcoin if they choose it.
string pageName = "pp";
if (m_directToBitcoin) {
InitializeBitcoinTransaction(txn, baseUrl);
pageName = "btcgo";
}
user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm purchase?", "http://" +
baseUrl + "/"+pageName+"/?txn=" + txn.TxID);
}