Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.33k stars 910 forks source link

Trading Error. #163

Closed Tetrahedrite closed 11 years ago

Tetrahedrite commented 11 years ago

My Code :


using SteamKit2;
using System.Collections.Generic;
using SteamTrade;

namespace SteamBot
{
    public class SimpleUserHandler : UserHandler
    {
        public int ScrapPutUp;

        public int Added_Check;

        public SimpleUserHandler (Bot bot, SteamID sid) : base(bot, sid) {}

        public override bool OnFriendAdd () 
        {
            return true;
        }

        public override void OnFriendRemove () {}

        public override void OnMessage (string message, EChatEntryType type) 
        {
            Bot.SteamFriends.SendChatMessage(OtherSID, type, Bot.ChatResponse);
        }

        public override bool OnTradeRequest() 
        {
            return true;
        }

        public override void OnTradeError (string error) 
        {
            Bot.SteamFriends.SendChatMessage (OtherSID, 
                                              EChatEntryType.ChatMsg,
                                              "오 이런, 에러 발생!!: " + error + "."
                                              );
            Bot.log.Warn (error);
        }

        public override void OnTradeTimeout () 
        {
            Bot.SteamFriends.SendChatMessage (OtherSID, EChatEntryType.ChatMsg,
                                              "죄송하지만, 당신이 너무 오래 잠수를 하여 거래가 종료되었습니다.");
            Bot.log.Info ("유저가 잠수에 의해 킥됨.");
        }

        public override void OnTradeInit()
        {
            Trade.SendMessage("물품을 올려주십시오~");
        }

        public override void OnTradeAddItem (Schema.Item schemaItem, Inventory.Item inventoryItem) {}

        public override void OnTradeRemoveItem (Schema.Item schemaItem, Inventory.Item inventoryItem) {}

        public override void OnTradeMessage (string message) {}

        public override void OnTradeReady (bool ready) 
        {
            if (!ready)
            {
                Trade.SetReady (false);
            }
            else
            {
                if(Validate ())
                {
                    Added_Check = 0;

                    if (ScrapPutUp == 1)
                    {
                        if (Added_Check == 0)
                        {
                            Trade.AddItemByDefindex(58);
                            Trade.AddItemByDefindex(131);
                            Added_Check = 1;
                            System.Threading.Thread.Sleep(3000);
                            Trade.SetReady(true);
                            Log.Info("Added_Check = 1");
                        }

                        if (Added_Check == 2)
                        {
                            Trade.AddItemByDefindex(58);
                            Trade.AddItemByDefindex(131);
                            Trade.RemoveItemByDefindex(741);
                            Trade.RemoveItemByDefindex(460);
                            Added_Check = 1;
                            System.Threading.Thread.Sleep(3000);
                            Trade.SetReady(true);
                        }
                    }

                    System.Threading.Thread.Sleep(3000);
                    Trade.SetReady (true);

                }
                Trade.SendMessage ("폐기금속: " + ScrapPutUp);
            }
        }

        public override void OnTradeAccept() 
        {
            if (Validate() || IsAdmin)
            {
                bool success = Trade.AcceptTrade();

                if (success)
                {
                    Log.Success ("거래가 성사되었습니다!");
                }
                else
                {
                    Log.Warn ("거래가 실패하였습니다.");
                }
            }

            OnTradeClose ();
        }

        public bool Validate ()
        {            
            ScrapPutUp = 0;

            List<string> errors = new List<string> ();

            foreach (ulong id in Trade.OtherOfferedItems)
            {
                var item = Trade.OtherInventory.GetItem (id);
                if (item.Defindex == 5000)
                    ScrapPutUp++;
                else if (item.Defindex == 5001)
                    ScrapPutUp += 3;
                else if (item.Defindex == 5002)
                    ScrapPutUp += 9;
                else
                {
                    var schemaItem = Trade.CurrentSchema.GetItem (item.Defindex);
                    errors.Add ("아이템 " + schemaItem.Name + " 은 받지 않는 물건입니다.");
                }
            }

            if (ScrapPutUp < 1)
            {
                errors.Add ("최소 폐기 금속 1개를 올려야합니다.");
            }

/*            if (ScrapPutUp == 2)
            {
                if (Added_Check == 0)
                {
                    Trade.AddItemByDefindex(58);
                    Trade.AddItemByDefindex(131);
                    Trade.AddItemByDefindex(741);
                    Trade.AddItemByDefindex(460);
                    Added_Check = 2;
                }
                if (Added_Check == 1)
                {
                    Trade.AddItemByDefindex(741);
                    Trade.AddItemByDefindex(460);
                    Added_Check = 2;
                }
                if (Added_Check == 2)
                {
                    Log.Info("Added_Check 2 Again");
                }
            } */
            // send the errors
            if (errors.Count != 0)
                Trade.SendMessage("거래 에러 발생: ");
            foreach (string error in errors)
            {
                Trade.SendMessage(error);
            }

            return errors.Count == 0;
        }

    }

}

Why Trade Session Failed?

gamemaster1494 commented 11 years ago

Usually trade session fails becuase the bot fails to get its backpack (Whenever you trade and says Inventory not available) or steam trade timed out. Could also be steam servers down. Is the code erroring out? Or just the trade doesn't work?

Tetrahedrite commented 11 years ago

Oh, I solve it. It is only code error.