Exemple #1
0
        private static void KeepInTact(Socket s, string pass)
        {
            byte[] bytes = new byte[4096];
            bool   flag  = false;
            int    bytesRec;

            try
            {
                while (!flag) //checks if the password matches with the saved one
                {
                    bytesRec = s.Receive(bytes);
                    data     = Encoding.Unicode.GetString(bytes, 0, bytesRec);
                    if (data == pass)
                    {
                        SendPackets("good to go", s);
                        flag = true;
                    }
                    else
                    {
                        SendPackets("wrong password", s);
                    }
                }
                bytesRec = s.Receive(bytes); //recieves data from the client to save
                data     = Encoding.Unicode.GetString(bytes, 0, bytesRec);
                char[]   sep   = { '+' };
                string[] datas = data.Split(sep);
                Client.CheckAndAdd(s, datas[0], datas[1]);
                WmiFuncs.AddPaths(datas[0]);
                while (true) //and starts listenung to incoming requests
                {
                    bytesRec = s.Receive(bytes);
                    data     = Encoding.Unicode.GetString(bytes, 0, bytesRec);
                    data     = Server.CommandOutput(data, s);
                    SendPackets(data, s);
                    if (data.Contains("disconnect"))
                    {
                        break; // ends communication
                    }
                }
            }
            catch (SocketException)
            {
                Console.WriteLine("Client has disconnected");
            }
        }