예제 #1
0
        /// <summary>
        /// Creates a new ToffeeServer.
        /// </summary>
        /// <param name="configuration">The configuration to use for this server.</param>
        public ToffeeServer(ToffeeServerConfiguration configuration, LoggerCategory category = null)
        {
            // Create the TCP listener
            Listener  = new TcpListener(new IPEndPoint(IPAddress.Any, configuration.Port));
            Listening = false;

            // Set the properties of this server depending on the values in the configuration
            Port = configuration.Port;
            MaximumConnections = configuration.MaximumConnections;
            ForceEncryption    = configuration.ForceEncryption;
            EncryptionKey      = configuration.EncryptionKey;

            // Sanity check for encryption
            if ((ForceEncryption) && (EncryptionKey == 0x00))
            {
                Log?.Warning("Cannot force encryption, and have no encryption key! Setting 'ForceEncryption' to false.");
                ForceEncryption = false;
            }

            // Create the components
            if (configuration.Network != null)
            {
                Network = ToffeeNetwork.CreateNetwork(configuration.Network.Name, configuration.Network.Suffix);
            }
            else
            {
                Network = ToffeeNetwork.CreateNetwork(ToffeeNetwork.StandardToffeeNetwork);
            }
            SessionManager = new ToffeeSessionManager(this);
            Log            = category;
            Log?.Info("Created.");
        }
예제 #2
0
        public ToffeeSession(ToffeeSessionManager manager, Socket socket)
            : base(socket, manager.Server.Network.Name, manager.Server.EncryptionKey)
        {
            Manager     = manager;
            Validated   = false;
            ConnectTime = TimeUtil.GetUnixTimestamp();

            // Begin receiving packets
            BeginReceivePacket();
        }
예제 #3
0
        public ToffeeServer(int port, LoggerCategory category = null)
        {
            Listener  = new TcpListener(new IPEndPoint(IPAddress.Any, port));
            Listening = false;
            Port      = port;

            Network        = ToffeeNetwork.CreateNetwork(ToffeeNetwork.StandardToffeeNetwork);
            SessionManager = new ToffeeSessionManager(this);
            Log            = category;
            Log?.Info("Created.");
        }