Beispiel #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.");
        }
Beispiel #2
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.");
        }
Beispiel #3
0
        /// <summary>
        /// Creates a ToffeeParticipant instance with the settings provided.
        /// </summary>
        /// <param name="networkName"></param>
        /// <param name="encryptionKey"></param>
        public ToffeeParticipant(string networkName, ulong encryptionKey)
        {
            // Set the empty events
            Socket           = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ConnectionFailed = delegate { };
            ConnectionLost   = delegate { };

            // Protocol settings
            if (encryptionKey != 0)
            {
                Encryption = new EncryptionService(encryptionKey);
            }

            // Empty containers
            Network  = ToffeeNetwork.CreateNetwork(networkName);
            Objects  = new ObjectContainer();
            Services = new ServiceContainer();
            SendLock = new object();
        }