예제 #1
0
        public void Stop()
        {
            if (!Running)
            {
                throw new InvalidOperationException("Server not running");
            }

            ISLogger.Write("Stopping server");

            foreach (ConnectedClient client in clientMan?.AllClients)
            {
                clientMan.RemoveClient(client);
                client.Dispose();
            }
            tcpListener?.Stop();

            if (inputMan.Running)
            {
                inputMan?.Stop();
            }
            inputMan = null;

            if (curMonitor.Running)
            {
                curMonitor?.Stop();
            }
            curMonitor = null;
            if (procMonitor.Monitoring)
            {
                procMonitor?.StopMonitoring();
            }

            procMonitor = null;
            tcpListener = null;
            Running     = false;
            ServerStopped?.Invoke(this, null);
        }
예제 #2
0
        public void Start(int port)
        {
            if (Running)
            {
                throw new InvalidOperationException("Server already running");
            }

            try
            {
                Process.GetCurrentProcess().PriorityClass = ServerBasePriority;
            }catch (Exception ex)
            {
                ISLogger.Write("Cannot set process priority to {0}: {1}", ServerBasePriority, ex.Message);
            }


            ConnectedClient.LocalHost = new ConnectedClient(true);
            ISLogger.Write("Starting server...");
            ServerPort = port;
            clientMan  = new ClientManager(ServerDefaultMaxClients);
            clientMan.AddClient(ConnectedClient.LocalHost);
            tcpListener = new ClientListener();
            tcpListener.ClientConnected += TcpListener_ClientConnected;


            tcpListener.Start(port);


            SetConsoleText("Current client: localhost");

            //We need to determine which OS is being used
            OSHelper.Os os = OSHelper.GetOsVersion();

            switch (os.System)
            {
            case OSHelper.Platform.Windows:
            {
                inputMan    = new WindowsInputManager();
                curMonitor  = new WindowsCursorMonitor();
                outManager  = new WindowsOutputManager();
                procMonitor = new WindowsProcessMonitor();
                break;
            }

            default:
                throw new NotImplementedException();
            }
            inputMan.Start();

            curMonitor.Start();
            curMonitor.EdgeHit += LocalHost_EdgeHit;

            procMonitor.StartMonitoring();
            procMonitor.ProcessEnteredFullscreen += ProcMonitor_ProcessEnteredFullscreen;
            procMonitor.ProcessExitedFullscreen  += ProcMonitor_ProcessExitedFullscreen;
            Running = true;

            inputMan.InputReceived         += InputMan_InputReceived;
            inputMan.ClientHotkeyPressed   += InputMan_ClientHotkeyPressed;
            inputMan.FunctionHotkeyPressed += InputMan_FunctionHotkeyPressed;
            inputMan.ClipboardTextCopied   += InputMan_ClipboardTextCopied;

            LoadHotkeySettings();
        }