/// <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."); }
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(); }
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."); }