Ejemplo n.º 1
0
        void ProcessCurrentTrade()
        {
            if (CurrentTrade == null)
                return;

            CurrentTrade.Update();

            TradeEvent @event = null;
            while (CurrentTrade.Events.TryDequeue(out @event))
            {
                //Logger.WriteLine("Got event: " + evt.type);
                HandleTradeEvent(CurrentTrade, @event);
            }

            if (CurrentTrade.Status != ETradeTransactionStatus.InProgress)
                CurrentTrade = null;
        }
Ejemplo n.º 2
0
 void HandleTradeEvent(TradeSession trade, TradeEvent @event)
 {
     switch (@event.type)
     {
     case ETradeEventType.Initialized:
         HandleTradeInitialized(trade, @event);
         break;
     case ETradeEventType.Message:
         HandleTradeMessage(trade, @event);
         break;
     case ETradeEventType.ItemAdded:
         HandleTradeItemAdded(trade, @event);
         break;
     case ETradeEventType.ItemRemoved:
         var itemRemoved = trade.ForeignInventory.LookupItem(@event.item);
         Logger.WriteLine("Item removed: " + itemRemoved.details.name);
         break;
     case ETradeEventType.Confirmed:
         HandleTradeConfirmed(trade, @event);
         break;
     case ETradeEventType.InventoryLoaded:
         Logger.WriteLine("Inventory loaded: " + @event.ToString());
         break;
     case ETradeEventType.ForeignInventoryLoaded:
         Logger.WriteLine("Foreign Inventory loaded: " + @event.ToString());
         break;
     case ETradeEventType.Ready:
         Logger.WriteLine("Trader is ready to trade.");
         break;
     case ETradeEventType.Unready:
         Logger.WriteLine("Trader is not ready to trade.");
         break;
     case ETradeEventType.Finished:
         var s = string.Format("Trade is finished: " + trade.Status);
         if (trade.Status == ETradeTransactionStatus.Finished)
             s += string.Format(" id = {0}", @event.tradeId);
         Logger.WriteLine(s);
         break;
     default:
         Logger.WriteLine("Unhandled trade event: " + @event);
         break;
     }
 }
Ejemplo n.º 3
0
        void HandleTradeItemsCommand(string msg, TradeSession trade)
        {
            trade.SendChatMessage("Not implemented yet!");
            return;

            var sb = new StringBuilder();
            sb.AppendLine("Items:");

            foreach (var item in trade.ItemsToReceive)
            {
                sb.AppendLine(string.Format("{0} | {1}", item.id,
                    item.details.name));
            }

            trade.SendChatMessage(sb.ToString());
        }
Ejemplo n.º 4
0
 void HandleTradeCancelCommand(string msg, TradeSession trade)
 {
     trade.CancelTrade();
 }
Ejemplo n.º 5
0
 void HandleTradeConfirmCommand(string msg, TradeSession trade)
 {
     trade.Confirm();
 }
Ejemplo n.º 6
0
        void HandleTradeRemoveCommand(string msg, TradeSession trade)
        {
            string[] args = msg.Split(' ');
            if (args.Length < 2)
            {
                trade.SendChatMessage("Invalid arguments.");
                return;
            }

            var pattern = string.Format(".*{0}.*",
                msg.Substring(msg.IndexOf(" ")).Trim());

            if (string.IsNullOrWhiteSpace(pattern))
                return;

            UpdateBackpack();

            var assets = GetAssetsMatchingPattern(pattern);

            foreach (var asset in assets)
            {
                var item = GetItemFromDefIndex(asset.DefIndex);
                Logger.WriteLine("Removing from trade: {0}", item.Name);

                trade.RemoveItem(asset.Id);
            }
        }
Ejemplo n.º 7
0
 void HandleTradeHelpCommand(string msg, TradeSession trade)
 {
     OutputCommandsHelp<TradeCommand>("Trade",
         (s) => trade.SendChatMessage(s));
 }
Ejemplo n.º 8
0
 void HandleTradeReadyCommand(string msg, TradeSession trade)
 {
     trade.ToggleReady();
 }
Ejemplo n.º 9
0
        void HandleTradeTextCommand(TradeSession trade, TradeEvent @event)
        {
            SendChatDelegate sendDelegate = (sender, entry, text) =>
            {
                trade.SendChatMessage(text);
            };

            TradeCommand cmd;
            if (!HandleCommandCommon(
                @event.message, @event.sender, sendDelegate, out cmd))
                return;

            var messageMap = new Dictionary<TradeCommand, Action<string, TradeSession>>
            {
                { TradeCommand.Help, HandleTradeHelpCommand },
                { TradeCommand.Ready, HandleTradeReadyCommand },
                { TradeCommand.Add, HandleTradeAddCommand },
                { TradeCommand.Remove, HandleTradeRemoveCommand },
                { TradeCommand.Confirm, HandleTradeConfirmCommand },
                { TradeCommand.Items, HandleTradeItemsCommand },
                { TradeCommand.Cancel, HandleTradeCancelCommand },
            };

            Action<string, TradeSession> func;
            if (!messageMap.TryGetValue(cmd, out func))
            {
                Logger.WriteLine("Unhandled trade command: {0}", cmd);
                return;
            }

            func(@event.message, trade);
        }
Ejemplo n.º 10
0
        void HandleTradeInitialized(TradeSession trade, TradeEvent @event)
        {
            if (trade.Inventory != null)
                return;

            foreach (var ctx in @event.inventoryApps)
            {
                Logger.WriteLine("Loading inventory: " + ctx.name);
                trade.LoadInventory(SteamUser.SteamID, ctx.appid, ctx.contexts[0].id);
                return;
            }
        }
Ejemplo n.º 11
0
        void HandleTradeMessage(TradeSession trade, TradeEvent @event)
        {
            Logger.WriteLine("{0} says in trade: {1}",
                SteamFriends.GetFriendPersonaName(trade.OtherSteamId),
                @event.message);

            HandleTradeTextCommand(trade, @event);
        }
Ejemplo n.º 12
0
        void HandleTradeItemAdded(TradeSession trade, TradeEvent @event)
        {
            if (@event.item.appid != TF2App)
            {
                Logger.WriteLine("Ignored item: not TF2 item...");
                return;
            }

            var asset = trade.ForeignInventory.LookupItem(@event.item);
            var item = GetItemFromAsset(asset);

            if (item == null)
            {
                Logger.WriteLine("Unknown item added: " + @event.item);
                return;
            }

            Logger.WriteLine("Item added: " + item.ItemName);
        }
Ejemplo n.º 13
0
 void HandleTradeConfirmed(TradeSession trade, TradeEvent @event)
 {
     Logger.WriteLine("Trade confirmed.");
     trade.Confirm();
 }