Esempio n. 1
0
 public TcpServer(ILogger logger, INetworkServerSettings settings, INetworkConnectionHandler connectionHandler)
 {
     this.settings          = settings;
     this.connectionHandler = connectionHandler;
     this.logger            = logger;
     this.listener          = new TcpListener(IPAddress.Parse(settings.Ip), settings.Port);
 }
Esempio n. 2
0
        public void HandleConnect(INetworkServer networkServer, INetworkServerSettings settings, Socket connection)
        {
            var conn = connectionProvider.Get(connection);

            if (conn != null)
            {
                //logger.WriteDebug($"Client from '{conn.RemoteEndPoint}' connected!");
                if (sessionManager.NewAllowed())
                {
                    conn.SetSession(sessionProvider.New(this, conn)); // creates a temporarily session
                    connectionManager.Add(conn);
                    conn.BeginHandlePackets();
                }
                else
                {
                    logger.WriteDebug("Cannot generate any more sessions. Closing connection.");
                    conn.Close(true);
                }
            }
        }