public void Start(ISServerDependencies dependencies, StartOptions args, int port) { if (Running) { throw new InvalidOperationException("Server already running"); } ISLogger.EnableConsole = true; this.dependencies = dependencies; ISLogger.Write("Starting server..."); Running = true; try { clientMan = new ClientManager(16); startArgs = args; StartUdpHost(args, port); StartModules(args, dependencies); clientListener = new ISClientListener(port); AssignLocalEvents(); SetDefaultHotkeys(); clientMan.AddClient(ISServerSocket.Localhost); ClientConfig.ReloadClientConfigs(clientMan); Started?.Invoke(this, null); } catch (Exception ex) { ISLogger.Write("Failed to start server: " + ex.Message); Stop(); } }
private bool TryAcceptClient(ISServerSocket client) { try { clientMan.AddClient(client); return(true); } catch (Exception ex) { if (ex is ClientManager.DuplicateGuidException) { ISLogger.Write("client {0} declined: {1}", client.ClientName, "Duplicate GUID"); } else if (ex is ClientManager.DuplicateNameException) { ISLogger.Write("client {0} declined: {1}", client.ClientName, "Duplicate name"); } else if (ex is ClientManager.DuplicateNameException) { ISLogger.Write("client {0} declined: {1}", client.ClientName, "client limit reached"); } client.DeclineClient(ISServerSocket.ClientDeclinedReason.DuplicateName); //todo - possible race condition here? messages need to be sent before the client is disposed client.Dispose(); return(false); } }
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(); }