示例#1
0
 /// <summary>
 /// Starts a server for remote clients to connect to on the specified port, with the specified password.
 /// </summary>
 /// <param name="MainBot">The main bot, which is used for sending messages from remote clients.</param>
 /// <param name="remotePort">The port to listen on.</param>
 /// <param name="remotePassword">The password to use. Does not have to be the same as the password of the bots account.</param>
 public void Start(ClassicBot MainBot, int remotePort, string remotePassword)
 {
     RemoteServer = new Server(remotePort,this);
     MinecraftBot = MainBot;
     _password = remotePassword;
     _port = remotePort;
 }
示例#2
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            double rx = (MaxVertex.X - MinVertex.X + 1) / 2d;
            double ry = (MaxVertex.Y - MinVertex.Y + 1) / 2d;
            double rz = (MaxVertex.Z - MinVertex.Z + 1) / 2d;

            radius.X = (float)(1 / (rx * rx));
            radius.Y = (float)(1 / (ry * ry));
            radius.Z = (float)(1 / (rz * rz));

            // find center points
            center.X = (float)((MinVertex.X + MaxVertex.X) / 2d);
            center.Y = (float)((MinVertex.Y + MaxVertex.Y) / 2d);
            center.Z = (float)((MinVertex.Z + MaxVertex.Z) / 2d);

            Coords = MinVertex;
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator<Vector3I> coordEnumerator = BlockEnumerator(MinVertex, MaxVertex).GetEnumerator();
            while(coordEnumerator.MoveNext())
            {
                if (Aborted == true) {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);

            }
            main.SetDrawerToNull();
        }
示例#3
0
 /// <summary>
 /// Starts a server for remote clients to connect to on the specified port, with the specified password.
 /// </summary>
 /// <param name="MainBot">The main bot, which is used for sending messages from remote clients.</param>
 /// <param name="remotePort">The port to listen on.</param>
 /// <param name="remotePassword">The password to use. Does not have to be the same as the password of the bots account.</param>
 public void Start(ClassicBot MainBot, int remotePort, string remotePassword)
 {
     RemoteServer = new Server(remotePort, this);
     MinecraftBot = MainBot;
     _password    = remotePassword;
     _port        = remotePort;
 }
示例#4
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing. 
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            for (; Coords.X <= MaxVertex.X; Coords.X++)
            {
                for (; Coords.Y <=  MaxVertex.Y; Coords.Y++)
                {
                    for (; Coords.Z <=  MaxVertex.Z; Coords.Z++)
                    {
                        if (Aborted == true) {
                            return;
                        }
                        Thread.Sleep(sleeptime);
                        main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                        main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                    }
                    Coords.Z = MinVertex.Z; //Reset height.
                }
                Coords.Y = MinVertex.Y;
            }
            main.SetDrawerToNull();
        }
示例#5
0
        /// <summary> Load all plugins avaliable in the plugins directory. </summary>
        /// <param name="commands"> The Dictionary to add commands to. </param>
        /// <param name="main"> The ClassicBot instance to attach to. (e.g. for message sending.)</param>
        public static void LoadPlugins( Dictionary<string, CommandDelegate> commands, ClassicBot main )
        {
            if( !Directory.Exists( "plugins" ) ) {
                return;
            }
            string[] pluginFiles = Directory.GetFiles( "plugins", "*.dll", SearchOption.TopDirectoryOnly );
            if( pluginFiles.Length == 0 ) return;

            for( int i = 0; i < pluginFiles.Length; i++ ) {
                main.Log( LogType.BotActivity, "Loading commands from plugin file " + pluginFiles[i] );
                try {
                    Assembly assembly = Assembly.LoadFile( Path.GetFullPath( pluginFiles[i] ) );
                    Type[] types = assembly.GetTypes();
                    for( int j = 0; j < types.Length; j++ ) {
                        Type type = types[j];
                        if( type.IsSubclassOf( typeof( Plugin ) ) ) {
                            Plugin plugin = (Plugin)Activator.CreateInstance( type );
                            plugin.Initialize( main );
                            if( !commands.ContainsKey( plugin.CommandName ) ) {
                                main.Log( LogType.BotActivity, "Loaded command " + plugin.CommandName );
                                commands.Add( plugin.CommandName, plugin.Command );
                            }
                        }
                    }
                } catch( Exception e ) {
                    main.Log( LogType.Error, "Couldn't load commands from the plugin.", e.ToString() );
                }
            }
            LoadScripts( commands, main );
        }
示例#6
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            double   rx        = (MaxVertex.X - MinVertex.X + 1) / 2d;
            double   ry        = (MaxVertex.Y - MinVertex.Y + 1) / 2d;
            double   rz        = (MaxVertex.Z - MinVertex.Z + 1) / 2d;

            radius.X = (float)(1 / (rx * rx));
            radius.Y = (float)(1 / (ry * ry));
            radius.Z = (float)(1 / (rz * rz));

            // find center points
            center.X = (float)((MinVertex.X + MaxVertex.X) / 2d);
            center.Y = (float)((MinVertex.Y + MaxVertex.Y) / 2d);
            center.Z = (float)((MinVertex.Z + MaxVertex.Z) / 2d);

            Coords = MinVertex;
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator <Vector3I> coordEnumerator = BlockEnumerator(MinVertex, MaxVertex).GetEnumerator();

            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
示例#7
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            for (; Coords.X <= MaxVertex.X; Coords.X++)
            {
                for (; Coords.Y <= MaxVertex.Y; Coords.Y++)
                {
                    for (; Coords.Z <= MaxVertex.Z; Coords.Z++)
                    {
                        if (Aborted == true)
                        {
                            return;
                        }
                        Thread.Sleep(sleeptime);
                        main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                        main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                    }
                    Coords.Z = MinVertex.Z;                     //Reset height.
                }
                Coords.Y = MinVertex.Y;
            }
            main.SetDrawerToNull();
        }
示例#8
0
 /// <summary>
 /// Loads all the events. This should only be called once.
 /// </summary>
 private void LoadBotEvents(ClassicBot bot)
 {
     bot.Events.MapProgress += MapLoading;
     bot.Events.ChatMessage += ChatMessage;
     //bot.Events.BotException += BotException;
     bot.Events.GotKicked += GotKicked;
     bot.Events.MapLoaded += MapLoaded;
 }
示例#9
0
        static void CompileScripts( Dictionary<string, Script> scripts, Dictionary<string, CommandDelegate> commands, ClassicBot main )
        {
            foreach( var keypair in scripts ) {
                Script script = keypair.Value;
                if( String.IsNullOrEmpty( script.Code ) ) continue;
                CodeDomProvider compiler;
                if( script.IsCSharp ) {
                    compiler = new Microsoft.CSharp.CSharpCodeProvider( new Dictionary<string, string>{ { "CompilerVersion", "v2.0" } } );
                } else {
                    compiler = new Microsoft.VisualBasic.VBCodeProvider( new Dictionary<string, string>{ { "CompilerVersion", "v2.0" } } );
                }

                CompilerParameters cParams = new CompilerParameters {
                    GenerateExecutable = false,
                    GenerateInMemory = true,
                    //CompilerOptions = "/unsafe", Causes errors with the Visual Basic Compiler.
                    TreatWarningsAsErrors = false,
                    WarningLevel = 4,
                };
                if( script.KnownReferences == null || script.KnownReferences.Length == 0 ) { // Add defalt references.
                    cParams.ReferencedAssemblies.Add( "System.dll" );
                    cParams.ReferencedAssemblies.Add( "LibClassicBot.dll" );
                } else {
                    cParams.ReferencedAssemblies.AddRange( script.KnownReferences );
                }

                CompilerResults results = compiler.CompileAssemblyFromSource( cParams, script.Code );
                if( results.Errors.Count != 0 )  {
                    try {
                        foreach( CompilerError error in results.Errors ) {
                            string errorMsg = String.Format( "{0} Line: {1} {2}", error.ErrorNumber, error.Line, error.ErrorText );
                            if( error.IsWarning ) {
                                main.Log( LogType.Error, "Warning while compiling script " + keypair.Key, errorMsg );
                            } else {
                                main.Log( LogType.Error, "Error while compiling script " + keypair.Key, errorMsg );
                            }
                        }
                    } catch( Exception e ) {
                        main.Log( LogType.Error, "Error while trying to display errors. " , e.ToString() );
                    }
                    continue;
                }
                compiler.Dispose();

                Type[] types = results.CompiledAssembly.GetTypes();
                for( int i = 0; i < types.Length; i++ ) {
                    Type type = types[i];
                    if( type.IsSubclassOf( typeof( Plugin ) ) ) {
                        Plugin plugin = (Plugin)Activator.CreateInstance( type );
                        plugin.Initialize( main );
                        if( !commands.ContainsKey( plugin.CommandName ) ) {
                            main.Log( LogType.BotActivity, "Loaded command " + plugin.CommandName );
                            commands.Add( plugin.CommandName, plugin.Command );
                        }
                    }
                }
            }
        }
示例#10
0
 /// <summary>
 /// Starts a server for remote clients to connect to on the specified port, with the specified password.
 /// </summary>
 /// <param name="MainBot">The main bot, which is used for sending messages from remote clients.</param>
 /// <param name="remotePort">The port to listen on.</param>
 /// <param name="remotePassword">The password to use. Does not have to be the same as the password of the bots account.</param>
 public void Start(ClassicBot MainBot, int remotePort, string remotePassword)
 {
     MinecraftBot = MainBot;
     _password = remotePassword;
     _port = remotePort;
     Thread listenThread = new Thread(ListenForClients);
     listenThread.Name = "RemoteServerThread";
     listenThread.IsBackground = true;
     listenThread.Start();
 }
示例#11
0
        static void LoadScripts(Dictionary <string, CommandDelegate> commands, ClassicBot main)
        {
            if (!Directory.Exists("scripts"))
            {
                return;
            }
            String[] files = Directory.GetFiles("scripts", "*.*", SearchOption.TopDirectoryOnly);
            if (files.Length == 0)
            {
                return;
            }
            Dictionary <string, Script> scripts = new Dictionary <string, Script>();

            for (int i = 0; i < files.Length; i++)
            {
                string fileName  = files[i];
                string extension = Path.GetExtension(fileName).ToLowerInvariant();                   // Includes .
                string name      = Path.GetFileNameWithoutExtension(fileName);

                if (extension == ".reference" || extension == ".references")
                {
                    Script script;
                    if (!scripts.TryGetValue(name, out script))
                    {
                        script        = new Script();
                        scripts[name] = script;
                    }
                    script.KnownReferences = File.ReadAllText(fileName).Split(',');
                }
                else if (extension == ".cs")
                {
                    Script script;
                    if (!scripts.TryGetValue(name, out script))
                    {
                        script        = new Script();
                        scripts[name] = script;
                    }
                    script.Code     = File.ReadAllText(fileName);
                    script.IsCSharp = true;
                    main.Log(LogType.BotActivity, "Loading commands from script file " + fileName);
                }
                else if (extension == ".vb")
                {
                    Script script;
                    if (!scripts.TryGetValue(name, out script))
                    {
                        script        = new Script();
                        scripts[name] = script;
                    }
                    script.Code = File.ReadAllText(fileName);
                    main.Log(LogType.BotActivity, "Loading commands from script file " + fileName);
                }
            }
            CompileScripts(scripts, commands, main);
        }
示例#12
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = points[0];

            vicMazeGen.cMaze maze     = new vicMazeGen.cMaze();
            string[]         rawLines = main.GetMessage(originalchatline).Split(' ');
            if (rawLines.Length < 4)            //Not enough arguements given
            {
                main.SendMessagePacket("Not enough arguements. (" + (rawLines.Length - 2) + " given, 2 expected.)");
                main.SetDrawerToNull();
                return;
            }
            int mazeX; int mazeY; byte smoothness;  int seed;

            //Required paramters - Fail if these are not found.
            if (!Int32.TryParse(rawLines[2], out mazeX) || !Int32.TryParse(rawLines[3], out mazeY))
            {
                main.SendMessagePacket("Given maze size was in the incorrect format.");
                main.SetDrawerToNull();
                return;
            }             //todo catch divide by zero exceptions.
            //Optional paramters - Otherwise use random numbers.
            if (rawLines.Length > 4 && Byte.TryParse(rawLines[4], out smoothness))
            {
            }
            else
            {
                smoothness = (byte)(new Random().Next(0, 30));
            }
            if (rawLines.Length > 5 && Int32.TryParse(rawLines[5], out seed))
            {
            }
            else
            {
                seed = (new Random().Next(0, Int32.MaxValue));
            }                                                                   //I think it can go larger. Random can't though.
            //Actually generate.
            maze.GenerateMaze(mazeX / 2, mazeY / 2, smoothness, seed);
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            IEnumerator <Vector3I> coordEnumerator = maze.BlockEnumerator(points[0], mazeX, mazeY);

            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Thread.Sleep(sleeptime);
                Coords = coordEnumerator.Current;
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
示例#13
0
        /// <summary>
        /// Starts a server for remote clients to connect to on the specified port, with the specified password.
        /// </summary>
        /// <param name="MainBot">The main bot, which is used for sending messages from remote clients.</param>
        /// <param name="remotePort">The port to listen on.</param>
        /// <param name="remotePassword">The password to use. Does not have to be the same as the password of the bots account.</param>
        public void Start(ClassicBot MainBot, int remotePort, string remotePassword)
        {
            MinecraftBot = MainBot;
            _password    = remotePassword;
            _port        = remotePort;
            Thread listenThread = new Thread(ListenForClients);

            listenThread.Name         = "RemoteServerThread";
            listenThread.IsBackground = true;
            listenThread.Start();
        }
示例#14
0
        void Button1Click(object sender, EventArgs e)
        {
            ClassicBot cc = new ClassicBot(userBox.Text, passwordBox.Text, addBox.Text);

            AddPlugins(cc);
            cc.Start(false);
            StatBot = cc;
            if (firstrun)
            {
                LoadBotEvents(cc);
            }
        }
示例#15
0
        public Client(ClientSocket socket, ClassicBot bot)
        {
            _socket        = socket;           // -- Asssign incoming variables
            Bot            = bot;
            _receiveBuffer = new ByteBuffer(); // -- Setup send/receive buffers and initiate collections
            SendBuffer     = new ByteBuffer();
            Extensions     = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);
            ClientPlayer   = new Player(Bot.Username, this, Bot.Mppass); // -- Create a new player container for ourselves
            _lastActive    = DateTime.UtcNow;

            // -- Setup event handlers for the socket
            _socket.Connected    += SocketOnConnected;
            _socket.DataReceived += SocketOnDataReceived;
            _socket.Disconnected += SocketOnDisconnected;
            SendBuffer.DataAdded += SendBufferOnDataAdded;

            PopulatePackets(); // -- Ready the packets for handling
        }
示例#16
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            coordEnumerator = LineEnumerator(points[0], points[1]).GetEnumerator();
            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true) {
                    return;
                }
                Coords = coordEnumerator.Current;
                Thread.Sleep(sleeptime);
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
示例#17
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords    = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            Vector3I Coords2   = Vector3I.Max(points[0], points[1]);

            Coords2.Z = MinVertex.Z;
            Vector3I Coords3 = Coords;
            int      xMax    = (MinVertex.X + MaxVertex.X / 2);
            int      yMax    = (MinVertex.Y + MaxVertex.Y / 2);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);

            while (Coords3.X <= xMax && Coords3.Y <= yMax)             //It's not pretty, but it works.
            {
                Coords = Coords3;
                for (; Coords.X <= Coords2.X; Coords.X++)
                {
                    for (; Coords.Y <= Coords2.Y; Coords.Y++)
                    {
                        for (; Coords.Z <= Coords2.Z; Coords.Z++)
                        {
                            if (Aborted == true)
                            {
                                return;
                            }
                            Thread.Sleep(sleeptime);
                            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                            main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                        }
                        Coords.Z = Coords3.Z;                         //Reset height.
                    }
                    Coords.Y = Coords3.Y;
                }
                Coords3.X++;
                Coords3.Y++;
                Coords3.Z++;
                Coords2.X--;
                Coords2.Y--;
                Coords2.Z++;                 //All these are needed, maybe some day I'll improve this.
            }
            main.SetDrawerToNull();
        }
示例#18
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);

            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
            coordEnumerator = LineEnumerator(points[0], points[1]).GetEnumerator();
            while (coordEnumerator.MoveNext())
            {
                if (Aborted == true)
                {
                    return;
                }
                Coords = coordEnumerator.Current;
                Thread.Sleep(sleeptime);
                main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
            }
            main.SetDrawerToNull();
        }
示例#19
0
        /// <summary>
        /// Executes the drawer, and should be executed on a separate thread.
        /// The token is there if the user finds a need to stop the drawing. (This happens when CriticalAbort is set to true.)
        /// </summary>
        /// <param name="cToken">The CuboidToken to check if the drawing needs to be stopped.</param>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I Coords = Vector3I.Min(points[0], points[1]);
            Vector3I MinVertex = Vector3I.Min(points[0], points[1]);
            Vector3I MaxVertex = Vector3I.Max(points[0], points[1]);
            Vector3I Coords2 = Vector3I.Max(points[0], points[1]);
            Coords2.Z = MinVertex.Z;
            Vector3I Coords3 = Coords;
            int xMax = (MinVertex.X + MaxVertex.X / 2);
            int yMax = (MinVertex.Y + MaxVertex.Y / 2);
            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);

            while (Coords3.X <= xMax && Coords3.Y <= yMax) //It's not pretty, but it works.
            {
                Coords = Coords3;
                for (; Coords.X <= Coords2.X; Coords.X++)
                {
                    for (; Coords.Y <= Coords2.Y; Coords.Y++)
                    {
                        for (; Coords.Z <= Coords2.Z; Coords.Z++)
                        {
                            if (Aborted == true) {
                                return;
                            }
                            Thread.Sleep(sleeptime);
                            main.SendPositionPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z);
                            main.SendBlockPacket((short)Coords.X, (short)Coords.Y, (short)Coords.Z, 1, blocktype);
                        }
                        Coords.Z = Coords3.Z; //Reset height.
                    }
                    Coords.Y = Coords3.Y;
                }
                Coords3.X++;
                Coords3.Y++;
                Coords3.Z++;
                Coords2.X--;
                Coords2.Y--;
                Coords2.Z++; //All these are needed, maybe some day I'll improve this.
            }
            main.SetDrawerToNull();
        }
示例#20
0
        static void CompileScripts(Dictionary <string, Script> scripts, Dictionary <string, CommandDelegate> commands, ClassicBot main)
        {
            foreach (var keypair in scripts)
            {
                Script script = keypair.Value;
                if (String.IsNullOrEmpty(script.Code))
                {
                    continue;
                }
                CodeDomProvider compiler;
                if (script.IsCSharp)
                {
                    compiler = new Microsoft.CSharp.CSharpCodeProvider(new Dictionary <string, string> {
                        { "CompilerVersion", "v2.0" }
                    });
                }
                else
                {
                    compiler = new Microsoft.VisualBasic.VBCodeProvider(new Dictionary <string, string> {
                        { "CompilerVersion", "v2.0" }
                    });
                }

                CompilerParameters cParams = new CompilerParameters {
                    GenerateExecutable = false,
                    GenerateInMemory   = true,
                    //CompilerOptions = "/unsafe", Causes errors with the Visual Basic Compiler.
                    TreatWarningsAsErrors = false,
                    WarningLevel          = 4,
                };
                if (script.KnownReferences == null || script.KnownReferences.Length == 0)                    // Add defalt references.
                {
                    cParams.ReferencedAssemblies.Add("System.dll");
                    cParams.ReferencedAssemblies.Add("LibClassicBot.dll");
                }
                else
                {
                    cParams.ReferencedAssemblies.AddRange(script.KnownReferences);
                }

                CompilerResults results = compiler.CompileAssemblyFromSource(cParams, script.Code);
                if (results.Errors.Count != 0)
                {
                    try {
                        foreach (CompilerError error in results.Errors)
                        {
                            string errorMsg = String.Format("{0} Line: {1} {2}", error.ErrorNumber, error.Line, error.ErrorText);
                            if (error.IsWarning)
                            {
                                main.Log(LogType.Error, "Warning while compiling script " + keypair.Key, errorMsg);
                            }
                            else
                            {
                                main.Log(LogType.Error, "Error while compiling script " + keypair.Key, errorMsg);
                            }
                        }
                    } catch (Exception e) {
                        main.Log(LogType.Error, "Error while trying to display errors. ", e.ToString());
                    }
                    continue;
                }
                compiler.Dispose();

                Type[] types = results.CompiledAssembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    Type type = types[i];
                    if (type.IsSubclassOf(typeof(Plugin)))
                    {
                        Plugin plugin = (Plugin)Activator.CreateInstance(type);
                        plugin.Initialize(main);
                        if (!commands.ContainsKey(plugin.CommandName))
                        {
                            main.Log(LogType.BotActivity, "Loaded command " + plugin.CommandName);
                            commands.Add(plugin.CommandName, plugin.Command);
                        }
                    }
                }
            }
        }
示例#21
0
 /// <summary>
 /// This method initalizes the command of the plugin.
 /// </summary>
 /// <param name="main">The ClassicBot with which this plugin
 /// is attached to.</param>
 /// <example>This for example, creates a new plugin that sends a message saying test
 /// everytime it is called. <code>Command = delegate(string Line)<br/>
 /// {<br/>
 ///     main.SendMessagePacket("Test");<br/>
 /// };</code></example>
 public abstract void Initialize(ClassicBot main);
示例#22
0
        static void LoadScripts( Dictionary<string, CommandDelegate> commands, ClassicBot main )
        {
            if( !Directory.Exists( "scripts" ) ) {
                return;
            }
            String[] files = Directory.GetFiles( "scripts", "*.*", SearchOption.TopDirectoryOnly );
            if( files.Length == 0 ) return;
            Dictionary<string, Script> scripts = new Dictionary<string, Script>();

            for( int i = 0; i < files.Length; i++ ) {
                string fileName = files[i];
                string extension = Path.GetExtension( fileName ).ToLowerInvariant(); // Includes .
                string name = Path.GetFileNameWithoutExtension( fileName );

                if( extension == ".reference" || extension == ".references" ) {
                    Script script;
                    if( !scripts.TryGetValue( name, out script ) ) {
                        script = new Script();
                        scripts[name] = script;
                    }
                    script.KnownReferences = File.ReadAllText( fileName ).Split( ',' );
                } else if( extension == ".cs" ) {
                    Script script;
                    if( !scripts.TryGetValue( name, out script ) ) {
                        script = new Script();
                        scripts[name] = script;
                    }
                    script.Code = File.ReadAllText( fileName );
                    script.IsCSharp = true;
                    main.Log( LogType.BotActivity, "Loading commands from script file " + fileName );
                } else if( extension == ".vb" ) {
                    Script script;
                    if( !scripts.TryGetValue( name, out script ) ) {
                        script = new Script();
                        scripts[name] = script;
                    }
                    script.Code = File.ReadAllText( fileName );
                    main.Log( LogType.BotActivity, "Loading commands from script file " + fileName );
                }
            }
            CompileScripts( scripts, commands, main );
        }
示例#23
0
        /// <summary> Load all plugins avaliable in the plugins directory. </summary>
        /// <param name="commands"> The Dictionary to add commands to. </param>
        /// <param name="main"> The ClassicBot instance to attach to. (e.g. for message sending.)</param>
        public static void LoadPlugins(Dictionary <string, CommandDelegate> commands, ClassicBot main)
        {
            if (!Directory.Exists("plugins"))
            {
                return;
            }
            string[] pluginFiles = Directory.GetFiles("plugins", "*.dll", SearchOption.TopDirectoryOnly);
            if (pluginFiles.Length == 0)
            {
                return;
            }

            for (int i = 0; i < pluginFiles.Length; i++)
            {
                main.Log(LogType.BotActivity, "Loading commands from plugin file " + pluginFiles[i]);
                try {
                    Assembly assembly = Assembly.LoadFile(Path.GetFullPath(pluginFiles[i]));
                    Type[]   types    = assembly.GetTypes();
                    for (int j = 0; j < types.Length; j++)
                    {
                        Type type = types[j];
                        if (type.IsSubclassOf(typeof(Plugin)))
                        {
                            Plugin plugin = (Plugin)Activator.CreateInstance(type);
                            plugin.Initialize(main);
                            if (!commands.ContainsKey(plugin.CommandName))
                            {
                                main.Log(LogType.BotActivity, "Loaded command " + plugin.CommandName);
                                commands.Add(plugin.CommandName, plugin.Command);
                            }
                        }
                    }
                } catch (Exception e) {
                    main.Log(LogType.Error, "Couldn't load commands from the plugin.", e.ToString());
                }
            }
            LoadScripts(commands, main);
        }
示例#24
0
        public static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Welcome to LibClassicBot beta.");
            Console.WriteLine("Below is a list of commands and how to use them");
            Console.WriteLine(".position - Announces the position of the bot in the map.");
            Console.WriteLine(".allow <user> - Adds a user to a list of allowed operators.");
            Console.WriteLine(".disallow <user> - Removes a user from the list of allowed operators.");
            Console.WriteLine(".say <message> - Makes the bot send the specified message.");
            Console.WriteLine(".players - Lists the visibile players to the bot in the current map.");
            Console.WriteLine(".move <x,y,z> - Moves the bot to the specified coordinates.");
            Console.WriteLine(".place <x,y,z> - Attempts to place a block at the specified coordinates.");
            Console.WriteLine(".haspaid <username> - Announces if a user has paid or not.");
            Console.WriteLine(".cuboid <blocktype> - Cuboids between two points.");
            Console.WriteLine(".cuboidh <blocktype> - Draws a hollow cuboid between two points.");
            Console.WriteLine(".cuboidw <blocktype> - Draws a wireframe between two points.");
            Console.WriteLine(".ellipsoid <blocktype> - Draws an ellipsoid between two points.");
            Console.WriteLine(".pyramid <blocktype> - Draws an upwards pyramid between two points.");
            Console.WriteLine(".follow <username> - Follows player. (Case sensitive)");
            Console.WriteLine(".speed <number> - The number of blocks to place per second.");
            Console.WriteLine(".abort - Stops the currently running draw operation.");
            Console.WriteLine(".drawimg 0 <filename> - Attempts to draw the specified image.");
            Console.ResetColor();

            Console.WriteLine("Enter the username to be used by the bot: (Minecraft account)");
            string username = Console.ReadLine();

            Console.WriteLine("Enter the password to be used by the bot: (Minecraft account)");
            string password = Console.ReadLine();

            Console.WriteLine("Enter the address of the server to connect to: ");
            string hash = Console.ReadLine();

            if (!hash.StartsWith("http"))
            {
                if (hash.StartsWith("minecraft"))
                {
                    hash = "http://" + hash;
                }
                else
                {
                    hash = "http://minecraft.net/classic/play/" + hash;
                }
            }

            ClassicBot    Bot1   = new ClassicBot(username, password, hash);
            ConsoleLogger logger = new ConsoleLogger();

            Bot1.RegisterLogger(logger);
            FileLogger file = new FileLogger();

            Bot1.RegisterLogger(file);
            Bot1.Events.ChatMessage          += Bot1_ChatMessage;
            Bot1.Events.PlayerMoved          += Bot1_PlayerMoved;
            Bot1.Events.RemoteSessionStarted += RemoteSessionStarted;
            Bot1.Events.RemoteUserLoggedIn   += RemoteUserLoggedIn;
            Bot1.Events.RemoteSessionEnded   += RemoteSessionEnded;
                        #if !MONO
            Bot1.Events.MapLoaded     += Bot1_MapLoaded;
            Bot1.Events.ConfigLoading += delegate { Console.WriteLine("Loading"); };
                        #endif

            #region Plugins
            CommandDelegate MazeCommand = delegate(string Line)
            {
                Maze maze = new Maze();
                maze.originalchatline = Line;
                Bot1.SetDrawer(Line, maze, 2);
            };
            Bot1.RegisteredCommands.Add("maze", MazeCommand);

            CommandDelegate DrawCommand = delegate(string Line)
            {
                DrawImage img = new DrawImage();
                img.originalchatline = Line;
                Bot1.SetDrawer(Line, img, 2);
            };
            Bot1.RegisteredCommands.Add("drawimg", DrawCommand);

            CommandDelegate PositionCommand = delegate(string Line)
            {
                Bot1.SendMessagePacket(String.Format("Positon in world is at {0},{1},{2}.", Bot1.X, Bot1.Y, Bot1.Z));
            };
            Bot1.RegisteredCommands.Add("position", PositionCommand);

            CommandDelegate AddOpCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.AddOperator(full[1]);
                Bot1.SendMessagePacket("Allowed user: "******"allow", AddOpCommand);

            CommandDelegate RemoveOpCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.RemoveOperator(full[1]);
                Bot1.SendMessagePacket("Disallowed user: "******"disallow", RemoveOpCommand);

            CommandDelegate ListOpsCommand = delegate(string Line)
            {
                string[] names = Bot1.Users.ToArray();
                Bot1.SendLongChat(String.Join(", ", names));
            };
            Bot1.RegisteredCommands.Add("ops", ListOpsCommand);

            CommandDelegate SayCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.SendMessagePacket(full[1]);
            };
            Bot1.RegisteredCommands.Add("say", SayCommand);

            CommandDelegate PlayersCommand = delegate(string Line)
            {
                List <string> Names = new List <string>();
                foreach (Player player in Bot1.Players.Values)
                {
                    Names.Add(player.Name);
                }
                string output = String.Join(",", Names.ToArray());
                Bot1.SendLongChat("Players in current world: " + output);
            };
            Bot1.RegisteredCommands.Add("players", PlayersCommand);

            CommandDelegate MoveCommand = delegate(string Line)
            {
                string[] full   = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                Bot1.SendPositionPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]));
            };
            Bot1.RegisteredCommands.Add("move", MoveCommand);

            CommandDelegate PlaceCommand = delegate(string Line)
            {
                string[] full   = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 4);
                Bot1.SendBlockPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]), 1, Byte.Parse(coords[3]));
            };
            Bot1.RegisteredCommands.Add("place", PlaceCommand);

            CommandDelegate HasPaidCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                try
                {
                    bool      paid;
                    WebClient client   = new WebClient();
                    string    response = client.DownloadString("https://minecraft.net/haspaid.jsp?user="******"minecraft.net returned: " + (int)response.StatusCode + " " + response.StatusCode.ToString());
                        }
                    }
                    else
                    {
                        Bot1.SendMessagePacket("Unhandled error occured: " + ex.Status.ToString());
                    }
                }
            };
            Bot1.RegisteredCommands.Add("haspaid", HasPaidCommand);

            CommandDelegate FollowCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                personfollowed = full[1];
                Bot1.SendMessagePacket("Following user " + full[1]);
            };
            Bot1.RegisteredCommands.Add("follow", FollowCommand);

            CommandDelegate CuboidCommand = delegate(string Line)
            {
                Cuboid cuboid = new Cuboid();
                Bot1.SetDrawer(Line, cuboid, 2);
            };
            Bot1.RegisteredCommands.Add("cuboid", CuboidCommand);

            CommandDelegate PyramidCommand = delegate(string Line)
            {
                Pyramid pyramid = new Pyramid();
                Bot1.SetDrawer(Line, pyramid, 2);
            };
            Bot1.RegisteredCommands.Add("pyramid", PyramidCommand);

            CommandDelegate AbortCommand = delegate(string Line)
            {
                Bot1.CancelDrawer();
                personfollowed = String.Empty;
            };
            Bot1.RegisteredCommands.Add("abort", AbortCommand);

            CommandDelegate SpeedCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.CuboidSleepTime = 1000 / Int32.Parse(full[1]);
            };
            Bot1.RegisteredCommands.Add("speed", SpeedCommand);

            CommandDelegate EllipsoidCommand = delegate(string Line)
            {
                Ellipsoid ellipsoid = new Ellipsoid();
                Bot1.SetDrawer(Line, ellipsoid, 2);
            };
            Bot1.RegisteredCommands.Add("ellipsoid", EllipsoidCommand);

            CommandDelegate CuboidHCommand = delegate(string Line)
            {
                CuboidHollow cuboidh = new CuboidHollow();
                Bot1.SetDrawer(Line, cuboidh, 2);
            };
            Bot1.RegisteredCommands.Add("cuboidh", CuboidHCommand);

            CommandDelegate CuboidWCommand = delegate(string Line)
            {
                CuboidWireframe cuboidw = new CuboidWireframe();
                Bot1.SetDrawer(Line, cuboidw, 2);
            };
            Bot1.RegisteredCommands.Add("cuboidw", CuboidWCommand);

            CommandDelegate LineCommand = delegate(string Line)
            {
                Line line = new Line();
                Bot1.SetDrawer(Line, line, 2);
            };
            Bot1.RegisteredCommands.Add("line", LineCommand);

            CommandDelegate IgnoreCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.IgnoredUserList.Add(full[1]);
                Bot1.SendMessagePacket("Ignored user: "******"ignore", IgnoreCommand);

            CommandDelegate UnIgnoreCommand = delegate(string Line)
            {
                string[] full = Bot1.GetMessage(Line).Split(new char[] { ' ' }, 2);
                Bot1.IgnoredUserList.Remove(full[1]);
                Bot1.SendMessagePacket("Unignored user: "******"unignore", UnIgnoreCommand);

            /*CommandDelegate TestPosCommand = delegate(string Line)
             * { //Ain't no way to stop it. Uncomment with severe caution.
             *      new System.Threading.Thread(
             *              delegate() {
             *                      Random rnd = new Random();
             *                      while(true){
             *
             *                              int rndval1 = rnd.Next(0, 360);
             *                              byte newpitch = Extensions.DegreesToYaw(rndval1);
             *                              int rndval2 = rnd.Next(0, 360);
             *                              byte newyaw = Extensions.DegreesToYaw(rndval2);
             *                              Bot1.SendPositionPacket(Bot1.X, Bot1.Y, Bot1.Z, newyaw, newpitch);
             *                              System.Threading.Thread.Sleep(10);
             *                      }
             *              }).Start();
             * };
             * Bot1.RegisteredCommands.Add("testpos", TestPosCommand);*/
            #endregion

            StaticBot1 = Bot1;
            Bot1.Start(false);

loop:
            {
                string response = Console.ReadLine();
                Bot1.SendMessagePacket(response);
                goto loop;
            }
        }
示例#25
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap   myBitmap   = null;

            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] { ' ' }, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; }             //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);

            if (direction == 4)
            {
                return;
            }

            Block[] refCols = GetReferenceColours();
            Block   currentBlock;

            double[] distance = new double[refCols.Length];
            int      position;

            for (int curwidth = 0; curwidth < myBitmap.Width; curwidth++)
            {
                for (int curheight = 0; curheight < myBitmap.Height; curheight++)
                {
                    currentBlock.Z = (firstPoint.Z + curheight);
                    if (direction == 0)
                    {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 1)
                    {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if (direction == 2)
                    {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else
                    {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for (int j = 0; j < distance.Length; j++)                        //Calculate distances between the colors in the image and the set reference colors, and store them.
                    {
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R), 2) +
                                                Math.Pow((currentBlock.col.B - refCols[j].col.B), 2) +
                                                Math.Pow((currentBlock.col.G - refCols[j].col.G), 2));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for (int h = 1; h < distance.Length; h++)                        //Find the smallest distance in the array of distances.
                    {
                        if (distance[h] < minimum)
                        {
                            minimum  = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType; //Set the block we found closest to the image to the block we are placing.
                    if (position <= 20)                                   //Back colour blocks
                    {
                        if (direction == 0)
                        {
                            currentBlock.Y += 1;
                        }
                        else if (direction == 1)
                        {
                            currentBlock.Y -= 1;
                        }
                        else if (direction == 2)
                        {
                            currentBlock.X -= 1;
                        }
                        else if (direction == 3)
                        {
                            currentBlock.X += 1;
                        }
                    }                     //Otherwise, draw them in the front row.
                    if (currentBlock.col.A < 20)
                    {
                        currentBlock.blockType = 0;                                                //Transparent pixels.
                    }
                    if (Aborted == true)
                    {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }
示例#26
0
        private void AddPlugins(ClassicBot bot)
        {
            #region Plugins

            CommandDelegate PositionCommand = delegate(string Line)
            {
                bot.SendMessagePacket(String.Format("Positon in world is at {0},{1},{2}.", bot.X, bot.Y, bot.Z));
            };
            bot.RegisteredCommands.Add("position", PositionCommand);

            CommandDelegate AddOpCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.AddOperator(full[1]);
                bot.SendMessagePacket("Allowed user: "******"allow", AddOpCommand);

            CommandDelegate RemoveOpCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 1);
                bot.RemoveOperator(full[1]);
                bot.SendMessagePacket("Disallowed user: "******"disallow", RemoveOpCommand);

            CommandDelegate SayCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.SendMessagePacket(full[1]);
            };
            bot.RegisteredCommands.Add("say", SayCommand);

            CommandDelegate PlayersCommand = delegate(string Line)
            {
                List <string> Names = new List <string>();
                foreach (Player player in bot.Players.Values)
                {
                    Names.Add(player.Name);
                }
                string output = String.Join(",", Names.ToArray());
                bot.SendLongChat("Players in current world: " + output);
            };
            bot.RegisteredCommands.Add("players", PlayersCommand);

            CommandDelegate MoveCommand = delegate(string Line)
            {
                string[] full   = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                bot.SendPositionPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]));
            };
            bot.RegisteredCommands.Add("move", MoveCommand);

            CommandDelegate PlaceCommand = delegate(string Line)
            {
                string[] full   = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                string[] coords = full[1].Split(new char[] { ',' }, 3);
                bot.SendBlockPacket(Int16.Parse(coords[0]), Int16.Parse(coords[1]), Int16.Parse(coords[2]), 1, 29);
            };
            bot.RegisteredCommands.Add("place", PlaceCommand);

            CommandDelegate HasPaidCommand = delegate(string Line)
            {
                string[] LineSplit = Extensions.StripColors(Line).Split(' ');
                try
                {
                    bool      b;
                    WebClient c        = new WebClient();
                    string    response = c.DownloadString("https://minecraft.net/haspaid.jsp?user="******"minecraft.net returned: " + (int)response.StatusCode + " " + response.StatusCode.ToString());
                        }
                    }
                    else
                    {
                        bot.SendMessagePacket("Unhandled error occured: " + ex.Status.ToString());
                    }
                }
            };
            bot.RegisteredCommands.Add("haspaid", HasPaidCommand);

            CommandDelegate FollowCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                personfollowed = full[1];
                bot.SendMessagePacket("Following user " + full[1]);
            };
            bot.RegisteredCommands.Add("follow", FollowCommand);

            CommandDelegate CuboidCommand = delegate(string Line)
            {
                Cuboid cuboid = new Cuboid();
                bot.SetDrawer(Line, cuboid, 2);
            };
            bot.RegisteredCommands.Add("cuboid", CuboidCommand);

            CommandDelegate PyramidCommand = delegate(string Line)
            {
                Pyramid pyramid = new Pyramid();
                bot.SetDrawer(Line, pyramid, 2);
            };
            bot.RegisteredCommands.Add("pyramid", PyramidCommand);

            CommandDelegate AbortCommand = delegate(string Line)
            {
                bot.CancelDrawer();
                personfollowed = String.Empty;
            };
            bot.RegisteredCommands.Add("abort", AbortCommand);

            CommandDelegate SpeedCommand = delegate(string Line)
            {
                string[] full = bot.GetMessage(Line).Split(new char[] { ' ' }, 2);
                bot.CuboidSleepTime = 1000 / Int32.Parse(full[1]);
            };
            bot.RegisteredCommands.Add("speed", SpeedCommand);

            CommandDelegate EllipsoidCommand = delegate(string Line)
            {
                Ellipsoid ellipsoid = new Ellipsoid();
                bot.SetDrawer(Line, ellipsoid, 2);
            };
            bot.RegisteredCommands.Add("ellipsoid", EllipsoidCommand);

            CommandDelegate CuboidHCommand = delegate(string Line)
            {
                CuboidHollow cuboidh = new CuboidHollow();
                bot.SetDrawer(Line, cuboidh, 2);
            };
            bot.RegisteredCommands.Add("cuboidh", CuboidHCommand);

            CommandDelegate CuboidWCommand = delegate(string Line)
            {
                CuboidWireframe cuboidw = new CuboidWireframe();
                bot.SetDrawer(Line, cuboidw, 2);
            };
            bot.RegisteredCommands.Add("cuboidw", CuboidWCommand);

            CommandDelegate LineCommand = delegate(string Line)
            {
                Line line = new Line();
                bot.SetDrawer(Line, line, 2);
            };
            bot.RegisteredCommands.Add("line", LineCommand);
            #endregion
        }
示例#27
0
        /// <summary>
        /// Executes the drawer on a separate thread. The bool is there if the user finds a need to stop the drawing.
        /// (This happens when CancelDrawer() is called.)
        /// </summary>
        public void Start(ClassicBot main, ref bool Aborted, Vector3I[] points, byte blocktype, ref int sleeptime)
        {
            Vector3I firstPoint = points[0];
            Bitmap myBitmap = null;
            string[] full = main.GetMessage(originalchatline).Trim().Split(new char[] {' '}, 3);
            try { myBitmap = new Bitmap(full[2]); } catch { return; } //Invalid file, stop drawing.
            myBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            byte direction = GetDirection(points);
            if (direction == 4) return;

            Block[] refCols = GetReferenceColours();
            Block currentBlock;
            double[] distance = new double[refCols.Length];
            int position;
            for ( int curwidth = 0; curwidth < myBitmap.Width; curwidth++ ) {
                for ( int curheight = 0; curheight < myBitmap.Height; curheight++ ) {

                    currentBlock.Z = (firstPoint.Z + curheight);
                    if(direction == 0) {
                        currentBlock.X = (firstPoint.X + curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if ( direction == 1 ) {
                        currentBlock.X = (firstPoint.X - curwidth);
                        currentBlock.Y = firstPoint.Y;
                    }
                    else if(direction == 2) {
                        currentBlock.Y = (firstPoint.Y + curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    else {
                        currentBlock.Y = (firstPoint.Y - curwidth);
                        currentBlock.X = firstPoint.X;
                    }
                    currentBlock.col = myBitmap.GetPixel(curwidth, curheight);

                    for ( int j = 0; j < distance.Length; j++ ) {//Calculate distances between the colors in the image and the set reference colors, and store them.
                        distance[j] = Math.Sqrt(Math.Pow((currentBlock.col.R - refCols[j].col.R ), 2) +
                                                Math.Pow(( currentBlock.col.B - refCols[j].col.B ), 2) +
                                                Math.Pow(( currentBlock.col.G - refCols[j].col.G ), 2 ));
                    }
                    position = 0;
                    double minimum = distance[0];
                    for ( int h = 1; h < distance.Length; h++ ) {//Find the smallest distance in the array of distances.
                        if ( distance[h] < minimum ) {
                            minimum = distance[h];
                            position = h;
                        }
                    }
                    currentBlock.blockType = refCols[position].blockType;//Set the block we found closest to the image to the block we are placing.
                    if ( position <= 20 ) {//Back colour blocks
                        if ( direction == 0 ) { currentBlock.Y += 1; }
                        else if (direction == 1) { currentBlock.Y -= 1;  }
                        else if ( direction == 2 ) { currentBlock.X -=1; }
                        else if ( direction == 3 ) { currentBlock.X +=1; }
                    } //Otherwise, draw them in the front row.
                    if ( currentBlock.col.A < 20 ) currentBlock.blockType = 0; //Transparent pixels.
                    if (Aborted == true) {
                        return;
                    }
                    Thread.Sleep(sleeptime);
                    main.SendPositionPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z);
                    main.SendBlockPacket((short)currentBlock.X, (short)currentBlock.Y, (short)currentBlock.Z, 1, currentBlock.blockType);
                }
            }
            myBitmap.Dispose();
            main.SetDrawerToNull();
        }
示例#28
0
 /// <summary>
 /// This method initalizes the command of the plugin.
 /// </summary>
 /// <param name="main">The ClassicBot with which this plugin
 /// is attached to.</param>
 /// <example>This for example, creates a new plugin that sends a message saying test
 /// everytime it is called. <code>Command = delegate(string Line)<br/> 
 /// {<br/>
 /// 	main.SendMessagePacket("Test");<br/>
 /// };</code></example>
 public abstract void Initialize(ClassicBot main);