-- This file is part of SpikeRC.

-- SpikeRC is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- SpikeRC is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License
-- along with SpikeRC.  If not, see <http://www.gnu.org/licenses/>.

module User where

import Network.Socket hiding (send, sendTo, recv, recvFrom)
import Network.Socket.ByteString
import qualified Data.ByteString.Char8 as BS (pack, unpack)
import Control.Monad

type Target = String

data User = User
            { username   :: Maybe Target
            , connection :: Socket
            } deriving (Eq, Show)

recvUser :: User -> IO String
recvUser user = (liftM BS.unpack) $ recv (connection user) 1024

sendUser :: User -> String -> IO Int
sendUser user str = send (connection user) (BS.pack $ str ++ "\r\n")
