コード例 #1
0
        /// <summary>
        /// Swaps the trade offer items of two trade partners and updates the database, hand item collection etc. The swap is aborted if the trade is invalid.
        /// </summary>
        /// <param name="partnerItemStrip">The itemStripHandler object of the trade partner session.</param>
        public void swapTradeOffers(itemStripHandler partnerItemStrip)
        {
            if (this.isTrading && partnerItemStrip.isTrading && (this.tradeOfferItemCount > 0 || partnerItemStrip.tradeOfferItemCount > 0)) // Can swap items
            {
                Database dbClient = new Database(true, false);
                if (!dbClient.Ready)
                {
                    return;
                }

                foreach (int myTradeOfferItemID in this.tradeOfferItemIDs)
                {
                    stripItem lItem = this.getHandItem(myTradeOfferItemID);
                    if (lItem == null)
                    {
                        return;                                                                                                              // Trade invalid
                    }
                    this.removeHandItem(myTradeOfferItemID, false);                                                                          // Remove from this item strip
                    partnerItemStrip.addHandItem(lItem);                                                                                     // Add to partner item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + partnerItemStrip.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                foreach (int partnerTradeOfferItemID in partnerItemStrip.tradeOfferItemIDs)
                {
                    stripItem lItem = partnerItemStrip.getHandItem(partnerTradeOfferItemID);
                    if (lItem == null)
                    {
                        return;                                                                                                  // Trade invalid
                    }
                    partnerItemStrip.removeHandItem(partnerTradeOfferItemID, false);                                             // Remove from partner item strip
                    this.addHandItem(lItem);                                                                                     // Add to this item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + this.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                dbClient.Close(); // Close database connection
            }
        }
コード例 #2
0
ファイル: itemStripHandler.cs プロジェクト: habb0/Woodpecker
        /// <summary>
        /// Swaps the trade offer items of two trade partners and updates the database, hand item collection etc. The swap is aborted if the trade is invalid.
        /// </summary>
        /// <param name="partnerItemStrip">The itemStripHandler object of the trade partner session.</param>
        public void swapTradeOffers(itemStripHandler partnerItemStrip)
        {
            if (this.isTrading && partnerItemStrip.isTrading && (this.tradeOfferItemCount > 0 || partnerItemStrip.tradeOfferItemCount > 0)) // Can swap items
            {
                Database dbClient = new Database(true, false);
                if (!dbClient.Ready)
                    return;

                foreach (int myTradeOfferItemID in this.tradeOfferItemIDs)
                {
                    stripItem lItem = this.getHandItem(myTradeOfferItemID);
                    if (lItem == null)
                        return; // Trade invalid

                    this.removeHandItem(myTradeOfferItemID, false); // Remove from this item strip
                    partnerItemStrip.addHandItem(lItem); // Add to partner item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + partnerItemStrip.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                foreach (int partnerTradeOfferItemID in partnerItemStrip.tradeOfferItemIDs)
                {
                    stripItem lItem = partnerItemStrip.getHandItem(partnerTradeOfferItemID);
                    if (lItem == null)
                        return; // Trade invalid

                    partnerItemStrip.removeHandItem(partnerTradeOfferItemID, false); // Remove from partner item strip
                    this.addHandItem(lItem); // Add to this item strip
                    dbClient.runQuery("UPDATE items SET ownerid = '" + this.userID + "' WHERE id = '" + lItem.ID + "' LIMIT 1"); // Update database
                }

                dbClient.Close(); // Close database connection
            }
        }
コード例 #3
0
ファイル: Session.cs プロジェクト: habb0/Woodpecker
        /// <summary>
        /// Destroys the session and clears up all used resources.
        /// </summary>
        public void Destroy()
        {
            if (this.isHoldingUser)
            {
                ObjectTree.Game.Users.removeUserSession(this.User.ID);
                this.leaveRoom(false);
                this.User = null;

                this.itemStripHandler.saveHandItems();
                this.itemStripHandler.Clear();
                this.itemStripHandler = null;
            }
            this.gameConnection.Abort();
            this.gameConnection = null;
        }