Universe.Modules.Currency.BaseCurrencyConnector.UserCurrencyTransfer C# (CSharp) Method

UserCurrencyTransfer() private method

private UserCurrencyTransfer ( UUID toID, UUID fromID, UUID toObjectID, string toObjectName, UUID fromObjectID, string fromObjectName, uint amount, string description, TransactionType type, UUID transactionID ) : bool
toID UUID
fromID UUID
toObjectID UUID
toObjectName string
fromObjectID UUID
fromObjectName string
amount uint
description string
type TransactionType
transactionID UUID
return bool
        public bool UserCurrencyTransfer(UUID toID, UUID fromID, UUID toObjectID, string toObjectName, UUID fromObjectID,
            string fromObjectName, uint amount, string description, TransactionType type, UUID transactionID)
        {
            if (m_doRemoteOnly) {
                object remoteValue = DoRemoteByURL ("CurrencyServerURI", toID, fromID, toObjectID, toObjectName, fromObjectID,
                                                    fromObjectName, amount, description, type, transactionID);
                return remoteValue != null && (bool)remoteValue;
            }

            // check if the 'toID' is a group
            var groupService = Framework.Utilities.DataManager.RequestPlugin<IGroupsServiceConnector> ();
            if (groupService.IsGroup(toID))
                return GroupCurrencyTransfer(toID, fromID, false, toObjectName, fromObjectID,
                    fromObjectName, (int) amount, description, type, transactionID);
                
            // use transfer
            UserCurrency toCurrency = GetUserCurrency(toID);
            UserCurrency fromCurrency = fromID == UUID.Zero ? null : GetUserCurrency(fromID);

            if (toCurrency == null)
                return false;

            // Groups (legacy) should not receive stipends
            if ((type == TransactionType.StipendPayment) && toCurrency.IsGroup)
                return false;
            
            if (fromCurrency != null)
            {
                if (fromID == (UUID)Constants.BankerUUID)
                {
                    // payment from the Banker
                    // 20150730 - greythane - need to fiddle 'the books' as -ve balances are not currently available
                    fromCurrency.Amount += amount;
                } else
                {
                    // Normal users cannot have a credit balance.. check to see whether they have enough money
                    if ((int)fromCurrency.Amount - (int)amount < 0)
                        return false; // Not enough money
                }

                // subtract this payment
                fromCurrency.Amount -= amount;
                UserCurrencyUpdate (fromCurrency, true);
            }

            if (fromID == toID)
                toCurrency = GetUserCurrency (toID);

            //Update the user who is getting paid
            toCurrency.Amount += amount;
            UserCurrencyUpdate(toCurrency, true);

            //Must send out notifications to the users involved so that they get the updates
            if (m_userInfoService == null)
            {
                m_userInfoService = m_registry.RequestModuleInterface<IAgentInfoService>();
                m_userAccountService = m_registry.RequestModuleInterface<IUserAccountService> ();
            }
            if (m_userInfoService != null)
            {
                UserInfo toUserInfo = m_userInfoService.GetUserInfo(toID.ToString());
                UserInfo fromUserInfo = fromID == UUID.Zero ? null : m_userInfoService.GetUserInfo(fromID.ToString());
                UserAccount toAccount = m_userAccountService.GetUserAccount(null, toID);
                UserAccount fromAccount = m_userAccountService.GetUserAccount(null, fromID);

                if (m_config.SaveTransactionLogs)
                    AddTransactionRecord(
                        (transactionID == UUID.Zero ? UUID.Random() : transactionID), 
                        description,
                        toID,
                        fromID,
                        amount,
                        type,
                        toCurrency.Amount, 
                        (fromCurrency == null ? 0 : fromCurrency.Amount),
                        (toAccount == null ? "System" : toAccount.Name), 
                        (fromAccount == null ? "System" : fromAccount.Name),
                        toObjectName,
                        fromObjectName,
                        (fromUserInfo == null ? UUID.Zero : fromUserInfo.CurrentRegionID)
                    );

                if (fromID == toID)
                {
                    if (toUserInfo != null && toUserInfo.IsOnline)
                        SendUpdateMoneyBalanceToClient(toID, transactionID, toUserInfo.CurrentRegionURI, toCurrency.Amount,
                            toAccount == null ? "" : (toAccount.Name + " paid you " + InWorldCurrency + amount + (description == "" ? "" : ": " + description)));
                } else
                {
                    if (toUserInfo != null && toUserInfo.IsOnline)
                    {
                        SendUpdateMoneyBalanceToClient(toID, transactionID, toUserInfo.CurrentRegionURI, toCurrency.Amount,
                            fromAccount == null ? "" : (fromAccount.Name + " paid you " + InWorldCurrency  + amount + (description == "" ? "" : ": " + description)));
                    }
                    if (fromUserInfo != null && fromUserInfo.IsOnline)
                    {
                        SendUpdateMoneyBalanceToClient(fromID, transactionID, fromUserInfo.CurrentRegionURI, fromCurrency.Amount,
                            "You paid " + (toAccount == null ? "" : toAccount.Name) + " " + InWorldCurrency + amount);
                    }
                }
            }
            return true;
        }

Same methods

BaseCurrencyConnector::UserCurrencyTransfer ( UUID toID, UUID fromID, uint amount, string description, TransactionType type, UUID transactionID ) : bool

Usage Example

        bool EventManager_OnValidateBuyLand(EventManager.LandBuyArgs e)
        {
            IParcelManagementModule parcelManagement = GetSceneFor(e.agentId).RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagement == null)
            {
                return(false);
            }
            ILandObject lob = parcelManagement.GetLandObject(e.parcelLocalID);

            if (lob != null)
            {
                UUID AuthorizedID = lob.LandData.AuthBuyerID;
                int  saleprice    = lob.LandData.SalePrice;
                UUID pOwnerID     = lob.LandData.OwnerID;

                bool landforsale = ((lob.LandData.Flags & (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0);
                if ((AuthorizedID == UUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice &&
                    landforsale)
                {
                    if (m_connector.UserCurrencyTransfer(lob.LandData.OwnerID, e.agentId, (uint)saleprice, "Land Buy", TransactionType.LandSale, UUID.Zero))
                    {
                        e.parcelOwnerID = pOwnerID;
                        e.landValidated = true;
                        return(true);
                    }

                    // not validated
                    e.landValidated = false;
                }
            }
            return(false);
        }
All Usage Examples Of Universe.Modules.Currency.BaseCurrencyConnector::UserCurrencyTransfer