Пример #1
0
        private void HandleParcelBuy(AgentCircuit circuit, SceneInterface scene, Message m)
        {
            var req = (ParcelBuy)m;

            if (req.CircuitAgentID != req.AgentID ||
                req.CircuitSessionID != req.SessionID)
            {
                return;
            }

            ViewerAgent agent = circuit.Agent;

            ParcelInfo pinfo;

            if (scene.Parcels.TryGetValue(req.LocalID, out pinfo) && (pinfo.Flags & ParcelFlags.ForSale) != 0)
            {
                if (pinfo.AuthBuyer.EqualsGrid(agent.Owner) || pinfo.AuthBuyer == UGUI.Unknown)
                {
                    if (pinfo.SalePrice != 0)
                    {
                        /* we have to process it on economy */
                        EconomyServiceInterface economyService = agent.EconomyService;
                        if (economyService != null)
                        {
                            if (pinfo.GroupOwned)
                            {
                                economyService.TransferMoney(agent.Owner, pinfo.Group, new LandSaleTransaction(scene.GetRegionInfo().Location, scene.ID, scene.Name)
                                {
                                    ParcelID   = pinfo.ID,
                                    ParcelName = pinfo.Name
                                }, pinfo.SalePrice, () => ChangeParcelOwnership(scene, pinfo, agent.Owner, pinfo.SalePrice, req));
                            }
                            else
                            {
                                economyService.TransferMoney(agent.Owner, pinfo.Owner, new LandSaleTransaction(scene.GetRegionInfo().Location, scene.ID, scene.Name)
                                {
                                    ParcelID   = pinfo.ID,
                                    ParcelName = pinfo.Name
                                }, pinfo.SalePrice, () => ChangeParcelOwnership(scene, pinfo, agent.Owner, pinfo.SalePrice, req));
                            }
                        }
                    }
                    else
                    {
                        ChangeParcelOwnership(scene, pinfo, agent.Owner, pinfo.SalePrice, req);
                    }
                }
            }
        }
        public void HandleBuyPass(Message m)
        {
            var p = (ParcelBuyPass)m;

            if (p.CircuitAgentID != p.AgentID ||
                p.CircuitSessionID != p.SessionID)
            {
                return;
            }

            IAgent agent;

            if (!Agents.TryGetValue(p.AgentID, out agent))
            {
                return;
            }

            ParcelInfo parcelInfo;

            if (!Parcels.TryGetValue(p.LocalID, out parcelInfo))
            {
                return;
            }

            double passHours = parcelInfo.PassHours;
            int    passPrice = parcelInfo.PassPrice;

            if ((parcelInfo.Flags & ParcelFlags.UsePassList) == 0 || passPrice < 0 || passHours <= 0)
            {
                return;
            }

            EconomyServiceInterface economyService = agent.EconomyService;

            if (economyService == null)
            {
                agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyNoEconomyConfigured", "Unable to buy. No economy configured."), ID);
                return;
            }

            var extendSeconds = (ulong)TimeSpan.FromHours(passHours).Seconds;

            if (parcelInfo.GroupOwned)
            {
                economyService.TransferMoney(agent.Owner, parcelInfo.Group, new LandpassSaleTransaction(
                                                 GridPosition,
                                                 ID,
                                                 Name)
                {
                    ParcelID   = parcelInfo.ID,
                    ParcelName = parcelInfo.Name,
                    PassHours  = passHours
                }, passPrice, () => Parcels.LandpassList.ExtendExpiry(ID, parcelInfo.ID, agent.Owner, extendSeconds));
            }
            else
            {
                economyService.TransferMoney(agent.Owner, parcelInfo.Owner, new LandpassSaleTransaction(
                                                 GridPosition,
                                                 ID,
                                                 Name)
                {
                    ParcelID   = parcelInfo.ID,
                    ParcelName = parcelInfo.Name,
                    PassHours  = passHours
                }, passPrice, () => Parcels.LandpassList.ExtendExpiry(ID, parcelInfo.ID, agent.Owner, extendSeconds));
            }
        }