Пример #1
0
        public override void OnTradeTimeout()
        {
            //Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg,
            //                                  "Trade timeout.");
            Log.Warn("Trade timeout.");
            Log.Info("Getting Inventory");
            Bot.GetInventory();

            int ItemsLeft = 0;

            if (ManageCrates)
            {
                ItemsLeft = GetTradeItems(Bot.MyInventory, TransferCrates).Count;
            }
            else
            {
                ItemsLeft = GetTradeItems(Bot.MyInventory, 0).Count;
            }

            if (ItemsLeft > 0)
            {
                Log.Debug("Still have items to trade");
                //errorOcccured = true;
                CancelTrade();
                OnTradeClose();
            }
            else
            {
                Log.Debug("No items in inventory, removing");
                TradeReadyBots.Remove(mySteamID);
                CancelTrade();
                OnTradeClose();
                Bot.StopBot();
            }
        }
Пример #2
0
        public override void OnLoginCompleted()
        {
            List <Inventory.Item> itemsToTrade = new List <Inventory.Item>();

            // Must get inventory here
            Log.Info("Getting Inventory");
            Bot.GetInventory();

            // Optional Crafting
            if (AutoCraftWeps)
            {
                AutoCraftAll();
            }

            if (ManageCrates)
            {
                DeleteSelectedCrates(DeleteCrates);

                // One more break before updating inventory
                Thread.Sleep(500);
                Bot.GetInventory();

                itemsToTrade = GetTradeItems(Bot.MyInventory, TransferCrates);
            }
            else
            {
                itemsToTrade = GetTradeItems(Bot.MyInventory, 0);
            }

            if (!BotItemMap.ContainsKey(mySteamID))
            {
                BotItemMap.Add(mySteamID, itemsToTrade);
                Admins.Add(mySteamID);
            }

            Log.Info("[Giving] " + Bot.DisplayName + " checking in. " + BotItemMap.Count + " of " + NumberOfBots + " Bots.");

            if (!Bot.MyInventory.IsFreeToPlay())
            {
                if (BotItemMap[mySteamID].Count > 0)
                {
                    TradeReadyBots.Add(mySteamID);
                    Log.Info(Bot.DisplayName + " has items. Added to list." + TradeReadyBots.Count + " Bots waiting to trade.");
                }
                else
                {
                    Log.Warn(Bot.DisplayName + " did not have an item to trade.");
                    Log.Warn("Stopping bot.");
                    Bot.StopBot();
                }
            }
            else
            {
                // Requires more info on f2p item characteristics.
                Log.Warn(Bot.DisplayName + " is free to play. F2P trading is not configured yet.");
                Bot.StopBot();
            }
        }
Пример #3
0
        public void TradeAccept()
        {
            if (OtherSID == MainSID || OtherSID == CrateSID)
            {
                Thread.Sleep(100);
                Success = AcceptTrade();
                if (Success)
                {
                    Log.Success("Trade was Successful!");
                    totalAdded += Trade.OtherOfferedItems.Count;
                    TradeReadyBots.Remove(mySteamID);
                    //Trade.Poll();
                    //Bot.StopBot();
                }
                else
                {
                    Log.Warn("Trade might have failed.");
                    Bot.GetInventory();

                    int ItemsLeft = 0;

                    if (ManageCrates)
                    {
                        ItemsLeft = GetTradeItems(Bot.OtherInventory, TransferCrates).Count;
                    }
                    else
                    {
                        ItemsLeft = GetTradeItems(Bot.OtherInventory, 0).Count;
                    }

                    if (ItemsLeft > 0)
                    {
                        Log.Warn("Bot has no items, trade may have succeeded. Removing bot.");
                        TradeReadyBots.Remove(mySteamID);
                        CancelTrade();

                        Log.Warn("[Receiving] TRADE CLOSED");
                        Bot.CloseTrade();
                        Bot.StopBot();
                    }
                }
            }
            else if (IsAdmin)
            {
                if (AcceptTrade())
                {
                    totalAdded += Trade.OtherOfferedItems.Count;
                    Log.Success("Trade was Successful!");
                }
                else
                {
                    Log.Warn("Trade might have failed.");
                    // Going to wait a little while to give the other bot time to finish prep if necessary.
                    Thread.Sleep(1000);
                }
                OnTradeClose();
            }
        }
Пример #4
0
        public void AddItems()
        {
            Thread.Sleep(500);

            Bot.GetInventory();

            Log.Debug("Adding all items.");

            uint added = AddItemsFromList(BotItemMap[mySteamID]);

            if (added > 0)
            {
                Log.Success("Added " + added + " items.");
                System.Threading.Thread.Sleep(50);
                if (!SendMessage("ready"))
                {
                    CancelTrade();
                    OnTradeClose();
                }
            }
            else
            {
                Log.Debug("Something's gone wrong.");
                Bot.GetInventory();
                int ItemsLeft = 0;

                if (ManageCrates)
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, TransferCrates).Count;
                }
                else
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, 0).Count;
                }

                if (ItemsLeft > 0)
                {
                    Log.Debug("Still have items to trade, aborting trade.");
                    //errorOcccured = true;
                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "failed");
                    OnTradeClose();
                }
                else
                {
                    Log.Debug("No items in bot inventory. This shouldn't be possible.");
                    TradeReadyBots.Remove(mySteamID);

                    CancelTrade();
                    OnTradeClose();
                    Bot.StopBot();
                }
            }
        }
Пример #5
0
        public override void OnTradeAccept()
        {
            bool success = AcceptTrade();

            if (success)
            {
                Log.Success("Trade was Successful!");
                OnTradeClose();
                Bot.StopBot();
            }
            else
            {
                Log.Warn("Trade might have failed.");
                OnTradeClose();
            }
        }
Пример #6
0
 public override void OnBotCommand(string command)
 {
     Log.Debug("Received command via console: " + command);
     if (command == "craft")
     {
         AutoCraftAll();
     }
     if (command == "stop")
     {
         Bot.StopBot();
     }
     if (command == "start")
     {
         Bot.RestartBot();
     }
 }
Пример #7
0
        public void TradeAccept()
        {
            Thread.Sleep(100);
            Success = AcceptTrade();

            if (Success)
            {
                Log.Success("Trade was Successful!");
                //Trade.Poll();
                //Bot.StopBot();
            }
            else
            {
                Log.Warn("Trade might have failed.");
                Bot.GetInventory();

                int ItemsLeft = 0;

                if (ManageCrates)
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, TransferCrates).Count;
                }
                else
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, 0).Count;
                }

                if (ItemsLeft > 0)
                {
                    Log.Warn("Bot has no items, trade may have succeeded. Removing bot.");
                    TradeReadyBots.Remove(mySteamID);
                    OnTradeClose();
                    Bot.StopBot();
                }
            }
        }
Пример #8
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!Directory.Exists(BotManager.DATA_FOLDER))
            {
                Directory.CreateDirectory(BotManager.DATA_FOLDER);
            }

            if (!File.Exists(BotManager.DATA_FOLDER + "settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json"))
                {
                    File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr);
                }

                return;
            }

            Configuration configObject;

            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is corrupt or improperly formatted.");
                return;
            }

            if (botIndex >= configObject.Bots.Length)
            {
                Console.WriteLine("Invalid bot index.");
                return;
            }

            Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey,
                            (b2, sid) => BotManager.UserHandlerCreator(b2, sid, configObject), true, true);

            Console.Title = "Bot Manager";
            b.StartBot();

            string AuthSet     = "auth";
            string ExecCommand = "exec";
            string ExitCommand = "exit";

            // this loop is needed to keep the botmode console alive.
            // instead of just sleeping, this loop will handle console input
            while (true)
            {
                string inputText = Console.ReadLine();

                if (string.IsNullOrEmpty(inputText))
                {
                    continue;
                }

                // Small parse for console input
                var c = inputText.Trim();

                var cs = c.Split(' ');

                if (cs.Length > 1)
                {
                    if (cs[0].Equals(AuthSet, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.AuthCode = cs[1].Trim();
                    }
                    else if (cs[0].Equals(ExecCommand, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.HandleBotCommand(c.Remove(0, cs[0].Length + 1));
                    }
                    else if (cs[0].ToLower() == ExitCommand)
                    {
                        b.StopBot();
                    }
                }
            }
        }
Пример #9
0
        // This mode is to run a single Bot until it's terminated.
        private static void BotMode(int botIndex)
        {
            if (!Directory.Exists(BotManager.DATA_FOLDER))
            {
                Directory.CreateDirectory(BotManager.DATA_FOLDER);
            }

            if (!File.Exists(BotManager.DATA_FOLDER + "settings.json"))
            {
                Console.WriteLine("No settings.json file found.");
                if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json"))
                {
                    File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr);
                }

                return;
            }

            Configuration configObject;
            try
            {
                configObject = Configuration.LoadConfiguration("settings.json");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                // handle basic json formatting screwups
                Console.WriteLine("settings.json file is corrupt or improperly formatted.");
                return;
            }

            if (botIndex >= configObject.Bots.Length)
            {
                Console.WriteLine("Invalid bot index.");
                return;
            }

            Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey,
                (b2, sid) => BotManager.UserHandlerCreator(b2, sid, configObject), true, true);
            Console.Title = "Bot Manager";
            b.StartBot();

            string AuthSet = "auth";
            string ExecCommand = "exec";
            string ExitCommand = "exit";

            // this loop is needed to keep the botmode console alive.
            // instead of just sleeping, this loop will handle console input
            while (true)
            {
                string inputText = Console.ReadLine();

                if (string.IsNullOrEmpty(inputText))
                    continue;

                // Small parse for console input
                var c = inputText.Trim();

                var cs = c.Split(' ');

                if (cs.Length > 1)
                {
                    if (cs[0].Equals(AuthSet, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.AuthCode = cs[1].Trim();
                    }
                    else if (cs[0].Equals(ExecCommand, StringComparison.CurrentCultureIgnoreCase))
                    {
                        b.HandleBotCommand(c.Remove(0, cs[0].Length + 1));
                    }
                    else if (cs[0].ToLower() == ExitCommand)
                    {
                        b.StopBot();
                    }
                }
            }
        }
Пример #10
0
        public void AddItems()
        {
            Log.Info("Getting Inventory");
            Bot.GetInventory();

            var AllItems = new List <Inventory.Item>();

            if (OtherSID == CrateSID)
            {
                if (ManageCrates)
                {
                    AllItems = GetCrates(Bot.MyInventory, TransferCrates);
                }
                else
                {
                    return;
                }
            }
            else if (OtherSID == MainSID)
            {
                AllItems = GetTradeItems(Bot.MyInventory, TransferCrates);
            }
            else
            {
                return;
            }

            Log.Debug("Adding items");
            uint added = AddItemsFromList(AllItems);

            if (added > 0 || AllItems.Count == 0)
            {
                Log.Info("Added " + added + " items.");
                System.Threading.Thread.Sleep(50);
                MeAdded = true;
                if (!SendMessage("ready"))
                {
                    CancelTrade();
                    OnTradeClose();
                }
            }
            else
            {
                Log.Debug("Something's gone wrong.");
                Bot.GetInventory();
                int ItemsLeft = 0;

                if (ManageCrates)
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, TransferCrates).Count;
                }
                else
                {
                    ItemsLeft = GetTradeItems(Bot.MyInventory, 0).Count;
                }

                if (ItemsLeft > 0)
                {
                    Log.Debug("Still have items to trade, aborting trade.");
                    //errorOcccured = true;
                    CancelTrade();
                    OnTradeClose();
                }
                else
                {
                    Log.Debug("No items in bot inventory. This shouldn't be possible.");
                    TradeReadyBots.Remove(mySteamID);
                    CancelTrade();

                    Log.Warn("[Receiving] TRADE CLOSED");
                    Bot.CloseTrade();
                    Bot.StopBot();
                }
            }
        }