Ejemplo n.º 1
0
 void TryConnect(string wid, bool useToken, int retries, int timeout)
 {
     re.Reset();
     if (retries < 0)
     {
         this.InvokeX(() =>
         {
             MessageBox.Show(this, "Timed out, max retry limit reached. Wrong world id?", "Timeout", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             EnableMainPanel();
         });
         return;
     }
     //if (cachedToken == null)
     //    if (useToken) cli = new EEWClient(File.ReadAllText(EEWClient.TokenPath));
     //    else
     //    {
     //        var creds = File.ReadAllLines(EEWClient.TokenPath);
     //        cli = new EEWClient(creds[0], creds[1], out cachedToken);
     //    }
     //else cli = new EEWClient(cachedToken);
     //cli.OnMessage += (o, e) =>
     //{
     //    if (e.Type == MessageType.SelfInfo) username = e.GetString(0);
     //};
     //string token;
     try
     {
         string token = null;
         this.InvokeX(() => token = Clipboard.GetText());
         cli = new EEUClient(token);
         cli.OnDisconnect += OnDisconnect;
         cli.Connect();
     }
     catch (Exception ex)
     {
         this.InvokeX(() =>
         {
             MessageBox.Show(this, "Make sure you copied your EEU token to clipboard.\n" + ex.ToString(), "Error connecting", MessageBoxButtons.OK, MessageBoxIcon.Error);
             EnableMainPanel();
         });
         return;
     }
     con = cli.CreateWorldConnection(wid);
     //con.UseAsync = true;
     //con.UseLocking = false;
     con.OnMessage += OnMessage;
     con.Init();
     if (!re.Wait(timeout))
     {
         cli?.Dispose();
         TryConnect(wid, useToken, retries - 1, timeout + 750);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            cli = new EEUClient(GetClipboardText());         //get eeu token from clipboard
            cli.Connect();                                   //don't forget to connect

            Console.WriteLine(cli.SelfInfo.ToString());      //print info about self

            var lobby = cli.CreateLobbyConnection();         //get lobby

            Console.WriteLine(lobby.LoadStats().ToString()); //print lobby stats
            foreach (var room in lobby.LoadRooms())
            {                                                //print every room in lobby
                Console.WriteLine(room.ToString());
            }

            data           = new RoomData();
            con            = cli.CreateWorldConnection("worldid"); //connect to world
            con.OnMessage += OnMessage;
            con.ChatPrefix = "[ExampleBot] ";                      //change prefix for commands like Chat
            con.Init();

            List <BlockId> blockids = (Enum.GetValues(typeof(BlockId)) as BlockId[]).ToList();//get all BlockId values and store them in a list
            int            id       = 0;

            while (cli.Connected)
            {                       //fill world with incrementing ids
                Console.ReadLine(); //wait for enter key
                for (int i = 0; i < 3; i++)
                {
                    for (int y = 0; y < data.Height; y++)
                    {
                        for (int x = 0; x < data.Width; x++)
                        {                             //loop over world
                            var bid = blockids[id++]; //get next block in list
                            if (id >= blockids.Count)
                            {
                                id = 0;                             //loop over
                            }
                            var layer = bid.IsBackground() ? 0 : 1; //if block is bg, place it in bg layer
                            if (data.Blocks[layer, x, y].Id != (ushort)bid)
                            {
                                con.PlaceBlock(layer, x, y, bid);                                            //place block
                            }
                        }//for x,y
                    }
                    Thread.Sleep(1);//small delay
                }//for

                FillWorld(0, 1);//clear foreground layer
            }//while
            Console.WriteLine("not connected");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "disconnect")
            {
                button1.Enabled = false;
                players.Clear();
                zones.Clear();
                listBox1.Items.Clear();
                listBox2.Items.Clear();
                cli?.Dispose();
                b?.Dispose();
                b2?.Dispose();
                g?.Dispose();
                g2?.Dispose();
                pictureBox1.Image = null;
                pictureBoxWithInterpolationMode1.Image = null;
                button1.Text    = "connect";
                button1.Enabled = true;
                return;
            }
            button1.Enabled = false;
            var wid = textBox1.Text;

            File.WriteAllText(WIDPATH, wid);
            try
            {
                cli = new EEUClient(Clipboard.GetText());
                cli.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                button1.Enabled = true;
                return;
            }
            data              = new RoomData();
            cli.OnDisconnect += delegate(object o, CloseEventArgs ee) { MessageBox.Show(ee.ToString(), "OnDisconnect", MessageBoxButtons.OK, MessageBoxIcon.Error); };
            con            = cli.CreateWorldConnection(wid);
            con.OnMessage += OnMessage;
            con.Init();
            button1.Text    = "disconnect";
            button1.Enabled = true;
        }