/// <summary> /// 启动代理 /// </summary> public void Start() { Listener.Start(); "接受第一个请求".Log(); Listener.BeginAcceptTcpClient(new AsyncCallback(Accept), Listener); IsActive = true; }
private static void ListenAsync() { AcquireListener(); if (Listener == null) { return; } VitaNexCore.TryCatch( () => Listener.BeginAcceptTcpClient( r => { var client = VitaNexCore.TryCatchGet(() => Listener.EndAcceptTcpClient(r), CMOptions.ToConsole); ListenAsync(); if (client != null && client.Connected) { VitaNexCore.TryCatch(() => Connected(client), CMOptions.ToConsole); } }, null), e => { _Listening = false; CMOptions.ToConsole(e); }); }
// Adds an incoming connection to the queue private void Listen(IAsyncResult Result) { // Check if server is bound if (Listener.Server.IsBound) { try { // Get incoming connection var Connection = Listener.EndAcceptTcpClient(Result); // Lock our connection queue to prevent any race conditions lock (ConnectionQueue) { // Add the incoming connection to our connection queue ConnectionQueue.Enqueue(Connection); // Signal that a connection is ready to be accepted ReadyEvent.Set(); } // Start listening again Listener.BeginAcceptTcpClient(Listen, null); } catch { } } }
private void Listen() { if (Running) { Listener.BeginAcceptTcpClient(ProcessNewClient, null); } }
public static void ListenAsync() { AcquireListener(); if (Listener == null) { return; } VitaNexCore.TryCatch( () => { Listener.BeginAcceptTcpClient( r => { var client = VitaNexCore.TryCatchGet(Listener.EndAcceptTcpClient, r, CSOptions.ToConsole); ListenAsync(); if (client != null && client.Connected) { //client.NoDelay = true; if (_ServerStarted) { var ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address; var allow = !CSOptions.UseWhitelist; if (allow) { allow = !CSOptions.Blacklist.Any(l => Utility.IPMatch(l, ip)) && !Firewall.IsBlocked(ip); } if (!allow && CSOptions.UseWhitelist) { allow = CSOptions.Whitelist.Any(l => Utility.IPMatch(l, ip)); } if (allow) { Connect(new WebAPIClient(client)); return; } } client.Close(); } }, null); }, e => { if (!(e is SocketException) && !(e is ObjectDisposedException)) { CSOptions.ToConsole(e); } }); }
// start the server public void StartListening() { if (!IsListening) { Listener.Start(); Listener.BeginAcceptTcpClient(OnAcceptedTcpClient, this); } }
protected void AcceptClientAsync(IAsyncResult result) { lock (NetworkLock) { if (Listener == null) { return; // Server shutting down } var client = new RemoteClient(Listener.EndAcceptTcpClient(result)); client.NetworkStream = new MinecraftStream(new BufferedStream(client.NetworkClient.GetStream())); Clients.Add(client); Listener.BeginAcceptTcpClient(AcceptClientAsync, null); } }
public void SocketAcceptCallback(IAsyncResult ar) { TcpListener listener = (TcpListener)ar.AsyncState; try { TcpClient client = listener.EndAcceptTcpClient(ar); client.NoDelay = true; NewClient(client); Listener.BeginAcceptTcpClient(new AsyncCallback(SocketAcceptCallback), listener); } catch (Exception e) { AddMessage(e.Message); } }
protected void AcceptConnectionAsync(IAsyncResult result) { try { if (Listener == null || result == null) { return; // This happens sometimes on shut down, it's weird } var tcpClient = Listener.EndAcceptTcpClient(result); var client = new MinecraftClient(tcpClient, this); lock (NetworkLock) { Clients.Add(client); } Listener.BeginAcceptTcpClient(AcceptConnectionAsync, null); } catch { } // TODO: Investigate this more deeply }
private static void AcceptClient(IAsyncResult result) { var client = Listener.EndAcceptTcpClient(result); Console.WriteLine("New connection from " + client.Client.RemoteEndPoint.ToString()); // Connect to remote var server = new TcpClient(); server.Connect(ProxySettings.RemoteEndPoint); var proxy = new Proxy(client.GetStream(), server.GetStream(), new Log(new StreamWriter(GetLogName()), ProxySettings), ProxySettings); Sessions.Add(proxy); foreach (var plugin in Plugins) { plugin.SessionInitialize(proxy); } proxy.Start(); Listener.BeginAcceptTcpClient(AcceptClient, null); }
protected virtual void OnAccept(IAsyncResult ar) { ProxyClient client = null; try { if (!IsListening) { return; } client = NewClient(Listener.EndAcceptTcpClient(ar)); Listener.BeginAcceptTcpClient(OnAccept, null); lock (Clients) Clients.Add(client); client.Start(RemoteAddress, RemotePort); if (client.SourceTcp.Client != null) { StaticLogger.Info(string.Format("Client {0} connected", client.SourceTcp.Client.RemoteEndPoint)); } } catch (Exception ex) { if (client != null) { OnException(client, ex); } else { //Ignore objectdisposed, happens when stopping if (!(ex is ObjectDisposedException)) { StaticLogger.Error(ex); } } } }
public static void Listen() { if (Listener != null && Accept) { Listener.BeginAcceptTcpClient(ConnectClient, Listener); } if (SslListener != null && Accept) { Console.WriteLine(DateTime.Now.ToLongTimeString() + ": Listening for SSL connections"); SslListener.BeginAcceptTcpClient(SslConnectClient, SslListener); } while (true) { DiscoverIntentions(); Thread.Sleep(10); if (GameMasterThread.Status != TaskStatus.Running) { GameMasterThread.Start(); Console.WriteLine("Restarting GameMaster main thread"); } } }
public static void ListenAsync() { AcquireListener(); if (Listener == null) { return; } try { Listener.BeginAcceptTcpClient(EndAcceptTcpClient, null); } catch (SocketException) { } catch (ObjectDisposedException) { } catch (Exception e) { CSOptions.ToConsole(e); } }
/// <summary> /// Starts the server. /// </summary> public void Start() { if (Levels.Count == 0) { LogProvider.Log("Unable to start server with no worlds loaded."); throw new InvalidOperationException("Unable to start server with no worlds loaded."); } LogProvider.Log("Starting Craft.Net server..."); CryptoServiceProvider = new RSACryptoServiceProvider(1024); ServerKey = CryptoServiceProvider.ExportParameters(true); Listener.Start(); Listener.BeginAcceptTcpClient(AcceptConnectionAsync, null); NetworkWorkerThread = new Thread(NetworkWorker); NetworkWorkerThread.Start(); updatePlayerListTimer = new Timer(UpdatePlayerList, null, 60000, 60000); LogProvider.Log("Server started."); }
public void Start() { ModuleStatus = ModuleStatus.Running; try { Listener.Start(); Task.Factory.StartNew(delegate() { while (ModuleStatus == ModuleStatus.Running) { AllDone.Reset(); Listener.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), Listener); AllDone.WaitOne(); } }); } catch (Exception e) { throw new Exception(e.Message); } }
/// <summary> /// Creates a new instance of our HTTP server. This is used to inject the HTML client into browsers. /// </summary> /// <param name="listenInterface">The interface to bind the socket to.</param> /// <param name="port">The port to listen on.</param> /// <param name="document">The webpage.</param> /// <param name="document404Error">An HTML document used to indicate 404 errors.</param> /// <param name="documentMimeError">An HTML document used to indicate that a type of data is unsupported. This should never happen under normal circumstances, as the dashboard only uses supported file types.</param> ///<param name="secure">True if you wish to enable HTTPS.</param> /// <param name="dosDetector">The DoS detector.</param> /// <param name="mainClass">The plugin's main.</param> /// <param name="apiServer">The WebAPI server.</param> /// <param name="certificate">The SSL certificate to use.</param> public HttpServer(string listenInterface, ushort port, string document, string document404Error, string documentMimeError, Impostor.Commands.Core.Class mainClass, WebApiServer apiServer, QuiteEffectiveDetector dosDetector, bool secure, X509Certificate2 certificate) { if (secure && certificate == null) { throw new Exception("What are you doing, anti?"); } //utf8 is standard. this.Document = Encoding.UTF8.GetBytes(document); this.Document404Error = Encoding.UTF8.GetBytes(document404Error); this.DocumentTypeNotSupported = Encoding.UTF8.GetBytes(documentMimeError); this.Running = true; this.MainClass = mainClass; this.Listener = new TcpListener(IPAddress.Parse(listenInterface), port); this.ApiServer = apiServer; this.LogComposer = new CsvComposer(); this.InvalidPageHandlers = new List <string>(); this.QEDetector = dosDetector; this.AttackerAddresses = new ConcurrentBag <string>(); this.EnableSecurity = secure; this.Certificate = certificate; Listener.Start(); Listener.BeginAcceptTcpClient(EndAccept, Listener); }
private void WaitForClients() { Listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null); }
public void StartListening() { Listener.Start(); Listener.BeginAcceptTcpClient(OnConnectionAccepted, null); }
private void WaitForConnection() { Listener.BeginAcceptTcpClient(new AsyncCallback(ConnectionHandler), null); }
internal void HandleConnectionAccepted(PacketServerConnection connection) { ConnectionsList.Add(connection); ConnectionAccepted?.Invoke(this, new PacketServerConnectionAcceptedEventArgs(connection)); Listener.BeginAcceptTcpClient(OnConnectionAccepted, null); }
private void WaitForClientConnect() { Listener.BeginAcceptTcpClient(OnClientConnect, new object()); }
/// <summary> /// Starts an asynchronous check for new connections /// </summary> private void ListenForNewClient() { Listener.BeginAcceptTcpClient(AcceptClient, null); }