private void passwordCheck()
 {
     maxattemptsreached = false;
     try
     {
         server = client.GetStream();
         byte[] inStream = new byte[100250];
         server.Read(inStream, 0, (int)client.ReceiveBufferSize);
         string returndata = System.Text.Encoding.ASCII.GetString(inStream);
         returndata = returndata.Substring(0, returndata.IndexOf("$"));
         returndata = encryptionClass.Decrypt(returndata, "1s 1t 0k %!1,5");
         if (returndata == "NothingWrong")
         {
             if (mainWindowClass.passwordToConnect != "")
             {
                 sendCommand(mainWindowClass.passwordToConnect, "Th15 p@55w0r4 w111 b3 r3c31v3d %!1");
             }
             else
             {
                 sendCommand("D3f@u1t p@55w0rd %!0", "Th15 p@55w0r4 w111 b3 r3c31v3d %!1");
             }
             server   = client.GetStream();
             inStream = new byte[100250];
             server.Read(inStream, 0, (int)client.ReceiveBufferSize);
             returndata = System.Text.Encoding.ASCII.GetString(inStream);
             returndata = returndata.Substring(0, returndata.IndexOf("$"));
             returndata = encryptionClass.Decrypt(returndata, "Th15 1s th3 r3sp0ns3 %!2");
             if (returndata != "FailedToDecrypt")
             {
                 if (returndata.Substring(0, 15) == "YouShallNotPass")
                 {
                     isConnected   = false;
                     invalidServer = false;
                     attempts      = returndata.Substring(15);
                 }
                 else if (returndata.Substring(0, 12) == "YouShallPass")
                 {
                     isConnected   = true;
                     invalidServer = false;
                 }
             }
             else
             {
                 isConnected   = false;
                 invalidServer = true;
             }
         }
         else
         {
             isConnected        = false;
             invalidServer      = false;
             maxattemptsreached = true;
         }
     }
     catch (Exception)
     {
         //MessageBox.Show(e.ToString());
         isConnected   = false;
         invalidServer = true;
     }
 }
Beispiel #2
0
        public void openServer()
        {
            mainWindowClass.serverStatus = true;
            checkClient();
            while (isConnected)
            {
                try
                {
                    networkStream = client.GetStream();
                    byte[] byteFrom = new byte[100250];
                    networkStream.Read(byteFrom, 0, (int)client.ReceiveBufferSize);
                    string dataFromClient = System.Text.Encoding.ASCII.GetString(byteFrom);
                    dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                    dataFromClient = encryptionClass.Decrypt(dataFromClient, "c0mm@nds t0 s3nd %!3");
                    if (dataFromClient != "FailedToDecrypt")
                    {
                        if (dataFromClient == "Closes")
                        {
                            closeServer();
                            isConnected = false;
                        }
                        string command = dataFromClient.Substring(0, 6);
                        switch (command)
                        {
                        case "strmnt":
                        {
                            command = dataFromClient.Substring(6);
                            int    i   = 0;
                            string aux = "";
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            //MessageBox.Show(aux);
                            sendCommandsServerClass.warningCpu = Int32.Parse(aux);
                            //MessageBox.Show(sendCommandsServerClass.warningRAM);
                            aux = "";
                            i++;
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            sendCommandsServerClass.warningRAM = Int32.Parse(aux);
                            aux = "";
                            i++;
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            sendCommandsServerClass.warningTime      = Int32.Parse(aux);
                            sendCommandsServerClass.monitoringStatus = true;
                            Thread startMonitoring = new Thread(sendCommandsServerClass.startMonitoring);
                            startMonitoring.Start();
                        };
                            break;

                        case "strchg":
                        {
                            command = dataFromClient.Substring(6);
                            int    i   = 0;
                            string aux = "";
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            //MessageBox.Show(aux);
                            if (sendCommandsServerClass.warningCpu != Int32.Parse(aux))
                            {
                                sendCommandsServerClass.warningCpu = Int32.Parse(aux);
                                sendCommandsServerClass.hintsCpu   = 0;
                            }
                            //MessageBox.Show(sendCommandsServerClass.warningRAM);
                            aux = "";
                            i++;
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            if (sendCommandsServerClass.warningRAM != Int32.Parse(aux))
                            {
                                sendCommandsServerClass.warningRAM = Int32.Parse(aux);
                                sendCommandsServerClass.hintsRam   = 0;
                            }
                            aux = "";
                            i++;
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            if (sendCommandsServerClass.warningTime != Int32.Parse(aux))
                            {
                                sendCommandsServerClass.warningTime = Int32.Parse(aux);
                                sendCommandsServerClass.hintsCpu    = 0;
                                sendCommandsServerClass.hintsRam    = 0;
                            }
                        }; break;

                        case "scrsht":
                        {
                            sendPhoto(sendCommandsServerClass.screenshot());
                        };
                            break;

                        case "sndfil":
                        {
                            command = dataFromClient.Substring(6);
                            int    i = 0;
                            long   fileLenght;
                            string fileName = "", aux = "";
                            while (command[i] != '?')
                            {
                                fileName += command[i];
                                i++;
                            }
                            i++;
                            while (command[i] != ' ')
                            {
                                aux += command[i];
                                i++;
                            }
                            fileLenght = Int64.Parse(aux);
                            receiveFile(fileName, fileLenght);
                        }; break;

                        case "stpmnt": sendCommandsServerClass.monitoringStatus = false; break;

                        case "closec": sendCommandsServerClass.closeComputer(); break;

                        case "restar": sendCommandsServerClass.restartComputer(); break;

                        case "sleepq": sendCommandsServerClass.sleepComputer(); break;

                        case "messag":
                        {
                            command = dataFromClient.Substring(6);
                            if (mainWindowClass.chatOpen)
                            {
                                mainWindowClass.chatWindow.Dispatcher.Invoke(new Action(() => mainWindowClass.chatWindow.receiveMessage(command, true)));
                            }
                            else
                            {
                                mainWindowClass.Dispatcher.Invoke(new Action(() => mainWindowClass.chatButtonClick(command, true)));
                            }
                        }; break;
                        }
                    }
                    else
                    {
                        isConnected = false;
                    }
                }
                catch (Exception)
                {
                    isConnected = false;
                }
            }
            sendCommandsServerClass.monitoringStatus = false;
            client.Close();
            if (mainWindowClass.keepServerOnAfterClient)
            {
                openServer();
            }
            else
            {
                mainWindowClass.canCloseTheApplication = true;
                mainWindowClass.serverStatus           = false;
            }
            server.Stop();
            mainWindowClass.chatAvalible = false;
            mainWindowClass.restoreConnectPage1Default();
            if (mainWindowClass.chatWindow != null)
            {
                mainWindowClass.Dispatcher.Invoke(new Action(() => mainWindowClass.chatWindow.Close()));
            }
        }