using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenMetaverse;

namespace StatsInSecondLife
{
    public partial class Form1 : Form
    {
        
        public GridClient client = new GridClient();
     
    
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            InternalDictionary<UUID,OpenMetaverse.FriendInfo> DIC = client.Friends.FriendList;
            button1.Visible = false;
            button2.Visible = true;
            string first_name = textBox1.Text;
            string last_name = textBox2.Text;
            string password = textBox3.Text;
            

            
            if(client.Network.Login(first_name, last_name, password,"My Bot bot","1.0")==true)
            {
                System.Threading.Thread.Sleep(2000);
                listBox1.Items.Add("Number of objects: " + client.Network.CurrentSim.Stats.Objects);
                System.Threading.Thread.Sleep(2000);
                listBox1.Items.Add("Number of Avatars online: " + client.Network.CurrentSim.Stats.Agents);
                System.Threading.Thread.Sleep(2000);
                listBox1.Items.Add("Time in Simulator (seconds): " + client.Network.CurrentSim.Stats.ConnectTime);
                System.Threading.Thread.Sleep(2000);
                
                //----------------------------

                DIC.ForEach(delegate(FriendInfo friend)
			    {
                if(friend.IsOnline == true)
                {
			        listBox2.Items.Add(friend.Name+" - "+"online");
                }
                else
                    listBox2.Items.Add(friend.Name + " - " + "offline");
			    });

                
                
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            button1.Visible = true;
            client.Network.Logout();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            InternalDictionary<UUID, OpenMetaverse.FriendInfo> DIC_UUID = client.Friends.FriendList;
            string NAME = listBox2.SelectedItem.ToString();

            DIC_UUID.ForEach(delegate(FriendInfo friend)
            {
                if (friend.Name == NAME)
                {
                    client.Self.InstantMessage(friend.UUID, textBox4.Text);
                }
            });

            textBox4.Text = "";
        }
    }
}
