Esempio n. 1
0
        public Block(Message m, OstBot ostBot) : this()
        {
            dataArray = new object[m.Count];

            blockType = m.Type;

            int i;// = 0;//= 1; // (0: layer)

            if (blockType == "b")
            {
                i = 0;
                if (ostBot.playerList.ContainsKey(m.GetInt(0)))
                {
                    dataArray[m.Count - 1] = ostBot.playerList[m.GetInt(0)];
                }
                else
                {
                    dataArray[m.Count - 1] = (Player)null;
                }
            }
            else
            {
                i            = 1;
                dataArray[0] = 0;//(Player)null;
            }

            for (int j = i; j < ((blockType == "b")? m.Count - 1 : m.Count); j++)
            {
                dataArray[j] = Program.ostBot.toObject(m, (uint)(j));
            }
        }
Esempio n. 2
0
 public BotSystem(OstBot ostBot)
 {
     updateTask = new Task(() =>
     {
         try
         {
             Stopwatch stopwatch = new Stopwatch();
             stopwatch.Start();
             while (enabled)
             {
                 Update();
                 int time = (int)stopwatch.ElapsedMilliseconds;
                 if (time < UpdateSleep)
                 {
                     Thread.Sleep(UpdateSleep - time);
                 }
                 stopwatch.Reset();
             }
         }
         catch (Exception e)
         {
             ostBot.shutdown();
             throw e;
         }
     });
 }
Esempio n. 3
0
 public void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
 {
     lock (botSystems)
     {
         foreach (var pair in botSystems)
         {
             if (pair.Value != null)
             {
                 new Task(() =>//new Thread(() =>
                 {
                     pair.Value.onMessage(sender, ostBot, m);
                 }).Start();
             }
         }
     }
 }
Esempio n. 4
0
        //[STAThread]
        static void Main(string[] args)
        {
            /*try
             * {*/
            Application.EnableVisualStyles();
            console = new ConsoleWindow();
            console.Show();
            ostBot = new OstBot();
            form1  = new Form1();
            Application.Run(form1);

            /*}
             * catch (Exception e)
             * {
             *  ostBot.shutdown();
             *  ostBot = null;
             *  throw e;
             * }*/
        }
Esempio n. 5
0
        public void onCommand(object sender, string text, int userId, Player player, OstBot ostBot)
        {
            string[] args = text.Split(' ');

            string[] arg  = text.ToLower().Split(' ');
            string   name = "";

            /*Player player;
             *
             * lock (ostBot.playerList)
             * {
             *  if (ostBot.playerList.ContainsKey(userId))
             *  {
             *      player = ostBot.playerList[userId];
             *      name = player.Name;
             *  }
             *  else
             *  {
             *      player = new Player(PlayerIOClient.Message.Create("m", -1, "", 0, 0, 0, false, false, false, 0, false, false, 0)); //new EEPlayer(-1, "", 0, 0, 0, false, false, false, 0, false, false, 0);
             *  }
             * }*/
            bool isBotMod = (name == "ostkaka" || name == "botost" || name == "gustav9797" || name == "gbot" || player.ismod || userId == -1);

            lock (botSystems)
            {
                foreach (var pair in botSystems)
                {
                    if (pair.Value != null)
                    {
                        //new Task(() =>//new Thread(() =>
                        //{
                        pair.Value.onCommand(sender, ostBot, text, args, userId, player, name, isBotMod);
                        //}).Start();
                    }
                }
            }
        }
Esempio n. 6
0
 public abstract void onCommand(object sender, OstBot ostBot, string text, string[] args, int userId, Player player, string name, bool isBotMod);
Esempio n. 7
0
 public abstract void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m);
Esempio n. 8
0
        public override void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
        {
            Console.WriteLine(m.Type);
            switch (m.Type)
            {
            case "b":
                new Task(() =>
                {
                    string name = "";
                    if (m.Count >= 5)
                    {
                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(m.GetInt(4)))
                            {
                                name = ostBot.playerList[m.GetInt(4)].Name;
                            }
                        }
                        if (name == "")     // else if
                        {
                            lock (ostBot.leftPlayerList)
                            {
                                if (ostBot.leftPlayerList.ContainsKey(m.GetInt(4)))
                                {
                                    name = ostBot.leftPlayerList[m.GetInt(4)].Name;
                                }
                            }
                        }
                    }

                    if (disabledPlayers.Contains(name))
                    {
                        /*return;
                         * }*/
                        Block trollBlock = new Block(m, ostBot);
                        Block block;
                        for (int i = 0; true; i++)
                        {
                            block = ostBot.room.getMapBlock(trollBlock.layer, trollBlock.x, trollBlock.y, i);

                            /*string name2 = "";
                             *
                             * lock (ostBot.playerList)
                             * {
                             *  if (ostBot.playerList.ContainsKey(block.placer.UserId))
                             *  {
                             *      name2 = ostBot.playerList[block.placer.UserId].Name;
                             *  }
                             * }
                             * if (name == "") //else if
                             * {
                             *  lock (ostBot.leftPlayerList)
                             *  {
                             *      if (ostBot.leftPlayerList.ContainsKey(block.placer.UserId))
                             *      {
                             *          name2 = ostBot.leftPlayerList[block.placer.UserId].Name;
                             *      }
                             *  }
                             * }*/
                            if (block.placer == null)
                            {
                                break;
                            }

                            lock (disabledPlayers)
                            {
                                if (!disabledPlayers.Contains(block.placer.Name))
                                {
                                    break;
                                }
                            }
                        }
                        ostBot.room.DrawBlock(block);
                    }
                    else if (!protectedPlayers.Contains(name))
                    {
                        Block trollBlock = new Block(m, ostBot);
                        Block oldBlock   = ostBot.room.getMapBlock(trollBlock.layer, trollBlock.x, trollBlock.y, 1);

                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(oldBlock.placer.UserId))
                            {
                                if (protectedPlayers.Contains(oldBlock.placer.Name))
                                {
                                    ostBot.room.DrawBlock(oldBlock);
                                }
                            }
                        }
                    }
                    if (getPlacerPlayers.Contains(name))
                    {
                        getPlacerPlayers.Remove(name);
                        string name2   = "[undefined]";
                        Block block    = new Block(m, ostBot);
                        Block oldBlock = ostBot.room.getMapBlock(block.layer, block.x, block.y, 1);

                        lock (ostBot.playerList)
                        {
                            if (ostBot.playerList.ContainsKey(oldBlock.placer.UserId))
                            {
                                name2 = oldBlock.placer.Name;
                            }
                        }
                        if (name2 == "[undefined]")
                        {
                            lock (ostBot.leftPlayerList)
                            {
                                if (ostBot.leftPlayerList.ContainsKey(oldBlock.placer.UserId))
                                {
                                    name2 = oldBlock.placer.Name;
                                }
                            }
                        }

                        ostBot.connection.Send("say", name + ": Block placed by " + name2);
                    }
                }).Start();
                break;
            }
        }
Esempio n. 9
0
        public override void onCommand(object sender, OstBot ostBot, string text, string[] args, int userId, Player player, string name, bool isBotMod)
        {
            switch (args[0])
            {
            case "woot":
                if (isBotMod)
                {
                    ostBot.connection.Send("wootup");
                }
                break;

            case "reset":
                if (isBotMod)
                {
                    ostBot.connection.Send("say", "/reset");
                }
                break;

            case "loadlevel":
                if (isBotMod)
                {
                    ostBot.connection.Send("say", "/loadlevel");
                }
                break;

            case "save":
                if (isBotMod)
                {
                    ostBot.connection.Send("save");
                }
                break;

            case "clear":
                if (isBotMod)
                {
                    ostBot.connection.Send("clear");
                }
                break;

            case "kick":
                break;

            case "ban":
                break;

            case "fill":           //<blocktyp><data> / <blocktyp><lager> / <blocktyp><pengar till pengardörr>..   //med arean mellan 2 block
                new Task(() =>
                {
                    if (args.Length > 1 && isBotMod)
                    {
                        int blockId;
                        Int32.TryParse(args[1], out blockId);
                        int layer = (blockId >= 500) ? 1 : 0;
                        for (int y = 1; y < ostBot.room.height - 1; y++)
                        {
                            for (int x = 1; x < ostBot.room.width - 1; x++)
                            {
                                ostBot.room.DrawBlock(Block.CreateBlock(layer, x, y, blockId, null));
                            }
                        }
                    }
                }).Start();
                break;

            case "fillworld":      //<blocktyp><data>
                break;

            case "fillarea":       //<x1><y1><x2><y2><blocktyp><data>
                break;

            case "fillexpand":
            {
                int toReplace     = 0;
                int toReplaceWith = 0;
                if (args.Length == 2)
                {
                    if (!int.TryParse(args[1], out toReplaceWith))
                    {
                        ostBot.connection.Send("say", "Usage: !fillexpand <from id=0> <to id>");
                        return;
                    }
                }
                else if (args.Length == 3)
                {
                    if (!int.TryParse(args[2], out toReplaceWith) || !int.TryParse(args[1], out toReplace))
                    {
                        ostBot.connection.Send("say", "Usage: !fillexpand <from id=0> <to id>");
                        return;
                    }
                }
                Block startBlock = ostBot.room.getBotMapBlock(0, /*_*//*player.blockX, player.blockY*/ 0, 0);
                if (startBlock.blockId == toReplace)
                {
                    int          total       = 0;
                    List <Point> closeBlocks = new List <Point> {
                        new Point(1, 0), new Point(-1, 0), new Point(0, 1), new Point(0, -1)
                    };
                    Queue <Point> blocksToCheck = new Queue <Point>();
                    List <Point>  blocksToFill  = new List <Point>();
                    blocksToCheck.Enqueue(new Point(startBlock.x, startBlock.y));
                    while (blocksToCheck.Count > 0)
                    {
                        Point parent = blocksToCheck.Dequeue();
                        //if (!blocksToFill.Contains(parent))
                        for (int i = 0; i < closeBlocks.Count; i++)
                        {
                            Point current      = new Point(closeBlocks[i].X + parent.X, closeBlocks[i].Y + parent.Y);
                            Block currentBlock = ostBot.room.getBotMapBlock(0, current.X, current.Y);
                            if (currentBlock.blockId == toReplace && !blocksToCheck.Contains(current) && !blocksToFill.Contains(current) && current.X >= 0 && current.Y >= 0 && current.X <= ostBot.room.width && current.Y <= ostBot.room.height)
                            {
                                blocksToFill.Add(current);
                                blocksToCheck.Enqueue(current);
                                total++;
                                if (total > 10000)
                                {
                                    ostBot.connection.Send("say", "Don't try to fill the whole world, fool!");
                                    return;
                                }
                            }
                        }
                    }
                    ostBot.connection.Send("say", "total blocks: " + total + ". Filling..");
                    foreach (Point p in blocksToFill)
                    {
                        ostBot.room.DrawBlock(Block.CreateBlock(0, (int)p.X, (int)p.Y, toReplaceWith, player));
                    }
                }
            }
            break;

            case "replace":            //med arean mellan 2 block
                new Task(() =>
                {
                    if (args.Length > 2 && isBotMod)
                    {
                        int blockId1, blockId2;
                        Int32.TryParse(args[1], out blockId1);
                        Int32.TryParse(args[2], out blockId2);
                        int layer1 = (blockId1 >= 500) ? 1 : 0;
                        int layer2 = (blockId2 >= 500) ? 1 : 0;
                        for (int y = 1; y < ostBot.room.height - 1; y++)
                        {
                            for (int x = 1; x < ostBot.room.width - 1; x++)
                            {
                                if (ostBot.room.getBotMapBlock(layer1, x, y).blockId == blockId1)
                                {
                                    ostBot.room.DrawBlock(Block.CreateBlock(layer2, x, y, blockId2, null));
                                }
                            }
                        }
                    }
                }).Start();
                break;

            case "replaceworld":
                break;

            case "replacearea":
                break;

            case "getplacer":
                if (!getPlacerPlayers.Contains(name))
                {
                    getPlacerPlayers.Add(name);
                }
                break;

            case "protect":             //<name>
                if (args.Length > 1 && isBotMod)
                {
                    if (!protectedPlayers.Contains(args[1]))
                    {
                        protectedPlayers.Add(args[1]);
                    }
                }
                break;

            case "unprotect":             //<name>
                if (args.Length > 1 && isBotMod)
                {
                    if (protectedPlayers.Contains(args[1]))
                    {
                        protectedPlayers.Remove(args[1]);
                    }
                }
                break;

            case "repair":              //<name>
                if (args.Length > 1 && isBotMod)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        for (int y = 0; y < ostBot.room.height; y++)
                        {
                            for (int x = 0; x < ostBot.room.width; x++)
                            {
                                Block block;

                                //if (ostBot.room.getBotMapBlock(l, x, y).b_userId == -1)
                                //    continue;


                                for (int i = 0; true; i++)
                                {
                                    block = ostBot.room.getMapBlock(l, x, y, i);
                                    string userName = "";
                                    lock (ostBot.playerList)
                                    {
                                        if (ostBot.playerList.ContainsKey(block.placer.UserId))
                                        {
                                            userName = block.placer.Name;
                                        }
                                    }
                                    if (userName == "")     //else if
                                    {
                                        lock (ostBot.leftPlayerList)
                                        {
                                            if (ostBot.leftPlayerList.ContainsKey(block.placer.UserId))
                                            {
                                                userName = block.placer.Name;
                                            }
                                        }
                                    }

                                    //if (protectedPlayers.Contains(userName))
                                    //    break;

                                    if (userName == args[1])
                                    {
                                        ostBot.room.DrawBlock(block);
                                        break;
                                    }
                                    else
                                    {
                                        //Console.WriteLine("block borttaget från" + userName);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case "repairprotected":              //<name>
                if (args.Length > 1 && isBotMod)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        for (int y = 0; y < ostBot.room.height; y++)
                        {
                            for (int x = 0; x < ostBot.room.width; x++)
                            {
                                Block block;

                                //if (ostBot.room.getBotMapBlock(l, x, y).b_userId == -1)
                                //    continue;


                                for (int i = 0; true; i++)
                                {
                                    block = ostBot.room.getMapBlock(l, x, y, i);
                                    string userName = "";
                                    lock (ostBot.playerList)
                                    {
                                        if (ostBot.playerList.ContainsKey(block.placer.UserId))
                                        {
                                            userName = block.placer.Name;
                                        }
                                    }
                                    if (userName == "")     //else if
                                    {
                                        lock (ostBot.leftPlayerList)
                                        {
                                            if (ostBot.leftPlayerList.ContainsKey(block.placer.UserId))
                                            {
                                                userName = block.placer.Name;
                                            }
                                        }
                                    }

                                    //
                                    //    break;

                                    if (protectedPlayers.Contains(userName))    //if (userName == args[1])
                                    {
                                        ostBot.room.DrawBlock(block);
                                        break;
                                    }
                                    else
                                    {
                                        //Console.WriteLine("block borttaget från" + userName);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case "disableedit":        //<spelarnamn>
                if (args.Length > 1 && isBotMod)
                {
                    lock (disabledPlayers)
                    {
                        if (!disabledPlayers.Contains(args[1]))
                        {
                            disabledPlayers.Add(args[1]);
                        }
                    }
                }
                break;

            case "enableedit":        //<spelarnamn>
                if (args.Length > 1 && isBotMod)
                {
                    lock (disabledPlayers)
                    {
                        if (disabledPlayers.Contains(args[1]))
                        {
                            disabledPlayers.Remove(args[1]);
                        }
                    }
                }
                break;

            case "rollback":       //<spelarnamn>
                if (args.Length > 1 && isBotMod)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        for (int y = 0; y < ostBot.room.height; y++)
                        {
                            for (int x = 0; x < ostBot.room.width; x++)
                            {
                                Block block;

                                {
                                    Block block2 = ostBot.room.getBotMapBlock(l, x, y);

                                    if (block2.placer != null)
                                    {
                                        if (block2.placer.UserId == -1)
                                        {
                                            continue;
                                        }
                                    }
                                }


                                for (int i = 0; true; i++)
                                {
                                    block = ostBot.room.getMapBlock(l, x, y, i);
                                    string userName = "";
                                    if (block.placer != null)
                                    {
                                        userName = block.placer.Name;
                                    }

                                    /*lock (ostBot.playerList)
                                     * {
                                     *  if (ostBot.playerList.ContainsKey(block.placer.UserId))
                                     *  {
                                     *      userName = block.placer.Name;
                                     *  }
                                     * }
                                     * if (userName == "") //else if
                                     * {
                                     *  lock (ostBot.leftPlayerList)
                                     *  {
                                     *      if (ostBot.leftPlayerList.ContainsKey(block.placer.UserId))
                                     *      {
                                     *          userName = block.placer.Name;
                                     *      }
                                     *  }
                                     * }*/

                                    if (userName != args[1])
                                    {
                                        ostBot.room.DrawBlock(block);
                                        break;
                                    }
                                    else
                                    {
                                        //Console.WriteLine("block borttaget från" + userName);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case "votedisable":
                if (args.Length > 1)
                {
                    int playerId;
                    lock (ostBot.nameList)
                    {
                        if (ostBot.nameList.ContainsKey(args[1]))
                        {
                            playerId = ostBot.nameList[args[1]];
                        }
                        else
                        {
                            break;
                        }
                    }
                    Player playerToDisable;
                    lock (ostBot.playerList)
                    {
                        if (ostBot.playerList.ContainsKey(playerId))
                        {
                            playerToDisable = ostBot.playerList[playerId];
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                break;
            }
        }
Esempio n. 10
0
 public Commands(OstBot ostBot)
     : base(ostBot)
 {
     enabled = true;
 }
Esempio n. 11
0
        private void BlockDrawer(OstBot ostBot)
        {
            ostBot.connection.Send(ostBot.worldKey + "k", true);
            if (!blockDrawerEnabled)
            {
                blockDrawerEnabled = true;
                new Thread(() =>
                {
                    try
                    {
                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();

                        while (ostBot.connected)
                        {
                            while (ostBot.hasCode)
                            {
                                lock (blockQueue)
                                {
                                    if (blockQueue.Count != 0)
                                    {
                                        if (blockSet.Contains(blockQueue.Peek()))
                                        {
                                            //Console.WriteLine("jag är en sjuk sak");
                                            blockQueue.Peek().Send(ostBot.connection);
                                            lock (blockRepairQueue)
                                                blockRepairQueue.Enqueue(blockQueue.Dequeue());
                                            //Console.WriteLine("!!");
                                        }
                                        else
                                        {
                                            blockQueue.Dequeue();
                                            continue;
                                        }
                                    }
                                    else if (blockRepairQueue.Count != 0)
                                    {
                                        while (!blockSet.Contains(blockRepairQueue.Peek()))
                                        {
                                            blockRepairQueue.Dequeue();
                                            if (blockRepairQueue.Count == 0)
                                            {
                                                break;
                                            }
                                        }

                                        if (blockRepairQueue.Count == 0)
                                        {
                                            continue;
                                        }

                                        blockRepairQueue.Peek().Send(ostBot.connection);
                                        blockRepairQueue.Enqueue(blockRepairQueue.Dequeue());
                                    }
                                    else
                                    {
                                        Thread.Sleep(5);
                                        continue;
                                    }
                                    double sleepTime = drawSleep - stopwatch.Elapsed.TotalMilliseconds;
                                    if (sleepTime >= 0.5)
                                    {
                                        Thread.Sleep((int)sleepTime);
                                    }
                                    stopwatch.Reset();
                                }
                            }
                            Thread.Sleep(100);
                        }
                    }
                    catch (Exception e)
                    {
                        ostBot.shutdown();
                        throw e;
                    }
                }).Start();
            }
        }
Esempio n. 12
0
 public Room(OstBot ostBot)
     : base(ostBot)
 {
     enabled = true;
 }
Esempio n. 13
0
        public override void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
        {
            //try
            //{
            switch (m.Type)
            {
            case "init":
                bool isOwner;
                if (ostBot.isBB)
                {
                    //worldKey = rot13(m[3].ToString());
                    //botPlayerID = m.GetInt(6);
                    width  = m.GetInt(10);
                    height = m.GetInt(11);
                    //hasCode = m.GetBoolean(8);
                    isOwner = m.GetBoolean(9);
                }
                else
                {
                    //worldKey = rot13(m[5].ToString());
                    //botPlayerID = m.GetInt(6);
                    width  = m.GetInt(12);
                    height = m.GetInt(13);
                    //hasCode = m.GetBoolean(10);
                    isOwner = m.GetBoolean(11);
                }


                if (isOwner)
                {
                    BlockDrawer(ostBot);
                }

                lock (blockMap)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        blockMap[l] = new List <Block> [width, height];

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                blockMap[l][x, y] = new List <Block>();
                            }
                        }
                    }
                }

                LoadMap(m, 18);
                break;

            case "reset":

                lock (blockMap)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        blockMap[l] = new List <Block> [width, height];

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                blockMap[l][x, y] = new List <Block>();
                            }
                        }
                    }
                }
                LoadMap(m, 0);
                break;

            case "access":
                Thread.Sleep(5);
                BlockDrawer(ostBot);
                break;

            case "b":
            {
                Block  block;
                Player placer = null;

                while (blockMap == null)
                {
                    Thread.Sleep(5);
                }

                while (blockMap[m.GetInt(0)] == null)
                {
                    Thread.Sleep(5);
                }

                Block newBlock = new Block(m, ostBot);

                lock (blockMap)
                    blockMap[m.GetInt(0)][m.GetInt(1), m.GetInt(2)].Add(newBlock);

                if (m.Count >= 5)
                {
                    block = Block.CreateBlock(m.GetInt(0), m.GetInt(1), m.GetInt(2), m.GetInt(3), newBlock.placer);
                }
                else
                {
                    block = Block.CreateBlock(m.GetInt(0), m.GetInt(1), m.GetInt(2), m.GetInt(3), null);
                }

                OnBlockDraw(block);
            }
            break;

            case "bc":     // bc, bs, pt, lb, br
            {
                Block block;

                while (blockMap == null)
                {
                    Thread.Sleep(5);
                }

                while (blockMap[0] == null)
                {
                    Thread.Sleep(5);
                }

                block = new Block(m, ostBot);

                lock (blockMap)
                    blockMap[0][m.GetInt(0), m.GetInt(1)].Add(block);

                OnBlockDraw(block);
            }
            break;

            case "bs":
                goto case "bc";

            case "pt":
                goto case "bc";

            case "lb":
                goto case "bc";

            case "br":
                goto case "bc";

            case "clear":
            {
                //Redstone.ClearLists();
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        for (int i = 0; i < blockMap.Length; i++)
                        {
                            blockMap[i][x, y].Add(Block.CreateBlock(0, x, y, 0, null));
                        }
                    }
                }
                DrawBorder();
            }
            break;
            }
            //}
            //catch (Exception e)
            //{
            // ostBot.shutdown();
            //throw e;
            //}
        }