gameServer/NetRoutines.hs
author unc0rr
Sun, 06 Jun 2010 19:03:06 +0000
changeset 3501 a3159a410e5c
parent 3500 af8390d807d6
child 3502 ad38c653b7d9
permissions -rw-r--r--
Reimplement more core actions

{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
module NetRoutines where

import Network.Socket
import System.IO
import Control.Concurrent.Chan
import qualified Control.Exception as Exception
import Data.Time
import Control.Monad
-----------------------------
import CoreTypes
import Utils

acceptLoop :: Socket -> Chan CoreMessage -> IO ()
acceptLoop servSock chan = forever $ do
    Exception.handle
        (\(_ :: Exception.IOException) -> putStrLn "exception on connect") $
        do
        (sock, sockAddr) <- Network.Socket.accept servSock

        clientHost <- sockAddr2String sockAddr

        currentTime <- getCurrentTime

        sendChan' <- newChan

        let newClient =
                (ClientInfo
                    sendChan'
                    sock
                    clientHost
                    currentTime
                    ""
                    ""
                    False
                    0
                    0
                    0
                    False
                    False
                    False
                    undefined
                    undefined
                    )

        writeChan chan $ Accept newClient
        return ()