Esempio n. 1
0
        protected virtual void B_Other(string evt, byte[] txt)
        {
            try
            {
                var data = new VMEODSecureTradePlayer(txt);

                NotifyChange(OtherOffer, data, OtherOfferCatalog.Position);

                OtherOffer = data;
                SetOtherPerson(data.PlayerPersist);
                BuildOffer(OtherOffer.ObjectOffer, OtherOfferCatalog);

                OtherAvatarAmount.CurrentText  = data.MoneyOffer.ToString();
                OtherAcceptedButton.ForceState = data.Accepted?3:0;
            }
            catch (Exception) { }
        }
Esempio n. 2
0
        protected virtual void B_Me(string evt, byte[] txt)
        {
            try
            {
                var data = new VMEODSecureTradePlayer(txt);

                NotifyChange(MyOffer, data, OfferCatalog.Position);

                MyOffer = data;
                SetMyPerson(data.PlayerPersist);
                BuildInventory();
                BuildOffer(MyOffer.ObjectOffer, OfferCatalog);

                //our payout money is synced a second after we stop typing.
                AcceptButton.Selected = MyOffer.Accepted;
            }
            catch (Exception) { }
        }
Esempio n. 3
0
        private void NotifyChange(VMEODSecureTradePlayer prev, VMEODSecureTradePlayer now, Vector2 position)
        {
            if (prev.MoneyOffer != now.MoneyOffer)
            {
                //money changed
                NotifyRects.Add(new Tuple <Rectangle, float>(new Rectangle(position.ToPoint() + new Point((Small800)?229:453, 7), new Point(102, 29)), 1.0f));
            }

            for (int i = 0; i < 5; i++)
            {
                var pobj = prev.ObjectOffer[i];
                var nobj = now.ObjectOffer[i];
                if (((nobj == null) != (pobj == null)) || (nobj != null && (nobj.GUID != pobj.GUID || nobj.PID != pobj.PID)))
                {
                    NotifyRects.Add(new Tuple <Rectangle, float>(new Rectangle(position.ToPoint() + new Point(i * 45 + 1, 2), new Point(43, 43)), 1.0f));
                }
            }
        }
Esempio n. 4
0
        public void SecureTrade(VM vm, VMEODSecureTradePlayer p1, VMEODSecureTradePlayer p2, VMAsyncSecureTradeCallback callback)
        {
            var moneyMove = p1.MoneyOffer - p2.MoneyOffer;

            Host.InBackground(() =>
            {
                var cityMessages = new List <NotifyLotRoommateChange>();
                using (var db = DAFactory.Get())
                {
                    var failState = VMEODSecureTradeError.SUCCESS;
                    var result    = db.Avatars.Transaction(p1.PlayerPersist, p2.PlayerPersist, moneyMove, 9, () =>
                    {
                        //this is all part of the transaction. returning false in here will undo all sql queries we make.

                        //try to transfer the in-inventory objects.
                        VMEODSecureTradeObject lot1 = null;
                        VMEODSecureTradeObject lot2 = null;

                        var objs = new List <uint>();
                        foreach (var item in p1.ObjectOffer)
                        {
                            if (item == null)
                            {
                                continue;
                            }
                            if (item.LotID > 0)
                            {
                                lot1 = item;
                                continue;
                            }
                            objs.Add(item.PID);
                        }
                        var count = db.Objects.ChangeInventoryOwners(objs, p1.PlayerPersist, p2.PlayerPersist);
                        //if the number of rows changed does not equal the number we wanted to change, the transaction is invalid.
                        if (count != objs.Count)
                        {
                            failState = VMEODSecureTradeError.MISSING_OBJECT;
                            return(false);
                        }

                        objs = new List <uint>();
                        foreach (var item in p2.ObjectOffer)
                        {
                            if (item == null)
                            {
                                continue;
                            }
                            if (item.LotID > 0)
                            {
                                lot2 = item;
                                continue;
                            }
                            objs.Add(item.PID);
                        }
                        count = db.Objects.ChangeInventoryOwners(objs, p2.PlayerPersist, p1.PlayerPersist);
                        if (count != objs.Count)
                        {
                            failState = VMEODSecureTradeError.MISSING_OBJECT;
                            return(false);
                        }

                        for (int i = 0; i < 2; i++)
                        {
                            var iLot   = (i == 0) ? lot1 : lot2;
                            var myP    = (i == 0) ? p1 : p2;
                            var otherP = (i == 0) ? p2 : p1;
                            if (iLot != null)
                            {
                                var lot = db.Lots.Get((int)iLot.LotID);
                                if (lot.owner_id != myP.PlayerPersist && (i == 0 || lot1 == null))
                                {
                                    failState = VMEODSecureTradeError.WRONG_OWNER_LOT;
                                    return(false);
                                }
                                if (lot.owner_id != null)
                                {
                                    db.Roommates.RemoveRoommate(lot.owner_id.Value, lot.lot_id);
                                }
                                //evict this roommate from any lots they are on
                                var otherLots = db.Roommates.GetAvatarsLots(otherP.PlayerPersist);
                                foreach (var olot in otherLots)
                                {
                                    db.Roommates.RemoveRoommate(olot.avatar_id, olot.lot_id);
                                    if (olot.permissions_level == 2)
                                    {
                                        if (i == 0 && lot2 != null && lot2.PID == olot.lot_id)
                                        {
                                            //if this lot is being traded later, leave its owner hanging until we can get it again
                                            db.Lots.UpdateOwner(olot.lot_id, null);
                                        }
                                        else
                                        {
                                            db.Lots.ReassignOwner(olot.lot_id);
                                        }
                                    }

                                    //our lot will be changed. update it if we're not giving them our lot (the lot may need to be deleted, and our
                                    //objects removed, or if we're not giving them the objects on our lot (they must be removed)
                                    //if the lot's open then we need to tell it we're no longer the roommate.
                                    //we can't detect this from this side, so do it anyways.
                                    cityMessages.Add(new NotifyLotRoommateChange()
                                    {
                                        LotId    = olot.lot_id,
                                        AvatarId = olot.avatar_id,
                                        Change   = ChangeType.REMOVE_ROOMMATE
                                    });
                                }
                                //create the other avatar as a roommate in this lot, then assign them as owner
                                db.Roommates.CreateOrUpdate(new DbRoommate()
                                {
                                    avatar_id = otherP.PlayerPersist, lot_id = lot.lot_id, permissions_level = 2
                                });
                                db.Lots.UpdateOwner(lot.lot_id, otherP.PlayerPersist);

                                if (iLot.GUID == 2)
                                {
                                    //give them our objects. be extra cautious here and don't transfer the lot if the object count differs.
                                    var objectsTransferred = db.Objects.UpdateObjectOwnerLot(myP.PlayerPersist, lot.lot_id, otherP.PlayerPersist);
                                    if (objectsTransferred != iLot.ObjectCount)
                                    {
                                        failState = VMEODSecureTradeError.MISSING_OBJECT_LOT;
                                        return(false);
                                    }
                                }

                                cityMessages.Add(new NotifyLotRoommateChange()
                                {
                                    LotId     = lot.lot_id,
                                    AvatarId  = otherP.PlayerPersist,
                                    Change    = (iLot.GUID == 2) ? ChangeType.BECOME_OWNER_WITH_OBJECTS : ChangeType.BECOME_OWNER,
                                    ReplaceId = (iLot.GUID == 2) ? myP.PlayerPersist : 0
                                });
                            }
                        }

                        return(failState == VMEODSecureTradeError.SUCCESS);
                    });
                    if (failState == VMEODSecureTradeError.SUCCESS && !result.success)
                    {
                        failState = VMEODSecureTradeError.MISSING_MONEY;
                    }

                    vm.SendCommand(new VMNetAsyncResponseCmd(0, new VMTransferFundsState
                    {
                        Responded      = true,
                        Success        = result.success,
                        TransferAmount = result.amount,
                        UID1           = p1.PlayerPersist,
                        Budget1        = (uint)result.source_budget,
                        UID2           = p2.PlayerPersist,
                        Budget2        = (uint)result.dest_budget
                    }));
                    //send out updated inventories to both avatars
                    UpdateInventoryFor(vm, p1.PlayerPersist);
                    UpdateInventoryFor(vm, p2.PlayerPersist);
                    callback(failState);

                    if (failState == VMEODSecureTradeError.SUCCESS)
                    {
                        var conn          = City.GetByShardId(Context.ShardId);
                        object[] messages = cityMessages.ToArray();
                        conn.Write(messages);
                    }
                }
            });
        }
Esempio n. 5
0
 public void SecureTrade(VM vm, VMEODSecureTradePlayer p1, VMEODSecureTradePlayer p2, VMAsyncSecureTradeCallback callback)
 {
 }