private async void Button_Click(object sender, RoutedEventArgs e)
        {
            UserBot userBot = new UserBot();

            userBot.api_id   = Convert.ToInt32(api_id1.Text);
            userBot.api_hash = api_hash1.Text;
            userBot.number   = number1.Text;
            userBot.client   = new TelegramClient(userBot.api_id, userBot.api_hash);
            await userBot.client.ConnectAsync();

            if (userBot.client.Session.AuthKey == null)
            {
                userBot.hash = await userBot.client.SendCodeRequestAsync(userBot.number);
            }
            Clients.Add(userBot);
        }
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            UserBot userBot = Clients[0];

            userBot.code = code1.Text;
            if (userBot.client.Session.AuthKey == null)
            {
                userBot.user = await userBot.client.MakeAuthAsync(userBot.number, userBot.hash, userBot.code);
            }
            else
            {
                userBot.user = userBot.client.Session.TLUser;
            }
            userBot.dialogs = (TLDialogs)await userBot.client.GetUserDialogsAsync();

            userBot.contacts = (TLContacts)await userBot.client.GetContactsAsync();

            exp1.Header = userBot.user.FirstName;
        }
        public void loadAcc()
        {
            String[] lines = File.ReadAllLines("Акаунты.txt");
            for (int i = 0; i < lines.Length; i++)
            {
                UserBot userBot = new UserBot();
                userBot.api_id   = Convert.ToInt32(lines[i].Split(':')[0]);
                userBot.api_hash = lines[i].Split(':')[1];
                userBot.number   = lines[i].Split(':')[2];
                userBot.status   = "need get code";
                Button button = new Button();
                button.Content = userBot.number;
                button.Width   = 120;
                button.Margin  = new Thickness(0, 0, 0, 5);
                button.Height  = 30;
                button.Click  += Button_AuthAndSendMessage;

                TextBox textBox = new TextBox();
                textBox.Width  = 60;
                textBox.Height = 30;
                textBox.Text   = "";
                textBox.Margin = new Thickness(5, 0, 0, 0);
                textBox.Tag    = button.Content.ToString();

                TextBox textBoxText = new TextBox();
                textBoxText.Width         = 170;
                textBoxText.Height        = 30;
                textBoxText.Text          = "Отправляемый текст";
                textBoxText.Margin        = new Thickness(5, 0, 0, 0);
                textBoxText.Tag           = button.Content.ToString() + "text";
                textBoxText.AcceptsReturn = true;


                SP2.Children.Add(button);
                SP2.Children.Add(textBox);
                SP2.Children.Add(textBoxText);
                SP2.Height += 40;
                Clients.Add(userBot);
            }
        }
Beispiel #4
0
 public override void OnSelfEnterRoom()
 {
     try
     {
         this.botResponse    = new List <BotResponse>();
         this.randomSpeeches = new List <RandomSpeech>();
         using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
         {
             this.uBot = Essential.GetGame().GetCatalog().RetrBot(dbClient.ReadDataRow("SELECT * FROM user_bots WHERE id=" + (base.GetRoomUser().UId - 1000)));
             if (this.uBot.BotType != "default")
             {
                 foreach (DataRow drow in dbClient.ReadDataTable("SELECT * FROM bots_responses WHERE bot_type='" + this.uBot.BotType + "'").Rows)
                 {
                     botResponse.Add(new BotResponse((uint)drow["id"], 0, drow["keywords"].ToString(), drow["response_text"].ToString(), drow["mode"].ToString(), (int)drow["serve_id"]));
                 }
             }
             else
             {
                 foreach (DataRow drow in dbClient.ReadDataTable("SELECT * FROM bots_responses WHERE bot_id='" + this.uBot.BotId + "'").Rows)
                 {
                     botResponse.Add(new BotResponse((uint)drow["id"], 0, drow["keywords"].ToString(), drow["response_text"].ToString(), drow["mode"].ToString(), (int)drow["serve_id"]));
                 }
             }
             DataTable dtable = dbClient.ReadDataTable("SELECT * FROM bots_speech WHERE bot_id='" + this.uBot.BotId + "'");
             foreach (DataRow drow in dtable.Rows)
             {
                 randomSpeeches.Add(new RandomSpeech((string)drow["text"], Essential.StringToBoolean(drow["shout"].ToString()), Convert.ToUInt32(drow["bot_id"])));
             }
             speechInterval = dbClient.ReadInt32("SELECT speaking_interval from user_bots WHERE id = " + this.uBot.BotId);
             canSpeak       = Convert.ToBoolean(dbClient.ReadString("SELECT automatic_chat from user_bots WHERE id = " + this.uBot.BotId));
         }
         this.SpeechTimer = speechInterval * 2;
         this.speechDelta = speechInterval * 2;
         this.ActionTimer = new Random(((int)this.virtualId ^ 2) + DateTime.Now.Millisecond).Next(10, 30);
     }catch
     {
     }
 }
Beispiel #5
0
        public void Handle(GameClient session, ClientMessage message)
        {
            Room room = Essential.GetGame().GetRoomManager().GetRoom(session.GetHabbo().CurrentRoomId);

            if (room != null && (room.CheckRights(session, true)))
            {
                uint    botId = message.PopWiredUInt();
                UserBot bot   = session.GetHabbo().GetInventoryComponent().GetBotById(botId);
                if (bot != null && !bot.PlacedInRoom)
                {
                    int num  = message.PopWiredInt32();
                    int num2 = message.PopWiredInt32();

                    if (room.method_30(num, num2, 0.0, true, false))//&& !room.ContainsBot())
                    {
                        bot.PlacedInRoom = true;
                        bot.RoomId       = (int)room.Id;
                        List <RandomSpeech> list  = new List <RandomSpeech>();
                        List <BotResponse>  list2 = new List <BotResponse>();
                        try
                        {
                            room.AddBotToRoom(new RoomBot(bot.BotId, (uint)bot.RoomId, AIType.UserBot, "freeroam", bot.Name, "", bot.Look, num, num2, 0, 0, 0, 0, 0, 0, ref list, ref list2, 0), bot);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        session.GetHabbo().GetInventoryComponent().RemoveBotById(bot.BotId);
                        using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                        {
                            dbClient.ExecuteQuery("UPDATE user_bots SET room_id = '" + bot.RoomId + "', x = " + num + " , y = " + num2 + " WHERE id = '" + botId + "' LIMIT 1");
                        }
                        session.SendMessage(session.GetHabbo().GetInventoryComponent().ComposeBotInventoryListMessage());
                    }
                }
            }
        }
        private async void Button_AuthAndSendMessage(object sender, RoutedEventArgs e)
        {
            Button  btn           = sender as Button;
            var     controls      = SP2.Children;
            TextBox tb            = null;
            TextBox tbMessageText = null;

            foreach (var control in controls)
            {
                if (control.GetType() == typeof(TextBox))
                {
                    var iterTB = control as TextBox;
                    if (iterTB.Tag.ToString() == btn.Content.ToString())
                    {
                        tb = control as TextBox;
                        continue;
                    }
                    iterTB = control as TextBox;
                    if (iterTB.Tag.ToString() == btn.Content.ToString() + "text")
                    {
                        tbMessageText = control as TextBox;
                        continue;
                    }
                }
            }



            UserBot userBot = Clients.Where(x => x.number == btn.Content.ToString()).First();

            userBot.textMessage = tbMessageText.Text;
            try
            {
                switch (userBot.status)
                {
                case "need get code":
                    if (File.Exists(userBot.number + ".dat"))
                    {
                        userBot.session = new FileSessionStore();
                        userBot.client  = new TelegramClient(userBot.api_id, userBot.api_hash, userBot.session, userBot.number);
                        await userBot.client.ConnectAsync();

                        userBot.status = "code was delivered";
                        try
                        {
                            userBot.dialogs = (TLDialogs)await userBot.client.GetUserDialogsAsync();

                            userBot.contacts = (TLContacts)await userBot.client.GetContactsAsync();

                            userBot.status = "auth";
                            btn.Background = new SolidColorBrush(Colors.LightGreen);
                        }
                        catch (Exception ex)
                        {
                            log.Add("[" + userBot.number + "] - Ошибка авторизации");
                            btn.Background = new SolidColorBrush(Colors.IndianRed);
                            if (File.Exists(userBot.number + ".dat"))
                            {
                                try
                                {
                                    File.Delete(userBot.number + ".dat");
                                }
                                catch
                                {
                                    log.Add("Ошибка удаления файла " + userBot.number + ".dat");
                                }
                            }
                        }
                    }
                    else
                    {
                        userBot.session = new FileSessionStore();
                        userBot.client  = new TelegramClient(userBot.api_id, userBot.api_hash, userBot.session, userBot.number);
                        await userBot.client.ConnectAsync();

                        userBot.hash = await userBot.client.SendCodeRequestAsync(userBot.number);

                        userBot.status = "code was delivered";
                    }

                    break;

                case "code was delivered":
                    userBot.code = tb.Text;
                    userBot.user = await userBot.client.MakeAuthAsync(userBot.number, userBot.hash, userBot.code);

                    try
                    {
                        userBot.dialogs = (TLDialogs)await userBot.client.GetUserDialogsAsync();

                        userBot.contacts = (TLContacts)await userBot.client.GetContactsAsync();

                        userBot.status = "auth";
                        btn.Background = new SolidColorBrush(Colors.LightGreen);
                    }
                    catch (Exception ex)
                    {
                        log.Add("[" + userBot.number + "] - Ошибка авторизации");
                        btn.Background = new SolidColorBrush(Colors.IndianRed);
                        if (File.Exists(userBot.number + ".dat"))
                        {
                            try
                            {
                                File.Delete(userBot.number + ".dat");
                            }
                            catch
                            {
                                log.Add("Ошибка удаления файла " + userBot.number + ".dat");
                            }
                        }
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                btn.Background = new SolidColorBrush(Colors.IndianRed);
            }
        }
        public void Handle(GameClient Session, ClientMessage Event)
        {
            if (!Session.GetHabbo().CurrentRoom.CheckRights(Session, true))
            {
                return;
            }
            Room     room       = Session.GetHabbo().CurrentRoom;
            uint     id         = Event.PopWiredUInt();
            int      ActionType = Event.PopWiredInt32();
            RoomUser BotUser    = room.getBot(id);

            /*string Username = Event.PopFixedString();
             *
             * BotUser.RoomBot.Name = Username;
             * using(DatabaseClient dbClient = Essential.GetDatabase().GetClient())
             * {
             *  dbClient.AddParamWithValue("username", Username);
             *  dbClient.ExecuteQuery("UPDATE user_bots SET name=@username WHERE id=" + id);
             * }*/

            List <RandomSpeech> list  = new List <RandomSpeech>();
            List <BotResponse>  list2 = new List <BotResponse>();
            int     currentX          = BotUser.X;
            int     currentY          = BotUser.Y;
            int     currentRot        = BotUser.BodyRotation;
            double  currentH          = BotUser.double_0;
            UserBot bot = null;

            switch (ActionType)
            {
            case 1:
                string Look = Session.GetHabbo().Figure;
                BotUser.RoomBot.Look = Look;
                room.method_6(BotUser.VirtualId, false);
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.AddParamWithValue("look", Look);
                    dbClient.ExecuteQuery("UPDATE user_bots SET look=@look WHERE id=" + id);
                    bot = Essential.GetGame().GetCatalog().RetrBot(dbClient.ReadDataRow("SELECT * FROM user_bots WHERE id=" + id));
                }
                room.AddBotToRoom(new RoomBot(id, Session.GetHabbo().CurrentRoomId, AIType.UserBot, "freeroam", BotUser.RoomBot.Name, BotUser.RoomBot.Motto, Look, currentX, currentY, 0, currentRot, 0, 0, 0, 0, ref list, ref list2, 0), bot);
                break;

            case 2:
                string   Data = Event.PopFixedString();
                DataRow  BotData;
                string[] firstdata        = Data.Split(';');
                string[] toinendata       = firstdata[0].Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                string   automaticChat    = firstdata[2];
                string   speakingInterval = firstdata[4];    //seconds

                if (String.IsNullOrEmpty(speakingInterval) || Convert.ToInt32(speakingInterval) <= 0)
                {
                    speakingInterval = "7";
                }
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("DELETE FROM bots_speech WHERE bot_id = '" + id + "'");
                }
                for (int i = 0; i <= toinendata.Length - 1; i++)
                {
                    using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                    {
                        dbClient.AddParamWithValue("data", toinendata[i]);
                        dbClient.ExecuteQuery("INSERT INTO `bots_speech` (`bot_id`, `text`) VALUES ('" + id + "', @data)");
                        dbClient.ExecuteQuery("UPDATE user_bots SET automatic_chat='" + automaticChat + "',speaking_interval=" + Convert.ToInt32(speakingInterval) + " WHERE id = " + id);
                    }
                }

                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    BotData = dbClient.ReadDataRow("SELECT * FROM user_bots WHERE id = '" + id + "'");
                }
                DataTable BotSpeech;
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    BotSpeech = dbClient.ReadDataTable("SELECT text, shout, bot_id FROM bots_speech;");
                    bot       = Essential.GetGame().GetCatalog().RetrBot(dbClient.ReadDataRow("SELECT * FROM user_bots WHERE id=" + id));
                }
                foreach (DataRow Row2 in BotSpeech.Rows)
                {
                    list.Add(new RandomSpeech((string)Row2["text"], Essential.StringToBoolean(Row2["shout"].ToString()), Convert.ToUInt32(Row2["bot_id"])));
                }
                room.method_6(BotUser.VirtualId, false);
                room.AddBotToRoom(new RoomBot((uint)BotData["id"], (uint)BotData["room_id"], AIType.UserBot, "freeroam", (string)BotData["name"], (string)BotData["motto"], (string)BotData["look"], currentX, currentY, 0, currentRot, 0, 0, 0, 0, ref list, ref list2, (int)Session.GetHabbo().Id), bot);


                break;

            case 3:
                //stop dancing
                break;

            case 4:
                if (BotUser.DanceId > 0)
                {
                    BotUser.DanceId = 0;
                }
                else
                {
                    Random rnd = new Random();
                    BotUser.DanceId = rnd.Next(1, 4);
                }
                ServerMessage message = new ServerMessage(Outgoing.Dance);
                message.AppendInt32(BotUser.VirtualId);
                message.AppendInt32(BotUser.DanceId);
                Session.GetHabbo().CurrentRoom.SendMessage(message, null);
                break;

            case 5:
                string Username = Event.PopFixedString();
                if (!Essential.IsValidName(Username))
                {
                    break;
                }
                BotUser.RoomBot.Name = Username;
                room.method_6(BotUser.VirtualId, false);
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.AddParamWithValue("username", Username);
                    dbClient.ExecuteQuery("UPDATE user_bots SET name=@username WHERE id=" + id);
                    bot = Essential.GetGame().GetCatalog().RetrBot(dbClient.ReadDataRow("SELECT * FROM user_bots WHERE id=" + id));
                }
                room.AddBotToRoom(new RoomBot(id, Session.GetHabbo().CurrentRoomId, AIType.UserBot, "freeroam", Username, BotUser.RoomBot.Motto, BotUser.RoomBot.Look, currentX, currentY, 0, currentRot, 0, 0, 0, 0, ref list, ref list2, 0), bot);
                break;

            default:
                //nothing
                break;
            }
        }