示例#1
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));
        }
示例#2
0
        /// <summary>
        /// Sends an item update for the given trade with the given items to the server.
        /// </summary>
        /// <param name="tradeId">Trade ID</param>
        /// <param name="items">Items on offer</param>
        /// <param name="token">Unique request token</param>
        public void UpdateItems(string tradeId, IEnumerable <ProtoThing> items, string token = "")
        {
            // Do nothing if not online
            if (!(netClient.Connected && authenticator.Authenticated && userManager.LoggedIn))
            {
                return;
            }

            // Create and pack an UpdateTradeItems packet
            UpdateTradeItemsPacket packet = new UpdateTradeItemsPacket
            {
                SessionId = authenticator.SessionId,
                Uuid      = userManager.Uuid,
                TradeId   = tradeId,
                Items     = { items },
                Token     = token
            };
            Any packedPacket = ProtobufPacketHelper.Pack(packet);

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