Пример #1
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            AppDomain currentDomain = default(AppDomain);

            currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += GlobalUnhandledExceptionHandler;

            Console.Title = "Akarr's steambot";

            config = new Config();
            if (!config.LoadConfig())
            {
                Console.WriteLine("Config file (config.cfg) can't be found or is corrupted ! Bot can't start.");
                Console.ReadKey();
                return;
            }

            PrintWelcomeMessage();

            if (config.DisplayLocation)
            {
                SendLocation();
            }

            if (args.Count() >= 1)
            {
                if (args[0] == "-update" && Directory.GetCurrentDirectory().ToString().EndsWith("tmp"))
                {
                    string destination = Directory.GetParent(Directory.GetCurrentDirectory()).ToString();
                    foreach (string newPath in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories))
                    {
                        string update = destination + "\\" + Path.GetFileName(newPath);
                        File.Copy(newPath, update, true);
                    }
                    string process = Directory.GetParent(Directory.GetCurrentDirectory()) + @"\ASteambot.exe";
                    Console.WriteLine("ASteambot UPDATED ! Restarting...");
                    Console.WriteLine(process);
                    Thread.Sleep(5000);
                    Process newAS = new Process();
                    newAS.StartInfo.WorkingDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).ToString();
                    newAS.StartInfo.FileName         = process;
                    newAS.StartInfo.Arguments        = "";
                    newAS.Start();
                    Environment.Exit(0);
                }
            }

            updater = new Updater();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Searching for updates...");
            Console.ForegroundColor = ConsoleColor.White;

            /*if(IsLinux() && !config.DisableAutoUpdate)
             * {
             *  Console.ForegroundColor = ConsoleColor.Red;
             *  Console.WriteLine("Updater has been reported to not work on Linux, updated manually.");
             *  Console.WriteLine("You can download the last release here :");
             *  Console.WriteLine("https://github.com/Arkarr/ASteambot/releases/latest");
             *  Console.ForegroundColor = ConsoleColor.White;
             * }*/

            if (File.Exists("./update.sh"))
            {
                File.Delete("./update.sh");
            }

            if (config.DisableAutoUpdate)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Updater disabled. Not fetching for last updates.");
                Console.ForegroundColor = ConsoleColor.White;
            }
            else if (!updater.CheckVersion(Regex.Match(BUILD_VERSION, "([^\\s]+)").Value))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Update found ! Updating...");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Title           = "Akarr's steambot - Updating...";

                updater.Update();

                string  path      = Directory.GetCurrentDirectory() + "/ASteambot.exe";
                Process asteambot = new Process();

                asteambot.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();

                if (IsLinux())
                {
                    asteambot.StartInfo.FileName = "setsid " + path + " '-update'";
                }
                else
                {
                    asteambot.StartInfo.FileName  = path;
                    asteambot.StartInfo.Arguments = "-update";
                }

                Thread.Sleep(3000);

                asteambot.Start();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Update done ! Restarting...");
                Console.ForegroundColor = ConsoleColor.White;

                Environment.Exit(0);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Already up to date !");
                Console.ForegroundColor = ConsoleColor.White;
            }

            //WebInterfaceHelper.AddTrade(new SteamTrade.TradeOffer.TradeOffer(null, new SteamKit2.SteamID()));

            steambotManager = new Manager(config);
            threadManager   = new Thread(new ThreadStart(steambotManager.Start));
            threadManager.CurrentUICulture = new CultureInfo("en-US");
            threadManager.Start();

            AttemptLoginBot(config.SteamUsername, config.SteamPassword, config.SteamAPIKey);

            while (steambotManager.OnlineBots.Count < 1)
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));
            }

            steambotManager.SelectFirstBot();

            if (!IsLinux())
            {
                if (File.Exists("website.zip"))
                {
                    Console.WriteLine("Website not extracted ! Doing that now...");
                    if (!Directory.Exists("website"))
                    {
                        Directory.CreateDirectory("website");
                    }
                    ZipFile.ExtractToDirectory("website.zip", "./website");
                    File.Delete("website.zip");
                    Console.WriteLine("Done !");
                }

                if (Directory.Exists("/website/"))
                {
                    httpsrv = new HTTPServer("/website/", 85);
                    Console.WriteLine("HTTP Server started on port : " + httpsrv.Port + ">>> http://localhost:" + httpsrv.Port + "/index.html");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Website folder not present, can't start web interface. Re-download ASteambot from original github.");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("HTTP Server disabled for UNIX users. Wait for a fix :) !");
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.Title = "Akarr's steambot";

            string command = "";

            while (command != "quit")
            {
                Console.Write("> ");
                command = Console.ReadLine();
                steambotManager.Command(command);
            }

            if (httpsrv != null)
            {
                httpsrv.Stop();
            }
        }