Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Cancels a trade with the given ID.
        /// </summary>
        /// <param name="tradeId">Trade ID</param>
        /// <exception cref="ArgumentException">Trade ID cannot be null or empty</exception>
        public void CancelTrade(string tradeId)
        {
            if (string.IsNullOrEmpty(tradeId))
            {
                throw new ArgumentException("Trade ID cannot be null or empty.", nameof(tradeId));
            }

            lock (activeTradesLock)
            {
                // Make sure the trade exists
                if (!activeTrades.ContainsKey(tradeId))
                {
                    return;
                }
            }

            // Do nothing if not online
            if (!(netClient.Connected || authenticator.Authenticated || userManager.LoggedIn))
            {
                return;
            }

            // Create and pack a CompleteTradePacket
            UpdateTradeStatusPacket packet = new UpdateTradeStatusPacket
            {
                SessionId = authenticator.SessionId,
                Uuid      = userManager.Uuid,
                TradeId   = tradeId,
                Cancelled = true
            };
            Any packedPacket = ProtobufPacketHelper.Pack(packet);

            // Send it on its way
            netClient.Send(MODULE_NAME, packedPacket.ToByteArray());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends a status update for the given trade to the server.
        /// </summary>
        /// <param name="tradeId">Trade ID</param>
        /// <param name="accepted">Accepted state</param>
        /// <param name="cancelled">Cancel the trade</param>
        public void UpdateStatus(string tradeId, bool?accepted = null, bool?cancelled = null)
        {
            // Do nothing if not online
            if (!(netClient.Connected && authenticator.Authenticated && userManager.LoggedIn))
            {
                return;
            }

            // Create and pack an UpdateTradeStatus packet
            UpdateTradeStatusPacket packet = new UpdateTradeStatusPacket
            {
                SessionId = authenticator.SessionId,
                Uuid      = userManager.Uuid,
                TradeId   = tradeId,
                Accepted  = accepted.HasValue ? accepted.Value : false,
                Cancelled = cancelled.HasValue ? cancelled.Value : false
            };
            Any packedPacket = ProtobufPacketHelper.Pack(packet);

            // Send it on its way
            netClient.Send(MODULE_NAME, packedPacket.ToByteArray());
        }