Пример #1
0
 public void StartServer()
 {
     Console.WriteLine("[PIPE SERVER] Starting pipe server.");
     new Thread(delegate()
     {
         var ps = new PipeSecurity();
         ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
         while (true)
         {
             var pipeServer = NamedPipeServerStreamConstructors.New("ShotrInputHandler", PipeDirection.InOut, 1,
                                                                    PipeTransmissionMode.Message, PipeOptions.WriteThrough, 1024, 1024, ps);
             try
             {
                 Console.WriteLine("[PIPE SERVER] Waiting for client...");
                 pipeServer.WaitForConnection();
                 Console.WriteLine("[PIPE SERVER] Got client through pipe server.");
                 try
                 {
                     var ss   = new StreamString(pipeServer);
                     var data = ss.ReadString();
                     Console.WriteLine($"[PIPE SERVER] Received the message: {data}.");
                     PipeServerReceivedClient.Invoke(this, new PipeServerEventArgs(data));
                 }
                 catch (IOException e)
                 {
                     Console.WriteLine("[PIPE SERVER] ERROR: Pipe client had an error. Code: {0}", e.Message);
                 }
             }
             catch
             {
             }
             pipeServer.Close();
         }
     }).Start();
 }
Пример #2
0
        /// <summary>
        /// Sets <see cref="PipeSecurity"/>'s for each <see cref="NamedPipeServerStream"/> that will be created by <see cref="PipeServer{T}"/> <br/>
        /// Overrides <see cref="PipeServer{T}.CreatePipeStreamFunc"/>
        /// </summary>
        /// <param name="server"></param>
        /// <param name="pipeSecurity"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static void SetPipeSecurity <T>(this IPipeServer <T> server, PipeSecurity pipeSecurity)
        {
            server       = server ?? throw new ArgumentNullException(nameof(server));
            pipeSecurity = pipeSecurity ?? throw new ArgumentNullException(nameof(pipeSecurity));

            server.CreatePipeStreamFunc = pipeName => NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);
        }
Пример #3
0
        private void handleConnection(IAsyncResult res)
        {
            //serverStream = new NamedPipeServerStream($@"\.\DSParamStudio\pipe\CommandQueue", PipeDirection.In, System.IO.Pipes.NamedPipeServerStream.MaxAllowedServerInstances);


            NamedPipeServerStream srv = (NamedPipeServerStream)res.AsyncState;

            //srv.EndWaitForConnection(res);
            serverStream.EndWaitForConnection(res);
            serverStream = NamedPipeServerStreamConstructors.New($@"\.\DSParamStudio\pipe\CommandQueue", PipeDirection.InOut, System.IO.Pipes.NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 0, 0, pipeSecurity);
            serverStream.BeginWaitForConnection(handleConnection, serverStream);
            ServerClient sv = new ServerClient(srv);

            activeConnections.Add(sv);

            while (srv.IsConnected)
            {
                string command = sv.reader.ReadLine();
                if (command != null && command.Length > 0)
                {
                    EditorCommandQueue.AddCommand("windowFocus");
                    EditorCommandQueue.AddCommand(command);
                }
            }
        }
Пример #4
0
        public static NamedPipeServerStream CreatePipe(string pipeName, PipeSecurity pipeSecurity)
        {
#if NETCOREAPP3_1
            return(NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity));
#else
            return(new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity));
#endif
        }
Пример #5
0
 public void DisposeTest()
 {
     {
         using var stream = NamedPipeServerStreamConstructors.New(nameof(NamedPipeServerStreamConstructorsTests));
     }
     {
         using var stream = NamedPipeServerStreamConstructors.New(nameof(NamedPipeServerStreamConstructorsTests));
     }
 }
Пример #6
0
        public void ExceptionTest()
        {
            var exception = Assert.ThrowsException <IOException>(() =>
            {
                using var stream1 = NamedPipeServerStreamConstructors.New(nameof(NamedPipeServerStreamConstructorsTests));
                using var stream2 = NamedPipeServerStreamConstructors.New(nameof(NamedPipeServerStreamConstructorsTests));
            });

            Console.WriteLine(exception.ToString());
        }
Пример #7
0
        public void ProcessNextClient()
        {
            try
            {
                var pipeStream = NamedPipeServerStreamConstructors.New(PipeName, PipeDirection.InOut, _maxConnections,
                                                                       PipeTransmissionMode.Byte, PipeOptions.None, 512, 512, _pipeSecurity);

                pipeStream.WaitForConnection();
                //Task.Factory.StartNew(() => ProcessClientThread(pipeStream), TaskCreationOptions.LongRunning);
                Task.Factory.StartNew(() => ProcessClientThread(pipeStream));
            }
            catch (Exception e)
            {
                //If there are no more avail connections (254 is in use already) then just keep looping until one is avail
                _log.Error("ProcessNextClient error: {0}", e.ToString().Flatten());
            }
        }
Пример #8
0
        public StudioServer()
        {
            try
            {
                pipeSecurity = new PipeSecurity();
                pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));

                serverStream = NamedPipeServerStreamConstructors.New($@"\.\DSParamStudio\pipe\CommandQueue", PipeDirection.InOut, System.IO.Pipes.NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 0, 0, pipeSecurity);

                serverStream.BeginWaitForConnection(handleConnection, serverStream);

                new Thread(TestThread).Start();
            }
            catch
            {
            }
        }
Пример #9
0
        public void RunLoop(string initialURI)
        {
            if (initialURI != null)
            {
                OnToken?.Invoke(this, StartToken.FromString(initialURI));
            }
            while (true)
            {
                PipeSecurity ps = new PipeSecurity();

                ps.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));

                NamedPipeServerStream pipeServer = NamedPipeServerStreamConstructors.New("AmongUsCapturePipe", PipeDirection.InOut, 1, pipeSecurity: ps);

                pipeServer.WaitForConnection();
                Console.WriteLine("Client connected");
                try
                {
                    //Read the request from the client. Once the client has
                    // written to the pipe its security token will be available.
                    StreamString ss = new StreamString(pipeServer);

                    string     rawToken   = ss.ReadString();
                    StartToken startToken = StartToken.FromString(rawToken);
                    Console.WriteLine($@"Decoded message as {JsonConvert.SerializeObject(startToken, Formatting.Indented)}");
                    OnToken?.Invoke(this, startToken);
                }
                // Catch the IOException that is raised if the pipe is broken
                // or disconnected.
                catch (IOException e)
                {
                    Console.WriteLine(@"ERROR: {0}", e.Message);
                }
                pipeServer.Close();
            }
        }
Пример #10
0
 public static NamedPipeServerStream CreatePipe(string pipeName, PipeSecurity pipeSecurity = null)
 {
     return(NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity));
 }