Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-11-05 04:07:41

AK712
Member
Joined: 2015-02-16
Posts: 94

Bot Disconnects after X Amount of Blocks Placed

Hello,

This problem has halted development on a few of my bots and I need to know how to fix it. No matter what level my bot is in, it always disconnects after it draws X amount of blocks. No matter what I do, it's always the same... Can someone help? I have no clue why it's doing this... Is it something that was built into EE?


O4DmNuI.png

Offline

#2 2015-11-05 04:42:06

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Bot Disconnects after X Amount of Blocks Placed

sounds like you need a thread

[insert oprah 'you get a bees/suit/whatever' image, but sub it "thread"]

Offline

#3 2015-11-05 04:46:35

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Bot Disconnects after X Amount of Blocks Placed

hummerz5 wrote:

[insert oprah 'you get a bees/suit/whatever' image, but sub it "thread"]

Couldn't have just typed:
"You get a thread! And you get a thread!..."?
Thread.Sleep(10-20); is best.


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#4 2015-11-05 12:56:21

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: Bot Disconnects after X Amount of Blocks Placed


Everybody edits, but some edit more than others

Offline

#5 2015-11-05 13:12:52

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Bot Disconnects after X Amount of Blocks Placed

Ak, perhaps post the code snippet that places the blocks?

Offline

#6 2015-11-05 18:36:09

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Bot Disconnects after X Amount of Blocks Placed

Give us some code and tell us how many blocks it sends before disconnecting; we're not mind readers.

The most likely problem is that you have no delay between each block that you send. EE will disconnect a bot that spams blocks too quickly, as the bot could lag or crash the room.
EE also blocks some packets if a bunch of them are sent too quickly (but not quickly enough for the bot to be kicked), which is why for instance a delay of 7ms will leave gaps in a line of blocks sent.

Xfrogman43 wrote:

Thread.Sleep(10-20); is best.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#7 2015-11-05 22:23:08

AK712
Member
Joined: 2015-02-16
Posts: 94

Re: Bot Disconnects after X Amount of Blocks Placed

for (int i = 0; i < mapsizex; i++)
                    {
                        for (int j = 0; j < mapsizey; j++)
                        {
                            connection.Send(worldKey, 0, i, j, fgarray[j, i]);
                            System.Threading.Thread.Sleep(8);
                            connection.Send(worldKey, 1, i, j, bgarray[j, i]);
                            System.Threading.Thread.Sleep(8);
                        }
                    }

So... It disconnects after about 1000 blocks. I should probably have it System.Threading.Thread.Sleep(100); after every row then... But the problem then would be the sheer amount of time it takes to draw :c


O4DmNuI.png

Offline

#8 2015-11-05 22:29:26, last edited by Tomahawk (2015-11-05 22:36:09)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Bot Disconnects after X Amount of Blocks Placed

Have you tried increasing the delay to about 15ms to see if it still disconnects?

If you add System.Threading to your list of usings, you only have to write Thread.Sleep(8);
Likewise, renaming your connection to "con" saves a surprising amount of time in the long run, even with intellisense.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#9 2015-11-05 22:48:07

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Bot Disconnects after X Amount of Blocks Placed

The minimum delay is 10, if I'm right it's something specified by Player.IO itself, and not necessarily by Everybody Edits.

Tomahawk wrote:

Likewise, renaming your connection to "con" saves a surprising amount of time in the long run, even with intellisense.

I beg to differ.

Offline

#10 2015-11-05 23:14:19

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Bot Disconnects after X Amount of Blocks Placed

den3107 wrote:

I beg to differ.

How about disagreeing with things that actually matter?


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

Wooted by:

#11 2015-11-05 23:23:05

AK712
Member
Joined: 2015-02-16
Posts: 94

Re: Bot Disconnects after X Amount of Blocks Placed

Changing sleep time to 15 and adding a sleep time of 1000 after every row still disconnected the bot. Also, the amount of blocks it disconnected at was ~7850.

By this time it's drawing so absurdly slow... it's almost not worth it.


O4DmNuI.png

Offline

#12 2015-11-05 23:43:10

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Bot Disconnects after X Amount of Blocks Placed

Oh, go ahead and ignore my assistance
no problem
really
I'm not upset
serious. It's totally OK you folks... insert sarcastic retort here... not so much of a rejoinder, though.

Offline

#13 2015-11-06 00:43:44

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Bot Disconnects after X Amount of Blocks Placed

Tomahawk wrote:
den3107 wrote:

I beg to differ.

How about disagreeing with things that actually matter?

About that using the name con would be better.

hummerz5 wrote:

Oh, go ahead and ignore my assistance
no problem
really
I'm not upset
serious. It's totally OK you folks... insert sarcastic retort here... not so much of a rejoinder, though.

Not using a thread won't get you kicked out of the room.

Offline

#14 2015-11-16 05:43:38

AK712
Member
Joined: 2015-02-16
Posts: 94

Re: Bot Disconnects after X Amount of Blocks Placed

Two threads and two different bots placing blocks at the same time... bot users disconnect at the exact same time at the exact same number of blocks. Now I know there's something wrong with the game and not with my bots.

Looks like all my bots just went down the tubes ;-;


O4DmNuI.png

Offline

#15 2015-11-16 08:46:40

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: Bot Disconnects after X Amount of Blocks Placed

It's your connection. I have no problem in placing blocks. And I don't even get disconnected.
If I use EEArtist and get disconnected the bot will automatic upload the rest that it missed after the disconnect.
Maybe you should do something like that?

Offline

#16 2015-11-16 12:43:30, last edited by Processor (2015-11-24 22:47:29)

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Bot Disconnects after X Amount of Blocks Placed

I bet it has something to do with you blocking the main connection thread, which causes it's internal buffer to overload. I just decompiled to check the source code of PlayerIOClient and saw that a buffer overload will indeed automatically disconnect your connection (there are 7200+ "b" messages waiting in line to be received). How confusing!

I assume that you are using .NET 4.0 or better. Run your blocking code in a worker thread then:

Task.Factory.StartNew(() => {
    // Put your for loop here
}, TaskCreationOptions.LongRunning);

I hope this helps.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

Wooted by: (2)

#17 2015-11-16 14:43:55

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Bot Disconnects after X Amount of Blocks Placed

but we said it wasn't the thread, so no

Offline

#18 2015-11-16 15:15:26

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Bot Disconnects after X Amount of Blocks Placed

hummerz5 wrote:

but we said it wasn't the thread, so no

Where?

@AK712 Could you provide us an MCVE? (http://stackoverflow.com/help/mcve)


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

#19 2015-11-17 03:57:38, last edited by hummerz5 (2015-11-17 03:58:06)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Bot Disconnects after X Amount of Blocks Placed

Processor wrote:
hummerz5 wrote:

but we said it wasn't the thread, so no

Where?

@AK712 Could you provide us an MCVE? (http://stackoverflow.com/help/mcve)

hummerz5 wrote:

sounds like you need a thread

den3107 wrote:
hummerz5 wrote:

Oh, go ahead and ignore my assistance
no problem
really
I'm not upset
serious. It's totally OK you folks... insert sarcastic retort here... not so much of a rejoinder, though.

Not using a thread won't get you kicked out of the room.

Offline

#20 2015-11-17 13:29:41

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Bot Disconnects after X Amount of Blocks Placed

I've provided a fairly technical explanation why in this case a thread might be required. I don't see why you would assume that den3107's statement is superior to mine.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

#21 2015-11-17 14:44:15

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Bot Disconnects after X Amount of Blocks Placed

I outlined how I had the same idea and was rejected. It seems my sarcasm wasn't properly conveyed.

Offline

#22 2015-11-17 19:33:41, last edited by Tomahawk (2015-11-17 19:34:15)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Bot Disconnects after X Amount of Blocks Placed

Let's assume that PlayerIO and EE are not the issue, because no other coders have had this problem recently. We can then say that the error's in your code, AK.

So post more of it. The whole method that's writing the blocks (or the code around it if it's not in a method) and where it's called, as well as your connection code - in case you're screwing something up there.

It's a bit pointless to argue about the reason if there's not enough code provided; you make too many assumptions.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#23 2015-11-24 00:49:25

AK712
Member
Joined: 2015-02-16
Posts: 94

Re: Bot Disconnects after X Amount of Blocks Placed

using System;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using PlayerIOClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        static Dictionary<int, userdata> users = new Dictionary<int, userdata>();
        public static int[,] fgarray = new int[300, 300];
        public static int[,] bgarray = new int[300, 300];
        public static int mapsizex = 300;
        public static int mapsizey = 300;
        public static Client client;
        public static Connection connection;
        public static bool connected = false;
        public static string worldKey;
        public bool hasaccess;
        static string derot(string arg1)
        {
            int num = 0;
            string str = "";
            for (int i = 0; i < arg1.Length; i++)
            {
                num = arg1[i];
                if ((num >= 0x61) && (num <= 0x7a))
                {
                    if (num > 0x6d) num -= 13;
                    else num += 13;
                }
                else if ((num >= 0x41) && (num <= 90))
                {
                    if (num > 0x4d) num -= 13;
                    else num += 13;
                }
                str = str + ((char)num);
            }
            return str;
        }
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", textBox1.Text, textBox2.Text);
            connection = client.Multiplayer.CreateJoinRoom("PWUjj3nEicb0I", "public", true, new Dictionary<string, string>(), new Dictionary<string, string>());
            connection.OnMessage += new MessageReceivedEventHandler(this.onMessage);
            connection.Send("init");
        }
        private void button3_Click(object sender, EventArgs e)
        {
            client = PlayerIO.QuickConnect.KongregateConnect("everybody-edits-su9rn58o40itdbnw69plyw", textBox1.Text, textBox2.Text);
            connection = client.Multiplayer.CreateJoinRoom(textBox3.Text, "public", true, new Dictionary<string, string>(), new Dictionary<string, string>());
            connection.OnMessage += new MessageReceivedEventHandler(this.onMessage);
            connection.Send("init");
        }
        public void readFGFile(string file)
        {
            StreamReader sr = new StreamReader(file);
            String line;
            try
            {
                line = sr.ReadLine();
                while (line != null)
                {
                    int[] thisarray = line.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
                    for (int i = 0; i < mapsizey; i++)
                    {
                        for (int j = 0; j < mapsizex; j++)
                        {
                            fgarray[i, j] = thisarray[(i * mapsizex) + j];
                        }
                    }
                    line = sr.ReadLine();
                }
            }
            finally
            {
                sr.Close();
            }
        }
        public void readBGFile(string file)
        {
            StreamReader sr = new StreamReader(file);
            String line;
            try
            {
                line = sr.ReadLine();
                while (line != null)
                {
                    int[] thisarray = line.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
                    for (int i = 0; i < mapsizey; i++)
                    {
                        for (int j = 0; j < mapsizex; j++)
                        {
                            bgarray[i, j] = thisarray[(i * mapsizex) + j];
                        }
                    }
                    line = sr.ReadLine();
                }
            }
            finally
            {
                sr.Close();
            }
        }
        public void onMessage(object sender, PlayerIOClient.Message m)
        {
            if (m.Type == "init")
            {
                fgarray = new int[300, 300];
                bgarray = new int[300, 300];
                for (int x = 0; x < 300; x++)
                {
                    for (int y = 0; y < 300; y++)
                    {
                        fgarray[x, y] = 0;
                        bgarray[x, y] = 0;
                    }
                }
                worldKey = derot(m.GetString(5));
                connection.Send("init2");
                System.Threading.Thread.Sleep(20);
            }
            if (m.Type == "add")
            {
                users.Add(m.GetInt(0), new userdata() { username = m.GetString(1)});
                System.Threading.Thread.Sleep(20);
            }
            if (m.Type == "b")
            {
                if (m.GetInt(0) == 0)
                {
                    fgarray[m.GetInt(2), m.GetInt(1)] = m.GetInt(3);
                }
                else if (m.GetInt(0) == 1)
                {
                    bgarray[m.GetInt(2), m.GetInt(1)] = m.GetInt(3);
                }
            }
            if (m.Type == "say")
            {
                string s = m.GetString(1);
                if (s.StartsWith("!mapsizex ") && users[m.GetInt(0)].username == "ak712")
                {
                    mapsizex = Convert.ToInt32(s.Substring(10));
                    fgarray = new int[mapsizey, mapsizex];
                    bgarray = new int[mapsizey, mapsizex];
                    for (int x = 0; x < mapsizex; x++)
                    {
                        for (int y = 0; y < mapsizey; y++)
                        {
                            fgarray[y, x] = 0;
                            bgarray[y, x] = 0;
                        }
                    }
                }
                if (s.StartsWith("!mapsizey ") && users[m.GetInt(0)].username == "ak712")
                {
                    mapsizey = Convert.ToInt32(s.Substring(10));
                    fgarray = new int[mapsizey, mapsizex];
                    bgarray = new int[mapsizey, mapsizex];
                    for (int x = 0; x < mapsizex - 1; x++)
                    {
                        for (int y = 0; y < mapsizey - 1; y++)
                        {
                            fgarray[y, x] = 0;
                            bgarray[y, x] = 0;
                        }
                    }
                }
                if (s.StartsWith("!createmap") && users[m.GetInt(0)].username == "ak712")
                {
                    mapsizex = 94;
                    mapsizey = 226;
                    fgarray = new int[mapsizey, mapsizex];
                    bgarray = new int[mapsizey, mapsizex];
                    readFGFile("Example.txt");
                    readBGFile("Example2.txt");
                    for (int i = 0; i < mapsizex; i++)
                    {
                        for (int j = 0; j < mapsizey; j++)
                        {
                            if (fgarray[j, i] > 0)
                            {
                                connection.Send(worldKey, 0, i, j, fgarray[j, i]);
                                System.Threading.Thread.Sleep(15);
                            }
                            if (bgarray[j, i] > 0)
                            {
                                connection.Send(worldKey, 1, i, j, bgarray[j, i]);
                                System.Threading.Thread.Sleep(15);
                            }
                        }
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }
        }
        class userdata
        {
            public string username { get; set; }
        }
    }
}

O4DmNuI.png

Offline

#24 2015-11-24 22:40:11, last edited by Tomahawk (2015-11-24 22:41:24)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,835

Re: Bot Disconnects after X Amount of Blocks Placed

Hm.

While there's a number of things in your code which could be corrected or simplified, there's nothing there that would make your bot disconnect while sending blocks.

Have you tested if the bot disconnects while just sitting in a world, or while sending lots of some other message? The problem might not be specifically to do with block sending; for all we know your internet connection could be glitching every few minutes.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#25 2015-11-24 22:48:09

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Bot Disconnects after X Amount of Blocks Placed

You should still try my suggestion.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

AK7121448643958561838

Board footer

Powered by FluxBB

[ Started around 1714084271.9157 - Generated in 0.083 seconds, 10 queries executed - Memory usage: 1.76 MiB (Peak: 2.04 MiB) ]