Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a ToffeeInternalClient instance.
        /// </summary>
        public ToffeeInternalClient(ToffeeInternalConfiguration configuration, string roleName = "", LoggerCategory category = null)
            : base(ToffeeNetwork.StandardToffeeNetwork, 0)
        {
            // Properties
            Configuration = configuration;
            Role          = roleName;
            Log           = category;

            // If we can, log that this instance was created.
            Log?.Info("Created internal client.");

            // Connect to the message director
            Connect(configuration.Host, configuration.Port);
        }