module Client.Configuration.ServerSettings
(
ServerSettings(..)
, ssNicks
, ssUser
, ssReal
, ssUserInfo
, ssPassword
, ssSaslUsername
, ssSaslPassword
, ssSaslEcdsaFile
, ssHostName
, ssPort
, ssTls
, ssTlsClientCert
, ssTlsClientKey
, ssTlsServerCert
, ssTlsCiphers
, ssConnectCmds
, ssSocksHost
, ssSocksPort
, ssChanservChannels
, ssFloodPenalty
, ssFloodThreshold
, ssMessageHooks
, ssName
, ssReconnectAttempts
, ssAutoconnect
, ssNickCompletion
, ssLogDir
, loadDefaultServerSettings
, UseTls(..)
) where
import Client.Commands.Interpolation
import Client.Commands.WordCompletion
import Control.Lens
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text as Text
import Irc.Identifier (Identifier)
import Network.Socket (HostName, PortNumber)
import System.Environment
data ServerSettings = ServerSettings
{ _ssNicks :: !(NonEmpty Text)
, _ssUser :: !Text
, _ssReal :: !Text
, _ssUserInfo :: !Text
, _ssPassword :: !(Maybe Text)
, _ssSaslUsername :: !(Maybe Text)
, _ssSaslPassword :: !(Maybe Text)
, _ssSaslEcdsaFile :: !(Maybe FilePath)
, _ssHostName :: !HostName
, _ssPort :: !(Maybe PortNumber)
, _ssTls :: !UseTls
, _ssTlsClientCert :: !(Maybe FilePath)
, _ssTlsClientKey :: !(Maybe FilePath)
, _ssTlsServerCert :: !(Maybe FilePath)
, _ssTlsCiphers :: String
, _ssConnectCmds :: ![[ExpansionChunk]]
, _ssSocksHost :: !(Maybe HostName)
, _ssSocksPort :: !PortNumber
, _ssChanservChannels :: ![Identifier]
, _ssFloodPenalty :: !Rational
, _ssFloodThreshold :: !Rational
, _ssMessageHooks :: ![Text]
, _ssName :: !(Maybe Text)
, _ssReconnectAttempts:: !Int
, _ssAutoconnect :: Bool
, _ssNickCompletion :: WordCompletionMode
, _ssLogDir :: Maybe FilePath
}
deriving Show
data UseTls
= UseTls
| UseInsecureTls
| UseInsecure
deriving Show
makeLenses ''ServerSettings
loadDefaultServerSettings :: IO ServerSettings
loadDefaultServerSettings =
do env <- getEnvironment
let username = Text.pack (fromMaybe "guest" (lookup "USER" env))
return ServerSettings
{ _ssNicks = username NonEmpty.:| []
, _ssUser = username
, _ssReal = username
, _ssUserInfo = username
, _ssPassword = Text.pack <$> lookup "IRCPASSWORD" env
, _ssSaslUsername = Nothing
, _ssSaslPassword = Text.pack <$> lookup "SASLPASSWORD" env
, _ssSaslEcdsaFile = Nothing
, _ssHostName = ""
, _ssPort = Nothing
, _ssTls = UseInsecure
, _ssTlsClientCert = Nothing
, _ssTlsClientKey = Nothing
, _ssTlsServerCert = Nothing
, _ssTlsCiphers = "HIGH"
, _ssConnectCmds = []
, _ssSocksHost = Nothing
, _ssSocksPort = 1080
, _ssChanservChannels = []
, _ssFloodPenalty = 2
, _ssFloodThreshold = 10
, _ssMessageHooks = []
, _ssName = Nothing
, _ssReconnectAttempts= 6
, _ssAutoconnect = False
, _ssNickCompletion = defaultNickWordCompleteMode
, _ssLogDir = Nothing
}