gameServer/NetRoutines.hs
author Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
Tue, 07 Jan 2014 11:40:58 +0100
branch0.9.20
changeset 9928 fe4b1ce9b6f8
parent 9528 9351e96990ae
child 10076 b235e520ea21
permissions -rw-r--r--
backport of r2aa9cf5badfcc978268a9bf06950942f27dfd366 Added cast to qreal, avoiding ftbfs due to issue #758 More explanation here https://wiki.debian.org/ArmEabiFixes And on qt-project.org reference website: "Typedef for double on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms, qreal is a typedef for float for performance reasons."

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

import Network.Socket
import Control.Concurrent.Chan
import Data.Time
import Control.Monad
import Data.Unique
-----------------------------
import CoreTypes
import Utils
import RoomsAndClients

acceptLoop :: Socket -> Chan CoreMessage -> IO ()
acceptLoop servSock chan = forever $
        do
        (sock, sockAddr) <- Network.Socket.accept servSock

        clientHost <- sockAddr2String sockAddr

        currentTime <- getCurrentTime

        sendChan' <- newChan

        uid <- newUnique

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

        writeChan chan $ Accept newClient
        return ()