예제 #1
0
        /// <summary>
        /// Handles incoming <see cref="UpdateTradeStatusPacket"/>s.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="UpdateTradeStatusPacket"/></param>
        private void updateTradeStatusPacketHandler(string connectionId, UpdateTradeStatusPacket packet)
        {
            lock (activeTradesLock)
            {
                // Ignore packets from trades we don't have
                if (!activeTrades.ContainsKey(packet.TradeId))
                {
                    return;
                }

                Trade trade = activeTrades[packet.TradeId];

                // Try set our accepted state
                trade.TrySetAccepted(userManager.Uuid, packet.Accepted);

                // Try get the other party's UUID
                if (trade.TryGetOtherParty(userManager.Uuid, out string otherPartyUuid))
                {
                    // Try set their accepted state
                    trade.TrySetAccepted(otherPartyUuid, packet.OtherPartyAccepted);
                }
            }

            // Raise the trade update event
            OnTradeUpdateSuccess?.Invoke(this, new TradeUpdateEventArgs(packet.TradeId));
        }
예제 #2
0
        /// <summary>
        /// Handles incoming <see cref="UpdateTradeItemsPacket"/>s.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="UpdateTradeItemsPacket"/></param>
        private void updateTradeItemsPacketHandler(string connectionId, UpdateTradeItemsPacket packet)
        {
            lock (activeTradesLock)
            {
                // Ignore packets from trades we don't have
                if (!activeTrades.ContainsKey(packet.TradeId))
                {
                    return;
                }

                Trade trade = activeTrades[packet.TradeId];

                // Set our items on offer
                trade.TrySetItemsOnOffer(userManager.Uuid, packet.Items);

                RaiseLogEntry(new LogEventArgs(string.Format("Got items {0} for us", packet.Items.Count), LogLevel.DEBUG));

                // Try get the other party's UUID
                if (trade.TryGetOtherParty(userManager.Uuid, out string otherPartyUuid))
                {
                    // Set the other party's items on offer
                    trade.TrySetItemsOnOffer(otherPartyUuid, packet.OtherPartyItems);

                    RaiseLogEntry(new LogEventArgs(string.Format("Got items {0} for {1}", packet.Items.Count, otherPartyUuid), LogLevel.DEBUG));
                }
            }

            // Raise the trade update event
            OnTradeUpdateSuccess?.Invoke(this, new TradeUpdateEventArgs(packet.TradeId));
        }
예제 #3
0
        /// <summary>
        /// Handles incoming <see cref="UpdateTradeItemsResponsePacket"/>s.
        /// </summary>
        /// <param name="connectionId">Original connection ID</param>
        /// <param name="packet">Incoming <see cref="UpdateTradeItemsResponsePacket"/></param>
        private void updateTradeItemsResponsePacketHandler(string connectionId, UpdateTradeItemsResponsePacket packet)
        {
            lock (activeTradesLock)
            {
                // Ignore packets from trades we don't have
                if (!activeTrades.ContainsKey(packet.TradeId))
                {
                    return;
                }

                Trade trade = activeTrades[packet.TradeId];

                if (packet.Success)
                {
                    // Set our items on offer
                    trade.TrySetItemsOnOffer(userManager.Uuid, packet.Items);

                    RaiseLogEntry(new LogEventArgs(string.Format("Got items {0} for us", packet.Items.Count), LogLevel.DEBUG));

                    // Raise the successful trade update event
                    OnTradeUpdateSuccess?.Invoke(this, new TradeUpdateEventArgs(packet.TradeId, packet.Token));
                }
                else
                {
                    // Raise the failed trade update event
                    // Do this before removing the trade so its state is preserved for anything that needs handle it
                    OnTradeUpdateFailure?.Invoke(this, new TradeUpdateEventArgs(packet.TradeId, packet.FailureReason, packet.FailureMessage, packet.Token));

                    // Check the failure reason
                    switch (packet.FailureReason)
                    {
                    case TradeFailureReason.TradeDoesNotExist:
                        lock (activeTradesLock)
                        {
                            // Remove the trade since it doesn't exist
                            activeTrades.Remove(packet.TradeId);
                        }
                        break;
                    }
                }
            }
        }