Ejemplo n.º 1
0
        // read console input and act
        private void readConsoleInput(string mT)
        {
            string mainText = mT;

            // basic help information and all available commands
            #region available commands
            if (mainText.ToLower().Trim() == "/help".ToString().ToLower().Trim())
            {
                MainConsole.AppendText("\nList of available commands:");
                MainConsole.AppendText("\n/help ability {ability name}");
                MainConsole.CaretPosition = MainConsole.CaretPosition.DocumentEnd;
            }
            #endregion

            // help for all abilities
            #region all abilities
            else if (mainText.ToLower().Trim() == "/help ability adaptability".ToString().ToLower().Trim())
            {
                //adaptabilityInfo();
            }
            #endregion

            // unrecognized command information
            else
            {
                MainConsole.AppendText("\nUnrecognized command. Use /help to see a list of available commands.");
                MainConsole.CaretPosition = MainConsole.CaretPosition.DocumentEnd;
            }
        }
Ejemplo n.º 2
0
 private void ConnectButton_Click(object sender, EventArgs e) //Connect to server
 {
     if (Regex.IsMatch(IP_TextBox.Text, @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b") && !connected)
     {
         client = new TcpClient();
         IPEndPoint IP_End = new IPEndPoint(IPAddress.Parse(IP_TextBox.Text), int.Parse(Port_TextBox.Text));
         try
         {
             client.Connect(IP_End);
             if (client.Connected)
             {
                 connected = true;
                 MainConsole.AppendText("Connected \n");
                 STW           = new StreamWriter(client.GetStream());
                 STR           = new StreamReader(client.GetStream());
                 STW.AutoFlush = true;
                 backgroundWorker1.RunWorkerAsync();
             }
         }
         catch (Exception exc)
         {
             backgroundWorker1.CancelAsync();
             MessageBox.Show(exc.Message.ToString());
         }
     }
     else
     {
         if (connected)
         {
             MessageBox.Show("Already connected");
         }
         else
         {
             MessageBox.Show("Wrong IP Address");
         }
     }
 }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            InputWord.Text = InputWord.Text.Replace("\n", "");

            MainConsole.Clear();

            MainConsole.AppendText("Старт\n");
            MainConsole.Select(0, 5);
            MainConsole.SelectionFont = new Font(MainConsole.Font.FontFamily, this.Font.Size, FontStyle.Bold);

            string word = InputWord.Text;
            List <Tuple <string, string> > list = new List <Tuple <string, string> >();


            for (int i = 1; i <= number_of_enter; ++i)
            {
                string enter = (panel.Controls.Find("In" + i, true)[0] as TextBox).Text;
                string exit  = (panel.Controls.Find("Out" + i, true)[0] as TextBox).Text;

                list.Add(new Tuple <string, string>(enter, exit));
            }

            MainConsole.AppendText("Слово: " + word + "\n");
            MainConsole.Select(6, 6);
            MainConsole.SelectionFont = new Font(MainConsole.Font.FontFamily, this.Font.Size, FontStyle.Bold);

            while (true)
            {
                bool exit = true;

                for (int i = 0; i < number_of_enter; ++i)
                {
                    if (list[i].Item1 == "")
                    {
                        word = list[i].Item2 + word;

                        MainConsole.AppendText("Подстановка " + (i + 1) + ":  " + word + "\n");
                        MainConsole.Select(MainConsole.Text.Length - word.Length - 17, 13);
                        MainConsole.SelectionFont = new Font(MainConsole.Font.FontFamily, this.Font.Size, FontStyle.Bold);

                        exit = (panel.Controls.Find("End" + (i + 1), true)[0] as CheckBox).Checked;
                        break;
                    }

                    int index = word.IndexOf(list[i].Item1);

                    if (index != -1)
                    {
                        word = word.Remove(index, list[i].Item1.Length);
                        word = word.Insert(index, list[i].Item2);

                        MainConsole.AppendText("Подстановка " + (i + 1) + ":  " + word + "\n");
                        MainConsole.Select(MainConsole.Text.Length - word.Length - 17, 13);
                        MainConsole.SelectionFont = new Font(MainConsole.Font.FontFamily, this.Font.Size, FontStyle.Bold);

                        exit = (panel.Controls.Find("End" + (i + 1), true)[0] as CheckBox).Checked;
                        break;
                    }
                }

                if (exit)
                {
                    MainConsole.AppendText("Стоп: " + word + "\n");
                    MainConsole.Select(MainConsole.Text.Length - word.Length - 8, 6);
                    MainConsole.SelectionFont = new Font(MainConsole.Font.FontFamily, this.Font.Size, FontStyle.Bold);
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            while (client.Connected)
            {
                try
                {
                    received_text = STR.ReadLine();

                    //haslo
                    if (received_text == "250 User Ok")
                    {
                        STW.WriteLine("pass " + password);
                    }

                    if (received_text == "250 Pass Ok")
                    {
                        logged_in = true;
                    }


                    if (received_text == "250 Ok")
                    {
                        STW.WriteLine("rcpt to: " + "<" + to + ">");
                    }

                    if (received_text == "250 Accepted")
                    {
                        STW.WriteLine("data");
                    }

                    if (received_text == ("354 Ok Send data"))
                    {
                        STW.WriteLine("From: " + SenderTextBox.Text);
                        STW.WriteLine("To: " + ReceiverTextBox.Text);
                        STW.WriteLine("Subject: " + SubjectTextBox.Text);
                        STW.WriteLine(DataTextBox.Text);
                        if (!has_file)
                        {
                            STW.WriteLine(".");
                            STW.WriteLine("No files");
                        }
                        else
                        {
                            STW.WriteLine(".");
                            STW.WriteLine("Size " + fileBytes.Length.ToString());
                        }
                    }

                    if (received_text == "250 Size Ok")
                    {
                        STW.WriteLine("FileName " + fileName);
                    }

                    if (received_text == "250 Ready")
                    {
                        sending_file = true;

                        if (sending_file)
                        {
                            this.MainConsole.Invoke(new MethodInvoker(delegate() { MainConsole.AppendText(received_text + "\n"); }));
                            received_text = "";
                            var        stream = client.GetStream();
                            FileStream fs     = new FileStream(filePath, FileMode.Open);

                            //bufferCount = Convert.ToInt32(Math.Ceiling((double)fs.Length / (double)bufferSize));

                            //teraz niepotrzebne
                            //for (int i = 0; i < bufferCount; i++)

                            buffer = new byte[bufferSize];
                            int size = fs.Read(buffer, 0, bufferSize);

                            client.Client.Send(fileBytes, fileSize, SocketFlags.Partial);


                            fs.Close();
                            sending_file = false;
                        }
                    }



                    this.MainConsole.Invoke(new MethodInvoker(delegate() { MainConsole.AppendText(received_text + "\n"); }));
                    if (!helo)
                    {
                        STW.WriteLine("helo " + clientIP);
                        helo = true;
                    }

                    received_text = "";
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message.ToString());
                }
            }
        }