private void OnAcceptSocket(IAsyncResult ar) { try { Socket socket = _listener.EndAcceptSocket(ar); if (socket.Connected) { if (SocketConnectionCheck.CheckConnection(socket, MaxIpConnectionCount, AntiDDosStatus)) { socket.NoDelay = _disableNagleAlgorithm; AcceptedConnections++; ConnectionData connectionInfo = new ConnectionData(socket, _parser.Clone() as IDataParser, AcceptedConnections) { Disconnected = OnChannelDisconnect }; OnClientConnected(connectionInfo); } } } catch { // ignored } try { _listener?.BeginAcceptSocket(OnAcceptSocket, _listener); } catch { // ignored } }
private void NewConnectionRequest(IAsyncResult iAr) { if (_connectionListener != null) { if (_acceptConnections) { try { var replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = _disableNagleAlgorithm; var Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; var connectionCount = GetAmountOfConnectionFromIp(Ip); if (connectionCount < _maxIpConnectionCount) { _acceptedConnections++; var c = new ConnectionInformation(_acceptedConnections, replyFromComputer, parser.Clone() as IDataParser, Ip); ReportUserLogin(Ip); c.ConnectionChanged += c_connectionChanged; connectionEvent?.Invoke(c); } else { Log.Info("Connection denied from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "]. Too many connections (" + connectionCount + ")."); } } catch { // ignored } finally { _connectionListener.BeginAccept(NewConnectionRequest, _connectionListener); } } } }
/// <summary> /// Handels a new incoming data request from some computer from arround the world /// </summary> /// <param name="iAr">the IAsyncResult of the connection</param> private void newConnectionRequest(IAsyncResult iAr) { if (connectionListener != null) { if (_acceptConnections) { try { Socket replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = disableNagleAlgorithm; string Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; int ConnectionCount = getAmountOfConnectionFromIp(Ip); if (ConnectionCount < maxIpConnectionCount) { _acceptedConnections++; ConnectionInformation c = new ConnectionInformation(_acceptedConnections, replyFromComputer, this, parser.Clone() as IDataParser, Ip); reportUserLogin(Ip); c.connectionChanged += c_connectionChanged; if (connectionEvent != null) { connectionEvent(c); } } else { log.Info("Connection denied from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "]. Too many connections (" + ConnectionCount + ")."); } } catch { } finally { connectionListener.BeginAccept(newConnectionRequest, connectionListener); } } else { } } }
/// <summary> /// Handels a new incoming data request from some computer from arround the world /// </summary> /// <param name="iAr">the IAsyncResult of the connection</param> private void newConnectionRequest(IAsyncResult iAr) { if (connectionListener != null) { if (_acceptConnections) { try { Socket replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = disableNagleAlgorithm; string Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; int ConnectionCount = getAmountOfConnectionFromIp(Ip); if (ConnectionCount < maxIpConnectionCount) { _acceptedConnections++; ConnectionInformation c = new ConnectionInformation(_acceptedConnections, replyFromComputer, this, parser.Clone() as IDataParser, Ip); reportUserLogin(Ip); c.connectionChanged += c_connectionChanged; if (connectionEvent != null) { connectionEvent(c); } } else { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" [FUNCIONANDO] => [Rocket Emu] => Conexão negada de [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "]. por muitas conexões (" + ConnectionCount + ")."); } } catch { } finally { connectionListener.BeginAccept(newConnectionRequest, connectionListener); } } else { } } }
public void Init(int portID, int maxConnections, int connectionsPerIP, IDataParser parser, bool disableNaglesAlgorithm) { clients = new Dictionary<int, Client>(); this.parser = parser; this.parser = parser.Clone() as IDataParser; this.InitializeFields(); this.MaximumConnections = maxConnections; this.portInformation = portID; this.MaxIpConnectionCount = connectionsPerIP; this.acceptedConnections = 0; this.PrepareConnectionDetails(); }
/// <summary> /// Handels a new incoming data request from some computer from arround the world /// </summary> /// <param name="iAr">the IAsyncResult of the connection</param> private void newConnectionRequest(IAsyncResult iAr) { if (this.connectionListener != null) { if (acceptConnections) { try { Socket replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = this.disableNagleAlgorithm; Out.writeLine("New connection from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "].", Out.logFlags.StandardLogLevel); //if (activeConnections.Count < maximumConnections) { string Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; //if (getAmountOfConnectionFromIp(Ip) < maxIpConnectionCount) { acceptedConnections++; Out.writeLine("Accepted connection [" + acceptedConnections + "] from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "].", Out.logFlags.BelowStandardlogLevel); ConnectionInformation c = new ConnectionInformation(replyFromComputer, acceptedConnections, this, parser.Clone() as IDataParser, Ip); reportUserLogin(Ip); c.connectionChanged += c_connectionChanged; //activeConnections.Add(acceptedConnections, c); if (connectionEvent != null) { connectionEvent(c); } } //else // Out.writeLine("Connection denied from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "]. The user has too many connections", Out.logFlags.StandardLogLevel); } //else // Out.writeLine("Maximum amount of connections reached " + maximumConnections, Out.logFlags.ImportantLogLevel); } catch { //Out.writeError(ex.Message); } } finally { connectionListener.BeginAccept(new AsyncCallback(newConnectionRequest), connectionListener); } } else { Out.writeLine("Connection denied, server is not currently accepting connections!", Out.logFlags.StandardLogLevel); } } }
/// <summary> /// Handels a new incoming data request from some computer from arround the world /// </summary> /// <param name="iAr">the IAsyncResult of the connection</param> private void newConnectionRequest(IAsyncResult iAr) { if (connectionListener != null) { if (acceptConnections) { try { var replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = disableNagleAlgorithm; //Out.writeLine("New connection from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "].", Out.logFlags.StandardLogLevel); //if (activeConnections.Count < maximumConnections) var Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; acceptedConnections++; //Out.writeLine("Accepted connection [" + acceptedConnections + "] from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "].", Out.logFlags.BelowStandardlogLevel); var c = new ConnectionInformation(replyFromComputer, acceptedConnections, parser.Clone() as IDataParser, Ip); reportUserLogin(Ip); c.connectionChanged += c_connectionChanged; //activeConnections.Add(acceptedConnections, c); if (connectionEvent != null) { connectionEvent(c); } } catch { //Out.writeError(ex.Message); } } finally { connectionListener.BeginAccept(newConnectionRequest, connectionListener); } } else { //Out.writeLine("Connection denied, server is not currently accepting connections!", Out.logFlags.StandardLogLevel); } } }
private void NewConnectionRequest(IAsyncResult iAr) { if (ConnectionListener != null) { if (AcceptConnections) { try { Socket replyFromComputer = ((Socket)iAr.AsyncState).EndAccept(iAr); replyFromComputer.NoDelay = DisableNaglesAlgorithm; string Ip = replyFromComputer.RemoteEndPoint.ToString().Split(':')[0]; int ConnectionCount = GetAmountOfConnectionFromIp(Ip); if (ConnectionCount < MaxIpConnectionCount) { AcceptedConnections++; ConnectionInformation C = new ConnectionInformation(AcceptedConnections, replyFromComputer, this, Parser.Clone() as IDataParser, Ip); ReportUserLogin(Ip); C.ConnectionChanged += CConnectionChanged; if (ConnectionEvent2 != null) { ConnectionEvent2(C); } } else { //log.Info("Connection denied from [" + replyFromComputer.RemoteEndPoint.ToString().Split(':')[0] + "]. Too many connections (" + ConnectionCount + ")."); } } catch { } finally { ConnectionListener.BeginAccept(NewConnectionRequest, ConnectionListener); } } else { } } }