Пример #1
0
        public MasterBot()
        {
            //SaveFile saveFile = new SaveFile("file.test");
            //saveFile.Load();

            //saveFile.AddNode(new NodePath("data.xp"), new Node("353"));
            //saveFile.AddNode(new NodePath("data.inventory.stone"), new Node("5"));
            //saveFile.AddNode(new NodePath("data.inventory.copper"), new Node("5"));
            //saveFile.AddNode(new NodePath("data.inventory.iron"), new Node("5"));
            //saveFile.Save();

            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);

            MinimapColors.CreateColorCodes();

            mainForm = new MainForm(this);
            mainForm.FormClosing += delegate
            {
                Disconnect("Form Closing");
                mainThread.Stop();
            };
            mainThread = new SafeThread(() => { Application.Run(mainForm); });
            mainThread.Start();

            subBotHandler = new SubBotHandler(this, mainForm.BotTabPage);
            subBotHandler.AddSubBot((ASubBot)(room = new Room.Room(this)));
            subBotHandler.AddSubBot(new BlockPlaceTest(this));
            subBotHandler.AddSubBot(new Commands(this));
            subBotHandler.AddSubBot(new WorldEdit(this));
            subBotHandler.AddSubBot(new Protection(this));
            subBotHandler.AddSubBot(new ZombiesSubbot(this), false);
            subBotHandler.AddSubBot(new HouseBuilding(this));
            subBotHandler.AddSubBot(new RunFromGods(this), false);

            //////////////////////////////////////

            //PluginSectionHandler pluginSectionHandler = new PluginSectionHandler();

            Action<string[]> lambda = new Action<string[]>((string[] pluginFiles) =>
                {
                    for (int j = 0; j < pluginFiles.Count(); j++)
                    {
                        if (Path.GetFileName(pluginFiles[j]).EndsWith(".dll")
                            && Path.GetFileName(pluginFiles[j]) != "PlayerIOClient.dll"
                            && Path.GetFileName(pluginFiles[j]) != "MasterBotLib.dll"
                            && Path.GetFileName(pluginFiles[j]) != "Skylight.dll"
                            && Path.GetFileName(pluginFiles[j]) != "libnoise.dll")
                        {
                            Assembly.LoadFrom(Path.GetFullPath(pluginFiles[j]));

                            //Loop through all opened assemblies in the current AppDomain
                            foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
                            {
                                foreach (Type t in a.GetTypes())
                                {
                                    if (t.GetInterface("IPlugin") != null)
                                    {
                                        try
                                        {
                                            plugins.Add(a);
                                            IPlugin pluginclass = Activator.CreateInstance(t) as IPlugin;
                                            pluginclass.PerformAction(this);
                                            break;
                                        }
                                        catch (Exception e)
                                        {
                                            this.mainForm.Console.WriteLine("%eError loading plugin(may be false): " + e.Message);
                                        }
                                    }
                                }
                            }

                            /////////////////////////////////////////
                            //  OLD /////////////////////////////////
                            /////////////////////////////////////////

                            /*string text;
                            StreamReader reader = new StreamReader(pluginFiles[j]);
                            text = reader.ReadToEnd();
                            reader.Close();

                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.LoadXml(text);

                            List<IPlugin> plugins = (List<IPlugin>) pluginSectionHandler.Create(this, pluginFiles[j], xmlDoc);

                            foreach(IPlugin p in plugins)
                                p.PerformAction(this);*/

                        }
                    }
                });

            const string path = "plugins\\";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            lambda(Directory.GetFiles(path));

            string[] pluginDirectories = Directory.GetDirectories("plugins\\");

            for (int i = 0; i < pluginDirectories.Count(); i++)
            {
                lambda(Directory.GetFiles(pluginDirectories[i]));
            }
        }
Пример #2
0
        public ChatSayer(IBot bot)
        {
            this.bot = bot;

            chatThread = new SafeThread(() =>
                {
                    if (bot.Connected)
                    {
                        lock (messages)
                        {
                            if (messages.Count > 0)
                            {
                                Message message = messages.Dequeue();

                                if (message is MessageCommand)
                                {
                                    bot.Connection.Send(PlayerIOClient.Message.Create("say", message.Content));
                                }
                                else
                                {
                                    //message is PM or broadcast, may need to be split
                                    List<string> splitMessage = new List<string>();
                                    if (message is MessagePM)
                                    {
                                        MessagePM messagePM = (MessagePM)message;
                                        string totalMessage = message.Content;
                                        int length = 80 - (8 + messagePM.Receiver.Name.Length);
                                        while (totalMessage != "")
                                        {
                                            if (totalMessage.Length >= length)
                                            {
                                                splitMessage.Add(totalMessage.Substring(0, length));
                                                totalMessage = totalMessage.Remove(0, length);
                                            }
                                            else
                                            {
                                                splitMessage.Add(totalMessage);
                                                break;
                                            }
                                        }

                                        bot.Connection.Send(PlayerIOClient.Message.Create("say", "/pm " + messagePM.Receiver.Name + " " + splitMessage.First() + "  " + characters[character]));
                                        splitMessage.RemoveAt(0);
                                        foreach (string s in splitMessage)
                                        {
                                            messages.Enqueue(new MessagePM(s, messagePM.Receiver));
                                        }
                                    }
                                    else
                                    {
                                        string totalMessage = message.Content;
                                        int length = 77;
                                        while (totalMessage != "")
                                        {
                                            if (totalMessage.Length >= length)
                                            {
                                                splitMessage.Add(totalMessage.Substring(0, length));
                                                totalMessage = totalMessage.Remove(0, length);
                                            }
                                            else
                                            {
                                                splitMessage.Add(totalMessage);
                                                break;
                                            }
                                        }

                                        bot.Connection.Send(PlayerIOClient.Message.Create("say", splitMessage.First() + "  " + characters[character]));
                                        splitMessage.RemoveAt(0);
                                        foreach (string s in splitMessage)
                                        {
                                            messages.Enqueue(new Message(s));
                                        }
                                    }
                                }

                                character++;
                                if (character > characters.Length - 1)
                                    character = 0;

                                Thread.Sleep(interval);
                            }
                            else
                                Thread.Sleep(1);
                        }

                        /*-message.Split(
                        bot.Connection.Send(Message.Create("say", message));
                        "/pm " + receiver.Name + " " + message + "  " + characters[character]
                        message + "  " + characters[character]*/

                    }
                });

            chatThread.Start();
        }